AlcapDAQ  1
Macros | Functions | Variables
hyt1331.c File Reference
#include <stdio.h>
#include <string.h>
#include "mcstd.h"

Go to the source code of this file.

Macros

#define MAX_DEVICES   4 /* Maximal 4 PC cards */
 

Functions

INLINE void cam8i (const int c, const int n, const int a, const int f, BYTE *d)
 
INLINE void cami (const int c, const int n, const int a, const int f, WORD *d)
 
INLINE void cam16i (const int c, const int n, const int a, const int f, WORD *d)
 
INLINE void cam24i (const int c, const int n, const int a, const int f, DWORD *d)
 
INLINE void cam8i_q (const int c, const int n, const int a, const int f, BYTE *d, int *x, int *q)
 
INLINE void cam16i_q (const int c, const int n, const int a, const int f, WORD *d, int *x, int *q)
 
INLINE void cam24i_q (const int c, const int n, const int a, const int f, DWORD *d, int *x, int *q)
 
INLINE void cam16i_r (const int c, const int n, const int a, const int f, WORD **d, const int r)
 
INLINE void cam24i_r (const int c, const int n, const int a, const int f, DWORD **d, const int r)
 
INLINE void cam16i_rq (const int c, const int n, const int a, const int f, WORD **d, const int r)
 
INLINE void cam24i_rq (const int c, const int n, const int a, const int f, DWORD **d, const int r)
 
INLINE void cam16i_sa (const int c, const int n, const int a, const int f, WORD **d, const int r)
 
INLINE void cam24i_sa (const int c, const int n, const int a, const int f, DWORD **d, const int r)
 
INLINE void cam16i_sn (const int c, const int n, const int a, const int f, WORD **d, const int r)
 
INLINE void cam24i_sn (const int c, const int n, const int a, const int f, DWORD **d, const int r)
 
INLINE void cam8o (const int c, const int n, const int a, const int f, BYTE d)
 
INLINE void camo (const int c, const int n, const int a, const int f, WORD d)
 
INLINE void cam16o (const int c, const int n, const int a, const int f, WORD d)
 
INLINE void cam24o (const int c, const int n, const int a, const int f, DWORD d)
 
INLINE void cam16o_q (const int c, const int n, const int a, const int f, WORD d, int *x, int *q)
 
INLINE void cam24o_q (const int c, const int n, const int a, const int f, DWORD d, int *x, int *q)
 
INLINE void cam8o_r (const int c, const int n, const int a, const int f, BYTE *d, const int r)
 
INLINE void cam16o_r (const int c, const int n, const int a, const int f, WORD *d, const int r)
 
INLINE void cam24o_r (const int c, const int n, const int a, const int f, DWORD *d, const int r)
 
INLINE int camc_chk (const int c)
 
INLINE void camc (const int c, const int n, const int a, const int f)
 
INLINE void camc_q (const int c, const int n, const int a, const int f, int *q)
 
INLINE void camc_sa (const int c, const int n, const int a, const int f, const int r)
 
INLINE void camc_sn (const int c, const int n, const int a, const int f, const int r)
 
INLINE void cam_inhibit_set (const int c)
 
INLINE void cam_inhibit_clear (const int c)
 
INLINE int cam_inhibit_test (const int c)
 
INLINE void cam_crate_clear (const int c)
 
INLINE void cam_crate_zinit (const int c)
 
INLINE void cam_lam_enable (const int c, const int n)
 
INLINE void cam_lam_disable (const int c, const int n)
 
INLINE void cam_interrupt_enable (const int c)
 
INLINE void cam_interrupt_disable (const int c)
 
INLINE int cam_interrupt_test (const int c)
 
INLINE void cam_lam_read (const int c, DWORD *lam)
 
INLINE void cam_lam_clear (const int c, const int n)
 
INLINE int cam_init_rpc (char *host_name, char *exp_name, char *fe_name, char *client_name, char *rpc_server)
 
int directio_give_port (DWORD start, DWORD end)
 
int directio_lock_port (DWORD start, DWORD end)
 
int pci_scan (int vendor_id, int device_id, int n_dev, BYTE *pirq, DWORD *ba)
 
void catch_sigsegv (int signo)
 
INLINE int cam_init (void)
 
INLINE void cam_exit (void)
 

Variables

WORD io_base [MAX_DEVICES]
 
BYTE irq [MAX_DEVICES]
 
int gbl_sw1d [MAX_DEVICES]
 

Macro Definition Documentation

#define MAX_DEVICES   4 /* Maximal 4 PC cards */

Definition at line 116 of file hyt1331.c.

Referenced by cam_exit().

Function Documentation

INLINE void cam16i ( const int  c,
const int  n,
const int  a,
const int  f,
WORD d 
)

Definition at line 156 of file hyt1331.c.

References cami().

Referenced by cam16i_sn().

157 {
158  cami(c, n, a, f, d);
159 }
INLINE void cam16i_q ( const int  c,
const int  n,
const int  a,
const int  f,
WORD d,
int *  x,
int *  q 
)

Definition at line 202 of file hyt1331.c.

References io_base, and status.

Referenced by cnaf_callback().

