annotate ater/tx_func.c @ 46:12415d7ce262

README: document itt-ater-8
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 12 Sep 2024 17:43:39 +0000
parents 16715bd149e0
children 13fffc41f989
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
44
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
33 void init_trau_ul_frame_csd(int nr, bool ir_16k)
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
34 {
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
35 struct ater_subslot *at = &subslots[nr];
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
36 struct osmo_trau_frame *fr = &at->ul_frame;
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
37
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
38 fr->type = OSMO_TRAU16_FT_DATA;
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
39 fr->dir = OSMO_TRAU_DIR_UL;
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
40 fr->c_bits[5] = ir_16k;
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
41 memset(fr->c_bits + 6, 1, 9);
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
42 memset(fr->d_bits, 1, 63 * 4);
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
43 }
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
44
26
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
45 static void handle_play(struct ater_subslot *at)
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
46 {
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
47 if (at->play_wait_align) {
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
48 if (at->mfrm_count)
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
49 return;
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
50 at->play_wait_align = false;
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
51 }
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
52 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
53 at->is_efr, &at->ul_frame);
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
54 at->play_buf_ptr++;
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
55 if (at->play_buf_ptr < at->play_buf_total)
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
56 return;
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
57 free(at->play_buffer);
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
58 at->play_buffer = NULL;
27
2742dbea95f1 ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
59 printf("file play finished\n");
26
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
60 }
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
61
19
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
62 static void tx_service_subslot(int nr)
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
63 {
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
64 struct ater_subslot *at = &subslots[nr];
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
65 struct osmo_trau_frame *fr = &at->ul_frame;
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
66 struct msgb *msg;
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
67 int len;
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
68
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
69 if (!at->is_active)
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
70 return;
26
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
71 if (at->play_buffer)
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
72 handle_play(at);
44
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
73 if (!at->is_data) {
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
74 at->mfrm_count++;
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
75 if (at->mfrm_count >= 24) {
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
76 at->mfrm_count = 0;
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
77 fr->c_bits[14] = 1;
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
78 } else {
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
79 fr->c_bits[14] = 0;
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
80 }
19
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
81 }
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
82 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
83 if (!msg)
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
84 return;
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
85 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
86 if (len <= 0) {
0d70444b5070 ater: more robust msgb handling in TRAU-UL output
Mychaela Falconia <falcon@freecalypso.org>
parents: 19
diff changeset
87 msgb_free(msg);
0d70444b5070 ater: more robust msgb handling in TRAU-UL output
Mychaela Falconia <falcon@freecalypso.org>
parents: 19
diff changeset
88 return;
0d70444b5070 ater: more robust msgb handling in TRAU-UL output
Mychaela Falconia <falcon@freecalypso.org>
parents: 19
diff changeset
89 }
19
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
90 msgb_put(msg, len);
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
91 osmo_i460_mux_enqueue(at->schan, msg);
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
92 }
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
93
18
61862af2247f ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 void transmit_e1_ts(void)
61862af2247f ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 {
61862af2247f ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 uint8_t buf[160];
19
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
97 int nr;
18
61862af2247f ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98
19
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
99 for (nr = 0; nr < ATER_SUBSLOTS; nr++)
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
100 tx_service_subslot(nr);
18
61862af2247f ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 osmo_i460_mux_out(&i460_ts, buf, 160);
61862af2247f ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 write(ts_fd, buf, 160);
61862af2247f ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 }