#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 */
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)
#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 */
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)
#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 */
#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);
/* 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 */
#include <osmocore/gsm_utils.h>
+extern const uint8_t system_inherent_gain;
+
/* initialize RF Frontend */
void rffe_init(void);
/* 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
#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)
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;
#include <calypso/tpu.h>
#include <calypso/tsp.h>
+#include <layer1/agc.h>
+#include <rffe.h>
#include <rf/trf6151.h>
/* 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);
+}