204 {
205  WORD adr;
206  BYTE status;
207 
208  adr = io_base[c >> 2] + ((c % 3) << 4);
209  OUTP(adr + 8, n);
210  OUTP(adr + 6, a);
211  OUTP(adr + 10, f);
212 
213  status = (BYTE) INP(adr + 6);
214  *((BYTE *) d) = INP(adr);
215  *(((BYTE *) d) + 1) = INP(adr + 2);
216 
217  *q = status & 1;
218  *x = status >> 7;
219 }
INLINE void cam16i_r ( const int  c,
const int  n,
const int  a,
const int  f,
WORD **  d,
const int  r 
)

Definition at line 245 of file hyt1331.c.

References i, io_base, and status.

247 {
248  WORD adr, i, status;
249 
250  adr = io_base[c >> 2] + ((c % 3) << 4);
251 
252  OUTP(adr + 8, n);
253  OUTP(adr + 6, a);
254  OUTP_P(adr + 10, f);
255 
256  status = (BYTE) INP(adr + 6);
257  *((BYTE *) * d) = INP(adr);
258  *(((BYTE *) * d) + 1) = INP(adr + 2); /* read the first word */
259  (*d)++;
260 
261  INPW_P(adr + 12); /* trigger first cycle */
262 
263  for (i = 0; i < (r - 1); i++)
264  *((*d)++) = INPW(adr + 12); /* read data and trigger next cycle */
265 }
INLINE void cam16i_rq ( const int  c,
const int  n,
const int  a,
const int  f,
WORD **  d,
const int  r 
)

Definition at line 318 of file hyt1331.c.

References i, and io_base.

Referenced by cnaf_callback().

320 {
321  WORD adr, i;
322  int fail;
323 
324  /* following code is disabled by above code */
325  adr = io_base[c >> 2] + ((c % 3) << 4);
326 
327  OUTP(adr + 8, n);
328  OUTP(adr + 6, a);
329  /* Turn on the Q-mode for repeat until Q=1 in the INPW(adr+12) */
330  OUTP(adr + 1, 0x10);
331  OUTP_P(adr + 10, f);
332  INPW_P(adr + 12); /* trigger first cycle */
333 
334  for (i = 0; i < r; i++) {
335  /* read data and trigger next cycle fail = no valid Q within 12usec */
336  **d = INPW_P(adr + 12);
337  fail = ((BYTE) INP(adr + 6)) & 0x20; // going to test!
338  if (fail)
339  break;
340  (*d)++;
341  }
342  /* Turn off the Q-mode for repeat until Q=1 in the INPW(adr+12) */
343  OUTP(adr + 1, 0x0);
344 }
INLINE void cam16i_sa ( const int  c,
const int  n,
const int  a,
const int  f,
WORD **  d,
const int  r 
)

Definition at line 379 of file hyt1331.c.

References cami(), gbl_sw1d, i, and io_base.

381 {
382  WORD adr, i;
383 
384  if (gbl_sw1d[c]) {
385  adr = io_base[c >> 2] + ((c % 3) << 4);
386  /* enable auto increment */
387  OUTP_P(adr + 10, 49);
388  OUTP(adr + 8, n);
389  OUTP(adr + 6, a - 1);
390  OUTP_P(adr + 10, f);
391  INPW_P(adr + 12);
392 
393  for (i = 0; i < r; i++)
394  *((*d)++) = INPW_P(adr + 12); /* read data and trigger next cycle */
395 
396  /* disable auto increment */
397  OUTP_P(adr + 10, 48);
398  } else
399  for (i = 0; i < r; i++)
400  cami(c, n, a + i, f, (*d)++);
401 }
INLINE void cam16i_sn ( const int  c,
const int  n,
const int  a,
const int  f,
WORD **  d,
const int  r 
)

Definition at line 436 of file hyt1331.c.

References cam16i(), and i.

438 {
439  int i;
440 
441  for (i = 0; i < r; i++)
442  cam16i(c, n + i, a, f, (*d)++);
443 }
INLINE void cam16o ( const int  c,
const int  n,
const int  a,
const int  f,
WORD  d 
)

Definition at line 486 of file hyt1331.c.

References camo().

487 {
488  camo(c, n, a, f, d);
489 }
INLINE void cam16o_q ( const int  c,
const int  n,
const int  a,
const int  f,
WORD  d,
int *  x,
int *  q 
)

Definition at line 508 of file hyt1331.c.

References io_base, and status.

Referenced by cnaf_callback().

510 {
511  unsigned int adr, status;
512 
513  adr = io_base[c >> 2] + ((c % 3) << 4);
514  OUTP(adr + 8, n);
515  OUTP(adr, (BYTE) d);
516  OUTP(adr + 2, *(((BYTE *) & d) + 1));
517  OUTP(adr + 6, a);
518  OUTP(adr + 10, f);
519 
520  status = (BYTE) INP(adr + 6);
521  *q = status & 1;
522  *x = status >> 7;
523 }
INLINE void cam16o_r ( const int  c,
const int  n,
const int  a,
const int  f,
WORD d,
const int  r 
)

Definition at line 566 of file hyt1331.c.

References i, and io_base.

