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

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [sw/] [uartscope.cpp] - Blame information for rev 112

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

Line No. Rev Author Line
1 111 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    uartscope.cpp
4
//
5
// Project:     XuLA2-LX25 SoC based upon the ZipCPU
6
//
7
// Purpose:     To read out, and decompose, the results of the wishbone scope
8
//              as applied to the UART interaction within the XuLA2-LX9(25)
9
//      board--particularly the UART interaction that will talk with a RPi.
10
//
11
//
12
// Creator:     Dan Gisselquist, Ph.D.
13
//              Gisselquist Technology, LLC
14
//
15
////////////////////////////////////////////////////////////////////////////////
16
//
17
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
18
//
19
// This program is free software (firmware): you can redistribute it and/or
20
// modify it under the terms of  the GNU General Public License as published
21
// by the Free Software Foundation, either version 3 of the License, or (at
22
// your option) any later version.
23
//
24
// This program is distributed in the hope that it will be useful, but WITHOUT
25
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
26
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
27
// for more details.
28
//
29
// You should have received a copy of the GNU General Public License along
30
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
31
// target there if the PDF file isn't present.)  If not, see
32
// <http://www.gnu.org/licenses/> for a copy.
33
//
34
// License:     GPL, v3, as defined and found on www.gnu.org,
35
//              http://www.gnu.org/licenses/gpl.html
36
//
37
//
38
////////////////////////////////////////////////////////////////////////////////
39
//
40
//
41
//
42
#include <stdio.h>
43
#include <stdlib.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
 
51
#include "llcomms.h"
52
#include "usbi.h"
53
#include "port.h"
54
#include "regdefs.h"
55
 
56
#define WBSCOPE         R_RAMSCOPE
57
#define WBSCOPEDATA     R_RAMSCOPED
58
 
59
FPGA    *m_fpga;
60
void    closeup(int v) {
61
        m_fpga->kill();
62
        exit(0);
63
}
64
 
65
void    decode(DEVBUS::BUSW val) {
66
        int     trig, txbusy, tx_stb, tx_data, tx_uart;
67
        int     rx_rdy, rx_stb, rx_data, rx_uart;
68
        int     rx_break, rx_frame, rx_parity;
69
        int     wbcyc, wbstb, wbwe, wback, wbaddr;
70
 
71
        trig    = ((val>>31)&1);
72
        txbusy  = ((val>>30)&1);
73
        wbaddr  = ((val>>28)&3);
74
        rx_break  = (val>>27)&1;
75
        rx_frame  = (val>>26)&1;
76
        rx_parity = (val>>25)&1;
77
        rx_rdy    = (val>>24)&1;
78
        wbcyc     = (val>>23)&1;
79
        wbstb     = (val>>22)&1;
80
        wbwe      = (val>>21)&1;
81
        wback     = (val>>20)&1;
82
 
83
        rx_stb    = (val>>19)&1;
84
        rx_data   = (val>>11)&0x0ff;
85
 
86
        tx_stb    = (val>>10)&1;
87
        tx_data   = (val>> 2)&0x0ff;
88
 
89
        rx_uart   = (val>> 1)&1;
90
        tx_uart   = (val    )&1;
91
 
92
        printf(" UART %s %s [%s:%02x%s] [%s:%02x%s] %s%s%s@%08x %s %s%s%s",
93
                (rx_uart)?"RXD":"   ", (tx_uart)?"TXD":"   ",
94
                (rx_stb)?"RX!":"   ", rx_data, rx_rdy?"/RDY":"    ",
95
                (tx_stb)?"TX!":"   ", tx_data, txbusy?"/BSY":"    ",
96
                (wbcyc)?"C":" ", (wbstb)?"S":" ", (wbwe)?"W":"R",
97
                wbaddr, wback?"A":" ",
98
                rx_break?" BRK":"", rx_frame?" FERR":"", rx_parity?" PERR":"");
99
}
100
 
