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

Reduced RSSI sampling to improve RX yield

This commit is contained in:
Peter Antypas 2020-11-03 13:57:55 -08:00
parent a565aaa16d
commit dc421cd0ce
9 changed files with 39 additions and 25 deletions

View File

@ -24,8 +24,6 @@
#include <map>
#include "CircularQueue.hpp"
#include "Events.hpp"
#include "FreeRTOS.h"
#include "queue.h"
using namespace std;
@ -58,8 +56,6 @@ public:
void dispatch();
private:
EventQueue();
//QueueHandle_t mQueueHandle;
//StaticQueue_t mQueue;
CircularQueue<Event*> mISRQueue;
CircularQueue<Event*> mTaskQueue;
map<EventConsumer *, uint32_t> mConsumers;

View File

@ -41,7 +41,8 @@ public:
GPIO_TypeDef *dataPort,
uint32_t dataPin,
GPIO_TypeDef *clockPort,
uint32_t clockPin);
uint32_t clockPin,
int chipId);
virtual ~RFIC();
@ -71,6 +72,7 @@ protected:
uint8_t mLastNRZIBit;
BitState mBitState;
bool mSPIBusy;
uint32_t mChipID;
};
#endif /* RFIC_HPP_ */

View File

@ -38,7 +38,8 @@ public:
GPIO_TypeDef *dataPort,
uint32_t dataPin,
GPIO_TypeDef *clockPort,
uint32_t clockPin);
uint32_t clockPin,
int chipId);
virtual ~Receiver();
@ -68,6 +69,7 @@ protected:
uint16_t mSlotBitNumber;
bool mSwitchAtNextSlot;
VHFChannel mSwitchToChannel;
uint32_t mTimeSlot = 0xffffffff;
};
#endif /* RECEIVER_HPP_ */

View File

@ -36,7 +36,8 @@ public:
GPIO_TypeDef *dataPort,
uint32_t dataPin,
GPIO_TypeDef *clockPort,
uint32_t clockPin);
uint32_t clockPin,
int chipId);
void onBitClock();

View File

@ -33,7 +33,8 @@ RFIC::RFIC(GPIO_TypeDef *sdnPort,
GPIO_TypeDef *dataPort,
uint32_t dataPin,
GPIO_TypeDef *clockPort,
uint32_t clockPin)
uint32_t clockPin,
int chipID)
{
mSDNP = sdnPort;
mCSPort = csPort;
@ -47,6 +48,7 @@ RFIC::RFIC(GPIO_TypeDef *sdnPort,
//mRSSIAdjustment = 0;
mSPIBusy = false;
mChipID = chipID;
if ( !isInitialized() )
powerOnReset();
@ -70,7 +72,7 @@ inline void RFIC::spiOff()
bool RFIC::sendCmd(uint8_t cmd, void* params, uint8_t paramLen, void* result, uint8_t resultLen)
{
mSPIBusy = true;
//bsp_signal_high();
spiOn();
bsp_tx_spi_byte(cmd);
@ -81,10 +83,14 @@ bool RFIC::sendCmd(uint8_t cmd, void* params, uint8_t paramLen, void* result, ui
bsp_tx_spi_byte(b[i]);
}
spiOff();
//bsp_signal_low();
//bsp_signal_high();
while ( readSPIResponse(result, resultLen) == false)
;
//bsp_signal_low();
mSPIBusy = false;
return true;
}

View File

@ -56,7 +56,7 @@ void RadioManager::init()
mTransceiverIC = new Transceiver(SDN1_PORT, SDN1_PIN,
CS1_PORT, CS1_PIN,
TRX_IC_DATA_PORT, TRX_IC_DATA_PIN,
TRX_IC_CLK_PORT, TRX_IC_CLK_PIN);
TRX_IC_CLK_PORT, TRX_IC_CLK_PIN, 0);
mTransceiverIC->init();
#ifndef TX_TEST_MODE
@ -64,7 +64,7 @@ void RadioManager::init()
mReceiverIC = new Receiver(SDN2_PORT, SDN2_PIN,
CS2_PORT, CS2_PIN,
RX_IC_DATA_PORT, RX_IC_DATA_PIN,
RX_IC_CLK_PORT, RX_IC_CLK_PIN);
RX_IC_CLK_PORT, RX_IC_CLK_PIN, 1);
mReceiverIC->init();
#endif

View File

