/
tmk1553.c
3909 lines (3608 loc) · 94.1 KB
/
tmk1553.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
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* tmk1553b.c -- the tmk1553b v4.06 char module. (c) ELCUS, 2002,2011.
*
* Part of this code comes from the book "Linux Device Drivers"
* by Alessandro Rubini and Jonathan Corbet, published
* by O'Reilly & Associates.
*/
#define TMK_VER_HI 4
#define TMK_VER_LO 06
#ifndef __KERNEL__
# define __KERNEL__
#endif
#ifndef MODULE
# define MODULE
#endif
#ifndef TMK1553B_NOCONFIGH
#include <linux/config.h>
#endif
#ifdef CONFIG_SMP
#define __SMP__
#endif
#ifdef CONFIG_64BIT
#define __64BIT__
#endif
//#if CONFIG_MODVERSIONS==1
//#define MODVERSIONS
//#include <linux/modversions.h>
//#endif
#include <linux/version.h>
#include <linux/module.h>
#include <linux/kernel.h> /* printk() */
#include <linux/slab.h> /* kmalloc() */
#include <linux/fs.h> /* everything... */
#include <linux/errno.h> /* error codes */
#include <linux/types.h> /* size_t */
#include <linux/proc_fs.h>
#include <linux/fcntl.h> /* O_ACCMODE */
//#include <asm/system.h> /* cli(), *_flags */
#include <linux/ioport.h>
#include <linux/wait.h>
#include <linux/sched.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <asm/io.h>
#include <linux/pci.h>
#include <linux/miscdevice.h>
//#include <asm/msr.h>
#ifndef KERNEL_VERSION
#define KERNEL_VERSION(a,b,c) ((a)*65536+(b)*256+(c))
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
#include <linux/kcomp.h>
#define spin_lock_bh(lock) do {start_bh_atomic(); spin_lock(lock);} while(0)
#define spin_unlock_bh(lock) do {spin_unlock(lock); end_bh_atomic();} while(0)
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
#define LINUX26
#endif
#ifndef LINUX26
#define IRQ_NONE
#define IRQ_HANDLED
#define IRQRETURN_T void
#else
#define IRQRETURN_T irqreturn_t
#endif
#ifndef EXPORT_NO_SYMBOLS
#define EXPORT_NO_SYMBOLS
#endif
#ifndef SET_MODULE_OWNER
#define SET_MODULE_OWNER(some_struct) do { } while (0)
#endif
#ifndef IRQF_DISABLED
#define IRQF_DISABLED 0
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)
#include <linux/sched/signal.h>
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0)
#include <linux/uaccess.h>
#else
#include <asm/uaccess.h>
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0)
#define wait_queue_t wait_queue_entry_t
#endif
//#define DBG 1
//#define MY_DBG
//#define MY_DBG_DPC
//#ifdef CONFIG_DEVFS_FS
//#define MY_CONFIG_DEVFS_FS
//#endif
#ifdef MY_DBG
#define MY_KERN_DEBUG KERN_EMERG
#define MY_KERN_INFO KERN_EMERG
#define MY_KERN_WARNING KERN_EMERG
#else
#define MY_KERN_DEBUG KERN_DEBUG
#define MY_KERN_INFO KERN_INFO
#define MY_KERN_WARNING KERN_WARNING
#endif // def MY_DBG
typedef void* PVOID;
typedef u32 UINT;
typedef u32* PUINT;
typedef u16 USHORT;
typedef u16* PUSHORT;
typedef u8 UCHAR;
typedef u8* PUCHAR;
typedef int HANDLE;
typedef int NTSTATUS;
typedef int PKEVENT;
typedef int PEPROCESS;
#define IN
#define OUT
#define TRUE 1
#define FALSE 0
#ifdef TMK1553B_THREADS
#define pid group_leader->pid
#endif
#include "tmk1553b.h" /* local definitions */
int fTMKInit = 0;
UINT tmkNumber;
#define MAX_TMK_NUMBER 7
#define MAX_RT_NUMBER (30-MAX_TMK_NUMBER-1)
#define MAX_VTMK_NUMBER (MAX_TMK_NUMBER+1+MAX_RT_NUMBER)
#define MAX_LOAD_TYPE 7
int nMaxTmkNumber = MAX_TMK_NUMBER;
#define MRT_READ_BRC_DATA 1
#define MRT_WRITE_BRC_DATA 1
UINT adwTmkOptions[MAX_TMK_NUMBER+1+MAX_RT_NUMBER+1];
unsigned short awBrcRxState[MAX_TMK_NUMBER+1][32*4];
unsigned short awBrcRxBuf[MAX_TMK_NUMBER+1][32*32];
typedef struct
{
short nType;
char szName[10];
unsigned short wPorts1;
unsigned short wPorts2;
unsigned short wIrq1;
unsigned short wIrq2;
unsigned short wIODelay;
unsigned short wHiddenPorts;
int nTmk;
int fLoaded;
int nLoadType;
int fIrqShared;
int nDev;
int nSubDev;
int fLocalReadInt;
int fMRT;
int nPorts;
} TTmkConfig;
TTmkConfig aTmkConfig[MAX_TMK_NUMBER+1];
typedef struct
{
struct list_head ProcListEntry;
PEPROCESS hProc;
int fTMK[MAX_TMK_NUMBER+1+MAX_RT_NUMBER+1];
int nSelectedTMK;
u32 maskTMK[(MAX_VTMK_NUMBER)/32+1];
u32 maskEvents[(MAX_VTMK_NUMBER)/32+1];
wait_queue_head_t wq;
int waitFlag;
} TListProc;
struct list_head hlProc;
//HPROC hTmkVM[MAX_TMK_NUMBER+1];
PEPROCESS hCurProc;
TListProc *hlnCurProc;
typedef struct
{
PEPROCESS hProc;
PKEVENT hEvent;
TListProc *hlnProc;
} TTMK;
TTMK aTMK[MAX_TMK_NUMBER+1+MAX_RT_NUMBER+1];
typedef struct
{
int nInt;
USHORT wMode;
USHORT awEvData[3];
PEPROCESS hProc;
} TListEvD, *pTListEvD;
//pTListEvD ahlEvData[MAX_TMK_NUMBER+1];
//pTListEvD hlnEvData;
//VMMLIST ahlEvData[MAX_TMK_NUMBER+1];
//VMMLISTNODE hlnEvData;
spinlock_t tmkIrqSpinLock, tmkSpinLock;
void tmkDpcRoutine(unsigned long);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
DECLARE_TASKLET (tmkDpc, tmkDpcRoutine, 0);
#endif
IRQRETURN_T tmkInterruptServiceRoutine(int irq, void *dev_id
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21)
, struct pt_regs *regs
#endif
);
// 2^^n only !
#define EVENTS_SIZE 512
TListEvD aEvData[MAX_TMK_NUMBER+1+MAX_RT_NUMBER+1][EVENTS_SIZE];
int iEvDataBegin[MAX_TMK_NUMBER+1+MAX_RT_NUMBER+1];
int iEvDataEnd[MAX_TMK_NUMBER+1+MAX_RT_NUMBER+1];
int cEvData[MAX_TMK_NUMBER+1+MAX_RT_NUMBER+1];
int cDpcData[MAX_TMK_NUMBER+1+MAX_RT_NUMBER+1];
volatile int tmkEvents[(MAX_VTMK_NUMBER)/32+1];
typedef struct
{
int nIrq;
int cTmks;
int hTmk[MAX_TMK_NUMBER+1];
} TIrq;
TIrq ahIrq[MAX_TMK_NUMBER+1];
int cIrqs = 0;
int nmrt, nrtmax;
char *szTmk1553b = "tmk1553b";
int tmk1553b_nr_devs = TMK1553B_NR_DEVS; /* number of bare tmk1553b devices */
static int major = TMK1553B_MAJOR;
static char *name = 0;
static int misc = 0;
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,3)
module_param(major, int, 0);
MODULE_PARM_DESC(major, "Major number");
module_param(name, charp, 0);
MODULE_PARM_DESC(name, "Device name");
module_param(misc, int, 0);
MODULE_PARM_DESC(major, "Misc device flag");
#else
MODULE_PARM(major,"i");
MODULE_PARM(name,"s");
MODULE_PARM(misc,"i");
//MODULE_PARM(tmk1553b_nr_devs,"i");
#endif
static int a0 = 0xFFFF;
static int b0 = 0xFFFF;
static int i0 = 0xFF;
static int d0 = 0;
static int e0 = 0;
static char *t0 = 0;
static char *l0 = 0;
static int a1 = 0xFFFF;
static int b1 = 0xFFFF;
static int i1 = 0xFF;
static int d1 = 0;
static int e1 = 0;
static char *t1 = 0;
static char *l1 = 0;
static int a2 = 0xFFFF;
static int b2 = 0xFFFF;
static int i2 = 0xFF;
static int d2 = 0;
static int e2 = 0;
static char *t2 = 0;
static char *l2 = 0;
static int a3 = 0xFFFF;
static int b3 = 0xFFFF;
static int i3 = 0xFF;
static int d3 = 0;
static int e3 = 0;
static char *t3 = 0;
static char *l3 = 0;
static int a4 = 0xFFFF;
static int b4 = 0xFFFF;
static int i4 = 0xFF;
static int d4 = 0;
static int e4 = 0;
static char *t4 = 0;
static char *l4 = 0;
static int a5 = 0xFFFF;
static int b5 = 0xFFFF;
static int i5 = 0xFF;
static int d5 = 0;
static int e5 = 0;
static char *t5 = 0;
static char *l5 = 0;
static int a6 = 0xFFFF;
static int b6 = 0xFFFF;
static int i6 = 0xFF;
static int d6 = 0;
static int e6 = 0;
static char *t6 = 0;
static char *l6 = 0;
static int a7 = 0xFFFF;
static int b7 = 0xFFFF;
static int i7 = 0xFF;
static int d7 = 0;
static int e7 = 0;
static char *t7 = 0;
static char *l7 = 0;
static int nrt = 0;
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,3)
module_param(a0, int, 0);
module_param(b0, int, 0);
module_param(i0, int, 0);
module_param(d0, int, 0);
module_param(e0, int, 0);
module_param(t0, charp, 0);
module_param(l0, charp, 0);
module_param(a1, int, 0);
module_param(b1, int, 0);
module_param(i1, int, 0);
module_param(d1, int, 0);
module_param(e1, int, 0);
module_param(t1, charp, 0);
module_param(l1, charp, 0);
module_param(a2, int, 0);
module_param(b2, int, 0);
module_param(i2, int, 0);
module_param(d2, int, 0);
module_param(e2, int, 0);
module_param(t2, charp, 0);
module_param(l2, charp, 0);
module_param(a3, int, 0);
module_param(b3, int, 0);
module_param(i3, int, 0);
module_param(d3, int, 0);
module_param(e3, int, 0);
module_param(t3, charp, 0);
module_param(l3, charp, 0);
module_param(a4, int, 0);
module_param(b4, int, 0);
module_param(i4, int, 0);
module_param(d4, int, 0);
module_param(e4, int, 0);
module_param(t4, charp, 0);
module_param(l4, charp, 0);
module_param(a5, int, 0);
module_param(b5, int, 0);
module_param(i5, int, 0);
module_param(d5, int, 0);
module_param(e5, int, 0);
module_param(t5, charp, 0);
module_param(l5, charp, 0);
module_param(a6, int, 0);
module_param(b6, int, 0);
module_param(i6, int, 0);
module_param(d6, int, 0);
module_param(e6, int, 0);
module_param(t6, charp, 0);
module_param(l6, charp, 0);
module_param(a7, int, 0);
module_param(b7, int, 0);
module_param(i7, int, 0);
module_param(d7, int, 0);
module_param(e7, int, 0);
module_param(t7, charp, 0);
module_param(l7, charp, 0);
module_param(nrt, int, 0);
MODULE_PARM_DESC(a0,"ISA addr1 device 0");
MODULE_PARM_DESC(b0,"ISA addr2 device 0");
MODULE_PARM_DESC(i0,"ISA interrupt device 0");
MODULE_PARM_DESC(d0,"PCI card number device 0");
MODULE_PARM_DESC(e0,"PCI device on PCI card number device 0");
MODULE_PARM_DESC(t0,"Device type device 0");
MODULE_PARM_DESC(l0,"Device load device 0");
MODULE_PARM_DESC(a1,"ISA addr1 device 1");
MODULE_PARM_DESC(b1,"ISA addr2 device 1");
MODULE_PARM_DESC(i1,"ISA interrupt device 1");
MODULE_PARM_DESC(d1,"PCI card number device 1");
MODULE_PARM_DESC(e1,"PCI device on PCI card number device 1");
MODULE_PARM_DESC(t1,"Device type device 1");
MODULE_PARM_DESC(l1,"Device load device 1");
MODULE_PARM_DESC(a2,"ISA addr1 device 2");
MODULE_PARM_DESC(b2,"ISA addr2 device 2");
MODULE_PARM_DESC(i2,"ISA interrupt device 2");
MODULE_PARM_DESC(d2,"PCI card number device 2");
MODULE_PARM_DESC(e2,"PCI device on PCI card number device 2");
MODULE_PARM_DESC(t2,"Device type device 2");
MODULE_PARM_DESC(l2,"Device load device 2");
MODULE_PARM_DESC(a3,"ISA addr1 device 3");
MODULE_PARM_DESC(b3,"ISA addr2 device 3");
MODULE_PARM_DESC(i3,"ISA interrupt device 3");
MODULE_PARM_DESC(d3,"PCI card number device 3");
MODULE_PARM_DESC(e3,"PCI device on PCI card number device 3");
MODULE_PARM_DESC(t3,"Device type device 3");
MODULE_PARM_DESC(l3,"Device load device 3");
MODULE_PARM_DESC(a4,"ISA addr1 device 4");
MODULE_PARM_DESC(b4,"ISA addr2 device 4");
MODULE_PARM_DESC(i4,"ISA interrupt device 4");
MODULE_PARM_DESC(d4,"PCI card number device 4");
MODULE_PARM_DESC(e4,"PCI device on PCI card number device 4");
MODULE_PARM_DESC(t4,"Device type device 4");
MODULE_PARM_DESC(l4,"Device load device 4");
MODULE_PARM_DESC(a5,"ISA addr1 device 5");
MODULE_PARM_DESC(b5,"ISA addr2 device 5");
MODULE_PARM_DESC(i5,"ISA interrupt device 5");
MODULE_PARM_DESC(d5,"PCI card number device 5");
MODULE_PARM_DESC(e5,"PCI device on PCI card number device 5");
MODULE_PARM_DESC(t5,"Device type device 5");
MODULE_PARM_DESC(l5,"Device load device 5");
MODULE_PARM_DESC(a6,"ISA addr1 device 6");
MODULE_PARM_DESC(b6,"ISA addr2 device 6");
MODULE_PARM_DESC(i6,"ISA interrupt device 6");
MODULE_PARM_DESC(d6,"PCI card number device 6");
MODULE_PARM_DESC(e6,"PCI device on PCI card number device 6");
MODULE_PARM_DESC(t6,"Device type device 6");
MODULE_PARM_DESC(l6,"Device load device 6");
MODULE_PARM_DESC(a7,"ISA addr1 device 7");
MODULE_PARM_DESC(b7,"ISA addr2 device 7");
MODULE_PARM_DESC(i7,"ISA interrupt device 7");
MODULE_PARM_DESC(d7,"PCI card number device 7");
MODULE_PARM_DESC(e7,"PCI device on PCI card number device 7");
MODULE_PARM_DESC(t7,"Device type device 7");
MODULE_PARM_DESC(l7,"Device load device 7");
MODULE_PARM_DESC(nrt,"Maximum number of RTs per MultiRT device");
#else
MODULE_PARM(a0,"i");
MODULE_PARM(b0,"i");
MODULE_PARM(i0,"i");
MODULE_PARM(d0,"i");
MODULE_PARM(e0,"i");
MODULE_PARM(t0,"s");
MODULE_PARM(l0,"s");
MODULE_PARM(a1,"i");
MODULE_PARM(b1,"i");
MODULE_PARM(i1,"i");
MODULE_PARM(d1,"i");
MODULE_PARM(e1,"i");
MODULE_PARM(t1,"s");
MODULE_PARM(l1,"s");
MODULE_PARM(a2,"i");
MODULE_PARM(b2,"i");
MODULE_PARM(i2,"i");
MODULE_PARM(d2,"i");
MODULE_PARM(e2,"i");
MODULE_PARM(t2,"s");
MODULE_PARM(l2,"s");
MODULE_PARM(a3,"i");
MODULE_PARM(b3,"i");
MODULE_PARM(i3,"i");
MODULE_PARM(d3,"i");
MODULE_PARM(e3,"i");
MODULE_PARM(t3,"s");
MODULE_PARM(l3,"s");
MODULE_PARM(a4,"i");
MODULE_PARM(b4,"i");
MODULE_PARM(i4,"i");
MODULE_PARM(d4,"i");
MODULE_PARM(e4,"i");
MODULE_PARM(t4,"s");
MODULE_PARM(l4,"s");
MODULE_PARM(a5,"i");
MODULE_PARM(b5,"i");
MODULE_PARM(i5,"i");
MODULE_PARM(d5,"i");
MODULE_PARM(e5,"i");
MODULE_PARM(t5,"s");
MODULE_PARM(l5,"s");
MODULE_PARM(a6,"i");
MODULE_PARM(b6,"i");
MODULE_PARM(i6,"i");
MODULE_PARM(d6,"i");
MODULE_PARM(e6,"i");
MODULE_PARM(t6,"s");
MODULE_PARM(l6,"s");
MODULE_PARM(a7,"i");
MODULE_PARM(b7,"i");
MODULE_PARM(i7,"i");
MODULE_PARM(d7,"i");
MODULE_PARM(e7,"i");
MODULE_PARM(t7,"s");
MODULE_PARM(l7,"s");
MODULE_PARM(nrt,"i");
#endif
MODULE_AUTHOR("Yury Savchuk");
MODULE_DESCRIPTION("Driver for ELCUS (http://www.elcus.ru) MIL-STD-1553B boards");
tmk1553b_Dev *tmk1553b_devices; /* allocated in tmk1553b_init_module */
static struct miscdevice tmk1553b_mdev;
#include "tmklllin.h"
UINT TMK_tmkgetmaxn(void);
UINT TMK_tmkconfig(void);
UINT TMK_tmkdone(void);
UINT TMK_tmkselect(void);
UINT TMK_tmkselected(void);
UINT TMK_tmkgetmode(void);
UINT TMK_tmksetcwbits(void);
UINT TMK_tmkclrcwbits(void);
UINT TMK_tmkgetcwbits(void);
UINT TMK_tmkwaitevents(void);
//UINT TMK_tmkdefevent(void);
UINT TMK_tmkgetevd(void);
//UINT TMK_bcdefintnorm(void);
//UINT TMK_bcdefintexc(void);
//UINT TMK_bcdefintx(void);
//UINT TMK_bcdefintsig(void);
UINT TMK_bcreset(void);
UINT TMK_bc_def_tldw(void);
UINT TMK_bc_enable_di(void);
UINT TMK_bc_disable_di(void);
UINT TMK_bcdefirqmode(void);
UINT TMK_bcgetirqmode(void);
UINT TMK_bcgetmaxbase(void);
UINT TMK_bcdefbase(void);
UINT TMK_bcgetbase(void);
UINT TMK_bcputw(void);
UINT TMK_bcgetw(void);
UINT TMK_bcgetansw(void);
UINT TMK_bcputblk(void);
UINT TMK_bcgetblk(void);
UINT TMK_bcdefbus(void);
UINT TMK_bcgetbus(void);
UINT TMK_bcstart(void);
UINT TMK_bcstartx(void);
UINT TMK_bcdeflink(void);
UINT TMK_bcgetlink(void);
UINT TMK_bcstop(void);
UINT TMK_bcgetstate(void);
//UINT TMK_rtdefintcmd(void);
//UINT TMK_rtdefinterr(void);
//UINT TMK_rtdefintdata(void);
UINT TMK_rtreset(void);
UINT TMK_rtdefirqmode(void);
UINT TMK_rtgetirqmode(void);
UINT TMK_rtdefmode(void);
UINT TMK_rtgetmode(void);
UINT TMK_rtgetmaxpage(void);
UINT TMK_rtdefpage(void);
UINT TMK_rtgetpage(void);
UINT TMK_rtdefpagepc(void);
UINT TMK_rtdefpagebus(void);
UINT TMK_rtgetpagepc(void);
UINT TMK_rtgetpagebus(void);
UINT TMK_rtdefaddress(void);
UINT TMK_rtgetaddress(void);
UINT TMK_rtdefsubaddr(void);
UINT TMK_rtgetsubaddr(void);
UINT TMK_rtputw(void);
UINT TMK_rtgetw(void);
UINT TMK_rtputblk(void);
UINT TMK_rtgetblk(void);
UINT TMK_rtsetanswbits(void);
UINT TMK_rtclranswbits(void);
UINT TMK_rtgetanswbits(void);
UINT TMK_rtgetflags(void);
UINT TMK_rtputflags(void);
UINT TMK_rtsetflag(void);
UINT TMK_rtclrflag(void);
UINT TMK_rtgetflag(void);
UINT TMK_rtgetstate(void);
UINT TMK_rtbusy(void);
UINT TMK_rtlock(void);
UINT TMK_rtunlock(void);
UINT TMK_rtgetcmddata(void);
UINT TMK_rtputcmddata(void);
//UINT TMK_mtdefintx(void);
//UINT TMK_mtdefintsig(void);
UINT TMK_mtreset(void);
#define TMK_mtdefirqmode TMK_bcdefirqmode
#define TMK_mtgetirqmode TMK_bcgetirqmode
#define TMK_mtgetmaxbase TMK_bcgetmaxbase
#define TMK_mtdefbase TMK_bcdefbase
#define TMK_mtgetbase TMK_bcgetbase
#define TMK_mtputw TMK_bcputw
#define TMK_mtgetw TMK_bcgetw
UINT TMK_mtgetsw(void);
#define TMK_mtputblk TMK_bcputblk
#define TMK_mtgetblk TMK_bcgetblk
#define TMK_mtstartx TMK_bcstartx
#define TMK_mtdeflink TMK_bcdeflink
#define TMK_mtgetlink TMK_bcgetlink
#define TMK_mtstop TMK_bcstop
#define TMK_mtgetstate TMK_bcgetstate
UINT TMK_tmkgetinfo(void);
UINT TMK_getversion(void);
UINT TMK_rtenable(void);
UINT TMK_mrtgetmaxn(void);
UINT TMK_mrtconfig(void);
UINT TMK_mrtselected(void);
UINT TMK_mrtgetstate(void);
UINT TMK_mrtdefbrcsubaddr0(void);
UINT TMK_mrtreset(void);
UINT TMK_tmktimer(void);
UINT TMK_tmkgettimer(void);
UINT TMK_tmkgettimerl(void);
UINT TMK_bcgetmsgtime(void);
#define TMK_mtgetmsgtime TMK_bcgetmsgtime
UINT TMK_rtgetmsgtime(void);
UINT TMK_tmkgethwver(void);
UINT TMK_tmkgetevtime(void);
UINT TMK_tmkswtimer(void);
UINT TMK_tmkgetswtimer(void);
UINT TMK_tmktimeout(void);
UINT TMK_mrtdefbrcpage(void);
UINT TMK_mrtgetbrcpage(void);
UINT TMK_mbcinit(void);
UINT TMK_mbcpreparex(void);
UINT TMK_mbcstartx(void);
UINT TMK_mbcalloc(void);
UINT TMK_mbcfree(void);
UINT TMK_tmkwaiteventsflag(void);
UINT TMK_tmkwaiteventsm(void);
//UINT TMK_bcputblk64(void);
//UINT TMK_bcgetblk64(void);
//UINT TMK_rtputblk64(void);
//UINT TMK_rtgetblk64(void);
//UINT TMK_rtgetflags64(void);
//UINT TMK_rtputflags64(void);
UINT (*TMK_Procs[])(void) = {
TMK_tmkconfig,
TMK_tmkdone,
TMK_tmkgetmaxn,
TMK_tmkselect,
TMK_tmkselected,
TMK_tmkgetmode,
TMK_tmksetcwbits,
TMK_tmkclrcwbits,
TMK_tmkgetcwbits,
TMK_tmkwaitevents,
// TMK_tmkdefevent,
TMK_tmkgetevd,
// TMK_bcdefintnorm,
// TMK_bcdefintexc,
// TMK_bcdefintx,
// TMK_bcdefintsig,
TMK_bcreset,
TMK_bc_def_tldw,
TMK_bc_enable_di,
TMK_bc_disable_di,
TMK_bcdefirqmode,
TMK_bcgetirqmode,
TMK_bcgetmaxbase,
TMK_bcdefbase,
TMK_bcgetbase,
TMK_bcputw,
TMK_bcgetw,
TMK_bcgetansw,
TMK_bcputblk,
TMK_bcgetblk,
TMK_bcdefbus,
TMK_bcgetbus,
TMK_bcstart,
TMK_bcstartx,
TMK_bcdeflink,
TMK_bcgetlink,
TMK_bcstop,
TMK_bcgetstate,
// TMK_rtdefintcmd,
// TMK_rtdefinterr,
// TMK_rtdefintdata,
TMK_rtreset,
TMK_rtdefirqmode,
TMK_rtgetirqmode,
TMK_rtdefmode,
TMK_rtgetmode,
TMK_rtgetmaxpage,
TMK_rtdefpage,
TMK_rtgetpage,
TMK_rtdefpagepc,
TMK_rtdefpagebus,
TMK_rtgetpagepc,
TMK_rtgetpagebus,
TMK_rtdefaddress,
TMK_rtgetaddress,
TMK_rtdefsubaddr,
TMK_rtgetsubaddr,
TMK_rtputw,
TMK_rtgetw,
TMK_rtputblk,
TMK_rtgetblk,
TMK_rtsetanswbits,
TMK_rtclranswbits,
TMK_rtgetanswbits,
TMK_rtgetflags,
TMK_rtputflags,
TMK_rtsetflag,
TMK_rtclrflag,
TMK_rtgetflag,
TMK_rtgetstate,
TMK_rtbusy,
TMK_rtlock,
TMK_rtunlock,
TMK_rtgetcmddata,
TMK_rtputcmddata,
// TMK_mtdefintx,
// TMK_mtdefintsig,
TMK_mtreset,
TMK_mtdefirqmode,
TMK_mtgetirqmode,
TMK_mtgetmaxbase,
TMK_mtdefbase,
TMK_mtgetbase,
TMK_mtputw,
TMK_mtgetw,
TMK_mtgetsw,
TMK_mtputblk,
TMK_mtgetblk,
TMK_mtstartx,
TMK_mtdeflink,
TMK_mtgetlink,
TMK_mtstop,
TMK_mtgetstate,
TMK_tmkgetinfo,
TMK_getversion,
TMK_rtenable,
TMK_mrtgetmaxn,
TMK_mrtconfig,
TMK_mrtselected,
TMK_mrtgetstate,
TMK_mrtdefbrcsubaddr0,
TMK_mrtreset,
TMK_tmktimer,
TMK_tmkgettimer,
TMK_tmkgettimerl,
TMK_bcgetmsgtime,
TMK_mtgetmsgtime,
TMK_rtgetmsgtime,
TMK_tmkgethwver,
TMK_tmkgetevtime,
TMK_tmkswtimer,
TMK_tmkgetswtimer,
TMK_tmktimeout,
TMK_mrtdefbrcpage,
TMK_mrtgetbrcpage,
TMK_mbcinit,
TMK_mbcpreparex,
TMK_mbcstartx,
TMK_mbcalloc,
TMK_mbcfree,
TMK_mbcfree,//112
TMK_mbcfree,//113
TMK_mbcfree,//114
TMK_tmkwaiteventsflag,
TMK_tmkwaiteventsm
};
#define MAX_TMK_API (sizeof(TMK_Procs)/sizeof(void*)+1)
//int aCmds[MAX_TMK_API+1];
//#include "tmk1553b.h"
//#define MAKEWORD(a, b) ((WORD)(((BYTE)(a)) | ((WORD)((BYTE)(b))) << 8))
//#define MAKELONG(a, b) ((LONG)(((WORD)(a)) | ((DWORD)((WORD)(b))) << 16))
#define LOWORD(l) ((USHORT)(l))
#define HIWORD(l) ((USHORT)(((UINT)(l) >> 16) & 0xFFFF))
//#define LOBYTE(w) ((BYTE)(w))
//#define HIBYTE(w) ((BYTE)(((WORD)(w) >> 8) & 0xFF))
//typedef char *PSTR;
//typedef USHORT USHORT;
//typedef USHORT *PUSHORT;
// Pointers to input and output buffers
PUSHORT lpwIn, lpwOut, lpwBuf;
//PUINT lpcbReturned;
#define TMK_BAD_0 -1024
/*
#define TMK_BAD_TYPE 1
#define TMK_BAD_IRQ 2
#define TMK_BAD_NUMBER 3
#define BC_BAD_BUS 4
#define BC_BAD_BASE 5
#define BC_BAD_LEN 6
#define RT_BAD_PAGE 7
#define RT_BAD_LEN 8
#define RT_BAD_ADDRESS 9
#define RT_BAD_FUNC 10
#define BC_BAD_FUNC 11
#define TMK_BAD_FUNC 12
#define TMK_MAX_ERROR 12
*/
#include "tmktest.c"
#define LOADTX1 0
//#define LOADRT1 1
#define LOADTX4 2
#define LOADTX5 3
#define LOADTX6 4
#define LOADMR6 5
//#define LOADTT6 6
//#define LOADTD6 7
//#define LOADRT1
//#define LOADTX4
//#define LOADTX5
#include "load/txv11.c"
#ifdef LOADRT1
#include "load/rt1v03.c"
#endif //def LOADRT1
#ifdef LOADTX6
#define fpgabuf4 fpgabuf0
#endif //def LOADTX6
#ifdef LOADTX4
#define fpgabuf2 fpgabuf0
#endif //def LOADTX4
#ifdef LOADTX5
#define fpgabuf3 fpgabuf0
#endif //def LOADTX5
#ifdef CONFIG_PCI
#define fpgabuf5 fpgabuf0
#ifdef LOADTX6
#define fpgabuf6 fpgabuf0
#endif //def LOADTX6
#endif //def CONFIG_PCI
#ifdef LOADMR6
#include "load/mr6v02.c"
#endif //def LOADMR6
#ifdef LOADTT6
#include "load/tt6v04.c"
#endif //def LOADTT6
#ifdef LOADTD6
#include "load/td6v01.c"
#endif //def LOADTD6
#ifdef CONFIG_PCI
#ifdef LOADMR6
#define fpgabuf10 fpgabuf7
#endif //def LOADMR6
#ifdef LOADTT6
#define fpgabuf11 fpgabuf8
#endif //def LOADTT6
#ifdef LOADTD6
#define fpgabuf12 fpgabuf9
#endif //def LOADTD6
#endif //def CONFIG_PCI
#ifdef CONFIG_PCI
#define PLX_MAX_DEVICE_CNT 2
#define ID_TX1PCI 0x0001E1C5
#define ID_TX6PCI 0x0002E1C5
#define ID_TX1PCI2 0x0003E1C5
#define ID_TX6PCI2 0x0004E1C5
#define ID_TA1PCI 0x0005E1C5
#define ID_TA1PCI4 0x0006E1C5
#define ID_TA1PCI32RT 0x0007E1C5
#define ID_TA1PE2 0x0008E1C5
#define ID_TA1PE4 0x0009E1C5
#define ID_TA1PE32RT 0x000AE1C5
#define CFG_COMMAND 0x04
#define CFG_SUBSYSTEM_ID 0x2C
#define CFG_IRQ 0x3C
#define CFG_ADDR1 0x14
#define CFG_ADDR2 0x18
#define CFG_ADDR3 0x1C
#define CFG_ADDR4 0x20
#define CFG_ADDR5 0x24
#endif //def CONFIG_PCI
//#ifdef CONFIG_PCI
//#define TX_VID 0x10B5
//#define TX_DID 0x9030
//#define TX_SubVID 0xE1C5
//#define TX1_SubDID 0x0001
//#define TX6_SubDID 0x0002
//#define TX1_2_SubDID 0x0003
//#define TX6_2_SubDID 0x0004
//#define ID_TX1PCI 0x0001E1C5
//#define ID_TX6PCI 0x0002E1C5
//#endif //def CONFIG_PCI
#define READ_PORT (port+0xC)
#define LOAD_PORT (port+0xC)
#define RESET_PORT (port+6)
#define ADDR_PORT (port+0xA)
#define DATA_PORT (port+0xE)
#define MODE_PORT (port+8)
//#define BUSY_BIT 0x0080
#define BUSY_DEVICE 0x7E7F
#define EMPTY_DEVICE 0x7EFF
#define ERROR_DEVICE 0x7FFF
#define LOADED_DEVICE 0x0000
#define GENER1_BL 0x0004
#define GENER2_BL 0x4000
#define TX_OK 0
#define TX_BAD_PARAMS 1
#define TX_NOT_FOUND 2
#define TX_LOAD_ERROR 4
#define TX_INIT_ERROR 8
#define TX_TEST_ERROR 16
int tmkxload(unsigned port, unsigned char *fpgabuf, int len)
{
int i;
if ((inw(READ_PORT) & 0x7FFF) != EMPTY_DEVICE)
return TX_NOT_FOUND;
for (i = 0; i < len; ++i)
{
if ((inw(READ_PORT) & 0x7FFF) != EMPTY_DEVICE)
return TX_LOAD_ERROR;
outw((unsigned short)fpgabuf[i] | 0xFF00, LOAD_PORT);
while ((inw(READ_PORT) & 0x7FFF) == BUSY_DEVICE);
}
for (i = 0; i < 100; ++i) // wait 15 us
inw(READ_PORT);
outw(0, RESET_PORT);
outw(GENER1_BL+GENER2_BL, MODE_PORT);
if (inw(READ_PORT) != LOADED_DEVICE)
return TX_INIT_ERROR;
return TX_OK;
}
#ifdef CONFIG_PCI
int tmkxiload(unsigned portplx, int reset)
{
unsigned char *fpgabuf;
int len;
int res = TX_OK;
unsigned port;
int i;
int fLoad, fWait;
int cTmk, iTmk;
TTmkConfig *apTmk[MAX_TMK_NUMBER+1];
TTmkConfig *pTmk;
cTmk = 0;
fLoad = 0;
for (iTmk = 0; iTmk <= MAX_TMK_NUMBER; ++iTmk)
{
pTmk = &aTmkConfig[iTmk];
if ((unsigned)(pTmk->wHiddenPorts) != portplx ||
pTmk->fLoaded)
continue;