From 528d653bdef957121200364aa116aa1587fefa19 Mon Sep 17 00:00:00 2001 From: jaseg Date: Thu, 10 Jan 2019 14:31:20 +0900 Subject: Decoding and comma triggering works --- driver_fw/main.c | 38 +++++++++++++++++++++++++------------- fw/Scope.ipynb | 32 ++++++++++++++------------------ fw/adc.c | 42 +++++++++++++++++++++++++++++++++++++++++- fw/scope.gdb | 12 ++++++++++++ 4 files changed, 92 insertions(+), 32 deletions(-) create mode 100644 fw/scope.gdb diff --git a/driver_fw/main.c b/driver_fw/main.c index accb159..838ca9d 100644 --- a/driver_fw/main.c +++ b/driver_fw/main.c @@ -82,40 +82,52 @@ int main(void) { uint8_t txbuf[128]; int txpos = -1; /* FIXME test code */ - for (int i=0; i= sizeof(txbuf)/sizeof(txbuf[0])) txpos = -1; } } } -void TIM1_UP_IRQHandler() { - // FIXME debug code - static int debug_bit = 0; - debug_bit = !debug_bit; +int flipbits(int in) { + return + (in&0x200)>>9 | + (in&0x100)>>7 | + (in&0x080)>>5 | + (in&0x040)>>3 | + (in&0x020)>>1 | + (in&0x010)<<1 | + (in&0x008)<<3 | + (in&0x004)<<5 | + (in&0x002)<<7 | + (in&0x001)<<9; + +} +void TIM1_UP_IRQHandler() { TIM1->SR &= ~TIM_SR_UIF; int sym = txstate.current_symbol; int bit = sym&1; sym >>= 1; if (sym == 1) { /* last bit shifted out */ - sym = txstate.next_symbol | 1<<10; + if (txstate.next_symbol == -NO_SYMBOL) /*FIXME debug code*/ + asm volatile("bkpt"); + sym = flipbits(txstate.next_symbol) | 1<<10; txstate.next_symbol = -NO_SYMBOL; } txstate.current_symbol = sym; - TIM1->CCR1 = debug_bit ? 0xffff : 0x0000; + TIM1->CCR1 = bit ? 0xffff : 0x0000; } void NMI_Handler(void) { diff --git a/fw/Scope.ipynb b/fw/Scope.ipynb index 966c83c..33596a0 100644 --- a/fw/Scope.ipynb +++ b/fw/Scope.ipynb @@ -2,18 +2,19 @@ "cells": [ { "cell_type": "code", - "execution_count": 6, + "execution_count": 208, "metadata": {}, "outputs": [], "source": [ "from matplotlib import pyplot as plt\n", "%matplotlib notebook\n", - "import struct" + "import struct\n", + "import math" ] }, { "cell_type": "code", - "execution_count": 119, + "execution_count": 207, "metadata": {}, "outputs": [], "source": [ @@ -22,27 +23,21 @@ " raw_data = f.read()\n", " data = struct.unpack(f'<{len(raw_data)//2}{\"h\" if signed else \"H\"}', raw_data)\n", " \n", - " print(''.join(str(x) for x in data[offx:][:100]))\n", - " fig, axs = plt.subplots(channels, 1, figsize=(10, 5))\n", - " for i, ax in enumerate(axs):\n", - " ax.plot(data[offx:][:end][i::channels])\n", - " ax.grid()" + " fig, axs = plt.subplots(channels, 1, squeeze=False, sharex=True, figsize=(10, 5))\n", + " for i, ax in enumerate(axs.flatten()):\n", + " ax.plot([math.nan if x==-255 else x for x in data[offx:][:end][i::channels]])\n", + " ax.grid()\n", + " \n", + " return data" ] }, { "cell_type": "code", - "execution_count": 121, + "execution_count": 213, "metadata": { "scrolled": false }, "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "61515991715159978151599491515997101515997111515991121515994131515997141515991050-5345150-5361250-5358350-5351450-5348550-53616150-53547150-53488150-53549150-5361051599115159912515991351598845159915515988\n" - ] - }, { "data": { "application/javascript": [ @@ -826,7 +821,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -837,7 +832,8 @@ } ], "source": [ - "plot_data(offx=4, signed=True, channels=4)" + "data = plot_data(offx=4, signed=True, channels=1)\n", + "#print(''.join(str(x) for x in data[4:][3::4]))" ] }, { diff --git a/fw/adc.c b/fw/adc.c index 117377b..06cf027 100644 --- a/fw/adc.c +++ b/fw/adc.c @@ -258,14 +258,16 @@ void DMA1_Channel1_IRQHandler(void) { // st.detector.debounce_ctr--; //} + /* if (debug_buf_pos < NCH || debug_buf_pos >= sizeof(adc_buf)/sizeof(adc_buf[0])) { debug_buf_pos = NCH; gdb_dump(); } adc_buf[debug_buf_pos++] = st.detector.len_ctr; adc_buf[debug_buf_pos++] = st.detector.committed_len_ctr; - adc_buf[debug_buf_pos++] = st.detector.bit; adc_buf[debug_buf_pos++] = diff; + int foo = 0; + */ if (st.detector.len_ctr >= st.detector.committed_len_ctr) { /* @@ -274,8 +276,41 @@ void DMA1_Channel1_IRQHandler(void) { gdb_dump(); } adc_buf[debug_buf_pos++] = st.detector.bit; + int foo = st.detector.symbol; + if (foo < 0 && foo != K28_1) + foo = 0; + adc_buf[debug_buf_pos++] = foo; */ + if (st.detector.symbol != -DECODING_IN_PROGRESS) { + static int trig = 0; + if (st.detector.symbol == -K28_1) { + if (trig == 10) { + gdb_dump(); + for (int i=0; i= sizeof(adc_buf)/sizeof(adc_buf[0])) { + debug_buf_pos = 0; + } + if (debug_buf_pos >= NCH) { + adc_buf[debug_buf_pos++] = st.detector.symbol; + } + } + /* + if (debug_buf_pos < NCH || debug_buf_pos >= sizeof(adc_buf)/sizeof(adc_buf[0])) { + debug_buf_pos = NCH; + gdb_dump(); + } + adc_buf[debug_buf_pos++] = st.detector.bit; + */ + //foo = st.detector.bit ? 1 : -1; + st.detector.committed_len_ctr += st.detector.base_interval_cycles; st.detector.symbol = xfr_8b10b_feed_bit((struct state_8b10b_dec *)&st.detector.rx8b10b, st.detector.bit); /* @@ -285,9 +320,14 @@ void DMA1_Channel1_IRQHandler(void) { gdb_dump(); } adc_buf[debug_buf_pos++] = st.detector.symbol; + adc_buf[debug_buf_pos++] = st.detector.symbol == -DECODING_ERROR; + adc_buf[debug_buf_pos++] = st.detector.symbol == -K28_1; + adc_buf[debug_buf_pos++] = 0; } */ } + + //adc_buf[debug_buf_pos++] = foo; st.detector.len_ctr++; st.ovs_count = 0; diff --git a/fw/scope.gdb b/fw/scope.gdb new file mode 100644 index 0000000..8e4bb99 --- /dev/null +++ b/fw/scope.gdb @@ -0,0 +1,12 @@ +target remote localhost:3334 +set pagination off +file main.elf +load + +break DMA1_Channel1_IRQHandler +command 1 + dump binary value /tmp/scope_dump.bin adc_buf + continue +end + +continue -- cgit