Avoid sleeps to prevent low-frequency artifacts

Replace them with busy looks that do not lower the current draw.
It still prevent memory saturation as the loops do not touch memory.
This commit is contained in:
Jan Hamal Dvořák 2024-07-27 15:39:40 +02:00
parent 24d6acdb53
commit f5fb02c190

View file

@ -87,6 +87,14 @@ static queue_t iq_queue;
static uint8_t iq_queue_buffer[IQ_QUEUE_LEN][IQ_BLOCK_LEN]; static uint8_t iq_queue_buffer[IQ_QUEUE_LEN][IQ_BLOCK_LEN];
static size_t iq_queue_pos = 0; static size_t iq_queue_pos = 0;
static uint32_t rnd = 0;
inline static __unused uint32_t rnd_next()
{
rnd = rnd * 0x41c64e6d + 12345;
return rnd;
}
static void dma_channel_clear_chain_to(int ch) static void dma_channel_clear_chain_to(int ch)
{ {
uint32_t ctrl = dma_hw->ch[ch].al1_ctrl; uint32_t ctrl = dma_hw->ch[ch].al1_ctrl;
@ -128,7 +136,7 @@ static void init_lo()
sm_config_set_out_shift(&pc, false, true, 32); sm_config_set_out_shift(&pc, false, true, 32);
pio_sm_init(PIO, LO_SM, prog.origin, &pc); pio_sm_init(PIO, LO_SM, prog.origin, &pc);
pio_sm_set_consecutive_pindirs(PIO, LO_SM, LO_PIN, 1, GPIO_OUT); pio_sm_set_consecutive_pindirs(PIO, LO_SM, LO_PIN, 1, GPIO_IN);
pio_sm_exec_wait_blocking(PIO, LO_SM, pio_encode_set(pio_pins, 0)); pio_sm_exec_wait_blocking(PIO, LO_SM, pio_encode_set(pio_pins, 0));
} }
@ -477,10 +485,12 @@ static void rf_rx(void)
int head = (dma_hw->ch[dma_ch_in_cos].write_addr - base) / 4; int head = (dma_hw->ch[dma_ch_in_cos].write_addr - base) / 4;
int delta = (head < pos ? head + RX_WORDS : head) - pos; int delta = (head < pos ? head + RX_WORDS : head) - pos;
sleep_us(10);
while (delta < RX_STRIDE) { while (delta < RX_STRIDE) {
sleep_us(1); int wait = rnd_next() & 63;
for (int i = 0; i < wait; i++)
asm volatile("nop");
head = (dma_hw->ch[dma_ch_in_cos].write_addr - base) / 4; head = (dma_hw->ch[dma_ch_in_cos].write_addr - base) / 4;
delta = (head < pos ? head + RX_WORDS : head) - pos; delta = (head < pos ? head + RX_WORDS : head) - pos;
} }
@ -616,7 +626,10 @@ static void do_rx()
fwrite(block, IQ_BLOCK_LEN, 1, stdout); fwrite(block, IQ_BLOCK_LEN, 1, stdout);
fflush(stdout); fflush(stdout);
} else { } else {
sleep_us(25); int wait = rnd_next() & 0x1fff;
for (int i = 0; i < wait; i++)
asm volatile("nop");
} }
} }