Browse Source

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
sbg
David Sidrane 8 years ago committed by Lorenz Meier
parent
commit
bc8b117e85
  1. 117
      src/drivers/boards/common/board_common.h
  2. 75
      src/drivers/boards/common/stm32/board_identity.c
  3. 16
      src/platforms/posix/include/system_config.h
  4. 55
      src/platforms/px4_micro_hal.h

117
src/drivers/boards/common/board_common.h

@ -198,31 +198,35 @@ typedef enum board_reset_e { @@ -198,31 +198,35 @@ typedef enum board_reset_e {
board_reset_enter_bootloader = 3 /* Perform a reset to the boot loader */
} board_reset_e;
/* Defined the types used for board UUID
/* Defined the types used for board UUID and MFG UID
*
* A type suitable for holding the byte format of the UUID
* The raw format is the result of a memcopy from the lowest address
* to the highest address of the CPU's serial number
* Bytes [00] ,[01], [02], [03], [04], [05], [06], [07], [08], [09], [10], [11]...
* Bits 00-07,8-15,16-23,24-31,32-39,40-47,48-55,56-63,64-71,72-79,80-87,88-95...
*
* The original PX4 stm32 (legacy) based implementation **displayed** the
* UUID as: ABCD EFGH IJKL
* Where:
* A was bit 31 and D was bit 0
* E was bit 63 and H was bit 32
* I was bit 95 and L was bit 64
*
* Since the string was used by some manufactures to identify the units
* it must be preserved.
*
* For new targets moving forward we will use
* IJKL EFGH ABCD
*/
typedef uint8_t raw_uuid_byte_t[PX4_CPU_UUID_BYTE_LENGTH];
/* A type suitable for holding the reordering array for the byte format of the UUID
*/
typedef const uint8_t uuid_uint8_reorder_t[PX4_CPU_UUID_BYTE_LENGTH];
/* A type suitable for defining the 8 bit format of the UUID */
typedef uint8_t uuid_byte_t[PX4_CPU_UUID_BYTE_LENGTH];
/* A type suitable for defining the 32bit format of the UUID and reordering */
typedef uint32_t raw_uuid_uint32_t[PX4_CPU_UUID_WORD32_LENGTH];
typedef const uint8_t raw_uuid_uint32_reorder_t[PX4_CPU_UUID_WORD32_LENGTH];
/* A type suitable for defining the 32bit format of the UUID */
typedef uint32_t uuid_uint32_t[PX4_CPU_UUID_WORD32_LENGTH];
/*
* The Legacy px4 uint32 ordering
* word [0] [1] [2]
* bits 31-00, 63-32, 95-64
/* A type suitable for defining the 8 bit format of the MFG UID
* This is always returned as MSD @ index 0 -LSD @ index PX4_CPU_MFGUID_BYTE_LENGTH-1
*/
extern const raw_uuid_uint32_reorder_t px4_legacy_word32_order;
typedef uint8_t mfguid_t[PX4_CPU_MFGUID_BYTE_LENGTH];
/************************************************************************************
* Private Functions
************************************************************************************/
@ -292,6 +296,10 @@ __EXPORT void board_rc_input(bool invert_on); @@ -292,6 +296,10 @@ __EXPORT void board_rc_input(bool invert_on);
#else
__EXPORT void board_system_reset(int status) noreturn_function;
#endif
#if !defined(BOARD_HAS_POWER_CONTROL)
#define px4_board_pwr(switch_on) { do {} while(0); }
#endif
/************************************************************************************
* Name: board_set_bootload_mode
*
@ -308,19 +316,6 @@ __EXPORT int board_set_bootload_mode(board_reset_e mode); @@ -308,19 +316,6 @@ __EXPORT int board_set_bootload_mode(board_reset_e mode);
#endif
#if !defined(BOARD_OVERRIDE_UUID)
/************************************************************************************
* Name: board_get_uuid_raw
*
* Description:
* All boards either provide a way to read a uuid of PX4_CPU_UUID_BYTE_LENGTH
* from PX4_CPU_UUID_ADDRESS in the SoC's address space OR define
* BOARD_OVERRIDE_UUID as an array of bytes that is PX4_CPU_UUID_BYTE_LENGTH
* The raw format is the result of coping the bytes from the SoC in low memory
* to high memory.
*
************************************************************************************/
__EXPORT void board_get_uuid_raw(raw_uuid_byte_t *raw_uuid_bytes);
/************************************************************************************
* Name: board_get_uuid
*
@ -328,36 +323,37 @@ __EXPORT void board_get_uuid_raw(raw_uuid_byte_t *raw_uuid_bytes); @@ -328,36 +323,37 @@ __EXPORT void board_get_uuid_raw(raw_uuid_byte_t *raw_uuid_bytes);
* All boards either provide a way to read a uuid of PX4_CPU_UUID_BYTE_LENGTH
* from PX4_CPU_UUID_ADDRESS in the SoC's address space OR define
* BOARD_OVERRIDE_UUID as an array of bytes that is PX4_CPU_UUID_BYTE_LENGTH
* The format is the result of coping the bytes from the SoC in low memory
* to high memory and then reordering them based on the reorder.
*
************************************************************************************/
__EXPORT void board_get_uuid(raw_uuid_byte_t raw_uuid_bytes,
uuid_uint8_reorder_t reorder);
__EXPORT void board_get_uuid(uuid_byte_t uuid_bytes);
/************************************************************************************
* Name: board_get_uuid_raw32
* Name: board_get_uuid32
*
* Description:
* All boards either provide a way to read a uuid of PX4_CPU_UUID_WORD32_LENGTH
* from PX4_CPU_UUID_ADDRESS in the Soc's address space OR define
* BOARD_OVERRIDE_UUID as an array of bytes that is PX4_CPU_UUID_BYTE_LENGTH
* The raw32 format is the result of coping returning the 32bit words from
* low memory to high memory. But provide an optional to argument to reorder
* the output array.
* On Legacy (stm32) targets the raw32 format is the result of coping returning
* the 32bit words from low memory to high memory. On new targets the result
* will be an array of words with the MSW at index 0 and the LSW: at index
* PX4_CPU_UUID_WORD32_LENGTH-1.
*
* The ordering can optionally be set by defining
* PX4_CPU_UUID_WORD32_FORMAT_ORDER
*
************************************************************************************/
__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);
/************************************************************************************
* Name: board_get_uuid_formated32
* Name: board_get_uuid32_formated
*
* Description:
* All boards either provide a way to retrieve a uuid and format it
* Or define BOARD_OVERRIDE_UUID
* The format is the result the optionally reordered raw 32bit word format
* printed with the optional separator
* or define BOARD_OVERRIDE_UUID
* The format can optionally be reordered if PX4_CPU_UUID_WORD32_FORMAT_ORDER is
* defined and printed with the optional separator
*
* With seperator = ":"
* 31-00:63-32:95-64
@ -370,15 +366,36 @@ __EXPORT void board_get_uuid_raw32(raw_uuid_uint32_t raw_uuid_words, @@ -370,15 +366,36 @@ __EXPORT void board_get_uuid_raw32(raw_uuid_uint32_t raw_uuid_words,
* 3238333641203833355110
*
************************************************************************************/
__EXPORT int board_get_uuid_formated32(char *format_buffer, int size,
__EXPORT 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);
#endif // !defined(BOARD_OVERRIDE_UUID)
#if !defined(BOARD_HAS_POWER_CONTROL)
#define px4_board_pwr(switch_on) { do {} while(0); }
#endif
#if !defined(BOARD_OVERRIDE_MFGUID)
/************************************************************************************
* Name: board_get_mfguid
*
* Description:
* All boards either provide a way to retrieve a manafactuers Uniqe ID or
* define BOARD_OVERRIDE_MFGUID.
* The MFGUID is returned as an array of bytes in
* MSD @ index 0 - LSD @ index PX4_CPU_MFGUID_BYTE_LENGTH-1
*
************************************************************************************/
int board_get_mfguid(mfguid_t mfgid);
/************************************************************************************
* Name: board_get_mfguid_formated
*
* Description:
* All boards either provide a way to retrieve a formatted string of the
* manafactuers Uniqe ID or define BOARD_OVERRIDE_MFGUID
*
************************************************************************************/
int board_get_mfguid_formated(char *format_buffer, int size);
#endif // !defined(BOARD_OVERRIDE_MFGUID)
/************************************************************************************
* Name: board_mcu_version

75
src/drivers/boards/common/stm32/board_identity.c

@ -41,49 +41,54 @@ @@ -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
*/
typedef const uint8_t uuid_uint8_reorder_t[PX4_CPU_UUID_BYTE_LENGTH];
void board_get_uuid(raw_uuid_byte_t uuid, uuid_uint8_reorder_t reorder)
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, @@ -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;
}

