view helpers/cfg-hdr-gen.c @ 635:baa0a02bc676

niq32.c DTR handling restored for targets that have it TI's original TCS211 fw treated GPIO 3 as the DTR input (wired so on C-Sample and D-Sample boards, also compatible with Leonardo and FCDEV3B which have a fixed pull-down resistor on this GPIO line), and the code in niq32.c called UAF_DTRInterruptHandler() (implemented in uartfax.c) from the IQ_KeypadGPIOHandler() function. But on Openmoko's GTA02 with their official fw this GPIO is a floating input, all of the DTR handling code in uartfax.c including the interrupt logic is still there, but the hobbled TCS211-20070608 semi-src delivery which OM got from TI contained a change in niq32.c (which had been kept in FC until now) that removed the call to UAF_DTRInterruptHandler() as part of those not-quite-understood "CC test" hacks. The present change fixes this bug at a long last: if we are building fw for a target that has TI's "classic" DTR & DCD GPIO arrangement (dsample, fcmodem and gtm900), we bring back all of TI's original code in both uartfax.c and niq32.c, whereas if we are building fw for a target that does not use this classic GPIO arrangement, the code in niq32.c goes back to what we got from OM and all DTR & DCD code in uartfax.c is conditioned out. This change also removes the very last remaining bit of "CC test" bogosity from our FreeCalypso code base.
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 19 Jan 2020 01:41:35 +0000
parents b8b08c302ace
children
line wrap: on
line source

/*
 * This helper program generates the set of *.cfg header files, based on a
 * template file and environment variables for the non-constant settings.
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <strings.h>

char *infname;
FILE *inf, *outf;
char include_guard_symbol[32];
char linebuf[256];
int lineno;

make_include_guard_symbol(fname)
	char *fname;
{
	char *sp, *dp;
	int c;

	sp = fname;
	dp = include_guard_symbol;
	*dp++ = '_';
	*dp++ = '_';
	while (c = *sp++) {
		if (islower(c))
			c = toupper(c);
		else if (c == '.')
			c = '_';
		*dp++ = c;
	}
	*dp++ = '_';
	*dp++ = '_';
	*dp = '\0';
}

close_output()
{
	if (outf) {
		fprintf(outf, "#endif /* %s */\n", include_guard_symbol);
		fclose(outf);
		outf = 0;
	}
}

bracket_line()
{
	char *cp;

	close_output();
	cp = index(linebuf+1, ']');
	if (!cp) {
		fprintf(stderr, "%s line %d: unterminated bracket line\n",
			infname, lineno);
		exit(1);
	}
	*cp = '\0';
	outf = fopen(linebuf+1, "w");
	if (!outf) {
		perror(linebuf+1);
		exit(1);
	}
	make_include_guard_symbol(linebuf+1);
	fprintf(outf, "#ifndef %s\n", include_guard_symbol);
	fprintf(outf, "#define %s\n", include_guard_symbol);
}

process_line()
{
	char *cp, *symbol, *value;

	if (linebuf[0] == '[')
		return bracket_line();
	for (cp = linebuf; isspace(*cp); cp++)
		;
	if (*cp == '\0' || *cp == '#')
		return;
	for (symbol = cp; *cp && !isspace(*cp); cp++)
		;
	if (!*cp) {
inv:		fprintf(stderr, "%s line %d: expected two fields\n",
			infname, lineno);
		exit(1);
	}
	*cp++ = '\0';
	while (isspace(*cp))
		cp++;
	if (*cp == '\0' || *cp == '#')
		goto inv;
	for (value = cp; *cp && !isspace(*cp); cp++)
		;
	if (*cp)
		*cp++ = '\0';
	while (isspace(*cp))
		cp++;
	if (*cp != '\0' && *cp != '#')
		goto inv;
	if (!strcmp(value, "var")) {
		value = getenv(symbol);
		if (!value) {
			fprintf(stderr,
			"%s line %d: no environment variable named %s\n",
				infname, lineno, symbol);
			exit(1);
		}
	}
	if (!outf) {
		fprintf(stderr, "%s line %d: no open output file\n",
			infname, lineno);
		exit(1);
	}
	fprintf(outf, "#define %s %s\n", symbol, value);
}

main(argc, argv)
	char **argv;
{
	if (argc != 3) {
		fprintf(stderr, "usage: %s template-file output-dir\n",
			argv[0]);
		exit(1);
	}
	infname = argv[1];
	inf = fopen(infname, "r");
	if (!inf) {
		perror(infname);
		exit(1);
	}
	if (chdir(argv[2]) < 0) {
		perror(argv[2]);
		exit(1);
	}
	for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++)
		process_line();
	close_output();
	exit(0);
}