568 {
569  WORD adr, i;
570 
571  adr = io_base[c >> 2] + ((c % 3) << 4);
572 
573  /* trigger first cycle */
574  OUTP(adr + 8, n);
575  OUTP(adr, *((BYTE *) d));
576  OUTP(adr + 2, *(((BYTE *) d) + 1));
577  OUTP(adr + 6, a);
578  OUTP(adr + 10, f);
579 
580  for (i = 0; i < r - 1; i++)
581  OUTPW(adr + 12, *(++d)); /* write data and trigger next cycle */
582 }
INLINE void cam24i ( const int  c,
const int  n,
const int  a,
const int  f,
DWORD d 
)

Definition at line 163 of file hyt1331.c.

References io_base, and status.

Referenced by cam24i_sa(), cam24i_sn(), and s500_read().

164 {
165  WORD adr;
166  BYTE status;
167 
168  adr = io_base[c >> 2] + ((c % 3) << 4);
169  OUTP(adr + 8, n);
170  OUTP(adr + 6, a);
171  OUTP(adr + 10, f);
172 
173  status = (BYTE) INP(adr + 6);
174  *((BYTE *) d) = INP(adr);
175  *(((BYTE *) d) + 1) = INP(adr + 2);
176  *(((BYTE *) d) + 2) = INP(adr + 4);
177  *(((BYTE *) d) + 3) = 0;
178 }
INLINE void cam24i_q ( const int  c,
const int  n,
const int  a,
const int  f,
DWORD d,
int *  x,
int *  q 
)

Definition at line 223 of file hyt1331.c.

References io_base, and status.

Referenced by cnaf_callback().

225 {
226  WORD adr, status;
227 
228  adr = io_base[c >> 2] + ((c % 3) << 4);
229  OUTP(adr + 8, n);
230  OUTP(adr + 6, a);
231  OUTP(adr + 10, f);
232 
233  status = (BYTE) INP(adr + 6);
234  *((BYTE *) d) = INP(adr);
235  *(((BYTE *) d) + 1) = INP(adr + 2);
236  *(((BYTE *) d) + 2) = INP(adr + 4);
237  *(((BYTE *) d) + 3) = 0;
238 
239  *q = status & 1;
240  *x = status >> 7;
241 }
INLINE void cam24i_r ( const int  c,
const int  n,
const int  a,
const int  f,
DWORD **  d,
const int  r 
)

Definition at line 269 of file hyt1331.c.

References i, io_base, and status.

271 {
272  WORD adr, i, status;
273 
274  adr = io_base[c >> 2] + ((c % 3) << 4);
275  OUTP(adr + 8, n);
276  OUTP(adr + 6, a);
277 
278  for (i = 0; i < r; i++) {
279  OUTP(adr + 10, f);
280  status = (BYTE) INP(adr + 6);
281  *((BYTE *) * d) = INP(adr);
282  *(((BYTE *) * d) + 1) = INP(adr + 2);
283  *(((BYTE *) * d) + 2) = INP(adr + 4);
284  *(((BYTE *) * d) + 3) = 0;
285  (*d)++;
286  }
287 
288  /*
289  gives unrealiable results, SR 6.4.00
290 
291  adr = io_base[c >> 2]+((c % 3)<<4);
292 
293  OUTP(adr+8, n);
294  OUTP(adr+6, a);
295  OUTP_P(adr+10,f);
296 
297  status = (BYTE) INP(adr+6);
298  *((BYTE *) *d) = INP(adr);
299  *(((BYTE *) *d)+1) = INP(adr+2); // read the first word
300  *(((BYTE *) *d)+2) = INP(adr+4);
301  *(((BYTE *) *d)+3) = 0;
302  (*d)++;
303 
304  INPW_P(adr+12); // trigger first cycle
305 
306  for (i=0 ; i<(r-1) ; i++)
307  {
308  *(((BYTE *) *d)+2) = INP_P(adr+4);
309  *(((BYTE *) *d)+3) = 0;
310  *((WORD *) *d) = INPW_P(adr+12);
311  (*d)++;
312  }
313  */
314 }
INLINE void cam24i_rq ( const int  c,
const int  n,
const int  a,
const int  f,
DWORD **  d,
const int  r 
)

Definition at line 348 of file hyt1331.c.

References i, and io_base.

Referenced by cnaf_callback().

350 {
351  WORD adr;
352  int i, fail;
353 
354  adr = io_base[c >> 2] + ((c % 3) << 4);
355 
356  OUTP(adr + 8, n);
357  OUTP(adr + 6, a);
358  /* Turn on the Q-mode for repeat until Q=1 in the INPW(adr+12) */
359  OUTP(adr + 1, 0x10);
360  OUTP_P(adr + 10, f);
361  INPW_P(adr + 12); /* trigger first cycle */
362 
363  for (i = 0; i < r; i++) {
364  /* read data and trigger next cycle fail = no valid Q within 12usec */
365  *(((BYTE *) * d) + 2) = INP(adr + 4);
366  *(((BYTE *) * d) + 3) = 0;
367  *((WORD *) * d) = INPW_P(adr + 12);
368  fail = ((BYTE) INP(adr + 6)) & 0x20; // going to test!
369  if (fail)
370  break;
371  (*d)++;
372  }
373  /* Turn off the Q-mode for repeat until Q=1 in the INPW(adr+12) */
374  OUTP(adr + 1, 0x0);
375 }
INLINE void cam24i_sa ( const int  c,
const int  n,
const int  a,
const int  f,
DWORD **  d,
const int  r 
)

