mirror of
https://github.com/peterantypas/maiana.git
synced 2025-05-28 05:10:40 -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 "OTPData.h"
|
||||
#include "config.h"
|
||||
|
||||
// This should be plenty big (no need to be a whole flash page though)
|
||||
typedef union
|
||||
{
|
||||
StationData station;
|
||||
uint64_t dw[128];
|
||||
} StationDataPage;
|
||||
#include "ConfigFlags.h"
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t magic;
|
||||
uint32_t reserved;
|
||||
uint32_t flags[5];
|
||||
} ConfigFlags;
|
||||
|
||||
typedef union
|
||||
{
|
||||
ConfigFlags config;
|
||||
uint64_t dw[4];
|
||||
} ConfigPage;
|
||||
|
||||
class Configuration
|
||||
{
|
||||
@ -68,17 +50,19 @@ public:
|
||||
private:
|
||||
|
||||
Configuration();
|
||||
bool eraseStationDataPage();
|
||||
bool writeStationDataPage();
|
||||
bool eraseConfigFlags();
|
||||
//bool eraseStationDataPage();
|
||||
//bool writeStationDataPage();
|
||||
//bool eraseConfigFlags();
|
||||
|
||||
const ConfigFlags *readConfigFlags();
|
||||
bool writeConfigFlags(const ConfigFlags *flags);
|
||||
bool erasePage(uint32_t address);
|
||||
//bool readConfigFlags();
|
||||
//bool writeConfigFlags();
|
||||
//bool erasePage(uint32_t address);
|
||||
|
||||
uint32_t nextAvailableOTPSlot();
|
||||
const char *hwRev();
|
||||
const char *serNum();
|
||||
private:
|
||||
ConfigFlags mFlags = {0};
|
||||
};
|
||||
|
||||
#endif /* CONFIGURATION_HPP_ */
|
||||
|
@ -22,7 +22,8 @@
|
||||
|
||||
#include <stdint.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
|
||||
// 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_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)
|
||||
typedef void(*char_input_cb)(char c);
|
||||
|
@ -74,7 +74,7 @@
|
||||
#define MIN_MSG_18_TX_INTERVAL 30
|
||||
#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
|
||||
|
||||
// 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 CONFIGURATION_FLAG_ADDRESS 0x0800F000
|
||||
#define STATION_DATA_ADDRESS 0x0800F800
|
||||
#define OTP_DATA 1
|
||||
|
||||
#define ENABLE_WDT 1
|
||||
|
@ -27,8 +27,8 @@
|
||||
|
||||
|
||||
// These are not defined in ANY CMSIS or HAL header, WTF ST???
|
||||
#define OTP_ADDRESS 0x1FFF7000
|
||||
#define OTP_SIZE 0x00000400
|
||||
#define OTP_ADDRESS 0x1FFF7000
|
||||
#define OTP_SIZE 0x00000400
|
||||
|
||||
#define CONFIG_FLAGS_MAGIC 0x2092ED2C
|
||||
|
||||
@ -46,7 +46,7 @@ static StationData __THIS_STATION__ = {
|
||||
};
|
||||
#endif
|
||||
|
||||
static StationDataPage __page;
|
||||
//static StationDataPage __page;
|
||||
|
||||
Configuration &Configuration::instance()
|
||||
{
|
||||
@ -67,31 +67,32 @@ void Configuration::init()
|
||||
reportSystemData();
|
||||
reportStationData();
|
||||
}
|
||||
|
||||
bsp_read_config_flags(&mFlags);
|
||||
}
|
||||
|
||||
void Configuration::enableTX()
|
||||
{
|
||||
// For now, the only flag in use is a TX switch bit which is set to 0
|
||||
ConfigFlags flags = {CONFIG_FLAGS_MAGIC, 0, {0}};
|
||||
writeConfigFlags(&flags);
|
||||
mFlags = {CONFIG_FLAGS_MAGIC, 0, {0}};
|
||||
bsp_write_config_flags(mFlags);
|
||||
}
|
||||
|
||||
void Configuration::disableTX()
|
||||
{
|
||||
// For now, the only flag in use is a TX switch bit which is set to 0
|
||||
ConfigFlags flags = {CONFIG_FLAGS_MAGIC, 0, {0}};
|
||||
flags.flags[0] = 0x01;
|
||||
writeConfigFlags(&flags);
|
||||
mFlags = {CONFIG_FLAGS_MAGIC, 0, {0}};
|
||||
mFlags.flags[0] = 0x01;
|
||||
bsp_write_config_flags(mFlags);
|
||||
}
|
||||
|
||||
bool Configuration::isTXEnabled()
|
||||
{
|
||||
const ConfigFlags *cfg = readConfigFlags();
|
||||
if ( cfg == nullptr )
|
||||
if ( mFlags.magic != CONFIG_FLAGS_MAGIC )
|
||||
return true;
|
||||
|
||||
// Bit 0 in word 0 inhibits transmission
|
||||
return (cfg->flags[0] & 0x01) == 0;
|
||||
return (mFlags.flags[0] & 0x01) == 0;
|
||||
}
|
||||
|
||||
const char *Configuration::hwRev()
|
||||
@ -151,7 +152,7 @@ void Configuration::reportStationData()
|
||||
|
||||
bool Configuration::isStationDataProvisioned()
|
||||
{
|
||||
return __page.station.magic == STATION_DATA_MAGIC;
|
||||
return bsp_is_station_data_provisioned();
|
||||
}
|
||||
|
||||
#if OTP_DATA
|
||||
@ -176,117 +177,26 @@ void Configuration::reportOTPData()
|
||||
}
|
||||
#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()
|
||||
{
|
||||
if ( eraseStationDataPage() )
|
||||
reportStationData();
|
||||
|
||||
erasePage(CONFIGURATION_FLAG_ADDRESS);
|
||||
bsp_erase_station_data();
|
||||
reportStationData();
|
||||
bsp_erase_config_flags();
|
||||
}
|
||||
|
||||
bool Configuration::writeStationData(const StationData &data)
|
||||
{
|
||||
if ( !eraseStationDataPage() )
|
||||
return false;
|
||||
|
||||
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;
|
||||
bsp_write_station_data(data);
|
||||
reportStationData();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Configuration::readStationData(StationData &data)
|
||||
{
|
||||
memcpy(&__page, (const void*)STATION_DATA_ADDRESS, sizeof __page);
|
||||
memcpy(&data, &__page.station, sizeof data);
|
||||
bsp_read_station_data(&data);
|
||||
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
|
||||
const OTPData *Configuration::readOTP()
|
||||
|
@ -52,7 +52,7 @@ void NoiseFloorDetector::report(char channel, uint8_t rssi)
|
||||
#elif BOARD_REV == 109
|
||||
if ( rssi < 0x24 )
|
||||
#else
|
||||
if ( rssi < 0x32 ) // Not realistic, likely a bug
|
||||
if ( rssi < 0x12 ) // Not realistic, likely a bug
|
||||
#endif
|
||||
return;
|
||||
|
||||
|
@ -27,6 +27,9 @@
|
||||
|
||||
#if BOARD_REV==110
|
||||
|
||||
#define STATION_DATA_ADDRESS 0x0800F800
|
||||
|
||||
|
||||
const char *BSP_HW_REV = "11.x";
|
||||
|
||||
SPI_HandleTypeDef hspi1;
|
||||
@ -45,7 +48,12 @@ irq_callback trxClockCallback = nullptr;
|
||||
irq_callback rxClockCallback = 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
|
||||
{
|
||||
@ -321,10 +329,76 @@ void HAL_MspInit(void)
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
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