LLC2_API
llif.h
Go to the documentation of this file.
00001 /*****************************************************************************
00002  *
00003  * File: llif.h
00004  *
00005  * $RCSfile: llif.h,v $
00006  * 
00007  * Copyright (C) 2001 D-TACQ Solutions Ltd
00008  * not to be used without owner's permission
00009  *
00010  * Description: interface to device driver - gets mappings for
00011  * control-mailboxes, and data-slave memory, 
00012  * provides convenience functions for access                
00013  *
00014  * $Id: llif.h,v 1.9.4.8 2006/01/19 20:15:28 pgm Exp $
00015  * $Log: llif.h,v $
00016  * Revision 1.9.4.8  2006/01/19 20:15:28  pgm
00017  * *** empty log message ***
00018  *
00019  * Revision 1.9.4.7  2006/01/15 15:04:26  pgm
00020  * *** empty log message ***
00021  *
00022  * Revision 1.9.4.6  2005/11/04 17:26:18  pgm
00023  * *** empty log message ***
00024  *
00025  * Revision 1.9.4.5  2004/11/04 07:13:13  pgm
00026  * merged multicard case
00027  *
00028  * Revision 1.9.4.4.2.2  2004/09/26 11:32:39  pgm
00029  * multiboard tstats pollstats in
00030  *
00031  * Revision 1.9.4.4.2.1  2004/09/25 11:53:03  pgm
00032  * first pass multi done - check it works for n==1
00033  *
00034  * Revision 1.9.4.4  2004/09/15 12:48:21  pgm
00035  * use internal var for llWaitDmaDone, reformat
00036  *
00037  * Revision 1.9.4.3  2004/07/31 21:48:25  pgm
00038  * now with Feedback - but why does it plot backwards\/
00039  *
00040  * Revision 1.9.4.2  2004/07/27 20:49:06  pgm
00041  * llcontrol 2G with AO - in debug
00042  *
00043  * Revision 1.9.4.1  2004/07/25 20:39:38  pgm
00044  * hbpolling, 96 channels
00045  *
00046  * Revision 1.9  2002/09/25 09:50:49  pgm
00047  * opt to use bigbuf
00048  *
00049  * Revision 1.8  2002/09/02 15:36:14  pgm
00050  * hook up int masking
00051  *
00052  * Revision 1.7  2001/05/25 12:05:15  pgm
00053  * its a runner - shippit quick
00054  *
00055  * Revision 1.6  2001/05/21 17:42:38  pgm
00056  * reformed
00057  *
00058  * Revision 1.5  2001/05/20 21:24:10  pgm
00059  * ll WIP - almost works
00060  *
00061  * Revision 1.4  2001/05/19 19:46:15  pgm
00062  * enters LL mode with good bufs, mboxes
00063  *
00064  * Revision 1.3  2001/05/19 07:03:40  pgm
00065  * LL done for SOFT CLOCK, compiles
00066  *
00067  * Revision 1.2  2001/05/18 20:21:13  pgm
00068  * compiles. needs algorithms
00069  *
00070  * Revision 1.1  2001/05/18 07:09:37  pgm
00071  * first cut - wont compile :-(
00072  *
00073  * Revision 1.2  2000/12/28 11:03:00  pgm
00074  * *** empty log message ***
00075  *
00076  * Revision 1.1  1999/10/22 16:26:49  pgm
00077  * first entry to cvs
00078  *
00079  *
00080 \*****************************************************************************/
00081 
00082 /** @file llif.h interface to device driver. - gets mappings for
00083  * control-mailboxes, and data-slave memory, 
00084  * provides convenience functions for access 
00085  */
00086 
00087 
00088 #ifndef __LLIF_H__
00089 #define __LLIF_H__
00090 
00091 extern int verbose;
00092 
00093 #define PRINTF( n ) if ( verbose>=(n) ) printf
00094 
00095 #ifndef __U32__
00096 typedef unsigned short u16;
00097 typedef unsigned u32;        // define a 32 bit quantity
00098 #endif
00099 
00100 /*
00101  * define interface to mailboxes.
00102  * struct MU is effectively "this" - much cleaner in C++!!
00103  *
00104  */
00105 
00106 typedef u32 MFA;       /* Message Frame Address - unit of Q */
00107 
00108 
00109 
00110 
00111 struct MU;   /* Message Unit */
00112 
00113 
00114 /** set a mail mbox register: ibox [0-3]. return 0 on success */
00115 int setMbox( struct MU* m, int ibox, u32 value );      
00116 
00117 
00118 /** get contents of mailbox register: ibox [0-3] */
00119 u32 getMbox( struct MU* m, int ibox );      
00120 
00121 /** get last contents of mailbox register: ibox [0-3] */
00122 u32 getMboxShadow(struct MU* m, int ibox );
00123 
00124 /** just set these bits. */
00125 int setMboxBits( struct MU* m, int ibox, u32 bits_to_set );
00126 
00127 
00128 /** just clr these bits. */
00129 int clrMboxBits( struct MU* m, int ibox, u32 bits_to_clr );
00130 
00131 /** set the field in the register only. */
00132 int setMboxField( struct MU* m, int ibox, u32 field_mask, u32 field_value );
00133 
00134 
00135 /** return when any of the bits become true. */
00136 u32 pollMboxBits( struct MU* m, int ibox, u32 mask, u32 goal );
00137 
00138 /** polls regular ack from acq32. */
00139 int pollAck( struct MU* m );
00140 
00141 /** iboard [1-3]. return mapping on success. */
00142 struct MU* mmapMbox( int iboard );
00143 
00144 
00145 
00146 void setMboxPollcount(struct MU* m, int poll_count);
00147 int getMboxPollcount(struct MU* m);
00148 
00149 
00150 void showLastWrites( struct MU* m );
00151 
00152 /** define interface to buffer memory.
00153  * again, for multiple boards this will be far more palatable as a C++ class
00154  */
00155 struct DmaBuffer;   /* opaque struct for clients */
00156 
00157 struct DmaBuffer* mmapDmaBuffer( int iboard, unsigned nbytes ); 
00158 // maps dma buffer for board iboard {1..4}, nbytes long. ret mapping on success
00159 u32 getBusAddr( struct DmaBuffer* b, u32 offset_bytes);
00160 u32* getVaddr( struct DmaBuffer* b, u32 offset_bytes);
00161 int getDmaBufferLen(struct DmaBuffer* b);
00162 
00163 
00164 struct DmaBuffer* mmapBigBuffer( int iboard, unsigned nbytes ); 
00165 // maps dma buffer from driver bigbuff section.
00166 
00167 void mmapValidateDmaBuffer( struct MU* mbx, int nsamples );
00168 // tell driver to allow normal data device access to red dmabuffer
00169 
00170 
00171 
00172 void acq32_enableInts( struct MU* mbx, unsigned mask );
00173 void acq32_maskInts  ( struct MU* mbx, unsigned mask );
00174 
00175 /*
00176  * hbPolling - place a marker in Host Buffer, poll for overwrite
00177  */
00178 int hbPoll(struct DmaBuffer *buf, int offset, 
00179            int sample_len, volatile int* user_abort);
00180 void hbPrimePoll(struct DmaBuffer *buf, int offset, int sample_len);
00181 void hbPrimeBuffer(struct DmaBuffer *buf);
00182 
00183 
00184 /**
00185  * I2O Q ports:
00186  * OUTBOUND: host reserves free MFA, puts MFA as command
00187  * INBOUND:  host gets message MFA, replaces MFA when done
00188  *
00189  * NB: direction with respect to HOST! 
00190  */
00191 
00192 MFA mu_reserveOutbound(struct MU* mu);
00193 int mu_putOutbound(struct MU* mu, MFA mfa);
00194 /* return 0 on success */
00195 
00196 MFA mu_getInbound(struct MU* mu);
00197 int mu_returnInbound(struct MU* mu, MFA mfa);
00198 
00199 
00200 
00201 static inline void memset32(u32 *buf, u32 value, int count)
00202 {
00203         int ii;
00204 
00205         for (ii = 0; ii < count; ++ii){
00206                 buf[ii] = value;
00207         }
00208 }
00209 
00210 /** set a deferred action to take place on path close/
00211  * @param m
00212  * @param cmd command to send to MAILBOX_0, 0: no command
00213  */
00214 void setPathCleanup(struct MU* m, unsigned cmd);
00215 
00216 void acq200_setImask(int slot, const char* mask);
00217 void acq200_setImask(int slot, u32* mask);
00218 #define MFA_FAIL 0xffffffff
00219 #endif