FreeCalypso > hg > ice1-trau-tester
annotate ater/tx_func.c @ 41:50a72d4ff498
top Makefile: add libhr
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 30 Aug 2024 16:42:50 +0000 |
parents | 2742dbea95f1 |
children | 16715bd149e0 |
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> |
26
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
15 #include <osmocom/trau/trau_frame.h> |
18
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include "globals.h" |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 #include "submux.h" |
26
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
19 #include "out_frame.h" |
18
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
19
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
21 void init_trau_ul_frame(int nr) |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
22 { |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
23 struct ater_subslot *at = &subslots[nr]; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
24 struct osmo_trau_frame *fr = &at->ul_frame; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
25 |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
26 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
|
27 fr->dir = OSMO_TRAU_DIR_UL; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
28 memset(fr->c_bits + 5, 0, 6); |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
29 memset(fr->c_bits + 15, 1, 6); |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
30 memset(fr->t_bits, 1, 4); |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
31 } |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
32 |
26
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
33 static void handle_play(struct ater_subslot *at) |
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
34 { |
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
35 if (at->play_wait_align) { |
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
36 if (at->mfrm_count) |
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
37 return; |
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
38 at->play_wait_align = false; |
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
39 } |
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
40 trau_frame_from_record(at->play_buffer + at->play_buf_ptr * 34, |
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
41 at->is_efr, &at->ul_frame); |
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
42 at->play_buf_ptr++; |
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
43 if (at->play_buf_ptr < at->play_buf_total) |
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
44 return; |
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
45 free(at->play_buffer); |
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
46 at->play_buffer = NULL; |
27
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
47 printf("file play finished\n"); |
26
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
48 } |
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
49 |
19
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
50 static void tx_service_subslot(int nr) |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
51 { |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
52 struct ater_subslot *at = &subslots[nr]; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
53 struct osmo_trau_frame *fr = &at->ul_frame; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
54 struct msgb *msg; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
55 int len; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
56 |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
57 if (!at->is_active) |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
58 return; |
26
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
59 if (at->play_buffer) |
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
60 handle_play(at); |
19
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
61 at->mfrm_count++; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
62 if (at->mfrm_count >= 24) { |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
63 at->mfrm_count = 0; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
64 fr->c_bits[14] = 1; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
65 } else { |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
66 fr->c_bits[14] = 0; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
67 } |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
68 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
|
69 if (!msg) |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
70 return; |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
71 len = osmo_trau_frame_encode(msg->tail, msgb_tailroom(msg), fr); |
23
0d70444b5070
ater: more robust msgb handling in TRAU-UL output
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
72 if (len <= 0) { |
0d70444b5070
ater: more robust msgb handling in TRAU-UL output
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
73 msgb_free(msg); |
0d70444b5070
ater: more robust msgb handling in TRAU-UL output
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
74 return; |
0d70444b5070
ater: more robust msgb handling in TRAU-UL output
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
75 } |
19
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
76 msgb_put(msg, len); |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
77 osmo_i460_mux_enqueue(at->schan, msg); |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
78 } |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
79 |
18
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 void transmit_e1_ts(void) |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 { |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 uint8_t buf[160]; |
19
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
83 int nr; |
18
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 |
19
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
85 for (nr = 0; nr < ATER_SUBSLOTS; nr++) |
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
86 tx_service_subslot(nr); |
18
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 osmo_i460_mux_out(&i460_ts, buf, 160); |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 write(ts_fd, buf, 160); |
61862af2247f
ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 } |