From 08d09e678f942fef9e9efc9a88e62f0b4e7bb0a4 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Tue, 22 Jun 2010 07:27:34 +0000 Subject: [PATCH] Sanyo lv24020lp FM: Improve frequency measurement on PP thus improving initial frequency setting. Properly account for IF when tuning FM oscillator (this worked poorly before but appears to work as expected now -- aka. works for me). Not sure what this will do to iAudio7 or Cowon D2 but if they can implement a good duration measurement, they should do so or use the internal timer if possible. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27042 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/tuner/lv24020lp.c | 32 +++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/firmware/drivers/tuner/lv24020lp.c b/firmware/drivers/tuner/lv24020lp.c index a53d93bf65..86f8c39593 100644 --- a/firmware/drivers/tuner/lv24020lp.c +++ b/firmware/drivers/tuner/lv24020lp.c @@ -496,9 +496,25 @@ static int tuner_measure(unsigned char type, int scale, int duration) /* start counter, delay for specified time and stop it */ lv24020lp_write_set(CNT_CTRL, CNT_EN); - udelay(duration*1000 - 16); + +#ifdef CPU_PP + /* obtain actual duration, including interrupts that occurred and + * the time to write the counter stop */ + long usec = USEC_TIMER; +#endif + + udelay(duration*1000); + lv24020lp_write_clear(CNT_CTRL, CNT_EN); +#ifdef CPU_PP + duration = (USEC_TIMER - usec) / 1000; +#endif + + /* This function takes a loooong time and other stuff needs + running by now */ + yield(); + /* read tick count */ finval = (lv24020lp_read(CNT_H) << 8) | lv24020lp_read(CNT_L); @@ -512,10 +528,6 @@ static int tuner_measure(unsigned char type, int scale, int duration) else finval = scale*finval / duration; - /* This function takes a loooong time and other stuff needs - running by now */ - yield(); - return (int)finval; } @@ -532,6 +544,16 @@ static void set_frequency(int freq) enable_afc(false); + /* For the LV2400x, the tuned frequency is the sum of the displayed + * frequency and the preset IF frequency, in formula: + * Tuned FM frequency = displayed frequency + preset IF frequency + * + * For example: when the IF frequency of LV2400x is preset at 110 kHz, + * it must be tuned at 88.51 MHz to receive the radio station at 88.4 MHz. + * -- AN2400S04@ – V0.4 + */ + freq += if_set; + /* MHz -> kHz */ freq /= 1000;