Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line | 
|---|---|---|---|
| 9 | f9daq | 1 | //------------------------------------------------------------------------------------------- | 
        
| 2 | // pcilib.c - interface hardware dependend functions to interface to the pvmon | 
        ||
| 3 | // | 
        ||
| 4 | // (c) 1999-2002 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 | // $Log: pcilibLx.c,v $ | 
        ||
| 15 | // Revision 1.4  2002/10/20 18:07:48  klaus | 
        ||
| 16 | // mostly working alpha version | 
        ||
| 17 | // | 
        ||
| 18 | // Revision 1.3  2002/10/20 11:49:33  klaus | 
        ||
| 19 | // first parts working | 
        ||
| 20 | // | 
        ||
| 21 | // Revision 1.2  2002/10/19 09:44:36  klaus | 
        ||
| 22 | // first success compiling project | 
        ||
| 23 | // | 
        ||
| 24 | // Revision 1.1.1.1  2002/10/18 22:14:29  klaus | 
        ||
| 25 | // | 
        ||
| 26 | |||
| 27 | //------------------------------------------------------------------------------------------- | 
        ||
| 28 | // INCLUDES | 
        ||
| 29 | // | 
        ||
| 30 | #include <stdio.h> | 
        ||
| 31 | #include <string.h> | 
        ||
| 32 | #include <errno.h> | 
        ||
| 33 | #include <ctype.h> | 
        ||
| 34 | |||
| 35 | #include <../driver/pcivme.h> | 
        ||
| 36 | #include <../driver/vic.h> | 
        ||
| 37 | #include <../driver/vme.h> | 
        ||
| 38 | #include <../lib/pcivme_ni.h> | 
        ||
| 39 | #include <pcilibLx.h> | 
        ||
| 40 | #include <mbuffer.h> | 
        ||
| 41 | |||
| 42 | //------------------------------------------------------------------------------------------- | 
        ||
| 43 | // DEFINES | 
        ||
| 44 | // | 
        ||
| 45 | |||
| 46 | //------------------------------------------------------------------------------------------- | 
        ||
| 47 | // TYPEDEFS | 
        ||
| 48 | // | 
        ||
| 49 | |||
| 50 | //------------------------------------------------------------------------------------------- | 
        ||
| 51 | // GLOBALS | 
        ||
| 52 | // | 
        ||
| 53 | static int storedError = 0;  | 
        ||
| 54 | static int nLocalWordMode = 0; // initial 32 bit mode  | 
        ||
| 55 | |||
| 56 | //-------------------------------------------------------------------------- | 
        ||
| 57 | // LOCALS | 
        ||
| 58 | //  | 
        ||
| 59 | |||
| 60 | //------------------------------------------------------------------------------------------- | 
        ||
| 61 | // FUNCTIONS | 
        ||
| 62 | // | 
        ||
| 63 | |||
| 64 | //------------------------------------------------------------------------------------------- | 
        ||
| 65 | // set word mode | 
        ||
| 66 | // | 
        ||
| 67 | int setWordMode(int nMode)  | 
        ||
| 68 | { | 
        ||
| 69 | nLocalWordMode = nMode;  | 
        ||
| 70 | |||
| 71 | return nLocalWordMode;  | 
        ||
| 72 | } | 
        ||
| 73 | |||
| 74 | //------------------------------------------------------------------------------------------- | 
        ||
| 75 | // set interface special registers - VIC68A | 
        ||
| 76 | // | 
        ||
| 77 | unsigned long _SetRegister(int nIfcHandle, unsigned long Address, unsigned long Value)  | 
        ||
| 78 | { | 
        ||
| 79 | __u8 ubContent = (__u8)Value;  | 
        ||
| 80 | |||
| 81 | VMEaccessVIC(nIfcHandle, VIC68A_WRITE, Address, &ubContent);  | 
        ||
| 82 | |||
| 83 | return ubContent;  | 
        ||
| 84 | } | 
        ||
| 85 | |||
| 86 | |||
| 87 | //------------------------------------------------------------------------------------------- | 
        ||
