autoranging with timeout

pull/6/head
alanbjohnston 7 years ago committed by GitHub
parent 02ff2ecb32
commit 2ae75ad8a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,6 +21,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <time.h>
#include "ax25.h" #include "ax25.h"
#include "ax5043.h" #include "ax5043.h"
#include "status.h" #include "status.h"
@ -621,14 +622,19 @@ int ax5043_autoranging(ax5043_conf_t *conf) {
usleep(10); usleep(10);
//val = 0; //val = 0;
/* Wait until the autoranging is complete */ /* 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); ret = ax5043_spi_read_8(conf, &val, pllranging_reg);
if (ret) { if (ret) {
return ret; return ret;
} }
if ((clock() - start) > 500000) {
timeout = 1;
}
} }
if (val & BIT(5)) { if ((val & BIT(5)) || timeout) {
return -PQWS_AX5043_AUTORANGING_ERROR; return -PQWS_AX5043_AUTORANGING_ERROR;
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.