16
src/platforms/posix/include/system_config.h

@ -10,18 +10,24 @@ @@ -10,18 +10,24 @@
#define PX4_I2C_OBDEV_LED 0x55
#define BOARD_OVERRIDE_UUID "SIMULATIONID"
#define BOARD_OVERRIDE_MFGUID BOARD_OVERRIDE_UUID
#define SIM_FORMATED_UUID "000000010000000200000003"
#define PX4_CPU_UUID_BYTE_LENGTH 12
#define PX4_CPU_UUID_WORD32_LENGTH 3
#define PX4_CPU_UUID_WORD32_LEGACY_FORMAT_SIZE (PX4_CPU_UUID_WORD32_LENGTH-1+(2*PX4_CPU_UUID_BYTE_LENGTH))
#define PX4_CPU_MFGUID_BYTE_LENGTH PX4_CPU_UUID_BYTE_LENGTH
#define PX4_CPU_UUID_WORD32_UNIQUE_H 2 /* Most significant digits change the least */
#define PX4_CPU_UUID_WORD32_UNIQUE_M 1 /* Middle significant digits */
#define PX4_CPU_UUID_WORD32_UNIQUE_L 0 /* Least significant digits change the most */
#define PX4_CPU_UUID_WORD32_FORMAT_SIZE (PX4_CPU_UUID_WORD32_LENGTH-1+(2*PX4_CPU_UUID_BYTE_LENGTH)+1)
#define PX4_CPU_MFGUID_FORMAT_SIZE ((2*PX4_CPU_MFGUID_BYTE_LENGTH)+1)
#define BOARD_OVERRIDE_CPU_VERSION (-1)
#define board_mcu_version(rev, revstr, errata) BOARD_OVERRIDE_CPU_VERSION
typedef unsigned char raw_uuid_byte_t[PX4_CPU_UUID_BYTE_LENGTH];
typedef unsigned int raw_uuid_uint32_t[PX4_CPU_UUID_WORD32_LENGTH];
typedef unsigned char uuid_byte_t[PX4_CPU_UUID_BYTE_LENGTH];
typedef unsigned int uuid_uint32_t[PX4_CPU_UUID_WORD32_LENGTH];
#define board_get_uuid_raw32(id, null) do {id[0]=0;id[1]=1;id[2]=2;} while(0)
#define board_get_uuid_formated32(format_buffer, size, format, seperator, optional_reorder) do { strcpy(format_buffer, SIM_FORMATED_UUID); } while(0)
#define board_get_uuid32(id) do {for(int _idi=0; _idi < PX4_CPU_UUID_WORD32_LENGTH; _idi++) {id[_idi] = _idi;}} while(0)
#define board_get_uuid32_formated(format_buffer, size, format, seperator) do { strcpy(format_buffer, SIM_FORMATED_UUID); } while(0)
#define CONFIG_NFILE_STREAMS 1

