source: drsdaq/VME/struck/sis1100/V2.02/test/test_mapsize.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: 4.1 KB
Line 
1#define _GNU_SOURCE
2#include <stdio.h>
3#include <errno.h>
4#include <sys/types.h>
5#include <unistd.h>
6#include <stdlib.h>
7#include <string.h>
8#include <fcntl.h>
9#include <sys/mman.h>
10#include <sys/ioctl.h>
11
12#include "dev/pci/sis1100_var.h"
13
14static int write_reg(int p, int offset, u_int32_t value)
15{
16 struct sis1100_ctrl_reg reg;
17 reg.offset=offset;
18 reg.val=value;
19 if (ioctl(p, SIS1100_CONTROL_WRITE, &reg)<0) {
20 printf("SIS1100_CONTROL_WRITE 0x%08x -> 0x%03x: %s\n",
21 reg.val, reg.offset, strerror(errno));
22 return -1;
23 }
24 if (reg.error) {
25 printf("SIS1100_CONTROL_WRITE 0x%08x -> 0x%03x: error=%d\n",
26 reg.val, reg.offset, reg.error);
27 return -1;
28 }
29 return 0;
30}
31
32/****************************************************************************/
33static u_int32_t* mmap_vme_space(int p, size_t* mapped_len)
34{
35 u_int32_t *space, size;
36
37 if (ioctl(p, SIS1100_MAPSIZE, &size)) {
38 printf("ioctl(SIS1100_MAPSIZE): %s\n", strerror(errno));
39 return 0;
40 }
41
42 /* map the vme space */
43 space=mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, p, 0);
44 if (space==MAP_FAILED)
45 {
46 printf("mmap vme space: %s\n", strerror(errno));
47 return 0;
48 }
49 *mapped_len=size;
50 return space;
51}
52/****************************************************************************/
53int main(int argc, char* argv[])
54{
55 int p;
56 volatile u_int32_t* vmespace;
57 volatile u_int32_t data;
58 size_t vmespacelen;
59
60 if (argc!=2) {
61 printf("usage: %s path\n", argv[0]);
62 return 1;
63 }
64
65 if ((p=open(argv[1], O_RDWR, 0))<0) {
66 printf("open \"%s\": %s\n", argv[1], strerror(errno));
67 return 1;
68 }
69
70 vmespace=mmap_vme_space(p, &vmespacelen);
71 if (!vmespace) {
72 printf("map vme failed\n");
73 return 1;
74 }
75 printf("vmespacelen=%d MByte\n", vmespacelen>>20);
76
77 if (write_reg(p, 0x400, 0xff01081c)<0) return 1;
78 if (write_reg(p, 0x404, 0x09)<0) return 1;
79 if (write_reg(p, 0x40c, 0x0)<0) return 1;
80
81 if (write_reg(p, 0x408, 0xffffffff)<0) return 1;
82 data=vmespace[0];
83 if (write_reg(p, 0x408, 0xfffffff0)<0) return 1;
84 data=vmespace[0];
85 if (write_reg(p, 0x408, 0xffffff00)<0) return 1;
86 data=vmespace[0];
87 if (write_reg(p, 0x408, 0xfffff000)<0) return 1;
88 data=vmespace[0];
89 if (write_reg(p, 0x408, 0xffff0000)<0) return 1;
90 data=vmespace[0];
91 if (write_reg(p, 0x408, 0xfff00000)<0) return 1;
92 data=vmespace[0];
93 if (write_reg(p, 0x408, 0xff000000)<0) return 1;
94 data=vmespace[0];
95 if (write_reg(p, 0x408, 0xf0000000)<0) return 1;
96 data=vmespace[0];
97 if (write_reg(p, 0x408, 0x00000000)<0) return 1;
98 data=vmespace[0];
99
100 if (write_reg(p, 0x408, 0x00000000)<0) return 1;
101 data=vmespace[0x1];
102 data=vmespace[0x2];
103 data=vmespace[0x4];
104 data=vmespace[0x8];
105 data=vmespace[0x10];
106 data=vmespace[0x20];
107 data=vmespace[0x40];
108 data=vmespace[0x80];
109 data=vmespace[0x100];
110 data=vmespace[0x200];
111 data=vmespace[0x400];
112 data=vmespace[0x800];
113 data=vmespace[0x1000];
114 data=vmespace[0x2000];
115 data=vmespace[0x4000];
116 data=vmespace[0x8000];
117 data=vmespace[0x10000];
118 data=vmespace[0x20000];
119 data=vmespace[0x40000];
120 data=vmespace[0x80000];
121 data=vmespace[0x100000];
122 data=vmespace[0x200000];
123 data=vmespace[0x400000];
124 data=vmespace[0x800000];
125
126
127/*
128 * if (write_reg(p, 0x400, 0x0f01101c)<0) return 1;
129 * if (write_reg(p, 0x404, 0x09)<0) return 1;
130 * if (write_reg(p, 0x404, 0x0)<0) return 1;
131 * if (write_reg(p, 0x404, 0x0)<0) return 1;
132 *
133 * data=vmespace[0xffffffff];
134 */
135
136 if (munmap((void*)vmespace, vmespacelen)<0) {
137 fprintf(stderr, "munmap: %s\n", strerror(errno));
138 }
139 close(p);
140
141 return 0;
142}
Note: See TracBrowser for help on using the repository browser.