From f916aeddea05a5905b8ffc7e42a0f5ecc7dd2e5b Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Thu, 11 Jan 2024 09:57:06 -0800 Subject: [PATCH] PX4:comon Support BOARD_HAS_HW_SPLIT_VERSIONING --- .../px4_platform_common/board_common.h | 32 +++++++++++++++++++ .../common/include/px4_platform_common/spi.h | 6 +++- platforms/common/spi.cpp | 26 ++++++++++++--- .../px4_platform/board_determine_hw_info.h | 4 +++ src/lib/version/version.h | 10 ++++++ 5 files changed, 72 insertions(+), 6 deletions(-) diff --git a/platforms/common/include/px4_platform_common/board_common.h b/platforms/common/include/px4_platform_common/board_common.h index 7a6af777c4..90bc82b3f2 100644 --- a/platforms/common/include/px4_platform_common/board_common.h +++ b/platforms/common/include/px4_platform_common/board_common.h @@ -265,6 +265,18 @@ # define HW_VER_REV(v,r) ((uint32_t)((v) & 0xffff) << 16) | ((uint32_t)(r) & 0xffff) #endif +#if defined(BOARD_HAS_HW_SPLIT_VERSIONING) +typedef uint16_t hw_fmun_id_t; +typedef uint16_t hw_base_id_t; +// Original Signals GPIO_HW_REV_SENSE/GPIO_HW_VER_REV_DRIVE is used to ID the FMUM +// Original Signals GPIO_HW_VER_SENSE/GPIO_HW_VER_REV_DRIVE is used to ID the BASE +# define BOARD_HAS_VERSIONING 1 +# define HW_FMUM_ID(rev) ((hw_fmun_id_t)(rev) & 0xffff) +# define HW_BASE_ID(ver) ((hw_base_id_t)(ver) & 0xffff) +# define GET_HW_FMUM_ID() (HW_FMUM_ID(board_get_hw_revision())) +# define GET_HW_BASE_ID() (HW_BASE_ID(board_get_hw_version())) +#endif + #define HW_INFO_REV_DIGITS 3 #define HW_INFO_VER_DIGITS 3 @@ -752,6 +764,26 @@ __EXPORT const char *board_get_hw_type_name(void); #define board_get_hw_type_name() "" #endif +/************************************************************************************ + * Name: board_get_hw_base_type_name + * + * Description: + * Optional returns a 0 terminated string defining the HW type. + * + * Input Parameters: + * None + * + * Returned Value: + * a 0 terminated string defining the HW type. This may be a 0 length string "" + * + ************************************************************************************/ + +#if defined(BOARD_HAS_HW_SPLIT_VERSIONING) +__EXPORT const char *board_get_hw_base_type_name(void); +#else +#define board_get_hw_base_type_name() "" +#endif + /************************************************************************************ * Name: board_get_hw_version * diff --git a/platforms/common/include/px4_platform_common/spi.h b/platforms/common/include/px4_platform_common/spi.h index 6664409822..a2e4682b98 100644 --- a/platforms/common/include/px4_platform_common/spi.h +++ b/platforms/common/include/px4_platform_common/spi.h @@ -73,7 +73,11 @@ struct px4_spi_bus_t { struct px4_spi_bus_all_hw_t { px4_spi_bus_t buses[SPI_BUS_MAX_BUS_ITEMS]; - int board_hw_version_revision{-1}; ///< 0=default, >0 for a specific revision (see board_get_hw_version & board_get_hw_revision), -1=unused +#if defined(BOARD_HAS_HW_SPLIT_VERSIONING) + hw_fmun_id_t board_hw_fmun_id {USHRT_MAX}; +#else + int board_hw_version_revision {-1}; ///< 0=default, >0 for a specific revision (see board_get_hw_version & board_get_hw_revision), -1=unused +#endif }; #if BOARD_NUM_SPI_CFG_HW_VERSIONS > 1 diff --git a/platforms/common/spi.cpp b/platforms/common/spi.cpp index 62713b0798..6a29a100b2 100644 --- a/platforms/common/spi.cpp +++ b/platforms/common/spi.cpp @@ -44,12 +44,26 @@ #if BOARD_NUM_SPI_CFG_HW_VERSIONS > 1 void px4_set_spi_buses_from_hw_version() { -#if defined(BOARD_HAS_SIMPLE_HW_VERSIONING) - int hw_version_revision = board_get_hw_version(); -#else - int hw_version_revision = HW_VER_REV(board_get_hw_version(), board_get_hw_revision()); -#endif +# if defined(BOARD_HAS_HW_SPLIT_VERSIONING) + int hw_fmun_id = GET_HW_FMUM_ID(); + for (int i = 0; i < BOARD_NUM_SPI_CFG_HW_VERSIONS; ++i) { + if (!px4_spi_buses && px4_spi_buses_all_hw[i].board_hw_fmun_id == 0) { + px4_spi_buses = px4_spi_buses_all_hw[i].buses; + } + + if (px4_spi_buses_all_hw[i].board_hw_fmun_id == hw_fmun_id) { + px4_spi_buses = px4_spi_buses_all_hw[i].buses; + } + } + +# else + +# if defined(BOARD_HAS_SIMPLE_HW_VERSIONING) + int hw_version_revision = board_get_hw_version(); +# else + int hw_version_revision = HW_VER_REV(board_get_hw_version(), board_get_hw_revision()); +# endif for (int i = 0; i < BOARD_NUM_SPI_CFG_HW_VERSIONS; ++i) { if (!px4_spi_buses && px4_spi_buses_all_hw[i].board_hw_version_revision == 0) { @@ -61,6 +75,8 @@ void px4_set_spi_buses_from_hw_version() } } +# endif + if (!px4_spi_buses) { // fallback px4_spi_buses = px4_spi_buses_all_hw[0].buses; } diff --git a/platforms/nuttx/src/px4/common/include/px4_platform/board_determine_hw_info.h b/platforms/nuttx/src/px4/common/include/px4_platform/board_determine_hw_info.h index 95e99ffd46..b0864d45c0 100644 --- a/platforms/nuttx/src/px4/common/include/px4_platform/board_determine_hw_info.h +++ b/platforms/nuttx/src/px4/common/include/px4_platform/board_determine_hw_info.h @@ -36,6 +36,10 @@ __BEGIN_DECLS #define HW_INFO_SUFFIX "%0" STRINGIFY(HW_INFO_VER_DIGITS) "x%0" STRINGIFY(HW_INFO_REV_DIGITS) "x" +#if defined(BOARD_HAS_HW_SPLIT_VERSIONING) +# define HW_INFO_FMUM_SUFFIX "%0" STRINGIFY(HW_INFO_REV_DIGITS) "x" +# define HW_INFO_BASE_SUFFIX "%0" STRINGIFY(HW_INFO_VER_DIGITS) "x" +#endif /************************************************************************************ * Name: board_determine_hw_info * diff --git a/src/lib/version/version.h b/src/lib/version/version.h index ef2d9b5f09..dc11e7cb02 100644 --- a/src/lib/version/version.h +++ b/src/lib/version/version.h @@ -88,6 +88,16 @@ static inline int px4_board_hw_revision(void) return board_get_hw_revision(); } +#if defined(BOARD_HAS_HW_SPLIT_VERSIONING) +/** + * get the base board type + */ +static inline const char *px4_board_base_type(void) +{ + return board_get_hw_base_type_name(); +} +#endif + /** * get the build URI (used for crash logging) */