annotate sw/mcsi-rxtx/tx_func.c @ 12:23555b9a1c20

fc-mcsi-rxtx: implement pcm-fill command
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 28 Oct 2024 06:52:33 +0000
parents e93a11f44e6f
children f908a782cff9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Here we implement basic Tx functions: emitting an uplink sample stream
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * to Calypso MCSI via the FPGA.
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
12
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
7 #include <ctype.h>
11
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <unistd.h>
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 extern int target_fd;
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 u_short pcm_fill_word;
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 static void
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 do_idle_fill(buf)
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 u_short *buf;
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 {
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 unsigned n;
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 for (n = 0; n < 160; n++)
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 buf[n] = pcm_fill_word;
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 }
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 static void
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 emit_uart_output(samples)
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 u_short *samples;
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 {
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 u_char bytes[320], *dp;
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 unsigned n, samp;
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 dp = bytes;
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 for (n = 0; n < 160; n++) {
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 samp = samples[n];
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 *dp++ = samp;
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 *dp++ = samp >> 8;
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 write(target_fd, bytes, 320);
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 void
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 transmit_20ms_block()
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 {
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 u_short tx_samples[160];
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 do_idle_fill(tx_samples);
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 emit_uart_output(tx_samples);
e93a11f44e6f fc-mcsi-rxtx: implement basic Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
12
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
50
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
51 void
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
52 cmd_pcm_fill(argc, argv)
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
53 char **argv;
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
54 {
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
55 u_long val;
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
56 char *endp;
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
57
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
58 if (argc < 2) {
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
59 printf("%04x\n", pcm_fill_word);
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
60 return;
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
61 }
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
62 if (!isxdigit(argv[1][0])) {
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
63 inv: printf("error: pcm-fill argument is not a valid hex word\n");
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
64 return;
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
65 }
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
66 val = strtoul(argv[1], &endp, 16);
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
67 if (*endp)
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
68 goto inv;
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
69 if (val > 0xFFFF)
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
70 goto inv;
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
71 pcm_fill_word = val;
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
72 }