Definition at line 405 of file hyt1331.c.

References cam24i(), gbl_sw1d, i, and io_base.

407 {
408  WORD adr, i;
409 
410  if (gbl_sw1d[c]) {
411  adr = io_base[c >> 2] + ((c % 3) << 4);
412 
413  /* enable auto increment */
414  OUTP_P(adr + 10, 49);
415  OUTP(adr + 8, n);
416  OUTP(adr + 6, a - 1);
417  OUTP_P(adr + 10, f);
418  INPW_P(adr + 12);
419  for (i = 0; i < r; i++) {
420  /* read data and trigger next cycle */
421  *(((BYTE *) * d) + 2) = INP(adr + 4);
422  *(((BYTE *) * d) + 3) = 0;
423  *((WORD *) * d) = INPW_P(adr + 12);
424  (*d)++;
425  }
426 
427  /* disable auto increment */
428  OUTP_P(adr + 10, 48);
429  } else
430  for (i = 0; i < r; i++)
431  cam24i(c, n, a + i, f, (*d)++);
432 }
INLINE void cam24i_sn ( const int  c,
const int  n,
const int  a,
const int  f,
DWORD **  d,
const int  r 
)

Definition at line 447 of file hyt1331.c.

References cam24i(), and i.

449 {
450  int i;
451 
452  for (i = 0; i < r; i++)
453  cam24i(c, n + i, a, f, (*d)++);
454 }
INLINE void cam24o ( const int  c,
const int  n,
const int  a,
const int  f,
DWORD  d 
)

Definition at line 493 of file hyt1331.c.

References io_base.

494 {
495  unsigned int adr;
496 
497  adr = io_base[c >> 2] + ((c % 3) << 4);
498  OUTP(adr + 8, n);
499  OUTP(adr, (BYTE) d);
500  OUTP(adr + 2, *(((BYTE *) & d) + 1));
501  OUTP(adr + 4, *(((BYTE *) & d) + 2));
502  OUTP(adr + 6, a);
503  OUTP(adr + 10, f);
504 }
INLINE void cam24o_q ( const int  c,
const int  n,
const int  a,
const int  f,
DWORD  d,
int *  x,
int *  q 
)

Definition at line 527 of file hyt1331.c.

References io_base, and status.

Referenced by cnaf_callback().

529 {
530  unsigned int adr, status;
531 
532  adr = io_base[c >> 2] + ((c % 3) << 4);
533  OUTP(adr + 8, n);
534  OUTP(adr, (BYTE) d);
535  OUTP(adr + 2, *(((BYTE *) & d) + 1));
536  OUTP(adr + 4, *(((BYTE *) & d) + 2));
537  OUTP(adr + 6, a);
538  OUTP(adr + 10, f);
539 
540  status = (BYTE) INP(adr + 6);
541  *q = status & 1;
542  *x = status >> 7;
543 }
INLINE void cam24o_r ( const int  c,
const int  n,
const int  a,
const int  f,
DWORD d,
const int  r 
)

Definition at line 586 of file hyt1331.c.

References i, and io_base.

588 {
589  WORD adr, i;
590 
591  adr = io_base[c >> 2] + ((c % 3) << 4);
592 
593  /* trigger first cycle */
594  OUTP(adr + 8, n);
595  OUTP(adr, *((BYTE *) d));
596  OUTP(adr + 2, *(((BYTE *) d) + 1));
597  OUTP(adr + 4, *(((BYTE *) d) + 2));
598  OUTP(adr + 6, a);
599  OUTP(adr + 10, f);
600 
601  for (i = 0; i < r - 1; i++) {
602  d++;
603  OUTP(adr + 4, *(((BYTE *) d) + 2));
604  OUTPW(adr + 12, (WORD) * d); /* write data and trigger next cycle */
605  }
606 }
INLINE void cam8i ( const int  c,
const int  n,
const int  a,
const int  f,
BYTE *  d 
)

Definition at line 125 of file hyt1331.c.

References io_base, and status.

126 {
127  WORD adr, status;
128 
129  adr = io_base[c >> 2] + ((c % 3) << 4);
130  OUTP(adr + 8, n);
131  OUTP(adr + 6, a);
132  OUTP(adr + 10, f);
133 
134  status = (BYTE) INP(adr + 6);
135  *((BYTE *) d) = INP(adr);
136 }
INLINE void cam8i_q ( const int  c,
const int  n,
const int  a,
const int  f,
BYTE *  d,
int *  x,
int *  q 
)

Definition at line 182 of file hyt1331.c.

References io_base, and status.

184 {
185  WORD adr;
186  BYTE status;
187 
188  adr = io_base[c >> 2] + ((c % 3) << 4);
189  OUTP(adr + 8, n);
190  OUTP(adr + 6, a);
191  OUTP(adr + 10, f);
192 
193  status = (BYTE) INP(adr + 6);
194  *((BYTE *) d) = INP(adr);
195 
196  *q = status & 1;
197  *x = status >> 7;
198 }
INLINE void cam8o ( const int  c,
const int  n,
const int  a,
const int  f,
BYTE  d 
)

Definition at line 458 of file hyt1331.c.

References io_base.

