Merge fixing, commit to catch up on recent files

This commit is contained in:
furrtek
2016-02-04 10:27:53 +01:00
parent 44638e504b
commit 6e496e2b26
90 changed files with 2257 additions and 1428 deletions

View File

@@ -1 +1 @@
Basic RX/TX stuff for testing :)
Original firmware's functionalities: Receiver.

View File

@@ -50,121 +50,6 @@
#include <cstdint>
#include <cstddef>
#include <array>
#include <string>
#include <bitset>
class ThreadBase {
public:
constexpr ThreadBase(
const char* const name
) : name { name }
{
}
static msg_t fn(void* arg) {
auto obj = static_cast<ThreadBase*>(arg);
chRegSetThreadName(obj->name);
obj->run();
return 0;
}
virtual void run() = 0;
private:
const char* const name;
};
class BasebandThread : public ThreadBase {
public:
BasebandThread(
) : ThreadBase { "baseband" }
{
}
Thread* start(const tprio_t priority) {
return chThdCreateStatic(wa, sizeof(wa),
priority, ThreadBase::fn,
this
);
}
Thread* thread_main { nullptr };
Thread* thread_rssi { nullptr };
BasebandProcessor* baseband_processor { nullptr };
BasebandConfiguration baseband_configuration;
private:
WORKING_AREA(wa, 2048);
void run() override {
BasebandStatsCollector stats {
chSysGetIdleThread(),
thread_main,
thread_rssi,
chThdSelf()
};
while(true) {
// TODO: Place correct sampling rate into buffer returned here:
const auto buffer_tmp = baseband::dma::wait_for_rx_buffer();
const buffer_c8_t buffer {
buffer_tmp.p, buffer_tmp.count, baseband_configuration.sampling_rate
};
if( baseband_processor ) {
baseband_processor->execute(buffer);
}
stats.process(buffer,
[](const BasebandStatistics statistics) {
const BasebandStatisticsMessage message { statistics };
shared_memory.application_queue.push(message);
}
);
}
}
};
class RSSIThread : public ThreadBase {
public:
RSSIThread(
) : ThreadBase { "rssi" }
{
}
Thread* start(const tprio_t priority) {
return chThdCreateStatic(wa, sizeof(wa),
priority, ThreadBase::fn,
this
);
}
uint32_t sampling_rate { 400000 };
private:
WORKING_AREA(wa, 128);
void run() override {
RSSIStatisticsCollector stats;
while(true) {
// 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 {
buffer_tmp.p, buffer_tmp.count, sampling_rate
};
stats.process(
buffer,
[](const RSSIStatistics statistics) {
const RSSIStatisticsMessage message { statistics };
shared_memory.application_queue.push(message);
}
);
}
}
};
extern "C" {
@@ -187,9 +72,6 @@ void __late_init(void) {
}
static BasebandThread baseband_thread;
static RSSIThread rssi_thread;
static void init() {
i2s::i2s0::configure(
audio::i2s0_config_tx,
@@ -208,31 +90,9 @@ static void init() {
gpdma::controller.enable();
nvicEnableVector(DMA_IRQn, CORTEX_PRIORITY_MASK(LPC_DMA_IRQ_PRIORITY));
baseband::dma::init();
rf::rssi::init();
touch::dma::init();
const auto thread_main = chThdSelf();
const auto thread_rssi = rssi_thread.start(NORMALPRIO + 10);
baseband_thread.thread_main = thread_main;
baseband_thread.thread_rssi = thread_rssi;
baseband_thread.start(NORMALPRIO + 20);
}
static void shutdown() {
// TODO: Is this complete?
nvicDisableVector(DMA_IRQn);
m0apptxevent_interrupt_disable();
chSysDisable();
systick_stop();
touch::dma::allocate();
touch::dma::enable();
}
static void halt() {
@@ -242,146 +102,27 @@ static void halt() {
}
}
class EventDispatcher {
public:
MessageHandlerMap& message_handlers() {
return message_map;
}
static void shutdown() {
// TODO: Is this complete?
nvicDisableVector(DMA_IRQn);
chSysDisable();
void run() {
while(is_running) {
const auto events = wait();
dispatch(events);
}
}
systick_stop();
void request_stop() {
is_running = false;
}
ShutdownMessage shutdown_message;
shared_memory.application_queue.push(shutdown_message);
private:
MessageHandlerMap message_map;
bool is_running = true;
eventmask_t wait() {
return chEvtWaitAny(ALL_EVENTS);
}
void dispatch(const eventmask_t events) {
if( events & EVT_MASK_BASEBAND ) {
handle_baseband_queue();
}
if( events & EVT_MASK_SPECTRUM ) {
handle_spectrum();
}
}
void handle_baseband_queue() {
std::array<uint8_t, Message::MAX_SIZE> message_buffer;
while(Message* const message = shared_memory.baseband_queue.pop(message_buffer)) {
message_map.send(message);
}
}
void handle_spectrum() {
if( baseband_thread.baseband_processor ) {
baseband_thread.baseband_processor->update_spectrum();
}
}
};
static constexpr auto direction = baseband::Direction::Receive;
halt();
}
int main(void) {
init();
events_initialize(chThdSelf());
m0apptxevent_interrupt_enable();
EventDispatcher event_dispatcher;
auto& message_handlers = event_dispatcher.message_handlers();
message_handlers.register_handler(Message::ID::BasebandConfiguration,
[&message_handlers](const Message* const p) {
auto message = reinterpret_cast<const BasebandConfigurationMessage*>(p);
if( message->configuration.mode != baseband_thread.baseband_configuration.mode ) {
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;
switch(message->configuration.mode) {
case 0:
baseband_thread.baseband_processor = new NarrowbandAMAudio();
break;
case 1:
baseband_thread.baseband_processor = new NarrowbandFMAudio();
break;
case 2:
baseband_thread.baseband_processor = new WidebandFMAudio();
break;
case 3:
baseband_thread.baseband_processor = new AISProcessor();
break;
case 4:
baseband_thread.baseband_processor = new WidebandSpectrum();
break;
case 5:
baseband_thread.baseband_processor = new TPMSProcessor();
break;
default:
break;
}
if( baseband_thread.baseband_processor ) {
if( direction == baseband::Direction::Receive ) {
rf::rssi::start();
}
baseband::dma::enable(direction);
}
}
baseband_thread.baseband_configuration = message->configuration;
}
);
message_handlers.register_handler(Message::ID::Shutdown,
[&event_dispatcher](const Message* const) {
event_dispatcher.request_stop();
}
);
/* TODO: Ensure DMAs are configured to point at first LLI in chain. */
if( direction == baseband::Direction::Receive ) {
rf::rssi::dma::allocate(4, 400);
}
touch::dma::allocate();
touch::dma::enable();
const auto baseband_buffer =
new std::array<baseband::sample_t, 8192>();
baseband::dma::configure(
baseband_buffer->data(),
direction
);
EventDispatcher event_dispatcher;
event_dispatcher.run();
shutdown();

View File

@@ -1 +1 @@
First module
Receiver

View File

@@ -25,30 +25,17 @@
using namespace lpc43xx;
void AFSKRXProcessor::execute(buffer_c8_t buffer) {
void AFSKRXProcessor::execute(const buffer_c8_t& buffer) {
if( !configured ) {
return;
}
/* Called every 2048/3072000 second -- 1500Hz. */
auto decimator_out = decimator.execute(buffer);
const buffer_c16_t work_baseband_buffer {
(complex16_t*)decimator_out.p,
sizeof(*decimator_out.p) * decimator_out.count
};
/* 96kHz complex<int16_t>[64]
* -> FIR filter, <6kHz (0.063fs) pass, gain 1.0
* -> 48kHz int16_t[32] */
auto channel = channel_filter.execute(decimator_out, work_baseband_buffer);
const buffer_s16_t work_audio_buffer {
(int16_t*)decimator_out.p,
sizeof(*decimator_out.p) * decimator_out.count
};
/* 48kHz complex<int16_t>[32]
* -> FM demodulation
* -> 48kHz int16_t[32] */
auto audio = demod.execute(channel, work_audio_buffer);
const auto decim_0_out = decim_0.execute(buffer, dst_buffer);
const auto decim_1_out = decim_1.execute(decim_0_out, dst_buffer);
const auto channel_out = channel_filter.execute(decim_1_out, dst_buffer);
auto audio = demod.execute(channel_out, work_audio_buffer);
/*static uint64_t audio_present_history = 0;
const auto audio_present_now = squelch.execute(audio);
@@ -65,7 +52,7 @@ void AFSKRXProcessor::execute(buffer_c8_t buffer) {
}*/
//}
audio_hpf.execute_in_place(audio);
//audio_hpf.execute_in_place(audio);
for(size_t i=0; i<audio.count; i++) {
if (spur > 10) {
@@ -97,9 +84,9 @@ void AFSKRXProcessor::execute(buffer_c8_t buffer) {
if (sc >= 600) {
sc = 0;
AFSKDataMessage message;
memcpy(message.data,aud,128*2);
shared_memory.application_queue.push(message);
//AFSKDataMessage message;
//memcpy(message.data,aud,128*2);
//shared_memory.application_queue.push(message);
audc = 0;
} else {
sc++;
@@ -110,7 +97,7 @@ void AFSKRXProcessor::execute(buffer_c8_t buffer) {
audc++;
}
fill_audio_buffer(audio);
audio_output.write(audio);
}
void AFSKRXProcessor::data_handler(

View File

@@ -24,38 +24,35 @@
#include "baseband_processor.hpp"
#include "channel_decimator.hpp"
#include "dsp_decimate.hpp"
#include "dsp_demodulate.hpp"
#include "dsp_fir_taps.hpp"
#include "dsp_iir.hpp"
#include "dsp_iir_config.hpp"
#include "dsp_squelch.hpp"
#include "audio_output.hpp"
#include "message.hpp"
#include <cstdint>
#include <cstddef>
#include <bitset>
class AFSKRXProcessor : public BasebandProcessor {
public:
AFSKRXProcessor() {
decimator.set_decimation_factor(ChannelDecimator::DecimationFactor::By32);
channel_filter.configure(channel_filter_taps.taps, 2);
}
void execute(buffer_c8_t buffer) override;
void execute(const buffer_c8_t& buffer) override;
private:
ChannelDecimator decimator;
const fir_taps_real<64>& channel_filter_taps = taps_64_lp_042_078_tfilter;
dsp::decimate::FIRAndDecimateComplex channel_filter;
dsp::demodulate::FM demod { 48000, 5000 };
IIRBiquadFilter audio_hpf { audio_hpf_config };
//FMSquelch squelch;
std::array<complex16_t, 512> dst;
const buffer_c16_t dst_buffer {
dst.data(),
dst.size()
};
const buffer_f32_t work_audio_buffer {
(float*)dst.data(),
sizeof(dst) / sizeof(float)
};
dsp::decimate::FIRAndDecimateComplex channel_filter;
dsp::demodulate::FM demod; // 48000 5000
dsp::decimate::FIRC8xR16x24FS4Decim8 decim_0;
dsp::decimate::FIRC16xR16x32Decim8 decim_1;
AudioOutput audio_output;
uint16_t bit_timer = 0, freq_timer = 0;
uint16_t sc;
uint8_t audc, spur, sign, prev_sign, bit = 0;
@@ -63,6 +60,9 @@ private:
int16_t aud[128];
void data_handler(const double data);
bool configured { false };
void configure(const NBFMConfigureMessage& message);
};
#endif/*__PROC_TPMS_H__*/

View File

@@ -24,46 +24,6 @@
#include <cstdint>
#include <cstddef>
void SIGFRXProcessor::execute(buffer_c8_t buffer) {
void SIGFRXProcessor::execute(const buffer_c8_t& buffer) {
/* Called every 2048/3072000 second -- 1500Hz. */
auto decimator_out = decimator.execute(buffer);
const buffer_c16_t work_baseband_buffer {
(complex16_t*)decimator_out.p,
sizeof(*decimator_out.p) * decimator_out.count
};
/* 192kHz complex<int16_t>[64]
* -> 96kHz int16_t[32] */
//auto channel = channel_filter.execute(decimator_out, work_baseband_buffer);
// TODO: Feed channel_stats post-decimation data?
feed_channel_spectrum(
decimator_out,
41000, //decimator_out.sampling_rate * channel_filter_taps.pass_frequency_normalized,
70000 //decimator_out.sampling_rate * channel_filter_taps.stop_frequency_normalized
);
/*const buffer_s16_t work_audio_buffer {
(int16_t*)decimator_out.p,
sizeof(*decimator_out.p) * decimator_out.count
};
*
auto audio = demod.execute(channel, work_audio_buffer);
static uint64_t audio_present_history = 0;
const auto audio_present_now = squelch.execute(audio);
audio_present_history = (audio_present_history << 1) | (audio_present_now ? 1 : 0);
const bool audio_present = (audio_present_history != 0);
if( !audio_present ) {
// Zero audio buffer.
for(size_t i=0; i<audio.count; i++) {
audio.p[i] = 0;
}
}
audio_hpf.execute_in_place(audio);
fill_audio_buffer(audio);*/
}

View File

@@ -24,31 +24,15 @@
#include "baseband_processor.hpp"
#include "channel_decimator.hpp"
#include "dsp_decimate.hpp"
#include "dsp_demodulate.hpp"
#include "dsp_fir_taps.hpp"
#include "dsp_iir.hpp"
#include "dsp_iir_config.hpp"
#include "dsp_squelch.hpp"
class SIGFRXProcessor : public BasebandProcessor {
public:
SIGFRXProcessor() {
decimator.set_decimation_factor(ChannelDecimator::DecimationFactor::By16);
//channel_filter.configure(channel_filter_taps.taps, 1);
}
void execute(buffer_c8_t buffer) override;
void execute(const buffer_c8_t& buffer) override;
private:
ChannelDecimator decimator;
//const fir_taps_real<64>& channel_filter_taps = taps_64_lp_410_700_tfilter; //taps_64_lp_104_140_tfilter
//dsp::decimate::FIRAndDecimateComplex channel_filter;
dsp::demodulate::FM demod { 48000, 7500 };
IIRBiquadFilter audio_hpf { audio_hpf_config };
FMSquelch squelch;
};
#endif