FreeCalypso > hg > ice1-trau-tester
annotate ater/tx_func.c @ 19:1e375472d5a5
ater: implement TRAU frame output
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 24 Jun 2024 08:07:45 +0000 |
parents | 61862af2247f |
children | 0d70444b5070 |
rev | line source |
---|---|
18
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * Here we are going to implement Tx on Ater toward the TRAU. |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdint.h> |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdbool.h> |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <unistd.h> |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
19
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
12 #include <osmocom/core/msgb.h> |
18
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <osmocom/core/select.h> |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <osmocom/isdn/i460_mux.h> |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include "globals.h" |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include "submux.h" |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
19
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
19 void init_trau_ul_frame(int nr) |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
20 { |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
21 struct ater_subslot *at = &subslots[nr]; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
22 struct osmo_trau_frame *fr = &at->ul_frame; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
23 |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
24 fr->type = at->is_efr ? OSMO_TRAU16_FT_EFR : OSMO_TRAU16_FT_FR; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
25 fr->dir = OSMO_TRAU_DIR_UL; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
26 memset(fr->c_bits + 5, 0, 6); |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
27 memset(fr->c_bits + 15, 1, 6); |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
28 memset(fr->t_bits, 1, 4); |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
29 } |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
30 |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
31 static void tx_service_subslot(int nr) |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
32 { |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
33 struct ater_subslot *at = &subslots[nr]; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
34 struct osmo_trau_frame *fr = &at->ul_frame; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
35 struct msgb *msg; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
36 int len; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
37 |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
38 if (!at->is_active) |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
39 return; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
40 at->mfrm_count++; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
41 if (at->mfrm_count >= 24) { |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
42 at->mfrm_count = 0; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
43 fr->c_bits[14] = 1; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
44 } else { |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
45 fr->c_bits[14] = 0; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
46 } |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
47 msg = msgb_alloc_c(g_ctx, 640, "TRAU-UL-frame"); |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
48 if (!msg) |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
49 return; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
50 len = osmo_trau_frame_encode(msg->tail, msgb_tailroom(msg), fr); |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
51 msgb_put(msg, len); |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
52 osmo_i460_mux_enqueue(at->schan, msg); |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
53 } |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
54 |
18
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 void transmit_e1_ts(void) |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 { |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 uint8_t buf[160]; |
19
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
58 int nr; |
18
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 |
19
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
60 for (nr = 0; nr < ATER_SUBSLOTS; nr++) |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
61 tx_service_subslot(nr); |
18
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 osmo_i460_mux_out(&i460_ts, buf, 160); |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 write(ts_fd, buf, 160); |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 } |