/[VMELinux]/vmeutils/unilib.cpp
ViewVC logotype

Contents of /vmeutils/unilib.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Mon Jun 18 14:57:44 2001 UTC (18 years, 9 months ago) by astro
Branch: MAIN
CVS Tags: vmelinux-1_1_2, Linux2_4_x
Changes since 1.1: +2 -6 lines
Changed the device number from 70 to 221 as assigned by the Linux authorities.
1 //------------------------------------------------------------------------------
2 //title: VME Debugger for XVME-655
3 //version: Linux 2.2
4 //programmer: Michael Wyrick & John Huggins
5 //project: VMELinux Project in association with Chesapeake Research
6 //------------------------------------------------------------------------------
7 // Purpose:
8 // Docs:
9 //------------------------------------------------------------------------------
10 // $Id: unilib.cpp,v 1.2 2001/06/18 14:57:44 astro Exp $
11 //------------------------------------------------------------------------------
12 #include <stdio.h>
13 #include <ctype.h>
14 #include <fcntl.h>
15 #include <unistd.h>
16 #include <sys/ioctl.h>
17 #include "universe.h"
18 #include "unilib.h"
19
20 // Set to one if 16 bit and/or 32 bit values should be byte swapped
21 // when going to or from the VMEbus.
22 int SwapEndian = 0;
23
24 int vme_handle;
25 int uni_handle;
26 int vme_space;
27 int ctl = 0x00800000;
28 unsigned int pci_base_addr;
29 unsigned int pci_bound_addr;
30 unsigned int vme_base_addr;
31
32 extern int which_img;
33
34 //----------------------------------------------------------------------------
35 //
36 //----------------------------------------------------------------------------
37 unsigned int ReadUniReg(int reg)
38 {
39 unsigned int v;
40
41 lseek(uni_handle,reg,SEEK_SET);
42 read(uni_handle,&v,4);
43 return v;
44 }
45
46 //----------------------------------------------------------------------------
47 // Setup the Universe
48 //----------------------------------------------------------------------------
49 void WriteUniReg(int reg, unsigned int v)
50 {
51 lseek(uni_handle,reg,SEEK_SET);
52 write(uni_handle,&v,4);
53 }
54
55 //----------------------------------------------------------------------------
56 // Read one or more bytes, one byte at a time.
57 //----------------------------------------------------------------------------
58 unsigned char rb(int addr,int *error)
59 {
60 int c;
61 unsigned char v[4];
62
63 lseek(vme_handle,addr,SEEK_SET);
64 c = read(vme_handle,v,1);
65 if (c != 1)
66 *error = -1;
67 else
68 *error = 0;
69 return v[0];
70 }
71
72 //----------------------------------------------------------------------------
73 // Read one or more words, one word at a time.
74 //----------------------------------------------------------------------------
75 unsigned short rw(int addr,int *error)
76 {
77 int c;
78 unsigned short v[2];
79 unsigned short result;
80
81 lseek(vme_handle,addr,SEEK_SET);
82 c = read(vme_handle,&v,2);
83 if (c != 2)
84 *error = -1;
85 else
86 *error = 0;
87
88 if (SwapEndian)
89 result = ((v[0] & 0xFF00) >> 8) | ((v[0] & 0x00FF) << 8);
90 else
91 result = v[0];
92
93 return result;
94 }
95 unsigned short result;
96
97 //----------------------------------------------------------------------------
98 // Read one or more longwords(32bit), one at a time.
99 //----------------------------------------------------------------------------
100 unsigned int rl(int addr,int *error)
101 {
102 int c;
103 unsigned int v[4];
104 unsigned int result;
105
106 lseek(vme_handle,addr,SEEK_SET);
107 c = read(vme_handle,&v,4);
108 if (c != 4)
109 *error = -1;
110 else
111 *error = 0;
112
113 if (SwapEndian) // Added by JSH
114 result = ((v[0] & 0xFF000000) >> 24) | ((v[0] & 0x00FF0000) >> 8) | ((v[0] & 0x0000FF00) << 8) | ((v[0] & 0x000000FF) << 24);
115 else
116 result = v[0];
117
118 return result;
119 }
120
121 //----------------------------------------------------------------------------
122 // Write one or more bytes, one byte at a time.
123 //----------------------------------------------------------------------------
124 void wb(int addr,unsigned char v,int *error)
125 {
126 int c;
127
128 lseek(vme_handle,addr,SEEK_SET);
129 c = write(vme_handle,&v,1);
130 if (c != 1)
131 *error = -1;
132 else
133 *error = 0;
134 }
135
136 //----------------------------------------------------------------------------
137 // Write one or more words, one word at a time.
138 //----------------------------------------------------------------------------
139 void ww(int addr,unsigned short v,int *error)
140 {
141 int c;
142 unsigned short result;
143
144 if (SwapEndian)
145 result = ((v & 0x00FF00) >> 8) | ((v & 0x00FF) << 8);
146 else
147 result = v;
148
149 lseek(vme_handle,addr,SEEK_SET);
150 c = write(vme_handle,&result,2);
151 if (c != 2)
152 *error = -1;
153 else
154 *error = 0;
155 }
156
157 //----------------------------------------------------------------------------
158 // Write one or more longwords(32bit), one at a time.
159 //----------------------------------------------------------------------------
160 void wl(int addr,unsigned int v,int *error)
161 {
162 int c;
163 unsigned int result;
164
165 if (SwapEndian) // Added by JSH
166 result = ((v & 0xFF000000) >> 24) | ((v & 0x00FF0000) >> 8) | ((v & 0x0000FF00) << 8) | ((v & 0x000000FF) << 24) ;
167 else
168 result = v;
169
170 lseek(vme_handle,addr,SEEK_SET);
171 // c = write(vme_handle,&v,4);
172 c = write(vme_handle,&result,4);
173 if (c != 4)
174 *error = -1;
175 else
176 *error = 0;
177 }
178
179 //----------------------------------------------------------------------------
180 //
181 //----------------------------------------------------------------------------
182 int init_vmelib(void)
183 {
184 switch (which_img) {
185 case 0 :
186 vme_handle = open("//dev//vme_m0",O_RDWR,0);
187 break;
188 case 1 :
189 vme_handle = open("//dev//vme_m1",O_RDWR,0);
190 break;
191 case 2 :
192 vme_handle = open("//dev//vme_m2",O_RDWR,0);
193 break;
194 case 3 :
195 vme_handle = open("//dev//vme_m3",O_RDWR,0);
196 break;
197 }
198 uni_handle = open("//dev//vme_ctl",O_RDWR,0);
199
200 if (!vme_handle) {
201 printf("Can't open VME device\n");
202 return 1;
203 }
204
205 if (!uni_handle) {
206 printf("Can't open Universe Control device\n");
207 return 1;
208 }
209
210 return 0;
211 }
212
213 //----------------------------------------------------------------------------
214 //
215 //----------------------------------------------------------------------------
216 void shutdown_vmelib(void)
217 {
218 close(vme_handle);
219 close(uni_handle);
220 }
221
222 //----------------------------------------------------------------------------
223 //
224 //----------------------------------------------------------------------------
225 void vmespace(int i)
226 {
227 int am;
228 int size;
229
230 size = i & VME_SIZE;
231
232 switch (size) {
233 case VME_SIZE_8:
234 ctl &= ~CTL_VDW;
235 ctl |= CTL_VDW_8;
236 ioctl(vme_handle,IOCTL_SET_CTL,ctl);
237 break;
238 case VME_SIZE_16:
239 ctl &= ~CTL_VDW;
240 ctl |= CTL_VDW_16;
241 ioctl(vme_handle,IOCTL_SET_CTL,ctl);
242 break;
243 case VME_SIZE_32:
244 ctl &= ~CTL_VDW;
245 ctl |= CTL_VDW_32;
246 ioctl(vme_handle,IOCTL_SET_CTL,ctl);
247 break;
248 case VME_SIZE_64:
249 ctl &= ~CTL_VDW;
250 ctl |= CTL_VDW_64;
251 ioctl(vme_handle,IOCTL_SET_CTL,ctl);
252 break;
253 }
254
255 am = i & 0x03;
256
257 if (i & VME_PRG_DATA) {
258 ctl |= CTL_PGM;
259 ioctl(vme_handle,IOCTL_SET_CTL,ctl);
260 } else {
261 ctl &= ~CTL_PGM;
262 ioctl(vme_handle,IOCTL_SET_CTL,ctl);
263 }
264
265 if (i & VME_SUP_USR) {
266 ctl |= CTL_SUPER;
267 ioctl(vme_handle,IOCTL_SET_CTL,ctl);
268 } else {
269 ctl &= ~CTL_SUPER;
270 ioctl(vme_handle,IOCTL_SET_CTL,ctl);
271 }
272
273 if (i & VME_CYCLE) {
274 ctl |= CTL_VCT;
275 ioctl(vme_handle,IOCTL_SET_CTL,ctl);
276 } else {
277 ctl &= ~CTL_VCT;
278 ioctl(vme_handle,IOCTL_SET_CTL,ctl);
279 }
280
281 if (am == VME_A16) {
282 vme_space = am;
283 ctl &= ~CTL_VAS;
284 ctl |= CTL_VAS_A16;
285 ioctl(vme_handle,IOCTL_SET_CTL,ctl);
286 } else if (am == VME_A24) {
287 vme_space = am;
288 ctl &= ~CTL_VAS;
289 ctl |= CTL_VAS_A24;
290 ioctl(vme_handle,IOCTL_SET_CTL,ctl);
291 } else if (am == VME_A32) {
292 vme_space = am;
293 ctl &= ~CTL_VAS;
294 ctl |= CTL_VAS_A32;
295 ioctl(vme_handle,IOCTL_SET_CTL,ctl);
296 } else if (am == VME_CR_CSR) {
297 vme_space = am;
298 ctl &= ~CTL_VAS;
299 ctl |= CTL_VAS_CR_CSR;
300 ioctl(vme_handle,IOCTL_SET_CTL,ctl);
301 } else {
302 printf("Invaild VMESPACE\n");
303 }
304 }
305
306 //----------------------------------------------------------------------------
307 // Note: Images 1-3 have to be 64k aligned
308 //----------------------------------------------------------------------------
309 void vmemap(unsigned int addr,int count,char space)
310 {
311 int to;
312
313 vmespace(space);
314
315 switch (which_img) {
316 case 0:
317 pci_base_addr = 0xC0000000;
318 break;
319 case 1:
320 pci_base_addr = 0xC1000000;
321 break;
322 case 2:
323 pci_base_addr = 0xC2000000;
324 break;
325 case 3:
326 pci_base_addr = 0xC3000000;
327 break;
328 }
329
330 pci_bound_addr = pci_base_addr + (((count-1) / 0x10000)+1)*0x10000;
331 vme_base_addr = addr;
332 to = -pci_base_addr + vme_base_addr;
333
334 ctl &= ~CTL_EN; // Disable Slave
335 ioctl(vme_handle,IOCTL_SET_CTL,ctl);
336 ioctl(vme_handle,IOCTL_SET_TO,to);
337 ioctl(vme_handle,IOCTL_SET_BD,pci_bound_addr);
338 ioctl(vme_handle,IOCTL_SET_BS,pci_base_addr); // Must set this after BD
339 ctl |= CTL_EN; // Enable Slave
340 ioctl(vme_handle,IOCTL_SET_CTL,ctl);
341
342
343 // Lets do programed for now
344 ioctl(vme_handle,IOCTL_SET_MODE,MODE_PROGRAMMED);
345 }

  ViewVC Help
Powered by ViewVC 1.2-dev