source: drsdaq/VME/struck/mvmestd.h@ 22

Last change on this file since 22 was 22, checked in by ogrimm, 16 years ago
First commit of drsdaq program
File size: 11.7 KB
Line 
1/*********************************************************************
2
3 Name: mvmestd.h
4 Created by: Stefan Ritt
5
6 Cotents: Midas VME standard routines (MVMESTD) supplying an
7 abstract layer to all supported VME interfaces.
8
9 $Id: mvmestd.h 3783 2007-07-30 16:03:49Z ritt@PSI.CH $
10
11*********************************************************************/
12
13#ifndef MVMESTD_H
14#define MVMESTD_H
15
16/**dox***************************************************************/
17/** @file mvmestd.h
18The Midas VME include file
19*/
20
21/** @defgroup mvmestdinclude Midas VME standard
22 */
23/** @defgroup mvmestdfunctionh VME Functions (mvme_xxx)
24 */
25
26/**dox***************************************************************/
27/** @addtogroup mvmestdinclude
28 *
29 * @{ */
30
31/**dox***************************************************************/
32#ifndef DOXYGEN_SHOULD_SKIP_THIS
33
34/*---- replacements if not running under MIDAS ---------------------*/
35
36#ifndef MIDAS_TYPE_DEFINED
37#define MIDAS_TYPE_DEFINED
38
39typedef unsigned short int WORD;
40
41#ifndef _MSC_VER
42typedef unsigned int DWORD;
43#endif
44
45#define SUCCESS 1
46
47#endif /* MIDAS_TYPE_DEFINED */
48
49/* make functions under WinNT dll exportable */
50#if defined(_MSC_VER) && defined(MIDAS_DLL)
51#define EXPRT __declspec(dllexport)
52#else
53#define EXPRT
54#endif
55
56/**dox***************************************************************/
57#endif /* DOXYGEN_SHOULD_SKIP_THIS */
58
59/*---- status codes ------------------------------------------------*/
60
61#define MVME_SUCCESS 1
62#define MVME_NO_INTERFACE 2
63#define MVME_NO_CRATE 3
64#define MVME_UNSUPPORTED 4
65#define MVME_INVALID_PARAM 5
66#define MVME_NO_MEM 6
67#define MVME_ACCESS_ERROR 7
68
69/*---- types -------------------------------------------------------*/
70
71typedef unsigned int mvme_addr_t;
72typedef unsigned int mvme_locaddr_t;
73typedef unsigned int mvme_size_t;
74
75/*---- constants ---------------------------------------------------*/
76
77/**
78data modes
79*/
80#define MVME_DMODE_D8 1 /**< D8 */
81#define MVME_DMODE_D16 2 /**< D16 */
82#define MVME_DMODE_D32 3 /**< D32 */
83#define MVME_DMODE_D64 4 /**< D64 */
84#define MVME_DMODE_RAMD16 5 /**< RAM memory of VME adapter */
85#define MVME_DMODE_RAMD32 6 /**< RAM memory of VME adapter */
86#define MVME_DMODE_LM 7 /**< local memory mapped to VME */
87
88#define MVME_DMODE_DEFAULT MVME_DMODE_D32
89
90/* block transfer modes */
91
92#define MVME_BLT_NONE 1 /**< normal programmed IO */
93#define MVME_BLT_BLT32 2 /**< 32-bit block transfer */
94#define MVME_BLT_MBLT64 3 /**< multiplexed 64-bit block transfer */
95#define MVME_BLT_2EVME 4 /**< two edge block transfer */
96#define MVME_BLT_2ESST 5 /**< two edge source synchrnous transfer */
97#define MVME_BLT_BLT32FIFO 6 /**< FIFO mode, don't increment address */
98#define MVME_BLT_MBLT64FIFO 7 /**< FIFO mode, don't increment address */
99#define MVME_BLT_2EVMEFIFO 8 /**< two edge block transfer with FIFO mode */
100
101/* vme bus address modifiers */
102
103#define MVME_AM_A32_SB (0x0F) /**< A32 Extended Supervisory Block */
104#define MVME_AM_A32_SP (0x0E) /**< A32 Extended Supervisory Program */
105#define MVME_AM_A32_SD (0x0D) /**< A32 Extended Supervisory Data */
106#define MVME_AM_A32_NB (0x0B) /**< A32 Extended Non-Privileged Block */
107#define MVME_AM_A32_NP (0x0A) /**< A32 Extended Non-Privileged Program */
108#define MVME_AM_A32_ND (0x09) /**< A32 Extended Non-Privileged Data */
109#define MVME_AM_A32_SMBLT (0x0C) /**< A32 Multiplexed Block Transfer (D64) */
110#define MVME_AM_A32_NMBLT (0x08) /**< A32 Multiplexed Block Transfer (D64) */
111
112#define MVME_AM_A32 MVME_AM_A32_SD
113#define MVME_AM_A32_D64 MVME_AM_A32_SMBLT
114
115#define MVME_AM_A24_SB (0x3F) /**< A24 Standard Supervisory Block Transfer */
116#define MVME_AM_A24_SP (0x3E) /**< A24 Standard Supervisory Program Access */
117#define MVME_AM_A24_SD (0x3D) /**< A24 Standard Supervisory Data Access */
118#define MVME_AM_A24_NB (0x3B) /**< A24 Standard Non-Privileged Block Transfer */
119#define MVME_AM_A24_NP (0x3A) /**< A24 Standard Non-Privileged Program Access */
120#define MVME_AM_A24_ND (0x39) /**< A24 Standard Non-Privileged Data Access */
121#define MVME_AM_A24_SMBLT (0x3C) /**< A24 Multiplexed Block Transfer (D64) */
122#define MVME_AM_A24_NMBLT (0x38) /**< A24 Multiplexed Block Transfer (D64) */
123
124#define MVME_AM_A24 MVME_AM_A24_SD
125#define MVME_AM_A24_D64 MVME_AM_A24_SMBLT
126
127#define MVME_AM_A16_SD (0x2D) /**< A16 Short Supervisory Data Access */
128#define MVME_AM_A16_ND (0x29) /**< A16 Short Non-Privileged Data Access */
129
130#define MVME_AM_A16 MVME_AM_A16_SD
131
132#define MVME_AM_DEFAULT MVME_AM_A32
133
134/*---- interface structure -----------------------------------------*/
135typedef struct {
136 int handle; /**< internal handle */
137 int index; /**< index of interface 0..n */
138 void *info; /**< internal info structure */
139 int am; /**< Address modifier */
140 int dmode; /**< Data mode (D8,D16,D32,D64) */
141 int blt_mode; /**< Block transfer mode */
142 void *table; /**< Optional table for some drivers */
143} MVME_INTERFACE;
144
145/*---- function declarations ---------------------------------------*/
146
147/* make functions callable from a C++ program */
148#ifdef __cplusplus
149extern "C" {
150#endif
151
152/**dox***************************************************************/
153/** @addtogroup mvmestdfunctionh
154 *
155 * @{ */
156
157/********************************************************************/
158/** VME open
159The code below summarize the use of most of the mvme calls included in this
160interface.
161\code
162#include "vmicvme.h" // or other VME interface driver.
163
164int main () {
165 int i, status, vmeio_status, data;
166 MVME_INTERFACE *myvme;
167
168 // Open VME channel
169 status = mvme_open(&myvme, 0);
170
171 // Reset VME
172 // Under VMIC reboot CPU!!
173 // status = mvme_sysreset(myvme);
174
175 // Setup AM
176 status = mvme_set_am(myvme, MVME_AM_A24_ND);
177
178 // Setup Data size
179 status = mvme_set_dmode(myvme, MVME_DMODE_D32);
180
181 // Read VMEIO status
182 status = mvme_read(myvme, &vmeio_status, 0x78001C, 4);
183 printf("VMEIO status : 0x%x\n", vmeio_status);
184
185 // Write Single value
186 mvme_write_value(myvme, 0x780010, 0x3);
187
188 // Read Single Value
189 printf("Value : 0x%x\n", mvme_read_value(myvme, 0x780018));
190
191 // Write to the VMEIO in latch mode
192 for (i=0;i<10000;i++) {
193 data = 0xF;
194 status = mvme_write(myvme, 0x780010, &data, 4);
195 data = 0x0;
196 status = mvme_write(myvme, 0x780010, &data, 4);
197 }
198
199 // Close VME channel
200 status = mvme_close(myvme);
201 return 1;
202}
203\endcode
204@param **vme user VME pointer to the interface
205@param index interface number should be used to distingush multiple VME
206interface access within the same program.
207@return status MVME_SUCCESS, MVME_NO_INTERFACE, MVME_INVALID_PARAM, MVME_ACCESS_ERROR
208*/
209int EXPRT mvme_open(MVME_INTERFACE **vme, int idx);
210
211/********************************************************************/
212/**
213Close and release ALL the opened VME channel.
214See example in @ref mvme_open()
215@param *vme VME structure.
216@return MVME_SUCCESS, MVME_ACCESS_ERROR
217*/
218int EXPRT mvme_close(MVME_INTERFACE *vme);
219
220/********************************************************************/
221/**
222VME bus reset.
223Effect of the VME bus reset is dependent of the type of VME interface used.
224See example in @ref mvme_open()
225@param *vme VME structure.
226@return MVME_SUCCESS, MVME_ACCESS_ERROR
227*/
228int EXPRT mvme_sysreset(MVME_INTERFACE *vme);
229
230/********************************************************************/
231/**
232Read from VME bus.
233Implementation of the read can include automatic DMA transfer based on the
234size of the data. See example in @ref mvme_open()
235@param *vme VME structure
236@param *dst destination pointer
237@param vme_addr source address (VME location).
238@param n_bytes requested transfer size.
239@return MVME_SUCCESS
240*/
241int EXPRT mvme_read(MVME_INTERFACE *vme, void *dst, mvme_addr_t vme_addr, mvme_size_t n_bytes);
242
243/********************************************************************/
244/**
245Read single data from VME bus.
246Useful for register access. See example in @ref mvme_open()
247@param *vme VME structure
248@param vme_addr source address (VME location).
249@return MVME_SUCCESS
250*/
251unsigned int EXPRT mvme_read_value(MVME_INTERFACE *vme, mvme_addr_t vme_addr);
252
253/********************************************************************/
254/**
255Write data to VME bus.
256Implementation of the write can include automatic DMA transfer based on the
257size of the data. See example in @ref mvme_open()
258@param *vme VME structure
259@param vme_addr source address (VME location).
260@param *src source array
261@param n_bytes size of the array in bytes
262@return MVME_SUCCESS
263*/
264int EXPRT mvme_write(MVME_INTERFACE *vme, mvme_addr_t vme_addr, void *src, mvme_size_t n_bytes);
265
266/********************************************************************/
267/**
268Write single data to VME bus.
269Useful for register access. See example in @ref mvme_open()
270@param *vme VME structure
271@param vme_addr source address (VME location).
272@param value Value to be written to the VME bus
273@return MVME_SUCCESS
274*/
275int EXPRT mvme_write_value(MVME_INTERFACE *vme, mvme_addr_t vme_addr, unsigned int value);
276
277/********************************************************************/
278/**
279Set Address Modifier.
280@param *vme VME structure
281@param am address modifier
282@return MVME_SUCCESS
283*/
284int EXPRT mvme_set_am(MVME_INTERFACE *vme, int am);
285
286/********************************************************************/
287/**
288Get Address Modifier.
289@param *vme VME structure
290@param *am returned address modifier
291@return MVME_SUCCESS
292*/
293int EXPRT mvme_get_am(MVME_INTERFACE *vme, int *am);
294
295/********************************************************************/
296/**
297Set Data mode.
298@param *vme VME structure
299@param dmode Data mode
300@return MVME_SUCCESS
301*/
302int EXPRT mvme_set_dmode(MVME_INTERFACE *vme, int dmode);
303
304/********************************************************************/
305/**
306Get current Data mode.
307@param *vme VME structure
308@param *dmode returned address modifier
309@return MVME_SUCCESS
310*/
311int EXPRT mvme_get_dmode(MVME_INTERFACE *vme, int *dmode);
312
313/********************************************************************/
314/**
315Set Block Transfer mode.
316@param *vme VME structure
317@param mode BLT mode
318@return MVME_SUCCESS
319*/
320int EXPRT mvme_set_blt(MVME_INTERFACE *vme, int mode);
321
322/********************************************************************/
323/**
324Get current Data mode.
325@param *vme VME structure
326@param *mode returned BLT mode
327@return MVME_SUCCESS
328*/
329 int EXPRT mvme_get_blt(MVME_INTERFACE *vme, int *mode);
330 int EXPRT mvme_interrupt_generate(MVME_INTERFACE *mvme, int level, int vector, void *info);
331 int EXPRT mvme_interrupt_attach(MVME_INTERFACE *mvme, int level, int vector,
332 void (*isr)(int, void*, void *), void *info);
333 int EXPRT mvme_interrupt_detach(MVME_INTERFACE *mvme, int level, int vector, void *info);
334 int EXPRT mvme_interrupt_enable(MVME_INTERFACE *mvme, int level, int vector, void *info);
335 int EXPRT mvme_interrupt_disable(MVME_INTERFACE *mvme, int level, int vector, void *info);
336
337#ifdef __cplusplus
338}
339#endif
340
341/**dox***************************************************************/
342/** @} */ /* end of mvmestdfunctionh */
343/**dox***************************************************************/
344/** @} */ /* end of mvmestdinclude */
345
346#endif // MVMESTD_H
Note: See TracBrowser for help on using the repository browser.