dbg-mon.c 1.11 KB
/* dbg-mon.c v1 Frank Berndt
 * debug board background deamon;
 * :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;
	char *msg;
	u_char ctrl;
	u_char rbuf[2048];

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

	/*
	 * reset the semaphores;
	 */
	ctrl = 0x40;
	dbp_ctrl(1, &ctrl);
	ctrl = 0x01;
	dbp_ctrl(1, &ctrl);

	/*
	 * spin on semaphore and print;
	 */
	while(1) {
		ret = dbp_ctrl(0, &ctrl);	/* wait for semaphore */
		msg = "set read ptr";
		if(ret < 0)
			break;
		if( !(ctrl & 0x01))
			continue;		/* no request */
		ret = dbp_set_rptr(0);		/* set rptr to 0 */
		msg = "read ctrl";
		if(ret < 0)
			break;
		ret = dbp_read_data(rbuf, sizeof(rbuf));
		msg = "read data";
		if(ret <= 0)
			break;
		printf("# %s\n", rbuf);		/* dump string */
		ctrl = 0x01;
		ret = dbp_ctrl(1, &ctrl);
		msg = "clear semaphore";
		if(ret <= 0)
			break;
	}
	printf("%s: %s: %s\n", argv[0], msg, strerror(errno));
	dbp_close();
	exit(1);
}