Subversion Repositories f9daq

Rev

Rev 21 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21 f9daq 1
/*
2
   cc32lib.c -- a simple access library for the PCICC32 PCI to CAMAC Interface from ARW Elektronik
3
 
4
   (c) 2000 ARW Elektronik
5
 
6
   this source code is published under GPL (Open Source). You can use, redistrubute and
7
   modify it unless this header   is not modified or deleted. No warranty is given that
8
   this software will work like expected.
9
   This product is not authorized for use as critical component in life support systems
10
   wihout the express written approval of ARW Elektronik Germany.
11
 
12
   Please announce changes and hints to ARW Elektronik
13
 
14
   first steps derived from the LINUX pcicc32 library                   AR   16.03.2000
15
   new architecture - added WINNT to DLL                                AR   30.07.2000
16
   added buffer, UNTIL_NOT_Q and AUTOREAD functionality                 AR   17.03.2001
17
   added interrupt handling                                             AR   08.06.2002
18
*/
19
 
20
/*--- INCLUDES -----------------------------------------------------------------------------------*/
21
#include <windows.h>
22
#include <stdio.h>
23
#include <stdlib.h>
24
#include <string.h>
25
#include <errno.h>
26
 
27
#include "os_info.h"      /* to determine the underlaying OS                                      */
28
#include "libcc32_95.h"   /* the win95 + 98 parts                                                 */
29
#include "libcc32_NT.h"   /* the winnt part                                                       */
30
#include "libcc32.h"      /* shared header bewteen applictaion and library                        */
31
 
32
/*--- DEFINES ------------------------------------------------------------------------------------*/
33
 
34
/*--- EXTERNALS ----------------------------------------------------------------------------------*/
35
 
36
/*--- TYPEDEFS -----------------------------------------------------------------------------------*/
37
typedef struct
38
{
39
        int            (*cc32_open)(char *cszPath, int nModuleNumber, void **handle);
40
        int            (*cc32_close)(void *handle);
41
        unsigned short (*cc32_read_word)(void *handle, unsigned int N, unsigned int A, unsigned int F);
42
        unsigned long  (*cc32_read_long)(void *handle, unsigned int N, unsigned int A, unsigned int F, char *Q, char *X);
43
        unsigned long  (*cc32_read_long_all)(void *handle, unsigned int N, unsigned int A, unsigned int F);
44
        void           (*cc32_write_word)(void *handle, unsigned int N, unsigned int A, unsigned int F, unsigned short uwData);
45
        void           (*cc32_write_long)(void *handle, unsigned int N, unsigned int A, unsigned int F, unsigned long ulData);
46
        int            (*cc32_poll_error)(void *handle, char *nTimeout, char *nLam);
47
        int            (*cc32_read_word_buffer)(void * handle, unsigned int N, unsigned int A, unsigned int F, unsigned short *pwBuffer, unsigned long *pdwLen);
48
        int            (*cc32_read_long_buffer)(void * handle, unsigned int N, unsigned int A, unsigned int F, unsigned long *pdwBuffer, unsigned long *pdwLen);
49
        int            (*cc32_read_long_all_buffer)(void * handle, unsigned int N, unsigned int A, unsigned int F, unsigned long *pdwBuffer, unsigned long *pdwLen);
50
        int            (*cc32_access_switch)(void *handle, unsigned short uwSwitch);
51
        int            (*cc32_enable_interrupt)(void *handle);
52
        int            (*cc32_disable_interrupt)(void *handle);
53
        int            (*cc32_get_interrupt)(void *handle, unsigned long *dwStatus);
54
} MY_ACTIONS;
55
 
56
/*--- GLOBALS ------------------------------------------------------------------------------------*/
57
MY_ACTIONS  ma;
58
static BOOLEAN firstime = TRUE;
59
 
60
/*--- FUNCTIONS -----------------------------------------------------------------------*/
61
 
