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

Checkpoint. Best RX performance possible with current architecture

This commit is contained in:
Peter Antypas 2020-11-03 11:08:57 -08:00
parent 8ab5a8b322
commit 34f7543b9d
6 changed files with 40 additions and 24 deletions

View File

@ -44,12 +44,12 @@ public:
bool init();
VHFChannel channel();
virtual void startReceiving(VHFChannel channel);
virtual void startReceiving(VHFChannel channel, bool reconfigGPIOs);
virtual void onBitClock();
virtual void timeSlotStarted(uint32_t slot);
void switchToChannel(VHFChannel channel);
protected:
void startListening(VHFChannel channel);
void startListening(VHFChannel channel, bool reconfigGPIOs);
bool addBit(uint8_t bit);
void resetBitScanner();
uint8_t reportRSSI();

View File

@ -43,8 +43,8 @@ public:
void timeSlotStarted(uint32_t slot);
void assignTXPacket(TXPacket *p);
TXPacket *assignedTXPacket();
void startReceiving(VHFChannel channel);
void startListening(VHFChannel channel);
void startReceiving(VHFChannel channel, bool reconfigGPIOs);
void startListening(VHFChannel channel, bool reconfigGPIOs);
void transmitCW(VHFChannel channel);
void processEvent(const Event &);

View File

@ -82,10 +82,10 @@ void RadioManager::start()
//DBG("Radio Manager starting\r\n");
configureInterrupts();
if ( mTransceiverIC )
mTransceiverIC->startReceiving(CH_87);
mTransceiverIC->startReceiving(CH_87, true);
if ( mReceiverIC )
mReceiverIC->startReceiving(CH_88);
mReceiverIC->startReceiving(CH_88, true);
GPS::instance().setDelegate(this);
//DBG("Radio Manager started\r\n");

View File

@ -63,10 +63,10 @@ bool Receiver::init()
return true;
}
void Receiver::startReceiving(VHFChannel channel)
void Receiver::startReceiving(VHFChannel channel, bool reconfigGPIOs)
{
mChannel = channel;
startListening(mChannel);
startListening(mChannel, reconfigGPIOs);
resetBitScanner();
}
@ -77,11 +77,15 @@ void Receiver::switchToChannel(VHFChannel channel)
}
// TODO: This is a really, really long operation - over 320us !!!
void Receiver::startListening(VHFChannel channel)
void Receiver::startListening(VHFChannel channel, bool reconfigGPIOs)
{
//bsp_signal_high();
configureGPIOsForRX();
if ( reconfigGPIOs )
{
// This takes about 140us
configureGPIOsForRX();
}
// This takes 180us
mChannel = channel;
RX_OPTIONS options;
options.channel = AIS_CHANNELS[channel].ordinal;
@ -91,8 +95,12 @@ void Receiver::startListening(VHFChannel channel)
options.next_state2 = 0;
options.next_state3 = 0;
/**
* This can take up to 220us, that's 3 bit clocks!!!
*/
bsp_signal_high();
sendCmd (START_RX, &options, sizeof options, NULL, 0);
//bsp_signal_low();
bsp_signal_low();
}
void Receiver::resetBitScanner()
@ -107,6 +115,14 @@ void Receiver::resetBitScanner()
mRXPacket->reset();
}
/*
* TODO: Under a worst case scenario, this interrupt service method
* can take up to 320us to complete (that's 4 clock bits!!!)
*
* Re-architecting will be necessary to resolve this, and it will almost certainly
* require ditching FreeRTOS in favor of "bare metal".
*/
void Receiver::onBitClock()
{
// Don't waste time processing bits when the transceiver is transmitting
@ -140,7 +156,7 @@ void Receiver::timeSlotStarted(uint32_t slot)
if ( mSwitchAtNextSlot )
{
mSwitchAtNextSlot = false;
startReceiving(mSwitchToChannel);
startReceiving(mSwitchToChannel, false);
}
}
@ -178,7 +194,7 @@ void Receiver::processNRZIBit(uint8_t bit)
if ( mRXPacket->size() >= MAX_AIS_RX_PACKET_SIZE )
{
// Start over
startReceiving(mChannel);
startReceiving(mChannel, false);
return;
}
@ -186,7 +202,7 @@ void Receiver::processNRZIBit(uint8_t bit)
if ( mOneBitCount >= 7 )
{
// Bad packet!
startReceiving(mChannel);
startReceiving(mChannel, false);
return;
}
@ -200,7 +216,7 @@ void Receiver::processNRZIBit(uint8_t bit)
{
mBitState = BIT_STATE_PREAMBLE_SYNC;
pushPacket();
startReceiving(mChannel);
startReceiving(mChannel, false);
}
else
{

View File

@ -90,7 +90,7 @@ void Transceiver::processEvent(const Event &e)
void Transceiver::transmitCW(VHFChannel channel)
{
startReceiving(channel);
startReceiving(channel, false);
configureGPIOsForTX(TX_POWER_LEVEL);
SET_PROPERTY_PARAMS p;
p.Group = 0x20;
@ -155,9 +155,9 @@ void Transceiver::configureGPIOsForTX(tx_power_level powerLevel)
setTXPower(powerLevel);
}
void Transceiver::startListening(VHFChannel channel)
void Transceiver::startListening(VHFChannel channel, bool reconfigGPIOs)
{
Receiver::startListening(channel);
Receiver::startListening(channel, reconfigGPIOs);
}
void Transceiver::assignTXPacket(TXPacket *p)
@ -231,7 +231,7 @@ void Transceiver::onBitClock()
if ( mTXPacket->eof() )
{
mLastTXTime = mUTC;
startReceiving(mChannel);
startReceiving(mChannel, true);
gRadioState = RADIO_RECEIVING;
reportTXEvent();
TXPacketPool::instance().deleteTXPacket(mTXPacket);
@ -267,7 +267,7 @@ void Transceiver::timeSlotStarted(uint32_t slot)
// Switch channel if we have a transmission scheduled and we're not on the right channel
if ( gRadioState == RADIO_RECEIVING && mTXPacket && mTXPacket->channel() != mChannel )
startReceiving(mTXPacket->channel());
startReceiving(mTXPacket->channel(), false);
}
void Transceiver::startTransmitting()
@ -306,9 +306,9 @@ void Transceiver::startTransmitting()
#endif
}
void Transceiver::startReceiving(VHFChannel channel)
void Transceiver::startReceiving(VHFChannel channel, bool reconfigGPIOs)
{
Receiver::startReceiving(channel);
Receiver::startReceiving(channel, reconfigGPIOs);
}
void Transceiver::configureGPIOsForRX()

View File

@ -477,7 +477,7 @@ uint32_t bsp_get_system_clock()
uint8_t bsp_tx_spi_byte(uint8_t data)
{
uint8_t result = 0;
HAL_SPI_TransmitReceive(&hspi1, &data, &result, 1, 10);
HAL_SPI_TransmitReceive(&hspi1, &data, &result, 1, 2);
return result;
}