diff --git a/components/bm1397/bm1397.c b/components/bm1397/bm1397.c index 8b2ebe8c..e67ba372 100644 --- a/components/bm1397/bm1397.c +++ b/components/bm1397/bm1397.c @@ -264,6 +264,22 @@ static void _send_read_address(void) unsigned char read_address[2] = {0x00, 0x00}; // send serial data _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_READ), read_address, 2, false); + + int received = SERIAL_rx(asic_response_buffer, 9, 500); + + if (received == 9) + { + //verify the chip ID + if ((asic_response_buffer[2] == 0x13) && (asic_response_buffer[3] == 0x97)) + { + ESP_LOGI(TAG, "BM1397 Detected!!!!"); + return true; + } + } + + ESP_LOGE(TAG, "Fail to receive the chip ID"); + + return false; } void BM1397_init(u_int64_t frequency) @@ -275,11 +291,13 @@ void BM1397_init(u_int64_t frequency) esp_rom_gpio_pad_select_gpio(BM1397_RST_PIN); gpio_set_direction(BM1397_RST_PIN, GPIO_MODE_OUTPUT); - // reset the bm1397 - _reset(); + //verify if the BM1397 is prenset + do{ + //reset the bm1397 + _reset(); - // send the init command - _send_read_address(); + //send the init command + } while(false==_send_read_address()); _send_init(frequency); } diff --git a/main/tasks/stratum_task.c b/main/tasks/stratum_task.c index bf882a88..b7443255 100644 --- a/main/tasks/stratum_task.c +++ b/main/tasks/stratum_task.c @@ -18,7 +18,7 @@ static const char *TAG = "stratum_task"; static ip_addr_t ip_Addr; -static bool bDNSFound = false; +static int8_t bDNSFound = 0; static StratumApiV1Message stratum_api_v1_message = {}; @@ -27,8 +27,16 @@ static SystemTaskModule SYSTEM_TASK_MODULE = { void dns_found_cb(const char *name, const ip_addr_t *ipaddr, void *callback_arg) { - ip_Addr = *ipaddr; - bDNSFound = true; + if (ipaddr != NULL) + { + ip_Addr = *ipaddr; + bDNSFound = 1; + } + else + { + // it fails to solve the DNS + bDNSFound = -1; + } } void stratum_task(void *pvParameters) @@ -46,7 +54,7 @@ void stratum_task(void *pvParameters) // check to see if the STRATUM_URL is an ip address already if (inet_pton(AF_INET, stratum_url, &ip_Addr) == 1) { - bDNSFound = true; + bDNSFound = 1; } else { @@ -54,8 +62,20 @@ void stratum_task(void *pvParameters) IP_ADDR4(&ip_Addr, 0, 0, 0, 0); ESP_LOGI(TAG, "Get IP for URL: %s\n", stratum_url); dns_gethostbyname(stratum_url, &ip_Addr, dns_found_cb, NULL); - while (!bDNSFound) - ; + while (true) + { + vTaskDelay(500 / portTICK_PERIOD_MS); + + // try again + if (bDNSFound == -1) + { + bDNSFound = 0; + dns_gethostbyname(stratum_url, &ip_Addr, dns_found_cb, NULL); + } + + if (bDNSFound == 1) + break; + } } // make IP address string from ip_Addr