forked from erikarn/LinBPQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bpqhdlc.c
1136 lines (788 loc) · 23 KB
/
bpqhdlc.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
/*
Copyright 2001-2015 John Wiseman G8BPQ
This file is part of LinBPQ/BPQ32.
LinBPQ/BPQ32 is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
LinBPQ/BPQ32 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LinBPQ/BPQ32. If not, see http://www.gnu.org/licenses
*/
//
// Module to provide HDLC Card (DRSI, Baycom etc) support for
// G8BPQ switch in a 32bit environment
//
// Win95 - Uses BPQHDLC.VXD to drive card
// NT -Uses BPQHDLC.DRV to drive card
//
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "CHeaders.h"
#include "bpq32.h"
extern UINT TRACE_Q;
_CRT_OBSOLETE(GetVersionEx) errno_t __cdecl _get_winmajor(__out unsigned int * _Value);
_CRT_OBSOLETE(GetVersionEx) errno_t __cdecl _get_winminor(__out unsigned int * _Value);
#define FILE_DEVICE_BPQHDLC 0x00008421
#define IOCTL_BPQHDLC_SEND CTL_CODE(FILE_DEVICE_BPQHDLC,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS)
#define IOCTL_BPQHDLC_POLL CTL_CODE(FILE_DEVICE_BPQHDLC,0x801,METHOD_BUFFERED,FILE_ANY_ACCESS)
#define IOCTL_BPQHDLC_TIMER CTL_CODE(FILE_DEVICE_BPQHDLC,0x802,METHOD_BUFFERED,FILE_ANY_ACCESS)
#define IOCTL_BPQHDLC_ADDCHANNEL CTL_CODE(FILE_DEVICE_BPQHDLC,0x803,METHOD_BUFFERED,FILE_ANY_ACCESS)
#define IOCTL_BPQHDLC_CHECKTX CTL_CODE(FILE_DEVICE_BPQHDLC,0x804,METHOD_BUFFERED,FILE_ANY_ACCESS)
#define IOCTL_BPQHDLC_IOREAD CTL_CODE(FILE_DEVICE_BPQHDLC,0x805,METHOD_BUFFERED,FILE_ANY_ACCESS)
#define IOCTL_BPQHDLC_IOWRITE CTL_CODE(FILE_DEVICE_BPQHDLC,0x806,METHOD_BUFFERED,FILE_ANY_ACCESS)
VOID __cdecl Debugprintf(const char * format, ...);
// Info to pass to Kernel HDLC Driver to define an SCC Subchannel
typedef struct _BPQHDLC_ADDCHANNEL_INPUT {
ULONG IOBASE; // IO Base Address
ULONG IOLEN; // Number of Addresses
UCHAR Interrupt; // Interrupt
UCHAR Channel;
ULONG ASIOC; // A CHAN ADDRESSES
ULONG SIO; // OUR ADDRESSES (COULD BE A OR B)
ULONG SIOC; // Our Control Channel
ULONG BSIOC; // B CHAN CONTROL
VOID * OtherChannel; // Kernel Channel record for first channel if this is 2nd channel
UCHAR SOFTDCDFLAG; // Use SoftDCD flag
int TXBRG; // FOR CARDS WITHOUT /32 DIVIDER
int RXBRG;
UCHAR WR10; // NRZ/NRZI FLAG
USHORT TXDELAY; //TX KEYUP DELAY TIMER
UCHAR PERSISTANCE;
} BPQHDLC_ADDCHANNEL_INPUT, *PBPQHDLC_ADDCHANNEL_INPUT;
DWORD n;
HANDLE hDevice=0;
BYTE bOutput[4]=" ";
DWORD cb=0;
int fResult=0;
BOOL Win98 = FALSE;
extern int QCOUNT;
int Init98(HDLCDATA * PORTVEC);
int Init2K(HDLCDATA * PORTVEC);
int INITPORT(PHDLCDATA PORTVEC);
int HDLCRX2K(PHDLCDATA PORTVEC, UCHAR * buff)
{
ULONG Param;
DWORD len=0;
if (hDevice == 0)
return (0);
if (PORTVEC->DRIVERPORTTABLE == 0) return 0;
memcpy(&Param, &PORTVEC->DRIVERPORTTABLE,4);
fResult = DeviceIoControl(
hDevice, // device handle
(Win98) ? 'G' : IOCTL_BPQHDLC_POLL, // control code
&Param, (Win98) ? (rand() & 0xff) : 4, //Input Params
buff,360,&len, // output parameters
0);
return (len);
}
int HDLCTIMER2K(PHDLCDATA PORTVEC)
{
DWORD len=0;
if (hDevice == 0)
return (0);
if (PORTVEC->DRIVERPORTTABLE == 0) return 0;
fResult = DeviceIoControl(
hDevice, // device handle
(Win98) ? 'T' : IOCTL_BPQHDLC_TIMER, // control code
&PORTVEC->DRIVERPORTTABLE,4, //Input Params
0,0,&len, // output parameters
0);
return (0);
}
int HDLCTXCHECK2K(PHDLCDATA PORTVEC)
{
DWORD Buff;
DWORD len=0;
if (hDevice == 0)
return (0);
if (Win98)
return 0;
if (PORTVEC->DRIVERPORTTABLE == 0) return 0;
fResult = DeviceIoControl(
hDevice, // device handle
IOCTL_BPQHDLC_CHECKTX, // control code
&PORTVEC->DRIVERPORTTABLE,4, //Input Params
&Buff,4,&len, // output parameters
0);
return (Buff);
}
int HDLCTX2K(PHDLCDATA PORTVEC,UCHAR * buff)
{
DWORD txlen=0;
if (hDevice == 0)
return (0);
txlen=(buff[6]<<8) + buff[5];
memcpy(buff,&PORTVEC->DRIVERPORTTABLE,4);
fResult = DeviceIoControl(
hDevice, // device handle
(Win98) ? 'S' : IOCTL_BPQHDLC_SEND, // control code
// control code
buff,txlen, // input parameters
NULL,0,&cb, // output parameters
0);
return (0);
}
int HDLCCLOSE(PHDLCDATA PORTVEC)
{
if (hDevice)
{
CloseHandle(hDevice);
hDevice = 0;
}
return 0;
}
int HDLCRX98(PHDLCDATA PORTVEC, UCHAR * buff)
{
DWORD len=0;
if (hDevice == 0)
return (0);
fResult = DeviceIoControl(
hDevice, // device handle
'G', // control code
PORTVEC->DRIVERPORTTABLE,rand() & 0xff, //Input Params
buff,360,&len, // output parameters
0);
return (len);
}
int HDLCTIMER98(PHDLCDATA PORTVEC)
{
DWORD len=0;
if (hDevice == 0)
return (0);
fResult = DeviceIoControl(
hDevice, // device handle
'T', // control code
PORTVEC->DRIVERPORTTABLE,4, //Input Params
0,0,&len, // output parameters
0);
return (0);
}
int HDLCTXCHECK98(PHDLCDATA PORTVEC)
{
return 0;
}
int HDLCTX98(PHDLCDATA PORTVEC,UCHAR * buff)
{
DWORD txlen=0;
if (hDevice == 0)
return (0);
txlen=(buff[6]<<8) + buff[5];
memcpy(buff,&PORTVEC->DRIVERPORTTABLE,4);
fResult = DeviceIoControl(
hDevice, // device handle
'S', // control code
buff,txlen,// input parameters
NULL,0,&cb, // output parameters
0);
return (0);
}
int IntHDLCRX(PHDLCDATA PORTVEC, UCHAR * buff)
{
if (Win98)
return HDLCRX98(PORTVEC, buff);
else
return HDLCRX2K(PORTVEC, buff);
}
VOID HDLCRX(PHDLCDATA PORTVEC)
{
struct _MESSAGE * Message;
int Len;
struct PORTCONTROL * PORT = (struct PORTCONTROL *)PORTVEC;
if (QCOUNT < 10)
return;
Message = GetBuff();
if (Message == NULL)
return;
Len = IntHDLCRX(PORTVEC, (UCHAR *)Message);
if (Len == 0)
{
ReleaseBuffer((UINT *)Message);
return;
}
C_Q_ADD(&PORT->PORTRX_Q, (UINT *)Message);
return;
}
int HDLCTIMER(PHDLCDATA PORTVEC)
{
if (Win98)
return HDLCTIMER98(PORTVEC);
else
return HDLCTIMER2K(PORTVEC);
}
int HDLCTXCHECK(PHDLCDATA PORTVEC)
{
if (Win98)
return HDLCTXCHECK98(PORTVEC);
else
return HDLCTXCHECK2K(PORTVEC);
}
VOID HDLCTX(PHDLCDATA PORTVEC,UCHAR * Buffer)
{
struct _LINKTABLE * LINK;
LINK = (struct _LINKTABLE *)Buffer[(BUFFLEN-4)/4];
if (LINK)
{
if (LINK->L2TIMER)
LINK->L2TIMER = LINK->L2TIME;
Buffer[(BUFFLEN-4)/4] = 0; // CLEAR FLAG FROM BUFFER
}
if (Win98)
HDLCTX98(PORTVEC, Buffer);
else
HDLCTX2K(PORTVEC, Buffer);
C_Q_ADD(&TRACE_Q, (UINT *)Buffer);
}
int HDLCINIT(HDLCDATA * PORTVEC)
{
int WinVer, WinMinor;
WritetoConsole("HDLC\n");
#pragma warning(push)
#pragma warning(disable : 4996)
_get_winmajor(&WinVer);
_get_winminor(&WinMinor);
#pragma warning(pop)
if (WinVer >= 5) // Win 2000 or above
return Init2K(PORTVEC);
else
{
Init98(PORTVEC);
OutputDebugString("HDLC Win98 Return from Init98\n");
return 0;
}
}
int Init98(HDLCDATA * PORTVEC)
{
char msg[255];
int err;
Win98 = TRUE;
OutputDebugString("Init HDLC 98\n");
//
// Open HDLC Driver, send send config params
//
if (hDevice == 0) // Not already loaded
{
//
// Load VXD
//
hDevice = CreateFile("\\\\.\\BPQHDLC.VXD",
0, 0, NULL, 0, FILE_FLAG_DELETE_ON_CLOSE, NULL);
if (hDevice == INVALID_HANDLE_VALUE)
{
hDevice=0;
err=GetLastError();
sprintf(msg,"Error loading Driver \\\\.\\BPQHDLC.VXD - Error code %d\n",err);
OutputDebugString(msg);
MessageBox(NULL,msg,"BPQ32",MB_ICONSTOP);
WritetoConsole("Initialisation Failed");
return (FALSE);
}
// OutputDebugString("Calling GetVersion\n");
// fResult = DeviceIoControl(
// hDevice, // device handle
// 10,//DIOC_GETVERSION, // control code
// NULL,0,// input parameters
// bOutput, 4, &cb, // output parameters
// 0);
srand( (unsigned)time( NULL ) ); //Prime random no generator
}
OutputDebugString("Calling Initialize\n");
//
// Initialize Driver for this card and channel
//
fResult = DeviceIoControl(
hDevice, // device handle
'I', // control code
PORTVEC, sizeof (struct PORTCONTROL), // input parameters
bOutput, 4, &cb, // output parameters
0);
memcpy(&PORTVEC->DRIVERPORTTABLE,bOutput,4);
Debugprintf("BPQ32 HDLC Driver Table ADDR %X", PORTVEC->DRIVERPORTTABLE);
OutputDebugString("Initialize Returned\n");
return (TRUE);
}
int PC120INIT(PHDLCDATA PORTVEC)
{
return (HDLCINIT(PORTVEC));
}
int DRSIINIT(PHDLCDATA PORTVEC)
{
return (HDLCINIT(PORTVEC));
}
int TOSHINIT(PHDLCDATA PORTVEC)
{
return (HDLCINIT(PORTVEC));
}
int RLC100INIT(PHDLCDATA PORTVEC)
{
return (HDLCINIT(PORTVEC));
}
int BAYCOMINIT(PHDLCDATA PORTVEC)
{
return (HDLCINIT(PORTVEC));
}
int PA0INIT(PHDLCDATA PORTVEC) // 14 PA0HZP OPTO-SCC
{
return (HDLCINIT(PORTVEC));
}
// W2K/XP Routines
#define IOTXCA VECTOR[0]
#define IOTXEA VECTOR[1]
#define IORXCA VECTOR[2]
#define IORXEA VECTOR[3]
#define SIOR READ_PORT_UCHAR(PORTVEC->SIO)
#define SIOW(A) WRITE_PORT_UCHAR(PORTVEC->SIO,A)
#define SIOCR READ_PORT_UCHAR(PORTVEC->SIOC)
#define SIOCW(A) WRITE_PORT_UCHAR(PORTVEC->SIOC, A)
//#define SETRVEC PORTVEC->IORXCA =
//#define SETTVEC PORTVEC->IOTXCA =
int CLOCKFREQ = 76800; // 4,915,200 HZ /(32*2)
int TOSHCLOCKFREQ = 57600;
UCHAR SDLCCMD[] = {
0,0,
2,0, // BASE VECTOR
4,0x20, // SDLC MODE
3,0xc8, // 8BIT, CRC ENABLE, RX DISABLED
7,0x7e, // STANDARD FLAGS
1,0x13, // INT ON ALL RX, TX INT EN, EXT INT EN
5,0xe1, // DTR, 8BIT, SDLC CRC,TX CRC EN
10,0xa0, // CRC PRESET TO 1
9,0x09, // ENABLE INTS
11,0x66, // NO XTAL, RXC = DPLL, TXC = RTXC, TRXC = BRG (NEEDS /32 BETWEEN TRXC AND RTXC)
14,0x83,
14,0x23,
15,0xc0 // EXT INT ONLY ON TX UND AND ABORT RX
};
#define SDLCLEN 26
UCHAR TOSHR11 = 0x68; // NO XTAL, RXC = DPLL, TXC = DPLL, NO CLK OUTPUT
UCHAR CIOPARAMS[] = {
0x2B,0xFF, // B DIRECTION - ALL IN
0x23,0xFF, // A DIRECTION - ALL IN
0x1D,0x0E2, // C/T 2 MODE - CONT, EXT IN, EXT O, SQUARE
0x1C,0x0E2, // C/T 1 MODE ""
0x19,0x10, // C/T 2 LSB - 16 = /32 FOR SQUARE WAVE
0x18,0, // MSB
0x17,0x10, // C/T 1 LSB
0x16,0, // MSB
0x0B,0x04, // CT2 "" - GATE
0x0A,0x04, // CT1 "" - GATE
0x06,0x0F, // PORT C DIRECTION - INPUTS
1,0x84, // ENABLE PORTS A AND B
0,0 // INTERRUPT CONTROL
};
#define CIOLEN 26
VOID WRITE_PORT_UCHAR(UINT Port, UINT Value)
{
ULONG buff[3];
buff[0] = Port;
buff[1] = Value;
fResult = DeviceIoControl(
hDevice, // device handle
IOCTL_BPQHDLC_IOWRITE, // control code
buff, 8, // input parameters
NULL,0,&cb, // output parameters
0);
}
UCHAR READ_PORT_UCHAR(ULONG Port)
{
ULONG buff[3];
buff[0] = Port;
fResult = DeviceIoControl(
hDevice, // device handle
IOCTL_BPQHDLC_IOREAD, // control code
buff, 4, // input parameters
buff, 4,&cb, // output parameters
0);
Debugprintf("BPQ32 HDLC READ_PORT_UCHAR Returned %X", LOBYTE(buff[0]));
return LOBYTE(buff[0]);
}
int Init2K(HDLCDATA * PORTVEC)
{
char msg[255];
int err;
if (hDevice == 0) // Not already loaded
{
//
// Open HDLC Driver
//
hDevice = CreateFile(
"\\\\.\\BPQHDLC", // Open the Device "file"
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
if (hDevice == INVALID_HANDLE_VALUE)
{
hDevice=0;
err=GetLastError();
sprintf(msg,"Error Opening Driver \\device\\BPQHDLC - Error code %d\n", err);
OutputDebugString(msg);
WritetoConsole(msg);
return (FALSE);
}
}
INITPORT(PORTVEC);
return 0;
}
PHDLCDATA See_if_First_On_Card(PHDLCDATA PORTVEC)
{
// SEE IF ANOTHER PORT IS ALREADY USING THE OTHER CHANNEL ON THIS CARD
int i;
PHDLCDATA PreviousPort = (PHDLCDATA)PORTTABLE;
for (i = 0; i < NUMBEROFPORTS; i++)
{
if (PORTVEC == PreviousPort)
{
// NONE BEFORE OURS
return NULL;
}
if (PORTVEC->PORTCONTROL.IOBASE == PreviousPort->PORTCONTROL.IOBASE)
{
// ENSURE ENTRIES ARE FOR DIFFERENT CHANNELS
if (PORTVEC->PORTCONTROL.CHANNELNUM == PreviousPort->PORTCONTROL.CHANNELNUM)
// CHANNEL DEFINITION ERROR
return (PHDLCDATA) -1;
else
return PreviousPort;
}
PreviousPort = (PHDLCDATA)PreviousPort->PORTCONTROL.PORTPOINTER;
}
return NULL; // FLAG NOT FOUND
}
VOID INITPART2(PHDLCDATA PORTVEC, USHORT SCCOffset, PHDLCDATA PreviousPort)
{
// SCCOffset is address of SCC relative to Card Base Address
int i;
USHORT SCCBase=PORTVEC->PORTCONTROL.IOBASE + SCCOffset;
int BRG;
// SET UP ADDRESS LIST - THIS PATH FOR CARDS WITH 'NORMAL'
// ADDRESSING - C/D=A0, A/B=A1, SO ORDER IS BCTRL BDATA ACTRL ADATA
// OR DE, WHICH USES WORD ADDRESSES C/D=A1, A/B=A2
PORTVEC->BSIOC = SCCBase; // B CHAN ADDR
PORTVEC->ASIOC = SCCBase+2; // A CHAN ADDR
// SEE WHICH CHANNEL TO USE
if (PORTVEC->PORTCONTROL.CHANNELNUM == 'A')
{
PORTVEC->A_PTR = PORTVEC; // POINT TO OUR ENTRY
PORTVEC->SIOC = SCCBase+2;
PORTVEC->SIO = SCCBase+3; // DATA 1 ABOVE CONTROL
if (PreviousPort) // Another Channel is first on Card
PORTVEC->B_PTR = PreviousPort; // CROSSLINK CHANNELS
}
else
{
// MUST BE B - CHECKED EARLIER
PORTVEC->B_PTR = PORTVEC; // POINT TO OUR ENTRY
PORTVEC->SIOC = SCCBase;
PORTVEC->SIO = SCCBase+1; // DATA 1 ABOVE CONTROL
if (PreviousPort) // Another Channel is first on Card
PORTVEC->A_PTR = PreviousPort; // CROSSLINK CHANNELS
}
// INITIALISE COMMS CHIP
if (PreviousPort == 0) // OTHER CHAN ALREADY SET UP?
{
// DO A HARD RESET OF THE SCC
WRITE_PORT_UCHAR(PORTVEC->ASIOC, 0); // Make Sure WR0
WRITE_PORT_UCHAR(PORTVEC->ASIOC, 0);
WRITE_PORT_UCHAR(PORTVEC->ASIOC, 9); // WR9
WRITE_PORT_UCHAR(PORTVEC->ASIOC, 0xC0); // Hard Reset
Sleep(2);
}
for (i=0; i< SDLCLEN; i++)
{
WRITE_PORT_UCHAR(PORTVEC->SIOC, SDLCCMD[i]);
}
PORTVEC->WR10 = 0x20; // NRZI
// SET UP BRG FOR REQUIRED SPEED
if (PORTVEC->PORTCONTROL.BAUDRATE == 0)
{
// SET EXTERNAL CLOCK
SIOCW(11); // WR11
SIOCW(0x20); // RX = TRXC TX = RTXC
return;
}
if (PORTVEC->PORTCONTROL.PORTTYPE == 12) // RLC 400 USES SAME CLOCK AS TOSH
BRG = TOSHCLOCKFREQ;
else
BRG = CLOCKFREQ;
BRG=(BRG/PORTVEC->PORTCONTROL.BAUDRATE)-2;
SIOCW(12); // Select WR12
SIOCW(BRG & 0xff); // SET LSB
SIOCW(13); // Select WR13
SIOCW(BRG >> 8); // SET MSB
return;
}
VOID INITCIO(PHDLCDATA PORTVEC)
{
// INITIALISE CIO - DRSI ONLY
int i;
ULONG CIOAddr = PORTVEC->PORTCONTROL.IOBASE + 7; // TO CIO PORT
READ_PORT_UCHAR(CIOAddr);
WRITE_PORT_UCHAR(CIOAddr, 0);
READ_PORT_UCHAR(CIOAddr);
WRITE_PORT_UCHAR(CIOAddr, 0);
WRITE_PORT_UCHAR(CIOAddr, 1); // FORCE RESET
WRITE_PORT_UCHAR(CIOAddr, 0); // CLEAR RESET
for (i=0; i< CIOLEN; i++)
{
WRITE_PORT_UCHAR(CIOAddr, CIOPARAMS[i] );
}
return;
}
VOID STARTCIO(PHDLCDATA PORTVEC)
{
USHORT CIOAddr = PORTVEC->PORTCONTROL.IOBASE + 7; // TO CIO PORT
UCHAR Reg;
// B CHANNEL
// SET COUNTER OUTPUT BIT ACTIVE
WRITE_PORT_UCHAR(CIOAddr, 0x2B); // PORT B DIRECTION
Reg = READ_PORT_UCHAR(CIOAddr);
if (PORTVEC->PORTCONTROL.CHANNELNUM == 'B')
{
Reg &= 0xEF; // SET BIT 4 AS OUTPUT
WRITE_PORT_UCHAR(CIOAddr, 0x2B); // PORT B DIRECTION
WRITE_PORT_UCHAR(CIOAddr, Reg); // UPDATE PORT B DIRECTION
// ENABLE COUNTER
WRITE_PORT_UCHAR(CIOAddr,1); // MASTER CONFIG
Reg = READ_PORT_UCHAR(CIOAddr); // GET IT
Reg |= 0x40; // ENABLE CT1
WRITE_PORT_UCHAR(CIOAddr,1); // MASTER CONFIG
WRITE_PORT_UCHAR(CIOAddr, Reg); // Set it
// START COUNTER
WRITE_PORT_UCHAR(CIOAddr,0x0A); // CT1 CONTROL
WRITE_PORT_UCHAR(CIOAddr,6); // START CT1
return;
}
Reg &= 0xFE; // SET BIT 0 AS OUTPUT
WRITE_PORT_UCHAR(CIOAddr, 0x2B); // PORT B DIRECTION
WRITE_PORT_UCHAR(CIOAddr, Reg); // UPDATE PORT B DIRECTION
// ENABLE COUNTER
WRITE_PORT_UCHAR(CIOAddr,1); // MASTER CONFIG
Reg = READ_PORT_UCHAR(CIOAddr); // GET IT
Reg |= 0x20; // ENABLE CT2
WRITE_PORT_UCHAR(CIOAddr,1); // MASTER CONFIG
WRITE_PORT_UCHAR(CIOAddr, Reg); // Set it
// START COUNTER
WRITE_PORT_UCHAR(CIOAddr,0x0B); // CT2 CONTROL
WRITE_PORT_UCHAR(CIOAddr,6); // START CT2
return;
}
VOID INITMODEM(PHDLCDATA PORTVEC)
{
// SETUP MODEM - PC120 ONLY
WRITE_PORT_UCHAR(PORTVEC->PORTCONTROL.IOBASE, 0x0a);
}
VOID CHECKCHAN(PHDLCDATA PORTVEC, USHORT CDOffset)
{
// CDoffset contains offset to Second SCC
// IF CHANNEL = C OR D SET TO SECOND SCC ADDRESS, AND CHANGE TO A OR B
if (PORTVEC->PORTCONTROL.CHANNELNUM > 'B')
{
// SECOND SCC
PORTVEC->PORTCONTROL.CHANNELNUM -=2;
PORTVEC->PORTCONTROL.IOBASE+=CDOffset;
}
}
// BAYCOM CARD
VOID BINITPART2(PHDLCDATA PORTVEC, USHORT SCCOffset, PHDLCDATA PreviousPort)
{
// ORDER IS 0 1 2 3 4 5 6 7
// ADATA BDATA CDATA DDATA ACTRL BCTRL CCTRL DCTRL
// Before entering here IOBASE and Chan have been updated if Chan were C or D
// SET UP ADDRESS LIST
int i;
USHORT SCCBase=PORTVEC->PORTCONTROL.IOBASE + SCCOffset;
int BRG;
// SET UP ADDRESS LIST - THIS PATH FOR CARDS WITH 'NORMAL'
// ADDRESSING - C/D=A0, A/B=A1, SO ORDER IS BCTRL BDATA ACTRL ADATA
// OR DE, WHICH USES WORD ADDRESSES C/D=A1, A/B=A2
PORTVEC->ASIOC = SCCBase+4; // A CHAN ADDR
PORTVEC->BSIOC = SCCBase+5; // B CHAN ADDR
// SEE WHICH CHANNEL TO USE
if (PORTVEC->PORTCONTROL.CHANNELNUM == 'A')
{
PORTVEC->A_PTR = PORTVEC; // POINT TO OUR ENTRY
PORTVEC->SIOC = SCCBase+4;
PORTVEC->SIO = SCCBase;
if (PreviousPort) // Another Channel is first on Card
PORTVEC->B_PTR = PreviousPort; // CROSSLINK CHANNELS
}
else
{
// MUST BE B - CHECKED EARLIER
PORTVEC->B_PTR = PORTVEC; // POINT TO OUR ENTRY
PORTVEC->SIOC = SCCBase+5;
PORTVEC->SIO = SCCBase+1;
if (PreviousPort) // Another Channel is first on Card
PORTVEC->A_PTR = PreviousPort; // CROSSLINK CHANNELS
}
// INITIALISE COMMS CHIP
if (PreviousPort == 0) // OTHER CHAN ALREADY SET UP?
{
// DO A HARD RESET OF THE SCC
WRITE_PORT_UCHAR(PORTVEC->ASIOC, 0); // Make Sure WR0
WRITE_PORT_UCHAR(PORTVEC->ASIOC, 0);
WRITE_PORT_UCHAR(PORTVEC->ASIOC, 9); // WR9
WRITE_PORT_UCHAR(PORTVEC->ASIOC, 0xC0); // Hard Reset
Sleep(2);
}
for (i=0; i< SDLCLEN; i++)
{
WRITE_PORT_UCHAR(PORTVEC->SIOC, SDLCCMD[i]);
}
// SET UP BRG FOR REQUIRED SPEED
if (PORTVEC->PORTCONTROL.BAUDRATE == 0)
{
// SET EXTERNAL CLOCK
SIOCW(11); // WR11
SIOCW(0x20); // RX = TRXC TX = RTXC
// BAYCOM RUH PORT USES NRZ
PORTVEC->WR10 = 0x0; // NRZ
return;
}
PORTVEC->WR10 = 0x20; // NRZI
// THERE IS NO /32 ON THE BAYCOM BOARD, SO FOR THE MOMENT WILL USE BRG
// FOR TRANSMIT. THIS REQUIRES IT TO BE REPROGRAMMED BETWEEN TX AND RX,
// AND SO PREVENTS LOOPBACK OR FULLDUP OPERATION
BRG=(CLOCKFREQ/PORTVEC->PORTCONTROL.BAUDRATE)-2;
SIOCW(12); // Select WR12
SIOCW(BRG & 0xff); // SET LSB
SIOCW(13); // Select WR13
SIOCW(BRG >> 8); // SET MSB
SIOCW(11); // WR11
SIOCW(0x70); // RXC=DPLL, TXC=BRG
PORTVEC->RXBRG = BRG;
// CALC TX RATE
PORTVEC->TXBRG = ((BRG+2)/32)-2;
SIOCW(12); // Select WR12
SIOCW(BRG & 0xff); // SET LSB
SIOCW(13); // Select WR13
SIOCW(BRG >> 8); // SET MSB
// IF 7910/3105 PORTS, SET TXC=BRG, RXC=DPLL
// IT SEEMS THE 3RD PORT IS MORE LIKELY TO BE USED WITH A SIMPLE
// MODEM WITHOUT CLOCK GERERATION (EG BAYCOM MODEM), SO SET ALL
// PORTS THE SAME
SIOCW(11); // WR11
SIOCW(0x70); // RXC=DPLL, TXC=BRG
}
BOOLEAN INITREST(PHDLCDATA PORTVEC, PHDLCDATA PrevPort)
{
BPQHDLC_ADDCHANNEL_INPUT AddParams;
VOID * Return = NULL;
int cb;
/* mov IRQHand[EBX],0 ; in case already hooked by another port
MOV PORTINTERRUPT[EBX],OFFSET32 SIOINT
CMP EDI,0
JNE SHORT INTDONE ; ALREADY SET UP
CALL HOOKINT ; INTERRUPT
INTDONE:
CALL RXAINIT
;
*/
// Pass Params to the driver