source: trunk/third/xntp/xntpd/map_vme.c @ 10832

Revision 10832, 3.7 KB checked in by brlewis, 27 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r10831, which included commits to RCS files with non-trunk default branches.
Line 
1/********************************************************/
2/*  map_vme.c                                           */
3/*  VME control of TrueTime VME-SG sync gen  card       */
4/*  and  TrueTime GPS-VME      receiver card            */
5/* Version for 700 series HPUX 9.0                      */
6/* Richard E.Schmidt, US Naval Observatory, Washington  */
7/*  27 March 94                                         */
8/********************************************************/
9
10#ifdef HAVE_CONFIG_H
11# include <config.h>
12#endif
13
14#if defined(REFCLOCK) && defined(GPSVME)
15#include <stdio.h>
16#include <errno.h>
17#include <time.h>
18#include <sys/types.h>
19#include <fcntl.h>
20#include <sys/file.h>
21#include <sys/ioctl.h>
22#include <sys/types.h>
23#include <sys/stat.h>
24#include <sys/sysmacros.h>
25#include <sys/rtprio.h> /* for rtprio */
26#include <sys/lock.h> /* for plock */
27#include "/etc/conf/machine/vme2.h"
28#include "/etc/conf/h/io.h"
29#include "gps.h"
30
31/* GLOBALS */
32void *gps_base;
33unsigned short  *greg[NREGS];
34struct vme2_map_addr ma;           /* memory mapped structure */
35int fd;                            /* file descriptor for VME */
36
37void unmap_vme ();
38
39caddr_t map_vme (filename)
40char *filename;
41{
42        int ret;
43        caddr_t base;
44        struct vme2_io_testx tx;
45        caddr_t cp;
46
47#define VME_START_ADDR  0x00000   /* Starting address in A16N VME Space */
48#define VMESIZE 0xFF      /* 256 bytes of A16N space length */
49
50/*
51 To create the HP9000/700 series device file, /dev/vme2:
52 mknod /dev/vme2 c 44 0x0; chmod 600 /dev/vme2
53
54 Then must create /etc/vme.CFG and run /etc/vme_config and reboot.
55*/
56        if ((fd = open (filename, O_RDWR)) < 0) {
57                printf("ERROR: VME bus adapter open failed. errno:%d\n",
58                        errno);
59                if(errno == ENODEV) {
60                  printf("ENODEV. Is driver in kernel? vme2 in dfile?\n");
61                  }
62                  exit(errno);
63        }
64        tx.card_type = VME_A16;
65        tx.vme_addr = VME_START_ADDR;
66        tx.width = SHORT_WIDE;
67
68        if(ioctl(fd, VME2_IO_TESTR, &tx)) {
69                printf("ioctl to test VME space failed. Errno: %d\n",
70                        errno);
71                exit(errno);
72        }
73        if(tx.error)
74                printf("io_testr failed internal error %d\n",tx.error);
75        if(tx.access_result <= 0) {
76                printf("io_testr failed\n");
77                exit(2);
78                }
79
80/* If successful mmap the device */
81/* NOW MAP THE CARD  */
82        ma.card_type = VME_A16;
83        ma.vme_addr = VME_START_ADDR;
84        ma.size = VMESIZE;
85
86        if(ioctl(fd, VME2_MAP_ADDR, &ma)) {
87                printf("ioctl to map VME space failed. Errno: %d\n",
88                        errno);
89                exit(errno);
90        }
91        if(ma.error) {
92                printf("ioctl to map VME failed\n");
93                exit(ENOMEM);
94        }
95        base = ma.user_addr;
96        return(base);   
97}
98
99
100void unmap_vme()
101{
102        if(ioctl(fd, VME2_UNMAP_ADDR, &ma))
103                printf("ioctl to unmap VME space failed. Errno: %d\n",
104                        errno);
105        close(fd);
106        return;
107}
108
109
110int init_vme()
111{
112/*  set up address offsets */
113
114        gps_base = map_vme (GPS_VME);
115
116/* offsets from base address: */
117
118        greg[0] =  (unsigned short *)gps_base + GFRZ1;
119        greg[1] = (unsigned short *)gps_base + GUFRZ1;
120        greg[2] = (unsigned short *)gps_base + GREG1A;
121        greg[3] = (unsigned short  *)gps_base + GREG1B;
122        greg[4] = (unsigned short  *)gps_base + GREG1C;
123        greg[5] = (unsigned short  *)gps_base + GREG1D;
124        greg[6] = (unsigned short  *)gps_base + GREG1E;
125
126        return (0);
127}
128
129#else /* not (REFCLOCK && GPSVME) */
130int map_vme_bs;
131#endif /* not (REFCLOCK && GPSVME) */
Note: See TracBrowser for help on using the repository browser.