diff options
author | jaseg <git@jaseg.de> | 2022-05-01 17:24:19 +0200 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2022-05-01 17:24:19 +0200 |
commit | f21e9797a28b6f4eb84f6c3a74d3b64817abc42a (patch) | |
tree | 9c4e22cefc22c58d906b404ddc513084e6151c68 /driver_fw | |
parent | 3cba41f49f2d91a13addea0004f7c91292d4d3e0 (diff) | |
download | 8seg-f21e9797a28b6f4eb84f6c3a74d3b64817abc42a.tar.gz 8seg-f21e9797a28b6f4eb84f6c3a74d3b64817abc42a.tar.bz2 8seg-f21e9797a28b6f4eb84f6c3a74d3b64817abc42a.zip |
Fix 8b10b encoding running disparity issues.
Diffstat (limited to 'driver_fw')
-rw-r--r-- | driver_fw/Makefile | 2 | ||||
-rw-r--r-- | driver_fw/main.c | 41 |
2 files changed, 28 insertions, 15 deletions
diff --git a/driver_fw/Makefile b/driver_fw/Makefile index f6a20ae..85bc4c7 100644 --- a/driver_fw/Makefile +++ b/driver_fw/Makefile @@ -1,4 +1,4 @@ -CUBE_PATH ?= $(wildcard ~)/resource/STM32Cube_FW_F0_V1.9.0 +CUBE_PATH ?= $(wildcard ~)/ref/stm32cube/STM32CubeF0 CMSIS_PATH ?= $(CUBE_PATH)/Drivers/CMSIS CMSIS_DEV_PATH ?= $(CMSIS_PATH)/Device/ST/STM32F0xx HAL_PATH ?= $(CUBE_PATH)/Drivers/STM32F0xx_HAL_Driver diff --git a/driver_fw/main.c b/driver_fw/main.c index 30ff633..5123237 100644 --- a/driver_fw/main.c +++ b/driver_fw/main.c @@ -81,6 +81,20 @@ static void set_status_leds(uint8_t val) { *((volatile uint8_t *)&(SPI1->DR)) = val ^ 0x0f; /* Invert LEDs connected to VCC instead of GND */ } +static int flipbits10(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; + +} int main(void) { /* Startup code */ @@ -194,7 +208,7 @@ int main(void) { /* Initialize AC protocol state machine in TIM3 ISR with the AC protocol comma */ xfr_8b10b_encode_reset(&txstate.st); - txstate.current_symbol = xfr_8b10b_encode(&txstate.st, K28_1) | 1<<10; + txstate.current_symbol = flipbits10(xfr_8b10b_encode(&txstate.st, K28_1)) | 1<<10; /* The timer is still stopped. Start it by manually triggering an update event. */ TIM3->EGR |= TIM_EGR_UG; @@ -219,22 +233,21 @@ int main(void) { } } -static int flipbits10(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; +#define BACKCHANNEL_INTERVAL 10 +__attribute__((__noreturn__)) void __assert_func (const char *, int, const char *, const char *){ + asm volatile ("bkpt"); + while (1); } -#define BACKCHANNEL_INTERVAL 10 +int hamming_weight(int i) { + int r = 0; + for (int j = 0; j < 32; j ++) { + if (i < 0) r ++; + i <<= 1; + } + return r; +} void TIM3_IRQHandler() { static int txpos = -1; |