mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-28 19:32:36 +08:00
Merge PR #19575 (changes to pr-extendend_hw_ver_rev_format)
- 4096 of 3 hex digits each for rev and ver is enough.
#defines used in SPI versions do not be long format, use use the macro
- Board provides a prefix and the formatting is sized and built in
- No need for funky board_get_base_eeprom_mtd_manifest interface
Original mft is used where the abstraction is done with the MFT interface
Co-authored-by: David Sidrane <David.Sidrane@Nscdg.com>
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
@@ -71,6 +71,7 @@ __BEGIN_DECLS
|
||||
* Function for writing hardware info to EEPROM
|
||||
*
|
||||
* Input Parameters:
|
||||
* *path - path to mtd_mft
|
||||
* *mtd_mft_unk - pointer to mtd_mft to write hw_info
|
||||
*
|
||||
* Returned Value:
|
||||
@@ -80,9 +81,9 @@ __BEGIN_DECLS
|
||||
************************************************************************************/
|
||||
|
||||
#if !defined(BOARD_HAS_SIMPLE_HW_VERSIONING) && defined(BOARD_HAS_VERSIONING)
|
||||
__EXPORT int board_set_eeprom_hw_info(mtd_mft_t *mtd_mft_unk);
|
||||
__EXPORT int board_set_eeprom_hw_info(const char *path, mtd_mft_t *mtd_mft_unk);
|
||||
#else
|
||||
static inline int board_set_eeprom_hw_info(mtd_mft_t *mtd_mft_unk) { return -ENOSYS; }
|
||||
static inline int board_set_eeprom_hw_info(const char *path, mtd_mft_t *mtd_mft_unk) { return -ENOSYS; }
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
@@ -101,9 +102,9 @@ static inline int board_set_eeprom_hw_info(mtd_mft_t *mtd_mft_unk) { return -ENO
|
||||
************************************************************************************/
|
||||
|
||||
#if !defined(BOARD_HAS_SIMPLE_HW_VERSIONING) && defined(BOARD_HAS_VERSIONING)
|
||||
__EXPORT int board_get_eeprom_hw_info(mtd_mft_t *mtd_mft);
|
||||
__EXPORT int board_get_eeprom_hw_info(const char *path, mtd_mft_t *mtd_mft);
|
||||
#else
|
||||
static inline int board_get_eeprom_hw_info(mtd_mft_t *mtd_mft) { return -ENOSYS; }
|
||||
static inline int board_get_eeprom_hw_info(const char *path, mtd_mft_t *mtd_mft) { return -ENOSYS; }
|
||||
#endif
|
||||
|
||||
__END_DECLS
|
||||
|
||||
@@ -100,7 +100,7 @@ __EXPORT int px4_mft_query(const px4_mft_s *mft, px4_manifest_types_e type,
|
||||
if (mft->mfts[m]->type == type)
|
||||
switch (type) {
|
||||
case MTD:
|
||||
return px4_mtd_query(sub, val);
|
||||
return px4_mtd_query(sub, val, nullptr);
|
||||
break;
|
||||
|
||||
case MFT:
|
||||
|
||||
@@ -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
|
||||
@@ -53,7 +53,8 @@
|
||||
# define GPIO_HW_VER_DRIVE GPIO_HW_VER_REV_DRIVE
|
||||
# endif
|
||||
|
||||
#define HW_INFO_SIZE 20 //<! Size to fit hw_info string
|
||||
#define HW_INFO_SIZE (int) arraySize(HW_INFO_INIT_PREFIX) + HW_INFO_VER_DIGITS + HW_INFO_REV_DIGITS
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
@@ -196,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) */
|
||||
@@ -207,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;
|
||||
}
|
||||
@@ -344,12 +345,8 @@ int board_determine_hw_info()
|
||||
|
||||
if (rv == OK) {
|
||||
|
||||
int hw_info_size = snprintf(hw_info, HW_INFO_SIZE, HW_INFO_INIT, hw_version, hw_revision);
|
||||
snprintf(hw_info, sizeof(hw_info), HW_INFO_INIT_PREFIX HW_INFO_SUFFIX, hw_version, hw_revision);
|
||||
|
||||
if ((hw_info_size < 0) || (hw_info_size >= HW_INFO_SIZE)) {
|
||||
printf("[boot] Error, hw_info string hasn't been completely written\n");
|
||||
rv = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -41,6 +41,7 @@
|
||||
#include <px4_arch/adc.h>
|
||||
#include <px4_platform_common/micro_hal.h>
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
#include <px4_platform_common/px4_manifest.h>
|
||||
#include <px4_platform/board_determine_hw_info.h>
|
||||
#include <px4_platform/board_hw_eeprom_rev_ver.h>
|
||||
#include <stdio.h>
|
||||
@@ -57,7 +58,8 @@
|
||||
# define GPIO_HW_VER_DRIVE GPIO_HW_VER_REV_DRIVE
|
||||
# endif
|
||||
|
||||
#define HW_INFO_SIZE 20 //<! Size to fit hw_info string
|
||||
#define HW_INFO_SIZE (int) arraySize(HW_INFO_INIT_PREFIX) + HW_INFO_VER_DIGITS + HW_INFO_REV_DIGITS
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
@@ -66,8 +68,6 @@ static int hw_version = 0;
|
||||
static int hw_revision = 0;
|
||||
static char hw_info[HW_INFO_SIZE] = {0};
|
||||
|
||||
static const char *mtd_mft_path = "/fs/mtd_mft";
|
||||
|
||||
/****************************************************************************
|
||||
* Protected Functions
|
||||
****************************************************************************/
|
||||
@@ -445,16 +445,19 @@ __EXPORT int board_get_hw_revision()
|
||||
|
||||
int board_determine_hw_info()
|
||||
{
|
||||
// ADC hw version range: {0x1 - 0xF}
|
||||
// MFT supported?
|
||||
const char *path;
|
||||
int rvmft = px4_mtd_query("MTD_MFT", NULL, &path);
|
||||
|
||||
// Read ADC jumpering hw_info
|
||||
int rv = determine_hw_info(&hw_revision, &hw_version);
|
||||
|
||||
if (rv == OK) {
|
||||
|
||||
/* EEPROM hw version range: {0x10 - 0xFFFF} */
|
||||
if (hw_version == HW_VERSION_EEPROM) {
|
||||
if (rvmft == OK && path != NULL && hw_version == HW_VERSION_EEPROM) {
|
||||
|
||||
mtd_mft_v0_t mtd_mft = {MTD_MFT_v0};
|
||||
rv = board_get_eeprom_hw_info((mtd_mft_t *)&mtd_mft);
|
||||
rv = board_get_eeprom_hw_info(path, (mtd_mft_t *)&mtd_mft);
|
||||
|
||||
if (rv == OK) {
|
||||
hw_version = mtd_mft.hw_extended_ver;
|
||||
@@ -463,13 +466,7 @@ int board_determine_hw_info()
|
||||
}
|
||||
|
||||
if (rv == OK) {
|
||||
|
||||
int hw_info_size = snprintf(hw_info, HW_INFO_SIZE, HW_INFO_INIT, hw_version, hw_revision);
|
||||
|
||||
if ((hw_info_size < 0) || (hw_info_size >= HW_INFO_SIZE)) {
|
||||
printf("[boot] Error, hw_info string hasn't been completely written\n");
|
||||
rv = -1;
|
||||
}
|
||||
snprintf(hw_info, sizeof(hw_info), HW_INFO_INIT_PREFIX HW_INFO_SUFFIX, hw_version, hw_revision);
|
||||
}
|
||||
|
||||
return rv;
|
||||
@@ -490,10 +487,10 @@ int board_determine_hw_info()
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
int board_set_eeprom_hw_info(mtd_mft_t *mtd_mft_unk)
|
||||
int board_set_eeprom_hw_info(const char *path, mtd_mft_t *mtd_mft_unk)
|
||||
{
|
||||
if (mtd_mft_unk == NULL) {
|
||||
return -1;
|
||||
if (mtd_mft_unk == NULL || path == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
// Later this will be a demux on type
|
||||
@@ -509,7 +506,7 @@ int board_set_eeprom_hw_info(mtd_mft_t *mtd_mft_unk)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
int fd = open(mtd_mft_path, O_WRONLY);
|
||||
int fd = open(path, O_WRONLY);
|
||||
|
||||
if (fd < 0) {
|
||||
return -errno;
|
||||
@@ -545,13 +542,13 @@ int board_set_eeprom_hw_info(mtd_mft_t *mtd_mft_unk)
|
||||
* -1 - Error while reading from EEPROM
|
||||
*
|
||||
************************************************************************************/
|
||||
__EXPORT int board_get_eeprom_hw_info(mtd_mft_t *mtd_mft)
|
||||
__EXPORT int board_get_eeprom_hw_info(const char *path, mtd_mft_t *mtd_mft)
|
||||
{
|
||||
if (mtd_mft == NULL) {
|
||||
if (mtd_mft == NULL || path == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
int fd = open(mtd_mft_path, O_RDONLY);
|
||||
int fd = open(path, O_RDONLY);
|
||||
|
||||
if (fd < 0) {
|
||||
return -errno;
|
||||
|
||||
Reference in New Issue
Block a user