Skip to content

Commit

Permalink
add warnings for consecutive timeout responses (no rx) from the chip (#…
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
adammwest and skot authored Oct 9, 2024
1 parent bf822ab commit df0c9ed
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 26 deletions.
23 changes: 17 additions & 6 deletions components/asic/bm1366.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}

Expand Down
21 changes: 17 additions & 4 deletions components/asic/bm1368.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}

Expand Down
25 changes: 19 additions & 6 deletions components/asic/bm1370.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down
27 changes: 18 additions & 9 deletions components/asic/bm1397.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 0 additions & 1 deletion components/asic/include/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit df0c9ed

Please sign in to comment.