@ -27,8 +27,8 @@
Receiver::Receiver(GPIO_TypeDef *sdnPort, uint32_t sdnPin, GPIO_TypeDef *csPort, uint32_t csPin,
GPIO_TypeDef *dataPort, uint32_t dataPin,
GPIO_TypeDef *clockPort, uint32_t clockPin)
: RFIC(sdnPort, sdnPin, csPort, csPin, dataPort, dataPin, clockPort, clockPin)
GPIO_TypeDef *clockPort, uint32_t clockPin, int chipId)
: RFIC(sdnPort, sdnPin, csPort, csPin, dataPort, dataPin, clockPort, clockPin, chipId)
{
mSlotBitNumber = 0xffff;
mSwitchAtNextSlot = false;
@ -85,7 +85,6 @@ void Receiver::startListening(VHFChannel channel, bool reconfigGPIOs)
configureGPIOsForRX();
}
// This takes 180us
mChannel = channel;
RX_OPTIONS options;
options.channel = AIS_CHANNELS[channel].ordinal;
@ -119,8 +118,7 @@ void Receiver::resetBitScanner()
* 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".
* Re-architecting will be necessary to resolve this.
*/
void Receiver::onBitClock()
@ -133,7 +131,8 @@ void Receiver::onBitClock()
uint8_t bit = HAL_GPIO_ReadPin(mDataPort, mDataPin);
processNRZIBit(bit);
if ( mSlotBitNumber != 0xffff && mSlotBitNumber++ == CCA_SLOT_BIT - 1 )
if ( mTimeSlot != 0xffffffff && mSlotBitNumber != 0xffff &&
mTimeSlot % 17 == mChipID && mSlotBitNumber++ == CCA_SLOT_BIT - 1 )
{
uint8_t rssi = reportRSSI();
mRXPacket->setRSSI(rssi);
@ -149,6 +148,7 @@ void Receiver::timeSlotStarted(uint32_t slot)
//DBG(" **** WTF??? Transmitting past slot boundary? **** \r\n");
mSlotBitNumber = 0;
mTimeSlot = slot;
if ( mBitState == BIT_STATE_IN_PACKET )
return;
@ -284,9 +284,12 @@ void Receiver::pushPacket()
uint8_t Receiver::reportRSSI()
{
bsp_signal_high();
uint8_t rssi = readRSSI();
bsp_signal_low();
char channel = AIS_CHANNELS[mChannel].designation;
NoiseFloorDetector::instance().report(channel, rssi);
return rssi;
}

View File

@ -29,8 +29,8 @@
Transceiver::Transceiver(GPIO_TypeDef *sdnPort, uint32_t sdnPin, GPIO_TypeDef *csPort,
uint32_t csPin, GPIO_TypeDef *dataPort, uint32_t dataPin,
GPIO_TypeDef *clockPort, uint32_t clockPin)
: Receiver(sdnPort, sdnPin, csPort, csPin, dataPort, dataPin, clockPort, clockPin)
GPIO_TypeDef *clockPort, uint32_t clockPin, int chipId)
: Receiver(sdnPort, sdnPin, csPort, csPin, dataPort, dataPin, clockPort, clockPin, chipId)
{
mTXPacket = NULL;
EventQueue::instance().addObserver(this, CLOCK_EVENT);

View File

@ -184,7 +184,7 @@ void bsp_hw_init()
HAL_TIM_Base_Init(&htim2);
HAL_NVIC_SetPriority(TIM2_IRQn, 5, 0);
HAL_NVIC_SetPriority(TIM2_IRQn, 6, 0);
HAL_NVIC_EnableIRQ(TIM2_IRQn);
// I2C
@ -220,11 +220,11 @@ void bsp_hw_init()
// RF IC clock interrupts
HAL_NVIC_SetPriority(EXTI1_IRQn, 5, 0);
HAL_NVIC_SetPriority(EXTI1_IRQn, 1, 0);
HAL_NVIC_EnableIRQ(EXTI1_IRQn);
HAL_NVIC_SetPriority(EXTI3_IRQn, 5, 0);
HAL_NVIC_SetPriority(EXTI3_IRQn, 1, 0);
HAL_NVIC_EnableIRQ(EXTI3_IRQn);
// This is our HAL tick timer now
@ -325,6 +325,10 @@ void HAL_MspInit(void)
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
/**
* Some of these interrupts will be managed and configured in FreeRTOS
*/
/* System interrupt init*/
/* MemoryManagement_IRQn interrupt configuration */
HAL_NVIC_SetPriority(MemoryManagement_IRQn, 0, 0);
@ -333,13 +337,13 @@ void HAL_MspInit(void)
/* UsageFault_IRQn interrupt configuration */
HAL_NVIC_SetPriority(UsageFault_IRQn, 0, 0);
/* SVCall_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SVCall_IRQn, 0, 0);
//HAL_NVIC_SetPriority(SVCall_IRQn, 2, 0);
/* DebugMonitor_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DebugMonitor_IRQn, 0, 0);
/* PendSV_IRQn interrupt configuration */
HAL_NVIC_SetPriority(PendSV_IRQn, 0, 0);
//HAL_NVIC_SetPriority(PendSV_IRQn, 2, 0);
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
//HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
/* USER CODE BEGIN MspInit 1 */