add warnings for consecutive timeout responses (no rx) from the chip (#378)

* add common vars to control rx warning behavoir
* rename vars, reduce rx timout value, add warning when 20s of consecutive rx timeouts occour
* rename device to asic
* better naming of warning condition variable

* move counter variables into the ASIC source files
* move constants to defines and counters to local vars
* fix stray semicolon

Co-authored-by: Skot <skot@bitnet.cx>
This commit is contained in:
adammwest 2024-10-10 00:59:45 +02:00 committed by GitHub
parent bf822ab009
commit df0c9ed745
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 71 additions and 26 deletions

View File

@ -45,6 +45,8 @@
#define TICKET_MASK 0x14
#define MISC_CONTROL 0x18
#define BM1366_TIMEOUT_MS 10000
#define BM1366_TIMEOUT_THRESHOLD 2
typedef struct __attribute__((__packed__))
{
uint8_t preamble[2];
@ -630,14 +632,23 @@ void BM1366_send_work(void * pvParameters, bm_job * next_bm_job)
asic_result * BM1366_receive_work(void)
{
// wait for a response, wait time is pretty arbitrary
int received = SERIAL_rx(asic_response_buffer, 11, 60000);
// wait for a response
int received = SERIAL_rx(asic_response_buffer, 11, BM1366_TIMEOUT_MS);
if (received < 0) {
ESP_LOGI(TAG, "Error in serial RX");
bool uart_err = received < 0;
bool uart_timeout = received == 0;
uint8_t asic_timeout_counter = 0;
// handle response
if (uart_err) {
ESP_LOGI(TAG, "UART Error in serial RX");
return NULL;
} else if (received == 0) {
// Didn't find a solution, restart and try again
} else if (uart_timeout) {
if (asic_timeout_counter >= BM1366_TIMEOUT_THRESHOLD) {
ESP_LOGE(TAG, "ASIC not sending data");
asic_timeout_counter = 0;
}
asic_timeout_counter++;
return NULL;
}

View File

@ -44,6 +44,8 @@
#define TICKET_MASK 0x14
#define MISC_CONTROL 0x18
#define BM1368_TIMEOUT_MS 10000
#define BM1368_TIMEOUT_THRESHOLD 2
typedef struct __attribute__((__packed__))
{
uint8_t preamble[2];
@ -370,12 +372,23 @@ void BM1368_send_work(void * pvParameters, bm_job * next_bm_job)
asic_result * BM1368_receive_work(void)
{
int received = SERIAL_rx(asic_response_buffer, 11, 60000);
// wait for a response
int received = SERIAL_rx(asic_response_buffer, 11, BM1368_TIMEOUT_MS);
if (received < 0) {
ESP_LOGI(TAG, "Error in serial RX");
bool uart_err = received < 0;
bool uart_timeout = received == 0;
uint8_t asic_timeout_counter = 0;
// handle response
if (uart_err) {
ESP_LOGI(TAG, "UART Error in serial RX");
return NULL;
} else if (received == 0) {
} else if (uart_timeout) {
if (asic_timeout_counter >= BM1368_TIMEOUT_THRESHOLD) {
ESP_LOGE(TAG, "ASIC not sending data");
asic_timeout_counter = 0;
}
asic_timeout_counter++;
return NULL;
}

View File

@ -45,6 +45,9 @@
#define TICKET_MASK 0x14
#define MISC_CONTROL 0x18
#define BM1370_TIMEOUT_MS 10000
#define BM1370_TIMEOUT_THRESHOLD 2
typedef struct __attribute__((__packed__))
{
uint8_t preamble[2];
@ -57,6 +60,7 @@ typedef struct __attribute__((__packed__))
static const char * TAG = "bm1370Module";
static uint8_t asic_response_buffer[SERIAL_BUF_SIZE];
static task_result result;
@ -437,14 +441,23 @@ void BM1370_send_work(void * pvParameters, bm_job * next_bm_job)
asic_result * BM1370_receive_work(void)
{
// wait for a response, wait time is pretty arbitrary
int received = SERIAL_rx(asic_response_buffer, 11, 60000);
// wait for a response
int received = SERIAL_rx(asic_response_buffer, 11, BM1370_TIMEOUT_MS);
if (received < 0) {
ESP_LOGI(TAG, "Error in serial RX");
bool uart_err = received < 0;
bool uart_timeout = received == 0;
uint8_t asic_timeout_counter = 0;
// handle response
if (uart_err) {
ESP_LOGI(TAG, "UART Error in serial RX");
return NULL;
} else if (received == 0) {
// Didn't find a solution, restart and try again
} else if (uart_timeout) {
if (asic_timeout_counter >= BM1370_TIMEOUT_THRESHOLD) {
ESP_LOGE(TAG, "ASIC not sending data");
asic_timeout_counter = 0;
}
asic_timeout_counter++;
return NULL;
}

View File

@ -45,6 +45,9 @@
#define TICKET_MASK 0x14
#define MISC_CONTROL 0x18
#define BM1397_TIMEOUT_MS 10000
#define BM1397_TIMEOUT_THRESHOLD 2
typedef struct __attribute__((__packed__))
{
uint8_t preamble[2];
@ -400,17 +403,23 @@ void BM1397_send_work(void *pvParameters, bm_job *next_bm_job)
asic_result *BM1397_receive_work(void)
{
// wait for a response, wait time is pretty arbitrary
int received = SERIAL_rx(asic_response_buffer, 9, 60000);
// wait for a response
int received = SERIAL_rx(asic_response_buffer, 9, BM1397_TIMEOUT_MS);
if (received < 0)
{
ESP_LOGI(TAG, "Error in serial RX");
bool uart_err = received < 0;
bool uart_timeout = received == 0;
uint8_t asic_timeout_counter = 0;
// handle response
if (uart_err) {
ESP_LOGI(TAG, "UART Error in serial RX");
return NULL;
}
else if (received == 0)
{
// Didn't find a solution, restart and try again
} else if (uart_timeout) {
if (asic_timeout_counter >= BM1397_TIMEOUT_THRESHOLD) {
ESP_LOGE(TAG, "ASIC not sending data");
asic_timeout_counter = 0;
}
asic_timeout_counter++;
return NULL;
}

View File

@ -4,7 +4,6 @@
#define SERIAL_BUF_SIZE 16
#define CHUNK_SIZE 1024
int SERIAL_send(uint8_t *, int, bool);
void SERIAL_init(void);
void SERIAL_debug_rx(void);