board_hw_info: update id string from V5X{0-a}{0-a} to V5X{xxx}{xxx}

This commit is contained in:
Igor Mišić
2022-05-03 12:10:16 -07:00
committed by David Sidrane
parent ac497e21c6
commit d9df4db473
19 changed files with 68 additions and 57 deletions
@@ -32,9 +32,10 @@
****************************************************************************/
#pragma once
#include "micro_hal.h"
__BEGIN_DECLS
#define HW_INFO_SUFFIX "%0" STRINGIFY(HW_INFO_VER_DIGITS) "x%0" STRINGIFY(HW_INFO_REV_DIGITS) "x"
/************************************************************************************
* Name: board_determine_hw_info
*
@@ -44,7 +44,7 @@
static int hw_version = 0;
static int hw_revision = 0;
static char hw_info[] = HW_INFO_INIT;
static char hw_info[] = HW_INFO_INIT_PREFIX HW_INFO_SUFFIX;
__EXPORT const char *board_get_hw_type_name(void)
{
@@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (C) 2019 PX4 Development Team. All rights reserved.
* Copyright (C) 2019, 2022 PX4 Development Team. All rights reserved.
* Author: @author David Sidrane <david_s5@nscdg.com>
*
* Redistribution and use in source and binary forms, with or without
@@ -52,12 +52,16 @@
# define GPIO_HW_REV_DRIVE GPIO_HW_VER_REV_DRIVE
# define GPIO_HW_VER_DRIVE GPIO_HW_VER_REV_DRIVE
# endif
#define HW_INFO_SIZE (int) arraySize(HW_INFO_INIT_PREFIX) + HW_INFO_VER_DIGITS + HW_INFO_REV_DIGITS
/****************************************************************************
* Private Data
****************************************************************************/
static int hw_version = 0;
static int hw_revision = 0;
static char hw_info[] = HW_INFO_INIT;
static char hw_info[HW_INFO_SIZE] = {0};
/****************************************************************************
* Protected Functions
@@ -193,7 +197,7 @@ static int read_id_dn(int *id, uint32_t gpio_drive, uint32_t gpio_sense, int adc
/* Are Resistors in place ?*/
uint32_t dn_sum = 0;
uint16_t dn = 0;
uint32_t dn = 0;
if ((high ^ low) && low == 0) {
/* Yes - Fire up the ADC (it has once control) */
@@ -204,14 +208,14 @@ static int read_id_dn(int *id, uint32_t gpio_drive, uint32_t gpio_sense, int adc
for (unsigned av = 0; av < samples; av++) {
dn = px4_arch_adc_sample(HW_REV_VER_ADC_BASE, adc_channel);
if (dn == 0xffff) {
if (dn == UINT32_MAX) {
break;
}
dn_sum += dn;
}
if (dn != 0xffff) {
if (dn != UINT32_MAX) {
*id = dn_sum / samples;
rv = OK;
}
@@ -338,8 +342,12 @@ int board_determine_hw_info()
int rv = determine_hw_info(&hw_revision, &hw_version);
if (rv == OK) {
hw_info[HW_INFO_INIT_REV] = board_get_hw_revision() + '0';
hw_info[HW_INFO_INIT_VER] = board_get_hw_version() + '0';
if (rv == OK) {
snprintf(hw_info, sizeof(hw_info), HW_INFO_INIT_PREFIX HW_INFO_SUFFIX, hw_version, hw_revision);
}
}
return rv;
@@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (C) 2017 PX4 Development Team. All rights reserved.
* Copyright (C) 2017, 2022 PX4 Development Team. All rights reserved.
* Author: @author David Sidrane <david_s5@nscdg.com>
*
* Redistribution and use in source and binary forms, with or without
@@ -56,12 +56,16 @@
# define GPIO_HW_REV_DRIVE GPIO_HW_VER_REV_DRIVE
# define GPIO_HW_VER_DRIVE GPIO_HW_VER_REV_DRIVE
# endif
#define HW_INFO_SIZE (int) arraySize(HW_INFO_INIT_PREFIX) + HW_INFO_VER_DIGITS + HW_INFO_REV_DIGITS
/****************************************************************************
* Private Data
****************************************************************************/
static int hw_version = 0;
static int hw_revision = 0;
static char hw_info[] = HW_INFO_INIT;
static char hw_info[HW_INFO_SIZE] = {0};
static const uint16_t mtd_mft_version = MTD_MFT_v0; //< Current version of structure in EEPROM
static const char *mtd_mft_path = "/fs/mtd_mft";
@@ -443,16 +447,25 @@ __EXPORT int board_get_hw_revision()
int board_determine_hw_info()
{
// ADC hw version range: {0x1 - 0xF}
int rv = determine_hw_info(&hw_revision, &hw_version);
if (rv == OK) {
hw_info[HW_INFO_INIT_REV] = board_get_hw_revision() < 10 ?
board_get_hw_revision() + '0' :
board_get_hw_revision() + 'a' - 10;
hw_info[HW_INFO_INIT_VER] = board_get_hw_version() < 10 ?
board_get_hw_version() + '0' :
board_get_hw_version() + 'a' - 10;
/* EEPROM hw version range: {0x10 - 0xFFFF} */
if (hw_version == HW_VERSION_EEPROM) {
mtd_mft_t mtd_mft;
rv = board_get_eeprom_hw_info(&mtd_mft);
if (rv == OK) {
hw_version = mtd_mft.hw_extended_ver;
}
}
}
if (rv == OK) {
snprintf(hw_info, sizeof(hw_info), HW_INFO_INIT_PREFIX HW_INFO_SUFFIX, hw_version, hw_revision);
}
return rv;