FreeCalypso > hg > e1-fake-trau
annotate ft16/subslot_rx.c @ 3:19047c3302a9
ft16: add Makefile
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 29 Aug 2024 13:09:39 +0000 |
parents | 5c18cd38c8ad |
children |
rev | line source |
---|---|
2
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * Here we are going to implement Abis subslot Rx. |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdint.h> |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdbool.h> |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <osmocom/core/select.h> |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <osmocom/core/utils.h> |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <osmocom/isdn/i460_mux.h> |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <osmocom/trau/trau_sync.h> |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include "globals.h" |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include "submux.h" |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 void i460_rx_func(struct osmo_i460_subchan *schan, void *user_data, |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 const ubit_t *bits, unsigned int num_bits) |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 { |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 struct abis_subslot *ab = user_data; |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 osmo_trau_sync_rx_ubits(ab->sync, bits, num_bits); |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 } |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 static void sync_lost(struct abis_subslot *ab) |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 { |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 if (!ab->got_sync) |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 return; |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 printf("Subslot %d lost frame sync\n", ab->nr); |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 ab->got_sync = false; |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 } |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 /* function copied from libosmo-abis/src/trau/trau_frame.c */ |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 static uint32_t get_bits(const ubit_t *bitbuf, int offset, int num) |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 { |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 int i; |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 uint32_t ret = 0; |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 for (i = offset; i < offset + num; i++) { |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 ret = ret << 1; |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 if (bitbuf[i]) |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 ret |= 1; |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 } |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 return ret; |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 } |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 void sync_rx_func(void *user_data, const ubit_t *bits, unsigned int num_bits) |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 { |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 struct abis_subslot *ab = user_data; |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 uint8_t ft; |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 if (!bits) { |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 sync_lost(ab); |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 return; |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 } |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 OSMO_ASSERT(num_bits == 320); |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 ft = get_bits(bits, 17, 5); |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 if (!ab->got_sync) { |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 printf("Subslot %d got frame sync with FT=0x%02X\n", |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 ab->nr, ft); |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 ab->got_sync = true; |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 ab->frame_type = ft; |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 return; |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 if (ft == ab->frame_type) |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 return; |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 printf("Subslot %d changed frame type from 0x%02X to 0x%02X\n", ab->nr, |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 ab->frame_type, ft); |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 ab->frame_type = ft; |
5c18cd38c8ad
ft16: import from ice1-trau-tester/abis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 } |