~ubuntu-branches/debian/squeeze/ntp/squeeze-201010051545

« back to all changes in this revision

Viewing changes to ntpd/map_vme.c

  • Committer: Bazaar Package Importer
  • Author(s): Matt Zimmerman
  • Date: 2004-10-11 16:10:27 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041011161027-icyjbji8ujym633o
Tags: 1:4.2.0a-10ubuntu2
Use ntp.ubuntulinux.org instead of pool.ntp.org

Show diffs side-by-side

added added

removed removed

Lines of Context:
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(CLOCK_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 */
32
 
void *gps_base;
33
 
unsigned short  *greg[NREGS];
34
 
struct vme2_map_addr ma;           /* memory mapped structure */
35
 
int fd;                            /* file descriptor for VME */
36
 
 
37
 
void unmap_vme (); 
38
 
 
39
 
caddr_t
40
 
map_vme (
41
 
        char *filename
42
 
        )
43
 
{
44
 
        int ret; 
45
 
        caddr_t base;
46
 
        struct vme2_io_testx tx;
47
 
        caddr_t cp;
48
 
 
49
 
#define VME_START_ADDR  0x00000   /* Starting address in A16N VME Space */
50
 
#define VMESIZE 0xFF      /* 256 bytes of A16N space length */
51
 
 
52
 
        /* 
53
 
           To create the HP9000/700 series device file, /dev/vme2:
54
 
           mknod /dev/vme2 c 44 0x0; chmod 600 /dev/vme2
55
 
 
56
 
           Then must create /etc/vme.CFG and run /etc/vme_config and reboot.
57
 
        */
58
 
        if ((fd = open (filename, O_RDWR)) < 0) {
59
 
                printf("ERROR: VME bus adapter open failed. errno:%d\n",
60
 
                       errno);
61
 
                if(errno == ENODEV) {
62
 
                        printf("ENODEV. Is driver in kernel? vme2 in dfile?\n");
63
 
                }
64
 
                exit(errno);
65
 
        }
66
 
        tx.card_type = VME_A16;
67
 
        tx.vme_addr = VME_START_ADDR;
68
 
        tx.width = SHORT_WIDE;
69
 
 
70
 
        if(ioctl(fd, VME2_IO_TESTR, &tx)) {
71
 
                printf("ioctl to test VME space failed. Errno: %d\n",
72
 
                       errno);
73
 
                exit(errno);
74
 
        }
75
 
        if(tx.error)
76
 
            printf("io_testr failed internal error %d\n",tx.error);
77
 
        if(tx.access_result < 0) {
78
 
                printf("io_testr failed\n");
79
 
                exit(2);
80
 
        }
81
 
 
82
 
        /* If successful mmap the device */
83
 
        /* NOW MAP THE CARD  */
84
 
        ma.card_type = VME_A16;
85
 
        ma.vme_addr = VME_START_ADDR;
86
 
        ma.size = VMESIZE;
87
 
 
88
 
        if(ioctl(fd, VME2_MAP_ADDR, &ma)) {
89
 
                printf("ioctl to map VME space failed. Errno: %d\n",
90
 
                       errno);
91
 
                exit(errno);
92
 
        }
93
 
        if(ma.error) {
94
 
                printf("ioctl to map VME failed\n");
95
 
                exit(ENOMEM);
96
 
        }
97
 
        base = ma.user_addr;
98
 
        return(base);   
99
 
}
100
 
 
101
 
 
102
 
void
103
 
unmap_vme(void)
104
 
{
105
 
        if(ioctl(fd, VME2_UNMAP_ADDR, &ma)) 
106
 
            printf("ioctl to unmap VME space failed. Errno: %d\n",
107
 
                   errno);
108
 
        close(fd);
109
 
        return;
110
 
}
111
 
 
112
 
 
113
 
int
114
 
init_vme(boid)
115
 
{
116
 
        /*  set up address offsets */
117
 
 
118
 
        gps_base = map_vme (GPS_VME);
119
 
 
120
 
/* offsets from base address: */
121
 
 
122
 
        greg[0] = (unsigned short *)gps_base + GFRZ1;
123
 
        greg[1] = (unsigned short *)gps_base + GUFRZ1;
124
 
        greg[2] = (unsigned short *)gps_base + GREG1A;
125
 
        greg[3] = (unsigned short *)gps_base + GREG1B;
126
 
        greg[4] = (unsigned short *)gps_base + GREG1C;
127
 
        greg[5] = (unsigned short *)gps_base + GREG1D;
128
 
        greg[6] = (unsigned short *)gps_base + GREG1E;
129
 
 
130
 
        return (0); 
131
 
}
132
 
 
133
 
#else /* not (REFCLOCK && CLOCK_GPSVME) */
134
 
int map_vme_bs;
135
 
#endif /* not (REFCLOCK && CLOCK_GPSVME) */