62
//--------------------------------------------------------------------------------------
63
// open the device
64
//
65
int __declspec(dllexport) cc32_open(char *cszPath, int nModuleNumber, CC32_HANDLE *handle)
66
{
67
        if (firstime)
68
        {
69
                if (IsWindowsNT())
70
                {
71
                        ma.cc32_open                                            = cc32_open_NT;
72
                        ma.cc32_close                                           = cc32_close_NT;
73
                        ma.cc32_read_word                                       = cc32_read_word_NT;
74
                        ma.cc32_read_long                                       = cc32_read_long_NT;
75
                        ma.cc32_read_long_all                           = cc32_read_long_all_NT;
76
                        ma.cc32_write_word                                      = cc32_write_word_NT;
77
                        ma.cc32_write_long                                      = cc32_write_long_NT;
78
                        ma.cc32_poll_error                                      = cc32_poll_error_NT;
79
                        ma.cc32_read_word_buffer                        = cc32_read_word_buffer_NT;
80
                        ma.cc32_read_long_buffer                        = cc32_read_long_buffer_NT;
81
                        ma.cc32_read_long_all_buffer            = cc32_read_long_all_buffer_NT;
82
                        ma.cc32_access_switch                           = cc32_access_switch_NT;
83
                        ma.cc32_enable_interrupt            = cc32_enable_interrupt_NT;
84
                        ma.cc32_disable_interrupt           = cc32_disable_interrupt_NT;
85
                        ma.cc32_get_interrupt               = cc32_get_interrupt_NT;
86
                }
87
                else
88
                        if (IsWindows95() || IsWindows98())
89
                        {
90
                                ma.cc32_open                                            = cc32_open_95;
91
                                ma.cc32_close                                           = cc32_close_95;
92
                                ma.cc32_read_word                                       = cc32_read_word_95;
93
                                ma.cc32_read_long                                       = cc32_read_long_95;
94
                                ma.cc32_read_long_all                           = cc32_read_long_all_95;
95
                                ma.cc32_write_word                                      = cc32_write_word_95;
96
                                ma.cc32_write_long                                      = cc32_write_long_95;
97
                                ma.cc32_poll_error                                      = cc32_poll_error_95;
98
                                ma.cc32_read_word_buffer                        = cc32_read_word_buffer_95;
99
                                ma.cc32_read_long_buffer                        = cc32_read_long_buffer_95;
100
                                ma.cc32_read_long_all_buffer            = cc32_read_long_all_buffer_95;
101
                                ma.cc32_access_switch                           = cc32_access_switch_95;
102
                                ma.cc32_enable_interrupt            = cc32_enable_interrupt_95;
103
                                ma.cc32_disable_interrupt           = cc32_disable_interrupt_95;
104
                                ma.cc32_get_interrupt               = cc32_get_interrupt_95;
105
                        }
106
                        else
107
                                return -1;
108
 
109
                firstime = FALSE;
110
        }
111
 
112
        return ma.cc32_open(cszPath, nModuleNumber, (CC32_HANDLE *)handle);
113
}
114
 
115
//--------------------------------------------------------------------------------------
116
// close the device
117
//
118
int __declspec(dllexport) cc32_close(CC32_HANDLE handle)
119
{
120
        return ma.cc32_close((CC32_HANDLE)handle);
121
}
122
 
123
//--------------------------------------------------------------------------------------
124
// read a word
125
//
126
unsigned short __declspec(dllexport) cc32_read_word(CC32_HANDLE handle, unsigned int N, unsigned int A, unsigned int F)
127
{
128
        return ma.cc32_read_word((CC32_HANDLE) handle, N, A, F);
129
}
130
 
131
//--------------------------------------------------------------------------------------
132
// read a long
133
//
134
unsigned long __declspec(dllexport) cc32_read_long_all(CC32_HANDLE handle, unsigned int N, unsigned int A, unsigned int F)
135
{
136
        return ma.cc32_read_long_all((CC32_HANDLE) handle, N, A, F);
137
}
138
 
139
//--------------------------------------------------------------------------------------
140
// read a long and get Q and X
141
//
142
unsigned long __declspec(dllexport) cc32_read_long(CC32_HANDLE handle, unsigned int N, unsigned int A, unsigned int F, char *Q, char *X)
143
{
144
        return ma.cc32_read_long((CC32_HANDLE) handle, N, A, F, Q, X);
145
}
146
 
