summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/ntpd/map_vme.c
blob: 3c161cc91450e9f16223f11136be69983043650e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/********************************************************/
/*  map_vme.c                                           */
/*  VME control of TrueTime VME-SG sync gen  card       */
/*  and  TrueTime GPS-VME      receiver card            */
/* Version for 700 series HPUX 9.0                      */
/* Richard E.Schmidt, US Naval Observatory, Washington  */
/*  27 March 94                                         */
/********************************************************/

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#if defined(REFCLOCK) && defined(CLOCK_GPSVME)
#include <stdio.h>
#include <errno.h>
#include <time.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/types.h> 
#include <sys/stat.h> 
#include <sys/sysmacros.h> 
#include <sys/rtprio.h>		/* for rtprio */
#include <sys/lock.h>		/* for plock */
#include "/etc/conf/machine/vme2.h"
#include "/etc/conf/h/io.h"
#include "gps.h"

/* GLOBALS */
void *gps_base;
unsigned short  *greg[NREGS];
struct vme2_map_addr ma;           /* memory mapped structure */
int fd;                            /* file descriptor for VME */

void unmap_vme (); 

caddr_t
map_vme (
	char *filename
	)
{
	int ret; 
	caddr_t base;
	struct vme2_io_testx tx;
	caddr_t cp;

#define VME_START_ADDR  0x00000   /* Starting address in A16N VME Space */
#define VMESIZE 0xFF      /* 256 bytes of A16N space length */

	/* 
	   To create the HP9000/700 series device file, /dev/vme2:
	   mknod /dev/vme2 c 44 0x0; chmod 600 /dev/vme2

	   Then must create /etc/vme.CFG and run /etc/vme_config and reboot.
	*/
	if ((fd = open (filename, O_RDWR)) < 0) {
		printf("ERROR: VME bus adapter open failed. errno:%d\n",
		       errno);
		if(errno == ENODEV) {
			printf("ENODEV. Is driver in kernel? vme2 in dfile?\n");
		}
		exit(errno);
	}
	tx.card_type = VME_A16;
	tx.vme_addr = VME_START_ADDR;
	tx.width = SHORT_WIDE;

	if(ioctl(fd, VME2_IO_TESTR, &tx)) {
		printf("ioctl to test VME space failed. Errno: %d\n",
		       errno);
		exit(errno);
	}
	if(tx.error)
	    printf("io_testr failed internal error %d\n",tx.error);
	if(tx.access_result <= 0) {
		printf("io_testr failed\n");
		exit(2);
	}

	/* If successful mmap the device */
	/* NOW MAP THE CARD  */
	ma.card_type = VME_A16;
	ma.vme_addr = VME_START_ADDR;
	ma.size = VMESIZE;

	if(ioctl(fd, VME2_MAP_ADDR, &ma)) {
		printf("ioctl to map VME space failed. Errno: %d\n",
		       errno);
		exit(errno);
	}
	if(ma.error) {
		printf("ioctl to map VME failed\n");
		exit(ENOMEM);
	}
	base = ma.user_addr;
	return(base);   
}


void
unmap_vme(void)
{
	if(ioctl(fd, VME2_UNMAP_ADDR, &ma)) 
	    printf("ioctl to unmap VME space failed. Errno: %d\n",
		   errno);
	close(fd);
	return;
}


int
init_vme(boid)
{
	/*  set up address offsets */

	gps_base = map_vme (GPS_VME);

/* offsets from base address: */

	greg[0] = (unsigned short *)gps_base + GFRZ1;
	greg[1] = (unsigned short *)gps_base + GUFRZ1;
	greg[2] = (unsigned short *)gps_base + GREG1A;
	greg[3] = (unsigned short *)gps_base + GREG1B;
	greg[4] = (unsigned short *)gps_base + GREG1C;
	greg[5] = (unsigned short *)gps_base + GREG1D;
	greg[6] = (unsigned short *)gps_base + GREG1E;

	return (0); 
}

#else /* not (REFCLOCK && CLOCK_GPSVME) */
int map_vme_bs;
#endif /* not (REFCLOCK && CLOCK_GPSVME) */
OpenPOWER on IntegriCloud