dbg-test.c 1.37 KB
/* bb-debug.c v1 Frank Berndt
 * bb debug board functions;
 * :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 n, ret;
	u_int val, exp;
	int wsize, rsize;
	u_char ctrl;
	u_char wbuf[2048];
	u_char rbuf[2048];

	ret = dbp_open(dbp_TinyMon, 0);

	/*
	 * check semaphores;
	 */
	ctrl = 0x40;
	dbp_ctrl(1, &ctrl);
	ret = dbp_ctrl(0, &ctrl);
	printf("ctrl 0x%x, ret %d\n", ctrl, ret);

	ctrl = 0x01;
	dbp_ctrl(1, &ctrl);
	ret = dbp_ctrl(0, &ctrl);
	printf("ctrl 0x%x, ret %d\n", ctrl, ret);

	ctrl = 0x02;
	dbp_ctrl(1, &ctrl);
	ret = dbp_ctrl(0, &ctrl);
	printf("ctrl 0x%x, ret %d\n", ctrl, ret);

	/*
	 * write 1k of buffer;
	 */
	ret = dbp_set_wptr(0);
	printf("set wptr %d\n", ret);

	bzero(wbuf, sizeof(wbuf));
	wsize = 1024;
	for(n = 0; n < wsize; n++)
		wbuf[n] = (n >> 8) + (n & 0xff);

	ret = dbp_write_data(wbuf, wsize);
	if(ret != wsize)
		perror("write failed");

	/*
	 * read back buffer and compare;
	 */
	ret = dbp_set_rptr(0);
	printf("set rptr %d\n", ret);

	rsize = 1024;
	ret = dbp_read_data(rbuf, rsize);
	if(ret != rsize)
		fprintf(stderr, "read failed %d\n", ret);

	for(n = 0; n < rsize; n++) {
		val = rbuf[n];
		exp = wbuf[n];
		if(val != exp)
			printf("Error: byte[%0d] 0x%x exp 0x%x\n", n, val, exp);
	}

	dbp_close();
}