static void rda5802_set_frequency(int freq) { int i; uint16_t readchan; /* check BAND and spacings */ int start = CHANNEL_BANDr(cache[CHANNEL]) & 1 ? 76000000 : 87000000; int chan = (freq - start) / 50000; for (i = 0; i < 5; i++) { /* tune and wait a bit */ rda5802_write_masked(CHANNEL, CHANNEL_CHANw(chan) | CHANNEL_TUNE, CHANNEL_CHAN | CHANNEL_TUNE); rda5802_write_cache(); sleep(HZ * 70 / 1000); rda5802_write_clear(CHANNEL, CHANNEL_TUNE); rda5802_write_cache(); /* check if tuning was successful */ readchan = rda5802_read_reg(READCHAN); if (readchan & READCHAN_STC) { if (READCHAN_READCHANr(readchan) == chan) { break; } } } }
static void rda5802_set_frequency(int freq) { int i; uint16_t readchan; static const int spacings[] = {100000, 200000, 50000, 50000}; static const int bandstart[] = {87000000, 76000000, 76000000, 65000000}; /* calculate channel number */ int start = bandstart[CHANNEL_BANDr(cache[CHANNEL])]; int space = spacings[CHANNEL_SPACEr(cache[CHANNEL])]; int chan = (freq - start) / space; for (i = 0; i < 5; i++) { /* tune and wait a bit */ rda5802_write_masked(CHANNEL, CHANNEL_CHANw(chan) | CHANNEL_TUNE, CHANNEL_CHAN | CHANNEL_TUNE); rda5802_write_cache(); sleep(HZ * 70 / 1000); rda5802_write_clear(CHANNEL, CHANNEL_TUNE); rda5802_write_cache(); /* check if tuning was successful */ readchan = rda5802_read_reg(READCHAN); if (readchan & READCHAN_STC) { if (READCHAN_READCHANr(readchan) == chan) { break; } } } }
static int rda5802_tuned(void) { /* Primitive tuning check: sufficient level and AFC not railed */ uint16_t status = rda5802_read_reg(STATUSRSSI); if (STATUSRSSI_RSSIr(status) >= SEEK_THRESHOLD && (status & STATUSRSSI_FM_TRUE)) { return 1; } return 0; }
static int rda5802_rssi(void) { uint16_t status = rda5802_read_reg(STATUSRSSI); return STATUSRSSI_RSSIr(status); }
static bool rda5802_st(void) { return (rda5802_read_reg(READCHAN) & READCHAN_ST); }
bool rda5802_detect(void) { return ((rda5802_read_reg(IDENT) & 0xFF00) == 0x5800); }