Move code into BasebandThread.

This commit is contained in:
Jared Boone 2015-12-10 14:41:07 -08:00
parent 83bf2a9a36
commit 82f367dfea

View File

@ -102,6 +102,8 @@ private:
const char* const name; const char* const name;
}; };
static constexpr auto direction = baseband::Direction::Receive;
class BasebandThread : public ThreadBase { class BasebandThread : public ThreadBase {
public: public:
BasebandThread( BasebandThread(
@ -116,6 +118,23 @@ public:
); );
} }
void set_configuration(const BasebandConfiguration& new_configuration) {
if( new_configuration.mode != baseband_configuration.mode ) {
disable();
// TODO: Timing problem around disabling DMA and nulling and deleting old processor
auto old_p = baseband_processor;
baseband_processor = nullptr;
delete old_p;
baseband_processor = create_processor(new_configuration.mode);
enable();
}
baseband_configuration = new_configuration;
}
Thread* thread_main { nullptr }; Thread* thread_main { nullptr };
Thread* thread_rssi { nullptr }; Thread* thread_rssi { nullptr };
BasebandProcessor* baseband_processor { nullptr }; BasebandProcessor* baseband_processor { nullptr };
@ -151,6 +170,36 @@ private:
); );
} }
} }
BasebandProcessor* create_processor(const int32_t mode) {
switch(mode) {
case 0: return new NarrowbandAMAudio();
case 1: return new NarrowbandFMAudio();
case 2: return new WidebandFMAudio();
case 3: return new AISProcessor();
case 4: return new WidebandSpectrum();
case 5: return new TPMSProcessor();
case 6: return new ERTProcessor();
default: return nullptr;
}
}
void disable() {
if( baseband_processor ) {
i2s::i2s0::tx_mute();
baseband::dma::disable();
rf::rssi::stop();
}
}
void enable() {
if( baseband_processor ) {
if( direction == baseband::Direction::Receive ) {
rf::rssi::start();
}
baseband::dma::enable(direction);
}
}
}; };
class RSSIThread : public ThreadBase { class RSSIThread : public ThreadBase {
@ -319,21 +368,6 @@ private:
} }
}; };
static constexpr auto direction = baseband::Direction::Receive;
static BasebandProcessor* create_processor(const int32_t mode) {
switch(mode) {
case 0: return new NarrowbandAMAudio();
case 1: return new NarrowbandFMAudio();
case 2: return new WidebandFMAudio();
case 3: return new AISProcessor();
case 4: return new WidebandSpectrum();
case 5: return new TPMSProcessor();
case 6: return new ERTProcessor();
default: return nullptr;
}
}
int main(void) { int main(void) {
init(); init();
@ -346,30 +380,7 @@ int main(void) {
message_handlers.register_handler(Message::ID::BasebandConfiguration, message_handlers.register_handler(Message::ID::BasebandConfiguration,
[&message_handlers](const Message* const p) { [&message_handlers](const Message* const p) {
auto message = reinterpret_cast<const BasebandConfigurationMessage*>(p); auto message = reinterpret_cast<const BasebandConfigurationMessage*>(p);
if( message->configuration.mode != baseband_thread.baseband_configuration.mode ) { baseband_thread.set_configuration(message->configuration);
if( baseband_thread.baseband_processor ) {
i2s::i2s0::tx_mute();
baseband::dma::disable();
rf::rssi::stop();
}
// TODO: Timing problem around disabling DMA and nulling and deleting old processor
auto old_p = baseband_thread.baseband_processor;
baseband_thread.baseband_processor = nullptr;
delete old_p;
baseband_thread.baseband_processor = create_processor(message->configuration.mode);
if( baseband_thread.baseband_processor ) {
if( direction == baseband::Direction::Receive ) {
rf::rssi::start();
}
baseband::dma::enable(direction);
}
}
baseband_thread.baseband_configuration = message->configuration;
} }
); );