a30a1e24ed847d9b88ab24b26795f381570a5296
[osmocom-bb.git] / src / target / firmware / include / layer1 / sync.h
1 #ifndef _L1_SYNC_H
2 #define _L1_SYNC_H
3
4 #include <osmocore/linuxlist.h>
5 #include <osmocore/gsm_utils.h>
6 #include <layer1/tdma_sched.h>
7 #include <l1a_l23_interface.h>
8
9 /* structure representing L1 sync information about a cell */
10 struct l1_cell_info {
11         /* on which ARFCN (+band) is the cell? */
12         uint16_t        arfcn;
13         /* what's the BSIC of the cell (from SCH burst decoding) */
14         uint32_t        bsic;
15         /* whats the delta of the cells current GSM frame number
16          * compared to our current local frame number */
17         int32_t         fn_offset;
18         /* how much does the TPU need adjustment (delta) to synchronize
19          * with the cells burst */
20         uint32_t        time_alignment;
21         /* FIXME: should we also store the AFC value? */
22 };
23
24 enum l1s_chan {
25         L1S_CHAN_MAIN,
26         L1S_CHAN_SACCH,
27         _NUM_L1S_CHAN
28 };
29
30
31 struct l1s_state {
32         struct gsm_time current_time;   /* current GSM time */
33         struct gsm_time next_time;      /* GSM time at next TMDMA irq */
34
35         /* the cell on which we are camping right now */
36         struct l1_cell_info serving_cell;
37
38         /* TDMA scheduler */
39         struct tdma_scheduler tdma_sched;
40
41         /* The current TPU offset register */
42         uint32_t        tpu_offset;
43
44         /* Transmit queues of pending packets for main DCCH and ACCH */
45         struct llist_head tx_queue[_NUM_L1S_CHAN];
46
47         /* bit-mask of multi-frame tasks that are currently active */
48         uint32_t        mf_tasks;
49
50         /* Structures below are for L1-task specific parameters, used
51          * to communicate between l1-sync and l1-async (l23_api) */
52         struct {
53                 /* power measurement l1 task */
54                 unsigned int mode;
55                 union {
56                         struct {
57                                 uint16_t arfcn_start;
58                                 uint16_t arfcn_next;
59                                 uint16_t arfcn_end;
60                         } range;
61                 };
62                 struct msgb *msg;
63         } pm;
64
65         struct {
66                 uint8_t         ra;
67         } rach;
68 };
69
70 extern struct l1s_state l1s;
71
72 enum l1_sig_num {
73         L1_SIG_PM,      /* Power Measurement */
74         L1_SIG_NB,      /* Normal Burst */
75 };
76
77 struct l1s_meas_hdr {
78         uint16_t snr;           /* signal/noise ratio */
79         int16_t toa_qbit;       /* time of arrival (qbits) */
80         int16_t pm_dbm8;        /* power level in dbm/8 */
81         int16_t freq_err;       /* Frequency error in Hz */
82 };
83
84 struct l1_signal {
85         uint16_t signum;
86         uint16_t arfcn;
87         union {
88                 struct {
89                         int16_t dbm8[2];
90                 } pm;
91                 struct {
92                         struct l1s_meas_hdr meas[4];
93                         uint16_t crc;
94                         uint16_t fire;
95                         uint16_t num_biterr;
96                         uint8_t frame[24];
97                 } nb;
98         };
99 };
100
101 typedef void (*l1s_cb_t)(struct l1_signal *sig);
102
103 void l1s_set_handler(l1s_cb_t handler);
104
105 int16_t l1s_snr_int(uint16_t snr);
106 uint16_t l1s_snr_fract(uint16_t snr);
107
108 void l1s_dsp_abort(void);
109
110 void l1s_fb_test(uint8_t base_fn, uint8_t fb_mode);
111 void l1s_sb_test(uint8_t base_fn);
112 void l1s_pm_test(uint8_t base_fn, uint16_t arfcn);
113 void l1s_nb_test(uint8_t base_fn);
114
115 void l1s_init(void);
116
117 /* reset the layer1 as part of synchronizing to a new cell */
118 void l1s_reset(void);
119
120 /* init.c */
121 void layer1_init(void);
122
123 #endif /* _L1_SYNC_H */