Rev 9 | Rev 13 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 9 | Rev 11 | ||
|---|---|---|---|
| Line 127... | Line 127... | ||
| 127 | init.sVie[0].wOffset = 0; |
127 | init.sVie[0].wOffset = 0; |
| 128 | 128 | ||
| 129 | if (ioctl(dev->nFileNo, PCIVME_INIT_HARDWARE, &init) < 0) |
129 | if (ioctl(dev->nFileNo, PCIVME_INIT_HARDWARE, &init) < 0) |
| 130 | { |
130 | { |
| 131 | dev->nLastError = errno; |
131 | dev->nLastError = errno; |
| - | 132 | printf("initHardware:err=%d %s\n" , errno, strerror(errno) ); |
|
| 132 | return errno; |
133 | return errno; |
| 133 | } |
134 | } |
| 134 | 135 | ||
| 135 | return 0; |
136 | return 0; |
| 136 | } |
137 | } |
| Line 145... | Line 146... | ||
| 145 | deinit.sVie[0].wOffset = 0; |
146 | deinit.sVie[0].wOffset = 0; |
| 146 | 147 | ||
| 147 | if (ioctl(dev->nFileNo, PCIVME_DEINIT_HARDWARE, &deinit) < 0) |
148 | if (ioctl(dev->nFileNo, PCIVME_DEINIT_HARDWARE, &deinit) < 0) |
| 148 | { |
149 | { |
| 149 | dev->nLastError = errno; |
150 | dev->nLastError = errno; |
| - | 151 | printf("deInitHardware:err=%d %s\n" , errno, strerror(errno) ); |
|
| 150 | return errno; |
152 | return errno; |
| 151 | } |
153 | } |
| 152 | 154 | ||
| 153 | return 0; |
155 | return 0; |
| 154 | } |
156 | } |
| Line 163... | Line 165... | ||
| 163 | dev = (VMEMM_DEVICE *)malloc(sizeof(*dev)); |
165 | dev = (VMEMM_DEVICE *)malloc(sizeof(*dev)); |
| 164 | if (!dev) |
166 | if (!dev) |
| 165 | return errno; |
167 | return errno; |
| 166 | 168 | ||
| 167 | dev->nFileNo = open(cszDeviceName, O_RDWR); |
169 | dev->nFileNo = open(cszDeviceName, O_RDWR); |
| 168 | - | ||
| - | 170 | printf("VMEopen: dev->nFileNo %d size=%d %s\n" , dev->nFileNo,sizeof(*dev), cszDeviceName ); |
|
| 169 | if (dev->nFileNo == -1) |
171 | if (dev->nFileNo == -1) |
| 170 | { |
172 | { |
| 171 | error = errno; |
173 | error = errno; |
| - | 174 | printf("VMEopen:err=%d %s\n" , error, strerror(error) ); |
|
| 172 | free(dev); |
175 | free(dev); |
| 173 | return error; |
176 | return error; |
| 174 | } |
177 | } |
| 175 | 178 | ||
| 176 | dev->cAddressModifier = ubAddressModifier; |
179 | dev->cAddressModifier = ubAddressModifier; |
| 177 | *pnHandle = (int)dev; |
180 | *pnHandle = (int)dev; |
| 178 | 181 | ||
| 179 | error = initHardware(dev); |
182 | error = initHardware(dev); |
| 180 | if (error) |
183 | if (error) |
| 181 | return error; |
184 | return error; |
| 182 | 185 | ||
| 183 | dev->nLastError = 0; |
186 | dev->nLastError = 0; |
| 184 | 187 | ||
| 185 | return setAccessProperties(*pnHandle, dev->cAddressModifier, BYTE_ACCESS); // set access properties to default |
188 | return setAccessProperties(*pnHandle, dev->cAddressModifier, BYTE_ACCESS); // set access properties to default |
| Line 188... | Line 191... | ||
| 188 | int VMEinit(const char *cszDeviceName, unsigned short nVMEMM, unsigned char ubAddressModifier, int *pnHandle) |
191 | int VMEinit(const char *cszDeviceName, unsigned short nVMEMM, unsigned char ubAddressModifier, int *pnHandle) |
| 189 | { |
192 | { |
| 190 | char *szLocalDeviceName = szDeviceName(cszDeviceName, nVMEMM); |
193 | char *szLocalDeviceName = szDeviceName(cszDeviceName, nVMEMM); |
| 191 | 194 | ||
| 192 | return VMEopen(szLocalDeviceName, ubAddressModifier, pnHandle); |
195 | return VMEopen(szLocalDeviceName, ubAddressModifier, pnHandle); |
| 193 | } |
196 | } |
| 194 | 197 | ||
| 195 | int setAccessProperties(int nHandle, unsigned char bModifier, unsigned char bAccessType) |
198 | int setAccessProperties(int nHandle, unsigned char bModifier, unsigned char bAccessType) |
| 196 | { |
199 | { |
| 197 | VMEMM_DEVICE *dev = (VMEMM_DEVICE *)nHandle; |
200 | VMEMM_DEVICE *dev = (VMEMM_DEVICE *)nHandle; |
| 198 | 201 | ||
| 199 | PCIVME_ACCESS_COMMAND access_command; |
202 | PCIVME_ACCESS_COMMAND access_command; |
| 200 | 203 | ||
| 201 | access_command.bAccessType = |
204 | access_command.bAccessType = |
| 202 | access_command.bIncrement = bAccessType; // increment and accessType are the same |
205 | access_command.bIncrement = bAccessType; // increment and accessType are the same |
| 203 | access_command.bModifier = bModifier; |
206 | access_command.bModifier = bModifier; |
| 204 | 207 | ||
| 205 | if (ioctl(dev->nFileNo, PCIVME_SET_ACCESS_PARA, &access_command) < 0) |
208 | if (ioctl(dev->nFileNo, PCIVME_SET_ACCESS_PARA, &access_command) < 0) |
| 206 | { |
209 | { |
| 207 | dev->nLastError = errno; |
210 | dev->nLastError = errno; |
| - | 211 | printf("setAccessProperties:err=%d %s\n" , errno, strerror(errno) ); |
|
| 208 | return errno; |
212 | return errno; |
| 209 | } |
213 | } |
| 210 | 214 | ||
| 211 | dev->cAddressModifier = bModifier; |
215 | dev->cAddressModifier = bModifier; |
| 212 | dev->cAccessWidth = bAccessType; |
216 | dev->cAccessWidth = bAccessType; |
| 213 | 217 | ||
| 214 | return 0; |
218 | return 0; |
| 215 | } |
219 | } |
| 216 | 220 | ||
| 217 | int VMEread(int nHandle, unsigned long ulAddress, unsigned char ubAccessWidth, unsigned long ulElementCount, void *pvBuffer) |
221 | int VMEread(int nHandle, unsigned long ulAddress, unsigned char ubAccessWidth, unsigned long ulElementCount, void *pvBuffer) |
| 218 | { |
222 | { |
| 219 | VMEMM_DEVICE *dev = (VMEMM_DEVICE *)nHandle; |
223 | VMEMM_DEVICE *dev = (VMEMM_DEVICE *)nHandle; |
| 220 | size_t count = (size_t)(ulElementCount * ubAccessWidth); |
224 | size_t count = (size_t)(ulElementCount * ubAccessWidth); |
| 221 | ssize_t result; |
225 | ssize_t result; |
| 222 | int error; |
226 | int error; |
| - | 227 | long pos; |
|
| 223 | 228 | ||
| - | 229 | printf("VMEread: AW 0x%0x 0x%0x , AM 0x%0x \n", dev->cAccessWidth, ubAccessWidth, dev->cAddressModifier); |
|
| 224 | if (dev->cAccessWidth != ubAccessWidth) |
230 | if (dev->cAccessWidth != ubAccessWidth) |
| 225 | { |
231 | { |
| 226 | if ((error = setAccessProperties(nHandle, dev->cAddressModifier, ubAccessWidth))) |
232 | if ((error = setAccessProperties(nHandle, dev->cAddressModifier, ubAccessWidth))) |
| 227 | return error; |
233 | return error; |
| - | 234 | } |
|
| - | 235 | pos = lseek(dev->nFileNo, ulAddress, SEEK_SET); |
|
| - | 236 | ||
| - | 237 | if ( pos < 0){ |
|
| - | 238 | printf("VMEread: pos=0x%08lx dev->nFileNo=%d ADDR=0x%08lx %s\n",pos, dev->nFileNo, ulAddress, strerror(errno)); |
|
| - | 239 | switch (errno){ |
|
| - | 240 | case EBADF:printf("errno =EBADF\n");break; |
|
| - | 241 | case EINVAL:printf("errno =EINVAL\n");break; |
|
| - | 242 | case EOVERFLOW:printf("errno =EOVERFLOW\n");break; |
|
| - | 243 | case ESPIPE:printf("errno =ESPIPE\n");break; |
|
| - | 244 | case ENXIO:printf("errno =ENXIO\n");break; |
|
| - | 245 | } |
|
| - | 246 | //return errno; |
|
| 228 | } |
247 | } |
| 229 | 248 | ||
| 230 | if (lseek(dev->nFileNo, ulAddress, SEEK_SET) < 0) |
- | |
| 231 | return errno; |
- | |
| 232 | 249 | ||
| 233 | result = read(dev->nFileNo, pvBuffer, count); |
250 | result = read(dev->nFileNo, pvBuffer, count); |
| 234 | - | ||
| - | 251 | printf("VMEread: read %d dev->nFileNo=%d err=%d %s\n",count, dev->nFileNo, errno, strerror(errno)); |
|
| 235 | if (result != count) |
252 | if (result != count) |
| 236 | { |
253 | { |
| 237 | if (result < 0) |
254 | if (result < 0) |
| 238 | { |
255 | { |
| 239 | dev->nLastError = errno; |
256 | dev->nLastError = errno; |
| Line 250... | Line 267... | ||
| 250 | { |
267 | { |
| 251 | VMEMM_DEVICE *dev = (VMEMM_DEVICE *)nHandle; |
268 | VMEMM_DEVICE *dev = (VMEMM_DEVICE *)nHandle; |
| 252 | size_t count = (size_t)(ulElementCount * ubAccessWidth); |
269 | size_t count = (size_t)(ulElementCount * ubAccessWidth); |
| 253 | ssize_t result; |
270 | ssize_t result; |
| 254 | int error; |
271 | int error; |
| - | 272 | long pos; |
|
| 255 | 273 | ||
| - | 274 | printf("VMEwrite: AW 0x%0x 0x%0x , AM 0x%0x \n", dev->cAccessWidth, ubAccessWidth, dev->cAddressModifier); |
|
| 256 | if (dev->cAccessWidth != ubAccessWidth) |
275 | if (dev->cAccessWidth != ubAccessWidth) |
| 257 | { |
276 | { |
| 258 | if ((error = setAccessProperties(nHandle, dev->cAddressModifier, ubAccessWidth))) |
277 | if ((error = setAccessProperties(nHandle, dev->cAddressModifier, ubAccessWidth))) |
| 259 | return error; |
278 | return error; |
| 260 | } |
279 | } |
| 261 | 280 | ||
| 262 |
|
281 | pos = lseek(dev->nFileNo, ulAddress, SEEK_SET); |
| - | 282 | if (pos < 0){ |
|
| - | 283 | printf("VMEwrite: pos=0x%08lx dev->nFileNo=%d ADDR=0x%08lx %s\n",pos, dev->nFileNo, ulAddress, strerror(errno)); |
|
| - | 284 | switch (errno){ |
|
| - | 285 | case EBADF:printf("errno =EBADF\n");break; |
|
| - | 286 | case EINVAL:printf("errno =EINVAL\n");break; |
|
| - | 287 | case EOVERFLOW:printf("errno =EOVERFLOW\n");break; |
|
| - | 288 | case ESPIPE:printf("errno =ESPIPE\n");break; |
|
| - | 289 | case ENXIO:printf("errno =ENXIO\n");break; |
|
| - | 290 | } |
|
| 263 |
|
291 | //return errno; |
| 264 | 292 | } |
|
| 265 | result = write(dev->nFileNo, pvBuffer, count); |
293 | result = write(dev->nFileNo, pvBuffer, count); |
| 266 | - | ||
| - | 294 | printf("VMEwrite: write %d dev->nFileNo=%d err=%d %s\n",count, dev->nFileNo,errno, strerror(errno)); |
|
| 267 | if (result != count) |
295 | if (result != count) |
| 268 | { |
296 | { |
| 269 | if (result < 0) |
297 | if (result < 0) |
| 270 | { |
298 | { |
| 271 | dev->nLastError = errno; |
299 | dev->nLastError = errno; |
| - | 300 | ||
| 272 | return errno; |
301 | return errno; |
| 273 | } |
302 | } |
| 274 | else |
303 | else |
| 275 | return EFAULT; |
304 | return EFAULT; |
| 276 | } |
305 | } |