[layer1] An actual AGC implementation
authorHarald Welte <laforge@gnumonks.org>
Fri, 25 Jun 2010 11:38:22 +0000 (13:38 +0200)
committerHarald Welte <laforge@gnumonks.org>
Fri, 25 Jun 2010 11:39:58 +0000 (13:39 +0200)
We introduce trf6151_compute_gain() to compute the gain setting that
leads to the ideal analog baseband power input level.

This function is called from rffe_set_gain() for both the compal and
the gta0x rf frontend, as there are no other amplifiers inside those
phone designs.

The new AGC function is not used yet from the regular layer1 code.

src/target/firmware/board/common/rffe_compal_dualband.c
src/target/firmware/board/common/rffe_gta0x_triband.c
src/target/firmware/include/layer1/agc.h
src/target/firmware/include/rf/trf6151.h
src/target/firmware/include/rffe.h
src/target/firmware/layer1/agc.c
src/target/firmware/rf/trf6151.c

index 6aa9381..bfd3d98 100644 (file)
@@ -7,6 +7,11 @@
 #include <calypso/tsp.h>
 #include <rf/trf6151.h>
 
+/* This is a value that has been measured on the C123 by Harald: 71dBm,
+   it is the difference between the input level at the antenna and what
+   the DSP reports, subtracted by the total gain of the TRF6151 */
+#define SYSTEM_INHERENT_GAIN   71
+
 /* describe how the RF frontend is wired on the Motorola E88 board (C117/C118/C121/C123) */
 
 #define                RITA_RESET      TSPACT(0)       /* Reset of the Rita TRF6151 */
@@ -60,11 +65,13 @@ uint8_t rffe_get_gain(void)
        return trf6151_get_gain();
 }
 
+const uint8_t system_inherent_gain = SYSTEM_INHERENT_GAIN;
+
 /* Given the expected input level of exp_inp dBm/8 and the target of target_bb
  * dBm8, configure the RF Frontend with the respective gain */
 void rffe_set_gain(int16_t exp_inp, int16_t target_bb)
 {
-       /* FIXME */
+       trf6151_compute_gain(exp_inp, target_bb);
 }
 
 void rffe_rx_win_ctrl(int16_t exp_inp, int16_t target_bb)
index 6406f04..a21cc61 100644 (file)
@@ -7,6 +7,11 @@
 #include <calypso/tsp.h>
 #include <rf/trf6151.h>
 
+/* This is a value that has been measured on the C123 by Harald: 71dBm,
+   it is the difference between the input level at the antenna and what
+   the DSP reports, subtracted by the total gain of the TRF6151 */
+#define SYSTEM_INHERENT_GAIN   71
+
 /* describe how the RF frontend is wired on the Openmoko GTA0x boards */
 
 #define                RITA_RESET      TSPACT(0)       /* Reset of the Rita TRF6151 */
@@ -75,11 +80,14 @@ uint8_t rffe_get_gain(void)
        return trf6151_get_gain();
 }
 
+const uint8_t system_inherent_gain = SYSTEM_INHERENT_GAIN;
+
+#define to_dbm8(x)     ((x)*8)
 /* Given the expected input level of exp_inp dBm/8 and the target of target_bb
  * dBm8, configure the RF Frontend with the respective gain */
 void rffe_set_gain(int16_t exp_inp, int16_t target_bb)
 {
-       /* FIXME */
+       trf6151_compute_gain(exp_inp, target_bb);
 }
 
 void rffe_rx_win_ctrl(int16_t exp_inp, int16_t target_bb)
index e4b13f1..2b7e46e 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef _L1_AGC_H
 #define _L1_AGC_H
 
+#define to_dbm8(x)     ((x)*8)
 int16_t agc_inp_dbm8_by_pm(int16_t pm);
 
 #endif /* _L1_AGC_H */
index 889baaa..f1b54f2 100644 (file)
@@ -3,6 +3,13 @@
 
 #include <osmocore/gsm_utils.h>
 
+/* minimum gain (FE = LOW, VGA at lowest setting */
+#define TRF6151_GAIN_MIN       14
+/* minimum gain (FE = HIGH, VGA at highest setting */
+#define TRF6151_GAIN_MAX       60
+/* Frontend gain if FE = HIGH */
+#define TRF6151_GAIN_FE                20
+
 /* initialize (reset + power up) */
 void trf6151_init(void);
 
