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

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [sw/] [sdcardscop.cpp] - Blame information for rev 115

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

Line No. Rev Author Line
1 111 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    sdcardscop.cpp
4
//
5
// Project:     XuLA2 board
6
//
7
// Purpose:     To read out, and decompose, the results of the wishbone scope
8
//              as applied to the SD-Card interaction over the SPI port.
9
//
10
//
11
// Creator:     Dan Gisselquist, Ph.D.
12
//              Gisselquist Technology, LLC
13
//
14
////////////////////////////////////////////////////////////////////////////////
15
//
16
// Copyright (C) 2015, Gisselquist Technology, LLC
17
//
18
// This program is free software (firmware): you can redistribute it and/or
19
// modify it under the terms of  the GNU General Public License as published
20
// by the Free Software Foundation, either version 3 of the License, or (at
21
// your option) any later version.
22
//
23
// This program is distributed in the hope that it will be useful, but WITHOUT
24
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
25
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
26
// for more details.
27
//
28
// License:     GPL, v3, as defined and found on www.gnu.org,
29
//              http://www.gnu.org/licenses/gpl.html
30
//
31
//
32
////////////////////////////////////////////////////////////////////////////////
33
//
34
//
35
//
36
#include <stdio.h>
37
#include <stdlib.h>
38
#include <unistd.h>
39
#include <strings.h>
40
#include <ctype.h>
41
#include <string.h>
42
#include <signal.h>
43
#include <assert.h>
44
 
45
#include "llcomms.h"
46
#include "usbi.h"
47
#include "port.h"
48
#include "regdefs.h"
49
 
50
#define WBSCOPE         R_CFGSCOPE
51
#define WBSCOPEDATA     R_CFGSCOPED
52
 
53
FPGA    *m_fpga;
54
void    closeup(int v) {
55
        m_fpga->kill();
56
        exit(0);
57
}
58
 
59
void    decode(DEVBUS::BUSW val) {
60
        int     csn, sck, mosi, miso;
61
        int     iwi, iws, ird, idat, odat;
62
        int     grant;
63
        int     cmd, rsp;
64
 
65
        csn  = ((val>>24)>>3)&1;
66
        sck  = ((val>>24)>>2)&1;
67
        mosi = ((val>>24)>>1)&1;
68
        miso = ((val>>24)   )&1;
69
 
70
        iws = (val>>30)&1;
71
        iwi = (val>>29)&1;      // ll_idle
72
        ird =  (val>>28)&1;     // ll_out_stb
73
 
74
        idat = (val>>8)&0x0ff;
75
        odat = (val&0x0ff);
76
 
77
        cmd = (val>>21)&0x07;
78
        rsp = (val>>17)&0x07;
79
 
80
        grant=(val>>20)&1;
81
 
82
        printf("%sSPI[%d,%d,%d,%d] (%d,%d) %02x %s%s [LL] %s %02x",
83
                (grant)?"   ":"!G-",
84
                csn, sck, mosi, miso,
85
                cmd, rsp,
86
                idat,
87
                (iws)?"-":" ",
88
                (iwi)?">":" ",
89
                (ird)?"->":"  ", odat);
90
}
91
 
92
int main(int argc, char **argv) {
93
        int     skp=0, port = FPGAPORT;
94
        bool    use_usb = true;
95
 
96
        skp=1;
97
        for(int argn=0; argn<argc-skp; argn++) {
98
                if (argv[argn+skp][0] == '-') {
99
                        if (argv[argn+skp][1] == 'u')
100
                                use_usb = true;
101
                        else if (argv[argn+skp][1] == 'p') {
102
                                use_usb = false;
103
                                if (isdigit(argv[argn+skp][2]))
104
                                        port = atoi(&argv[argn+skp][2]);
105
                        }
106
                        skp++; argn--;
107
                } else
108
                        argv[argn] = argv[argn+skp];
109
        } argc -= skp;
110
 
111
        if (use_usb)
112
                m_fpga = new FPGA(new USBI());
113
        else
114
                m_fpga = new FPGA(new NETCOMMS(FPGAHOST, port));
115
 
116
        signal(SIGSTOP, closeup);
117
        signal(SIGHUP, closeup);
118
 
119
        unsigned        v, lgln, scoplen;
120
        v = m_fpga->readio(WBSCOPE);
121
        if (0x60000000 != (v & 0x60000000)) {
122
                printf("Scope is not yet ready:\n");
123
                printf("\tRESET:\t\t%s\n", (v&0x80000000)?"Ongoing":"Complete");
124
                printf("\tSTOPPED:\t%s\n", (v&0x40000000)?"Yes":"No");
125
                printf("\tTRIGGERED:\t%s\n", (v&0x20000000)?"Yes":"No");
126
                printf("\tPRIMED:\t\t%s\n", (v&0x10000000)?"Yes":"No");
127
                printf("\tMANUAL:\t\t%s\n", (v&0x08000000)?"Yes":"No");
128
                printf("\tDISABLED:\t%s\n", (v&0x04000000)?"Yes":"No");
129
                printf("\tZERO:\t\t%s\n", (v&0x02000000)?"Yes":"No");
130
                exit(0);
131
        } else printf("SCOPD = %08x\n", v);
132
 
133
        lgln = (v>>20) & 0x1f;
134
        scoplen = (1<<lgln);
135
 
136
        DEVBUS::BUSW    *buf;
137
        buf = new DEVBUS::BUSW[scoplen];
138
 
139
        bool    compressed = false, vector_read = true;
140
        DEVBUS::BUSW    addrv = 0;
141
 
142
        if (vector_read) {
143
                m_fpga->readz(WBSCOPEDATA, scoplen, buf);
144
        } else {
145
                for(unsigned int i=0; i<scoplen; i++)
146
                        buf[i] = m_fpga->readio(WBSCOPEDATA);
147
        }
148
 
149
        if(compressed) {
150
                for(int i=0; i<(int)scoplen; i++) {
151
                        if ((buf[i]>>31)&1) {
152
                                addrv += (buf[i]&0x7fffffff);
153
                                printf(" ** \n");
154
                                continue;
155
                        }
156
                        printf("%10d %08x: ", addrv++, buf[i]);
157
                        decode(buf[i]);
158
                        printf("\n");
159
                }
160
        } else {
161
                for(int i=0; i<(int)scoplen; i++) {
162
                        if ((i>0)&&(buf[i] == buf[i-1])&&(i<(int)(scoplen-1))) {
163
                                if ((i>2)&&(buf[i] != buf[i-2]))
164
                                        printf(" **** ****\n");
165
                                continue;
166
                        } printf("%9d %08x: ", i, buf[i]);
167
                        decode(buf[i]);
168
                        printf("\n");
169
                }
170
        }
171
 
172
        if (m_fpga->poll()) {
173
                printf("FPGA was interrupted\n");
174
                m_fpga->clear();
175
        }
176
 
177
        delete[] buf;
178
        delete  m_fpga;
179
}
180
 

powered by: WebSVN 2.1.0

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