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