dbg-mon.c
1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* 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);
}