| 88 | // function to get special interface registers - VIC68A | 
        ||
| 89 | // | 
        ||
| 90 | unsigned long _GetRegister(int nIfcHandle, unsigned long Address)  | 
        ||
| 91 | { | 
        ||
| 92 |     __u8 ubContent; | 
        ||
| 93 | |||
| 94 | VMEaccessVIC(nIfcHandle, VIC68A_READ, Address, &ubContent);  | 
        ||
| 95 | |||
| 96 | return ubContent;  | 
        ||
| 97 | } | 
        ||
| 98 | |||
| 99 | |||
| 100 | //------------------------------------------------------------------------------------------- | 
        ||
| 101 | // init the interface with the current properties | 
        ||
| 102 | // | 
        ||
| 103 | int Init_Interface(char *szDevicePath, char AdrMode, int *nIfcHandle)  | 
        ||
| 104 | { | 
        ||
| 105 | return VMEopen(szDevicePath, AdrMode, nIfcHandle);  | 
        ||
| 106 | } | 
        ||
| 107 | |||
| 108 | |||
| 109 | //------------------------------------------------------------------------------------------- | 
        ||
| 110 | // deinit the current interface | 
        ||
| 111 | // | 
        ||
| 112 | void DeInit_Interface(int nIfcHandle)  | 
        ||
| 113 | { | 
        ||
| 114 | VMEclose(nIfcHandle);  | 
        ||
| 115 | } | 
        ||
| 116 | |||
| 117 | |||
| 118 | //------------------------------------------------------------------------------------------- | 
        ||
| 119 | // check if an error occured | 
        ||
| 120 | // | 
        ||
| 121 | int GetError(int nIfcHandle)  | 
        ||
| 122 | { | 
        ||
| 123 | int error;  | 
        ||
| 124 | |||
| 125 | if ((error = GetLastError(nIfcHandle)))  | 
        ||
| 126 | storedError = error;  | 
        ||
| 127 |     else | 
        ||
| 128 | storedError = VMEerror(nIfcHandle);  | 
        ||
| 129 | |||
| 130 | return storedError;  | 
        ||
| 131 | } | 
        ||
| 132 | |||
| 133 | |||
| 134 | //------------------------------------------------------------------------------------------- | 
        ||
| 135 | // clear a pending error | 
        ||
| 136 | // | 
        ||
| 137 | void ClearError(int nIfcHandle)  | 
        ||
| 138 | { | 
        ||
| 139 | storedError = 0;  | 
        ||
| 140 | } | 
        ||
| 141 | |||
| 142 | //------------------------------------------------------------------------------------------- | 
        ||
| 143 | // read elements and split a long access into 2 word accesses if word data path | 
        ||
| 144 | // | 
        ||
| 145 | char ReadByte(int nIfcHandle, unsigned long adr, unsigned short modifier)  | 
        ||
| 146 | { | 
        ||
| 147 |     __u8 c; | 
        ||
| 148 | |||
| 149 | setAccessProperties(nIfcHandle, (__u8)modifier, BYTE_ACCESS);  | 
        ||
| 150 | |||
| 151 | storedError = VMEread(nIfcHandle, adr, BYTE_ACCESS, 1, &c);  | 
        ||
| 152 | |||
| 153 | return c;  | 
        ||
| 154 | } | 
        ||
| 155 | |||
| 156 | short ReadWord(int nIfcHandle, unsigned long adr, unsigned short modifier)  | 
        ||
| 157 | { | 
        ||
| 158 |     __u16 w; | 
        ||
| 159 | |||
| 160 | setAccessProperties(nIfcHandle, (__u8)modifier, WORD_ACCESS);  | 
        ||
| 161 | |||
| 162 | storedError = VMEread(nIfcHandle, adr, WORD_ACCESS, 1, &w);  | 
        ||
| 163 | |||
| 164 | return w;  | 
        ||
| 165 | } | 
        ||
| 166 | |||
| 167 | long ReadLong(int nIfcHandle, unsigned long adr, unsigned short modifier)  | 
        ||
