source: drsdaq/VME/struck/sis1100/V2.02/test/reset1100.c@ 23

Last change on this file since 23 was 22, checked in by ogrimm, 16 years ago
First commit of drsdaq program
File size: 1.5 KB
Line 
1#include <stdio.h>
2#include <errno.h>
3#include <string.h>
4#include <sys/types.h>
5#include <fcntl.h>
6#include <sys/ioctl.h>
7
8#include <dev/pci/sis1100_var.h>
9
10static u_int32_t write_local_register(int p, u_int32_t offs, u_int32_t val)
11{
12 struct sis1100_ctrl_reg reg;
13
14 reg.offset=offs;
15 reg.val=val;
16 if (ioctl(p, SIS1100_CONTROL_WRITE, &reg)<0) {
17 fprintf(stderr, "ioctl(SIS1100_CONTROL_WRITE, offs=0x%x): %s\n",
18 offs, strerror(errno));
19 return -1;
20 }
21 return 0;
22}
23
24static u_int32_t read_local_register(int p, u_int32_t offs)
25{
26 struct sis1100_ctrl_reg reg;
27
28 reg.offset=offs;
29 if (ioctl(p, SIS1100_CONTROL_READ, &reg)<0) {
30 fprintf(stderr, "ioctl(SIS1100_CONTROL_READ, offs=0x%x): %s\n",
31 offs, strerror(errno));
32 return -1;
33 }
34 return reg.val;
35}
36
37int main(int argc, char* argv[])
38{
39 int p;
40 u_int32_t status, control;
41
42 if (argc<2)
43 {
44 fprintf(stderr, "usage: %s path\n", argv[0]);
45 return 1;
46 }
47
48 if ((p=open(argv[1], O_RDWR, 0))<0)
49 {
50 fprintf(stderr, "open(\"%s\"): %s\n", argv[1], strerror(errno));
51 return 1;
52 }
53
54 status=read_local_register(p, 4);
55 control=read_local_register(p, 8);
56 printf(" before reset:\n");
57 printf("status=0x%08x, control=0x%08x\n", status, control);
58 write_local_register(p, 8, 1);
59 status=read_local_register(p, 4);
60 control=read_local_register(p, 8);
61 printf(" after reset:\n");
62 printf("status=0x%08x, control=0x%08x\n", status, control);
63
64 close(p);
65 return 0;
66}
Note: See TracBrowser for help on using the repository browser.