1
0
mirror of https://github.com/peterantypas/maiana.git synced 2025-05-29 05:40:15 -07:00

TX LED logic 100% in FW

This commit is contained in:
Peter Antypas 2021-09-23 15:06:51 -07:00
parent 94dd635b3c
commit 07f47e7aef
10 changed files with 46 additions and 45 deletions

View File

@ -31,12 +31,5 @@ typedef struct {
} }
pa_params; pa_params;
#if 0
static const pa_params POWER_TABLE[] = {
{0x4467, 0x48, 0x20, 0x00},
{0x4460, 0x48, 0x20, 0x00},
{0x4463, 0x48, 0x12, 0x00}
};
#endif
#endif /* TXPOWERSETTINGS_H_ */ #endif /* TXPOWERSETTINGS_H_ */

View File

@ -27,13 +27,13 @@ public:
void queueMessage24(VHFChannel channel); void queueMessage24(VHFChannel channel);
void reportTXStatus(); void reportTXStatus();
bool isTXAllowed();
private: private:
TXScheduler (); TXScheduler ();
virtual ~TXScheduler (); virtual ~TXScheduler ();
time_t positionReportTimeInterval(); time_t positionReportTimeInterval();
void sendNMEASentence(const char *sentence); void sendNMEASentence(const char *sentence);
bool isTXAllowed();
private: private:
VHFChannel mPositionReportChannel; VHFChannel mPositionReportChannel;
VHFChannel mStaticDataChannel; VHFChannel mStaticDataChannel;

View File

@ -47,7 +47,7 @@ void bsp_enter_dfu();
void bsp_gnss_on(); void bsp_gnss_on();
void bsp_gnss_off(); void bsp_gnss_off();
bool bsp_is_tx_disabled(); bool bsp_is_tx_disabled();
bool bsp_is_tx_present();
void bsp_rx_led_on(); void bsp_rx_led_on();
void bsp_rx_led_off(); void bsp_rx_led_off();
void bsp_tx_led_on(); void bsp_tx_led_on();

View File

@ -25,8 +25,8 @@
#include "TXPowerSettings.h" #include "TXPowerSettings.h"
// Set to non-zero to enable transmission support #define FW_REV "3.2.0"
#define ENABLE_TX 1
/* /*
* Defining this symbol forces all output (NMEA + debug) to a high-speed USART for tunneling to an application that demuxes it. * Defining this symbol forces all output (NMEA + debug) to a high-speed USART for tunneling to an application that demuxes it.
@ -54,6 +54,8 @@
// Maximum allowed backlog in TX queue // Maximum allowed backlog in TX queue
#define MAX_TX_PACKETS_IN_QUEUE 4 #define MAX_TX_PACKETS_IN_QUEUE 4
// Set to true to emit proprietary NMEA sentences for debugging TX scheduling. Not useful in production.
#define REPORT_TX_SCHEDULING 0
// Set to true to force RSSI sampling at every SOTDMA timer slot on both channels // Set to true to force RSSI sampling at every SOTDMA timer slot on both channels
#define FULL_RSSI_SAMPLING 1 #define FULL_RSSI_SAMPLING 1
@ -89,6 +91,4 @@
#define CONFIGURATION_ADDRESS 0x0800F800 #define CONFIGURATION_ADDRESS 0x0800F800
#define OTP_DATA 1 #define OTP_DATA 1
#define FW_REV "3.1.0"
#endif /* CONFIG_H_ */ #endif /* CONFIG_H_ */

View File

@ -20,17 +20,9 @@
#include "LEDManager.hpp" #include "LEDManager.hpp"
#include "bsp.hpp" #include "bsp.hpp"
#include "Configuration.hpp" #include "Configuration.hpp"
#include "TXScheduler.hpp"
/**
* TODO: Update this to manage the status of the TX LED without any external hardware logic.
* It must take all inputs into consideration:
*
* - Presence of station data
* - Status of TX_DISABLE signal
* - Status of "tx off" software setting
*/
LEDManager::LEDManager() LEDManager::LEDManager()
{ {
// Do nothing // Do nothing
@ -47,15 +39,11 @@ void tickCB()
LEDManager::instance().onTick(); LEDManager::instance().onTick();
} }
static bool mForceTXLedOff = false;
void LEDManager::init() void LEDManager::init()
{ {
if ( !Configuration::instance().isStationDataProvisioned() ) if ( !TXScheduler::instance().isTXAllowed() )
{ {
mForceTXLedOff = true; // This call actually has the opposite effect
// This call actually has the opposite effect as it will cause the TX led to be pulled to GND
bsp_tx_led_on(); bsp_tx_led_on();
} }
bsp_set_tick_callback(tickCB); bsp_set_tick_callback(tickCB);
@ -72,10 +60,13 @@ void LEDManager::onTick()
} }
if ( !mForceTXLedOff && count2++ == 250 ) if ( count2++ == 200 )
{ {
count2 = 1; count2 = 1;
bsp_tx_led_off(); if ( TXScheduler::instance().isTXAllowed() )
bsp_tx_led_off();
else
bsp_tx_led_on();
} }
} }

