aboutsummaryrefslogtreecommitdiff
path: root/driver_fw
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2023-09-25 12:45:42 +0200
committerjaseg <git@jaseg.de>2023-09-25 12:45:47 +0200
commit583ac10d1450610a4110849c26cc16f03154d26e (patch)
treefc8781d53b80666b2d8c253b16972e5c0f54c848 /driver_fw
parent5629273bcb6c92a5a9b58ae0f43d25585a01a5ab (diff)
download8seg-583ac10d1450610a4110849c26cc16f03154d26e.tar.gz
8seg-583ac10d1450610a4110849c26cc16f03154d26e.tar.bz2
8seg-583ac10d1450610a4110849c26cc16f03154d26e.zip
Driver fw works
Diffstat (limited to 'driver_fw')
-rw-r--r--driver_fw/.gdbinit2
-rw-r--r--driver_fw/Makefile4
-rw-r--r--driver_fw/src/main.c33
-rw-r--r--driver_fw/tools/template_wave_tables.py4
4 files changed, 28 insertions, 15 deletions
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 <global.h>
#include <string.h>
+#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<<TIM_CCMR1_OC2M_Pos) | TIM_CCMR1_OC2PE;
TIM1->CCMR2 = (6<<TIM_CCMR2_OC3M_Pos) | TIM_CCMR2_OC3PE;
- TIM1->CCER = TIM_CCER_CC2E | TIM_CCER_CC2NE | TIM_CCER_CC3E | TIM_CCER_CC3NE;
- TIM1->BDTR = TIM_BDTR_MOE | (32<<TIM_BDTR_DTG_Pos) | TIM_BDTR_MOE;
+ TIM1->CCER = TIM_CCER_CC2E | TIM_CCER_CC2NE | TIM_CCER_CC2NP | TIM_CCER_CC3E | TIM_CCER_CC3NE | TIM_CCER_CC3P;
+ TIM1->BDTR = (8<<TIM_BDTR_DTG_Pos) | TIM_BDTR_MOE;
TIM1->DCR = (14<<TIM_DCR_DBA_Pos) | (1<<TIM_DCR_DBL_Pos);
- TIM1->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<<DMA_CCR_MSIZE_Pos) | (1<<DMA_CCR_PSIZE_Pos) | DMA_CCR_DIR | DMA_CCR_TCIE;
@@ -194,13 +204,15 @@ void dma_tx_constant(size_t table_size, uint16_t constant) {
void DMA1_Channel1_IRQHandler() {
static int transfer_errors = 0;
+ static int current_symbol = 0x2aa;
+
if (DMA1->ISR & DMA_ISR_TEIF1) {
transfer_errors ++;
}
DMA1->IFCR = DMA_IFCR_CGIF1;
- int bit = !!(tx_datagram[tx_sympos] & (1<<tx_bitpos));
+ int bit = !!(current_symbol & (1<<tx_bitpos));
if (tx_last_bit == bit) {
dma_tx_constant(COUNT_OF(waveform_zero_one), bit ? WAVEFORM_CONST_ONE : WAVEFORM_CONST_ZERO);
@@ -213,9 +225,10 @@ void DMA1_Channel1_IRQHandler() {
tx_last_bit = bit;
tx_bitpos ++;
- if (tx_bitpos >= 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'))