summaryrefslogtreecommitdiff
path: root/controller
diff options
context:
space:
mode:
authorjaseg <git-bigdata-wsl-arch@jaseg.de>2020-03-17 17:20:43 +0100
committerjaseg <git-bigdata-wsl-arch@jaseg.de>2020-03-17 17:20:43 +0100
commit80de5c2e24056d38e49c4aeff4f84a299165d933 (patch)
treedafe4bb88ca5e40ab87a88aab1335dcd52989be1 /controller
parent9d72724ca5fc130448ba0e93b5e46ed83f419d85 (diff)
downloadmaster-thesis-80de5c2e24056d38e49c4aeff4f84a299165d933.tar.gz
master-thesis-80de5c2e24056d38e49c4aeff4f84a299165d933.tar.bz2
master-thesis-80de5c2e24056d38e49c4aeff4f84a299165d933.zip
Debugging signal capture subsystem
Diffstat (limited to 'controller')
-rw-r--r--controller/fw/src/adc.c2
-rw-r--r--controller/fw/src/con_usart.h3
-rw-r--r--controller/fw/src/main.c19
-rw-r--r--controller/fw/src/serial.c29
-rw-r--r--controller/fw/src/serial.h2
5 files changed, 51 insertions, 4 deletions
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<<DMA_LISR_FEIF0_Pos;
+ adc_overruns++;
return;
panic();
}
diff --git a/controller/fw/src/con_usart.h b/controller/fw/src/con_usart.h
index a1ad963..db73f0d 100644
--- a/controller/fw/src/con_usart.h
+++ b/controller/fw/src/con_usart.h
@@ -6,9 +6,10 @@
extern volatile struct usart_desc con_usart;
#define con_printf(...) usart_printf(&con_usart, __VA_ARGS__)
+#define con_printf_blocking(...) usart_printf_blocking(&con_usart, __VA_ARGS__)
#ifndef CON_USART_BAUDRATE
-#define CON_USART_BAUDRATE 115200
+#define CON_USART_BAUDRATE 500000
#endif
void con_usart_init(void);
diff --git a/controller/fw/src/main.c b/controller/fw/src/main.c
index b100b16..6589297 100644
--- a/controller/fw/src/main.c
+++ b/controller/fw/src/main.c
@@ -197,7 +197,7 @@ int main(void)
clock_setup();
con_usart_init();
- con_printf("\033[2J\033[HBooting...\r\n");
+ con_printf("\033[0m\033[2J\033[HBooting...\r\n");
led_setup();
spi_flash_setup();
@@ -217,9 +217,22 @@ int main(void)
while (23) {
if (adc_fft_buf_ready_idx != -1) {
GPIOA->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; i<FMEAS_FFT_LEN/2; i++)
+ con_printf_blocking("%03x ", adc_fft_buf[old_idx][FMEAS_FFT_LEN/2 + i]);
+ adc_fft_buf_ready_idx = -1;
+ freq_sample_ts++; /* TODO: also increase in case of freq measurement error? */
GPIOA->BSRR = 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; i<chunk_len; i++)
@@ -129,6 +145,11 @@ int usart_send_chunk_nonblocking(volatile struct usart_desc *us, const char *chu
return usart_flush(us);
}
+void usart_wait_chunk_free(volatile struct usart_desc *us) {
+ while (us->tx_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__