459 {
460  unsigned int adr;
461 
462  adr = io_base[c >> 2] + ((c % 3) << 4);
463  OUTP(adr + 8, n);
464  OUTP(adr, d);
465  OUTP(adr + 6, a);
466  OUTP(adr + 10, f);
467 }
INLINE void cam8o_r ( const int  c,
const int  n,
const int  a,
const int  f,
BYTE *  d,
const int  r 
)

Definition at line 547 of file hyt1331.c.

References i, and io_base.

549 {
550  WORD adr, i;
551 
552  adr = io_base[c >> 2] + ((c % 3) << 4);
553 
554  /* trigger first cycle */
555  OUTP(adr + 8, n);
556  OUTP(adr, *((BYTE *) d));
557  OUTP(adr + 6, a);
558  OUTP(adr + 10, f);
559 
560  for (i = 0; i < r - 1; i++)
561  OUTPW(adr + 12, (BYTE) * (++d)); /* write data and trigger next cycle */
562 }
INLINE void cam_crate_clear ( const int  c)

Definition at line 710 of file hyt1331.c.

References io_base.

Referenced by cnaf_callback().

711 {
712  unsigned int adr;
713 
714  adr = io_base[c >> 2] + ((c % 3) << 4);
715  OUTP(adr + 10, 36);
716 }
INLINE void cam_crate_zinit ( const int  c)

Definition at line 720 of file hyt1331.c.

References io_base.

Referenced by cnaf_callback().

721 {
722  unsigned int adr;
723 
724  adr = io_base[c >> 2] + ((c % 3) << 4);
725  OUTP(adr + 10, 34);
726 }
INLINE void cam_exit ( void  )

Definition at line 1147 of file hyt1331.c.

References directio_lock_port(), i, io_base, and MAX_DEVICES.

1148 {
1149  int i;
1150 
1151  /* lock IO ports */
1152  for (i = 0; i < MAX_DEVICES; i++)
1153  if (io_base[i])
1154  directio_lock_port(io_base[i], io_base[i] + 4 * 0x10);
1155 }
INLINE void cam_inhibit_clear ( const int  c)

Definition at line 688 of file hyt1331.c.

References io_base.

Referenced by cam_init_once(), and cnaf_callback().

689 {
690  unsigned int adr;
691 
692  adr = io_base[c >> 2] + ((c % 3) << 4);
693  OUTP(adr + 10, 32);
694 }
INLINE void cam_inhibit_set ( const int  c)

Definition at line 678 of file hyt1331.c.

References io_base.

Referenced by cnaf_callback().

679 {
680  unsigned int adr;
681 
682  adr = io_base[c >> 2] + ((c % 3) << 4);
683  OUTP(adr + 10, 33);
684 }
INLINE int cam_inhibit_test ( const int  c)

Definition at line 698 of file hyt1331.c.

References io_base, and status.

699 {
700  unsigned int adr;
701  BYTE status;
702 
703  adr = io_base[c >> 2] + ((c % 3) << 4);
704  status = (BYTE) INP(adr + 6);
705  return (status & 1) > 0;
706 }
INLINE int cam_init ( void  )

Definition at line 1054 of file hyt1331.c.

References catch_sigsegv(), directio_give_port(), directio_lock_port(), gbl_sw1d, i, io_base, irq, pci_scan(), printf(), status, and SUCCESS.

Referenced by cam_init_once().

1055 {
1056  BYTE status, n_dev, i, n, a, f;
1057  WORD isa_io_base[] = { 0x200, 0x280, 0x300, 0x380 };
1058  WORD base_test;
1059  DWORD base_addr[6];
1060 
1061  /* set signal handler for segmet violation */
1062  signal(SIGSEGV, catch_sigsegv);
1063 
1064  /* scan PCI cards */
1065  for (n_dev = 0;; n_dev++) {
1066  if (!pci_scan(0x1196, 0x5331, n_dev + 1, irq + n_dev, base_addr))
1067  break;
1068 
1069  io_base[n_dev] = (WORD) (base_addr[3] & (~0x3UL));
1070 
1071  printf("hyt1331.c: Found PCI card at 0x%X, IRQ %d\n", io_base[n_dev], irq[n_dev]);
1072 
1073  if (directio_give_port(io_base[n_dev], io_base[n_dev] + 4 * 0x10) < 0) {
1074  signal(SIGSEGV, SIG_DFL);
1075  return 0;
1076  } else {
1077  n_dev++;
1078  break; // currently only supports one PCI interface
1079  }
1080  }
1081 
1082  /* scan ISA cards */
1083  for (i = 0; i < 4; i++) {
1084  base_test = isa_io_base[i];
1085 
1086  if (directio_give_port(base_test, base_test + 4 * 0x10) < 0) {
1087  signal(SIGSEGV, SIG_DFL);
1088  return 0;
1089  }
1090 
1091  /* Test if address is writable */
1092  OUTP(base_test, 0);
1093  status = INP(base_test);
1094  if (status != 0) {
1095  directio_lock_port(base_test, base_test + 4 * 0x10);
1096  continue;
1097  }
1098 
1099  /* Test A,N,F readback of ISA card */
1100  OUTP(base_test + 8, 1);
1101  OUTP(base_test + 6, 2);
1102  OUTP(base_test + 10, 32);
1103 
1104  a = (BYTE) INP(base_test + 10);
1105  n = (BYTE) INP(base_test + 10);
1106  f = (BYTE) INP(base_test + 10);
1107 
1108  if (n != 1 || a != 2 || f != 32) {
1109  directio_lock_port(base_test, base_test + 4 * 0x10);
1110  continue;
1111  }
1112 
1113  /* ISA card found */
1114  printf("hyt1331.c: Found ISA card at 0x%X\n", base_test);
1115 
1116  io_base[n_dev++] = base_test;
1117  }
1118 
1119  if (n_dev == 0) {
1120  printf("hyt1331.c: No PCI or ISA cards found\n");
1121  signal(SIGSEGV, SIG_DFL);
1122  return 0;
1123  }
1124 
1125  /* open port 80 for delayed write */
1126  directio_give_port(0x80, 0x80);
1127 
1128  /* check if we have access */
1129  OUTP(io_base[0], 0);
1130  signal(SIGSEGV, SIG_DFL);
1131 
1132  /* test auto increment switch SW1D */
1133  for (i = 0; i < n_dev; i++) {
1134  status = INP(io_base[i] + 6);
1135  if (!(status & (1 << 6))) {
1136  gbl_sw1d[i] = 0;
1137  } else {
1138  gbl_sw1d[i] = 1;
1139  }
1140  }
1141 
1142  return SUCCESS;
1143 }
INLINE int cam_init_rpc ( char *  host_name,
char *  exp_name,
char *  fe_name,
char *  client_name,
char *  rpc_server 
)

