mirror of
https://github.com/peterantypas/maiana.git
synced 2025-06-01 07:10:33 -07:00
Persistence delegated to BSP again
This commit is contained in:
parent
66b9019f9f
commit
c0b7a7973b
26
latest/Firmware/Transponder/Inc/ConfigFlags.h
Normal file
26
latest/Firmware/Transponder/Inc/ConfigFlags.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* ConfigFlags.h
|
||||||
|
*
|
||||||
|
* Created on: Oct 11, 2021
|
||||||
|
* Author: peter
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef INC_CONFIGFLAGS_H_
|
||||||
|
#define INC_CONFIGFLAGS_H_
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t magic;
|
||||||
|
uint32_t reserved;
|
||||||
|
uint32_t flags[5];
|
||||||
|
} ConfigFlags;
|
||||||
|
|
||||||
|
typedef union
|
||||||
|
{
|
||||||
|
ConfigFlags config;
|
||||||
|
uint64_t dw[4];
|
||||||
|
} ConfigPage;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* INC_CONFIGFLAGS_H_ */
|
@ -23,27 +23,9 @@
|
|||||||
#include "StationData.h"
|
#include "StationData.h"
|
||||||
#include "OTPData.h"
|
#include "OTPData.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "ConfigFlags.h"
|
||||||
// This should be plenty big (no need to be a whole flash page though)
|
|
||||||
typedef union
|
|
||||||
{
|
|
||||||
StationData station;
|
|
||||||
uint64_t dw[128];
|
|
||||||
} StationDataPage;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
uint32_t magic;
|
|
||||||
uint32_t reserved;
|
|
||||||
uint32_t flags[5];
|
|
||||||
} ConfigFlags;
|
|
||||||
|
|
||||||
typedef union
|
|
||||||
{
|
|
||||||
ConfigFlags config;
|
|
||||||
uint64_t dw[4];
|
|
||||||
} ConfigPage;
|
|
||||||
|
|
||||||
class Configuration
|
class Configuration
|
||||||
{
|
{
|
||||||
@ -68,17 +50,19 @@ public:
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
Configuration();
|
Configuration();
|
||||||
bool eraseStationDataPage();
|
//bool eraseStationDataPage();
|
||||||
bool writeStationDataPage();
|
//bool writeStationDataPage();
|
||||||
bool eraseConfigFlags();
|
//bool eraseConfigFlags();
|
||||||
|
|
||||||
const ConfigFlags *readConfigFlags();
|
//bool readConfigFlags();
|
||||||
bool writeConfigFlags(const ConfigFlags *flags);
|
//bool writeConfigFlags();
|
||||||
bool erasePage(uint32_t address);
|
//bool erasePage(uint32_t address);
|
||||||
|
|
||||||
uint32_t nextAvailableOTPSlot();
|
uint32_t nextAvailableOTPSlot();
|
||||||
const char *hwRev();
|
const char *hwRev();
|
||||||
const char *serNum();
|
const char *serNum();
|
||||||
|
private:
|
||||||
|
ConfigFlags mFlags = {0};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* CONFIGURATION_HPP_ */
|
#endif /* CONFIGURATION_HPP_ */
|
||||||
|
@ -22,7 +22,8 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "StationData.h"
|
||||||
|
#include "ConfigFlags.h"
|
||||||
|
|
||||||
// See the bottom section for the proper BOARD_REV symbol format and either modify this header
|
// See the bottom section for the proper BOARD_REV symbol format and either modify this header
|
||||||
// or define a different symbol in the preprocessor to build for a different board
|
// or define a different symbol in the preprocessor to build for a different board
|
||||||
@ -57,6 +58,20 @@ void bsp_tx_led_off();
|
|||||||
void bsp_gps_led_on();
|
void bsp_gps_led_on();
|
||||||
void bsp_gps_led_off();
|
void bsp_gps_led_off();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Station data persistence related
|
||||||
|
*/
|
||||||
|
void bsp_read_station_data(StationData *data);
|
||||||
|
void bsp_write_station_data(const StationData &data);
|
||||||
|
void bsp_erase_station_data();
|
||||||
|
bool bsp_is_station_data_provisioned();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration flag persistence
|
||||||
|
*/
|
||||||
|
void bsp_read_config_flags(ConfigFlags *flags);
|
||||||
|
void bsp_write_config_flags(const ConfigFlags &flags);
|
||||||
|
void bsp_erase_config_flags();
|
||||||
|
|
||||||
// Callback for processing UART input (interrupt)
|
// Callback for processing UART input (interrupt)
|
||||||
typedef void(*char_input_cb)(char c);
|
typedef void(*char_input_cb)(char c);
|
||||||
|
@ -74,7 +74,7 @@
|
|||||||
#define MIN_MSG_18_TX_INTERVAL 30
|
#define MIN_MSG_18_TX_INTERVAL 30
|
||||||
#define MAX_MSG_18_TX_INTERVAL 180
|
#define MAX_MSG_18_TX_INTERVAL 180
|
||||||
|
|
||||||
// Default interval for message 24 A&B (static data report)
|
// Default interval for message 24 A&B (static data report) = 6 minutes
|
||||||
#define MSG_24_TX_INTERVAL 360
|
#define MSG_24_TX_INTERVAL 360
|
||||||
|
|
||||||
// The spec calls for Class B transmitters to listen for the first 20 bits of each frame before transmitting.
|
// The spec calls for Class B transmitters to listen for the first 20 bits of each frame before transmitting.
|
||||||
@ -89,7 +89,6 @@
|
|||||||
#define CLI_FLAG_MAGIC 0x209a388d
|
#define CLI_FLAG_MAGIC 0x209a388d
|
||||||
|
|
||||||
#define CONFIGURATION_FLAG_ADDRESS 0x0800F000
|
#define CONFIGURATION_FLAG_ADDRESS 0x0800F000
|
||||||
#define STATION_DATA_ADDRESS 0x0800F800
|
|
||||||
#define OTP_DATA 1
|
#define OTP_DATA 1
|
||||||
|
|
||||||
#define ENABLE_WDT 1
|
#define ENABLE_WDT 1
|
||||||
|
@ -27,8 +27,8 @@
|
|||||||
|
|
||||||
|
|
||||||
// These are not defined in ANY CMSIS or HAL header, WTF ST???
|
// These are not defined in ANY CMSIS or HAL header, WTF ST???
|
||||||
#define OTP_ADDRESS 0x1FFF7000
|
#define OTP_ADDRESS 0x1FFF7000
|
||||||
#define OTP_SIZE 0x00000400
|
#define OTP_SIZE 0x00000400
|
||||||
|
|
||||||
#define CONFIG_FLAGS_MAGIC 0x2092ED2C
|
#define CONFIG_FLAGS_MAGIC 0x2092ED2C
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ static StationData __THIS_STATION__ = {
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static StationDataPage __page;
|
//static StationDataPage __page;
|
||||||
|
|
||||||
Configuration &Configuration::instance()
|
Configuration &Configuration::instance()
|
||||||
{
|
{
|
||||||
@ -67,31 +67,32 @@ void Configuration::init()
|
|||||||
reportSystemData();
|
reportSystemData();
|
||||||
reportStationData();
|
reportStationData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bsp_read_config_flags(&mFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Configuration::enableTX()
|
void Configuration::enableTX()
|
||||||
{
|
{
|
||||||
// For now, the only flag in use is a TX switch bit which is set to 0
|
// For now, the only flag in use is a TX switch bit which is set to 0
|
||||||
ConfigFlags flags = {CONFIG_FLAGS_MAGIC, 0, {0}};
|
mFlags = {CONFIG_FLAGS_MAGIC, 0, {0}};
|
||||||
writeConfigFlags(&flags);
|
bsp_write_config_flags(mFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Configuration::disableTX()
|
void Configuration::disableTX()
|
||||||
{
|
{
|
||||||
// For now, the only flag in use is a TX switch bit which is set to 0
|
// For now, the only flag in use is a TX switch bit which is set to 0
|
||||||
ConfigFlags flags = {CONFIG_FLAGS_MAGIC, 0, {0}};
|
mFlags = {CONFIG_FLAGS_MAGIC, 0, {0}};
|
||||||
flags.flags[0] = 0x01;
|
mFlags.flags[0] = 0x01;
|
||||||
writeConfigFlags(&flags);
|
bsp_write_config_flags(mFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Configuration::isTXEnabled()
|
bool Configuration::isTXEnabled()
|
||||||
{
|
{
|
||||||
const ConfigFlags *cfg = readConfigFlags();
|
if ( mFlags.magic != CONFIG_FLAGS_MAGIC )
|
||||||
if ( cfg == nullptr )
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Bit 0 in word 0 inhibits transmission
|
// Bit 0 in word 0 inhibits transmission
|
||||||
return (cfg->flags[0] & 0x01) == 0;
|
return (mFlags.flags[0] & 0x01) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *Configuration::hwRev()
|
const char *Configuration::hwRev()
|
||||||
@ -151,7 +152,7 @@ void Configuration::reportStationData()
|
|||||||
|
|
||||||
bool Configuration::isStationDataProvisioned()
|
bool Configuration::isStationDataProvisioned()
|
||||||
{
|
{
|
||||||
return __page.station.magic == STATION_DATA_MAGIC;
|
return bsp_is_station_data_provisioned();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if OTP_DATA
|
#if OTP_DATA
|
||||||
@ -176,117 +177,26 @@ void Configuration::reportOTPData()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool Configuration::eraseStationDataPage()
|
|
||||||
{
|
|
||||||
return erasePage(STATION_DATA_ADDRESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
//__attribute__ ((long_call, section (".code_in_ram")))
|
|
||||||
bool Configuration::erasePage(uint32_t address)
|
|
||||||
{
|
|
||||||
uint32_t page = (address - FLASH_BASE) / FLASH_PAGE_SIZE;
|
|
||||||
|
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
|
|
||||||
if ( HAL_FLASH_Unlock() != HAL_OK )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
FLASH_EraseInitTypeDef erase;
|
|
||||||
erase.TypeErase = FLASH_TYPEERASE_PAGES;
|
|
||||||
erase.Banks = FLASH_BANK_1;
|
|
||||||
erase.Page = page;
|
|
||||||
erase.NbPages = 1;
|
|
||||||
|
|
||||||
uint32_t errPage;
|
|
||||||
HAL_StatusTypeDef status = HAL_FLASHEx_Erase(&erase, &errPage);
|
|
||||||
HAL_FLASH_Lock();
|
|
||||||
return status == HAL_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Configuration::resetToDefaults()
|
void Configuration::resetToDefaults()
|
||||||
{
|
{
|
||||||
if ( eraseStationDataPage() )
|
bsp_erase_station_data();
|
||||||
reportStationData();
|
reportStationData();
|
||||||
|
bsp_erase_config_flags();
|
||||||
erasePage(CONFIGURATION_FLAG_ADDRESS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Configuration::writeStationData(const StationData &data)
|
bool Configuration::writeStationData(const StationData &data)
|
||||||
{
|
{
|
||||||
if ( !eraseStationDataPage() )
|
bsp_write_station_data(data);
|
||||||
return false;
|
reportStationData();
|
||||||
|
return true;
|
||||||
memcpy(&__page.station, &data, sizeof data);
|
|
||||||
if ( eraseStationDataPage() )
|
|
||||||
{
|
|
||||||
bool success = writeStationDataPage();
|
|
||||||
reportStationData();
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Configuration::writeStationDataPage()
|
|
||||||
{
|
|
||||||
uint32_t pageAddress = STATION_DATA_ADDRESS;
|
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
|
|
||||||
HAL_FLASH_Unlock();
|
|
||||||
HAL_StatusTypeDef status = HAL_OK;
|
|
||||||
for ( uint32_t dw = 0; dw < sizeof __page/8; ++dw )
|
|
||||||
{
|
|
||||||
status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, pageAddress + dw*8, __page.dw[dw]);
|
|
||||||
if ( status != HAL_OK )
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
HAL_FLASH_Lock();
|
|
||||||
|
|
||||||
return status == HAL_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Configuration::readStationData(StationData &data)
|
bool Configuration::readStationData(StationData &data)
|
||||||
{
|
{
|
||||||
memcpy(&__page, (const void*)STATION_DATA_ADDRESS, sizeof __page);
|
bsp_read_station_data(&data);
|
||||||
memcpy(&data, &__page.station, sizeof data);
|
|
||||||
return data.magic == STATION_DATA_MAGIC;
|
return data.magic == STATION_DATA_MAGIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ConfigFlags* Configuration::readConfigFlags()
|
|
||||||
{
|
|
||||||
const ConfigPage *res = (const ConfigPage*)CONFIGURATION_FLAG_ADDRESS;
|
|
||||||
if ( res->config.magic != CONFIG_FLAGS_MAGIC )
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
return &res->config;
|
|
||||||
}
|
|
||||||
|
|
||||||
//__attribute__ ((long_call, section (".code_in_ram")))
|
|
||||||
bool Configuration::writeConfigFlags(const ConfigFlags *flags)
|
|
||||||
{
|
|
||||||
if ( !erasePage(CONFIGURATION_FLAG_ADDRESS) )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
ConfigPage page;
|
|
||||||
memcpy(&page, flags, sizeof page);
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t pageAddress = CONFIGURATION_FLAG_ADDRESS;
|
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
|
|
||||||
if ( HAL_FLASH_Unlock() != HAL_OK )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
HAL_StatusTypeDef status = HAL_OK;
|
|
||||||
for ( uint32_t dw = 0; dw < sizeof page/8; ++dw )
|
|
||||||
{
|
|
||||||
status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, pageAddress + dw*8, page.dw[dw]);
|
|
||||||
if ( status != HAL_OK )
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
HAL_FLASH_Lock();
|
|
||||||
|
|
||||||
return status == HAL_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if OTP_DATA
|
#if OTP_DATA
|
||||||
const OTPData *Configuration::readOTP()
|
const OTPData *Configuration::readOTP()
|
||||||
|
@ -52,7 +52,7 @@ void NoiseFloorDetector::report(char channel, uint8_t rssi)
|
|||||||
#elif BOARD_REV == 109
|
#elif BOARD_REV == 109
|
||||||
if ( rssi < 0x24 )
|
if ( rssi < 0x24 )
|
||||||
#else
|
#else
|
||||||
if ( rssi < 0x32 ) // Not realistic, likely a bug
|
if ( rssi < 0x12 ) // Not realistic, likely a bug
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -27,6 +27,9 @@
|
|||||||
|
|
||||||
#if BOARD_REV==110
|
#if BOARD_REV==110
|
||||||
|
|
||||||
|
#define STATION_DATA_ADDRESS 0x0800F800
|
||||||
|
|
||||||
|
|
||||||
const char *BSP_HW_REV = "11.x";
|
const char *BSP_HW_REV = "11.x";
|
||||||
|
|
||||||
SPI_HandleTypeDef hspi1;
|
SPI_HandleTypeDef hspi1;
|
||||||
@ -45,7 +48,12 @@ irq_callback trxClockCallback = nullptr;
|
|||||||
irq_callback rxClockCallback = nullptr;
|
irq_callback rxClockCallback = nullptr;
|
||||||
irq_callback tickCallback = nullptr;
|
irq_callback tickCallback = nullptr;
|
||||||
|
|
||||||
#define EEPROM_ADDRESS 0x50 << 1
|
// This should be plenty big (no need to be a whole flash page)
|
||||||
|
typedef union
|
||||||
|
{
|
||||||
|
StationData station;
|
||||||
|
uint64_t dw[32];
|
||||||
|
} StationDataPage;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@ -321,10 +329,76 @@ void HAL_MspInit(void)
|
|||||||
|
|
||||||
bool bsp_is_tx_hardwired()
|
bool bsp_is_tx_hardwired()
|
||||||
{
|
{
|
||||||
// Always true for this board. It will get more involved later
|
// Always true for this board. It will get more involved later. Or maybe never ...
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void bsp_read_station_data(StationData *data)
|
||||||
|
{
|
||||||
|
memcpy(data, (const uint8_t*)STATION_DATA_ADDRESS, sizeof(StationData));
|
||||||
|
}
|
||||||
|
|
||||||
|
void bsp_write_station_data(const StationData &data)
|
||||||
|
{
|
||||||
|
bsp_erase_station_data();
|
||||||
|
StationDataPage page;
|
||||||
|
page.station = data;
|
||||||
|
page.station.magic = STATION_DATA_MAGIC;
|
||||||
|
|
||||||
|
uint32_t pageAddress = STATION_DATA_ADDRESS;
|
||||||
|
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
|
||||||
|
HAL_FLASH_Unlock();
|
||||||
|
HAL_StatusTypeDef status = HAL_OK;
|
||||||
|
for ( uint32_t dw = 0; dw < sizeof page/8; ++dw )
|
||||||
|
{
|
||||||
|
status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, pageAddress + dw*8, page.dw[dw]);
|
||||||
|
if ( status != HAL_OK )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
HAL_FLASH_Lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void bsp_erase_station_data()
|
||||||
|
{
|
||||||
|
uint32_t page = (STATION_DATA_ADDRESS - FLASH_BASE) / FLASH_PAGE_SIZE;
|
||||||
|
|
||||||
|
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
|
||||||
|
if ( HAL_FLASH_Unlock() != HAL_OK )
|
||||||
|
return;
|
||||||
|
|
||||||
|
FLASH_EraseInitTypeDef erase;
|
||||||
|
erase.TypeErase = FLASH_TYPEERASE_PAGES;
|
||||||
|
erase.Banks = FLASH_BANK_1;
|
||||||
|
erase.Page = page;
|
||||||
|
erase.NbPages = 1;
|
||||||
|
|
||||||
|
uint32_t errPage;
|
||||||
|
HAL_FLASHEx_Erase(&erase, &errPage);
|
||||||
|
HAL_FLASH_Lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool bsp_is_station_data_provisioned()
|
||||||
|
{
|
||||||
|
const StationData *d = (const StationData *)STATION_DATA_ADDRESS;
|
||||||
|
return d->magic == STATION_DATA_MAGIC;
|
||||||
|
}
|
||||||
|
|
||||||
|
void bsp_read_config_flags(ConfigFlags *flags)
|
||||||
|
{
|
||||||
|
// Not implemented
|
||||||
|
}
|
||||||
|
|
||||||
|
void bsp_write_config_flags(const ConfigFlags &flags)
|
||||||
|
{
|
||||||
|
// Not implemented
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void bsp_erase_config_flags()
|
||||||
|
{
|
||||||
|
// Not implemented
|
||||||
|
}
|
||||||
|
|
||||||
void bsp_set_rx_mode()
|
void bsp_set_rx_mode()
|
||||||
{
|
{
|
||||||
HAL_GPIO_WritePin(PA_BIAS_PORT, PA_BIAS_PIN, GPIO_PIN_RESET); // Kill the RF MOSFET bias voltage
|
HAL_GPIO_WritePin(PA_BIAS_PORT, PA_BIAS_PIN, GPIO_PIN_RESET); // Kill the RF MOSFET bias voltage
|
||||||
|
Loading…
x
Reference in New Issue
Block a user