diff --git a/src/drivers/boards/aerocore/CMakeLists.txt b/src/drivers/boards/aerocore/CMakeLists.txt index 2933d7d016..aa5701c396 100644 --- a/src/drivers/boards/aerocore/CMakeLists.txt +++ b/src/drivers/boards/aerocore/CMakeLists.txt @@ -34,7 +34,6 @@ px4_add_module( MODULE drivers__boards__aerocore COMPILE_FLAGS SRCS - ../common/board_name.c ../common/board_dma_alloc.c aerocore_init.c aerocore_timer_config.c diff --git a/src/drivers/boards/aerofc-v1/CMakeLists.txt b/src/drivers/boards/aerofc-v1/CMakeLists.txt index de093bbe97..409c5b1e72 100644 --- a/src/drivers/boards/aerofc-v1/CMakeLists.txt +++ b/src/drivers/boards/aerofc-v1/CMakeLists.txt @@ -35,7 +35,6 @@ px4_add_module( MODULE drivers__boards__aerofc-v1 COMPILE_FLAGS SRCS - ../common/board_name.c aerofc_init.c aerofc_spi.c aerofc_usb.c diff --git a/src/drivers/boards/auav-x21/CMakeLists.txt b/src/drivers/boards/auav-x21/CMakeLists.txt index f328679715..bce1a0c327 100644 --- a/src/drivers/boards/auav-x21/CMakeLists.txt +++ b/src/drivers/boards/auav-x21/CMakeLists.txt @@ -34,7 +34,6 @@ px4_add_module( MODULE drivers__boards__auav-x21 COMPILE_FLAGS SRCS - ../common/board_name.c ../common/board_dma_alloc.c auav_can.c auav_init.c diff --git a/src/drivers/boards/common/board_common.h b/src/drivers/boards/common/board_common.h index c35b7c5c61..61f1d4c832 100644 --- a/src/drivers/boards/common/board_common.h +++ b/src/drivers/boards/common/board_common.h @@ -100,16 +100,6 @@ * Public Functions ************************************************************************************/ -/************************************************************************************ - * Name: board_name - * - * Description: - * All boards must provide this API to return the board name. - * - ************************************************************************************/ - -__EXPORT const char *board_name(void); - /************************************************************************************ * Name: board_dma_alloc_init * diff --git a/src/drivers/boards/common/board_name.c b/src/drivers/boards/common/board_name.c deleted file mode 100644 index 8108cec4aa..0000000000 --- a/src/drivers/boards/common/board_name.c +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2016 PX4 Development Team. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name PX4 nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/** - * @file board_name.c - * - * Provide the board_name interface. - */ - -/************************************************************************************ - * Included Files - ************************************************************************************/ - -#include -#include "board_config.h" -#include - -/************************************************************************************ - * Definitions - ************************************************************************************/ - -/************************************************************************************ - * Private Functions - ************************************************************************************/ - -/************************************************************************************ - * Public Functions - ************************************************************************************/ - -/************************************************************************************ - * Name: board_name - * - * Description: - * All boards must provide this API to return the board name. - * - ************************************************************************************/ - -__EXPORT const char *board_name() -{ - return BOARD_NAME; -} diff --git a/src/drivers/boards/crazyflie/CMakeLists.txt b/src/drivers/boards/crazyflie/CMakeLists.txt index d677d46ae7..1b2a7533bc 100644 --- a/src/drivers/boards/crazyflie/CMakeLists.txt +++ b/src/drivers/boards/crazyflie/CMakeLists.txt @@ -33,7 +33,6 @@ px4_add_module( MODULE drivers__boards__crazyflie SRCS - ../common/board_name.c ../common/board_dma_alloc.c crazyflie_init.c crazyflie_usb.c diff --git a/src/drivers/boards/mindpx-v2/CMakeLists.txt b/src/drivers/boards/mindpx-v2/CMakeLists.txt index 61e380a207..25f0de9ead 100644 --- a/src/drivers/boards/mindpx-v2/CMakeLists.txt +++ b/src/drivers/boards/mindpx-v2/CMakeLists.txt @@ -35,7 +35,6 @@ px4_add_module( COMPILE_FLAGS SRCS ../common/board_dma_alloc.c - ../common/board_name.c mindpx_can.c mindpx2_init.c mindpx_timer_config.c diff --git a/src/drivers/boards/px4-stm32f4discovery/CMakeLists.txt b/src/drivers/boards/px4-stm32f4discovery/CMakeLists.txt index ee75158403..e4af694e5d 100644 --- a/src/drivers/boards/px4-stm32f4discovery/CMakeLists.txt +++ b/src/drivers/boards/px4-stm32f4discovery/CMakeLists.txt @@ -33,7 +33,6 @@ px4_add_module( MODULE drivers__boards__px4-stm32f4discovery SRCS - ../common/board_name.c px4discovery_init.c px4discovery_usb.c px4discovery_led.c diff --git a/src/drivers/boards/px4fmu-v1/CMakeLists.txt b/src/drivers/boards/px4fmu-v1/CMakeLists.txt index 05cca55e41..a06a1fc701 100644 --- a/src/drivers/boards/px4fmu-v1/CMakeLists.txt +++ b/src/drivers/boards/px4fmu-v1/CMakeLists.txt @@ -34,7 +34,6 @@ px4_add_module( MODULE drivers__boards__px4fmu-v1 COMPILE_FLAGS SRCS - ../common/board_name.c px4fmu_can.c px4fmu_init.c px4fmu_timer_config.c diff --git a/src/drivers/boards/px4fmu-v2/CMakeLists.txt b/src/drivers/boards/px4fmu-v2/CMakeLists.txt index e597a786cb..2d7a50354a 100644 --- a/src/drivers/boards/px4fmu-v2/CMakeLists.txt +++ b/src/drivers/boards/px4fmu-v2/CMakeLists.txt @@ -34,7 +34,6 @@ px4_add_module( MODULE drivers__boards__px4fmu-v2 COMPILE_FLAGS SRCS - ../common/board_name.c ../common/board_dma_alloc.c px4fmu_can.c px4fmu2_init.c diff --git a/src/drivers/boards/px4fmu-v4/CMakeLists.txt b/src/drivers/boards/px4fmu-v4/CMakeLists.txt index f90f833a56..6ad5e86bb1 100644 --- a/src/drivers/boards/px4fmu-v4/CMakeLists.txt +++ b/src/drivers/boards/px4fmu-v4/CMakeLists.txt @@ -34,7 +34,6 @@ px4_add_module( MODULE drivers__boards__px4fmu-v4 COMPILE_FLAGS SRCS - ../common/board_name.c ../common/board_dma_alloc.c px4fmu_can.c px4fmu_init.c diff --git a/src/drivers/boards/tap-v1/CMakeLists.txt b/src/drivers/boards/tap-v1/CMakeLists.txt index ae10ac451b..c117a22ed8 100644 --- a/src/drivers/boards/tap-v1/CMakeLists.txt +++ b/src/drivers/boards/tap-v1/CMakeLists.txt @@ -35,7 +35,6 @@ px4_add_module( MODULE drivers__boards__tap-v1 COMPILE_FLAGS SRCS - ../common/board_name.c ../common/board_dma_alloc.c tap_init.c tap_pwr.c diff --git a/src/lib/version/version.h b/src/lib/version/version.h index e4a0c839a8..4d23e5ade6 100644 --- a/src/lib/version/version.h +++ b/src/lib/version/version.h @@ -40,36 +40,46 @@ * @author Anton Babushkin */ -#ifndef VERSION_H_ -#define VERSION_H_ +#pragma once -/* The preferred method for publishing a board name up is to - * provide board_name() - * - */ -__BEGIN_DECLS - -__EXPORT const char *board_name(void); - -__END_DECLS #define FREEZE_STR(s) #s #define STRINGIFY(s) FREEZE_STR(s) #define FW_GIT STRINGIFY(GIT_VERSION) #define FW_BUILD_URI STRINGIFY(BUILD_URI) +/* The preferred method for publishing a board name is to + * define it in board_config.h as BOARD_NAME + */ #if defined(CONFIG_ARCH_BOARD_SITL) -# define HW_ARCH "SITL" +# define BOARD_NAME "SITL" #elif defined(CONFIG_ARCH_BOARD_EAGLE) -# define HW_ARCH "EAGLE" +# define BOARD_NAME "EAGLE" #elif defined(CONFIG_ARCH_BOARD_EXCELSIOR) -# define HW_ARCH "EXCELSIOR" +# define BOARD_NAME "EXCELSIOR" #elif defined(CONFIG_ARCH_BOARD_RPI) -# define HW_ARCH "RPI" +# define BOARD_NAME "RPI" #elif defined(CONFIG_ARCH_BOARD_BEBOP) -# define HW_ARCH "BEBOP" +# define BOARD_NAME "BEBOP" #else -#define HW_ARCH (board_name()) +# include "board_config.h" +# ifndef BOARD_NAME +# error "board_config.h must define BOARD_NAME" +# endif #endif -#endif /* VERSION_H_ */ + +__BEGIN_DECLS + +/** + * get the board name as string (including the version if there are multiple) + */ +static inline const char *px4_board_name(void) +{ + return BOARD_NAME; +} + + + +__END_DECLS + diff --git a/src/modules/logger/logger.cpp b/src/modules/logger/logger.cpp index efd3e1ac1d..aa9a6c398b 100644 --- a/src/modules/logger/logger.cpp +++ b/src/modules/logger/logger.cpp @@ -57,6 +57,7 @@ #include #include #include +#include #ifdef __PX4_DARWIN #include @@ -1361,7 +1362,7 @@ void Logger::write_header() void Logger::write_version() { write_info("ver_sw", PX4_GIT_VERSION_STR); - write_info("ver_hw", HW_ARCH); + write_info("ver_hw", px4_board_name()); write_info("sys_name", "PX4"); int32_t utc_offset = 0; diff --git a/src/modules/sdlog2/sdlog2.c b/src/modules/sdlog2/sdlog2.c index 358d5e124f..a1df573ae7 100644 --- a/src/modules/sdlog2/sdlog2.c +++ b/src/modules/sdlog2/sdlog2.c @@ -874,7 +874,7 @@ int write_version(int fd) /* fill version message and write it */ strncpy(log_msg_VER.body.fw_git, px4_git_version, sizeof(log_msg_VER.body.fw_git)); - strncpy(log_msg_VER.body.arch, HW_ARCH, sizeof(log_msg_VER.body.arch)); + strncpy(log_msg_VER.body.arch, px4_board_name(), sizeof(log_msg_VER.body.arch)); return write(fd, &log_msg_VER, sizeof(log_msg_VER)); } diff --git a/src/modules/uavcan/uavcan_main.cpp b/src/modules/uavcan/uavcan_main.cpp index 7816a3125f..a776179b1a 100644 --- a/src/modules/uavcan/uavcan_main.cpp +++ b/src/modules/uavcan/uavcan_main.cpp @@ -183,14 +183,14 @@ int UavcanNode::getHardwareVersion(uavcan::protocol::HardwareVersion &hwver) int rv = -1; if (UavcanNode::instance()) { - if (!std::strncmp(HW_ARCH, "PX4FMU_V1", 9)) { + if (!std::strncmp(px4_board_name(), "PX4FMU_V1", 9)) { hwver.major = 1; - } else if (!std::strncmp(HW_ARCH, "PX4FMU_V2", 9)) { + } else if (!std::strncmp(px4_board_name(), "PX4FMU_V2", 9)) { hwver.major = 2; } else { - ; // All other values of HW_ARCH resolve to zero + ; // All other values of px4_board_name() resolve to zero } uint8_t udid[12] = {}; // Someone seems to love magic numbers diff --git a/src/systemcmds/ver/ver.c b/src/systemcmds/ver/ver.c index e1cf703618..4894c35c5d 100644 --- a/src/systemcmds/ver/ver.c +++ b/src/systemcmds/ver/ver.c @@ -198,11 +198,12 @@ int ver_main(int argc, char *argv[]) if (!strncmp(argv[1], sz_ver_hwcmp_str, sizeof(sz_ver_hwcmp_str))) { if (argc >= 3 && argv[2] != NULL) { - /* compare 3rd parameter with HW_ARCH string, in case of match, return 0 */ - ret = strncmp(HW_ARCH, argv[2], strlen(HW_ARCH)); + /* compare 3rd parameter with px4_board_name() string, in case of match, return 0 */ + const char *board_name = px4_board_name(); + ret = strncmp(board_name, argv[2], strlen(board_name)); if (ret == 0) { - PX4_INFO("match: %s", HW_ARCH); + PX4_INFO("match: %s", board_name); } return ret; @@ -217,7 +218,7 @@ int ver_main(int argc, char *argv[]) bool show_all = !strncmp(argv[1], sz_ver_all_str, sizeof(sz_ver_all_str)); if (show_all || !strncmp(argv[1], sz_ver_hw_str, sizeof(sz_ver_hw_str))) { - printf("HW arch: %s\n", HW_ARCH); + printf("HW arch: %s\n", px4_board_name()); ret = 0; }