Merge pull request #6 from redvers/master

Added -B flag to re-direct output of Serial to a file
This commit is contained in:
Dave Hein 2018-12-01 18:46:39 -06:00 committed by GitHub
commit 71ce50b415
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 3 deletions

View File

@ -77,6 +77,7 @@ int32_t kludge = 0;
FILE *logfile = NULL; FILE *logfile = NULL;
FILE *tracefile = NULL; FILE *tracefile = NULL;
FILE *serialfile = NULL;
FILE *cmdfile = NULL; FILE *cmdfile = NULL;
PasmVarsT PasmVars[16]; PasmVarsT PasmVars[16];
@ -112,6 +113,7 @@ void usage(void)
//fprintf(stderr, " -c Enable cycle-accurate mode for pasm cogs\n"); //fprintf(stderr, " -c Enable cycle-accurate mode for pasm cogs\n");
fprintf(stderr, " -t# Enable the Prop 2 mode. # specifies options\n"); fprintf(stderr, " -t# Enable the Prop 2 mode. # specifies options\n");
fprintf(stderr, " -b# Enable the serial port and set the baudrate to # (default 115200)\n"); fprintf(stderr, " -b# Enable the serial port and set the baudrate to # (default 115200)\n");
fprintf(stderr, " -B <filename> Redirects serial output to filename\n");
fprintf(stderr, " -gdb Operate as a GDB target over stdin/stdout\n"); fprintf(stderr, " -gdb Operate as a GDB target over stdin/stdout\n");
fprintf(stderr, " -L <filename> Log GDB remote comm to <filename>\n"); fprintf(stderr, " -L <filename> Log GDB remote comm to <filename>\n");
fprintf(stderr, " -r <filename> Replay GDB session from <filename>\n"); fprintf(stderr, " -r <filename> Replay GDB session from <filename>\n");
@ -125,7 +127,13 @@ void usage(void)
void putchx(int32_t val) void putchx(int32_t val)
{ {
putchar(val); putchar(val);
fflush(stdout); fflush(tracefile);
}
void putschx(int32_t val)
{
fputc(val, serialfile);
fflush(serialfile);
} }
#if 0 #if 0
@ -569,9 +577,9 @@ void CheckSerialOut(SerialT *serial)
{ {
serial->flag = 0; serial->flag = 0;
if (serial->value == 13 && pstmode) if (serial->value == 13 && pstmode)
putchx(10); putschx(10);
else else
putchx(serial->value); putschx(serial->value);
} }
} }
@ -740,6 +748,7 @@ int main(int argc, char **argv)
int32_t maxloops = -1; int32_t maxloops = -1;
tracefile = stdout; tracefile = stdout;
serialfile = stdout;
getcwd(rootdir, 100); getcwd(rootdir, 100);
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
@ -758,6 +767,20 @@ int main(int argc, char **argv)
spinsim_exit(1); spinsim_exit(1);
} }
} }
else if (strcmp(argv[i], "-B") == 0){
if (i+1 == argc || argv[i+1][0] == '-')
{
fprintf(stderr, "Serial file not specified\n");
spinsim_exit(1);
}
if (!printflag) printflag = 0xffffffff;
i++;
serialfile = fopen(argv[i], "wt");
if(!serialfile){
fprintf(stderr, "Unable to open serial file %s.\n", argv[i]);
spinsim_exit(1);
}
}
else if (strncmp(argv[i], "-t", 2) == 0) else if (strncmp(argv[i], "-t", 2) == 0)
{ {
propmode = 2; propmode = 2;