mtd: add support for extended HW revision

This commit is contained in:
Igor Mišić
2022-11-07 17:26:14 +01:00
committed by Beat Küng
parent 855eb42c59
commit 815eed2c6d
8 changed files with 71 additions and 34 deletions
+9 -4
View File
@@ -71,8 +71,8 @@ static const px4_mtd_entry_t base_eeprom = {
.npart = 2, .npart = 2,
.partd = { .partd = {
{ {
.type = MTD_MFT, .type = MTD_MFT_VER,
.path = "/fs/mtd_mft", .path = "/fs/mtd_mft_ver",
.nblocks = 248 .nblocks = 248
}, },
{ {
@@ -86,12 +86,17 @@ static const px4_mtd_entry_t base_eeprom = {
static const px4_mtd_entry_t imu_eeprom = { static const px4_mtd_entry_t imu_eeprom = {
.device = &i2c4, .device = &i2c4,
.npart = 2, .npart = 3,
.partd = { .partd = {
{ {
.type = MTD_CALDATA, .type = MTD_CALDATA,
.path = "/fs/mtd_caldata", .path = "/fs/mtd_caldata",
.nblocks = 248 .nblocks = 240
},
{
.type = MTD_MFT_REV,
.path = "/fs/mtd_mft_rev",
.nblocks = 8
}, },
{ {
.type = MTD_ID, .type = MTD_ID,
+9 -4
View File
@@ -71,8 +71,8 @@ static const px4_mtd_entry_t base_eeprom = {
.npart = 2, .npart = 2,
.partd = { .partd = {
{ {
.type = MTD_MFT, .type = MTD_MFT_VER,
.path = "/fs/mtd_mft", .path = "/fs/mtd_mft_ver",
.nblocks = 248 .nblocks = 248
}, },
{ {
@@ -86,12 +86,17 @@ static const px4_mtd_entry_t base_eeprom = {
static const px4_mtd_entry_t imu_eeprom = { static const px4_mtd_entry_t imu_eeprom = {
.device = &i2c4, .device = &i2c4,
.npart = 2, .npart = 3,
.partd = { .partd = {
{ {
.type = MTD_CALDATA, .type = MTD_CALDATA,
.path = "/fs/mtd_caldata", .path = "/fs/mtd_caldata",
.nblocks = 248 .nblocks = 240
},
{
.type = MTD_MFT_REV,
.path = "/fs/mtd_mft_rev",
.nblocks = 8
}, },
{ {
.type = MTD_ID, .type = MTD_ID,
+7 -2
View File
@@ -65,12 +65,17 @@ static const px4_mtd_entry_t fmum_fram = {
static const px4_mtd_entry_t imu_eeprom = { static const px4_mtd_entry_t imu_eeprom = {
.device = &i2c4, .device = &i2c4,
.npart = 2, .npart = 3,
.partd = { .partd = {
{ {
.type = MTD_CALDATA, .type = MTD_CALDATA,
.path = "/fs/mtd_caldata", .path = "/fs/mtd_caldata",
.nblocks = 248 .nblocks = 240
},
{
.type = MTD_MFT_REV,
.path = "/fs/mtd_mft_rev",
.nblocks = 8
}, },
{ {
.type = MTD_ID, .type = MTD_ID,
+9 -4
View File
@@ -71,8 +71,8 @@ static const px4_mtd_entry_t base_eeprom = {
.npart = 2, .npart = 2,
.partd = { .partd = {
{ {
.type = MTD_MFT, .type = MTD_MFT_VER,
.path = "/fs/mtd_mft", .path = "/fs/mtd_mft_ver",
.nblocks = 248 .nblocks = 248
}, },
{ {
@@ -86,12 +86,17 @@ static const px4_mtd_entry_t base_eeprom = {
static const px4_mtd_entry_t imu_eeprom = { static const px4_mtd_entry_t imu_eeprom = {
.device = &i2c4, .device = &i2c4,
.npart = 2, .npart = 3,
.partd = { .partd = {
{ {
.type = MTD_CALDATA, .type = MTD_CALDATA,
.path = "/fs/mtd_caldata", .path = "/fs/mtd_caldata",
.nblocks = 248 .nblocks = 240
},
{
.type = MTD_MFT_REV,
.path = "/fs/mtd_mft_rev",
.nblocks = 8
}, },
{ {
.type = MTD_ID, .type = MTD_ID,
@@ -66,8 +66,8 @@ static const px4_mtd_entry_t base_eeprom = {
.npart = 2, .npart = 2,
.partd = { .partd = {
{ {
.type = MTD_MFT, .type = MTD_MFT_VER,
.path = "/fs/mtd_mft", .path = "/fs/mtd_mft_ver",
.nblocks = 248 .nblocks = 248
}, },
{ {
@@ -37,12 +37,13 @@ typedef enum {
MTD_PARAMETERS = 1, MTD_PARAMETERS = 1,
MTD_WAYPOINTS = 2, MTD_WAYPOINTS = 2,
MTD_CALDATA = 3, MTD_CALDATA = 3,
MTD_MFT = 4, MTD_MFT_VER = 4,
MTD_ID = 5, MTD_MFT_REV = 5,
MTD_NET = 6, MTD_ID = 6,
MTD_NET = 7
} px4_mtd_types_t; } px4_mtd_types_t;
#define PX4_MFT_MTD_TYPES {MTD_PARAMETERS, MTD_WAYPOINTS, MTD_CALDATA, MTD_MFT, MTD_ID, MTD_NET} #define PX4_MFT_MTD_TYPES {MTD_PARAMETERS, MTD_WAYPOINTS, MTD_CALDATA, MTD_MFT_VER, MTD_MFT_REV, MTD_ID, MTD_NET}
#define PX4_MFT_MTD_STR_TYPES {"MTD_PARAMETERS", "MTD_WAYPOINTS", "MTD_CALDATA", "MTD_MFT", "MTD_ID", "MTD_NET"} #define PX4_MFT_MTD_STR_TYPES {"MTD_PARAMETERS", "MTD_WAYPOINTS", "MTD_CALDATA", "MTD_MFT_VER", "MTD_MFT_REV", "MTD_ID", "MTD_NET"}
typedef struct { typedef struct {
const px4_mtd_types_t type; const px4_mtd_types_t type;
@@ -32,8 +32,10 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#define HW_VERSION_EEPROM 0x7 //!< Get hw_info from EEPROM #include <errno.h>
#define HW_EEPROM_VERSION_MIN 0x10 //!< Minimum supported version
#define HW_ID_EEPROM 0x7 //!< Get hw_info from EEPROM
#define HW_EEPROM_ID_MIN 0x10 //!< Minimum supported id (version/revision)
#pragma pack(push, 1) #pragma pack(push, 1)
@@ -43,13 +45,13 @@ typedef struct {
typedef struct { typedef struct {
mtd_mft_t version; mtd_mft_t version;
uint16_t hw_extended_ver; uint16_t hw_extended_id; //<! HW version for MTD_MFT_VER, HW revision for MTD_MFT_REV
uint16_t crc; uint16_t crc;
} mtd_mft_v0_t; } mtd_mft_v0_t;
typedef struct { typedef struct {
mtd_mft_t version; mtd_mft_t version;
uint16_t hw_extended_ver; uint16_t hw_extended_id;
//{device tree overlay} //{device tree overlay}
uint16_t crc; uint16_t crc;
} mtd_mft_v1_t; } mtd_mft_v1_t;
@@ -445,22 +445,36 @@ __EXPORT int board_get_hw_revision()
int board_determine_hw_info() int board_determine_hw_info()
{ {
// MFT supported?
const char *path;
int rvmft = px4_mtd_query("MTD_MFT", NULL, &path);
// Read ADC jumpering hw_info // Read ADC jumpering hw_info
int rv = determine_hw_info(&hw_revision, &hw_version); int rv = determine_hw_info(&hw_revision, &hw_version);
if (rv == OK) { if (rv == OK) {
if (rvmft == OK && path != NULL && hw_version == HW_VERSION_EEPROM) { // MFT supported?
const char *path;
int rvmft = px4_mtd_query("MTD_MFT_VER", NULL, &path);
if (rvmft == OK && path != NULL && hw_version == HW_ID_EEPROM) {
mtd_mft_v0_t mtd_mft = {MTD_MFT_v0}; mtd_mft_v0_t mtd_mft = {MTD_MFT_v0};
rv = board_get_eeprom_hw_info(path, (mtd_mft_t *)&mtd_mft); rv = board_get_eeprom_hw_info(path, (mtd_mft_t *)&mtd_mft);
if (rv == OK) { if (rv == OK) {
hw_version = mtd_mft.hw_extended_ver; hw_version = mtd_mft.hw_extended_id;
}
}
path = NULL;
rvmft = px4_mtd_query("MTD_MFT_REV", NULL, &path);
if (rvmft == OK && path != NULL && hw_revision == HW_ID_EEPROM) {
mtd_mft_v0_t mtd_mft = {MTD_MFT_v0};
rv = board_get_eeprom_hw_info(path, (mtd_mft_t *)&mtd_mft);
if (rv == OK) {
hw_revision = mtd_mft.hw_extended_id;
} }
} }
} }
@@ -495,14 +509,14 @@ int board_set_eeprom_hw_info(const char *path, mtd_mft_t *mtd_mft_unk)
// Later this will be a demux on type // Later this will be a demux on type
if (mtd_mft_unk->id != MTD_MFT_v0) { if (mtd_mft_unk->id != MTD_MFT_v0) {
printf("Verson is: %d, Only mft version %d is supported\n", mtd_mft_unk->id, MTD_MFT_v0); printf("Version is: %d, Only mft version %d is supported\n", mtd_mft_unk->id, MTD_MFT_v0);
return -EINVAL; return -EINVAL;
} }
mtd_mft_v0_t *mtd_mft = (mtd_mft_v0_t *)mtd_mft_unk; mtd_mft_v0_t *mtd_mft = (mtd_mft_v0_t *)mtd_mft_unk;
if (mtd_mft->hw_extended_ver < HW_EEPROM_VERSION_MIN) { if (mtd_mft->hw_extended_id < HW_EEPROM_ID_MIN) {
printf("hardware version for EEPROM must be greater than %x\n", HW_EEPROM_VERSION_MIN); printf("hardware version for EEPROM must be greater than %x\n", HW_EEPROM_ID_MIN);
return -EINVAL; return -EINVAL;
} }