diff options
Diffstat (limited to 'software')
-rw-r--r-- | software/rda1846dongle/rda1846.c | 125 | ||||
-rw-r--r-- | software/rda1846dongle/rda1846.h | 8 | ||||
-rw-r--r-- | software/rda1846dongle/rda1846_defines.h | 3 | ||||
-rw-r--r-- | software/rda1846dongle/rda1846dongle.c | 34 |
4 files changed, 151 insertions, 19 deletions
diff --git a/software/rda1846dongle/rda1846.c b/software/rda1846dongle/rda1846.c index ecab5d3..c806036 100644 --- a/software/rda1846dongle/rda1846.c +++ b/software/rda1846dongle/rda1846.c @@ -44,6 +44,7 @@ static uint8_t rda1846_write_register_raw(const uint8_t addr, const uint16_t dat i2c_error: TWI_StopTransmission(); + printf("I2C error (write_register_raw)\r\n"); return 1; } @@ -69,6 +70,7 @@ static uint8_t rda1846_read_register_raw(const uint8_t addr, uint16_t* data) i2c_error: TWI_StopTransmission(); + printf("I2C error (write_register_raw)\r\n"); return 1; } @@ -112,6 +114,7 @@ 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); +// rda1846_write_register(RDA1846_REG_RF_BAND, RDA1846_RF_BAND_70CM); // set crystal frequency (12.288 MHz) rda1846_write_register(RDA1846_REG_XTAL, RDA1846_XTAL_FREQ); @@ -128,8 +131,53 @@ void rda1846_init(void) // use this if VOX, SQ, TXON_RF, RXON_RF are meant as inputs // rda1846_write_register(RDA1846_REG_GPIO, RDA1846_GPIO_2_INT); - rda1846_write_register(RDA1846_REG_TX_VOICE, RDA1846_TX_VOICE_NONE); - rda1846_write_register(RDA1846_REG_DTMF_CTL, RDA1846_DTMF_DUAL | RDA1846_DTMF_EN); +// rda1846_write_register(RDA1846_REG_TX_VOICE, RDA1846_TX_VOICE_NONE); + rda1846_write_register(RDA1846_REG_TX_VOICE, RDA1846_TX_VOICE_MIC); +// rda1846_write_register(RDA1846_REG_TX_VOICE, RDA1846_TX_VOICE_TONE2); + +// rda1846_write_register(RDA1846_REG_DTMF_CTL, RDA1846_DTMF_DUAL | RDA1846_DTMF_EN); +} + +void rda1846_powerdown(void) +{ + uint16_t data; + if(rda1846_read_register(RDA1846_REG_CTL, &data)) + return; + + data &= ~(RDA1846_CTL_PDN); + rda1846_write_register(RDA1846_REG_CTL, data); +} + +void rda1846_wakeup(void) +{ + uint16_t data; + if(rda1846_read_register(RDA1846_REG_CTL, &data)) + return; + + data |= RDA1846_CTL_PDN; + rda1846_write_register(RDA1846_REG_CTL, data); +} + +void rda1846_receive(void) +{ + uint16_t data; + if(rda1846_read_register(RDA1846_REG_CTL, &data)) + return; + + data |= RDA1846_CTL_RX; + data &= ~(RDA1846_CTL_TX); + rda1846_write_register(RDA1846_REG_CTL, data); +} + +void rda1846_transmit(void) +{ + uint16_t data; + if(rda1846_read_register(RDA1846_REG_CTL, &data)) + return; + + data &= ~(RDA1846_CTL_RX); + data |= RDA1846_CTL_TX; + rda1846_write_register(RDA1846_REG_CTL, data); } void rda1846_soft_reset(void) @@ -161,8 +209,8 @@ uint16_t rda1846_get_flags(void) uint16_t data; if(rda1846_read_register(RDA1846_REG_FLAG, &data)) return 0xFFFF; - - return data; + + return data & 0x1687; } uint8_t rda1846_get_dtmf(uint8_t* idx1, uint8_t* idx2, uint8_t* code) @@ -187,25 +235,80 @@ int32_t rda1846_get_freq_kHz(void) if(ret) return -1; - freq = (((uint32_t)data)<<16); + freq = (((uint32_t)(data & 0x3FFF))<<16); ret = rda1846_read_register(RDA1846_REG_FREQL, &data); if(ret) return -1; - freq |= data; - + freq += data; return (freq>>3); } +#define RDA1846_BAND_LOW 134000 // kHz +#define RDA1846_BAND_HIGH 174000 // kHZ + uint8_t rda1846_set_freq_kHz(int32_t freq) { - if(freq < RDA1846_BAND_LOW || freq > RDA1846_BAND_HIGH) - return 1; + /* 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)); + uint8_t ret = rda1846_write_register(RDA1846_REG_FREQH, ((freq>>16) & 0x0000FFFF)); if(ret) return 1; - return rda1846_write_register(RDA1846_REG_FREQL, (uint16_t)(freq & 0x0000FFFF)); + return rda1846_write_register(RDA1846_REG_FREQL, (freq & 0x0000FFFF)); +} + +char* rda1846_regaddr_to_string(uint8_t addr) +{ + switch(addr) { + case RDA1846_REG_CTL: return "CTL"; + case RDA1846_REG_GPIO: return "GPIO"; + case RDA1846_REG_INT: return "INT"; + case RDA1846_REG_FLAG: return "FLAG"; + case RDA1846_REG_RSSI: return "RSSI"; + case RDA1846_REG_VSSI: return "VSSI"; + case RDA1846_REG_CLK_MODE: return "CLK_MODE"; + case RDA1846_REG_XTAL: return "XTAL"; + case RDA1846_REG_ADCLK: return "ADCLK"; + case RDA1846_REG_RF_BAND: return "RF_BAND"; + case RDA1846_REG_FREQH: return "FREQH"; + case RDA1846_REG_FREQL: return "FREQL"; + case RDA1846_REG_PA_BIAS: return "PA_BIAS"; + case RDA1846_REG_TX_VOICE: return "TX_VOICE"; + case RDA1846_REG_VOX_OPEN: return "VOX_OPEN"; + case RDA1846_REG_VOX_SHUT: return "VOX_SHUT"; + case RDA1846_REG_SUBAUDIO: return "SUBAUDIO"; + case RDA1846_REG_SQ_OPEN: return "SQ_OPEN"; + case RDA1846_REG_SQ_SHUT: return "SQ_SHUT"; + case RDA1846_REG_DTMF_CTL: return "DTMF_CTL"; + case RDA1846_REG_DTMF_T1: return "DTMF_T1"; + case RDA1846_REG_DTMF_T2: return "DTMF_T2"; + case RDA1846_REG_DTMF_C01: return "DTMF_C01"; + case RDA1846_REG_DTMF_C23: return "DTMF_C23"; + case RDA1846_REG_DTMF_C45: return "DTMF_C45"; + case RDA1846_REG_DTMF_C67: return "DTMF_C67"; + case RDA1846_REG_DTMF_OUT: return "DTMF_OUT"; + default: return "unknown"; + } +} + +void rda1846_dump_register(void) +{ + printf("RDA1846: register dump\r\n"); + + const uint8_t regs[] = { RDA1846_REG_RF_BAND, RDA1846_REG_XTAL, RDA1846_REG_ADCLK, + RDA1846_REG_CLK_MODE, RDA1846_REG_CTL, RDA1846_REG_INT, + RDA1846_REG_GPIO, RDA1846_REG_TX_VOICE, RDA1846_REG_DTMF_CTL, + RDA1846_REG_RSSI, RDA1846_REG_VSSI, RDA1846_REG_FLAG, + RDA1846_REG_DTMF_OUT, RDA1846_REG_FREQH, RDA1846_REG_FREQL }; + + int i; + for(i=0; i<sizeof(regs); ++i) { + uint16_t data; + if(rda1846_read_register(regs[i], &data)) + data = 0xFFFF; + printf(" 0x%02X (%s): 0x%04X\r\n", regs[i], rda1846_regaddr_to_string(regs[i]), data); + } } diff --git a/software/rda1846dongle/rda1846.h b/software/rda1846dongle/rda1846.h index e755bee..71d292b 100644 --- a/software/rda1846dongle/rda1846.h +++ b/software/rda1846dongle/rda1846.h @@ -36,6 +36,12 @@ void rda1846_init(void); void rda1846_soft_reset(void); +void rda1846_powerdown(void); +void rda1846_wakeup(void); + +void rda1846_receive(void); +void rda1846_transmit(void); + int16_t rda1846_get_rssi(void); int16_t rda1846_get_vssi(void); uint16_t rda1846_get_flags(void); @@ -44,4 +50,6 @@ uint8_t rda1846_get_dtmf(uint8_t*, uint8_t*, uint8_t*); int32_t rda1846_get_freq_kHz(void); uint8_t rda1846_set_freq_kHz(int32_t freq); +void rda1846_dump_register(void); + #endif diff --git a/software/rda1846dongle/rda1846_defines.h b/software/rda1846dongle/rda1846_defines.h index ab4b496..ad08703 100644 --- a/software/rda1846dongle/rda1846_defines.h +++ b/software/rda1846dongle/rda1846_defines.h @@ -77,8 +77,7 @@ // init values #define RDA1846_RF_BAND_2M 0x00C0 // select 2m Band -#define RDA1846_BAND_LOW 134000 // kHz -#define RDA1846_BAND_HIGH 174000 // kHZ +#define RDA1846_RF_BAND_70CM 0x0000 // select 70cm Band #define RDA1846_XTAL_FREQ 12288 // 12.288 MHz #define RDA1846_ADCLK_FREQ 6144 // 12.288/2 MHz #define RDA1846_CLK_MODE (1<<0) // 12-14 MHz diff --git a/software/rda1846dongle/rda1846dongle.c b/software/rda1846dongle/rda1846dongle.c index 4c78168..ebb97de 100644 --- a/software/rda1846dongle/rda1846dongle.c +++ b/software/rda1846dongle/rda1846dongle.c @@ -43,8 +43,20 @@ #include "rda1846_defines.h" #define DEFAULT_FREQ 145900 +//#define DEFAULT_FREQ 409750 int32_t current_freq_kHz = DEFAULT_FREQ; +static void set_default_freq(void) +{ + printf("setting frequency to %d.%03d MHz .. ", (uint16_t)(current_freq_kHz / 1000), + (uint16_t)(current_freq_kHz % 1000)); + current_freq_kHz = DEFAULT_FREQ; + if(rda1846_set_freq_kHz(current_freq_kHz)) + printf("error\r\n"); + else + printf("ok\r\n"); +} + static int32_t print_actual_freq(void) { int32_t f = rda1846_get_freq_kHz(); @@ -59,14 +71,18 @@ static void update_current_freq(void) { printf("setting frequency to %d.%03d MHz .. ", (uint16_t)(current_freq_kHz / 1000), (uint16_t)(current_freq_kHz % 1000)); + rda1846_powerdown(); + if(rda1846_set_freq_kHz(current_freq_kHz)) printf("error\r\n"); else printf("ok\r\n"); - current_freq_kHz = print_actual_freq(); - if(current_freq_kHz < 0) - current_freq_kHz = DEFAULT_FREQ; + rda1846_wakeup(); + + /* current_freq_kHz = print_actual_freq(); */ + /* if(current_freq_kHz < 0) */ + /* current_freq_kHz = DEFAULT_FREQ; */ } static void print_status(void) @@ -110,9 +126,18 @@ static void handle_cmd(uint8_t cmd) case 't': led_toggle(); printf("led TOGGLE\r\n"); break; case '!': reset2bootloader(); break; case 'r': rda1846_soft_reset(); printf("soft resetting RDA1846.\r\n"); break; + case 'i': rda1846_init(); printf("initializing RDA1846.\r\n"); break; + case 'F': set_default_freq(); break; case 'f': print_actual_freq(); break; case 's': print_status(); break; case 'd': print_dtmf(); break; + case 'D': rda1846_dump_register(); break; + case 'p': rda1846_powerdown(); break; + case 'P': rda1846_wakeup(); break; + + case 'R': rda1846_receive(); break; + case 'T': rda1846_transmit(); break; + case '+': current_freq_kHz+=25; update_current_freq(); break; case '-': current_freq_kHz-=25; update_current_freq(); break; default: printf("\r\n"); return; @@ -129,9 +154,6 @@ int main(void) usbio_init(); sei(); - rda1846_init(); - rda1846_set_freq_kHz(current_freq_kHz); - for(;;) { int16_t BytesReceived = usbio_bytes_received(); while(BytesReceived > 0) { |