Subversion Repositories f9daq

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
86 f9daq 1
//****************************************************************************
2
// Copyright (C) 2000-2004  ARW Elektronik Germany
3
//
4
//
5
// This program is free software; you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation; either version 2 of the License, or
8
// (at your option) any later version.
9
//
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with this program; if not, write to the Free Software
17
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
//
19
// This product is not authorized for use as critical component in 
20
// life support systems without the express written approval of 
21
// ARW Elektronik Germany.
22
//  
23
// Please announce changes and hints to ARW Elektronik
24
//
25
// Maintainer(s): Klaus Hitschler (klaus.hitschler@gmx.de)
26
//
27
//****************************************************************************
28
 
29
//****************************************************************************
30
//
31
// pcicc32_test.c -- a program to test some features of the PCICC32 PCI to 
32
//                   CAMAC Interface
33
//
34
// $Log: pcicc32_test.c,v $
35
// Revision 1.6  2004/08/12 20:00:09  klaus
36
// conversion to kernel-version 2.6, released version 6.0
37
//
38
// Revision 1.5  2002/04/17 18:57:33  klaus
39
// last changes to release 4.4
40
//
41
// Revision 1.4  2002/04/14 18:25:38  klaus
42
// added interrupt handling, driver 4.4. ...3.5.tar.gz
43
//
44
// Revision 1.3  2001/11/20 20:12:50  klaus
45
// included new header and CVS log
46
//
47
//
48
// first steps                                                 AR   26.02.2000
49
// default device changed to number 1                          AR   14.04.2000
50
//
51
//****************************************************************************
52
 
53
#define DEVICE_NAME "/dev/cc32_1"
54
 
55
#include <stdio.h>
56
#include <stdlib.h>
57
#include <string.h>
58
#include <unistd.h>
59
#include <sys/mman.h>
60
#include <errno.h>
61
#include <ctype.h>
62
 
63
#include "../lib/libcc32.h" /* the header of the shared library */
64
 
65
char *cszPrgName;
66
CC32_HANDLE handle;
67
 
68
void hlpMsg(void)
69
{
70
    printf("pcicc32_test - a program to test some features of the PCICC32 interface of ARW Elektronik Germany.\n");
71
    printf("Copyright see the GPL of the free software foundation. K.Hitschler, %s.\n", __DATE__);
72
    printf("usage: pcicc32_test [-d=device_name] [-?]\n");
73
    printf("                     -d - choose a device to use. (Default: %s)\n", DEVICE_NAME);
74
    printf("                     -? - this help.\n");  
75
}
76
 
77
int main(int argc, char **argv)
78
{
79
    char *fname = DEVICE_NAME;
80
    char *ptr;
81
    char ch;
82
    int i;
83
    int error;
84
    int nTimeout, nLam;
85
    int k, j;
86
 
87
 
88
    cszPrgName = argv[0];
89
    for (i = 1; i < argc; i++)
90
    {
91
        ptr = argv[i];
92
            if (*ptr == '-') ptr++;
93
            ch = *ptr;
94
            ptr++;
95
            if (*ptr == '=') ptr++;
96
            switch (tolower(ch))
97
            {
98
                    case '?': hlpMsg(); exit(0);
99
                    case 'd': fname = ptr; break;
100
                    default:  printf("%s : Unknown command ?%c?!\n", cszPrgName, ch); exit(0); 
101
            }
102
 
103
            if (!fname) printf("%s : Must have devicename!\n", cszPrgName);
104
    }
105
 
106
 
107
    if ((error = cc32_open(fname, &handle)))
108
    {
109
        fprintf(stderr, "%s: %s: %s\n", cszPrgName, fname, strerror(error));
110
        exit(1);
111
    }
112
    else
113
        printf("%s: open done.\n", cszPrgName);
114
 
115
    for (k = 0; k < 1; k++)
116
    {
117
            for (j = 0; j < 0x00FFFFFF; j++)
118
            {    
119
                    cc32_write_long(handle, 1 + (j % 23), (j % 15), 16 + (j % 15), j);
120
            }
121
    }
122
 
123
    // poll the event
124
    error = cc32_poll_event(handle, &nTimeout, &nLam);
125
    printf("%s : bConnected = %d, bFail = %d, bIrq = %d\n", cszPrgName, error, nTimeout, nLam);
126
 
127
    // enable all LAM mask bits for this test    
128
    cc32_write_long(handle, 28, 1, 16, 0x00FFFFFF);
129
    // enable interrupts
130
    error = cc32_interrupt_enable(handle);
131
 
132
    // generate a LAM interrupt with help of the test mode bits
133
    cc32_write_long(handle, 24, 0, 16, 5);
134
 
135
    // wait for a event 
136
    error = cc32_wait_event(handle, &nTimeout, &nLam);
137
    printf("%s : bConnected = %d, bFail = %d, bIrq = %d\n", cszPrgName, error, nTimeout, nLam);
138
 
139
    if (nLam)
140
    {
141
      // clear LAM
142
      cc32_write_word(handle, 28, 0, 16, 0);
143
    }
144
 
145
    // wait again for a event (which never comes)
146
    error = cc32_wait_event(handle, &nTimeout, &nLam);
147
    printf("%s : bConnected = %d, bFail = %d, bIrq = %d\n", cszPrgName, error, nTimeout, nLam);
148
 
149
 
150
    cc32_close(handle);;
151
 
152
    printf("%s: close done.\n", cszPrgName);
153
 
154
    return 0;
155
}