src: use new libosmogsm and include/osmocom/[gsm|core] path to headers
[osmocom-bb.git] / src / target / firmware / layer1 / apc.c
1 /* APC (Automatic Power Control) Implementation */
2
3 /* (C) 2010 by Harald Welte <laforge@gnumonks.org>
4  *
5  * All Rights Reserved
6  *
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.
11  *
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.
16  *
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.
20  *
21  */
22
23 #include <errno.h>
24
25 #include <osmocom/core/utils.h>
26 #include <osmocom/gsm/gsm_utils.h>
27
28 #include <layer1/apc.h>
29
30 /* calibration table defined in board file */
31 extern const int16_t dbm2apc_gsm900[];
32 extern const int dbm2apc_gsm900_max;
33
34
35 /* determine the AUXAPC value by the Tx Power Level */
36 int16_t apc_tx_dbm2auxapc(enum gsm_band band, int8_t dbm)
37 {
38         if (dbm < 0)
39                 return -ERANGE;
40
41         /* FIXME: offsets for different bands! */
42         if (dbm > dbm2apc_gsm900_max)
43                 dbm = dbm2apc_gsm900_max;
44
45         return dbm2apc_gsm900[dbm];
46 }
47
48 /* determine the AUXAPC value by the Tx Power Level */
49 int16_t apc_tx_pwrlvl2auxapc(enum gsm_band band, uint8_t lvl)
50 {
51         /* convert tx power level to dBm */
52         int dbm = ms_pwr_dbm(band, lvl);
53         if (dbm < 0)
54                 return dbm;
55
56         return apc_tx_dbm2auxapc(band, dbm);
57 }