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

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [sw/] [loadmem.cpp] - Blame information for rev 111

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 111 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    loadmem.cpp
4
//
5
// Project:     XuLA2 board
6
//
7
// Purpose:     Load a local file into the SDRAM's memory
8
//
9
//
10
// Creator:     Dan Gisselquist, Ph.D.
11
//              Gisselquist Technology, LLC
12
//
13
////////////////////////////////////////////////////////////////////////////////
14
//
15
// Copyright (C) 2015, Gisselquist Technology, LLC
16
//
17
// This program is free software (firmware): you can redistribute it and/or
18
// modify it under the terms of  the GNU General Public License as published
19
// by the Free Software Foundation, either version 3 of the License, or (at
20
// your option) any later version.
21
//
22
// This program is distributed in the hope that it will be useful, but WITHOUT
23
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
24
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
25
// for more details.
26
//
27
// License:     GPL, v3, as defined and found on www.gnu.org,
28
//              http://www.gnu.org/licenses/gpl.html
29
//
30
//
31
////////////////////////////////////////////////////////////////////////////////
32
//
33
//
34
//
35
#include <stdio.h>
36
#include <stdlib.h>
37
#include <unistd.h>
38
#include <strings.h>
39
#include <ctype.h>
40
#include <string.h>
41
#include <signal.h>
42
#include <assert.h>
43
 
44
#include "llcomms.h"
45
#include "usbi.h"
46
#include "port.h"
47
#include "regdefs.h"
48
 
49
FPGA    *m_fpga;
50
 
51
int main(int argc, char **argv) {
52
        FILE            *fpin;
53
        unsigned        pos=0;
54
        int             port = FPGAPORT, skp;
55
        const int       BUFLN = 127;
56
        FPGA::BUSW      *buf = new FPGA::BUSW[BUFLN];
57
        bool            use_usb = true;
58
 
59
        skp = 1;
60
        for(int argn=0; argn<argc-skp; argn++) {
61
                if (argv[argn+skp][0] == '-') {
62
                        if (argv[argn+skp][1] == 'u')
63
                                use_usb = true;
64
                        else if (argv[argn+skp][1] == 'p') {
65
                                use_usb = false;
66
                                if (isdigit(argv[argn+skp][2]))
67
                                        port = atoi(&argv[argn+skp][2]);
68
                        } skp++; argn--;
69
                } else
70
                        argv[argn] = argv[argn+skp];
71
        } argc -= skp;
72
 
73
        if (argc!=2) {
74
                printf("Usage: loadmem [-p [port]] srcfile\n");
75
                exit(-1);
76
        }
77
 
78
        fpin = fopen(argv[0], "rb");
79
        if (fpin == NULL) {
80
                fprintf(stderr, "Could not open %s\n", argv[1]);
81
                exit(-1);
82
        }
83
 
84
        if (use_usb)
85
                m_fpga = new FPGA(new USBI());
86
        else
87
                m_fpga = new FPGA(new NETCOMMS(FPGAHOST, port));
88
 
89
 
90
        try {
91
                int     nr;
92
                pos = SDRAMBASE;
93
                do {
94
                        nr = BUFLN;
95
                        if (nr + pos > SDRAMBASE*2)
96
                                nr = SDRAMBASE*2 - pos;
97
                        nr = fread(buf, sizeof(FPGA::BUSW), nr, fpin);
98
                        if (nr <= 0)
99
                                break;
100
 
101
                        m_fpga->writei(pos, nr, buf);
102
                        pos += nr;
103
                } while((nr > 0)&&(pos < 2*SDRAMBASE));
104
 
105
                printf("SUCCESS::fully wrote full file to memory (pos = %08x)\n", pos);
106
        } catch(BUSERR a) {
107
                fprintf(stderr, "BUS Err while writing at address 0x%08x\n", a.addr);
108
                fprintf(stderr, "... is your program too long for this memory?\n");
109
                exit(-2);
110
        } catch(...) {
111
                fprintf(stderr, "Other error\n");
112
                exit(-3);
113
        }
114
 
115
        fclose(fpin);
116
        delete  m_fpga;
117
}
118
 

powered by: WebSVN 2.1.0

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