diff --git a/afsk/ax5043.c b/afsk/ax5043.c index a1902d58..b28223a4 100644 --- a/afsk/ax5043.c +++ b/afsk/ax5043.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "ax25.h" #include "ax5043.h" #include "status.h" @@ -621,14 +622,19 @@ int ax5043_autoranging(ax5043_conf_t *conf) { usleep(10); //val = 0; /* Wait until the autoranging is complete */ - while ((val & BIT(4)) != 0) { // changed to !=, since https://www.onsemi.com/pub/Collateral/AND9347-D.PDF says BIT(4) RNG START clears when autoranging done + int timeout = 0; + clock_t start = clock(); + while (((val & BIT(4)) != 0) && !timeout ) { // changed to !=, since https://www.onsemi.com/pub/Collateral/AND9347-D.PDF says BIT(4) RNG START clears when autoranging done ret = ax5043_spi_read_8(conf, &val, pllranging_reg); if (ret) { return ret; } + if ((clock() - start) > 500000) { + timeout = 1; + } } - if (val & BIT(5)) { + if ((val & BIT(5)) || timeout) { return -PQWS_AX5043_AUTORANGING_ERROR; }