1
0
mirror of https://github.com/peterantypas/maiana.git synced 2025-05-27 21:00:24 -07:00

OpenPlotter commands

This commit is contained in:
Peter Antypas 2021-09-27 07:30:01 -07:00
parent 07f47e7aef
commit d207c1c7a2
10 changed files with 132 additions and 42 deletions

View File

@ -29,9 +29,22 @@ typedef union
{
StationData station;
uint64_t dw[128];
} ConfigPage;
} 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
{
public:
@ -51,10 +64,18 @@ public:
void enableTX();
void disableTX();
bool isTXEnabled();
private:
Configuration();
bool erasePage();
bool writePage();
bool eraseStationDataPage();
bool writeStationDataPage();
bool eraseConfigFlags();
const ConfigFlags *readConfigFlags();
bool writeConfigFlags(const ConfigFlags *flags);
bool erasePage(uint32_t address);
uint32_t nextAvailableOTPSlot();
const char *hwRev();
const char *serNum();

View File

@ -88,7 +88,10 @@
#define DFU_FLAG_MAGIC 0xa191feed
#define CLI_FLAG_MAGIC 0x209a388d
#define CONFIGURATION_ADDRESS 0x0800F800
#define CONFIGURATION_FLAG_ADDRESS 0x0800F000
#define STATION_DATA_ADDRESS 0x0800F800
#define OTP_DATA 1
#define ENABLE_WDT 1
#endif /* CONFIG_H_ */

View File

@ -131,7 +131,14 @@ def send_data(packet):
def send_get():
if not send_command(GET):
success = False
for i in range(2):
if send_command(GET):
success = True
break
time.sleep(.2)
if not success:
print "Failed to send command GET"
return (False, [])
@ -224,7 +231,7 @@ def boot(address):
return True
"""
def enter_dfu(portname):
p = serial.Serial(portname, 38400, timeout=2, parity=serial.PARITY_NONE, stopbits=1)
if not p.is_open:
@ -235,7 +242,8 @@ def enter_dfu(portname):
s = p.readline()
p.close()
return len(s) == 0
"""
if __name__ == '__main__':
if len(sys.argv) < 4:
print "Usage: {0} port image address".format(sys.argv[0])

View File

@ -154,7 +154,7 @@ SECTIONS
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
*(.code_in_ram) /* code executing from RAM */
. = ALIGN(8);
_edata = .; /* define a global symbol at data end */
} >RAM AT> FLASH

View File

