diff --git a/Makefile b/Makefile index 3aa8688..1d7e0f8 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ ENABLE_OVERLAY := 0 ENABLE_LTO := 1 # UART Programming 2.9 kB ENABLE_UART := 1 -ENABLE_UART_DEBUG := 0 +ENABLE_UART_DEBUG := 1 # AirCopy 2.5 kB ENABLE_AIRCOPY := 1 ENABLE_AIRCOPY_REMEMBER_FREQ := 1 diff --git a/board.c b/board.c index 79808ad..d22ab50 100644 --- a/board.c +++ b/board.c @@ -945,8 +945,7 @@ void BOARD_fetchChannelName(char *s, const int channel) if (!RADIO_CheckValidChannel(channel, false, 0)) return; - EEPROM_ReadBuffer(0x0F50 + (channel * 16), s + 0, 8); - EEPROM_ReadBuffer(0x0F58 + (channel * 16), s + 8, 2); + EEPROM_ReadBuffer(0x0F50 + (channel * 16), s, 10); for (i = 0; i < 10; i++) if (s[i] < 32 || s[i] > 127) diff --git a/driver/crc.c b/driver/crc.c index 855eb42..54d3ee5 100644 --- a/driver/crc.c +++ b/driver/crc.c @@ -20,26 +20,40 @@ void CRC_Init(void) { CRC_CR = - CRC_CR_CRC_EN_BITS_DISABLE - | CRC_CR_INPUT_REV_BITS_NORMAL - | CRC_CR_INPUT_INV_BITS_NORMAL - | CRC_CR_OUTPUT_REV_BITS_NORMAL - | CRC_CR_OUTPUT_INV_BITS_NORMAL - | CRC_CR_DATA_WIDTH_BITS_8 - | CRC_CR_CRC_SEL_BITS_CRC_16_CCITT; + CRC_CR_CRC_EN_BITS_DISABLE | + CRC_CR_INPUT_REV_BITS_NORMAL | + CRC_CR_INPUT_INV_BITS_NORMAL | + CRC_CR_OUTPUT_REV_BITS_NORMAL | + CRC_CR_OUTPUT_INV_BITS_NORMAL | + CRC_CR_DATA_WIDTH_BITS_8 | + CRC_CR_CRC_SEL_BITS_CRC_16_CCITT; CRC_IV = 0; } -uint16_t CRC_Calculate(const void *pBuffer, uint16_t Size) +void CRC_InitReverse(void) { - const uint8_t *data = (const uint8_t *)pBuffer; + CRC_CR = + CRC_CR_CRC_EN_BITS_DISABLE | + CRC_CR_INPUT_REV_BITS_REVERSED | + CRC_CR_INPUT_INV_BITS_NORMAL | + CRC_CR_OUTPUT_REV_BITS_REVERSED | + CRC_CR_OUTPUT_INV_BITS_NORMAL | + CRC_CR_DATA_WIDTH_BITS_8 | + CRC_CR_CRC_SEL_BITS_CRC_16_CCITT; + + CRC_IV = 0; +} + +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++) + for (i = 0; i < size; i++) CRC_DATAIN = data[i]; crc = (uint16_t)CRC_DATAOUT; diff --git a/driver/crc.h b/driver/crc.h index acc9b49..4f35cb2 100644 --- a/driver/crc.h +++ b/driver/crc.h @@ -19,8 +19,9 @@ #include -void CRC_Init(void); -uint16_t CRC_Calculate(const void *pBuffer, uint16_t Size); +void CRC_Init(void); +void CRC_InitReverse(void); +uint16_t CRC_Calculate(const void *buffer, const unsigned int size); #endif diff --git a/firmware.bin b/firmware.bin index e6ffba8..165c4d4 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index 7fd9acd..53c4281 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/mdc1200.c b/mdc1200.c index e21f9e2..c1e05d0 100644 --- a/mdc1200.c +++ b/mdc1200.c @@ -2,6 +2,7 @@ #include #include "bsp/dp32g030/crc.h" +#include "driver/crc.h" #include "driver/uart.h" #include "mdc1200.h" #include "misc.h" @@ -30,7 +31,7 @@ uint16_t bit_reverse_16(uint16_t n) n = ((n >> 8) & 0x00FFu) | ((n << 8) & 0xFF00u); return n; } - +/* uint32_t bit_reverse_32(uint32_t n) { n = ((n >> 1) & 0x55555555u) | ((n << 1) & 0xAAAAAAAAu); @@ -40,22 +41,12 @@ uint32_t bit_reverse_32(uint32_t n) n = ((n >> 16) & 0x0000FFFFu) | ((n << 16) & 0xFFFF0000u); return n; } +*/ -uint16_t reverse_bits(const uint16_t bits_in, const unsigned int num_bits) -{ - uint16_t i; - uint16_t bit; - uint16_t bits_out; - for (i = 1u << (num_bits - 1), bit = 1u, bits_out = 0u; i != 0; i >>= 1) - { - if (bits_in & i) - bits_out |= bit; - bit <<= 1; - } - return bits_out; -} +// ************************************ + +#if 0 -#if 1 uint16_t compute_crc(const uint8_t *data, const unsigned int data_len) { // using the reverse computation avoids having to reverse the bit order during and after unsigned int i; @@ -70,64 +61,65 @@ uint16_t reverse_bits(const uint16_t bits_in, const unsigned int num_bits) crc ^= 0xffff; return crc; } -#else + +#elif 1 + uint16_t compute_crc(const uint8_t *data, const unsigned int data_len) { - - // this can be done using the CPU's own CRC calculator once we know we're ok - unsigned int i; + uint16_t crc; - #if 0 - uint16_t crc; +// CRC_InitReverse(); - CRC_CR = (CRC_CR & ~CRC_CR_CRC_EN_MASK) | CRC_CR_CRC_EN_BITS_ENABLE; - #else - uint16_t crc = 0; - #endif + CRC_CR = (CRC_CR & ~CRC_CR_CRC_EN_MASK) | CRC_CR_CRC_EN_BITS_ENABLE; + + for (i = 0; i < data_len; i++) + //CRC_DATAIN = data[i]; + CRC_DATAIN = bit_reverse_8(data[i]); + crc = CRC_DATAOUT; + + CRC_CR = (CRC_CR & ~CRC_CR_CRC_EN_MASK) | CRC_CR_CRC_EN_BITS_DISABLE; + +// CRC_Init(); + + // bit reverse and invert the final CRC + //return crc ^ 0xffff; + return bit_reverse_16(crc) ^ 0xffff; + } + +#else + + uint16_t compute_crc(const uint8_t *data, const unsigned int data_len) + { + unsigned int i; + uint16_t crc = 0; for (i = 0; i < data_len; i++) { - #if 0 + uint8_t mask; + + // bit reverse each data byte + const uint8_t bits = bit_reverse_8(*data++); - // bit reverse each data byte before adding it to the CRC - // the cortex CPU might have an instruction to bit reverse for us ? - // - CRC_DATAIN = reverse_bits(data[i], 8); - //CRC_DATAIN = bit_reverse_8(data[i]); - - #else - uint8_t mask; - - // bit reverse each data byte before adding it to the CRC - // the cortex CPU might have an instruction to bit reverse for us ? - // - const uint8_t bits = reverse_bits(data[i], 8); - //const uint8_t bits = bit_reverse_8(*data++); - - for (mask = 0x0080; mask != 0; mask >>= 1) - { - uint16_t msb = crc & 0x8000; - if (bits & mask) - msb ^= 0x8000; - crc <<= 1; - if (msb) - crc ^= 0x1021; - } - #endif + for (mask = 0x0080; mask != 0; mask >>= 1) + { + uint16_t msb = crc & 0x8000; + if (bits & mask) + msb ^= 0x8000; + crc <<= 1; + if (msb) + crc ^= 0x1021; + } } - #if 0 - crc = (uint16_t)CRC_DATAOUT; - CRC_CR = (CRC_CR & ~CRC_CR_CRC_EN_MASK) | CRC_CR_CRC_EN_BITS_DISABLE; - #endif - // bit reverse and invert the final CRC - return reverse_bits(crc, 16) ^ 0xffff; - // return bit_reverse_16(crc) ^ 0xffff; + return bit_reverse_16(crc) ^ 0xffff; } + #endif +// ************************************ + #define FEC_K 7 void error_correction(uint8_t *data) @@ -277,7 +269,10 @@ uint8_t * encode_data(uint8_t *data) data[FEC_K + i] = bo; } } -/* + + // 01 80 00 23 31 FC 00 65 80 32 0F 99 86 23 + // 01 80 00 23 31 FC 00 65 80 32 0F 99 86 23 + #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) { const unsigned int size = FEC_K * 2; @@ -288,7 +283,7 @@ uint8_t * encode_data(uint8_t *data) UART_SendText("\r\n"); } #endif -*/ + { // interleave the bits unsigned int i; diff --git a/radio.c b/radio.c index 6d7144f..69d9eaa 100644 --- a/radio.c +++ b/radio.c @@ -1128,7 +1128,7 @@ void RADIO_tx_eot(void) #ifdef ENABLE_MDC1200 if (g_eeprom.roger_mode == ROGER_MODE_MDC) { - BK4819_send_MDC1200(MDC1200_OP_CODE_POST_ID, 0x80, g_eeprom.mdc1200_id); + BK4819_send_MDC1200(MDC1200_OP_CODE_POST_ID, 0x00, g_eeprom.mdc1200_id); } else #endif diff --git a/ui/main.c b/ui/main.c index ee2d6a9..7194fec 100644 --- a/ui/main.c +++ b/ui/main.c @@ -783,7 +783,7 @@ void UI_DisplayMain(void) UI_PrintStringSmallest(str, x, (line + 0) * 8, false, true); } } - x += smallest_char_spacing * 4; + x += (smallest_char_spacing * 4) - 1; if (g_eeprom.vfo_info[vfo_num].compand) UI_PrintStringSmallest("C", x, (line + 0) * 8, false, true); diff --git a/ui/menu.c b/ui/menu.c index e06dceb..f2083d8 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -1237,6 +1237,7 @@ void UI_DisplayMenu(void) UI_PrintString(str, sub_menu_x1, sub_menu_x2, 0, 8); // channel name + memset(str, 0, sizeof(str)); BOARD_fetchChannelName(str, g_sub_menu_selection); if (str[0] == 0) strcpy(str, "--");