101
int main(int argc, char **argv) {
102
        int     skp=0, port = FPGAPORT;
103
        bool    use_usb = true;
104
 
105
        skp=1;
106
        for(int argn=0; argn<argc-skp; argn++) {
107
                if (argv[argn+skp][0] == '-') {
108
                        if (argv[argn+skp][1] == 'u')
109
                                use_usb = true;
110
                        else if (argv[argn+skp][1] == 'p') {
111
                                use_usb = false;
112
                                if (isdigit(argv[argn+skp][2]))
113
                                        port = atoi(&argv[argn+skp][2]);
114
                        }
115
                        skp++; argn--;
116
                } else
117
                        argv[argn] = argv[argn+skp];
118
        } argc -= skp;
119
 
120
        if (use_usb)
121
                m_fpga = new FPGA(new USBI());
122
        else
123
                m_fpga = new FPGA(new NETCOMMS(FPGAHOST, port));
124
 
125
        signal(SIGSTOP, closeup);
126
        signal(SIGHUP, closeup);
127
 
128
        unsigned        v, lgln, scoplen;
129
        v = m_fpga->readio(WBSCOPE);
130
        if (0x60000000 != (v & 0x60000000)) {
131
                printf("Scope is not yet ready:\n");
132
                printf("\tRESET:\t\t%s\n", (v&0x80000000)?"Ongoing":"Complete");
133
                printf("\tSTOPPED:\t%s\n", (v&0x40000000)?"Yes":"No");
134
                printf("\tTRIGGERED:\t%s\n", (v&0x20000000)?"Yes":"No");
135
                printf("\tPRIMED:\t\t%s\n", (v&0x10000000)?"Yes":"No");
136
                printf("\tMANUAL:\t\t%s\n", (v&0x08000000)?"Yes":"No");
137
                printf("\tDISABLED:\t%s\n", (v&0x04000000)?"Yes":"No");
138
                printf("\tZERO:\t\t%s\n", (v&0x02000000)?"Yes":"No");
139
                exit(0);
140
        } else printf("SCOPD = %08x\n", v);
141
 
142
        lgln = (v>>20) & 0x1f;
143
        scoplen = (1<<lgln);
144
 
145
        DEVBUS::BUSW    *buf;
146
        buf = new DEVBUS::BUSW[scoplen];
147
 
148
        bool    compressed = false, vector_read = true;
149
        DEVBUS::BUSW    addrv = 0;
150
 
151
        if (vector_read) {
152
                m_fpga->readz(WBSCOPEDATA, scoplen, buf);
153
        } else {
154
                for(unsigned int i=0; i<scoplen; i++)
155
                        buf[i] = m_fpga->readio(WBSCOPEDATA);
156
        }
157
 
158
        if(compressed) {
159
                for(int i=0; i<(int)scoplen; i++) {
160
                        if ((buf[i]>>31)&1) {
161
                                addrv += (buf[i]&0x7fffffff);
162
                                printf(" ** \n");
163
                                continue;
164
                        }
165
                        printf("%10d %08x: ", addrv++, buf[i]);
166
                        decode(buf[i]);
167
                        printf("\n");
168
                }
169
        } else {
170
                for(int i=0; i<(int)scoplen; i++) {
171
                        if ((i>0)&&(buf[i] == buf[i-1])&&(i<(int)(scoplen-1))) {
172
                                if ((i>2)&&(buf[i] != buf[i-2]))
173
                                        printf(" **** ****\n");
174
                                continue;
175
                        } printf("%9d %08x: ", i, buf[i]);
176
                        decode(buf[i]);
177
                        printf("\n");
178
                }
179
        }
180
 
181
        if (m_fpga->poll()) {
182
                printf("FPGA was interrupted\n");
183
                m_fpga->clear();
184
        }
185
 
186
        delete[] buf;
187
        delete  m_fpga;
188
}
189
 

powered by: WebSVN 2.1.0

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