mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-01-12 15:33:38 +00:00
Change baseband, RSSI threads to be more RAII.
This commit is contained in:
parent
2b7e763619
commit
f8a473d56b
@ -48,13 +48,23 @@ static baseband::SGPIO baseband_sgpio;
|
||||
|
||||
WORKING_AREA(baseband_thread_wa, 4096);
|
||||
|
||||
Thread* BasebandThread::start(const tprio_t priority) {
|
||||
return chThdCreateStatic(baseband_thread_wa, sizeof(baseband_thread_wa),
|
||||
Thread* BasebandThread::thread = nullptr;
|
||||
|
||||
BasebandThread::BasebandThread(const tprio_t priority) {
|
||||
thread = chThdCreateStatic(baseband_thread_wa, sizeof(baseband_thread_wa),
|
||||
priority, ThreadBase::fn,
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
BasebandThread::~BasebandThread() {
|
||||
if( thread ) {
|
||||
chThdTerminate(thread);
|
||||
chThdWait(thread);
|
||||
thread = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void BasebandThread::set_configuration(const BasebandConfiguration& new_configuration) {
|
||||
if( new_configuration.mode != baseband_configuration.mode ) {
|
||||
disable();
|
||||
@ -93,7 +103,7 @@ void BasebandThread::run() {
|
||||
);
|
||||
//baseband::dma::allocate(4, 2048);
|
||||
|
||||
while(true) {
|
||||
while( !chThdShouldTerminate() ) {
|
||||
// TODO: Place correct sampling rate into buffer returned here:
|
||||
const auto buffer_tmp = baseband::dma::wait_for_rx_buffer();
|
||||
if( buffer_tmp ) {
|
||||
@ -127,15 +137,11 @@ void BasebandThread::disable() {
|
||||
i2s::i2s0::tx_mute();
|
||||
baseband::dma::disable();
|
||||
baseband_sgpio.streaming_disable();
|
||||
rf::rssi::stop();
|
||||
}
|
||||
}
|
||||
|
||||
void BasebandThread::enable() {
|
||||
if( baseband_processor ) {
|
||||
if( direction() == baseband::Direction::Receive ) {
|
||||
rf::rssi::start();
|
||||
}
|
||||
baseband_sgpio.configure(direction());
|
||||
baseband::dma::enable(direction());
|
||||
baseband_sgpio.streaming_enable();
|
||||
|
@ -30,7 +30,8 @@
|
||||
|
||||
class BasebandThread : public ThreadBase {
|
||||
public:
|
||||
Thread* start(const tprio_t priority);
|
||||
BasebandThread(const tprio_t priority);
|
||||
~BasebandThread();
|
||||
|
||||
void on_message(const Message* const message);
|
||||
|
||||
@ -41,6 +42,8 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
static Thread* thread;
|
||||
|
||||
BasebandProcessor* baseband_processor { nullptr };
|
||||
|
||||
BasebandConfiguration baseband_configuration;
|
||||
|
@ -54,9 +54,6 @@ Thread* EventDispatcher::thread_event_loop = nullptr;
|
||||
void EventDispatcher::run() {
|
||||
thread_event_loop = chThdSelf();
|
||||
|
||||
rssi_thread.start(NORMALPRIO + 10);
|
||||
baseband_thread.start(NORMALPRIO + 20);
|
||||
|
||||
lpc43xx::creg::m0apptxevent::enable();
|
||||
|
||||
while(is_running) {
|
||||
|
@ -50,8 +50,8 @@ public:
|
||||
private:
|
||||
static Thread* thread_event_loop;
|
||||
|
||||
BasebandThread baseband_thread;
|
||||
RSSIThread rssi_thread;
|
||||
BasebandThread baseband_thread { NORMALPRIO + 20 };
|
||||
RSSIThread rssi_thread { NORMALPRIO + 10 };
|
||||
|
||||
bool is_running = true;
|
||||
|
||||
|
@ -30,20 +30,32 @@
|
||||
|
||||
WORKING_AREA(rssi_thread_wa, 128);
|
||||
|
||||
Thread* RSSIThread::start(const tprio_t priority) {
|
||||
return chThdCreateStatic(rssi_thread_wa, sizeof(rssi_thread_wa),
|
||||
Thread* RSSIThread::thread = nullptr;
|
||||
|
||||
RSSIThread::RSSIThread(const tprio_t priority) {
|
||||
thread = chThdCreateStatic(rssi_thread_wa, sizeof(rssi_thread_wa),
|
||||
priority, ThreadBase::fn,
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
RSSIThread::~RSSIThread() {
|
||||
if( thread ) {
|
||||
chThdTerminate(thread);
|
||||
chThdWait(thread);
|
||||
thread = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void RSSIThread::run() {
|
||||
rf::rssi::init();
|
||||
rf::rssi::dma::allocate(4, 400);
|
||||
|
||||
RSSIStatisticsCollector stats;
|
||||
|
||||
while(true) {
|
||||
rf::rssi::start();
|
||||
|
||||
while( !chThdShouldTerminate() ) {
|
||||
// TODO: Place correct sampling rate into buffer returned here:
|
||||
const auto buffer_tmp = rf::rssi::dma::wait_for_buffer();
|
||||
const rf::rssi::buffer_t buffer {
|
||||
@ -59,5 +71,6 @@ void RSSIThread::run() {
|
||||
);
|
||||
}
|
||||
|
||||
rf::rssi::stop();
|
||||
rf::rssi::dma::free();
|
||||
}
|
||||
|
@ -30,11 +30,14 @@
|
||||
|
||||
class RSSIThread : public ThreadBase {
|
||||
public:
|
||||
Thread* start(const tprio_t priority);
|
||||
RSSIThread(const tprio_t priority);
|
||||
~RSSIThread();
|
||||
|
||||
private:
|
||||
void run() override;
|
||||
|
||||
static Thread* thread;
|
||||
|
||||
const uint32_t sampling_rate { 400000 };
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user