From a5c0b5deeb60a6844e4db5672366d296ae01546d Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Fri, 6 Sep 2013 21:29:31 -0700 Subject: [PATCH] Add MAX2837 functions to control operating mode. Replace direct manipulation of GPIOs controlling MAX2837 with operating mode functions. --- firmware/common/max2837.c | 53 ++++++++++++++++++++++++++------ firmware/common/max2837.h | 5 +++ firmware/hackrf_usb/hackrf_usb.c | 7 ++--- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/firmware/common/max2837.c b/firmware/common/max2837.c index c3d6d5cf..5473c6a6 100644 --- a/firmware/common/max2837.c +++ b/firmware/common/max2837.c @@ -220,14 +220,53 @@ void max2837_regs_commit(void) } } +void max2837_mode_shutdown(void) { + /* All circuit blocks are powered down, except the 4-wire serial bus + * and its internal programmable registers. + */ + gpio_clear(PORT_XCVR_ENABLE, + (PIN_XCVR_ENABLE | PIN_XCVR_RXENABLE | PIN_XCVR_TXENABLE)); +} + +void max2837_mode_standby(void) { + /* Used to enable the frequency synthesizer block while the rest of the + * device is powered down. In this mode, PLL, VCO, and LO generator + * are on, so that Tx or Rx modes can be quickly enabled from this mode. + * These and other blocks can be selectively enabled in this mode. + */ + gpio_clear(PORT_XCVR_ENABLE, (PIN_XCVR_RXENABLE | PIN_XCVR_TXENABLE)); + gpio_set(PORT_XCVR_ENABLE, PIN_XCVR_ENABLE); +} + +void max2837_mode_tx(void) { + /* All Tx circuit blocks are powered on. The external PA is powered on + * after a programmable delay using the on-chip PA bias DAC. The slow- + * charging Rx circuits are in a precharged “idle-off” state for fast + * Tx-to-Rx turnaround time. + */ + gpio_clear(PORT_XCVR_ENABLE, PIN_XCVR_RXENABLE); + gpio_set(PORT_XCVR_ENABLE, + (PIN_XCVR_ENABLE | PIN_XCVR_TXENABLE)); +} + +void max2837_mode_rx(void) { + /* All Rx circuit blocks are powered on and active. Antenna signal is + * applied; RF is downconverted, filtered, and buffered at Rx BB I and Q + * outputs. The slow- charging Tx circuits are in a precharged “idle-off” + * state for fast Rx-to-Tx turnaround time. + */ + gpio_clear(PORT_XCVR_ENABLE, PIN_XCVR_TXENABLE); + gpio_set(PORT_XCVR_ENABLE, + (PIN_XCVR_ENABLE | PIN_XCVR_RXENABLE)); +} + void max2837_start(void) { LOG("# max2837_start\n"); set_MAX2837_EN_SPI(1); max2837_regs_commit(); #if !defined TEST - gpio_clear(PORT_XCVR_ENABLE, (PIN_XCVR_RXENABLE | PIN_XCVR_TXENABLE)); - gpio_set(PORT_XCVR_ENABLE, PIN_XCVR_ENABLE); + max2837_mode_standby(); #endif } @@ -238,9 +277,7 @@ void max2837_tx(void) set_MAX2837_ModeCtrl(MAX2837_ModeCtrl_TxLPF); max2837_regs_commit(); - - gpio_clear(PORT_XCVR_ENABLE, PIN_XCVR_RXENABLE); - gpio_set(PORT_XCVR_ENABLE, PIN_XCVR_TXENABLE); + max2837_mode_tx(); #endif } @@ -252,8 +289,7 @@ void max2837_rx(void) max2837_regs_commit(); #if !defined TEST - gpio_clear(PORT_XCVR_ENABLE, PIN_XCVR_TXENABLE); - gpio_set(PORT_XCVR_ENABLE, PIN_XCVR_RXENABLE); + max2837_mode_rx(); #endif } @@ -263,8 +299,7 @@ void max2837_stop(void) set_MAX2837_EN_SPI(0); max2837_regs_commit(); #if !defined TEST - gpio_clear(PORT_XCVR_ENABLE, - (PIN_XCVR_ENABLE | PIN_XCVR_RXENABLE | PIN_XCVR_TXENABLE)); + max2837_mode_shutdown(); #endif } diff --git a/firmware/common/max2837.h b/firmware/common/max2837.h index 4c7d4f1e..0a09a497 100644 --- a/firmware/common/max2837.h +++ b/firmware/common/max2837.h @@ -37,6 +37,11 @@ extern void max2837_regs_read(void); * provided routines for those operations. */ extern void max2837_regs_commit(void); +void max2837_mode_shutdown(void); +void max2837_mode_standby(void); +void max2837_mode_tx(void); +void max2837_mode_rx(void); + /* Turn on/off all chip functions. Does not control oscillator and CLKOUT */ extern void max2837_start(void); extern void max2837_stop(void); diff --git a/firmware/hackrf_usb/hackrf_usb.c b/firmware/hackrf_usb/hackrf_usb.c index 48955d35..858d1093 100644 --- a/firmware/hackrf_usb/hackrf_usb.c +++ b/firmware/hackrf_usb/hackrf_usb.c @@ -115,7 +115,7 @@ bool set_freq(uint32_t freq_mhz, uint32_t freq_hz) success = true; - gpio_clear(PORT_XCVR_ENABLE, (PIN_XCVR_RXENABLE | PIN_XCVR_TXENABLE)); + max2837_mode_standby(); if(freq_mhz >= MIN_LP_FREQ_MHZ) { if(freq_mhz < MAX_LP_FREQ_MHZ) @@ -172,10 +172,9 @@ bool set_freq(uint32_t freq_mhz, uint32_t freq_hz) success = false; } if(transceiver_mode == TRANSCEIVER_MODE_RX) - gpio_set(PORT_XCVR_ENABLE, PIN_XCVR_RXENABLE); + max2837_mode_rx(); else if(transceiver_mode == TRANSCEIVER_MODE_TX) - gpio_set(PORT_XCVR_ENABLE, PIN_XCVR_TXENABLE); - + max2837_mode_tx(); freq_mhz_cache = freq_mhz; freq_hz_cache = freq_hz; return success;