OpenCores
URL https://opencores.org/ocsvn/s6soc/s6soc/trunk

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [host/] [dumpuart.cpp] - Diff between revs 19 and 45

Only display areas with differences | Details | Blame | View Log

Rev 19 Rev 45
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
// Filename:    dumpuart.cpp
// Filename:    dumpuart.cpp
//
//
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
//
//
// Purpose:     To produce any and all data from the UART port onto an output
// Purpose:     To produce any and all data from the UART port onto an output
//              pipe and/or an output file.  This replaces the minicom
//              pipe and/or an output file.  This replaces the minicom
//      interface.  This is necessary because 1) minicom can take a while to
//      interface.  This is necessary because 1) minicom can take a while to
//      set up, 2) the default interface is at 9600 Baud (not minicom's 
//      set up, 2) the default interface is at 9600 Baud (not minicom's 
//      default), 3) this produces an unfiltered/unbuffered terminal output,
//      default), 3) this produces an unfiltered/unbuffered terminal output,
//      and 4) it also guarantees that output goes to a file (when requested).
//      and 4) it also guarantees that output goes to a file (when requested).
//
//
// Creator:     Dan Gisselquist, Ph.D.
// Creator:     Dan Gisselquist, Ph.D.
//              Gisselquist Technology, LLC
//              Gisselquist Technology, LLC
//
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
//
//
// This program is free software (firmware): you can redistribute it and/or
// This program is free software (firmware): you can redistribute it and/or
// modify it under the terms of  the GNU General Public License as published
// modify it under the terms of  the GNU General Public License as published
// by the Free Software Foundation, either version 3 of the License, or (at
// by the Free Software Foundation, either version 3 of the License, or (at
// your option) any later version.
// your option) any later version.
//
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// for more details.
//
//
// License:     GPL, v3, as defined and found on www.gnu.org,
// License:     GPL, v3, as defined and found on www.gnu.org,
//              http://www.gnu.org/licenses/gpl.html
//              http://www.gnu.org/licenses/gpl.html
//
//
//
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
//
//
//
//
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <fcntl.h>
#include <unistd.h>
#include <unistd.h>
#include <strings.h>
#include <strings.h>
#include <ctype.h>
#include <ctype.h>
#include <string.h>
#include <string.h>
#include <signal.h>
#include <signal.h>
#include <assert.h>
#include <assert.h>
#include <termios.h>
#include <termios.h>
 
 
int main(int argc, char **argv) {
int main(int argc, char **argv) {
        const char      *dev = argv[1];
        const char      *dev = argv[1];
        const   char    *fname = (argc>=3)?argv[2]:NULL;
        const   char    *fname = (argc>=3)?argv[2]:NULL;
        int     ttyfd = -1, dumpfd = -1;
        int     ttyfd = -1, dumpfd = -1;
 
 
 
        if (argc < 2) {
 
                fprintf(stderr, "USAGE: dumpuart /dev/tty... \n");
 
                exit(EXIT_FAILURE);
 
        }
 
 
        ttyfd = open(dev, O_RDONLY);
        ttyfd = open(dev, O_RDONLY);
 
        if (ttyfd < 0) {
 
                fprintf(stderr, "Could not open device, %s\n", dev);
 
                exit(EXIT_FAILURE);
 
        }
 
        if (!isatty(ttyfd)) {
 
                fprintf(stderr, "Err: %s is not a terminal!\n", dev);
 
                exit(EXIT_FAILURE);
 
        }
 
 
        if (fname)
        if (fname)
                dumpfd = open(fname, O_CREAT|O_TRUNC|O_WRONLY, 0644);
                dumpfd = open(fname, O_CREAT|O_TRUNC|O_WRONLY, 0644);
 
 
        // Set the baud rate ...
        // Set the baud rate ...
        {
        {
                struct  termios tb;
                struct  termios tb;
 
 
                tcgetattr(ttyfd, &tb);
                tcgetattr(ttyfd, &tb);
                // Set to raw mode
                // Set to raw mode
                cfmakeraw(&tb);
                cfmakeraw(&tb);
                // Non-canonical mode (no line editing ...)
                // Non-canonical mode (no line editing ...)
                tb.c_lflag &= (~(ICANON));
                tb.c_lflag &= (~(ICANON));
                // Set no parity, 8 bit
                // Set no parity, 8 bit
                tb.c_cflag &= (~(CRTSCTS));
                tb.c_cflag &= (~(CRTSCTS));
                // One stop bit
                // One stop bit
                tb.c_cflag &= (~(CSTOPB));
                tb.c_cflag &= (~(CSTOPB));
                // 9600 Baud
                // 9600 Baud
                cfsetspeed(&tb, B9600);
                cfsetspeed(&tb, B9600);
                // Block until at least one byte is available
                // Block until at least one byte is available
                tb.c_cc[VMIN] = 1;
                tb.c_cc[VMIN] = 1;
                tb.c_cc[VTIME] = 0;
                tb.c_cc[VTIME] = 0;
                // Commit the changes
                // Commit the changes
                tcsetattr(ttyfd, TCSANOW, &tb);
                tcsetattr(ttyfd, TCSANOW, &tb);
        }
        }
 
 
        /*
        /*
        if (isatty(STDOUT_FILENO)) {
        if (isatty(STDOUT_FILENO)) {
                struct  termios tb;
                struct  termios tb;
                tcgetattr(STDOUT_FILENO, &tb);
                tcgetattr(STDOUT_FILENO, &tb);
        }
        }
        */
        */
 
 
        char    buf[64];
        char    buf[64];
        int     nr;
        int     nr;
 
 
        while((nr=read(ttyfd, buf, sizeof(buf)))>0) {
        while((nr=read(ttyfd, buf, sizeof(buf)))>0) {
                if (dumpfd >= 0)
                if (dumpfd >= 0)
                        write(dumpfd, buf, nr);
                        write(dumpfd, buf, nr);
                write(STDOUT_FILENO, buf, nr);
                write(STDOUT_FILENO, buf, nr);
        }
        }
 
 
        close(ttyfd);
        close(ttyfd);
        if (dumpfd >= 0)
        if (dumpfd >= 0)
                close(dumpfd);
                close(dumpfd);
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.