mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-21 06:51:01 +00:00
AFSK RX works (only Bell202 for now)
AFSK RX always logs to file Removed frequency and bw settings from modem setup view Updated binary Bugfix: Binary display shifted one bit Bugfix: Frequency manager views freezing if SD card not present Bugfix: Menuview blinking arrow not showing up at the right position Bugfix: Freeze if console written to while it's hidden Broken: LCR TX, needs UI update
This commit is contained in:
@@ -25,54 +25,119 @@
|
||||
|
||||
#include "event_m4.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
void AFSKRxProcessor::execute(const buffer_c8_t& buffer) {
|
||||
// This is called at 1500Hz
|
||||
// This is called at 3072000 / 2048 = 1500Hz
|
||||
|
||||
if (!configured) return;
|
||||
|
||||
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);
|
||||
// FM demodulation
|
||||
const auto decim_0_out = decim_0.execute(buffer, dst_buffer); // 2048 / 8 = 256 (512 I/Q samples)
|
||||
const auto decim_1_out = decim_1.execute(decim_0_out, dst_buffer); // 256 / 8 = 32 (64 I/Q samples)
|
||||
const auto channel_out = channel_filter.execute(decim_1_out, dst_buffer); // 32 / 2 = 16 (32 I/Q samples)
|
||||
|
||||
feed_channel_stats(channel_out);
|
||||
|
||||
auto audio = demod.execute(channel_out, audio_buffer);
|
||||
|
||||
audio_output.write(audio);
|
||||
|
||||
// Audio signal processing
|
||||
for (size_t c = 0; c < audio.count; c++) {
|
||||
|
||||
const int32_t sample_int = audio.p[c] * 32768.0f;
|
||||
const int32_t audio_sample = __SSAT(sample_int, 16);
|
||||
int32_t current_sample = __SSAT(sample_int, 16);
|
||||
|
||||
/*slicer_sr <<= 1;
|
||||
slicer_sr |= (audio_sample < 0); // Do we need hysteresis ?
|
||||
|
||||
// Detect transitions to adjust clock
|
||||
if ((slicer_sr ^ (slicer_sr >> 1)) & 1) {
|
||||
if (sphase < (0x8000u - sphase_delta_half))
|
||||
sphase += sphase_delta_eighth;
|
||||
current_sample /= 128;
|
||||
|
||||
// Delay line put
|
||||
delay_line[delay_line_index & 0x3F] = current_sample;
|
||||
|
||||
// Delay line get, and LPF
|
||||
sample_mixed = (delay_line[(delay_line_index - (samples_per_bit/2)) & 0x3F] * current_sample) / 4;
|
||||
sample_filtered = prev_mixed + sample_mixed + (prev_filtered / 2);
|
||||
|
||||
delay_line_index++;
|
||||
|
||||
prev_filtered = sample_filtered;
|
||||
prev_mixed = sample_mixed;
|
||||
|
||||
// Slice
|
||||
sample_bits <<= 1;
|
||||
sample_bits |= (sample_filtered < -20) ? 1 : 0;
|
||||
|
||||
// Check for "clean" transition: either 0011 or 1100
|
||||
if ((((sample_bits >> 2) ^ sample_bits) & 3) == 3) {
|
||||
// Adjust phase
|
||||
if (phase < 0x8000)
|
||||
phase += 0x800; // Is this a proper value ?
|
||||
else
|
||||
sphase -= sphase_delta_eighth;
|
||||
phase -= 0x800;
|
||||
}
|
||||
|
||||
sphase += sphase_delta;*/
|
||||
phase += phase_inc;
|
||||
|
||||
// Symbol time elapsed
|
||||
//if (sphase >= 0x10000u) {
|
||||
// sphase &= 0xFFFFu;
|
||||
if (phase >= 0x10000) {
|
||||
phase &= 0xFFFF;
|
||||
|
||||
rx_data <<= 1;
|
||||
rx_data |= 1;
|
||||
|
||||
bit_count++;
|
||||
if (bit_count == 8) {
|
||||
data_message.byte = rx_data;
|
||||
shared_memory.application_queue.push(data_message);
|
||||
bit_count = 0;
|
||||
if (trigger_word) {
|
||||
|
||||
// Continuous-stream value-triggered mode (AX.25) - UNTESTED
|
||||
word_bits <<= 1;
|
||||
word_bits |= (sample_bits & 1);
|
||||
|
||||
bit_counter++;
|
||||
|
||||
if (triggered) {
|
||||
if (bit_counter == word_length) {
|
||||
bit_counter = 0;
|
||||
|
||||
data_message.is_data = true;
|
||||
data_message.value = word_bits & word_mask;
|
||||
shared_memory.application_queue.push(data_message);
|
||||
}
|
||||
} else {
|
||||
if ((word_bits & word_mask) == trigger_value) {
|
||||
triggered = !triggered;
|
||||
bit_counter = 0;
|
||||
|
||||
data_message.is_data = true;
|
||||
data_message.value = trigger_value;
|
||||
shared_memory.application_queue.push(data_message);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// RS232-like modem mode
|
||||
if (state == WAIT_START) {
|
||||
if (!(sample_bits & 1)) {
|
||||
// Got start bit
|
||||
state = RECEIVE;
|
||||
bit_counter = 0;
|
||||
}
|
||||
} else if (state == WAIT_STOP) {
|
||||
if (sample_bits & 1) {
|
||||
// Got stop bit
|
||||
state = WAIT_START;
|
||||
}
|
||||
} else {
|
||||
word_bits <<= 1;
|
||||
word_bits |= (sample_bits & 1);
|
||||
|
||||
bit_counter++;
|
||||
}
|
||||
|
||||
if (bit_counter == word_length) {
|
||||
bit_counter = 0;
|
||||
state = WAIT_STOP;
|
||||
|
||||
data_message.is_data = true;
|
||||
data_message.value = word_bits;
|
||||
shared_memory.application_queue.push(data_message);
|
||||
}
|
||||
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,26 +147,39 @@ void AFSKRxProcessor::on_message(const Message* const message) {
|
||||
}
|
||||
|
||||
void AFSKRxProcessor::configure(const AFSKRxConfigureMessage& message) {
|
||||
constexpr size_t decim_0_input_fs = baseband_fs;
|
||||
/*constexpr size_t decim_0_input_fs = baseband_fs;
|
||||
constexpr size_t decim_0_output_fs = decim_0_input_fs / decim_0.decimation_factor;
|
||||
|
||||
constexpr size_t decim_1_input_fs = decim_0_output_fs;
|
||||
constexpr size_t decim_1_output_fs = decim_1_input_fs / decim_1.decimation_factor;
|
||||
|
||||
|
||||
constexpr size_t channel_filter_input_fs = decim_1_output_fs;
|
||||
const size_t channel_filter_output_fs = channel_filter_input_fs / 2;
|
||||
|
||||
const size_t demod_input_fs = channel_filter_output_fs;
|
||||
|
||||
decim_0.configure(taps_16k0_decim_0.taps, 33554432);
|
||||
decim_1.configure(taps_16k0_decim_1.taps, 131072);
|
||||
channel_filter.configure(taps_16k0_channel.taps, 2);
|
||||
demod.configure(demod_input_fs, 5000);
|
||||
const size_t demod_input_fs = channel_filter_output_fs;*/
|
||||
|
||||
bitrate = message.bitrate;
|
||||
sphase_delta = 0x10000u * bitrate / 24000;
|
||||
sphase_delta_half = sphase_delta / 2; // Just for speed
|
||||
sphase_delta_eighth = sphase_delta / 8;
|
||||
decim_0.configure(taps_11k0_decim_0.taps, 33554432);
|
||||
decim_1.configure(taps_11k0_decim_1.taps, 131072);
|
||||
channel_filter.configure(taps_11k0_channel.taps, 2);
|
||||
demod.configure(audio_fs, 5000);
|
||||
|
||||
audio_output.configure(audio_24k_hpf_300hz_config, audio_24k_deemph_300_6_config, 0);
|
||||
|
||||
samples_per_bit = audio_fs / message.baudrate;
|
||||
|
||||
phase_inc = (0x10000 * message.baudrate) / audio_fs;
|
||||
phase = 0;
|
||||
|
||||
trigger_word = message.trigger_word;
|
||||
word_length = message.word_length;
|
||||
trigger_value = message.trigger_value;
|
||||
word_mask = (1 << word_length) - 1;
|
||||
|
||||
// Delay line
|
||||
delay_line_index = 0;
|
||||
|
||||
triggered = false;
|
||||
state = WAIT_START;
|
||||
|
||||
configured = true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user