Improve repeated RX, fix scaling

Signed-off-by: Jan Hamal Dvořák <mordae@anilinux.org>
This commit is contained in:
Jan Hamal Dvořák 2024-01-27 10:55:23 +01:00
parent d6bd009c92
commit dc03f5e1b4

View file

@ -72,6 +72,8 @@ static volatile struct status {
int I, Q; int I, Q;
} status; } status;
#define PLEASE_DIE 0xd1e
static void bias_init(int in_pin, int out_pin) static void bias_init(int in_pin, int out_pin)
{ {
gpio_disable_pulls(in_pin); gpio_disable_pulls(in_pin);
@ -426,6 +428,11 @@ static void rf_rx(void)
int lpIavg3 = 0, lpQavg3 = 0; int lpIavg3 = 0, lpQavg3 = 0;
int lpIidx = 0, lpQidx = 0; int lpIidx = 0, lpQidx = 0;
for (int i = 0; i < LPF_SAMPLES; i++) {
lpIh1[i] = lpIh2[i] = lpIh3[i] = 0;
lpQh1[i] = lpQh2[i] = lpQh3[i] = 0;
}
#endif #endif
#if IIR_ON #if IIR_ON
@ -477,6 +484,17 @@ static void rf_rx(void)
int rotation = 0; int rotation = 0;
while (true) { while (true) {
uint32_t msg = 0;
if (multicore_fifo_rvalid()) {
msg = multicore_fifo_pop_blocking();
if (PLEASE_DIE == msg) {
multicore_fifo_push_blocking(0);
return;
}
}
int I = 0, Q = 0; int I = 0, Q = 0;
if (!dma_channel_is_busy(rx_dma)) if (!dma_channel_is_busy(rx_dma))
@ -514,8 +532,6 @@ static void rf_rx(void)
unsigned prev_sin_word = 0; unsigned prev_sin_word = 0;
#endif #endif
I = Q = 0;
for (int k = 0; k < NUM_SAMPLES; k++) { for (int k = 0; k < NUM_SAMPLES; k++) {
unsigned rx_word = rx_buf[pos]; unsigned rx_word = rx_buf[pos];
unsigned cos_word = lo_cos[pos]; unsigned cos_word = lo_cos[pos];
@ -591,20 +607,19 @@ static void rf_rx(void)
#if SPEED == 3 #if SPEED == 3
/* Normalize to 8 bits. */ /* Normalize to 8 bits. */
I = (I * 255) / 16; I = (I * 127) / 16;
Q = (Q * 255) / 16; Q = (Q * 127) / 16;
#endif #endif
I /= NUM_SAMPLES; I /= NUM_SAMPLES;
Q /= NUM_SAMPLES; Q /= NUM_SAMPLES;
#if HPF_ALPHA #if HPF_ALPHA
int tmpI = I * 256; int tmpI = I * 64;
I -= hpI / 256; I -= hpI / 64;
hpI = (hpI * ((1 << 12) - HPF_ALPHA) + tmpI * HPF_ALPHA) >> 12; hpI = (hpI * ((1 << 12) - HPF_ALPHA) + tmpI * HPF_ALPHA) >> 12;
int tmpQ = Q * 256; int tmpQ = Q * 64;
Q -= hpQ / 256; Q -= hpQ / 64;
hpQ = (hpQ * ((1 << 12) - HPF_ALPHA) + tmpQ * HPF_ALPHA) >> 12; hpQ = (hpQ * ((1 << 12) - HPF_ALPHA) + tmpQ * HPF_ALPHA) >> 12;
#endif #endif
@ -786,6 +801,8 @@ static void command(const char *cmd)
int c = getchar_timeout_us(0); int c = getchar_timeout_us(0);
if (13 == c) { if (13 == c) {
multicore_fifo_push_blocking(PLEASE_DIE);
multicore_fifo_pop_blocking();
multicore_reset_core1(); multicore_reset_core1();
dma_channel_abort(rx_dma); dma_channel_abort(rx_dma);
dma_channel_cleanup(rx_dma); dma_channel_cleanup(rx_dma);