view 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
line wrap: on
line source

/*
 * Here we implement basic Tx functions: emitting an uplink sample stream
 * to Calypso MCSI via the FPGA.
 */

#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

extern int target_fd;

u_short pcm_fill_word;

static void
do_idle_fill(buf)
	u_short *buf;
{
	unsigned n;

	for (n = 0; n < 160; n++)
		buf[n] = pcm_fill_word;
}

static void
emit_uart_output(samples)
	u_short *samples;
{
	u_char bytes[320], *dp;
	unsigned n, samp;

	dp = bytes;
	for (n = 0; n < 160; n++) {
		samp = samples[n];
		*dp++ = samp;
		*dp++ = samp >> 8;
	}
	write(target_fd, bytes, 320);
}

void
transmit_20ms_block()
{
	u_short tx_samples[160];

	do_idle_fill(tx_samples);
	emit_uart_output(tx_samples);
}

void
cmd_pcm_fill(argc, argv)
	char **argv;
{
	u_long val;
	char *endp;

	if (argc < 2) {
		printf("%04x\n", pcm_fill_word);
		return;
	}
	if (!isxdigit(argv[1][0])) {
inv:		printf("error: pcm-fill argument is not a valid hex word\n");
		return;
	}
	val = strtoul(argv[1], &endp, 16);
	if (*endp)
		goto inv;
	if (val > 0xFFFF)
		goto inv;
	pcm_fill_word = val;
}