View File

@ -165,17 +165,22 @@ void RadioManager::timeSlotStarted(uint32_t slotNumber)
void RadioManager::scheduleTransmission(TXPacket *packet) void RadioManager::scheduleTransmission(TXPacket *packet)
{ {
#if REPORT_TX_SCHEDULING
Event *e = EventPool::instance().newEvent(PROPR_NMEA_SENTENCE); Event *e = EventPool::instance().newEvent(PROPR_NMEA_SENTENCE);
#endif
if ( !mTXQueue.push(packet) ) if ( !mTXQueue.push(packet) )
{ {
#if REPORT_TX_SCHEDULING
if ( e ) if ( e )
{ {
sprintf(e->nmeaBuffer.sentence, "$PAISCHTX,%s,%d*", packet->messageType(), TX_QUEUE_FULL); sprintf(e->nmeaBuffer.sentence, "$PAISCHTX,%s,%d*", packet->messageType(), TX_QUEUE_FULL);
Utils::completeNMEA(e->nmeaBuffer.sentence); Utils::completeNMEA(e->nmeaBuffer.sentence);
EventQueue::instance().push(e); EventQueue::instance().push(e);
} }
#endif
TXPacketPool::instance().deleteTXPacket(packet); TXPacketPool::instance().deleteTXPacket(packet);
} }
#if REPORT_TX_SCHEDULING
else else
{ {
if ( e ) if ( e )
@ -185,6 +190,7 @@ void RadioManager::scheduleTransmission(TXPacket *packet)
EventQueue::instance().push(e); EventQueue::instance().push(e);
} }
} }
#endif
} }
void RadioManager::sendTestPacketNow(TXPacket *packet) void RadioManager::sendTestPacketNow(TXPacket *packet)

View File