@@ -35,4 +42,9 @@ void trf6151_rx_window(int16_t start_qbits, uint16_t arfcn, uint8_t vga_dbm, int
 
 /* prepare a Tx window with the TRF6151 finished at time 'start' (in qbits) */
 void trf6151_tx_window(int16_t start_qbits, uint16_t arfcn);
+
+/* Given the expected input level of exp_inp dBm/8 and the target of target_bb
+ * dBm8, configure the RF Frontend with the respective gain */
+void trf6151_compute_gain(int16_t exp_inp, int16_t target_bb);
+
 #endif /* TRF6151_H */
index e397f9c..950e597 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <osmocore/gsm_utils.h>
 
+extern const uint8_t system_inherent_gain;
+
 /* initialize RF Frontend */
 void rffe_init(void);
 
@@ -12,4 +14,6 @@ void rffe_mode(enum gsm_band band, int tx);
 /* get current gain of RF frontend (anything between antenna and baseband in dBm */
 uint8_t rffe_get_gain(void);
 
+void rffe_set_gain(int16_t exp_inp, int16_t target_bb);
+
 #endif
index 09fa825..780e260 100644 (file)
 #include <layer1/agc.h>
 #include <calypso/dsp.h>
 
-/* This is a value that has been measured on the C123 by Harald: 71dBm,
-   it is the difference between the input level at the antenna and what
-   the DSP reports, subtracted by the total gain of the TRF6151 */
-#define SYSTEM_INHERENT_GAIN   71
-
 /* compute the input level present at the antenna based on a baseband
  * power measurement of the DSP at baseband */
 int16_t agc_inp_dbm8_by_pm(int16_t pm)
@@ -43,7 +38,7 @@ int16_t agc_inp_dbm8_by_pm(int16_t pm)
        int16_t total_gain_dbm8;
 
        /* compute total current gain */
-       total_gain_dbm8 = (SYSTEM_INHERENT_GAIN + rffe_get_gain()) * 8;
+       total_gain_dbm8 = (system_inherent_gain + rffe_get_gain()) * 8;
 
        /* subtract gain from power measurement at baseband level */
        return pm - total_gain_dbm8;
index dfbad15..c1ae35a 100644 (file)
@@ -30,6 +30,8 @@
 
 #include <calypso/tpu.h>
 #include <calypso/tsp.h>
+#include <layer1/agc.h>
+#include <rffe.h>
 
 #include <rf/trf6151.h>
 
@@ -457,3 +459,36 @@ void trf6151_tx_window(int16_t start_qbits, uint16_t arfcn)
        /* FIXME: power down at the right time again */
 #endif
 }
+
+/* Given the expected input level of exp_inp dBm/8 and the target of target_bb
+ * dBm8, configure the RF Frontend with the respective gain */
+void trf6151_compute_gain(int16_t exp_inp, int16_t target_bb)
+{
+       /* TRF6151 VGA gain between 14 to 40 dB, plus 20db high/low */
+       int16_t exp_bb, delta;
+       int16_t vga_gain = TRF6151_GAIN_MIN;
+       int high = 0;
+
+       /* calculate the dBm8 that we expect at the baseband */
+       exp_bb = exp_inp + to_dbm8(system_inherent_gain);
+
+       /* calculate the error that we expect. */
+       delta = target_bb - exp_bb;
+
+       /* If this is negative or less than TRF6151_GAIN_MIN, we are pretty
+        * much lost as we cannot reduce the system inherent gain.  If it is
+        * positive, it corresponds to the gain that we need to configure */
+       if (delta < to_dbm8(TRF6151_GAIN_MIN)) {
+               printd("AGC Input level overflow\n");
+               high = 0;
+               vga_gain = TRF6151_GAIN_MIN;
+       } else if (delta > to_dbm8(TRF6151_GAIN_FE + TRF6151_GAIN_MIN)) {
+               high = 1;
+               delta -= to_dbm8(TRF6151_GAIN_FE);
+       }
+       vga_gain = to_dbm8(delta);
+       if (vga_gain > TRF6151_GAIN_MAX)
+               vga_gain = TRF6151_GAIN_MAX;
+
+       trf6151_set_gain(vga_gain, high);
+}