1 /* AFC (Automatic Gain Control) Implementation */
3 /* (C) 2010 by Harald Welte <laforge@gnumonks.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <osmocore/gsm_utils.h>
30 #include <layer1/agc.h>
31 #include <calypso/dsp.h>
33 /* compute the input level present at the antenna based on a baseband
34 * power measurement of the DSP at baseband */
35 int16_t agc_inp_dbm8_by_pm(int16_t pm)
37 /* pm is in 1/8 dBm at baseband */
38 int16_t total_gain_dbm8;
40 /* compute total current gain */
41 total_gain_dbm8 = (system_inherent_gain + rffe_get_gain()) * 8;
43 /* subtract gain from power measurement at baseband level */
44 return pm - total_gain_dbm8;
47 uint8_t agc_il_by_dbm8(int16_t dbm8)
51 /* convert from 1/8 dBm to l1c format: [220..0] in -1/2dBm unit */
61 return (uint8_t)(il >> 2);