From 535ddba4f22b64c9aa95850f11d96519caa34d5c Mon Sep 17 00:00:00 2001 From: ligenxxxx <59721724+ligenxxxx@users.noreply.github.com> Date: Tue, 30 Jul 2024 11:43:32 +0800 Subject: [PATCH] Resolve merge conflicts --- src/hardware.c | 179 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) diff --git a/src/hardware.c b/src/hardware.c index 9b10b23..cc11a0b 100644 --- a/src/hardware.c +++ b/src/hardware.c @@ -1772,3 +1772,182 @@ uint8_t check_uart_loopback() { } } #endif + +#ifdef USE_USB_DET +typedef void (*reset_mcu_ptr)(void); +reset_mcu_ptr reset_mcu = (reset_mcu_ptr)0x0000; + +void usb_det_task() { + if (USB_DET == 1) { + LED_BLUE_OFF; + WriteReg(0, 0x8F, 0x10); // reset RF_chip + while (USB_DET == 1) { + WAIT(1); + } + // reset 5680 + reset_mcu(); + } +} +#endif + +#if (0) +void _outstring(char *string) { + uint8_t i = 0; + for (i = 0; i < 128; i++) { + if (string[i] == 0) + break; + else + _outchar(string[i]); + } +} +#endif +void check_eeprom() { + const uint8_t tab_base_address[3] = { + EEP_ADDR_TAB1, + EEP_ADDR_TAB2, + EEP_ADDR_TAB3, + }; + const uint8_t dcoc_base_address[3] = { + EEP_ADDR_DCOC1, + EEP_ADDR_DCOC2, + EEP_ADDR_DCOC3, + }; + const uint8_t tab_range[2] = {20, 160}; + const uint8_t dcoc_range[2] = {80, 180}; + + uint8_t tab_list[3][FREQ_NUM_INTERNAL][POWER_MAX + 1]; + uint8_t dcoc_list[3][5]; + uint8_t ff_cnt[3]; + uint8_t i, j, k; + + // read all 3 table_power partitions + for (i = 0; i < 3; i++) { + ff_cnt[i] = 0; + for (j = 0; j < FREQ_NUM_INTERNAL; j++) { + for (k = 0; k < POWER_MAX + 1; k++) { + tab_list[i][j][k] = I2C_Read8(ADDR_EEPROM, tab_base_address[i] + j * (POWER_MAX + 1) + k); + ff_cnt[i] += (tab_list[i][j][k] == 0xff); + } + } + } + +#if (0) + // If eeprom is new, init partition 0 with default table_power + if (ff_cnt[0] == (FREQ_NUM_INTERNAL * (POWER_MAX + 1))) { + for (j = 0; j < FREQ_NUM_INTERNAL; j++) { + for (k = 0; k < POWER_MAX + 1; k++) { + I2C_Write8_Wait(10, ADDR_EEPROM, tab_base_address[0] + j * (POWER_MAX + 1) + k, table_power[j][k]); + } + } + _outstring("\r\nInit tab partition 0"); + } +#endif + + // Init partition 1/2 by copy paratition 0 if is needed (one time) + if ((ff_cnt[1] + ff_cnt[2]) > (FREQ_NUM_INTERNAL * (POWER_MAX + 1))) { + for (i = 1; i < 3; i++) { + for (j = 0; j < FREQ_NUM_INTERNAL; j++) { + for (k = 0; k < POWER_MAX + 1; k++) { + I2C_Write8_Wait(10, ADDR_EEPROM, tab_base_address[i] + j * (POWER_MAX + 1) + k, tab_list[0][j][k]); + tab_list[i][j][k] = tab_list[0][j][k]; + } + } + } + //_outstring("\r\nInit tab partition 1, 2"); + } + + // Check the validity of each value + for (i = 0; i < FREQ_NUM_INTERNAL; i++) { + for (j = 0; j < POWER_MAX + 1; j++) { + if (tab_list[0][i][j] == tab_list[1][i][j] && tab_list[1][i][j] == tab_list[2][i][j] && tab_list[0][i][j] > tab_range[0] && tab_list[0][i][j] < tab_range[1]) + // all partition are right + ; + else if (tab_list[0][i][j] == tab_list[1][i][j] && tab_list[1][i][j] != tab_list[2][i][j] && tab_list[0][i][j] > tab_range[0] && tab_list[0][i][j] < tab_range[1]) { + // partition 2 value is error + I2C_Write8_Wait(10, ADDR_EEPROM, tab_base_address[2] + i * (POWER_MAX + 1) + j, tab_list[0][i][j]); + //_outstring("\r\ntab2:"); + // _outchar('0' + i); + //_outchar('0' + j); + } else if (tab_list[0][i][j] == tab_list[2][i][j] && tab_list[1][i][j] != tab_list[2][i][j] && tab_list[0][i][j] > tab_range[0] && tab_list[0][i][j] < tab_range[1]) { + // partition 1 value is error + I2C_Write8_Wait(10, ADDR_EEPROM, tab_base_address[1] + i * (POWER_MAX + 1) + j, tab_list[0][i][j]); + //_outstring("\r\ntab1:"); + //_outchar('0' + i); + //_outchar('0' + j); + } else if (tab_list[0][i][j] != tab_list[2][i][j] && tab_list[1][i][j] == tab_list[2][i][j] && tab_list[1][i][j] > tab_range[0] && tab_list[1][i][j] < tab_range[1]) { + // partition 0 value is error + I2C_Write8_Wait(10, ADDR_EEPROM, tab_base_address[0] + i * (POWER_MAX + 1) + j, tab_list[1][i][j]); + //_outstring("\r\ntab0:"); + //_outchar('0' + i); + //_outchar('0' + j); + } else { + I2C_Write8_Wait(10, ADDR_EEPROM, tab_base_address[0] + i * (POWER_MAX + 1) + j, table_power[i][j]); + I2C_Write8_Wait(10, ADDR_EEPROM, tab_base_address[1] + i * (POWER_MAX + 1) + j, table_power[i][j]); + I2C_Write8_Wait(10, ADDR_EEPROM, tab_base_address[2] + i * (POWER_MAX + 1) + j, table_power[i][j]); + //_outstring("\r\n tab all:"); + //_outchar('0' + i); + //_outchar('0' + j); + } + } + } + + // read all 3 dcoc partitions + for (i = 0; i < 3; i++) { + ff_cnt[i] = 0; + for (j = 0; j < 5; j++) { + dcoc_list[i][j] = I2C_Read8(ADDR_EEPROM, dcoc_base_address[i] + j); + ff_cnt[i] += (dcoc_list[i][j] == 0xff); + } + } + + if (ff_cnt[0] == 3) + return; + // Init partition 1/2 by copy paratition 0 if is needed (one time) + if ((ff_cnt[1] + ff_cnt[2]) > 5) { + for (i = 1; i < 3; i++) { + for (j = 0; j < 5; j++) { + I2C_Write8_Wait(10, ADDR_EEPROM, dcoc_base_address[i] + j, dcoc_list[0][j]); + dcoc_list[i][j] = dcoc_list[0][j]; + } + } + //_outstring("\r\nInit dcoc partition 1, 2"); + } + + // Check the validity of each value + if (dcoc_list[0][0] == dcoc_list[1][0] && dcoc_list[1][0] == dcoc_list[2][0] && dcoc_list[0][0] == 0x00) { + ; + } else { + I2C_Write8_Wait(10, ADDR_EEPROM, dcoc_base_address[0], 0); + I2C_Write8_Wait(10, ADDR_EEPROM, dcoc_base_address[1], 0); + I2C_Write8_Wait(10, ADDR_EEPROM, dcoc_base_address[2], 0); + //_outstring("\r\ndcoc en err"); + } + + for (i = 1; i < 5; i++) { + if (dcoc_list[0][i] == dcoc_list[1][i] && dcoc_list[1][i] == dcoc_list[2][i] && dcoc_list[0][i] > dcoc_range[0] && dcoc_list[0][i] < dcoc_range[1]) + // all partition are right + ; + else if (dcoc_list[0][i] == dcoc_list[1][i] && dcoc_list[1][i] != dcoc_list[2][i] && dcoc_list[0][i] > dcoc_range[0] && dcoc_list[0][i] < dcoc_range[1]) { + // partition 2 value is error + I2C_Write8_Wait(10, ADDR_EEPROM, dcoc_base_address[2] + i, dcoc_list[0][i]); + //_outstring("\r\ndcoc2:"); + //_outchar('0' + i); + } else if (dcoc_list[0][i] != dcoc_list[1][i] && dcoc_list[1][i] == dcoc_list[2][i] && dcoc_list[1][i] > dcoc_range[0] && dcoc_list[1][i] < dcoc_range[1]) { + // partition 0 value is error + I2C_Write8_Wait(10, ADDR_EEPROM, dcoc_base_address[0] + i, dcoc_list[1][i]); + //_outstring("\r\ndcoc0:"); + //_outchar('0' + i); + } else if (dcoc_list[0][i] != dcoc_list[1][i] && dcoc_list[0][i] == dcoc_list[2][i] && dcoc_list[0][i] > dcoc_range[0] && dcoc_list[0][i] < dcoc_range[1]) { + // partition 1 value is error + I2C_Write8_Wait(10, ADDR_EEPROM, dcoc_base_address[1] + i, dcoc_list[0][i]); + //_outstring("\r\ndcoc1:"); + //_outchar('0' + i); + } else { + I2C_Write8_Wait(10, ADDR_EEPROM, dcoc_base_address[0] + i, 128); + I2C_Write8_Wait(10, ADDR_EEPROM, dcoc_base_address[1] + i, 128); + I2C_Write8_Wait(10, ADDR_EEPROM, dcoc_base_address[2] + i, 128); + //_outstring("\r\ndcoc all:"); + //_outchar('0' + i); + } + } +} \ No newline at end of file