Change baseband, RSSI threads to be more RAII.

This commit is contained in:
Jared Boone 2016-06-24 15:34:49 -07:00
parent 2b7e763619
commit f8a473d56b
6 changed files with 39 additions and 17 deletions

View file

@ -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();
}