From 80de5c2e24056d38e49c4aeff4f84a299165d933 Mon Sep 17 00:00:00 2001 From: jaseg Date: Tue, 17 Mar 2020 17:20:43 +0100 Subject: Debugging signal capture subsystem --- controller/fw/src/adc.c | 2 ++ controller/fw/src/con_usart.h | 3 ++- controller/fw/src/main.c | 19 ++++++++++++++++--- controller/fw/src/serial.c | 29 +++++++++++++++++++++++++++++ controller/fw/src/serial.h | 2 ++ 5 files changed, 51 insertions(+), 4 deletions(-) (limited to 'controller/fw') diff --git a/controller/fw/src/adc.c b/controller/fw/src/adc.c index 81f5ac1..027fd11 100644 --- a/controller/fw/src/adc.c +++ b/controller/fw/src/adc.c @@ -6,6 +6,7 @@ #include "adc.h" #include "sr_global.h" +static unsigned int adc_overruns = 0; uint16_t adc_fft_buf[2][FMEAS_FFT_LEN]; volatile int adc_fft_buf_ready_idx = -1; @@ -93,6 +94,7 @@ void DMA2_Stream0_IRQHandler(void) { GPIOA->BSRR = 1<<11<<16; /* clear all flags */ adc_dma->LIFCR = isr<BSRR = 1<<11; - adc_fft_buf_ready_idx = !adc_fft_buf_ready_idx; /* DEBUG */ - memcpy(adc_fft_buf[!adc_fft_buf_ready_idx], adc_fft_buf[adc_fft_buf_ready_idx] + FMEAS_FFT_LEN/2, sizeof(adc_fft_buf[0][0]) * FMEAS_FFT_LEN/2); + //adc_fft_buf_ready_idx = !adc_fft_buf_ready_idx; /* DEBUG */ + //DEBUG: + //memcpy(adc_fft_buf[!adc_fft_buf_ready_idx], adc_fft_buf[adc_fft_buf_ready_idx] + FMEAS_FFT_LEN/2, sizeof(adc_fft_buf[0][0]) * FMEAS_FFT_LEN/2); + + for (int i=0; i<168*1000*2; i++) + asm volatile ("nop"); + /* BEGIN DEBUG */ + con_printf_blocking("\r\n%06d: ", freq_sample_ts); + int old_idx = adc_fft_buf_ready_idx; + for (int i=0; iBSRR = 1<<11<<16; + continue; + /* END DEBUG */ GPIOA->BSRR = 1<<11; float out; diff --git a/controller/fw/src/serial.c b/controller/fw/src/serial.c index 71e1868..2d09f80 100644 --- a/controller/fw/src/serial.c +++ b/controller/fw/src/serial.c @@ -11,6 +11,8 @@ static void usart_schedule_dma(volatile struct usart_desc *us); static void usart_dma_reset(volatile struct usart_desc *us); static void usart_putc_nonblocking_tpf(void *us, char c); +static void usart_wait_chunk_free(volatile struct usart_desc *us); +static void usart_putc_blocking_tpf(void *us, char c); void usart_dma_reset(volatile struct usart_desc *us) { us->tx_buf.xfr_start = -1; @@ -117,10 +119,24 @@ int usart_putc_nonblocking(volatile struct usart_desc *us, char c) { return 0; } +int usart_putc_blocking(volatile struct usart_desc *us, char c) { + volatile struct dma_tx_buf *buf = &us->tx_buf; + + while (buf->wr_pos == buf->xfr_start) + ; + + buf->data[buf->wr_pos] = c; + buf->wr_pos = (buf->wr_pos + 1) % sizeof(us->data); + return 0; +} + void usart_putc_nonblocking_tpf(void *us, char c) { usart_putc_nonblocking((struct usart_desc *)us, c); } +void usart_putc_blocking_tpf(void *us, char c) { + usart_putc_blocking((struct usart_desc *)us, c); +} int usart_send_chunk_nonblocking(volatile struct usart_desc *us, const char *chunk, size_t chunk_len) { for (size_t i=0; itx_buf.chunk_end[us->tx_buf.wr_idx] != -1) + ; +} + int usart_flush(volatile struct usart_desc *us) { /* Find a free slot for this chunk */ if (us->tx_buf.chunk_end[us->tx_buf.wr_idx] != -1) { @@ -151,3 +172,11 @@ int usart_printf(volatile struct usart_desc *us, char *fmt, ...) { return usart_flush(us); } +int usart_printf_blocking(volatile struct usart_desc *us, char *fmt, ...) { + va_list va; + va_start(va, fmt); + tfp_format((void *)us, usart_putc_blocking_tpf, fmt, va); + usart_wait_chunk_free(us); + return usart_flush(us); +} + diff --git a/controller/fw/src/serial.h b/controller/fw/src/serial.h index 02f6f5d..bad4374 100644 --- a/controller/fw/src/serial.h +++ b/controller/fw/src/serial.h @@ -74,9 +74,11 @@ struct usart_desc { void usart_dma_init(volatile struct usart_desc *us, unsigned int baudrate); int usart_send_chunk_nonblocking(volatile struct usart_desc *us, const char *chunk, size_t chunk_len); int usart_putc_nonblocking(volatile struct usart_desc *us, char c); +int usart_putc_blocking(volatile struct usart_desc *us, char c); void usart_dma_stream_irq(volatile struct usart_desc *us); int usart_flush(volatile struct usart_desc *us); int usart_printf(volatile struct usart_desc *us, char *fmt, ...); +int usart_printf_blocking(volatile struct usart_desc *us, char *fmt, ...); #endif // __SERIAL_H__ -- cgit