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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [sw/] [host/] [wbprogram.cpp] - Rev 15

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

//
//
// Filename: 	wbprogram.cpp
//
// Project:	FPGA library development (Basys3 development board)
//
// Purpose:	Program the memory with a given '.bin' file.
//
// Creator:	Dan Gisselquist
//		Gisselquist Tecnology, LLC
//
// Copyright:	2015
//
//
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <strings.h>
#include <ctype.h>
#include <string.h>
#include <signal.h>
#include <assert.h>
 
#include "port.h"
#include "llcomms.h"
#include "regdefs.h"
#include "flashdrvr.h"
 
DEVBUS	*m_fpga;
void	closeup(int v) {
	m_fpga->kill();
	exit(0);
}
 
int main(int argc, char **argv) {
	FILE	*fp;
	const int	BUFLN = (1<<20); // 4MB Flash
	DEVBUS::BUSW	*buf = new DEVBUS::BUSW[BUFLN], v, addr = EQSPIFLASH;
	FLASHDRVR	*flash;
	int		argn = 1;
 
	if ((argc > argn)&&(NULL != strstr(argv[argn],"tty")))
		m_fpga = new FPGA(new TTYCOMMS(argv[argn++]));
	else if ((argc > argn)&&(NULL != strchr(argv[argn],':'))) {
		char *ptr = strchr(argv[argn],':');
		*ptr++ = '\n';
		m_fpga = new FPGA(new NETCOMMS(argv[argn++], atoi(ptr)));
	} else {
		FPGAOPEN(m_fpga);
	}
 
	// Start with testing the version:
	try {
		printf("VERSION: %08x\n", m_fpga->readio(R_VERSION));
	} catch(BUSERR b) {
		printf("VERSION: (Bus-Err)\n");
		exit(-1);
	}
 
	// SPI flash testing
	// Enable the faster (vector) reads
	bool	vector_read = true;
	unsigned	sz;
	bool		esectors[NSECTORS];
 
	argn = 1;
	if (argc <= argn) {
		printf("BAD USAGE: program [@<Address>] file.bin\n");
		exit(-1);
	} else if (argv[argn][0] == '@') {
		addr = strtoul(&argv[argn][1], NULL, 0);
		if ((addr < EQSPIFLASH)||(addr > EQSPIFLASH*2)) {
			printf("BAD ADDRESS: 0x%08x (from %s)\n", addr, argv[argn]);
			exit(-1);
		} argn++;
	}
 
	if (argc<= argn) {
		printf("BAD USAGE: no file argument\n");
		exit(-1);
	} else if (0 != access(argv[argn], R_OK)) {
		printf("Cannot access %s\n", argv[argn]);
		exit(-1);
	}
 
	flash = new FLASHDRVR(m_fpga);
 
	fp = fopen(argv[argn], "r");
	sz = fread(buf, sizeof(buf[0]), BUFLN, fp);
	fclose(fp);
 
	try {
		flash->write(addr, sz, buf, true);
	} catch(BUSERR b) {
		fprintf(stderr, "BUS-ERR @0x%08x\n", b.addr);
		exit(-1);
	}
 
	try {
		// Turn on the write protect flag
		m_fpga->writeio(R_QSPI_EREG, 0);
	} catch(BUSERR b) {
		fprintf(stderr, "BUS-ERR, trying to read QSPI port\n");
		exit(-1);
	}
 
	if (m_fpga->poll())
		printf("FPGA was interrupted\n");
	delete	m_fpga;
}
 
 
 

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

powered by: WebSVN 2.1.0

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