55
src/platforms/px4_micro_hal.h

@ -63,26 +63,59 @@ __BEGIN_DECLS @@ -63,26 +63,59 @@ __BEGIN_DECLS
* init32_t[1] PX4_CPU_UUID_ADDRESS[1] bits 63:32 (offset 4)
* init32_t[2] PX4_CPU_UUID_ADDRESS[3] bits 96:64 (offset 8)
*
* PX4 uses the legacy uint32 ordering
* word [0] [1] [2]
* bits 31-00, 63-32, 95-64
* The original PX4 stm32 (legacy) based implementation **displayed** the
* UUID as: ABCD EFGH IJKL
* Where:
* A was bit 31 and D was bit 0
* E was bit 63 and H was bit 32
* I was bit 95 and L was bit 64
*
* Since the string was used by some manufactures to identify the units
* it must be preserved.
*
* For new targets moving forward we will use
* IJKL EFGH ABCD
*/
# define PX4_CPU_UUID_BYTE_LENGTH 12
# define PX4_CPU_UUID_WORD32_LENGTH (PX4_CPU_UUID_BYTE_LENGTH/sizeof(uint32_t))
# define PX4_CPU_UUID_WORD32_LEGACY_FORMAT_ORDER {0,1,2}
# define PX4_CPU_UUID_WORD32_LEGACY_FORMAT_SIZE (PX4_CPU_UUID_WORD32_LENGTH-1+(2*PX4_CPU_UUID_BYTE_LENGTH))
/* The mfguid will be an array of bytes with
* MSD @ index 0 - LSD @ index PX4_CPU_MFGUID_BYTE_LENGTH-1
*
* It wil be conferted to a string with the MSD on left and LSD on the right most position.
*/
# define PX4_CPU_MFGUID_BYTE_LENGTH PX4_CPU_UUID_BYTE_LENGTH
/* By not defining PX4_CPU_UUID_CORRECT_CORRELATION the following maintains the legacy incorrect order
* used for selection of significant digits of the UUID in the PX4 code base.
* This is done to avoid the ripple effects changing the IDs used on STM32 base platforms
*/
# if defined(PX4_CPU_UUID_CORRECT_CORRELATION)
# define PX4_CPU_UUID_WORD32_UNIQUE_H 0 /* Least significant digits change the most */
# define PX4_CPU_UUID_WORD32_UNIQUE_M 1 /* Middle significant digits */
# define PX4_CPU_UUID_WORD32_UNIQUE_L 2 /* Most significant digits change the least */
# else
/* Legacy incorrect ordering */
# define PX4_CPU_UUID_WORD32_UNIQUE_H 2 /* Most significant digits change the least */
# define PX4_CPU_UUID_WORD32_UNIQUE_M 1 /* Middle significant digits */
# define PX4_CPU_UUID_WORD32_UNIQUE_L 0 /* Least significant digits change the most */
# endif
/* Separator nnn:nnn:nnnn 2 char per byte term */
# define PX4_CPU_UUID_WORD32_FORMAT_SIZE (PX4_CPU_UUID_WORD32_LENGTH-1+(2*PX4_CPU_UUID_BYTE_LENGTH)+1)
# define PX4_CPU_MFGUID_FORMAT_SIZE ((2*PX4_CPU_MFGUID_BYTE_LENGTH)+1)
# define px4_spibus_initialize(port_1based) stm32_spibus_initialize(port_1based)
# define px4_i2cbus_initialize(bus_num_1based) stm32_i2cbus_initialize(bus_num_1based)
# define px4_i2cbus_uninitialize(pdev) stm32_i2cbus_uninitialize(pdev)
# define px4_arch_configgpio(pinset) stm32_configgpio(pinset)
# define px4_arch_unconfiggpio(pinset) stm32_unconfiggpio(pinset)
# define px4_arch_gpioread(pinset) stm32_gpioread(pinset)
# define px4_arch_gpiowrite(pinset, value) stm32_gpiowrite(pinset, value)
# define px4_arch_gpiosetevent(pinset,r,f,e,fp) stm32_gpiosetevent(pinset,r,f, e,fp)
# endif
# define px4_arch_configgpio(pinset) stm32_configgpio(pinset)
# define px4_arch_unconfiggpio(pinset) stm32_unconfiggpio(pinset)
# define px4_arch_gpioread(pinset) stm32_gpioread(pinset)
# define px4_arch_gpiowrite(pinset, value) stm32_gpiowrite(pinset, value)
# define px4_arch_gpiosetevent(pinset,r,f,e,fp) stm32_gpiosetevent(pinset,r,f, e,fp)
#endif
#include <arch/board/board.h>
__END_DECLS
#endif

Loading…
Cancel
Save