Definition at line 826 of file hyt1331.c.

828 {
829  /* dummy routine for compatibility */
830  return 1;
831 }
INLINE void cam_interrupt_disable ( const int  c)

Definition at line 765 of file hyt1331.c.

References io_base.

766 {
767  unsigned int adr;
768 
769  /* disable interrupts in controller */
770  adr = io_base[c >> 2] + ((c % 3) << 4);
771  OUTP(adr + 10, 40);
772 }
INLINE void cam_interrupt_enable ( const int  c)

Definition at line 754 of file hyt1331.c.

References io_base.

755 {
756  unsigned int adr;
757 
758  /* enable interrupts in controller */
759  adr = io_base[c >> 2] + ((c % 3) << 4);
760  OUTP(adr + 10, 41);
761 }
INLINE int cam_interrupt_test ( const int  c)

Definition at line 776 of file hyt1331.c.

References io_base, and status.

777 {
778  unsigned int adr;
779  BYTE status;
780 
781  adr = io_base[c >> 2] + ((c % 3) << 4);
782  status = (BYTE) INP(adr + 6);
783  return (status & (1 << 2)) > 0;
784 }
INLINE void cam_lam_clear ( const int  c,
const int  n 
)

Definition at line 807 of file hyt1331.c.

References io_base.

808 {
809  unsigned int adr;
810 
811  /*
812  note that the LAM flip-flop in unit must be cleared via
813 
814  camc(c, n, 0, 10);
815 
816  in the user code prior to the call of cam_lam_clear()
817  */
818 
819  /* restart LAM scanner in controller */
820  adr = io_base[c >> 2] + ((c % 3) << 4);
821  INP(adr + 8);
822 }
INLINE void cam_lam_disable ( const int  c,
const int  n 
)

Definition at line 742 of file hyt1331.c.

References io_base.

743 {
744  /* disable the station number */
745  unsigned int adr;
746 
747  /* disable LAM in controller */
748  adr = io_base[c >> 2] + ((c % 3) << 4);
749  OUTP(adr + 10, 128 + n);
750 }
INLINE void cam_lam_enable ( const int  c,
const int  n 
)

Definition at line 730 of file hyt1331.c.

References io_base.

731 {
732  /* enable the station number */
733  unsigned int adr;
734 
735  /* enable LAM in controller */
736  adr = io_base[c >> 2] + ((c % 3) << 4);
737  OUTP(adr + 10, 64 + n);
738 }
INLINE void cam_lam_read ( const int  c,
DWORD lam 
)

Definition at line 788 of file hyt1331.c.

References io_base.

789 {
790  /*
791  return a BITWISE coded station NOT the station number
792  i.e.: n = 5 ==> lam = 0x10
793  */
794  unsigned int adr, csr;
795 
796  adr = io_base[c >> 2] + ((c % 3) << 4);
797  csr = (BYTE) INP(adr + 6);
798  if (csr & (1 << 3)) {
799  *lam = ((BYTE) INP(adr + 8)) & 0x1F; // mask upper 3 bits
800  *lam = 1 << (*lam - 1);
801  } else
802  *lam = 0;
803 }
INLINE void camc ( const int  c,
const int  n,
const int  a,
const int  f 
)

Definition at line 631 of file hyt1331.c.

References io_base.

Referenced by camc_chk(), camc_sa(), camc_sn(), lrs2249_bor1(), and lrs2249_read1().

632 {
633  unsigned int adr;
634 
635  adr = io_base[c >> 2] + ((c % 3) << 4);
636  OUTP(adr + 8, n);
637  OUTP(adr + 6, a);
638  OUTP(adr + 10, f);
639 }
INLINE int camc_chk ( const int  c)

Definition at line 610 of file hyt1331.c.

References camc(), and io_base.