@ -62,7 +62,9 @@ TXScheduler::TXScheduler ()
void TXScheduler::init() void TXScheduler::init()
{ {
reportTXStatus(); bool cliBootMode = *(uint32_t*)BOOTMODE_ADDRESS == CLI_FLAG_MAGIC;
if ( !cliBootMode )
reportTXStatus();
} }
TXScheduler::~TXScheduler () TXScheduler::~TXScheduler ()
@ -81,7 +83,7 @@ void TXScheduler::reportTXStatus()
if ( !e ) if ( !e )
return; return;
sprintf(e->nmeaBuffer.sentence, "$PAITXCFG,%d,%d,%d,%d*", !hwSwitchOff, softSwitch, hasStation, status); sprintf(e->nmeaBuffer.sentence, "$PAITXCFG,%d,%d,%d,%d,%d*", bsp_is_tx_present(), !hwSwitchOff, softSwitch, hasStation, status);
Utils::completeNMEA(e->nmeaBuffer.sentence); Utils::completeNMEA(e->nmeaBuffer.sentence);
EventQueue::instance().push(e); EventQueue::instance().push(e);
} }
@ -89,10 +91,13 @@ void TXScheduler::reportTXStatus()
bool TXScheduler::isTXAllowed() bool TXScheduler::isTXAllowed()
{ {
bool hwSwitchOff = bsp_is_tx_disabled(); bool hwSwitchOff = bsp_is_tx_disabled();
if ( hwSwitchOff )
return false;
bool softSwitch = Configuration::instance().isTXEnabled(); bool softSwitch = Configuration::instance().isTXEnabled();
bool hasStation = Configuration::instance().isStationDataProvisioned(); bool hasStation = Configuration::instance().isStationDataProvisioned();
return hwSwitchOff ? false : (softSwitch && hasStation); return softSwitch && hasStation;
} }
void TXScheduler::processEvent(const Event &e) void TXScheduler::processEvent(const Event &e)
@ -112,14 +117,9 @@ void TXScheduler::processEvent(const Event &e)
if ( !RadioManager::instance().initialized() || mUTC == 0 ) if ( !RadioManager::instance().initialized() || mUTC == 0 )
return; return;
#if TX_TEST_MODE
return;
#endif
if ( !isTXAllowed() ) if ( !isTXAllowed() )
return; return;
// Using a moving average of SOG to determine transmission rate // Using a moving average of SOG to determine transmission rate
static float alpha = 0.2; static float alpha = 0.2;
mAvgSpeed = mAvgSpeed * (1.0 - alpha) + mLastGPSFix.speed * alpha; mAvgSpeed = mAvgSpeed * (1.0 - alpha) + mLastGPSFix.speed * alpha;
@ -154,10 +154,6 @@ void TXScheduler::processEvent(const Event &e)
mUTC = e.clock.utc; mUTC = e.clock.utc;
// Every minute on the minute ...
if ( mUTC % 60 == 0 )
reportTXStatus();
break; break;
} }
@ -188,7 +184,9 @@ void TXScheduler::sendNMEASentence(const char *sentence)
void TXScheduler::queueMessage18(VHFChannel channel) void TXScheduler::queueMessage18(VHFChannel channel)
{ {
#if REPORT_TX_SCHEDULING
char sentence[48]; char sentence[48];
#endif
// If we don't have valid station data we don't do anything // If we don't have valid station data we don't do anything
if ( mStationData.magic != STATION_DATA_MAGIC ) if ( mStationData.magic != STATION_DATA_MAGIC )
@ -197,8 +195,10 @@ void TXScheduler::queueMessage18(VHFChannel channel)
TXPacket *p1 = TXPacketPool::instance().newTXPacket(channel); TXPacket *p1 = TXPacketPool::instance().newTXPacket(channel);
if ( !p1 ) if ( !p1 )
{ {
#if REPORT_TX_SCHEDULING
sprintf(sentence, "$PAISCHTX,18,%d*", TX_ALLOC_ERROR); sprintf(sentence, "$PAISCHTX,18,%d*", TX_ALLOC_ERROR);
sendNMEASentence(sentence); sendNMEASentence(sentence);
#endif
return; return;
} }
@ -215,7 +215,9 @@ void TXScheduler::queueMessage18(VHFChannel channel)
void TXScheduler::queueMessage24(VHFChannel channel) void TXScheduler::queueMessage24(VHFChannel channel)
{ {
#if REPORT_TX_SCHEDULING
char sentence[48]; char sentence[48];
#endif
// If we don't have valid station data we don't do anything // If we don't have valid station data we don't do anything
if ( mStationData.magic != STATION_DATA_MAGIC ) if ( mStationData.magic != STATION_DATA_MAGIC )
@ -224,8 +226,10 @@ void TXScheduler::queueMessage24(VHFChannel channel)
TXPacket *p2 = TXPacketPool::instance().newTXPacket(channel); TXPacket *p2 = TXPacketPool::instance().newTXPacket(channel);
if ( !p2 ) if ( !p2 )
{ {
#if REPORT_TX_SCHEDULING
sprintf(sentence, "$PAISCHTX,24A,%d*", TX_ALLOC_ERROR); sprintf(sentence, "$PAISCHTX,24A,%d*", TX_ALLOC_ERROR);
sendNMEASentence(sentence); sendNMEASentence(sentence);
#endif
return; return;
} }
@ -237,8 +241,10 @@ void TXScheduler::queueMessage24(VHFChannel channel)
TXPacket *p3 = TXPacketPool::instance().newTXPacket(channel); TXPacket *p3 = TXPacketPool::instance().newTXPacket(channel);
if ( !p3 ) if ( !p3 )
{ {
#if REPORT_TX_SCHEDULING
sprintf(sentence, "$PAISCHTX,24B,%d*", TX_ALLOC_ERROR); sprintf(sentence, "$PAISCHTX,24B,%d*", TX_ALLOC_ERROR);
sendNMEASentence(sentence); sendNMEASentence(sentence);
#endif
return; return;
} }

View File

@ -215,6 +215,7 @@ void Transceiver::onBitClock()
else if ( mUTC && mUTC - mTXPacket->timestamp() >= MIN_MSG_18_TX_INTERVAL ) else if ( mUTC && mUTC - mTXPacket->timestamp() >= MIN_MSG_18_TX_INTERVAL )
{ {
// The packet is way too old. Discard it. // The packet is way too old. Discard it.
#if REPORT_TX_SCHEDULING
Event *e = EventPool::instance().newEvent(PROPR_NMEA_SENTENCE); Event *e = EventPool::instance().newEvent(PROPR_NMEA_SENTENCE);
if ( e ) if ( e )
{ {
@ -222,7 +223,7 @@ void Transceiver::onBitClock()
Utils::completeNMEA(e->nmeaBuffer.sentence); Utils::completeNMEA(e->nmeaBuffer.sentence);
EventQueue::instance().push(e); EventQueue::instance().push(e);
} }
#endif
TXPacketPool::instance().deleteTXPacket(mTXPacket); TXPacketPool::instance().deleteTXPacket(mTXPacket);
mTXPacket = NULL; mTXPacket = NULL;
} }

View File

@ -319,6 +319,11 @@ void HAL_MspInit(void)
/* USER CODE END MspInit 1 */ /* USER CODE END MspInit 1 */
} }
bool bsp_is_tx_present()
{
return true;
}
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

View File

@ -56,13 +56,12 @@ void mainLoop()
Configuration::instance().init(); Configuration::instance().init();
DataTerminal::instance().init(); DataTerminal::instance().init();
CommandProcessor::instance().init(); CommandProcessor::instance().init();
LEDManager::instance().init();
RXPacketProcessor packetProcessor; RXPacketProcessor packetProcessor;
GPS::instance().init(); GPS::instance().init();
TXPacketPool::instance().init(); TXPacketPool::instance().init();
TXScheduler::instance().init(); TXScheduler::instance().init();
RadioManager::instance().init(); RadioManager::instance().init();
LEDManager::instance().init();
if ( !cliBootMode ) if ( !cliBootMode )
{ {