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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [sw/] [host/] [wbprogram.cpp] - Blame information for rev 13

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

Line No. Rev Author Line
1 4 dgisselq
//
2
//
3
// Filename:    wbprogram.cpp
4
//
5
// Project:     FPGA library development (Basys3 development board)
6
//
7
// Purpose:     Program the memory with a given '.bin' file.
8
//
9
// Creator:     Dan Gisselquist
10
//              Gisselquist Tecnology, LLC
11
//
12
// Copyright:   2015
13
//
14
//
15
#include <stdio.h>
16
#include <stdlib.h>
17
#include <unistd.h>
18
#include <strings.h>
19
#include <ctype.h>
20
#include <string.h>
21
#include <signal.h>
22
#include <assert.h>
23
 
24
#include "port.h"
25
#include "llcomms.h"
26
#include "regdefs.h"
27
#include "flashdrvr.h"
28
 
29
DEVBUS  *m_fpga;
30
void    closeup(int v) {
31
        m_fpga->kill();
32
        exit(0);
33
}
34
 
35
int main(int argc, char **argv) {
36
        FILE    *fp;
37
        const int       BUFLN = (1<<20); // 4MB Flash
38
        DEVBUS::BUSW    *buf = new DEVBUS::BUSW[BUFLN], v, addr = QSPIFLASH;
39
        FLASHDRVR       *flash;
40
        int             argn = 1;
41
 
42
        if ((argc > argn)&&(NULL != strstr(argv[argn],"tty")))
43
                m_fpga = new FPGA(new TTYCOMMS(argv[argn++]));
44
        else if ((argc > argn)&&(NULL != strchr(argv[argn],':'))) {
45
                char *ptr = strchr(argv[argn],':');
46
                *ptr++ = '\n';
47
                m_fpga = new FPGA(new NETCOMMS(argv[argn++], atoi(ptr)));
48
        } else {
49
                FPGAOPEN(m_fpga);
50
        }
51
 
52
        // Start with testing the version:
53
        try {
54
                printf("VERSION: %08x\n", m_fpga->readio(R_VERSION));
55
        } catch(BUSERR b) {
56
                printf("VERSION: (Bus-Err)\n");
57
                exit(-1);
58
        }
59
 
60
        // SPI flash testing
61
        // Enable the faster (vector) reads
62
        bool    vector_read = true;
63
        unsigned        sz;
64
        bool            esectors[NSECTORS];
65
 
66
        argn = 1;
67
        if (argc <= argn) {
68
                printf("BAD USAGE: program [@<Address>] file.bin\n");
69
                exit(-1);
70
        } else if (argv[argn][0] == '@') {
71
                addr = strtoul(&argv[argn][1], NULL, 0);
72
                if ((addr < QSPIFLASH)||(addr > QSPIFLASH*2)) {
73
                        printf("BAD ADDRESS: 0x%08x (from %s)\n", addr, argv[argn]);
74
                        exit(-1);
75
                } argn++;
76
        }
77
 
78
        if (argc<= argn) {
79
                printf("BAD USAGE: no file argument\n");
80
                exit(-1);
81
        } else if (0 != access(argv[argn], R_OK)) {
82
                printf("Cannot access %s\n", argv[argn]);
83
                exit(-1);
84
        }
85
 
86
        flash = new FLASHDRVR(m_fpga);
87
 
88
        fp = fopen(argv[argn], "r");
89
        sz = fread(buf, sizeof(buf[0]), BUFLN, fp);
90
        fclose(fp);
91
 
92
        try {
93
                flash->write(addr, sz, buf, false);
94
        } catch(BUSERR b) {
95
                fprintf(stderr, "BUS-ERR @0x%08x\n", b.addr);
96
                exit(-1);
97
        }
98
 
99
        try {
100
                // Turn on the write protect flag
101
                m_fpga->writeio(R_QSPI_EREG, 0);
102
        } catch(BUSERR b) {
103
                fprintf(stderr, "BUS-ERR, trying to read QSPI port\n");
104
                exit(-1);
105
        }
106
 
107
        if (m_fpga->poll())
108
                printf("FPGA was interrupted\n");
109
        delete  m_fpga;
110
}
111
 
112
 

powered by: WebSVN 2.1.0

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