diff --git a/firmware/drivers/tuner/si4700.c b/firmware/drivers/tuner/si4700.c index 848d25e..398c4ae 100644 --- a/firmware/drivers/tuner/si4700.c +++ b/firmware/drivers/tuner/si4700.c @@ -372,6 +372,7 @@ static void si4700_set_frequency(int freq) 76000000, /* SYSCONFIG2_BAND_760_1080 */ 76000000, /* SYSCONFIG2_BAND_760_900 */ }; + int i; /* check BAND and spacings */ int space = SYSCONFIG2_SPACEr(cache[SYSCONFIG2]); @@ -379,8 +380,7 @@ static void si4700_set_frequency(int freq) int chan = (freq - bands[band]) / spacings[space]; int readchan; - do - { + for (i = 0; i < 5; i++) { /* tuning should be done within 60 ms according to the datasheet */ si4700_write_reg(CHANNEL, CHANNEL_CHANw(chan) | CHANNEL_TUNE); sleep(HZ * 60 / 1000); @@ -389,7 +389,12 @@ static void si4700_set_frequency(int freq) readchan = si4700_read_reg(READCHAN) & READCHAN_READCHAN; si4700_write_clear(CHANNEL, CHANNEL_TUNE); - } while (!((cache[STATUSRSSI] & STATUSRSSI_STC) && (readchan == chan))); + + /* check if tuning was successful */ + if ((cache[STATUSRSSI] & STATUSRSSI_STC) && (readchan == chan)) { + break; + } + } } static int si4700_tuned(void)