FreeCalypso > hg > freecalypso-reveng
view fir/readfir.c @ 386:8d19e61d202f
pirelli/chg-circuit: found VBUS, VCHG and ICTL
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 23 Mar 2022 20:06:08 +0000 |
parents | 9b3e5be96bab |
children |
line wrap: on
line source
/* * Reading FIR coefficient tables from formatted ASCII files, * modified version for host processing. */ #include <sys/types.h> #include <ctype.h> #include <stdio.h> #include <string.h> #include <strings.h> #include <stdlib.h> #include "rdcommon.c" static int *writeptr; static process_number() { char *field; int rc, number; rc = get_field(&field); if (rc < 0) return(rc); if (!rc) { printf("error: %s is too short for a FIR coefficient table\n", filename); return(-1); } number = strtol(field, 0, 0); if (number >= 32768) number -= 65536; *writeptr++ = number; return(0); } read_fir_coeff_table_int(filename_arg, rdbuf) char *filename_arg; int *rdbuf; { char *field; int rc, i; filename = filename_arg; rdfile = fopen(filename, "r"); if (!rdfile) { perror(filename); return(-1); } lineno = 0; line_nfields = 0; rc = get_field(&field); if (rc <= 0) { not_valid_fir_table: fprintf(stderr, "error: %s is not a valid FIR coefficient table file\n", filename); fclose(rdfile); return(-1); } if (strcmp(field, "fir-coeff-table")) goto not_valid_fir_table; writeptr = rdbuf; for (i = 0; i < 31; i++) { rc = process_number(); if (rc < 0) { fclose(rdfile); return(rc); } } rc = get_field(&field); fclose(rdfile); if (rc < 0) return(rc); if (rc) { fprintf(stderr, "error: %s is too long for a FIR coefficient table\n", filename); return(-1); } return(0); }