dbg-dump.c 1022 Bytes
/* dbg-dump.c v1 Frank Berndt
 * debug board sram dump;
 * :set tabstop=4
 */

#include <sys/file.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <linux/parport.h>

#include "dbp.h"

/*
 * main entry;
 */
int
main(int argc, char **argv)
{
	int ret, p, n;
	char *msg;
	u_char ctrl;
	u_short rbuf[16];

	/*
	 * open the parallel port;
	 * configure the fpga;
	 */
	ret = dbp_open(dbp_TinyMon, 0);

	/*
	 * reset the semaphores;
	 */
	dbp_cr(1);
	ret = dbp_ctrl(0, &ctrl);
	printf("host ctrl 0x%x, ret %d\n", ctrl, ret);

	/*
	 * dump entire sram;
	 */
	for(p = 0; p < 2048; p += 32) {
		ret = dbp_set_rptr(p);		/* set rptr */
		msg = "read ctrl";
		if(ret < 0)
			break;
		ret = dbp_read_data(rbuf, sizeof(rbuf));
		msg = "read data";
		if(ret <= 0)
			break;
		for(n = 0; n < 16; n += 4) {
			printf("%04d 0x%04x 0x%04x 0x%04x 0x%04x\n",
				p + n*2, rbuf[n+0], rbuf[n+1], rbuf[n+2], rbuf[n+3]);
		}
	}
	if(ret <= 0)
		printf("%s: %s: %s\n", argv[0], msg, strerror(errno));
	dbp_close();
	exit(1);
}