summaryrefslogtreecommitdiffstats
path: root/src/target/firmware/rf
diff options
context:
space:
mode:
authorHarald Welte2010-06-25 13:38:22 +0200
committerHarald Welte2010-06-25 13:39:58 +0200
commit028dcd9e2543c4f91667c393813de24ae4e90cb8 (patch)
tree367dbd8b198aa8bccc05cc458c6e62f271f4ebba /src/target/firmware/rf
parent[layer1] Power Measurement updates (diff)
downloadosmocom-028dcd9e2543c4f91667c393813de24ae4e90cb8.tar.gz
osmocom-028dcd9e2543c4f91667c393813de24ae4e90cb8.tar.xz
osmocom-028dcd9e2543c4f91667c393813de24ae4e90cb8.zip
[layer1] An actual AGC implementation
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.
Diffstat (limited to 'src/target/firmware/rf')
-rw-r--r--src/target/firmware/rf/trf6151.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/target/firmware/rf/trf6151.c b/src/target/firmware/rf/trf6151.c
index dfbad15..c1ae35a 100644
--- a/src/target/firmware/rf/trf6151.c
+++ b/src/target/firmware/rf/trf6151.c
@@ -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);
+}