summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@mur.at>2013-02-28 01:42:01 +0000
committerChristian Pointner <equinox@mur.at>2013-02-28 01:42:01 +0000
commit562599b0190e00897636cc6e12bcf540890495ae (patch)
tree73f94eba00546a39b9675fc6abbc249c062f8df9
parentrda1846dongle: fixed addr offset (diff)
rda1846dongle:
added functions to set/get frequency initalization of crystal git-svn-id: https://svn.spreadspace.org/mur.sat@687 7de4ea59-55d0-425e-a1af-a3118ea81d4c
-rw-r--r--software/rda1846dongle/rda1846.c77
-rw-r--r--software/rda1846dongle/rda1846.h4
2 files changed, 67 insertions, 14 deletions
diff --git a/software/rda1846dongle/rda1846.c b/software/rda1846dongle/rda1846.c
index e6807f3..187f598 100644
--- a/software/rda1846dongle/rda1846.c
+++ b/software/rda1846dongle/rda1846.c
@@ -26,10 +26,24 @@
#include "rda1846.h"
-#define RDA1846_CHIP_ADDR 0xE2
-#define RDA1846_ADDR_W (0<<7)
-#define RDA1846_ADDR_R (1<<7)
-#define RDA1846_ADDR_LIMIT 0x7F
+#define RDA1846_CHIP_ADDR 0xE2
+#define RDA1846_ADDR_W (0<<7)
+#define RDA1846_ADDR_R (1<<7)
+#define RDA1846_ADDR_LIMIT 0x7F
+
+#define RDA1846_RF_BAND_2M 0x00C0
+#define RDA1846_BAND_LOW 134000
+#define RDA1846_BAND_HIGH 174000
+#define RDA1846_XTAL_FREQ 12288
+#define RDA1846_ADCLK_FREQ 6144
+#define RDA1846_CLK_MODE (1<<0)
+
+#define RDA1846_REG_CLK_MODE 0x04
+#define RDA1846_REG_RF_BAND 0x0F
+#define RDA1846_REG_FREQH 0x29
+#define RDA1846_REG_FREQL 0x2A
+#define RDA1846_REG_XTAL 0x2B
+#define RDA1846_REG_ADCLK 0x2C
static uint8_t rda1846_write_register_raw(const uint8_t addr, const uint16_t data)
{
@@ -76,13 +90,7 @@ i2c_error:
return 1;
}
-
-void rda1846_init(void)
-{
- TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 200000));
-}
-
-uint8_t rda1846_write_register(const uint8_t addr, const uint16_t data)
+static uint8_t rda1846_write_register(const uint8_t addr, const uint16_t data)
{
if(addr < RDA1846_ADDR_LIMIT)
return rda1846_write_register_raw(addr, data);
@@ -99,7 +107,7 @@ uint8_t rda1846_write_register(const uint8_t addr, const uint16_t data)
return 1;
}
-uint8_t rda1846_read_register(const uint8_t addr, uint16_t* data)
+static uint8_t rda1846_read_register(const uint8_t addr, uint16_t* data)
{
if(addr < RDA1846_ADDR_LIMIT)
return rda1846_read_register_raw(addr, data);
@@ -115,3 +123,48 @@ uint8_t rda1846_read_register(const uint8_t addr, uint16_t* data)
}
return 1;
}
+
+
+void rda1846_init(void)
+{
+ TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 200000));
+ // switch to 2m Band (134 ~ 174 MHz)
+ rda1846_write_register(RDA1846_REG_RF_BAND, RDA1846_RF_BAND_2M);
+
+ // set crystal frequency (12.288 MHz)
+ rda1846_write_register(RDA1846_REG_XTAL, RDA1846_XTAL_FREQ);
+ rda1846_write_register(RDA1846_ADCLK_FREQ, RDA1846_REG_ADCLK);
+ rda1846_write_register(RDA1846_CLK_MODE, RDA1846_REG_CLK_MODE);
+}
+
+int32_t rda1846_get_freq_kHz(void)
+{
+ int32_t freq;
+
+ uint16_t data;
+ uint8_t ret = rda1846_read_register(RDA1846_REG_FREQH, &data);
+ if(ret)
+ return -1;
+
+ freq = (((uint32_t)data)<<16);
+ ret = rda1846_read_register(RDA1846_REG_FREQL, &data);
+ if(ret)
+ return -1;
+
+ freq |= data;
+
+ return (freq>>3);
+}
+
+uint8_t rda1846_set_freq_kHz(int32_t freq)
+{
+ if(freq < RDA1846_BAND_LOW || freq > RDA1846_BAND_HIGH)
+ return 1;
+
+ freq = freq<<3;
+ uint8_t ret = rda1846_write_register(RDA1846_REG_FREQH, (uint16_t)(freq>>16));
+ if(ret)
+ return 1;
+
+ return rda1846_write_register(RDA1846_REG_FREQL, (uint16_t)(freq & 0x0000FFFF));
+}
diff --git a/software/rda1846dongle/rda1846.h b/software/rda1846dongle/rda1846.h
index 1d2a2ae..9147c57 100644
--- a/software/rda1846dongle/rda1846.h
+++ b/software/rda1846dongle/rda1846.h
@@ -34,7 +34,7 @@
#define MURSAT_rda1846_h_INCLUDED
void rda1846_init(void);
-uint8_t rda1846_write_register(const uint8_t addr, const uint16_t data);
-uint8_t rda1846_read_register(const uint8_t addr, uint16_t* data);
+int32_t rda1846_get_freq_kHz(void);
+uint8_t rda1846_set_freq_kHz(int32_t freq);
#endif