-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvmicvme_mdpp.c
822 lines (698 loc) · 22.4 KB
/
vmicvme_mdpp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
/*********************************************************************
Name: vmicvme.c
Created by: Pierre-Andre Amaudruz
Contents: VME interface for the VMIC VME board processor
using the mvmestd VME call convention.
$Id$
*********************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <assert.h>
#include "vmicvme_mdpp.h"
vme_bus_handle_t bus_handle;
vme_interrupt_handle_t int_handle;
struct sigevent event;
struct sigaction handler_act;
INT_INFO int_info;
mvme_size_t FullWsze (int am);
int vmic_mmap(MVME_INTERFACE *mvme, mvme_addr_t vme_addr, mvme_size_t size);
int vmic_unmap(MVME_INTERFACE *mvme, mvme_addr_t vmE_addr, mvme_size_t size);
mvme_addr_t vmic_mapcheck (MVME_INTERFACE *mvme, mvme_addr_t vme_addr, mvme_size_t n_bytes);
#define A32_CHUNK 0x08000000
/********************************************************************/
/**
Return the largest window size based on the address modifier.
For A32, VMIC cannot map a full 32bit address space.
We map it in chunks of 16 Mbytes instead
*/
mvme_size_t FullWsze (int am) {
switch (am & 0xF0) {
case 0x00:
return A32_CHUNK; // map A32 space in chunks of 16Mibytes
case 0x30:
return 0xFFFFFF; // map all of the A24 address space: 16Mibytes
case 0x20:
return 0xFFFF; // map all of the A16 address space: 64kibytes
default:
return 0;
}
}
/********************************************************************/
/**
Open a VME channel
One bus handle per crate.
@param *mvme VME structure.
@param index VME interface index
@return MVME_SUCCESS, ERROR
*/
int mvme_open(MVME_INTERFACE **mvme, int index)
{
DMA_INFO *info;
/* index can be only 0 for VMIC */
if (index != 0) {
perror("Invalid parameter (index != 0");
(*mvme)->handle = 0;
return(MVME_INVALID_PARAM);
}
/* Allocate MVME_INTERFACE */
*mvme = (MVME_INTERFACE *) calloc(1, sizeof(MVME_INTERFACE));
/* Going through init once only */
if(0 > vme_init( (vme_bus_handle_t *) &((*mvme)->handle))) {
perror("Error initializing the VMIC VMEbus");
(*mvme)->handle = 0;
return(MVME_NO_INTERFACE);
}
/* Allocte VME_TABLE */
(*mvme)->table = (char *) calloc(MAX_VME_SLOTS, sizeof(VME_TABLE));
/* Set default parameters */
(*mvme)->am = MVME_AM_DEFAULT;
/* create a default master window */
//if (vmic_mmap(*mvme, DEFAULT_SRC_ADD, FullWsze((*mvme)->am)) != MVME_SUCCESS) {
// printf("mvme_open: cannot create vme map window");
// return(MVME_ACCESS_ERROR);
//}
/* Allocate DMA_INFO */
info = (DMA_INFO *) calloc(1, sizeof(DMA_INFO));
(*mvme)->info = info;
/* Create DMA buffer */
if(0 > vme_dma_buffer_create( (vme_bus_handle_t) (*mvme)->handle
, &(info->dma_handle)
, DEFAULT_DMA_NBYTES, 0, NULL)) {
perror("Error creating the buffer");
return(ERROR);
}
if(NULL == (info->dma_ptr = vme_dma_buffer_map(
(vme_bus_handle_t) (*mvme)->handle
, info->dma_handle
, 0)))
{
perror("Error mapping the buffer");
vme_dma_buffer_release((vme_bus_handle_t) (*mvme)->handle, info->dma_handle);
return(ERROR);
}
printf("mvme_open:\n");
printf("Bus handle = 0x%x\n", (*mvme)->handle);
printf("DMA handle = 0x%x\n", (int)info->dma_handle);
printf("DMA area size = %d bytes\n", DEFAULT_DMA_NBYTES);
printf("DMA physical address = %p\n", (unsigned long *) info->dma_ptr);
return(MVME_SUCCESS);
}
/********************************************************************/
/**
Close and release ALL the opened VME channel.
@param *mvme VME structure.
@return MVME_SUCCESS, ERROR
*/
int mvme_close(MVME_INTERFACE *mvme)
{
int j;
VME_TABLE *table;
DMA_INFO *info;
table = ((VME_TABLE *)mvme->table);
info = ((DMA_INFO *)mvme->info);
// Debug
printf("mvme_close:\n");
printf("Bus handle = 0x%x\n", mvme->handle);
printf("DMA handle = 0x%x\n", (int)info->dma_handle);
printf("DMA physical address = %p\n", (unsigned long *) info->dma_ptr);
/*------------------------------------------------------------*/
/* Close DMA channel */
/*-PAA- The code below generate a crash on the VMIC7805 running
Linux 2.6.12.3. Seems to be traced to a wrong link list handling
in vme_dma.c module.
Running without deallocation seems not to cause problem for now.
Will investigate further.
status = vme_dma_buffer_unmap((vme_bus_handle_t ) mvme->handle, info->dma_handle);
if (status > 0) {
perror("Error unmapping the buffer");
}
status = vme_dma_buffer_release((vme_bus_handle_t ) mvme->handle, info->dma_handle);
if (status > 0) {
perror("Error releasing the buffer");
}
*/
/* Free info (DMA) allocation */
free (mvme->info);
/*------------------------------------------------------------*/
/* Close all the window handles */
for (j=0; j< MAX_VME_SLOTS; j++) {
if (table[j].valid) {
vme_master_window_release( (vme_bus_handle_t ) mvme->handle
, table[j].wh );
}
} // scan
/* Free table pointer */
free (mvme->table);
mvme->table = NULL;
/* close the bus handle */
if (mvme->handle != 0) {
if (0 > vme_term( (vme_bus_handle_t) mvme->handle)) {
perror("Error during VME termination");
return(MVME_ACCESS_ERROR);
}
}
/* Free mvme block */
free (mvme);
return(MVME_SUCCESS);
}
/********************************************************************/
/**
VME bus reset.
For the VMIC system this will reboot the CPU!
@param *mvme VME structure.
@return MVME_SUCCESS, ERROR
*/
int mvme_sysreset(MVME_INTERFACE *mvme)
{
if (vme_sysreset((vme_bus_handle_t )mvme->handle)) {
perror("vmeSysreset");
return MVME_ACCESS_ERROR;
}
return MVME_SUCCESS;
}
/********************************************************************/
/**
Read from VME bus. Uses MVME_BLT_BLT32 for enabling the DMA
or size to transfer larger the 128 bytes (32 DWORD)
VME access measurement on a VMIC 7805 is :
Single read access : 1us
DMA read access : 300ns / DMA latency 28us
@param *mvme VME structure
@param *dst destination pointer
@param vme_addr source address (VME location).
@param n_bytes requested transfer size.
@return MVME_SUCCESS, ERROR
*/
int mvme_read(MVME_INTERFACE *mvme, void *dst, mvme_addr_t vme_addr, mvme_size_t n_bytes)
{
int status;
/* Perform read */
/*--------------- DMA --------------*/
if ((mvme->blt_mode == MVME_BLT_BLT32) ||
(mvme->blt_mode == MVME_BLT_MBLT64) ||
(n_bytes > 127)) {
int am = mvme->am;
#ifdef DO_TIMING
struct timeval t1, t2, t3;
int dt1, dt2;
#endif
DMA_INFO *info = ((DMA_INFO*)mvme->info);
if (n_bytes >= DEFAULT_DMA_NBYTES)
{
fprintf(stderr,"mvme_read: Attempt to DMA %d bytes more than DEFAULT_DMA_NBYTES=%d\n", (int)n_bytes, DEFAULT_DMA_NBYTES);
return(ERROR);
}
if (mvme->blt_mode == MVME_BLT_BLT32)
am = MVME_AM_A24_NB;
else if (mvme->blt_mode == MVME_BLT_MBLT64)
am = MVME_AM_A24_NMBLT;
#ifdef DO_TIMING
gettimeofday(&t1,NULL);
#endif
status = vme_dma_read((vme_bus_handle_t )mvme->handle
, info->dma_handle
, 0
, vme_addr
, am
, n_bytes
, 0);
//fprintf(stderr,"dma read: addr 0x%x, am 0x%x, bytes: %d, status: %d\n", vme_addr, mvme->am, n_bytes, status);
if (status > 0) {
perror("Error reading data");
return(ERROR);
}
#ifdef DO_TIMING
gettimeofday(&t2,NULL);
#endif
memcpy(dst,info->dma_ptr,n_bytes);
#ifdef DO_TIMING
gettimeofday(&t3,NULL);
dt1 = t2.tv_usec - t1.tv_usec;
dt2 = t3.tv_usec - t2.tv_usec;
//fprintf(stderr,"dma read: addr 0x%x, am 0x%x, bytes: %d, status: %d, dma time: %d, memcpy time: %d, dma rate: %f, effective rate: %f\n", vme_addr, mvme->am, n_bytes, status, dt1, dt2, (double)n_bytes/(double)dt1,(double)n_bytes/(double)(dt1+dt2));
#endif
} else {
int i;
mvme_addr_t addr;
/*--------------- Single Access -------------*/
if( (addr = vmic_mapcheck(mvme, vme_addr, n_bytes)) == -1 ){
return(ERROR);
}
if (mvme->dmode == MVME_DMODE_D8) {
char* cdst = (char*)dst;
char* csrc = (char*)addr;
for (i=0; i<n_bytes; i+=sizeof(char))
*cdst++ = *csrc++;
} else if (mvme->dmode == MVME_DMODE_D16) {
WORD* sdst = (WORD*)dst;
WORD* ssrc = (WORD*)addr;
for (i=0; i<n_bytes; i+=sizeof(WORD))
*sdst++ = *ssrc++;
} else if (mvme->dmode == MVME_DMODE_D32) {
DWORD* ddst = (DWORD*)dst;
DWORD* dsrc = (DWORD*)addr;
for (i=0; i<n_bytes; i+=sizeof(DWORD))
*ddst++ = *dsrc++;
} else {
fprintf(stderr,"mvme_read: Invalid dmode %d\n",mvme->dmode);
return(ERROR);
}
}
return(MVME_SUCCESS);
}
/********************************************************************/
/**
Read single data from VME bus.
@param *mvme VME structure
@param vme_addr source address (VME location).
@return value return VME data
*/
DWORD mvme_read_value(MVME_INTERFACE *mvme, mvme_addr_t vme_addr)
{
mvme_addr_t addr;
DWORD dst = 0xFFFFFFFF;
if( (addr = vmic_mapcheck(mvme, vme_addr, 4)) == -1 ){
return(0);
}
/* Perform read */
if (mvme->dmode == MVME_DMODE_D8)
dst = *((char *)addr);
else if (mvme->dmode == MVME_DMODE_D16)
dst = *((WORD *)addr);
else if (mvme->dmode == MVME_DMODE_D32)
dst = *((DWORD *)addr);
return(dst);
}
/********************************************************************/
/**
Write data to VME bus. Uses MVME_BLT_BLT32 for enabling the DMA
or size to transfer larger the 128 bytes (32 DWORD)
@param *mvme VME structure
@param vme_addr source address (VME location).
@param *src source array
@param n_bytes size of the array in bytes
@return MVME_SUCCESS, MVME_ACCESS_ERROR
*/
int mvme_write(MVME_INTERFACE *mvme, mvme_addr_t vme_addr, void *src, mvme_size_t n_bytes)
{
/* Perform write */
/*--------------- DMA --------------*/
if ((mvme->blt_mode == MVME_BLT_BLT32) ||
(mvme->blt_mode == MVME_BLT_MBLT64) ||
(n_bytes > 127)) {
DMA_INFO *info = ((DMA_INFO *)mvme->info);
if (n_bytes >= DEFAULT_DMA_NBYTES)
{
fprintf(stderr,"mvme_write: Attempt to DMA %d bytes more than DEFAULT_DMA_NBYTES=%d\n", (int)n_bytes, DEFAULT_DMA_NBYTES);
return(ERROR);
}
memcpy(info->dma_ptr, src, n_bytes);
if(0 > vme_dma_write((vme_bus_handle_t )mvme->handle
, info->dma_handle
, 0
, vme_addr
, mvme->am
, n_bytes
, 0)) {
perror("Error writing data");
return(MVME_ACCESS_ERROR);
}
} else {
int i;
mvme_addr_t addr;
/*--------------- Single Access -------------*/
if( (addr = vmic_mapcheck(mvme, vme_addr, n_bytes)) == -1 ){
return(ERROR);
}
/* Perform write */
if (mvme->dmode == MVME_DMODE_D8) {
char*dst = (char*)addr;
char*sss = (char*)src;
for (i=0; i<n_bytes; i+=sizeof(char))
*dst++ = *sss++;
} else if (mvme->dmode == MVME_DMODE_D16) {
WORD*dst = (WORD*)addr;
WORD*sss = (WORD*)src;
for (i=0; i<n_bytes; i+=sizeof(WORD))
*dst++ = *sss++;
} else if (mvme->dmode == MVME_DMODE_D32) {
DWORD*dst = (DWORD*)addr;
DWORD*sss = (DWORD*)src;
for (i=0; i<n_bytes; i+=sizeof(DWORD))
*dst++ = *sss++;
} else {
fprintf(stderr,"mvme_write: Invalid dmode %d\n",mvme->dmode);
return(ERROR);
}
}
return MVME_SUCCESS;
}
/********************************************************************/
/**
Write single data to VME bus.
@param *mvme VME structure
@param vme_addr destination address (VME location).
@param value data to write to the VME address.
@return MVME_SUCCESS
*/
int mvme_write_value(MVME_INTERFACE *mvme, mvme_addr_t vme_addr, DWORD value)
{
mvme_addr_t addr;
if( (addr = vmic_mapcheck(mvme, vme_addr, 4)) == -1 ){
return(ERROR);
}
/* Perform write */
if (mvme->dmode == MVME_DMODE_D8)
*((char *)addr) = (char) (value & 0xFF);
else if (mvme->dmode == MVME_DMODE_D16)
*((WORD *)addr) = (WORD) (value & 0xFFFF);
else if (mvme->dmode == MVME_DMODE_D32)
*((DWORD *)addr) = value;
return MVME_SUCCESS;
}
/********************************************************************/
int mvme_set_am(MVME_INTERFACE *mvme, int am)
{
mvme->am = am;
return MVME_SUCCESS;
}
/********************************************************************/
int EXPRT mvme_get_am(MVME_INTERFACE *mvme, int *am)
{
*am = mvme->am;
return MVME_SUCCESS;
}
/********************************************************************/
int mvme_set_dmode(MVME_INTERFACE *mvme, int dmode)
{
mvme->dmode = dmode;
return MVME_SUCCESS;
}
/********************************************************************/
int mvme_get_dmode(MVME_INTERFACE *mvme, int *dmode)
{
*dmode = mvme->dmode;
return MVME_SUCCESS;
}
/********************************************************************/
int mvme_set_blt(MVME_INTERFACE *mvme, int mode)
{
mvme->blt_mode = mode;
return MVME_SUCCESS;
}
/********************************************************************/
int mvme_get_blt(MVME_INTERFACE *mvme, int *mode)
{
*mode = mvme->blt_mode;
return MVME_SUCCESS;
}
/********************************************************************/
/*
static void myisr(int sig, siginfo_t * siginfo, void *extra)
{
fprintf(stderr, "myisr interrupt received \n");
fprintf(stderr, "interrupt: level:%d Vector:0x%x\n", int_info.level, siginfo->si_value.sival_int & 0xFF);
}
*/
/********************************************************************/
int mvme_interrupt_generate(MVME_INTERFACE *mvme, int level, int vector, void *info)
{
if (vme_interrupt_generate((vme_bus_handle_t )mvme->handle, level, vector)) {
perror("vme_interrupt_generate");
return MVME_ERROR;
}
return MVME_SUCCESS;
}
/********************************************************************/
/**
<code>
static void handler(int sig, siginfo_t * siginfo, void *extra)
{
print_intr_msg(level, siginfo->si_value.sival_int);
done = 0;
}
</endcode>
*/
int mvme_interrupt_attach(MVME_INTERFACE *mvme, int level, int vector
, void (*isr)(int, void*, void *), void *info)
{
struct sigevent event;
struct sigaction handler_act;
/* Set up sigevent struct */
event.sigev_signo = SIGIO;
event.sigev_notify = SIGEV_SIGNAL;
event.sigev_value.sival_int = 0;
/* Install the signal handler */
sigemptyset(&handler_act.sa_mask);
handler_act.sa_sigaction = (void*)isr;
handler_act.sa_flags = SA_SIGINFO;
if (sigaction(SIGIO, &handler_act, NULL)) {
perror("sigaction");
return -1;
}
int_info.flags = *((unsigned int *) info);
if (vme_interrupt_attach((vme_bus_handle_t )mvme->handle
, &int_handle, level, vector
, int_info.flags, &event)) {
perror("vme_interrupt_attach");
return -1;
}
int_info.handle = int_handle;
int_info.level = level;
int_info.vector = vector;
return MVME_SUCCESS;
}
/********************************************************************/
int mvme_interrupt_detach(MVME_INTERFACE *mvme, int level, int vector, void *info)
{
if (int_info.handle) {
if (vme_interrupt_release((vme_bus_handle_t )mvme->handle
, int_info.handle)) {
perror("vme_interrupt_release");
return -1;
}
}
return MVME_SUCCESS;
}
/********************************************************************/
int mvme_interrupt_enable(MVME_INTERFACE *mvme, int level, int vector, void *info)
{
// vme_interrupt_enable((vme_bus_handle_t )mvme->handle,
// int_info.handle);
return MVME_SUCCESS;
}
/********************************************************************/
int mvme_interrupt_disable(MVME_INTERFACE *mvme, int level, int vector, void *info)
{
return MVME_SUCCESS;
}
/********************************************************************/
/**
VME Memory map, uses the driver MVME_INTERFACE for storing the map information.
@param *mvme VME structure
@param vme_addr source address (VME location).
@param n_bytes data to write
@return MVME_SUCCESS, MVME_ACCESS_ERROR
*/
int vmic_mmap(MVME_INTERFACE *mvme, mvme_addr_t vme_addr, mvme_size_t n_bytes)
{
int j;
void *phys_addr = NULL;
VME_TABLE *table;
table = (VME_TABLE *) mvme->table;
/* Find new slot */
j=0;
while (table[j].valid) j++;
if (j < MAX_VME_SLOTS) {
/* Create a new window */
table[j].low = vme_addr;
table[j].am = ((mvme->am == 0) ? MVME_AM_DEFAULT : mvme->am);
table[j].nbytes = n_bytes;
/* Create master window */
if(0 > vme_master_window_create( (vme_bus_handle_t )mvme->handle
, &(table[j].wh)
, table[j].low
, table[j].am
, table[j].nbytes
, VME_CTL_PWEN
, NULL) ) {
perror("Error creating the window");
return(MVME_ACCESS_ERROR);
}
/* Create the mapped window */
if(NULL == (table[j].ptr = (DWORD *)vme_master_window_map((vme_bus_handle_t )mvme->handle, table[j].wh, 0) ) ) {
perror("Error mapping the window");
vme_master_window_release( (vme_bus_handle_t )mvme->handle
, table[j].wh );
/* Cleanup slot */
table[j].wh = 0;
return(MVME_ACCESS_ERROR);
}
if (NULL == (phys_addr = vme_master_window_phys_addr ((vme_bus_handle_t )mvme->handle, table[j].wh)))
{
perror ("vme_master_window_phys_addr");
}
fprintf(stderr, "vmic_mmap: Mapped VME AM 0x%02x addr 0x%08x size 0x%08x at address %p\n", table[j].am, (int)vme_addr, (int)n_bytes, phys_addr);
table[j].valid = 1;
table[j].high = (table[j].low + table[j].nbytes);
}
else {
/* No more slot available */
return(MVME_ACCESS_ERROR);
}
return(MVME_SUCCESS);
}
/********************************************************************/
/**
Unmap VME region.
VME Memory map, uses the driver MVME_INTERFACE for storing the map information.
@param *mvme VME structure
@param nbytes requested transfer size.
@return MVME_SUCCESS, ERROR
*/
int vmic_unmap(MVME_INTERFACE *mvme, mvme_addr_t vme_addr, mvme_size_t size)
{
int j;
VME_TABLE *table;
table = (VME_TABLE *) mvme->table;
/* Search for map window */
for (j=0; table[j].valid; j++) {
/* Check the vme address range */
if ((vme_addr == table[j].low) && ((vme_addr+size) == table[j].high)) {
/* window found */
break;
}
}
if (!table[j].valid) {
/* address not found => nothing to do */
return(MVME_SUCCESS);
}
/* Remove map */
if (table[j].ptr) {
if (0 > vme_master_window_unmap ((vme_bus_handle_t )mvme->handle, table[j].wh)) {
perror ("vme_master_window_unmap");
return(ERROR);
}
if (0 > vme_master_window_release ((vme_bus_handle_t )mvme->handle, table[j].wh)) {
perror ("vme_master_window_release");
return(ERROR);
}
}
/* Cleanup slot */
table[j].wh = 0;
return(MVME_SUCCESS);
}
/********************************************************************/
/**
Retrieve mapped address from mapped table.
Check if the given address belongs to an existing map. If not will
create a new map based on the address, current address modifier and
the given size in bytes.
@param *mvme VME structure
@param nbytes requested transfer size.
@return MVME_SUCCESS, ERROR
*/
mvme_addr_t vmic_mapcheck (MVME_INTERFACE *mvme, mvme_addr_t vme_addr, mvme_size_t n_bytes)
{
int j;
VME_TABLE *table;
mvme_addr_t addr;
table = (VME_TABLE *) mvme->table;
/* Extract window handle from table based on the VME address to read */
for (j=0; table[j].valid; j++) {
/* Check for the proper am */
if (mvme->am != table[j].am)
continue;
/* Check the vme address range */
if ((vme_addr >= table[j].low) && ((vme_addr+n_bytes) < table[j].high)) {
/* valid range */
break;
}
}
// scan table
/* Check if handle found or need to create new one */
if (!table[j].valid) {
/* Adjust vme_addr start point (split in quarters) */
if (vme_addr >= A32_CHUNK)
// addr = vme_addr & (~A32_CHUNK);
addr = vme_addr & 0xF8000000;
else
addr = 0x00000000;
/* Create a new window */
if (vmic_mmap(mvme, addr, FullWsze(mvme->am)) != MVME_SUCCESS) {
perror("cannot create vme map window");
return(-1);
//abort(); // cannot return anything!
}
}
/* Get index in table in case new mapping has been requested */
for (j=0; table[j].valid; j++) {
/* Check for the proper am */
if (mvme->am != table[j].am)
continue;
/* Check the vme address range */
if ((vme_addr >= table[j].low) && ((vme_addr+n_bytes) < table[j].high)) {
/* valid range */
break;
}
} // scan table
if (!table[j].valid) {
perror("Map not found");
abort(); // cannot return anything!
}
addr = (mvme_addr_t) (table[j].ptr) + (mvme_addr_t) (vme_addr - table[j].low);
return addr;
}
/********************************************************************/
/*-PAA- For test purpose only
Allows code testing, in this case, the VMEIO board has been used. */
#ifdef MAIN_ENABLE
int main () {
int status;
int myinfo = VME_INTERRUPT_SIGEVENT;
MVME_INTERFACE *myvme;
int vmeio_status;
/* Open VME channel */
status = mvme_open(&myvme, 0);
/* Reset VME */
// status = mvme_sysreset(myvme);
/* Setup AM */
status = mvme_set_am(myvme, 0x09);
/* Setup Data size */
status = mvme_set_dmode(myvme, MVME_DMODE_D32);
/* Read VMEIO status */
status = mvme_read(myvme, &vmeio_status, 0x4078001C, 4);
printf("VMEIO status : 0x%x\n", vmeio_status);
/* Write Single value */
mvme_write_value(myvme, 0x40780010, 0x0);
/* Read Single Value */
printf("Value : 0x%lx\n", mvme_read_value(myvme, 0x40780018));
/* Write Single value */
mvme_write_value(myvme, 0x40780010, 0x3);
/* Read Single Value */
printf("Value : 0x%lx\n", mvme_read_value(myvme, 0x40780018));
/* Write Single value */
mvme_write_value(myvme, 0x40780008, 0xF);
/* Write to the VMEIO in pulse mode */
// data = 0xF;
// for (;;) {
// status = mvme_write(myvme, 0x78000C, &data, 4);
// status = mvme_write(myvme, 0x78000C, &data, 4);
// }
//------------ Interrupt section
// IRQ 7, vector from switch 0x0 -> 0x80 -> ch 0 source
mvme_interrupt_attach(myvme, 7, 0x10, myisr, &myinfo);
// for (;;) {
// }
// mvme_interrupt_enable(myvme, 1, 0x00, &myinfo);
// mvme_interrupt_disable(myvme, 1, 0x00, &myinfo);
mvme_interrupt_generate(myvme, 7, 0x10, &myinfo);
// mvme_interrupt_detach(myvme, 1, 0x00, &myinfo);
/* Close VME channel */
status = mvme_close(myvme);
return 1;
}
#endif