147
//--------------------------------------------------------------------------------------
148
// write a word
149
//
150
void __declspec(dllexport) cc32_write_word(CC32_HANDLE handle, unsigned int N, unsigned int A, unsigned int F, unsigned short uwData)
151
{
152
        ma.cc32_write_word((CC32_HANDLE) handle, N, A, F, uwData);
153
}
154
 
155
//--------------------------------------------------------------------------------------
156
// write a long
157
//
158
void __declspec(dllexport) cc32_write_long(CC32_HANDLE handle, unsigned int N, unsigned int A, unsigned int F, unsigned long ulData)
159
{
160
        ma.cc32_write_long((CC32_HANDLE) handle, N, A, F, ulData);
161
}
162
 
163
//--------------------------------------------------------------------------------------
164
// read and clear the PCIADA status
165
//
166
int __declspec(dllexport) cc32_poll_error(CC32_HANDLE handle, char *nTimeout, char *nLam)
167
{
168
        return ma.cc32_poll_error((CC32_HANDLE) handle, nTimeout, nLam);
169
}
170
 
171
//--------------------------------------------------------------------------------------
172
// read 'len' words or 'UNTIL_NOT_Q' from a address made out of N,A,F into a buffer
173
//
174
int __declspec(dllexport) cc32_read_word_buffer(CC32_HANDLE handle, unsigned int N, unsigned int A, unsigned int F,
175
                                                                                                                                unsigned short *pwBuffer, unsigned long *pdwLen)
176
{
177
        return ma.cc32_read_word_buffer(handle, N, A, F, pwBuffer, pdwLen);
178
}
179
 
180
//--------------------------------------------------------------------------------------
181
// read 'len' longs or 'UNTIL_NOT_Q' from a address made out of N,A,F into a buffer, mask 24 bits out
182
//
183
int __declspec(dllexport) cc32_read_long_buffer(CC32_HANDLE handle, unsigned int N, unsigned int A, unsigned int F,
184
                                                                                                                                unsigned long *pdwBuffer, unsigned long *pdwLen)
185
{
186
        return ma.cc32_read_long_buffer(handle, N, A, F, pdwBuffer, pdwLen);
187
}
188
 
189
//--------------------------------------------------------------------------------------
190
// read 'len' longs or 'UNTIL_NOT_Q' from a address made out of N,A,F into a buffer, without interpretation 
191
//
192
int __declspec(dllexport) cc32_read_long_all_buffer(CC32_HANDLE handle, unsigned int N, unsigned int A, unsigned int F,
193
                                                                                                                                unsigned long *pdwBuffer, unsigned long *pdwLen)
194
{
195
        return ma.cc32_read_long_all_buffer(handle, N, A, F, pdwBuffer, pdwLen);
196
}
197
 
198
//--------------------------------------------------------------------------------------
199
// set the accessmode for the path, e.g. UNTIL_NOT_Q or AUTOREAD or ... 
200
//
201
int __declspec(dllexport) cc32_access_switch(CC32_HANDLE handle, unsigned short uwSwitch)
202
{
203
        return ma.cc32_access_switch(handle, uwSwitch);
204
}
205
 
206
//--------------------------------------------------------------------------------------
207
// switch interrupts on
208
//
209
int __declspec(dllexport) cc32_enable_interrupt(CC32_HANDLE handle)
210
{
211
        return ma.cc32_enable_interrupt(handle);
212
}
213
 
214
//--------------------------------------------------------------------------------------
215
// switch interrupts off
216
//
217
int __declspec(dllexport) cc32_disable_interrupt(CC32_HANDLE handle)
218
{
219
        return ma.cc32_disable_interrupt(handle);
220
}
221
 
222
//--------------------------------------------------------------------------------------
223
// wait blocking for the next interrupt
224
//
225
int __declspec(dllexport) cc32_get_interrupt(CC32_HANDLE handle, unsigned long *dwStatus)
226
{
227
        return ma.cc32_get_interrupt(handle, dwStatus);
228
}