FreeCalypso > hg > fc-rfcal-tools
annotate autocal/rxcommon.c @ 63:131abadbd74d
doc/Rx-cal-theory written
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 28 May 2017 03:21:34 +0000 |
parents | 1a0dbc746d57 |
children |
rev | line source |
---|---|
44
5018fd8eecce
autocal: started Rx cal core code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
5018fd8eecce
autocal: started Rx cal core code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module contains the common code for |
5018fd8eecce
autocal: started Rx cal core code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * fc-rfcal-gmagic and fc-rfcal-rxband. |
5018fd8eecce
autocal: started Rx cal core code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
5018fd8eecce
autocal: started Rx cal core code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
5018fd8eecce
autocal: started Rx cal core code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
5018fd8eecce
autocal: started Rx cal core code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdlib.h> |
49
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
8 #include <unistd.h> |
44
5018fd8eecce
autocal: started Rx cal core code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <rvinterf/l1tm.h> |
5018fd8eecce
autocal: started Rx cal core code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <rvinterf/exitcodes.h> |
49
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
11 #include "l1stats.h" |
44
5018fd8eecce
autocal: started Rx cal core code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "rxcaldefs.h" |
5018fd8eecce
autocal: started Rx cal core code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
5018fd8eecce
autocal: started Rx cal core code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 l1tm_setup_for_rxcal() |
5018fd8eecce
autocal: started Rx cal core code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 { |
5018fd8eecce
autocal: started Rx cal core code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 do_rxpw(RX_AGC_ENA_FLAG, 0); |
5018fd8eecce
autocal: started Rx cal core code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 do_rxpw(RX_AGC_GAIN, RXCAL_AGC_DB); |
5018fd8eecce
autocal: started Rx cal core code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 do_rfpw(AFC_ENA_FLAG, 0); |
45
98abe6bd2042
autocal: scw implemented for Rx cal
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
19 do_scw(LOOPS, RXCAL_LOOP_COUNT); |
98abe6bd2042
autocal: scw implemented for Rx cal
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
20 do_scw(AUTO_RESULT_LOOPS, RXCAL_LOOP_COUNT); |
98abe6bd2042
autocal: scw implemented for Rx cal
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
21 do_scw(AUTO_RESET_LOOPS, RXCAL_LOOP_COUNT); |
98abe6bd2042
autocal: scw implemented for Rx cal
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
22 do_scw(STAT_TYPE, ACCUMULATED_RX_STATS); |
98abe6bd2042
autocal: scw implemented for Rx cal
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
23 do_scw(STAT_BITMASK, DSP_PM); |
44
5018fd8eecce
autocal: started Rx cal core code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 return(0); |
5018fd8eecce
autocal: started Rx cal core code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 } |
46
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
26 |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
27 halfdb_to_string(halfdb, strbuf) |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
28 int halfdb; |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
29 char *strbuf; |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
30 { |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
31 int sign; |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
32 |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
33 if (halfdb < 0) { |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
34 sign = 1; |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
35 halfdb = -halfdb; |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
36 } else |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
37 sign = 0; |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
38 sprintf(strbuf, "%s%d.%c", sign ? "-" : "", halfdb >> 1, |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
39 halfdb & 1 ? '5' : '0'); |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
40 return(0); |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
41 } |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
42 |
49
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
43 static unsigned |
46
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
44 rx_single_offset_meas(arfcn, offset) |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
45 unsigned arfcn; |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
46 char *offset; |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
47 { |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
48 char dbm[64], tsid_cmd[128]; |
49
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
49 struct l1stats l1st; |
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
50 unsigned pm; |
46
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
51 |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
52 halfdb_to_string(RXCAL_SIGGEN_LEVEL, dbm); |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
53 printf("Rx meas at ARFCN %u offset %s kHz, TL=%s dBm, AGC=%d dB\n", |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
54 arfcn, offset, dbm, RXCAL_AGC_DB); |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
55 sprintf(tsid_cmd, "signal-gen-sine %u %s %s\n", arfcn, offset, dbm); |
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
56 tsid_command(tsid_cmd); |
49
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
57 usleep(20000); |
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
58 do_rfe(RX_TCH); |
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
59 collect_auto_stats(&l1st); |
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
60 collect_rfe_completion(); |
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
61 if (!(l1st.bitmask & DSP_PM)) { |
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
62 fprintf(stderr, "DUT error: no DSP_PM in auto-stats msg\n"); |
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
63 exit(ERROR_TARGET); |
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
64 } |
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
65 pm = l1st.dsp_pm; |
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
66 printf("DSP_PM=0x%04X, %u half-dBm\n", pm, (pm + 16) >> 5); |
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
67 return(pm); |
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
68 } |
46
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
69 |
49
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
70 unsigned |
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
71 rx_measure(arfcn) |
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
72 unsigned arfcn; |
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
73 { |
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
74 unsigned pm1, pm2; |
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
75 |
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
76 do_rfpw(TCH_ARFCN, arfcn); |
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
77 pm1 = rx_single_offset_meas(arfcn, "+67"); |
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
78 pm2 = rx_single_offset_meas(arfcn, "-67"); |
1a0dbc746d57
autocal: Rx cal main engine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
79 return (pm1 + pm2 + 32) >> 6; |
46
751f8d9efed0
Rx cal: started the single measurement code
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
80 } |