From 2f894ab5a3f70d4ddeab03a8447ce88245ecf0d4 Mon Sep 17 00:00:00 2001 From: Piotr Wilkon Date: Thu, 31 Aug 2023 20:10:16 +0200 Subject: [PATCH] timer frq change, hamming distance using built-in fun --- Src/drivers/modem.c | 4 ++-- Src/fx25.c | 14 ++------------ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/Src/drivers/modem.c b/Src/drivers/modem.c index 4c2388f..d0c8290 100644 --- a/Src/drivers/modem.c +++ b/Src/drivers/modem.c @@ -768,7 +768,7 @@ void ModemInit(void) TIM1->DIER |= TIM_DIER_UIE; //baudrate timer - TIM3->PSC = 71; //72/72=1 MHz + TIM3->PSC = 3; //72/9=18 MHz TIM3->DIER |= TIM_DIER_UIE; if(ModemConfig.modem > MODEM_9600) @@ -927,7 +927,7 @@ void ModemInit(void) markStep = 4000000 / (DAC_SINE_SIZE * markFreq) - 1; spaceStep = 4000000 / (DAC_SINE_SIZE * spaceFreq) - 1; - baudRateStep = 1000000 / baudRate - 1; + baudRateStep = 18000000 / baudRate - 1; TIM3->ARR = baudRateStep; diff --git a/Src/fx25.c b/Src/fx25.c index d01b16a..305df3e 100644 --- a/Src/fx25.c +++ b/Src/fx25.c @@ -25,23 +25,13 @@ const struct Fx25Mode Fx25ModeList[11] = {.tag = 0x4A4ABEC4A724B796, .K = 64, .T = 64} }; -static uint8_t hammingDistance(uint64_t x, uint64_t y) -{ - x ^= y; - uint8_t distance = 0; - for(uint8_t i = 0; i < 64; i++) - { - distance += (x & 1); - x >>= 1; - } - return distance; -} + const struct Fx25Mode* Fx25GetModeForTag(uint64_t tag) { for(uint8_t i = 0; i < sizeof(Fx25ModeList) / sizeof(*Fx25ModeList); i++) { - if(hammingDistance(tag, Fx25ModeList[i].tag) <= FX25_MAX_DISTANCE) + if(__builtin_popcountll(tag ^ Fx25ModeList[i].tag) <= FX25_MAX_DISTANCE) return &Fx25ModeList[i]; } return NULL;