mirror of
https://github.com/peterantypas/maiana.git
synced 2025-05-28 05:10:40 -07:00
That wasn't a bare metal build :(
This commit is contained in:
parent
ddf5e39e9b
commit
512c2c892a
@ -48,7 +48,7 @@ public:
|
||||
/*
|
||||
* We push events here to be processed by the dispatching task
|
||||
*/
|
||||
void push(Event *event);
|
||||
bool push(Event *event);
|
||||
|
||||
/*
|
||||
* This method must be called repeatedly by an RTOS task or main() (never an ISR)
|
||||
|
32
latest/Firmware/Inc/Stats.hpp
Normal file
32
latest/Firmware/Inc/Stats.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Stats.hpp
|
||||
*
|
||||
* Created on: Nov 4, 2020
|
||||
* Author: peter
|
||||
*/
|
||||
|
||||
#ifndef INC_STATS_HPP_
|
||||
#define INC_STATS_HPP_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "EventQueue.hpp"
|
||||
|
||||
class Stats : public EventConsumer
|
||||
{
|
||||
public:
|
||||
static Stats &instance();
|
||||
void init();
|
||||
|
||||
void processEvent(const Event &e);
|
||||
|
||||
private:
|
||||
Stats();
|
||||
public:
|
||||
int eventQueuePopFailures = 0;
|
||||
int eventQueuePushFailures = 0;
|
||||
int rxPacketPoolPopFailures = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* INC_STATS_HPP_ */
|
@ -24,8 +24,8 @@
|
||||
#include "radio_config.h"
|
||||
#include "TXPowerSettings.h"
|
||||
|
||||
// Set to non-zero to enable FreeRTOS instead of "bare metal". Doesn't add much value at the moment.
|
||||
#define RTOS 0
|
||||
// Define to enable FreeRTOS instead of "bare metal". Doesn't add much value at the moment.
|
||||
//#define RTOS
|
||||
|
||||
/**
|
||||
* If this is defined, the device transmits carrier on channel 87 (161.975MHz) for 1 second after reset.
|
||||
@ -74,7 +74,7 @@
|
||||
#define MAX_TX_PACKETS_IN_QUEUE 4
|
||||
|
||||
// Headroom above noise floor (in dB) that constitutes a clear channel for transmission
|
||||
#define TX_CCA_HEADROOM 6
|
||||
#define TX_CCA_HEADROOM 3
|
||||
|
||||
// Transmission intervals in seconds
|
||||
#define MIN_TX_INTERVAL 5
|
||||
|
@ -29,9 +29,6 @@
|
||||
#include "task.h"
|
||||
#include "bsp.hpp"
|
||||
|
||||
#define EVENT_QUEUE_SIZE 50
|
||||
|
||||
//static Event* __queue[EVENT_QUEUE_SIZE];
|
||||
|
||||
EventQueue &EventQueue::instance()
|
||||
{
|
||||
@ -46,34 +43,28 @@ EventQueue::EventQueue()
|
||||
|
||||
void EventQueue::init()
|
||||
{
|
||||
//mQueueHandle = xQueueCreateStatic(EVENT_QUEUE_SIZE, sizeof(Event*), (uint8_t*)&__queue[0], &mQueue);
|
||||
//configASSERT(mQueueHandle);
|
||||
}
|
||||
|
||||
void EventQueue::push(Event *e)
|
||||
bool EventQueue::push(Event *e)
|
||||
{
|
||||
//if ( xTaskGetSchedulerState() != taskSCHEDULER_RUNNING )
|
||||
//return;
|
||||
|
||||
//BaseType_t xHighPriorityTaskWoken = pdTRUE;
|
||||
if ( Utils::inISR() )
|
||||
{
|
||||
//bsp_signal_high();
|
||||
//xQueueSendFromISR(mQueueHandle, &e, &xHighPriorityTaskWoken);
|
||||
//bsp_signal_low();
|
||||
if ( !mISRQueue.push(e) )
|
||||
EventPool::instance().deleteEvent(e);
|
||||
#if 0
|
||||
if ( xHighPriorityTaskWoken )
|
||||
portYIELD_FROM_ISR(xHighPriorityTaskWoken);
|
||||
#endif
|
||||
{
|
||||
EventPool::instance().deleteEvent(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//xQueueSend(mQueueHandle, &e, 0);
|
||||
if ( !mTaskQueue.push(e) )
|
||||
EventPool::instance().deleteEvent(e);
|
||||
{
|
||||
EventPool::instance().deleteEvent(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void EventQueue::addObserver(EventConsumer *c, uint32_t eventMask)
|
||||
|
@ -205,9 +205,13 @@ uint8_t RFIC::readRSSI()
|
||||
{
|
||||
MODEM_STATUS_REPLY s;
|
||||
if ( sendCmd(GET_MODEM_STATUS, NULL, 0, &s, sizeof s) )
|
||||
return s.CurrentRSSI;
|
||||
{
|
||||
return s.CurrentRSSI;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool RFIC::checkStatus()
|
||||
|
@ -24,6 +24,8 @@
|
||||
#include "EventQueue.hpp"
|
||||
#include "NoiseFloorDetector.hpp"
|
||||
#include "bsp.hpp"
|
||||
#include "Stats.hpp"
|
||||
|
||||
|
||||
Receiver::Receiver(GPIO_TypeDef *sdnPort, uint32_t sdnPin, GPIO_TypeDef *csPort, uint32_t csPin,
|
||||
GPIO_TypeDef *dataPort, uint32_t dataPin,
|
||||
@ -119,13 +121,16 @@ void Receiver::resetBitScanner()
|
||||
|
||||
void Receiver::onBitClock()
|
||||
{
|
||||
bsp_signal_high();
|
||||
++mSlotBitNumber;
|
||||
|
||||
// Don't waste time processing bits when the transceiver is transmitting
|
||||
if ( gRadioState == RADIO_TRANSMITTING )
|
||||
return;
|
||||
{
|
||||
bsp_signal_low();
|
||||
return;
|
||||
}
|
||||
|
||||
bsp_signal_high();
|
||||
|
||||
if ( !mRXPacket )
|
||||
{
|
||||
@ -153,8 +158,7 @@ void Receiver::onBitClock()
|
||||
else if ( mTimeSlot != 0xffffffff && mSlotBitNumber != 0xffff &&
|
||||
mTimeSlot % 17 == mChipID && mSlotBitNumber == CCA_SLOT_BIT - 1 )
|
||||
{
|
||||
uint8_t rssi = reportRSSI();
|
||||
mRXPacket->setRSSI(rssi);
|
||||
reportRSSI();
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -224,13 +228,13 @@ Receiver::Action Receiver::processNRZIBit(uint8_t bit)
|
||||
// Start over
|
||||
return RESTART_RX;
|
||||
}
|
||||
#if 0
|
||||
|
||||
// We can never have 7 consecutive "1" bits in a proper NRZI encoded packet
|
||||
if ( mOneBitCount >= 7 )
|
||||
{
|
||||
// Bad packet!
|
||||
return RESTART_RX;
|
||||
}
|
||||
#endif
|
||||
|
||||
mLastNRZIBit = bit;
|
||||
mBitWindow <<= 1;
|
||||
mBitWindow |= decodedBit;
|
||||
@ -302,12 +306,23 @@ void Receiver::pushPacket()
|
||||
{
|
||||
//bsp_signal_high();
|
||||
p->rxPacket = mRXPacket;
|
||||
EventQueue::instance().push(p);
|
||||
if ( !EventQueue::instance().push(p) )
|
||||
{
|
||||
// Count this
|
||||
++Stats::instance().eventQueuePushFailures;
|
||||
}
|
||||
//bsp_signal_low();
|
||||
mRXPacket = EventPool::instance().newRXPacket();
|
||||
if ( !mRXPacket )
|
||||
{
|
||||
// TODO: Count this
|
||||
++Stats::instance().rxPacketPoolPopFailures;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Count this
|
||||
++Stats::instance().eventQueuePopFailures;
|
||||
/**
|
||||
* We're out of resources so just keep using the existing packet.
|
||||
* If this happens, the most logical outcome is a watchdog reset
|
||||
@ -323,9 +338,11 @@ void Receiver::pushPacket()
|
||||
*/
|
||||
uint8_t Receiver::reportRSSI()
|
||||
{
|
||||
//bsp_signal_high();
|
||||
uint8_t rssi = readRSSI();
|
||||
char channel = AIS_CHANNELS[mChannel].designation;
|
||||
NoiseFloorDetector::instance().report(channel, rssi);
|
||||
//bsp_signal_low();
|
||||
return rssi;
|
||||
}
|
||||
|
||||
|
48
latest/Firmware/Src/Stats.cpp
Normal file
48
latest/Firmware/Src/Stats.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Stats.cpp
|
||||
*
|
||||
* Created on: Nov 4, 2020
|
||||
* Author: peter
|
||||
*/
|
||||
|
||||
|
||||
#include "Stats.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "EventQueue.hpp"
|
||||
|
||||
static int count = 0;
|
||||
|
||||
Stats &Stats::instance()
|
||||
{
|
||||
static Stats __instance;
|
||||
return __instance;
|
||||
}
|
||||
|
||||
Stats::Stats()
|
||||
{
|
||||
EventQueue::instance().addObserver(this, CLOCK_EVENT);
|
||||
}
|
||||
|
||||
void Stats::init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Stats::processEvent(const Event &e)
|
||||
{
|
||||
++count;
|
||||
if ( count % 60 == 0 )
|
||||
{
|
||||
char buff[32];
|
||||
sprintf(buff, "$PAISTC,%d,%d,%d*", eventQueuePopFailures, eventQueuePushFailures, rxPacketPoolPopFailures);
|
||||
Utils::completeNMEA(buff);
|
||||
|
||||
printf_serial(buff);
|
||||
count = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -217,7 +217,7 @@ void Transceiver::onBitClock()
|
||||
}
|
||||
else if ( mUTC && mSlotBitNumber == CCA_SLOT_BIT && mTXPacket->channel() == mChannel )
|
||||
{
|
||||
int rssi = mRXPacket->rssi();
|
||||
int rssi = readRSSI();
|
||||
int nf = NoiseFloorDetector::instance().getNoiseFloor(AIS_CHANNELS[mChannel].designation);
|
||||
if ( rssi <= nf + TX_CCA_HEADROOM )
|
||||
{
|
||||
|
@ -337,13 +337,16 @@ void HAL_MspInit(void)
|
||||
/* UsageFault_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(UsageFault_IRQn, 0, 0);
|
||||
/* SVCall_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(SVCall_IRQn, 2, 0);
|
||||
HAL_NVIC_SetPriority(SVCall_IRQn, 10, 0);
|
||||
/* DebugMonitor_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(DebugMonitor_IRQn, 0, 0);
|
||||
/* PendSV_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(PendSV_IRQn, 2, 0);
|
||||
HAL_NVIC_SetPriority(PendSV_IRQn, 10, 0);
|
||||
/* SysTick_IRQn interrupt configuration */
|
||||
|
||||
#ifndef RTOS
|
||||
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
|
||||
#endif
|
||||
|
||||
/* USER CODE BEGIN MspInit 1 */
|
||||
|
||||
|
@ -28,6 +28,9 @@
|
||||
#include "CommandProcessor.hpp"
|
||||
#include "bsp.hpp"
|
||||
#include "printf_serial.h"
|
||||
#include "Stats.hpp"
|
||||
|
||||
|
||||
#ifdef RTOS
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
@ -59,6 +62,7 @@ void mainTask(void *params)
|
||||
Configuration::instance().init();
|
||||
CommandProcessor::instance().init();
|
||||
DataTerminal::instance().init();
|
||||
Stats::instance().init();
|
||||
|
||||
RXPacketProcessor packetProcessor;
|
||||
|
||||
|
@ -134,6 +134,7 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||
/* USER CODE END Callback 0 */
|
||||
if (htim->Instance == TIM6) {
|
||||
HAL_IncTick();
|
||||
HAL_SYSTICK_IRQHandler();
|
||||
}
|
||||
/* USER CODE BEGIN Callback 1 */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user