| 168 | { | 
        ||
| 169 |     __u32 l; | 
        ||
| 170 | |||
| 171 | if (nLocalWordMode)  | 
        ||
| 172 |     { | 
        ||
| 173 | __u16 partl, parth;  | 
        ||
| 174 | |||
| 175 |         // lese high anteil von adresse +0 | 
        ||
| 176 | parth = ReadWord(nIfcHandle, adr, modifier);  | 
        ||
| 177 | |||
| 178 |         // lese low anteil von adresse +2 | 
        ||
| 179 | partl = ReadWord(nIfcHandle, adr + sizeof(__u16), modifier);  | 
        ||
| 180 | |||
| 181 | l = (parth << 16) | partl;  | 
        ||
| 182 |     } | 
        ||
| 183 |     else | 
        ||
| 184 |     { | 
        ||
| 185 | setAccessProperties(nIfcHandle, (__u8)modifier, LONG_ACCESS);  | 
        ||
| 186 | |||
| 187 | storedError = VMEread(nIfcHandle, adr, LONG_ACCESS, 1, &l);  | 
        ||
| 188 |     } | 
        ||
| 189 | |||
| 190 | return l;  | 
        ||
| 191 | } | 
        ||
| 192 | |||
| 193 | //------------------------------------------------------------------------------------------- | 
        ||
| 194 | // write a byte/word/long and split a long access into 2 word accesses if word data path | 
        ||
| 195 | // | 
        ||
| 196 | void WriteByte(int nIfcHandle, unsigned long adr, char value, unsigned short modifier)  | 
        ||
| 197 | { | 
        ||
| 198 | setAccessProperties(nIfcHandle, (__u8)modifier, BYTE_ACCESS);  | 
        ||
| 199 | |||
| 200 | storedError = VMEwrite(nIfcHandle, adr, BYTE_ACCESS, 1, &value);  | 
        ||
| 201 | } | 
        ||
| 202 | |||
| 203 | void WriteWord(int nIfcHandle, unsigned long adr, short value, unsigned short modifier)  | 
        ||
| 204 | { | 
        ||
| 205 | setAccessProperties(nIfcHandle, (__u8)modifier, WORD_ACCESS);  | 
        ||
| 206 | |||
| 207 | storedError = VMEwrite(nIfcHandle, adr, WORD_ACCESS, 1, &value);  | 
        ||
| 208 | } | 
        ||
| 209 | |||
| 210 | void WriteLong(int nIfcHandle, unsigned long adr, long value, unsigned short modifier)  | 
        ||
| 211 | { | 
        ||
| 212 | if (nLocalWordMode)  | 
        ||
| 213 |     { | 
        ||
| 214 |         __u16 part; | 
        ||
| 215 | |||
| 216 |         // high anteil auf adresse +0 | 
        ||
| 217 | part = (value >> 16) & 0xffff;  | 
        ||
| 218 | WriteWord(nIfcHandle, adr, part, modifier);  | 
        ||
| 219 | |||
| 220 |         // low anteil auf adresse +2 | 
        ||
| 221 | part = value & 0xffff;  | 
        ||
| 222 | WriteWord(nIfcHandle, adr + sizeof(__u16), part, modifier);  | 
        ||
| 223 |     } | 
        ||
| 224 |     else | 
        ||
| 225 |     { | 
        ||
| 226 | setAccessProperties(nIfcHandle, (__u8)modifier, LONG_ACCESS);  | 
        ||
| 227 | |||
| 228 | storedError = VMEwrite(nIfcHandle, adr, LONG_ACCESS, 1, &value);  | 
        ||
| 229 |     } | 
        ||
| 230 | } | 
        ||
| 231 | |||
| 232 | //------------------------------------------------------------------------------------------- | 
        ||
| 233 | // check for a pending SYSFAIL  | 
        ||
| 234 | // | 
        ||
| 235 | unsigned short PollSfail(int nIfcHandle)  | 
        ||
