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

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [host/] [dumpuart.cpp] - Blame information for rev 19

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    dumpuart.cpp
4
//
5
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
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 9600 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
// Creator:     Dan Gisselquist, Ph.D.
15
//              Gisselquist Technology, LLC
16
//
17
////////////////////////////////////////////////////////////////////////////////
18
//
19
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
20
//
21
// This program is free software (firmware): you can redistribute it and/or
22
// modify it under the terms of  the GNU General Public License as published
23
// by the Free Software Foundation, either version 3 of the License, or (at
24
// your option) any later version.
25
//
26
// This program is distributed in the hope that it will be useful, but WITHOUT
27
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
28
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
29
// for more details.
30
//
31
// License:     GPL, v3, as defined and found on www.gnu.org,
32
//              http://www.gnu.org/licenses/gpl.html
33
//
34
//
35
////////////////////////////////////////////////////////////////////////////////
36
//
37
//
38
//
39
#include <stdio.h>
40
#include <stdlib.h>
41
#include <sys/types.h>
42
#include <sys/stat.h>
43
#include <fcntl.h>
44
#include <unistd.h>
45
#include <strings.h>
46
#include <ctype.h>
47
#include <string.h>
48
#include <signal.h>
49
#include <assert.h>
50
#include <termios.h>
51
 
52
int main(int argc, char **argv) {
53
        const char      *dev = argv[1];
54
        const   char    *fname = (argc>=3)?argv[2]:NULL;
55
        int     ttyfd = -1, dumpfd = -1;
56
 
57
        ttyfd = open(dev, O_RDONLY);
58
        if (fname)
59
                dumpfd = open(fname, O_CREAT|O_TRUNC|O_WRONLY, 0644);
60
 
61
        // Set the baud rate ...
62
        {
63
                struct  termios tb;
64
 
65
                tcgetattr(ttyfd, &tb);
66
                // Set to raw mode
67
                cfmakeraw(&tb);
68
                // Non-canonical mode (no line editing ...)
69
                tb.c_lflag &= (~(ICANON));
70
                // Set no parity, 8 bit
71
                tb.c_cflag &= (~(CRTSCTS));
72
                // One stop bit
73
                tb.c_cflag &= (~(CSTOPB));
74
                // 9600 Baud
75
                cfsetspeed(&tb, B9600);
76
                // Block until at least one byte is available
77
                tb.c_cc[VMIN] = 1;
78
                tb.c_cc[VTIME] = 0;
79
                // Commit the changes
80
                tcsetattr(ttyfd, TCSANOW, &tb);
81
        }
82
 
83
        /*
84
        if (isatty(STDOUT_FILENO)) {
85
                struct  termios tb;
86
                tcgetattr(STDOUT_FILENO, &tb);
87
        }
88
        */
89
 
90
        char    buf[64];
91
        int     nr;
92
 
93
        while((nr=read(ttyfd, buf, sizeof(buf)))>0) {
94
                if (dumpfd >= 0)
95
                        write(dumpfd, buf, nr);
96
                write(STDOUT_FILENO, buf, nr);
97
        }
98
 
99
        close(ttyfd);
100
        if (dumpfd >= 0)
101
                close(dumpfd);
102
}

powered by: WebSVN 2.1.0

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