From 583ac10d1450610a4110849c26cc16f03154d26e Mon Sep 17 00:00:00 2001 From: jaseg Date: Mon, 25 Sep 2023 12:45:42 +0200 Subject: Driver fw works --- driver_fw/.gdbinit | 2 +- driver_fw/Makefile | 4 ++-- driver_fw/src/main.c | 33 +++++++++++++++++++++++---------- driver_fw/tools/template_wave_tables.py | 4 ++-- 4 files changed, 28 insertions(+), 15 deletions(-) (limited to 'driver_fw') diff --git a/driver_fw/.gdbinit b/driver_fw/.gdbinit index 082e6a7..d29f9a6 100644 --- a/driver_fw/.gdbinit +++ b/driver_fw/.gdbinit @@ -1,5 +1,5 @@ -target extended-remote 192.168.1.93:2022 +target extended-remote 192.168.1.95:2022 set print pretty on set print elements 512 diff --git a/driver_fw/Makefile b/driver_fw/Makefile index 8ae65b2..b847134 100644 --- a/driver_fw/Makefile +++ b/driver_fw/Makefile @@ -30,7 +30,7 @@ DEVICE := STM32G070RB ASM_SOURCES := startup.s -C_SOURCES := src/main.c $(BUILDDIR)/generated/waveform_tables.c +C_SOURCES := src/main.c $(BUILDDIR)/generated/waveform_tables.c common/8b10b.c CPP_SOURCES := # - none - @@ -79,7 +79,7 @@ DEVICE_DEFINES := -DSTM32$(DEVICE_FAMILY) $(addprefix -D,$(shell cat stm32_buil ARCH_FLAGS ?= -mthumb -mcpu=cortex-m0 -mfloat-abi=soft SYSTEM_FLAGS ?= -nostdlib -ffreestanding -nostartfiles -COMMON_CFLAGS += -I$(abspath include) +COMMON_CFLAGS += -I$(abspath include) -I$(abspath common) COMMON_CFLAGS += -I$(BUILDDIR) CFLAGS += -I$(abspath tools/musl_include_shims) diff --git a/driver_fw/src/main.c b/driver_fw/src/main.c index 6c63f4f..765c55a 100644 --- a/driver_fw/src/main.c +++ b/driver_fw/src/main.c @@ -1,6 +1,7 @@ #include #include +#include "8b10b.h" #include "generated/waveform_tables.h" volatile uint64_t sys_time_us; @@ -11,8 +12,15 @@ static void set_status_leds(uint32_t leds); static void dma_tx_constant(size_t table_size, uint16_t constant); static void dma_tx_waveform(size_t table_size, const uint16_t *table); -static uint8_t tx_datagram[32] = { +static int tx_datagram[33] = { /* FIXME test data */ +/* + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa}; +*/ + -K28_0, 0x00, 0xff, 0xAA, 0x55, 0xfe, 0x18, 0xcc, 0x10, 0x00, 0xff, 0xAA, 0x55, 0xfe, 0x18, 0xcc, 0x10, 0x00, 0xff, 0xAA, 0x55, 0xfe, 0x18, 0xcc, 0x10, @@ -20,6 +28,7 @@ static uint8_t tx_datagram[32] = { static size_t tx_bitpos = 0; static size_t tx_sympos = 0; static int tx_last_bit = 0; +static struct state_8b10b_enc encoder_state_8b10b; int main(void) { @@ -144,11 +153,11 @@ int main(void) { TIM1->CCMR1 = (6<CCMR2 = (6<CCER = TIM_CCER_CC2E | TIM_CCER_CC2NE | TIM_CCER_CC3E | TIM_CCER_CC3NE; - TIM1->BDTR = TIM_BDTR_MOE | (32<CCER = TIM_CCER_CC2E | TIM_CCER_CC2NE | TIM_CCER_CC2NP | TIM_CCER_CC3E | TIM_CCER_CC3NE | TIM_CCER_CC3P; + TIM1->BDTR = (8<DCR = (14<PSC = 4; - TIM1->ARR = 256; + TIM1->PSC = 3; + TIM1->ARR = 250; TIM1->CCR2 = 64; TIM1->CCR3 = 192; TIM1->DIER = TIM_DIER_UDE; @@ -159,7 +168,7 @@ int main(void) { NVIC_EnableIRQ(DMA1_Channel1_IRQn); NVIC_SetPriority(DMA1_Channel1_IRQn, 0); dma_tx_constant(COUNT_OF(waveform_zero_one), 0x00); - + xfr_8b10b_encode_reset(&encoder_state_8b10b); int i = 0; int j = 0; while (23) { @@ -182,8 +191,9 @@ void dma_tx_waveform(size_t table_size, const uint16_t *table) { } void dma_tx_constant(size_t table_size, uint16_t constant) { - static uint16_t tx_constant; - tx_constant = constant; + static uint16_t tx_constant[2]; + tx_constant[0] = constant; + tx_constant[1] = constant; DMA1_Channel1->CCR = 0; DMA1_Channel1->CCR = (1<ISR & DMA_ISR_TEIF1) { transfer_errors ++; } DMA1->IFCR = DMA_IFCR_CGIF1; - int bit = !!(tx_datagram[tx_sympos] & (1<= 8) { + if (tx_bitpos >= 10) { tx_bitpos = 0; tx_sympos ++; + current_symbol = xfr_8b10b_encode(&encoder_state_8b10b, tx_datagram[tx_sympos]); if (tx_sympos >= COUNT_OF(tx_datagram)) { tx_sympos = 0; } diff --git a/driver_fw/tools/template_wave_tables.py b/driver_fw/tools/template_wave_tables.py index ec60de0..2069075 100644 --- a/driver_fw/tools/template_wave_tables.py +++ b/driver_fw/tools/template_wave_tables.py @@ -55,8 +55,8 @@ def header(ctype, n, erange): if __name__ == '__main__': import argparse parser = argparse.ArgumentParser() - parser.add_argument('--table-size', type=int, default=256) - parser.add_argument('--range', type=int, default=256) + parser.add_argument('--table-size', type=int, default=32) + parser.add_argument('--range', type=int, default=250) parser.add_argument('--header', action='store_true') parser.add_argument('--storage-type', type=str, default='uint16_t') parser.add_argument('outfile', type=argparse.FileType('w')) -- cgit