@ -143,11 +143,13 @@ void CommandProcessor::processCommand(const char *buff)
}
else if ( s.find("tx on") == 0 )
{
// TODO
Configuration::instance().enableTX();
TXScheduler::instance().reportTXStatus();
}
else if ( s.find("tx off") == 0 )
{
// TODO
Configuration::instance().disableTX();
TXScheduler::instance().reportTXStatus();
}
else if ( s.find("tx?") == 0 )
{

View File

@ -30,6 +30,8 @@
#define OTP_ADDRESS 0x1FFF7000
#define OTP_SIZE 0x00000400
#define CONFIG_FLAGS_MAGIC 0x2092ED2C
#if 0
static StationData __THIS_STATION__ = {
STATION_DATA_MAGIC,
@ -44,7 +46,7 @@ static StationData __THIS_STATION__ = {
};
#endif
static ConfigPage __page;
static StationDataPage __page;
Configuration &Configuration::instance()
{
@ -69,17 +71,27 @@ void Configuration::init()
void Configuration::enableTX()
{
// TODO
// 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);
}
void Configuration::disableTX()
{
// TODO
// 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);
}
bool Configuration::isTXEnabled()
{
return true;
const ConfigFlags *cfg = readConfigFlags();
if ( cfg == nullptr )
return true;
// Bit 0 in word 0 inhibits transmission
return (cfg->flags[0] & 0x01) == 0;
}
const char *Configuration::hwRev()
@ -165,12 +177,19 @@ void Configuration::reportOTPData()
}
#endif
bool Configuration::erasePage()
bool Configuration::eraseStationDataPage()
{
uint32_t page = (CONFIGURATION_ADDRESS - FLASH_BASE) / FLASH_PAGE_SIZE;
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);
HAL_FLASH_Unlock();
if ( HAL_FLASH_Unlock() != HAL_OK )
return false;
FLASH_EraseInitTypeDef erase;
erase.TypeErase = FLASH_TYPEERASE_PAGES;
@ -180,31 +199,27 @@ bool Configuration::erasePage()
uint32_t errPage;
HAL_StatusTypeDef status = HAL_FLASHEx_Erase(&erase, &errPage);
if ( status != HAL_OK )
{
HAL_FLASH_Lock();
return false;
}
HAL_FLASH_Lock();
return true;
return status == HAL_OK;
}
void Configuration::resetToDefaults()
{
if ( erasePage() )
if ( eraseStationDataPage() )
reportStationData();
erasePage(CONFIGURATION_FLAG_ADDRESS);
}
bool Configuration::writeStationData(const StationData &data)
{
if ( !erasePage() )
if ( !eraseStationDataPage() )
return false;
memcpy(&__page.station, &data, sizeof data);
if ( erasePage() )
if ( eraseStationDataPage() )
{
bool success = writePage();
bool success = writeStationDataPage();
reportStationData();
return success;
}
@ -214,9 +229,9 @@ bool Configuration::writeStationData(const StationData &data)
}
}
bool Configuration::writePage()
bool Configuration::writeStationDataPage()
{
uint32_t pageAddress = CONFIGURATION_ADDRESS;
uint32_t pageAddress = STATION_DATA_ADDRESS;
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
HAL_FLASH_Unlock();
HAL_StatusTypeDef status = HAL_OK;
@ -233,11 +248,47 @@ bool Configuration::writePage()
bool Configuration::readStationData(StationData &data)
{
memcpy(&__page, (const void*)CONFIGURATION_ADDRESS, sizeof __page);
memcpy(&__page, (const void*)STATION_DATA_ADDRESS, sizeof __page);
memcpy(&data, &__page.station, sizeof 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()
{

View File

@ -41,11 +41,11 @@ void tickCB()
void LEDManager::init()
{
if ( !TXScheduler::instance().isTXAllowed() )
{
// This call actually has the opposite effect
bsp_tx_led_on();
}
if ( TXScheduler::instance().isTXAllowed() )
bsp_tx_led_on();
else
bsp_tx_led_off();
bsp_set_tick_callback(tickCB);
}
@ -64,9 +64,9 @@ void LEDManager::onTick()
{
count2 = 1;
if ( TXScheduler::instance().isTXAllowed() )
bsp_tx_led_off();
else
bsp_tx_led_on();
else
bsp_tx_led_off();
}
}

View File

@ -27,6 +27,7 @@
#include "bsp.hpp"
#include "TXErrors.h"
#include <stdio.h>
#include "TXScheduler.hpp"
Transceiver::Transceiver(GPIO_TypeDef *sdnPort, uint32_t sdnPin, GPIO_TypeDef *csPort,
uint32_t csPin, GPIO_TypeDef *dataPort, uint32_t dataPin,
@ -342,5 +343,5 @@ void Transceiver::reportTXEvent()
snprintf(e->nmeaBuffer.sentence, sizeof e->nmeaBuffer.sentence, "$PAITX,%c,%s*", AIS_CHANNELS[mTXPacket->channel()].designation, mTXPacket->messageType());
Utils::completeNMEA(e->nmeaBuffer.sentence);
EventQueue::instance().push(e);
bsp_tx_led_on();
bsp_tx_led_off();
}

View File

@ -350,12 +350,12 @@ void bsp_rx_led_off()
void bsp_tx_led_on()
{
HAL_GPIO_WritePin(TX_EVT_PORT, TX_EVT_PIN, GPIO_PIN_SET);
HAL_GPIO_WritePin(TX_EVT_PORT, TX_EVT_PIN, GPIO_PIN_RESET);
}
void bsp_tx_led_off()
{
HAL_GPIO_WritePin(TX_EVT_PORT, TX_EVT_PIN, GPIO_PIN_RESET);
HAL_GPIO_WritePin(TX_EVT_PORT, TX_EVT_PIN, GPIO_PIN_SET);
}
void bsp_gps_led_on()
@ -417,7 +417,7 @@ void bsp_write_string(const char *s)
void bsp_start_wdt()
{
IWDG_InitTypeDef iwdg;
iwdg.Prescaler = IWDG_PRESCALER_64;
iwdg.Prescaler = IWDG_PRESCALER_16;
iwdg.Reload = 0x0fff;
iwdg.Window = 0x0fff;

View File

@ -75,11 +75,15 @@ void mainLoop()
*(uint32_t*)BOOTMODE_ADDRESS = 0;
#if ENABLE_WDT
bsp_start_wdt();
#endif
while (1)
{
EventQueue::instance().dispatch();
#if ENABLE_WDT
bsp_refresh_wdt();
#endif
__WFI();
}
}