annotate ater8/tx_func.c @ 43:55f02d4aee79

top Makefile: add ater8
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 30 Aug 2024 19:04:57 +0000
parents ff94d7fc5891
children 3cc26391d24d
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
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
12 #include <osmocom/core/bits.h>
19
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
13 #include <osmocom/core/msgb.h>
18
61862af2247f ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <osmocom/core/select.h>
61862af2247f ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <osmocom/isdn/i460_mux.h>
26
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
16 #include <osmocom/trau/trau_frame.h>
18
61862af2247f ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
61862af2247f ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include "globals.h"
61862af2247f ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #include "submux.h"
26
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
20 #include "out_frame.h"
18
61862af2247f ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
19
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
22 void init_trau_ul_frame(int nr)
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 struct ater_subslot *at = &subslots[nr];
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
25 struct osmo_trau_frame *fr = &at->ul_frame;
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
26
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
27 fr->type = OSMO_TRAU8_SPEECH;
19
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
28 fr->dir = OSMO_TRAU_DIR_UL;
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
29 memset(fr->c_bits + 5, 1, 3);
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
30 fr->xc_bits[0] = 0;
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
31 memset(fr->t_bits, 1, 2);
19
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
26
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
34 static void handle_play(struct ater_subslot *at)
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
35 {
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
36 if (at->play_wait_align) {
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
37 if (at->mfrm_count)
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
38 return;
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
39 at->play_wait_align = false;
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
40 }
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
41 trau_frame_from_record(at->play_buffer + at->play_buf_ptr * 22,
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
42 &at->ul_frame, &at->frame_has_taf);
26
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
43 at->play_buf_ptr++;
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
44 if (at->play_buf_ptr < at->play_buf_total)
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
45 return;
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
46 free(at->play_buffer);
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
47 at->play_buffer = NULL;
27
2742dbea95f1 ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
48 printf("file play finished\n");
26
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
49 }
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
50
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
51 /* compute the odd parity bit of the given input bit sequence */
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
52 static ubit_t compute_odd_parity(const ubit_t *in, unsigned int num_bits)
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
53 {
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
54 int i;
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
55 unsigned int sum = 0;
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
56
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
57 for (i = 0; i < num_bits; i++) {
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
58 if (in[i])
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
59 sum++;
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
60 }
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
61
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
62 if (sum & 1)
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
63 return 0;
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
64 else
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
65 return 1;
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
66 }
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
67
19
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
68 static void tx_service_subslot(int nr)
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
69 {
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
70 struct ater_subslot *at = &subslots[nr];
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
71 struct osmo_trau_frame *fr = &at->ul_frame;
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
72 ubit_t taf;
19
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
73 struct msgb *msg;
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
74 int len;
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
75
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
76 if (!at->is_active)
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
77 return;
26
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
78 if (at->play_buffer)
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
79 handle_play(at);
19
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
80 at->mfrm_count++;
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
81 if (at->mfrm_count >= 12) {
19
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
82 at->mfrm_count = 0;
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
83 taf = 1;
19
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
84 } else {
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
85 taf = 0;
19
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
86 }
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
87 if (at->frame_has_taf)
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
88 fr->xc_bits[3] = taf;
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
89 fr->xc_bits[5] = compute_odd_parity(fr->xc_bits, 5);
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
90
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
91 msg = msgb_alloc_c(g_ctx, 320, "TRAU-UL-frame");
19
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
92 if (!msg)
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
93 return;
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
94 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
95 if (len <= 0) {
0d70444b5070 ater: more robust msgb handling in TRAU-UL output
Mychaela Falconia <falcon@freecalypso.org>
parents: 19
diff changeset
96 msgb_free(msg);
0d70444b5070 ater: more robust msgb handling in TRAU-UL output
Mychaela Falconia <falcon@freecalypso.org>
parents: 19
diff changeset
97 return;
0d70444b5070 ater: more robust msgb handling in TRAU-UL output
Mychaela Falconia <falcon@freecalypso.org>
parents: 19
diff changeset
98 }
19
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
99 msgb_put(msg, len);
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
100 osmo_i460_mux_enqueue(at->schan, msg);
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
101 }
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
102
18
61862af2247f ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 void transmit_e1_ts(void)
61862af2247f ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 {
61862af2247f ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 uint8_t buf[160];
19
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
106 int nr;
18
61862af2247f ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107
19
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
108 for (nr = 0; nr < ATER_SUBSLOTS; nr++)
1e375472d5a5 ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
109 tx_service_subslot(nr);
18
61862af2247f ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 osmo_i460_mux_out(&i460_ts, buf, 160);
61862af2247f ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 write(ts_fd, buf, 160);
61862af2247f ater: E1 timeslot output (osmo_i460 mux)
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 }