dbg-test.c
1.37 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* 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();
}