diff --git a/Src/main.c b/Src/main.c index 89cbf15..bd38bcf 100644 --- a/Src/main.c +++ b/Src/main.c @@ -363,10 +363,13 @@ void SystemClock_Config(void) /**Initializes the CPU, AHB and APB busses clocks */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE|RCC_OSCILLATORTYPE_MSI; + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE + |RCC_OSCILLATORTYPE_MSI|RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.LSEState = RCC_LSE_ON; RCC_OscInitStruct.MSIState = RCC_MSI_ON; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.MSICalibrationValue = 0; + RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI; @@ -397,7 +400,7 @@ void SystemClock_Config(void) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_USART2 |RCC_PERIPHCLK_I2C3|RCC_PERIPHCLK_ADC; PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1; - PeriphClkInit.I2c3ClockSelection = RCC_I2C3CLKSOURCE_PCLK1; + PeriphClkInit.I2c3ClockSelection = RCC_I2C3CLKSOURCE_HSI; PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_PLLSAI1; PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_MSI; @@ -544,7 +547,7 @@ static void MX_I2C3_Init(void) { hi2c3.Instance = I2C3; - hi2c3.Init.Timing = 0x00702991; // 80MHz CPU, 400kHz i2c + hi2c3.Init.Timing = 0x0010061A; // 16MHz HSI, 400kHz i2c hi2c3.Init.OwnAddress1 = 0; hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; @@ -571,7 +574,7 @@ static void MX_I2C3_Init(void) _Error_Handler(__FILE__, __LINE__); } - /**I2C Fast mode Plus enable + /**I2C Fast mode Plus enable */ HAL_I2CEx_EnableFastModePlus(I2C_FASTMODEPLUS_I2C3); diff --git a/TNC/DigitalPLL.hpp b/TNC/DigitalPLL.hpp index b0c6720..a44287d 100644 --- a/TNC/DigitalPLL.hpp +++ b/TNC/DigitalPLL.hpp @@ -102,7 +102,7 @@ struct BaseDigitalPLL const float_type abs_offset = std::abs(offset) + adjust; jitter_ = lock_filter_(abs_offset); - count_ -= jitter / 2; + count_ -= jitter / 4; bits_ = 1; } else { diff --git a/TNC/Fsk9600Demodulator.cpp b/TNC/Fsk9600Demodulator.cpp index 2c0689f..a57ef2f 100644 --- a/TNC/Fsk9600Demodulator.cpp +++ b/TNC/Fsk9600Demodulator.cpp @@ -6,20 +6,34 @@ namespace mobilinkd { namespace tnc { #if 0 -// 96k + +/** + * Generated with scipy.signal.firwin2 + * + * fs = 96000.0 + * nq = fs / 2.0 + * + * taps = np.array(firwin2( + * 132, + * [0, 40.0/nq, 120.0/nq, 5000.0/nq, 7200.0/nq, 1.0], + * [0,0,.8,2,0,0], window='cosine') * 32768, dtype=int) + * + */ const q15_t Fsk9600Demodulator::bpf_coeffs[FILTER_TAP_NUM] = { - -3, -3, -3, -3, -3, -2, -2, -3, -4, -7, -10, -14, -17, -20, - -22, -23, -22, -21, -19, -17, -17, -18, -20, -24, -27, -29, -28, -25, - -20, -13, -7, -6, -10, -24, -46, -75, -108, -138, -158, -160, -140, -94, - -26, 55, 140, 210, 249, 240, 174, 49, -126, -332, -539, -710, -804, -784, - -624, -309, 156, 750, 1430, 2140, 2816, 3394, 3816, 4038, 4038, 3816, 3394, 2816, - 2140, 1430, 750, 156, -309, -624, -784, -804, -710, -539, -332, -126, 49, 174, - 240, 249, 210, 140, 55, -26, -94, -140, -160, -158, -138, -108, -75, -46, - -24, -10, -6, -7, -13, -20, -25, -28, -29, -27, -24, -20, -18, -17, - -17, -19, -21, -22, -23, -22, -20, -17, -14, -10, -7, -4, -3, -2, - -2, -3, -3, -3, -3, -3 + -1, -3, -4, -3, -1, 0, 3, 3, 1, -2, -10, -19, + -28, -37, -43, -45, -44, -41, -37, -34, -32, -34, -37, -42, + -44, -41, -32, -16, 4, 26, 42, 44, 26, -15, -82, -166, + -258, -341, -395, -404, -355, -242, -73, 131, 342, 520, 623, 615, + 468, 178, -240, -747, -1280, -1761, -2106, -2236, -2092, -1639, -882, 138, + 1344, 2628, 3866, 4932, 5714, 6127, 6127, 5714, 4932, 3866, 2628, 1344, + 138, -882, -1639, -2092, -2236, -2106, -1761, -1280, -747, -240, 178, 468, + 615, 623, 520, 342, 131, -73, -242, -355, -404, -395, -341, -258, + -166, -82, -15, 26, 44, 42, 26, 4, -16, -32, -41, -44, + -42, -37, -34, -32, -34, -37, -41, -44, -45, -43, -37, -28, + -19, -10, -2, 1, 3, 3, 0, -1, -3, -4, -3, -1 }; + // 144k const q15_t Fsk9600Demodulator::bpf_coeffs[FILTER_TAP_NUM] = { -2, -3, -3, -4, -5, -6, -6, -7, -7, -7, -7, -6, -6, -6, @@ -35,18 +49,29 @@ const q15_t Fsk9600Demodulator::bpf_coeffs[FILTER_TAP_NUM] = { }; #endif -// 192k +/** + * Generated with scipy.signal.firwin2 + * + * fs = 192000.0 + * nq = fs / 2.0 + * + * taps = np.array(firwin2( + * 132, + * [0, 5600.0/nq, 9600.0/nq, 1.0], + * [1,2.5,0,0], window='hamming') * 32768, dtype=int) + */ const q15_t Fsk9600Demodulator::bpf_coeffs[FILTER_TAP_NUM] = { - -1, -2, -3, -4, -6, -8, -11, -14, -17, -20, -24, -27, -30, -31, - -32, -32, -30, -26, -21, -14, -5, 4, 14, 26, 37, 47, 55, 60, - 62, 59, 51, 37, 17, -8, -39, -76, -117, -161, -206, -250, -292, -327, - -355, -372, -376, -365, -336, -289, -222, -136, -29, 95, 237, 394, 562, 738, - 919, 1099, 1274, 1440, 1591, 1725, 1837, 1924, 1983, 2013, 2013, 1983, 1924, 1837, - 1725, 1591, 1440, 1274, 1099, 919, 738, 562, 394, 237, 95, -29, -136, -222, - -289, -336, -365, -376, -372, -355, -327, -292, -250, -206, -161, -117, -76, -39, - -8, 17, 37, 51, 59, 62, 60, 55, 47, 37, 26, 14, 4, -5, - -14, -21, -26, -30, -32, -32, -31, -30, -27, -24, -20, -17, -14, -11, - -8, -6, -4, -3, -2, -1 + 2, 1, 0, -2, -5, -7, -7, -6, -4, -1, 2, 5, + 6, 5, 2, 0, -2, -3, -2, -2, -3, -9, -20, -34, + -46, -52, -47, -27, 3, 39, 68, 81, 71, 36, -15, -70, + -115, -137, -135, -116, -96, -92, -110, -145, -176, -170, -96, 57, + 272, 489, 619, 563, 243, -361, -1192, -2101, -2868, -3243, -3005, -2022, + -300, 1996, 4563, 7005, 8918, 9967, 9967, 8918, 7005, 4563, 1996, -300, +-2022, -3005, -3243, -2868, -2101, -1192, -361, 243, 563, 619, 489, 272, + 57, -96, -170, -176, -145, -110, -92, -96, -116, -135, -137, -115, + -70, -15, 36, 71, 81, 68, 39, 3, -27, -47, -52, -46, + -34, -20, -9, -3, -2, -2, -3, -2, 0, 2, 5, 6, + 5, 2, -1, -4, -6, -7, -7, -5, -2, 0, 1, 2 }; diff --git a/TNC/KissHardware.cpp b/TNC/KissHardware.cpp index 318553f..e000f27 100644 --- a/TNC/KissHardware.cpp +++ b/TNC/KissHardware.cpp @@ -18,6 +18,13 @@ namespace mobilinkd { namespace tnc { namespace kiss { const char FIRMWARE_VERSION[] = "1.0.1"; const char HARDWARE_VERSION[] = "Mobilinkd Nucleo32 Breadboard TNC"; +const std::array modem_type_lookup = { + "NOT SET", + "AFSK1200", + "AFSK300", + "FSK9600", +}; + Hardware& settings() { static Hardware instance __attribute__((section(".bss3"))); @@ -299,6 +306,26 @@ void Hardware::handle_request(hdlc::IoFrame* frame) reply8(hardware::GET_DUPLEX, duplex); break; + case hardware::SET_MODEM_TYPE: + DEBUG("SET_MODEM_TYPE"); + if ((*it > 0) and (*it < 4)) + { + modem_type = *it; + DEBUG(modem_type_lookup[*it]); + update_crc(); + } + else + { + ERROR("Unknown modem type"); + } + osMessagePut(audioInputQueueHandle, audio::UPDATE_SETTINGS, + osWaitForever); + [[fallthrough]]; + case hardware::GET_MODEM_TYPE: + DEBUG("GET_MODEM_TYPE"); + reply8(hardware::GET_MODEM_TYPE, modem_type); + break; + case hardware::GET_FIRMWARE_VERSION: DEBUG("GET_FIRMWARE_VERSION"); reply(hardware::GET_FIRMWARE_VERSION, (uint8_t*) FIRMWARE_VERSION, diff --git a/TNC/KissHardware.hpp b/TNC/KissHardware.hpp index b4bfb7e..da54b15 100644 --- a/TNC/KissHardware.hpp +++ b/TNC/KissHardware.hpp @@ -92,6 +92,9 @@ constexpr const uint8_t GET_TIMESLOT = 35; constexpr const uint8_t GET_TXTAIL = 36; constexpr const uint8_t GET_DUPLEX = 37; +constexpr const uint8_t SET_MODEM_TYPE = 38; +constexpr const uint8_t GET_MODEM_TYPE = 39; + constexpr const uint8_t GET_FIRMWARE_VERSION = 40; constexpr const uint8_t GET_HARDWARE_VERSION = 41; constexpr const uint8_t SAVE_EEPROM_SETTINGS = 42; diff --git a/TNC/SerialPort.cpp b/TNC/SerialPort.cpp index 8f68539..a13d7f8 100644 --- a/TNC/SerialPort.cpp +++ b/TNC/SerialPort.cpp @@ -136,6 +136,7 @@ extern "C" void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart) auto block = serialPool.allocate(); if (!block) return; memmove(block->buffer + 1, rxBuffer, len); + block->buffer[0] = static_cast(len); auto status = osMessagePut(mobilinkd::tnc::getSerialPort()->queue(), (uint32_t) block, 0); if (status != osOK) serialPool.deallocate(block); } @@ -148,6 +149,7 @@ extern "C" void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) auto block = serialPool.allocate(); if (!block) return; memmove(block->buffer + 1, rxBuffer + RX_BUFFER_SIZE, len); + block->buffer[0] = static_cast(len); auto status = osMessagePut(mobilinkd::tnc::getSerialPort()->queue(), (uint32_t) block, 0); if (status != osOK) serialPool.deallocate(block); }