annotate abis/subslot_rx.c @ 33:351bd801cdce

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