mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-27 14:43:33 +08:00
common board idenity cleanup and add mfguid to api
Remove the notion of legacy from the api. The board level code will perform the traslation to lecacy format on the STM32. new targets will not need to do this as there is no case where the serial number were used by mfg for tracking. Extend board common api to get mfguid and mfguid formatted This adds an api that return the MFGUID as an array of bytes or a string. The data is returned with the MSD at index 0 and the LSD at index PX4_CPU_MFGUID_BYTE_LENGTH-1. Removed all reodering defines from the api and hal
This commit is contained in:
committed by
Lorenz Meier
parent
b182a5eeca
commit
bc8b117e85
@@ -41,49 +41,54 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
const raw_uuid_uint32_reorder_t px4_legacy_word32_order = PX4_CPU_UUID_WORD32_LEGACY_FORMAT_ORDER;
|
||||
#define CPU_UUID_BYTE_FORMAT_ORDER {3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8}
|
||||
#define SWAP_UINT32(x) (((x) >> 24) | (((x) & 0x00ff0000) >> 8) | (((x) & 0x0000ff00) << 8) | ((x) << 24))
|
||||
|
||||
void board_get_uuid_raw(raw_uuid_byte_t *raw_uuid)
|
||||
{
|
||||
memcpy(raw_uuid, (uint8_t *) STM32_SYSMEM_UID, PX4_CPU_UUID_BYTE_LENGTH);
|
||||
}
|
||||
/* A type suitable for holding the reordering array for the byte format of the UUID
|
||||
*/
|
||||
|
||||
void board_get_uuid(raw_uuid_byte_t uuid, uuid_uint8_reorder_t reorder)
|
||||
typedef const uint8_t uuid_uint8_reorder_t[PX4_CPU_UUID_BYTE_LENGTH];
|
||||
|
||||
|
||||
void board_get_uuid(uuid_byte_t uuid_bytes)
|
||||
{
|
||||
raw_uuid_byte_t raw_uuid;
|
||||
board_get_uuid_raw(&raw_uuid);
|
||||
uuid_uint8_reorder_t reorder = CPU_UUID_BYTE_FORMAT_ORDER;
|
||||
union {
|
||||
uuid_byte_t b;
|
||||
uuid_uint32_t w;
|
||||
} id;
|
||||
|
||||
/* Copy the serial from the chips non-write memory */
|
||||
|
||||
board_get_uuid32(id.w);
|
||||
|
||||
/* swap endianess */
|
||||
|
||||
for (int i = 0; i < PX4_CPU_UUID_BYTE_LENGTH; i++) {
|
||||
uuid[i] = raw_uuid[reorder[i]];
|
||||
uuid_bytes[i] = id.b[reorder[i]];
|
||||
}
|
||||
}
|
||||
|
||||
__EXPORT void board_get_uuid_raw32(raw_uuid_uint32_t raw_uuid_words,
|
||||
raw_uuid_uint32_reorder_t *optional_reorder)
|
||||
__EXPORT void board_get_uuid32(uuid_uint32_t uuid_words)
|
||||
{
|
||||
if (optional_reorder == NULL) {
|
||||
optional_reorder = &px4_legacy_word32_order;
|
||||
}
|
||||
|
||||
uint32_t *chip_uuid = (uint32_t *) STM32_SYSMEM_UID;
|
||||
|
||||
for (int i = 0; i < PX4_CPU_UUID_WORD32_LENGTH; i++) {
|
||||
raw_uuid_words[i] = chip_uuid[(*optional_reorder)[i]];
|
||||
uuid_words[i] = chip_uuid[i];
|
||||
}
|
||||
}
|
||||
|
||||
int board_get_uuid_formated32(char *format_buffer, int size,
|
||||
int board_get_uuid32_formated(char *format_buffer, int size,
|
||||
const char *format,
|
||||
const char *seperator,
|
||||
raw_uuid_uint32_reorder_t *optional_reorder)
|
||||
const char *seperator)
|
||||
{
|
||||
raw_uuid_uint32_t uuid;
|
||||
board_get_uuid_raw32(uuid, optional_reorder);
|
||||
uuid_uint32_t uuid;
|
||||
board_get_uuid32(uuid);
|
||||
int offset = 0;
|
||||
int sep_size = seperator ? strlen(seperator) : 0;
|
||||
|
||||
for (int i = 0; i < PX4_CPU_UUID_WORD32_LENGTH; i++) {
|
||||
offset += snprintf(&format_buffer[offset], size - ((i * 2 * sizeof(uint32_t)) + 1), format, uuid[i]);
|
||||
offset += snprintf(&format_buffer[offset], size - offset, format, uuid[i]);
|
||||
|
||||
if (sep_size && i < PX4_CPU_UUID_WORD32_LENGTH - 1) {
|
||||
strcat(&format_buffer[offset], seperator);
|
||||
@@ -93,3 +98,29 @@ int board_get_uuid_formated32(char *format_buffer, int size,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int board_get_mfguid(mfguid_t mfgid)
|
||||
{
|
||||
uint32_t *chip_uuid = (uint32_t *) STM32_SYSMEM_UID;
|
||||
uint32_t *rv = (uint32_t *) &mfgid[0];
|
||||
|
||||
for (int i = 0; i < PX4_CPU_UUID_WORD32_LENGTH; i++) {
|
||||
*rv++ = SWAP_UINT32(chip_uuid[(PX4_CPU_UUID_WORD32_LENGTH - 1) - i]);
|
||||
}
|
||||
|
||||
return PX4_CPU_MFGUID_BYTE_LENGTH;
|
||||
}
|
||||
|
||||
int board_get_mfguid_formated(char *format_buffer, int size)
|
||||
{
|
||||
mfguid_t mfguid;
|
||||
|
||||
board_get_mfguid(mfguid);
|
||||
int offset = 0;
|
||||
|
||||
for (unsigned int i = 0; i < PX4_CPU_MFGUID_BYTE_LENGTH; i++) {
|
||||
offset += snprintf(&format_buffer[offset], size - offset, "%02x", mfguid[i]);
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user