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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [sw/] [host/] [wbregs.cpp] - Diff between revs 4 and 51

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

Rev 4 Rev 51
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
// Filename:    wbregs.cpp
// Filename:    wbregs.cpp
//
//
// Project:     OpenArty, an entirely open SoC based upon the Arty platform
// Project:     OpenArty, an entirely open SoC based upon the Arty platform
//
//
// Purpose:     To give a user access, via a command line program, to read
// Purpose:     To give a user access, via a command line program, to read
//              and write wishbone registers one at a time.  Thus this program
//              and write wishbone registers one at a time.  Thus this program
//              implements readio() and writeio() but nothing more.
//              implements readio() and writeio() but nothing more.
//
//
//
//
// 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-2017, 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.
//
//
// You should have received a copy of the GNU General Public License along
// You should have received a copy of the GNU General Public License along
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
// with this program.  (It's in the $(ROOT)/doc directory.  Run make with no
// target there if the PDF file isn't present.)  If not, see
// target there if the PDF file isn't present.)  If not, see
// <http://www.gnu.org/licenses/> for a copy.
// <http://www.gnu.org/licenses/> for a copy.
//
//
// 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 <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 "port.h"
#include "port.h"
#include "regdefs.h"
#include "regdefs.h"
 
 
FPGA    *m_fpga;
FPGA    *m_fpga;
void    closeup(int v) {
void    closeup(int v) {
        m_fpga->kill();
        m_fpga->kill();
        exit(0);
        exit(0);
}
}
 
 
void    usage(void) {
void    usage(void) {
        printf("USAGE: wbregs address [value]\n"
        printf("USAGE: wbregs address [value]\n"
"\n"
"\n"
"\tWBREGS stands for Wishbone registers.  It is designed to allow a\n"
"\tWBREGS stands for Wishbone registers.  It is designed to allow a\n"
"\tuser to peek and poke at registers within a given FPGA design, so\n"
"\tuser to peek and poke at registers within a given FPGA design, so\n"
"\tlong as those registers have addresses on the wishbone bus.  The\n"
"\tlong as those registers have addresses on the wishbone bus.  The\n"
"\taddress may reference peripherals or memory, depending upon how the\n"
"\taddress may reference peripherals or memory, depending upon how the\n"
"\tbus is configured.\n"
"\tbus is configured.\n"
"\n"
"\n"
"\tAddress is either a 32-bit value with the syntax of strtoul, or a\n"
"\tAddress is either a 32-bit value with the syntax of strtoul, or a\n"
"\tregister name.  Register names can be found in regdefs.cpp\n"
"\tregister name.  Register names can be found in regdefs.cpp\n"
"\n"
"\n"
"\tIf a value is given, that value will be written to the indicated\n"
"\tIf a value is given, that value will be written to the indicated\n"
"\taddress, otherwise the result from reading the address will be \n"
"\taddress, otherwise the result from reading the address will be \n"
"\twritten to the screen.\n");
"\twritten to the screen.\n");
}
}
 
 
int main(int argc, char **argv) {
int main(int argc, char **argv) {
        int     skp=0, port = FPGAPORT;
        int     skp=0;
        bool    use_usb = true, use_decimal = false;
        bool    use_decimal = false;
 
 
        skp=1;
        skp=1;
        for(int argn=0; argn<argc-skp; argn++) {
        for(int argn=0; argn<argc-skp; argn++) {
                if (argv[argn+skp][0] == '-') {
                if (argv[argn+skp][0] == '-') {
                        if (argv[argn+skp][1] == 'd') {
                        if (argv[argn+skp][1] == 'd') {
                                use_decimal = true;
                                use_decimal = true;
                        } else {
                        } else {
                                usage();
                                usage();
                                exit(EXIT_SUCCESS);
                                exit(EXIT_SUCCESS);
                        }
                        }
                        skp++; argn--;
                        skp++; argn--;
                } else
                } else
                        argv[argn] = argv[argn+skp];
                        argv[argn] = argv[argn+skp];
        } argc -= skp;
        } argc -= skp;
 
 
        FPGAOPEN(m_fpga);
        FPGAOPEN(m_fpga);
 
 
        signal(SIGSTOP, closeup);
        signal(SIGSTOP, closeup);
        signal(SIGHUP, closeup);
        signal(SIGHUP, closeup);
 
 
        if ((argc < 1)||(argc > 2)) {
        if ((argc < 1)||(argc > 2)) {
                // usage();
                // usage();
                printf("USAGE: wbregs address [value]\n");
                printf("USAGE: wbregs address [value]\n");
                exit(-1);
                exit(-1);
        }
        }
 
 
        const char *nm;
        const char *nm;
        unsigned address = addrdecode(argv[0]), value;
        unsigned address = addrdecode(argv[0]), value;
        nm = addrname(address);
        nm = addrname(address);
        if (nm == NULL)
        if (nm == NULL)
                nm = "no name";
                nm = "no name";
 
 
        if (argc < 2) {
        if (argc < 2) {
                FPGA::BUSW      v;
                FPGA::BUSW      v;
                try {
                try {
                        unsigned char a, b, c, d;
                        unsigned char a, b, c, d;
                        v = m_fpga->readio(address);
                        v = m_fpga->readio(address);
                        a = (v>>24)&0x0ff;
                        a = (v>>24)&0x0ff;
                        b = (v>>16)&0x0ff;
                        b = (v>>16)&0x0ff;
                        c = (v>> 8)&0x0ff;
                        c = (v>> 8)&0x0ff;
                        d = (v    )&0x0ff;
                        d = (v    )&0x0ff;
                        if (use_decimal)
                        if (use_decimal)
                                printf("%d\n", v);
                                printf("%d\n", v);
                        else
                        else
                        printf("%08x (%8s) : [%c%c%c%c] %08x\n", address, nm,
                        printf("%08x (%8s) : [%c%c%c%c] %08x\n", address, nm,
                                isgraph(a)?a:'.', isgraph(b)?b:'.',
                                isgraph(a)?a:'.', isgraph(b)?b:'.',
                                isgraph(c)?c:'.', isgraph(d)?d:'.', v);
                                isgraph(c)?c:'.', isgraph(d)?d:'.', v);
                } catch(BUSERR b) {
                } catch(BUSERR b) {
                        printf("%08x (%8s) : BUS-ERROR\n", address, nm);
                        printf("%08x (%8s) : BUS-ERROR\n", address, nm);
                }
                }
        } else {
        } else {
                value = strtoul(argv[1], NULL, 0);
                value = strtoul(argv[1], NULL, 0);
                m_fpga->writeio(address, value);
                m_fpga->writeio(address, value);
                printf("%08x (%8s)-> %08x\n", address, nm, value);
                printf("%08x (%8s)-> %08x\n", address, nm, value);
        }
        }
 
 
        if (m_fpga->poll())
        if (m_fpga->poll())
                printf("FPGA was interrupted\n");
                printf("FPGA was interrupted\n");
        delete  m_fpga;
        delete  m_fpga;
}
}
 
 
 
 

powered by: WebSVN 2.1.0

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