From 439f514ed31e590ac623e8592d8d2a53b2da4704 Mon Sep 17 00:00:00 2001 From: wu58430 Date: Wed, 6 Dec 2023 21:53:43 +0800 Subject: [PATCH] fix EEPROM --- .idea/workspace.xml | 270 +++++++++++++++++++++++--------------------- Makefile | 2 +- app/mdc1200.c | 13 ++- driver/bk4819.c | 32 +++--- driver/crc.c | 54 ++++----- driver/crc.h | 2 +- settings.c | 2 +- ui/menu.c | 1 + 版本说明.txt | 11 ++ 9 files changed, 209 insertions(+), 178 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 78d4366..eaa95f3 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -20,7 +20,7 @@ - + @@ -504,6 +512,10 @@ - \ No newline at end of file diff --git a/Makefile b/Makefile index ee52ace..006043e 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ ENABLE_BYP_RAW_DEMODULATORS := 0 ENABLE_BLMIN_TMP_OFF := 0 ENABLE_SCAN_RANGES := 1 ENABLE_MDC1200 := 1 -ENABLE_MDC1200_SHOW_OP_ARG := 0 +ENABLE_MDC1200_SHOW_OP_ARG := 1 ENABLE_MDC1200_SIDE_BEEP := 0 # ---- DEBUGGING ---- ENABLE_AM_FIX_SHOW_DATA := 0 diff --git a/app/mdc1200.c b/app/mdc1200.c index 4941cd4..c49bd09 100644 --- a/app/mdc1200.c +++ b/app/mdc1200.c @@ -13,7 +13,7 @@ const uint8_t mdc1200_sync[5] = {0x07, 0x09, 0x2a, 0x44, 0x6f}; uint8_t mdc1200_sync_suc_xor[sizeof(mdc1200_sync)]; -#if 0 +#if 1 uint16_t compute_crc(const void *data, const unsigned int data_len) { // let the CPU's hardware do some work :) @@ -471,7 +471,8 @@ uint8_t mdc1200_rx_ready_tick_500ms; void MDC1200_process_rx(const uint16_t interrupt_bits) { - + char b[2]="R0"; + UART_Send((uint8_t *)&b,2); const uint16_t rx_sync_flags = BK4819_ReadRegister(0x0B); const uint16_t fsk_reg59 = BK4819_ReadRegister(0x59) & ~((1u << 15) | (1u << 14) | (1u << 12) | (1u << 11)); @@ -519,18 +520,22 @@ void MDC1200_process_rx(const uint16_t interrupt_bits) mdc1200_rx_buffer[mdc1200_rx_buffer_index++] = (word >> 8) & 0xff; } - + char a[2]="R1"; + UART_Send((uint8_t *)&a,2); if (mdc1200_rx_buffer_index >= sizeof(mdc1200_rx_buffer)) { BK4819_WriteRegister(0x59, (1u << 15) | (1u << 14) | fsk_reg59); BK4819_WriteRegister(0x59, (1u << 12) | fsk_reg59); - + char a[2]="RE"; + UART_Send((uint8_t *)&a,2); if (MDC1200_process_rx_data( mdc1200_rx_buffer, mdc1200_rx_buffer_index, &mdc1200_op, &mdc1200_arg, &mdc1200_unit_id)) { + char a[2]="OK"; + UART_Send((uint8_t *)&a,2); mdc1200_rx_ready_tick_500ms = 2 * 5; // 6 second MDC display time gUpdateDisplay = true; diff --git a/driver/bk4819.c b/driver/bk4819.c index 44eea8d..8fbd2d4 100644 --- a/driver/bk4819.c +++ b/driver/bk4819.c @@ -128,17 +128,17 @@ static uint16_t BK4819_ReadU16(void) PORTCON_PORTC_IE = (PORTCON_PORTC_IE & ~PORTCON_PORTC_IE_C2_MASK) | PORTCON_PORTC_IE_C2_BITS_ENABLE; GPIOC->DIR = (GPIOC->DIR & ~GPIO_DIR_2_MASK) | GPIO_DIR_2_BITS_INPUT; - SYSTICK_DelayUs(1); - + //SYSTICK_DelayUs(1); + SYSTICK_Delay250ns(1); Value = 0; for (i = 0; i < 16; i++) { Value <<= 1; Value |= GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SDA); GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL); - SYSTICK_DelayUs(1); + SYSTICK_Delay250ns(1); GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL); - SYSTICK_DelayUs(1); + SYSTICK_Delay250ns(1); } PORTCON_PORTC_IE = (PORTCON_PORTC_IE & ~PORTCON_PORTC_IE_C2_MASK) | PORTCON_PORTC_IE_C2_BITS_DISABLE; GPIOC->DIR = (GPIOC->DIR & ~GPIO_DIR_2_MASK) | GPIO_DIR_2_BITS_OUTPUT; @@ -153,14 +153,14 @@ uint16_t BK4819_ReadRegister(BK4819_REGISTER_t Register) GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCN); GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL); - SYSTICK_DelayUs(1); + SYSTICK_Delay250ns(1); GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCN); BK4819_WriteU8(Register | 0x80); Value = BK4819_ReadU16(); GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCN); - SYSTICK_DelayUs(1); + SYSTICK_Delay250ns(1); GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL); GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SDA); @@ -174,20 +174,20 @@ void BK4819_WriteRegister(BK4819_REGISTER_t Register, uint16_t Data) GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCN); GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL); - SYSTICK_DelayUs(1); + SYSTICK_Delay250ns(1); GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCN); BK4819_WriteU8(Register); - SYSTICK_DelayUs(1); + //SYSTICK_Delay250ns(1); BK4819_WriteU16(Data); - SYSTICK_DelayUs(1); + //SYSTICK_Delay250ns(1); GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCN); - SYSTICK_DelayUs(1); + SYSTICK_Delay250ns(1); GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL); GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SDA); @@ -205,14 +205,14 @@ void BK4819_WriteU8(uint8_t Data) else GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SDA); - SYSTICK_DelayUs(1); + SYSTICK_Delay250ns(1); GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL); - SYSTICK_DelayUs(1); + SYSTICK_Delay250ns(1); Data <<= 1; GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL); - SYSTICK_DelayUs(1); + SYSTICK_Delay250ns(1); } } @@ -228,14 +228,14 @@ void BK4819_WriteU16(uint16_t Data) else GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SDA); - SYSTICK_DelayUs(1); + SYSTICK_Delay250ns(1); GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL); Data <<= 1; - SYSTICK_DelayUs(1); + SYSTICK_Delay250ns(1); GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL); - SYSTICK_DelayUs(1); + SYSTICK_Delay250ns(1); } } diff --git a/driver/crc.c b/driver/crc.c index cfe4016..7d25766 100644 --- a/driver/crc.c +++ b/driver/crc.c @@ -69,31 +69,33 @@ void CRC_InitReverse(void) return crc; } -uint16_t CRC_Calculate( void *pBuffer, uint16_t Size) { -// uint8_t *pData = ( uint8_t *)pBuffer; -// uint16_t crc = 0; // 初始CRC值为0 +//uint16_t CRC_Calculate( void *pBuffer, uint16_t Size) { // -// while (Size--) { -// crc ^= (*pData++) << 8; // 将数据字节的最高位与CRC异或 -// for (uint8_t i = 0; i < 8; i++) { -// if (crc & 0x8000) { // 检查最高位是否为1 -// crc = (crc << 1) ^ CRC16_XMODEM_POLY; // 如果最高位为1,执行CRC多项式计算 -// } else { -// crc = crc << 1; // 如果最高位为0,继续左移 -// } -// } -// } -// -// return crc; - unsigned int i; - uint8_t *data8 = ( uint8_t *)pBuffer; - uint16_t crc = 0; - for (i = 0; i < Size; i++) - { - unsigned int k; - crc ^= data8[i]; - for (k = 8; k > 0; k--) - crc = (crc & 1u) ? (crc >> 1) ^ 0x8408 : crc >> 1; - } - return crc ^ 0xffff; +// unsigned int i; +// uint8_t *data8 = ( uint8_t *)pBuffer; +// uint16_t crc = 0; +// for (i = 0; i < Size; i++) +// { +// unsigned int k; +// crc ^= data8[i]; +// for (k = 8; k > 0; k--) +// crc = (crc & 1u) ? (crc >> 1) ^ 0x8408 : crc >> 1; +// } +// return crc ^ 0xffff; +//} +uint16_t CRC_Calculate(const void *buffer, const unsigned int size) +{ + const uint8_t *data = (const uint8_t *)buffer; + uint16_t i; + uint16_t crc; + + CRC_CR = (CRC_CR & ~CRC_CR_CRC_EN_MASK) | CRC_CR_CRC_EN_BITS_ENABLE; + + for (i = 0; i < size; i++) + CRC_DATAIN = data[i]; + crc = (uint16_t)CRC_DATAOUT; + + CRC_CR = (CRC_CR & ~CRC_CR_CRC_EN_MASK) | CRC_CR_CRC_EN_BITS_DISABLE; + + return crc; } diff --git a/driver/crc.h b/driver/crc.h index 45dd839..6d03789 100644 --- a/driver/crc.h +++ b/driver/crc.h @@ -20,7 +20,7 @@ #include void CRC_Init(void); - uint16_t CRC_Calculate( void *pBuffer, uint16_t Size); +uint16_t CRC_Calculate(const void *buffer, const unsigned int size); uint16_t CRC_Calculate1( void *pBuffer, uint16_t Size); void CRC_InitReverse(void); diff --git a/settings.c b/settings.c index 1a93a42..fbafbc7 100644 --- a/settings.c +++ b/settings.c @@ -517,7 +517,7 @@ void SETTINGS_SaveSettings(void) // State[2] = 0;//gEeprom.KEY_1_LONG_PRESS_ACTION; State[3] = 0;//gEeprom.KEY_2_SHORT_PRESS_ACTION; State[4] = 0;//gEeprom.KEY_2_LONG_PRESS_ACTION; - State[5] = //gEeprom.SCAN_RESUME_MODE; + State[5] = gEeprom.SCAN_RESUME_MODE; State[6] = 0;//gEeprom.AUTO_KEYPAD_LOCK; State[7] = 0;//gEeprom.POWER_ON_DISPLAY_MODE; EEPROM_WriteBuffer(0x0E90, State); diff --git a/ui/menu.c b/ui/menu.c index 9113b16..8de33b9 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -710,6 +710,7 @@ void UI_DisplayMenu(void) { { // sprintf(edit, "%04lX", gEeprom.MDC1200_ID); // %04X确保输出是4个字符长度的十六进制数 sprintf(String, "%04X", gEeprom.MDC1200_ID); // %04X确保输出是4个字符长度的十六进制数 + edit_index = -1; edit[0]=String[0]; edit[1]=String[1]; diff --git a/版本说明.txt b/版本说明.txt index 308a089..82bc8cc 100644 --- a/版本说明.txt +++ b/版本说明.txt @@ -1,3 +1,14 @@ +#0.10.7 + 修复“搜索恢复模式设置失效” + 修复“MDC ID菜单项无法输入数字切换菜单项” + TODO:“修复接收失败问题“ + TODO:精简DTMF信息菜单 + TODO:更新README客制部分 + TODO:更新Makefile + + +#0.10.6 + 纠正MDC信令 #0.10.4 在解锁全部频段下允许200M,350M,500M,删除对应菜单 修复“按键音开机后失效“