diff --git a/Inc/ax25.h b/Inc/ax25.h index 8c382fd..443d06a 100644 --- a/Inc/ax25.h +++ b/Inc/ax25.h @@ -31,7 +31,6 @@ enum Ax25RxStage RX_STAGE_FLAG, RX_STAGE_FRAME, #ifdef ENABLE_FX25 - RX_STAGE_FX25_TAG, RX_STAGE_FX25_FRAME, #endif }; diff --git a/Src/ax25.c b/Src/ax25.c index c2e71fe..f82a6d7 100644 --- a/Src/ax25.c +++ b/Src/ax25.c @@ -135,7 +135,6 @@ struct RxState #ifdef ENABLE_FX25 struct Fx25Mode *fx25Mode; uint64_t tag; //received correlation tag - uint8_t tagBit; #endif }; @@ -537,42 +536,20 @@ void Ax25BitParse(uint8_t bit, uint8_t modem) rx->tag >>= 1; if(bit) rx->tag |= 0x8000000000000000; - rx->tagBit++; - - if((rx->rx == RX_STAGE_FX25_TAG) || (rx->rx == RX_STAGE_FX25_FRAME)) + if(Ax25Config.fx25 + && (rx->rx != RX_STAGE_FX25_FRAME) + && (NULL != (rx->fx25Mode = (struct Fx25Mode*)Fx25GetModeForTag(rx->tag)))) { - if((rx->rx == RX_STAGE_FX25_TAG) && (rx->tagBit == 64)) - { - if(Ax25Config.fx25) - { - rx->fx25Mode = (struct Fx25Mode*)Fx25GetModeForTag(rx->tag); - if(Ax25Config.fx25 && (rx->fx25Mode != NULL)) - { - rx->rx = RX_STAGE_FX25_FRAME; - rx->frameIdx = 0; - rx->receivedBitIdx = 0; - rx->receivedByte = 0; - return; - } - } - rx->rx = RX_STAGE_FRAME; - } + rx->rx = RX_STAGE_FX25_FRAME; + rx->receivedByte = 0; + rx->receivedBitIdx = 0; + rx->frameIdx = 0; + return; } - else + + if(rx->rx != RX_STAGE_FX25_FRAME) { - if(rx->rawData != 0x7E) - { - if(Ax25Config.fx25) - { - if((rx->rx == RX_STAGE_FLAG) && (rx->tagBit == 8)) - rx->rx = RX_STAGE_FX25_TAG; - } - else - rx->rx = RX_STAGE_FRAME; - } - else - rx->tagBit = 0; #endif if(rx->rawData == 0x7E) //HDLC flag received @@ -638,12 +615,14 @@ void Ax25BitParse(uint8_t bit, uint8_t modem) rx->frameIdx = 0; return; } + else + rx->rx = RX_STAGE_FRAME; #ifdef ENABLE_FX25 } - if((rx->rx != RX_STAGE_FX25_FRAME) && (rx->rx != RX_STAGE_FX25_TAG)) + if(rx->rx != RX_STAGE_FX25_FRAME) { #else { @@ -689,8 +668,7 @@ void Ax25BitParse(uint8_t bit, uint8_t modem) h->corrected = AX25_NOT_FX25; lastCrc = crc; } - rx->rx = RX_STAGE_FX25_TAG; - rx->tagBit = 0; + rx->rx = RX_STAGE_FLAG; rx->receivedByte = 0; rx->receivedBitIdx = 0; rx->frameIdx = 0; diff --git a/Src/drivers/modem.c b/Src/drivers/modem.c index ebdd5b7..4c2388f 100644 --- a/Src/drivers/modem.c +++ b/Src/drivers/modem.c @@ -70,7 +70,7 @@ along with VP-Digi. If not, see . #define AMP_TRACKING_DECAY 0.00004f //0.00004 -#define DAC_SINE_SIZE 32 //DAC sine table size +#define DAC_SINE_SIZE 128 //DAC sine table size struct ModemDemodConfig ModemConfig; @@ -347,7 +347,7 @@ void DMA1_Channel2_IRQHandler(void) if(ModemConfig.modem == MODEM_9600) { if(ModemConfig.usePWM) - sample = scrambledSymbol ? 99 : 0; + sample = scrambledSymbol ? 256 : 1; else sample = scrambledSymbol ? 15 : 0; @@ -367,7 +367,7 @@ void DMA1_Channel2_IRQHandler(void) else { GPIOB->ODR &= ~0xF000; //zero 4 oldest bits - GPIOB->ODR |= (sample << 12); //write sample to 4 oldest bits + GPIOB->ODR |= ((uint32_t)sample << 12); //write sample to 4 oldest bits } } @@ -434,11 +434,11 @@ static int32_t demodulate(int16_t sample, struct DemodState *dem) if(sample <= dem->valley) { - dem->valley += (((int32_t)(AMP_TRACKING_ATTACK * (float)32768) * (int32_t)(sample - dem->valley)) >> 15); + dem->valley -= (((int32_t)(AMP_TRACKING_ATTACK * (float)32768) * (int32_t)(dem->valley - sample)) >> 15); } else { - dem->valley += (((int32_t)(AMP_TRACKING_DECAY * (float)32768) * (int32_t)(sample - dem->valley)) >> 15); + dem->valley -= (((int32_t)(AMP_TRACKING_DECAY * (float)32768) * (int32_t)(dem->valley - sample)) >> 15); } @@ -492,7 +492,7 @@ static int32_t demodulate(int16_t sample, struct DemodState *dem) if((sample > 0) != dem->dcdLastSymbol) //tone changed { - if(abs(dem->dcdPll) <= (uint32_t)(dem->pllStep)) //tone change occurred near zero + if((uint32_t)abs(dem->dcdPll) <= (uint32_t)(dem->pllStep)) //tone change occurred near zero dem->dcdCounter += dem->dcdInc; //increase DCD counter else //tone change occurred far from zero { @@ -943,7 +943,8 @@ void ModemInit(void) for(uint8_t i = 0; i < DAC_SINE_SIZE; i++) //calculate DAC sine samples { if(ModemConfig.usePWM) - dacSine[i] = ((sinf(2.f * 3.1416f * (float)i / (float)DAC_SINE_SIZE) + 1.f) * 45.f); + //produce values in range 1 to 256 + dacSine[i] = ((sinf(2.f * 3.1416f * (float)i / (float)DAC_SINE_SIZE) + 1.f) * 128.f); else dacSine[i] = ((7.f * sinf(2.f * 3.1416f * (float)i / (float)DAC_SINE_SIZE)) + 8.f); } @@ -957,12 +958,12 @@ void ModemInit(void) GPIOB->CRL &= ~GPIO_CRL_CNF6_0; //set up PWM generation - TIM4->PSC = 7; //72MHz/8=9MHz - TIM4->ARR = 90; //9MHz/90=100kHz + TIM4->PSC = 2; //72MHz/3=24MHz + TIM4->ARR = 257; //18MHz/258=93kHz TIM4->CCMR1 |= TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2; TIM4->CCER |= TIM_CCER_CC1E; - TIM4->CCR1 = 44; //initial duty cycle + TIM4->CCR1 = 127; //initial duty cycle TIM4->CR1 |= TIM_CR1_CEN; } diff --git a/Src/fx25.c b/Src/fx25.c index 316ce3c..d01b16a 100644 --- a/Src/fx25.c +++ b/Src/fx25.c @@ -25,13 +25,13 @@ const struct Fx25Mode Fx25ModeList[11] = {.tag = 0x4A4ABEC4A724B796, .K = 64, .T = 64} }; -static inline uint8_t hammingDistance(uint64_t x, uint64_t y) +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) > 0; + distance += (x & 1); x >>= 1; } return distance; diff --git a/Src/main.c b/Src/main.c index 6e4b512..22f0821 100644 --- a/Src/main.c +++ b/Src/main.c @@ -136,7 +136,7 @@ static void handleFrame(void) TermSendToAll(MODE_MONITOR, (uint8_t*)"F", 1); break; case PREFILTER_NONE: - TermSendToAll(MODE_MONITOR, (uint8_t*)"*", 1); + TermSendToAll(MODE_MONITOR, (uint8_t*)"N", 1); } } else @@ -224,7 +224,7 @@ int main(void) //set some initial values in case there is no configuration saved in memory Uart1.baudrate = 9600; Uart2.baudrate = 9600; - ModemConfig.usePWM = 0; + ModemConfig.usePWM = 1; ModemConfig.flatAudioIn = 0; Ax25Config.quietTime = 300; Ax25Config.txDelayLength = 300;