mrfioc2  2.3.0
mrfCommonIO.h
Go to the documentation of this file.
1 /***************************************************************************************************
2  |* mrfCommonIO.h -- Macros for Performing I/O Operations
3  |*
4  |*--------------------------------------------------------------------------------------------------
5  |* Author: Eric Bjorklund (LANSCE)
6  |* Date: 8 January 2007
7  |*
8  |*--------------------------------------------------------------------------------------------------
9  |* MODIFICATION HISTORY:
10  |* 08 Jan 2007 E.Bjorklund Original
11  |* 21 Oct 2009 E.Bjorklund Removed array macros.
12  |* Reorganized register "typing" mechanism.
13  |* Expanded to handle both big-endian and little-endian busses
14  |* 22 Jan 2009 E.Bjorklund Defined macros for use with all MRF hardware.
15  |*
16  |*--------------------------------------------------------------------------------------------------
17  |* MODULE DESCRIPTION:
18  |*
19  |* This header file contains macro definitions for performing basic I/O operations on the hardware
20  |* registers of the MRF Event System VME and PMC cards.
21  |*
22  |* The following operations are supported:
23  |* o 8-bit, 16-bit, and 32-bit scalar reads and writes.
24  |* o 8-bit, 16-bit, and 32-bit scalar bit set operations (read/modify/write).
25  |* o 8-bit, 16-bit, and 32-bit scalar bit clear operations (read/modify/write).
26  |* o 8-bit, 16-bit, and 32-bit scalar bit "flip" operations (read/modify/write),
27  |*
28  |* All I/O operations use underlying operating system routines to ensure that hardware pipelines
29  |* are flushed so that the operations are executed in the order in which they were specified.
30  |* The file "epicsMMIO.h", located in the OS-dependent directories (e.g., ./os/vxWorks/mrfIoOps.h,
31  |* or ./os/RTEMS/epicsMMIO.h) maps synchronous I/O operations onto their OS-dependent routines or
32  |* macros.
33  |*
34  |* The I/O macros in this file are designed to be easily understood and to minimize errors.
35  |* Each macro begins with a "base" and an "offset" parameter. The "base" parameter specifies
36  |* the address (in local space) of the card's register map. The "offset" parameter must be a
37  |* defined symbol of the form:
38  |* "Uxx_OffsetName"
39  |* The "Uxx" part of the name specifies the size of the register in bits (U8, U16, or U32) and
40  |* provides a form of "type declaration" for the symbol.
41  |*
42  |* Only the "OffsetName" part of the offset symbol should be specified when invoking one of the
43  |* I/O macros. The macro itself will prepend the appropriate "Uxx_" string. This will
44  |* automatically produce a compile-time error if you try to use the wrong sized macro for the
45  |* desired register (e.g., using an 8-bit read macro to access a 16-bit register).
46  |*
47  |*--------------------------------------------------------------------------------------------------
48  |* DEFINED MACROS:
49  |*
50  |* The macros defined in this file can be classified within the following 6 catagories:
51  |*
52  |* Read Operations:
53  |* READ8 (base,offset)
54  |* READ16 (base,offset)
55  |* READ32 (base,offset)
56  |*
57  |* Write Operations:
58  |* WRITE8 (base,offset,value)
59  |* WRITE16 (base,offset,value)
60  |* WRITE32 (base,offset,value)
61  |*
62  |* Bit Set Operations:
63  |* BITSET8 (base,offset,mask)
64  |* BITSET16 (base,offset,mask)
65  |* BITSET32 (base,offset,mask)
66  |*
67  |* Bit Clear Operations:
68  |* BITCLR8 (base,offset,mask)
69  |* BITCLR16 (base,offset,mask)
70  |* BITCLR32 (base,offset,mask)
71  |*
72  |* Bit Flip Operations:
73  |* BITFLIP8 (base,offset,mask)
74  |* BITFLIP16 (base,offset,mask)
75  |* BITFLIP32 (base,offset,mask)
76  |*
77  \**************************************************************************************************/
78 
79 /**************************************************************************************************
80  |* COPYRIGHT NOTIFICATION
81  |**************************************************************************************************
82  |*
83  |* THE FOLLOWING IS A NOTICE OF COPYRIGHT, AVAILABILITY OF THE CODE,
84  |* AND DISCLAIMER WHICH MUST BE INCLUDED IN THE PROLOGUE OF THE CODE
85  |* AND IN ALL SOURCE LISTINGS OF THE CODE.
86  |*
87  |**************************************************************************************************
88  |*
89  |* This software is distributed under the EPICS Open License Agreement which
90  |* can be found in the file, LICENSE, included with this distribution.
91  |*
92  \*************************************************************************************************/
93 
94 #ifndef MRF_COMMON_IO_H
95 #define MRF_COMMON_IO_H
96 
97 /**************************************************************************************************/
98 /* Include Other Header Files Needed by This Module */
99 /**************************************************************************************************/
100 
101 #include <epicsEndian.h> /* OS-independent macros for system endianness checking */
102 #include <epicsMMIO.h> /* OS-dependent synchronous I/O routines */
103 #include <mrfBitOps.h> /* Generic bit operations */
104 #include <stdexcept>
105 
106 /**************************************************************************************************/
107 /* Macros For Accessing MRF Timing Modules */
108 /* (Note that MRF timing modules are always accessed using native mode I/O */
109 /**************************************************************************************************/
110 
111 /*---------------------
112  * Synchronous Read Operations
113  */
114 #define READ32(base,offset) NAT_READ32(base,offset)
115 
116 /*---------------------
117  * Synchronous Write Operations
118  */
119 #define WRITE32(base,offset,value) NAT_WRITE32(base,offset,value)
120 
121 /*---------------------
122  * Bit Set Operations
123  */
124 #define BITSET32(base,offset,mask) BITSET(NAT,32,base,offset,mask)
125 
126 /*---------------------
127  * Bit Clear Operations
128  */
129 #define BITCLR32(base,offset,mask) BITCLR(NAT,32,base,offset,mask)
130 
131 /*---------------------
132  * Bit Flip Operations
133  */
134 #define BITFLIP32(base,offset,mask) BITFLIP(NAT,32,base,offset,mask)
135 
136 /**************************************************************************************************/
137 /* Macros For Native Order I/O */
138 /* */
139 
140 /*================================================================================================*/
141 /* Define the macros for synchronous I/O operations. */
142 /* These will ultimately resolve into operating system dependent function or macro calls. */
143 /*================================================================================================*/
144 
145 #define NAT_READ32(base,offset) \
146  nat_ioread32 ((epicsUInt8 *)(base) + U32_ ## offset)
147 
148 #define NAT_WRITE32(base,offset,value) \
149  nat_iowrite32 (((epicsUInt8 *)(base) + U32_ ## offset), value)
150 
151 /**************************************************************************************************/
152 /* Macros For Big-Endian Bus I/O */
153 /* */
154 
155 
156 /*================================================================================================*/
157 /* Define the macros for synchronous I/O operations. */
158 /* These will ultimately resolve into operating system dependent function or macro calls. */
159 /*================================================================================================*/
160 
161 /*---------------------
162  * Synchronous Read Operations
163  */
164 #define BE_READ32(base,offset) \
165  be_ioread32 ((epicsUInt8 *)(base) + U32_ ## offset)
166 
167 /*---------------------
168  * Synchronous Write Operations
169  */
170 #define BE_WRITE32(base,offset,value) \
171  be_iowrite32 (((epicsUInt8 *)(base) + U32_ ## offset), value)
172 
173 
174 /**************************************************************************************************/
175 /* Macros For Little-Endian Bus I/O */
176 /* */
177 
178 
179 /*================================================================================================*/
180 /* Define the macros for synchronous I/O operations. */
181 /* These will ultimately resolve into operating system dependent function or macro calls. */
182 /*================================================================================================*/
183 
184 /*---------------------
185  * Synchronous Read Operations
186  */
187 #define LE_READ8(base,offset) \
188  ioread8 ((epicsUInt8 *)(base) + U8_ ## offset)
189 #define LE_READ16(base,offset) \
190  le_ioread16 ((epicsUInt8 *)(base) + U16_ ## offset)
191 #define LE_READ32(base,offset) \
192  le_ioread32 ((epicsUInt8 *)(base) + U32_ ## offset)
193 
194 /*---------------------
195  * Synchronous Write Operations
196  */
197 #define LE_WRITE8(base,offset,value) \
198  iowrite8 (((epicsUInt8 *)(base) + U8_ ## offset), value)
199 #define LE_WRITE16(base,offset,value) \
200  le_iowrite16 (((epicsUInt8 *)(base) + U16_ ## offset), value)
201 #define LE_WRITE32(base,offset,value) \
202  le_iowrite32 (((epicsUInt8 *)(base) + U32_ ## offset), value)
203 
204 #endif