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