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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [sw/] [host/] [dumpuart.cpp] - Blame information for rev 51

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 51 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    dumpuart.cpp
4
//
5
// Project:     OpenArty, an entirely open SoC based upon the Arty platform
6
//
7
// Purpose:     To produce any and all data from the UART port onto an output
8
//              pipe and/or an output file.  This replaces the minicom
9
//      interface.  This is necessary because 1) minicom can take a while to
10
//      set up, 2) the default interface is at 115200 Baud (not minicom's 
11
//      default), 3) this produces an unfiltered/unbuffered terminal output,
12
//      and 4) it also guarantees that output goes to a file (when requested).
13
//
14
// This program was originally a part of the S6SoC suite of host programs.  It
15
// has since been modified for the OpenArty project--mostly by just changing the
16
// data speed from 9.6kB to 115.2kB.
17
//
18
//
19
// Creator:     Dan Gisselquist, Ph.D.
20
//              Gisselquist Technology, LLC
21
//
22
////////////////////////////////////////////////////////////////////////////////
23
//
24
// Copyright (C) 2015-2017, Gisselquist Technology, LLC
25
//
26
// This program is free software (firmware): you can redistribute it and/or
27
// modify it under the terms of  the GNU General Public License as published
28
// by the Free Software Foundation, either version 3 of the License, or (at
29
// your option) any later version.
30
//
31
// This program is distributed in the hope that it will be useful, but WITHOUT
32
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
33
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
34
// for more details.
35
//
36
// You should have received a copy of the GNU General Public License along
37
// with this program.  (It's in the $(ROOT)/doc directory.  Run make with no
38
// target there if the PDF file isn't present.)  If not, see
39
// <http://www.gnu.org/licenses/> for a copy.
40
//
41
// License:     GPL, v3, as defined and found on www.gnu.org,
42
//              http://www.gnu.org/licenses/gpl.html
43
//
44
//
45
////////////////////////////////////////////////////////////////////////////////
46
//
47
//
48
//
49
#include <stdio.h>
50
#include <stdlib.h>
51
#include <sys/types.h>
52
#include <sys/stat.h>
53
#include <fcntl.h>
54
#include <unistd.h>
55
#include <strings.h>
56
#include <ctype.h>
57
#include <string.h>
58
#include <signal.h>
59
#include <assert.h>
60
#include <termios.h>
61
 
62
int main(int argc, char **argv) {
63
        const char      *dev = argv[1];
64
        const   char    *fname = (argc>=3)?argv[2]:NULL;
65
        int     ttyfd = -1, dumpfd = -1;
66
 
67
        ttyfd = open(dev, O_RDONLY);
68
        if (fname)
69
                dumpfd = open(fname, O_CREAT|O_TRUNC|O_WRONLY, 0644);
70
 
71
        // Set the baud rate ...
72
        {
73
                struct  termios tb;
74
 
75
                tcgetattr(ttyfd, &tb);
76
                // Set to raw mode
77
                cfmakeraw(&tb);
78
                // Non-canonical mode (no line editing ...)
79
                tb.c_lflag &= (~(ICANON));
80
                // Set no parity
81
                tb.c_cflag &= (~(PARENB));
82
                // Set 8 data bits
83
                tb.c_cflag &= (~(CSIZE));
84
                tb.c_cflag |= CS8;
85
                // Turn on hardware flow control
86
                tb.c_cflag |= CRTSCTS;
87
                // One stop bit
88
                tb.c_cflag &= (~(CSTOPB));
89
                // 115200 Baud
90
                cfsetspeed(&tb, B115200);
91
                // Block until at least one byte is available
92
                tb.c_cc[VMIN] = 1;
93
                tb.c_cc[VTIME] = 0;
94
                // Commit the changes
95
                tcsetattr(ttyfd, TCSANOW, &tb);
96
        }
97
 
98
        /*
99
        if (isatty(STDOUT_FILENO)) {
100
                struct  termios tb;
101
                tcgetattr(STDOUT_FILENO, &tb);
102
        }
103
        */
104
 
105
        char    buf[64];
106
        int     nr;
107
 
108
        while((nr=read(ttyfd, buf, sizeof(buf)))>0) {
109
                if (dumpfd >= 0)
110
                        write(dumpfd, buf, nr);
111
                write(STDOUT_FILENO, buf, nr);
112
        }
113
 
114
        close(ttyfd);
115
        if (dumpfd >= 0)
116
                close(dumpfd);
117
}

powered by: WebSVN 2.1.0

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