| 236 | { | 
        ||
| 237 |     BOOLEAN bResult; | 
        ||
| 238 | |||
| 239 | VMEsysfailGet(nIfcHandle, &bResult);  | 
        ||
| 240 | |||
| 241 | return (unsigned short)bResult;  | 
        ||
| 242 | } | 
        ||
| 243 | |||
| 244 | //------------------------------------------------------------------------------------------- | 
        ||
| 245 | // clear a interface set SYSFAIL | 
        ||
| 246 | // | 
        ||
| 247 | void ClrSfail(int nIfcHandle)  | 
        ||
| 248 | { | 
        ||
| 249 | VMEsysfailSet(nIfcHandle, 0);  | 
        ||
| 250 | } | 
        ||
| 251 | |||
| 252 | //------------------------------------------------------------------------------------------- | 
        ||
| 253 | // set a SYSFAIL | 
        ||
| 254 | // | 
        ||
| 255 | void SetSfail(int nIfcHandle)  | 
        ||
| 256 | { | 
        ||
| 257 | VMEsysfailSet(nIfcHandle, 1);  | 
        ||
| 258 | } | 
        ||
| 259 | |||
| 260 | //------------------------------------------------------------------------------------------- | 
        ||
| 261 | // read a interrupt vector as byte/word/long (if supported) | 
        ||
| 262 | // | 
        ||
| 263 | char ReadVectorByte(int nIfcHandle)  | 
        ||
| 264 | { | 
        ||
| 265 |     __u8 ubVector; | 
        ||
| 266 | |||
| 267 | VMEinterrupt(nIfcHandle, &ubVector);  | 
        ||
| 268 | |||
| 269 | return ubVector;  | 
        ||
| 270 | } | 
        ||
| 271 | |||
| 272 | short ReadVectorWord(int nIfcHandle)  | 
        ||
| 273 | { | 
        ||
| 274 | printf("Word read of a vector not available!\n");  | 
        ||
| 275 | return 0;  | 
        ||
| 276 | } | 
        ||
| 277 | |||
| 278 | long ReadVectorLong(int nIfcHandle)  | 
        ||
| 279 | { | 
        ||
| 280 | printf("Longword read of a vector not available!\n");  | 
        ||
| 281 | return 0;  | 
        ||
| 282 | } | 
        ||
| 283 | |||
| 284 | //------------------------------------------------------------------------------------------- | 
        ||
| 285 | // emulate a 68K TAS (read/modify/write) instruction | 
        ||
| 286 | // | 
        ||
| 287 | char TAS(int nIfcHandle, unsigned long adr, unsigned short modifier)  | 
        ||
| 288 | { | 
        ||
| 289 | __u8 ubResult = 0x80;  | 
        ||
| 290 | |||
| 291 | VMETAS(nIfcHandle, adr, &ubResult);  | 
        ||
| 292 | |||
| 293 | return ubResult; // check if a read reads a lock  | 
        ||
| 294 | } | 
        ||
| 295 | |||
| 296 | //------------------------------------------------------------------------------------------- | 
        ||
| 297 | // generate a SYSRESET on the vmebus and re-init the interface | 
        ||
| 298 | // | 
        ||
| 299 | void Reset_VME(int nIfcHandle)  | 
        ||
| 300 | { | 
        ||
| 301 | VMEreset(nIfcHandle);  | 
        ||
| 302 | } | 
        ||
| 303 | |||
| 304 | |||
| 305 | //------------------------------------------------------------------------------------------- | 
        ||
| 306 | // print out some interface special info | 
        ||
| 307 | // | 
        ||
| 308 | void GetInterfaceInfo(int nIfcHandle, char type)  | 
        ||
| 309 | { | 
        ||
| 310 | switch (type)  | 
        ||
| 311 |     { | 
        ||
| 312 |     } | 
        ||
| 313 | } | 
        ||
| 314 | |||
| 315 | //------------------------------------------------------------------------------------------- | 
        ||
| 316 | //------------------------------------------------------------------------------------------- | 
        ||
| 317 | //------------------------------------------------------------------------------------------- |