611 {
612  unsigned int adr, n, a, f;
613 
614  /* clear inhibit */
615  camc(c, 1, 2, 32);
616 
617  /* read back naf */
618  adr = io_base[c >> 2] + ((c % 3) << 4);
619  a = (BYTE) INP(adr + 10);
620  n = (BYTE) INP(adr + 10);
621  f = (BYTE) INP(adr + 10);
622 
623  if (n != 1 || a != 2 || f != 32)
624  return -1;
625 
626  return 0;
627 }
INLINE void camc_q ( const int  c,
const int  n,
const int  a,
const int  f,
int *  q 
)

Definition at line 643 of file hyt1331.c.

References io_base, and status.

Referenced by lrs2249_read1().

644 {
645  unsigned int adr, status;
646 
647  adr = io_base[c >> 2] + ((c % 3) << 4);
648  OUTP(adr + 8, n);
649  OUTP(adr + 6, a);
650  OUTP(adr + 10, f);
651 
652  status = (BYTE) INP(adr + 6);
653  *q = status & 1;
654 }
INLINE void camc_sa ( const int  c,
const int  n,
const int  a,
const int  f,
const int  r 
)

Definition at line 658 of file hyt1331.c.

References camc(), and i.

659 {
660  int i;
661 
662  for (i = 0; i < r; i++)
663  camc(c, n, a + i, f);
664 }
INLINE void camc_sn ( const int  c,
const int  n,
const int  a,
const int  f,
const int  r 
)

Definition at line 668 of file hyt1331.c.

References camc(), and i.

669 {
670  int i;
671 
672  for (i = 0; i < r; i++)
673  camc(c, n + i, a, f);
674 }
INLINE void cami ( const int  c,
const int  n,
const int  a,
const int  f,
WORD d 
)

Definition at line 140 of file hyt1331.c.

References io_base, and status.

Referenced by cam16i(), cam16i_sa(), and lrs2249_read1().

141 {
142  WORD adr, status;
143 
144  adr = io_base[c >> 2] + ((c % 3) << 4);
145  OUTP(adr + 8, n);
146  OUTP(adr + 6, a);
147  OUTP(adr + 10, f);
148 
149  status = (BYTE) INP(adr + 6);
150  *((BYTE *) d) = INP(adr);
151  *(((BYTE *) d) + 1) = INP(adr + 2);
152 }
INLINE void camo ( const int  c,
const int  n,
const int  a,
const int  f,
WORD  d 
)

Definition at line 471 of file hyt1331.c.

References io_base.

Referenced by cam16o(), and s500_bor1().

472 {
473  unsigned int adr;
474 
475  adr = io_base[c >> 2] + ((c % 3) << 4);
476 
477  OUTP(adr + 8, n);
478  OUTP(adr, (BYTE) d);
479  OUTP(adr + 2, *(((BYTE *) & d) + 1));
480  OUTP(adr + 6, a);
481  OUTP(adr + 10, f);
482 }
void catch_sigsegv ( int  signo)

Definition at line 1045 of file hyt1331.c.

References printf().

Referenced by cam_init().

1046 {
1047  printf
1048  ("Cannot access ports. Please run with \"dio <prog>\" or compile with \"-DDO_IOPERM\"\n");
1049  signal(SIGSEGV, SIG_DFL);
1050 }
int directio_give_port ( DWORD  start,
DWORD  end 
)

Definition at line 835 of file hyt1331.c.

References printf(), and size.

Referenced by cam_init().

836 {
837 #ifdef _MSC_VER
838 
839  /* under Windows NT, use DirectIO driver to open ports */
840 
841  OSVERSIONINFO vi;
842  HANDLE hdio = 0;
843  DWORD buffer[] = { 6, 0, 0, 0 };
844  DWORD size;
845 
846  vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
847  GetVersionEx(&vi);
848 
849  /* use DirectIO driver under NT to gain port access */
850  if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
851  hdio = CreateFile("\\\\.\\directio", GENERIC_READ, FILE_SHARE_READ, NULL,
852  OPEN_EXISTING, 0, NULL);
853  if (hdio == INVALID_HANDLE_VALUE) {
854  printf("hyt1331.c: Cannot access IO ports (No DirectIO driver installed)\n");
855  return -1;
856  }
857 
858  /* open ports */
859  buffer[1] = start;
860  buffer[2] = end;
861  if (!DeviceIoControl(hdio, (DWORD) 0x9c406000, &buffer, sizeof(buffer),
862  NULL, 0, &size, NULL))
863  return -1;
864  }
865 
866  return 0;
867 
868 #elif defined(__linux__)
869 
870  /*
871  In order to access the IO ports of the CAMAC interface, one needs
872  to call the ioperm() function for those ports. This requires root
873  privileges. For normal operation, this is performed by the "dio"
874  program, which is a "setuid" program having temporarily root privi-
875  lege. So the user program is started with "dio <program>". Since the
876  program cannot be debugged through the dio program, we suplly here
877  the direct ioperm call which requires the program to be run as root,
878  making it possible to debug it. The program has then to be compiled
879  with "gcc -DDO_IOPERM -o <program> <program>.c hyt1331.c ..."
880  */
881 
882 #ifdef DO_IOPERM
883 
884  if (end <= 0x3FF) {
885  if (ioperm(start, end - start + 1, 1) < 0) {
886  printf("hyt1331.c: Cannot call ioperm() (no root privileges)\n");
887  return -1;
888  }
889  } else {
890  if (iopl(3) < 0) {
891  printf("hyt1331.c: Cannot call iopl() (no root privileges)\n");
892  return -1;
893  }
894  }
895 
896 #endif
897 
898  return 0;
899 
900 #else
901 #error This driver cannot be compiled under this operating system
902 #endif
903 }
int directio_lock_port ( DWORD  start,
DWORD  end 
)

Definition at line 907 of file hyt1331.c.

References printf(), and size.

Referenced by cam_exit(), and cam_init().

908 {
909 #ifdef _MSC_VER
910 
911  /* under Windows NT, use DirectIO driver to lock ports */
912 
913  OSVERSIONINFO vi;
914  HANDLE hdio;
915  DWORD buffer[] = { 7, 0, 0, 0 };
916  DWORD size;
917 
918  vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
919  GetVersionEx(&vi);
920 
921  /* use DirectIO driver under NT to gain port access */
922  if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
923  hdio = CreateFile("\\\\.\\directio", GENERIC_READ, FILE_SHARE_READ, NULL,
924  OPEN_EXISTING, 0, NULL);
925  if (hdio == INVALID_HANDLE_VALUE) {
926  printf("hyt1331.c: Cannot access IO ports (No DirectIO driver installed)\n");
927  return -1;
928  }
929 
930  /* lock ports */
931  buffer[1] = start;
932  buffer[2] = end;
933  if (!DeviceIoControl(hdio, (DWORD) 0x9c406000, &buffer, sizeof(buffer),
934  NULL, 0, &size, NULL))
935  return -1;
936  }
937 
938  return 0;
939 
940 #elif defined(__linux__)
941 
942 #ifdef DO_IOPERM
943 
944  if (end <= 0x3FF) {
945  if (ioperm(start, end - start + 0, 0) < 0) {
946  printf("hyt1331.c: Cannot call ioperm() (no root privileges)\n");
947  return -1;
948  }
949  } else {
950  if (iopl(0) < 0) {
951  printf("hyt1331.c: Cannot call iopl() (no root privileges)\n");
952  return -1;
953  }
954  }
955 
956 #endif
957 
958  return 0;
959 
960 #endif
961 }
int pci_scan ( int  vendor_id,
int  device_id,
int  n_dev,
BYTE *  pirq,
DWORD ba 
)

Definition at line 965 of file hyt1331.c.

References irq, printf(), and size.

Referenced by cam_init().

966 {
967 #ifdef __linux__
968 
969  FILE *f;
970  char line[1000];
971  int n;
972  DWORD base_addr[6], irq, dfn, vend, vend_id, dev_id;
973 
974  f = fopen("/proc/bus/pci/devices", "r");
975  if (f == NULL)
976  return 0;
977 
978  n = 0;
979  while (fgets(line, sizeof(line), f)) {
980  sscanf(line, "%x %x %x %lx %lx %lx %lx %lx %lx",
981  &dfn,
982  &vend,
983  &irq,
984  &base_addr[0],
985  &base_addr[1], &base_addr[2], &base_addr[3], &base_addr[4], &base_addr[5]);
986 
987  vend_id = vend >> 16U;
988  dev_id = vend & 0xFFFF;
989 
990  /*
991  printf("%x:%x %d %x %x %x %x\n", vend_id, dev_id, *irq, base_addr[0], base_addr[1],
992  base_addr[2], base_addr[3]);
993  */
994 
995  if (vend_id == vendor_id && dev_id == device_id)
996  n++;
997 
998  if (n == n_dev)
999  break;
1000  }
1001 
1002  fclose(f);
1003 
1004  if (n == n_dev) {
1005  *pirq = irq;
1006  memcpy(ba, base_addr, sizeof(base_addr));
1007  return 1;
1008  }
1009 
1010  return 0;
1011 
1012 #elif defined(_MSC_VER)
1013 
1014  DWORD buffer[] = { 8, 0, 0, 0 };
1015  DWORD retbuf[7];
1016  HANDLE hdio;
1017  int size;
1018 
1019  hdio = CreateFile("\\\\.\\directio", GENERIC_READ, FILE_SHARE_READ, NULL,
1020  OPEN_EXISTING, 0, NULL);
1021  if (hdio == INVALID_HANDLE_VALUE) {
1022  printf("hyt1331.c: Cannot access DirectIO driver\n");
1023  return -1;
1024  }
1025 
1026  buffer[1] = vendor_id;
1027  buffer[2] = device_id;
1028  buffer[3] = n_dev + 1;
1029  if (!DeviceIoControl(hdio, (DWORD) 0x9c406000, &buffer, sizeof(buffer),
1030  retbuf, sizeof(retbuf), &size, NULL))
1031  return 0;
1032 
1033  if (size == 0)
1034  return 0;
1035 
1036  *pirq = (BYTE) retbuf[0];
1037  memcpy(ba, retbuf + 1, sizeof(DWORD) * 6);
1038  return 1;
1039 
1040 #endif
1041 }

Variable Documentation

int gbl_sw1d[MAX_DEVICES]

Definition at line 121 of file hyt1331.c.

Referenced by cam16i_sa(), cam24i_sa(), and cam_init().

WORD io_base[MAX_DEVICES]
BYTE irq[MAX_DEVICES]