-
Notifications
You must be signed in to change notification settings - Fork 0
/
func.c
2881 lines (2597 loc) · 78.7 KB
/
func.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
//======================================== func.c === BEGIN ===
/**
* \file 'func.c'
*
* \author U. Hinz , ed.enilno-t@blerdhu
* \author B. Hennig , ed.gmx@ginneh.b
*
* \brief This file contains the fundamental source code
* of the 'K8055DD.dll' project and aims exclusively at the
* operational system 'eComStation' (OS/2) !
*
* The basics of this project are:
* - Accessing the
* ' VELLEMAN K8055 USB Experimental Interface Board '
* is done via the genecic USB driver 'usbecd.sys'
* by Wim Brul.
* - All functionality needed by a K8055 board must be put
* into a Device Specific Library.
* - Because up to three K8055 boards can be connected to a
* PC, such a library must allow code sharing and this
* is done best with a DLL.
*
* Compiling:
* |-------- input files ----------| |-- output file --|
*
* 'func.c' + 'func.h' + 'includes' ----> 'func.obj'
*
* How to use the 'OpenWatcom C 1.7' compiler and its options:
* ( One command line turned vertical )
*
* wcc386 ----------- OpenWatcom C/C++ 1.7 Compiler (32-bits)
*
* func -------------------------------- File 'func.c' and
* file 'func.h' are
* input files.
* The output file will
* be 'func.obj'.
*
* -i=D:\WATCOM17\h;D:\WATCOM17\h\os2 -- Location of includes
*
* -w4 ------------------------------ Warning level
* -e25 ------------------------------ Stop after 25 errors
* -zq ------------------------------ Quiet operation
* -od ------------------------------ No Optimisation
* -d2 ------------------------------ Debug, fully symbolic
* -bd ------------------------------ Build a DLL
* -6s ------------------------------ Pentium Pro Stack calls
* -bt=os2 --------------------------- Build target is OS/2
* -mf ------------------------------ Flat Memory
*
*
* Linking:
* |------ input files ------| |-- output file --|
*
* 'func.obj' + 'K8055.def' ---> 'K8055DD.dll'
*
* How to use the 'OpenWatcom C 1.7' linker and its options:
* ( One command line turned vertical )
*
* wlink -------------------- OpenWatcom C/C++ 1.7
*
* @K8055.def --------------- If a '@' is used, the following
* name belongs to a file with
* Linker Directives.
*
* system os2v2_dll dll ----- This is for an OS/2-DLL
*
* initi termi : ??? : ToDo :
*
* file --------------------- 'file' is to mark the beginning
* of an Object File List.
* func.obj Here just one file: 'func.obj'
*
* library ------------------ 'library' shows the beginning
* of a Library File List.
*
* os2386.lib Containing the OS/2 Dos Calls
* , File name separator
* clib3s.lib Open Watcom C Runtime Library
*
*
*
* \version 1.0.16 -
* 2011-07-12 string output K8055_InfoStr improved
* \version 1.0.15 -
* 2010-11-02 extended error codes partly rolled back
* \version 1.0.14 -
* 2010-10-25 error codes extended
* \version 1.0.13 -
* 2010-10-09 constants renamed, commenting
* \version 1.0.12 -
* 2010-09-22 function K8055_Init_01 removed again, commenting
* \version 1.0.11 -
* 2010-09-19 function K8055_Init redone, renaming, commenting
* \version 1.0.10 -
* 2010-09-16 new function K8055_Init_01, renaming, commenting
* \version 1.0.9 -
* 2010-05-14 constants renamed, commenting
* \version 1.0.8 -
* 2010-03-25 new function K8055_InfoStr, info strings,
* commenting
* \version 1.0.7 -
* 2010-02-07 new function K8055_PrepairDACxOut, commenting
* \version 1.0.5 -
* 2010-01-22 new function K8055_PrepairDigitalOut(),
* commenting
* \version 1.0.4 -
* 2010-12-14 new function K8055_DecodeDigitalInputs()
* \version 1.0.3 -
* 2010-12-13 new function K805_ReadAllInputs()
* \version 1.0.2 -
* 2009-12-10 new function K8055_DummyFnc1()
* \version 1.0.1 -
* 2009-08-23 new defines and docu rework
* \version 1.0.0 -
* 2009-07-01 Init
*/
// --- Includes, not OS/2 specific, located in '..\h' ---
//
#include <stdio.h>
#include <process.h>
#include <string.h>
#include <i86.h>
#include <dos.h>
#define INCL_DOS
// --- Includes, special for OS/2, located in '..\os2' ---
//
#include <os2.h>
// --- Includes, definitions for this project, -----------
// constants, error codes and function prototypes
//
#include "func.h"
//-----------------------------------------------------------//
//--- Byte arrays, used by K8055_Init -----------------------//
// - Used for reading descriptors
//
// --- Setup Paket for the Device Descriptor-------------------
BYTE byGetDevDscr[ SIZEUSBHEADER + 18 ] =
{ 0x80,6,0,1,0,0, 18,0 };
// --- Setup Paket for the Configuration Descriptor------------
BYTE byGetConfDscr[ SIZEUSBHEADER + 48 ] =
{ 0x80,6,0,2,0,0, 48,0 };
// --- Setup Paket for the Language String Descriptor----------
BYTE byGetLangStrDscr[ SIZEUSBHEADER + 4 ] =
{ 0x80,6,0,3,0,0, 4,0 };
// --- Setup Paket for the String2 Descriptor------------------
BYTE byGetString2Dscr[ SIZEUSBHEADER + 20 ] =
{ 0x80,6,2,3,9,4, 20,0 };
// --- Setup Pakets for 4 different String Descriptors---------
BYTE byGet1stStrDscr[ SIZEUSBHEADER + 24 ] =
{ 0x80,6,1,3,0,0, 24,0 };
BYTE byGet2ndStrDscr[ SIZEUSBHEADER + 24 ] =
{ 0x80,6,2,3,0,0, 24,0 };
BYTE byGet3rdStrDscr[ SIZEUSBHEADER + 24 ] =
{ 0x80,6,3,3,0,0, 24,0 };
BYTE byGet4thStrDscr[ SIZEUSBHEADER + 4 ] =
{ 0x80,6,4,3,0,0, 4,0 };
// --- Setup Paket for the Unknown21 --------------------------
BYTE by21unknown[ SIZEUSBHEADER + 1 ] =
{ 0x21,0x0a,0,0,0,0, 0,0 };
// --- Setup Paket for the Unknown5D --------------------------
BYTE by30unknown[ SIZEUSBHEADER + 30 ] =
{ 0x81,6,0,0x22,0,0, 30,0 };
//-----------------------------------------------------------//
//--- Byte array, used by K8055_Init ------------------------//
// - Used for setting configuration
//
// --- Setup Paket for Setting Configuration Number 1------
BYTE bySetConfigu[ SIZEUSBHEADER ] = { 0x00,9,1,0,0,0,0,0 };
//-----------------------------------------------------------//
//--- ULONG array, used by K8055_Init ------------------------//
// - Used for storing initialisation error codes
//
ULONG ulInitErrorStore[ 10 ] = { 0,0,0,0,0,0,0,0,0,0 };
//-----------------------------------------------------------//
//--- Byte arrays, used by K8055_Read and K8055_Write -------//
//
// --- Parameter Packet for Reading Data from Endpoint 81--
BYTE byaGetData[ SIZEGETBYTES ] =
{ 0xEC,0x10,0,0,0x81,3, 8,0 ,
0, 0, 0, 0, 0, 0, 0, 0 };
// --- Parameter Packet for Writing Data to Endpoint 01----
BYTE byaPutData[ SIZEPUTBYTES ] =
{ 0xEC,0x10,0,0,0x01,3, 8,0 ,
05, 0, 0, 0, 0, 0, 0, 0 };
//-----------------------------------------------------------//
//--- Byte array for K8055 Digital Inputs Decoder -----------//
BYTE byaDigInput[ 6 ] = { 0,16,32,1,64,128 };
//-----------------------------------------------------------//
//--- General purpose variables -----------------------------//
//
ULONG cbTransfer;
//-----------------------------------------------------------//
//--- Info strings ------------------------------------------//
//
CHAR szString1[INFO_STR_MAX_NUM][INFO_STR_CHARS_MAX] =
{ "1 abcdefghijklmnopqrstuvwxyzABCD\0",
"2 Authors: B. Hennig , U. Hinz \0",
"3 Date: 2011-07-12 \0",
"4 DLL-Version: 1.0.16 \0",
"5 Licence: BSD \0",
"6 DLL-Name: K8055DD \0" };
//-- ef ------------------------------------------- Begin ---//
// - Functions to be exported - //
//-----------------------------------------------------------1-
//
//
// Export Index 1
//
/**
* \brief 'K8055_Open()' will open one USB Device K8055 for
* later read or write operations.
* Those later operations include initialisation (Setup) and
* data exchange.
*
* \param 'pcaDeviceName'
* - Pointer to the character array that keeps the
* Device Name.
* In the 'CONFIG.SYS' statement it follows the
* N-Parameter.
* ( ..\usbecd.sys /D:10CF:5500:0000 /N:KDEV01 )
*
* \param 'pulFileDesc'
* - After 'K8055_Open()' was called successfully,
* it contains a Device ID (File ID) that represents
* that particular device within the OS.
* The opened K8055 remains open untill it will
* be closed by 'K8055_Close()'.
*
* \return 'ulrc'
* - Return Code. Meaning of bits listed below:
*
* 0x000 RET_OK Call returned with no error.
*
* 0x002 ERROR_POINTER Indicating parameter problems.
*
*
*/
ULONG K8055_Open( CHAR *pcaDeviceName, ULONG *pulFileDesc )
{
ULONG ulrc;
ULONG ulrcDosCall;
ULONG ulAction;
//
ulrc = RET_OKAY;
ulAction = 0;
//
if( (NULL == pulFileDesc) ||
(NULL == pcaDeviceName) )
{
ulrc = ulrc | ERROR_POINTER;
return ulrc;
}
//
ulrcDosCall = DosOpen( pcaDeviceName,
pulFileDesc,
&ulAction,
0, 0, 1, 18, 0 );
/*
0 NO_ERROR
2 ERROR_FILE_NOT_FOUND
3 ERROR_PATH_NOT_FOUND
4 ERROR_TOO_MANY_OPEN_FILES
5 ERROR_ACCESS_DENIED
12 ERROR_INVALID_ACCESS
26 ERROR_NOT_DOS_DISK
32 ERROR_SHARING_VIOLATION
36 ERROR_SHARING_BUFFER_EXCEEDED
82 ERROR_CANNOT_MAKE
87 ERROR_INVALID_PARAMETER
99 ERROR_DEVICE_IN_USE
108 ERROR_DRIVE_LOCKED
110 ERROR_OPEN_FAILED
112 ERROR_DISK_FULL
206 ERROR_FILENAME_EXCED_RANGE
231 ERROR_PIPE_BUSY
*/
if ( ulrcDosCall != 0 )
{
ulrc = ulrc | ERROR_FROM_CALL;
}
//
// printf("\nDosOpen ulrc=%hu ulAction=%hu",ulrc,ulAction);
return ulrc;
}
//----------1-
//-----------------------------------------------------------2-
//
//
// Export Index 2
//
/**
* \brief 'K8055_Init()' performs all steps that are needed to
* initialise K8055. First, device descriptors are read,
* then the configuration is set, and finally vendor requests
* are done. If this is done, K8055 is usable.
*
* \param 'pulFileDesc'
* - An application must consider, that more than one
* K8055 may exist. With this parameter a particular
* K8055 can be initialised.
*
*
* \return 'ulrc'
* - Return Code. Meaning of bits listed below:
*
* 0x000 RET_OK Call returned with no error.
*
* 0x001 ERROR_INIT Initialisation was not successful.
* Possible reasons:
* - Incorrect entry in 'CONFIG.SYS',
* - K8055 not working,
* - Any kind of hardware problem,
* - K8055 not plugged in.
*
* 0x002 ERROR_POINTER Indicating parameter problems.
*
* 0x010 ERROR_BUFFER Indicating a bad communication
* via Endpoint 0 (EP0) during
* initialisation.
*
*
*/
ULONG K8055_Init( ULONG *pulFileDesc )
{
ULONG ulrc;
ULONG ulrcSubFunc;
ULONG ulInitStepIdx;
ULONG ulArraySize;
//
ULONG index;
BOOL blTestSwitch;
//
ulrc = RET_OKAY;
ulrcSubFunc = RET_OKAY;
//
if( NULL == pulFileDesc )
{
// --- Return in case of problems.
// If the K8055 is not open,
// if the parameter is not valid.
//
return ERROR_POINTER;
}
// -- 1st Step: Reading Device Descriptor ------------
// ( from K8055 to PC via EP0 )
//
blTestSwitch = TRUE;
if ( blTestSwitch == TRUE )
{
ulInitStepIdx = 1;
ulrcSubFunc = GetDeviceDescriptor( *pulFileDesc );
ulInitErrorStore[ ulInitStepIdx ] = ulrcSubFunc;
// -- Testaid ---- Answer check --- 8+18 ----
blTestSwitch = FALSE;
if ( blTestSwitch == TRUE )
{
ulArraySize = 8 + 18;
PrintArray56Byte( &byGetDevDscr[0],
&ulArraySize );
}
// --- Number of read bytes to be checked: 0018 ---
if ( ! ( (byGetDevDscr[ 6 ] == 18) &&
(byGetDevDscr[ 7 ] == 0) ) )
{
ulrc = ulrc | ERROR_BUFFER;
}
//--------
delay(19);
}
//
// -- 2nd Step: Reading Configuration Descriptor -----
// ( from K8055 to PC via EP0 )
//
blTestSwitch = TRUE;
if ( blTestSwitch == TRUE )
{
ulInitStepIdx = 2;
ulrcSubFunc = GetConfigurationDescriptor( *pulFileDesc );
ulInitErrorStore[ ulInitStepIdx ] = ulrcSubFunc;
// -- Testaid ---- Answer check --- 8+41 ----
blTestSwitch = FALSE;
if ( blTestSwitch == TRUE )
{
ulArraySize = 8 + 41;
PrintArray56Byte( &byGetConfDscr[0],
&ulArraySize );
}
// --- Number of read bytes to be checked: 0041 ---
if ( ! ( (byGetConfDscr[ 6 ] == 41) &&
(byGetConfDscr[ 7 ] == 0) ) )
{
ulrc = ulrc | ERROR_BUFFER;
}
//--------
delay(19);
}
//
// -- 3rd Step: Reading Language Descriptor ----------
// ( from K8055 to PC via EP0 )
//
blTestSwitch = TRUE;
if ( blTestSwitch == TRUE )
{
ulInitStepIdx = 3;
ulrcSubFunc = GetLanguageDescriptor( *pulFileDesc );
ulInitErrorStore[ ulInitStepIdx ] = ulrcSubFunc;
// -- Testaid ---- Answer check --- 8+4 -----
blTestSwitch = FALSE;
if ( blTestSwitch == TRUE )
{
ulArraySize = 8 + 4;
PrintArray56Byte( &byGetLangStrDscr[0],
&ulArraySize );
}
// --- Number of read bytes to be checked: 0004 ---
if ( ! ( (byGetLangStrDscr[ 6 ] == 4) &&
(byGetLangStrDscr[ 7 ] == 0) ) )
{
ulrc = ulrc | ERROR_BUFFER;
}
//--------
delay(19);
}
//
// -- 4th Step: Reading 4th String Descriptor --------
// ( from K8055 to PC via EP0 )
//
blTestSwitch = TRUE;
if ( blTestSwitch == TRUE )
{
ulInitStepIdx = 4;
ulrcSubFunc = Get4thStringDescriptor( *pulFileDesc );
ulInitErrorStore[ ulInitStepIdx ] = ulrcSubFunc;
// -- Testaid ---- Answer check --- 8+4 -----
blTestSwitch = FALSE;
if ( blTestSwitch == TRUE )
{
ulArraySize = 8 + 4;
PrintArray56Byte( &byGet4thStrDscr[0],
&ulArraySize );
}
// --- Number of read bytes to be checked: 0004 ---
if ( ! ( (byGet4thStrDscr[ 6 ] == 4) &&
(byGet4thStrDscr[ 7 ] == 0) ) )
{
ulrc = ulrc | ERROR_BUFFER;
}
//--------
delay(19);
}
//
// -- 5th Step: Reading 2nd String Descriptor --------
// ( from K8055 to PC via EP0 )
//
blTestSwitch = TRUE;
if ( blTestSwitch == TRUE )
{
ulInitStepIdx = 5;
ulrcSubFunc = GetString2Descriptor( *pulFileDesc );
ulInitErrorStore[ ulInitStepIdx ] = ulrcSubFunc;
// -- Testaid ---- Answer check --- 8+20 ---
blTestSwitch = FALSE;
if ( blTestSwitch == TRUE )
{
ulArraySize = 8 + 20;
PrintArray56Byte( &byGetString2Dscr[0],
&ulArraySize );
}
// --- Number of read bytes to be checked: 0020 ---
if ( ! ( (byGetString2Dscr[ 6 ] == 20) &&
(byGetString2Dscr[ 7 ] == 0) ) )
{
ulrc = ulrc | ERROR_BUFFER;
}
//--------
delay(19);
}
//
// -- 6th Step: Setting Configuration ----------------
// ( from PC to K8055 via EP0 )
// K8055 has got only one (1) configuration.
// Nevertheless, K8055 must be activated this way.
//
blTestSwitch = TRUE;
if ( blTestSwitch == TRUE )
{
ulInitStepIdx = 6;
ulrcSubFunc = SetConfiguration( *pulFileDesc );
ulInitErrorStore[ ulInitStepIdx ] = ulrcSubFunc;
// -- Testaid ---- Answer check --- 8+0 ----
// SetConfiguration() has got no answer!
blTestSwitch = FALSE;
if ( blTestSwitch == TRUE )
{
ulArraySize = 8 + 0;
PrintArray56Byte( &bySetConfigu[0],
&ulArraySize );
}
// --- Number of read bytes to be checked: 0000 ---
if ( ! ( (bySetConfigu[ 6 ] == 0) &&
(bySetConfigu[ 7 ] == 0) ) )
{
ulrc = ulrc | ERROR_BUFFER;
}
//--------
delay(30);
}
//
// -- 7th Step: Writing an unknown Setup Packet ------
// ( from PC to K8055 via EP0 )
//
blTestSwitch = FALSE; //Blocked, unknown problem
if ( blTestSwitch == TRUE )
{
ulInitStepIdx = 7;
ulrcSubFunc = DoUnknown21( *pulFileDesc );
ulInitErrorStore[ ulInitStepIdx ] = ulrcSubFunc;
// -- Testaid ---- Answer check --- 8+0 ----
// DoUnknown21() has got no answer!
blTestSwitch = FALSE;
if ( blTestSwitch == TRUE )
{
ulArraySize = 8 + 1;
PrintArray56Byte( &by21unknown[0],
&ulArraySize );
}
// --- Number of read bytes to be checked: 0000 ---
if ( ! ( (by21unknown[ 6 ] == 1) &&
(by21unknown[ 7 ] == 0) ) )
{
ulrc = ulrc | ERROR_BUFFER;
}
//--------
delay(21);
}
//
// -- 8th Step: Writing an unknown Setup Packet ------
// ( from PC to K8055 via EP0 )
//
blTestSwitch = TRUE;
if ( blTestSwitch == TRUE )
{
ulInitStepIdx = 8;
ulrcSubFunc = DoUnknown30Bytes( *pulFileDesc );
ulInitErrorStore[ ulInitStepIdx ] = ulrcSubFunc;
// -- Testaid ---- Answer check --- 8+30 ---
blTestSwitch = FALSE;
if ( blTestSwitch == TRUE )
{
ulArraySize = 8 + 30;
PrintArray56Byte( &by30unknown[0],
&ulArraySize );
}
// --- Number of read bytes to be checked: 0029 ---
if ( ! ( (by30unknown[ 6 ] == 29) &&
(by30unknown[ 7 ] == 0) ) )
{
ulrc = ulrc | ERROR_BUFFER;
}
//--------
delay(19);
}
// -- Extra time allowing K8055 to get ready with the
// internal initialisation processes.
// How long it takes in fact ? - No idea !
//
delay(80);
// -- 9th Step: Reading data after initialisation ----
// ( from PC to K8055 )
// This step is not done with a Setup Packet.
// It is a normal data transfer operation, going
// via Endpoint 81 (EP81).
//
blTestSwitch = TRUE;
if ( blTestSwitch == TRUE )
{
ulInitStepIdx = 9;
ulrcSubFunc = Read_8_Bytes( *pulFileDesc );
ulInitErrorStore[ ulInitStepIdx ] = ulrcSubFunc;
// -- Testaid ---- Answer check --- 8+8 ---
blTestSwitch = FALSE;
if ( blTestSwitch == TRUE )
{
ulArraySize = 8 + 8;
PrintArray56Byte( &byaGetData[0],
&ulArraySize );
}
// -- Number of read bytes to be checked: 0008 ---
if ( ! ( (byaGetData[ 6 ] == 8) &&
(byaGetData[ 7 ] == 0) ) )
{
ulrc = ulrc | ERROR_BUFFER;
}
// ------
sleep(1);
}
// -- If one of the initalisation steps
// did not work, ERROR_INIT is set.
//
for ( index = 1; index <= 9; index++ )
{
if ( ulInitErrorStore[ index ] != 0 )
{
ulrc = ulrc | ERROR_INIT;
}
}
// -- If read bytes were missing, during the
// initialisation steps, ERROR_INIT is set.
if ( ( ulrc & ERROR_BUFFER ) != 0 )
{
ulrc = ulrc | ERROR_INIT;
}
// -- Testaid ---- Error Code ckeck ---
blTestSwitch = FALSE;
if ( blTestSwitch == TRUE )
{
ulArraySize = 10;
PrintArray10Ulong( &ulInitErrorStore, &ulArraySize );
printf("\n Error Code check: ");
printf( " %04X", ulrc );
}
// ToDo : ERROR_FROM_CALL
return ulrc;
}
//----------------2-
//-----------------------------------------------------------3-
//
//
// Export Index 3
//
/**
* \brief 'K8055_Read()' is for reading data from K8055 after
* its initialisation was done by 'K8055_Init()'.
* Every 10 miliseconds a new set of 8 data bytes can be
* claimed from the device.
*
* The position of the data bytes and their meaning are:
*
* { Ix xx A1 A2 I1cL I1cH I2cL I2cH }
*
* Ix - Digital Input
* (I1: 0x10, I2: 0x20, I3: 0x01, I4: 0x40, I5: 0x80,
* I6, I7, I8: not used)
* xx - unknown
* A1 - Analog Input 1 (0..255)
* A2 - Analog Input 2 (0..255)
* I1cL - Digital Input I1 Event Counter (Lower Byte)
* I1cH - dito (Higher Byte)
* (0..65535)
* I2cL - Digital Input I2 Event Counter (Lower Byte)
* I2cH - dito (Higher Byte)
* (0..65535)
*
*
* 'K8055_Read()' will not extract or decode single data bytes
* for convinience.
* Applications that want to make use of them have to do
* this as appropriate for their special needs.
*
* The function 'K8055_Read()' reads 8 data bytes from a buffer
* How big that buffer is and where it is, must be told by
* the parameters 'byNumberOfBytes' and 'pbyaGetData'.
*
* Caution!
* Using this function is risky, due to its weak error
* handling. Furthermore, an unsuited parameter can lead to
* unwanted consequences !
*
* \param 'pulFileDesc'
* - An application must know, that more than one
* K8055 may exist. With this parameter a particular
* K8055 can be addressed.
*
* \param 'byNumberOfBytes'
* - For K8055, the buffer that will hold the data
* after reading, is allways 8 bytes long.
*
* \param 'pbyaGetData'
* - Where to find the data after reading was done,
* is given with this parameter. 'pbyaGetData' points
* at the address of the first byte xx.
*
* \return - Return Code. Meaning of bits listed below:
*
* 0x000 RET_OK Call returned with no error.
*
* 0x002 ERROR_POINTER Indicating parameter problems.
*
*
*/
ULONG K8055_Read( ULONG *pulFileDesc,
BYTE byNumberOfBytes,
BYTE *pbyaData )
{
ULONG ulRc;
ULONG ulRcInnerCall;
//
ulRc = RET_OKAY;
//
if( (NULL == pulFileDesc) || (NULL == pbyaData) )
{
ulRc = ulRc | ERROR_POINTER;
return ulRc;
}
ulRcInnerCall = ReadNumberOfBytes( *pulFileDesc,
byNumberOfBytes,
pbyaData );
if ( ulRcInnerCall == ERROR_BUFFER )
{
ulRc = ulRcInnerCall;
return ulRc;
}
if ( ulRcInnerCall != 0 )
{
ulRc = ulRc | ERROR_FROM_CALL;
}
return ulRc;
}
//----------3-
//-----------------------------------------------------------4-
//
//
// Export Index 4
//
/**
* \brief 'K8055_Write()' is for sending data to an initialised
* K8055. Initialisation can be done with 'K8055_Init()' before.
* Then, a (new) set of 8 data bytes can be written.
*
* The timespan between two calls of 'K8055_Write()' must
* be longer than 10 milliseconds.
*
* Within that set of 8 data bytes the positions
* and their meaning are:
*
* { 0x05 DO DAC1 DAC2 xx xx xx xx }
*
* 0x05 - First byte is allways 0x05 - meaning unknown
* DO - Digital Output (0..255)
* DAC1 - Analog Output 1 (0..255)
* DAC2 - Analog Output 2 (0..255)
* xx - Unknown
*
* Caution!
* Using this function is risky, due to its weak error
* handling. Furthermore, an unsuited parameter can lead to
* unpredictable consequences !
*
* \param 'pulFileDesc'
* - An application must know, that more than one
* K8055 may exist. With this parameter a particular
* K8055 can be addressed.
*
* \param 'byNumberOfBytes'
* - 8 is the number of data bytes which will be put
* into the data byte section of that buffer.
* Any value different from 8 will lead to unforeseen
* results.
*
* \param 'pbyaPutData'
* - Where to find the data before writing,
* is given with this parameter. 'pbyaPutData' points
* at the address of the first byte. It is allway
* 0x05 as mentioned above.
*
* \return 'ulRc'
* - Return Code. Meaning of bits listed below:
*
* 0x000 RET_OK Call returned with no error.
*
* 0x002 ERROR_POINTER Indicating parameter problems.
*
*
*/
ULONG K8055_Write( ULONG *pulFileDesc,
BYTE byNumberOfBytes,
BYTE *pbyaPutData )
{
ULONG ulRc;
ULONG ulRcInnerCall;
//
ulRc = RET_OKAY;
//
if( (NULL == pulFileDesc) || (NULL == pbyaPutData) )
{
ulRc = ulRc | ERROR_POINTER;
return ulRc;
}
ulRcInnerCall = WriteNumberOfBytes( *pulFileDesc,
byNumberOfBytes,
pbyaPutData );
if ( ulRcInnerCall == ERROR_BUFFER )
{
ulRc = ulRcInnerCall;
return ulRc;
}
if ( ulRcInnerCall != 0 )
{
ulRc = ulRc | ERROR_FROM_CALL;
}
return ulRc;
}
//----------4-
//-----------------------------------------------------------5-
//
//
// Export Index 5
//
/**
* \bief The function 'K8055_Close()' will close a K8055
* which has been opened before. If the action was
* error free, no further interaction is possible with that
* particular K8055 any longer.
* If initialisation or data exchange are needed again,
* the correspondent function 'K8055_Open()' must be called
* before.
*
* \param 'pcaDeviceName'
* - Pointer to the character array that keeps the
* Device Name.
* In the 'CONFIG.SYS' statement it follows the
* N-Parameter. In example:
* ( ..\usbecd.sys /D:10CF:5500:0000 /N:K8055_$ )
*
* \return 'ulrc'
* - Return Code. Meaning of bits listed below:
*
* 0x000 RET_OK Call returned with no error.
*
* 0x002 ERROR_POINTER Indicating parameter problems.
*
*
*/
ULONG K8055_Close( ULONG *pulFileDesc )
{
ULONG ulrc;
ULONG ulrcDosCall;
//
ulrc = RET_OKAY;
if( NULL == pulFileDesc )
{
ulrc = ulrc | ERROR_POINTER;
return ulrc;
}
ulrcDosCall = DosClose( *pulFileDesc );
/* 'ulrcDosCall' can have the values listed here:
0 NO_ERROR
2 ERROR_FILE_NOT_FOUND
5 ERROR_ACCESS_DENIED
6 ERROR_INVALID_HANDLE
*/
if ( ulrcDosCall != 0 )
{
ulrc = ulrc | ERROR_FROM_CALL;
}
return ulrc;
}
//----------5-
//-----------------------------------------------------------6-
//
//
// Export Index 6
//
/**
* \brief The function 'K8055_DummyFunc()' is for testing
* purposes only. It provides a kind of Function Skeleton
* with no particular meaning.
*
* \param 'pulDummyParam'
* - A function without any parameter is no fun at all.
* 'K8055_DummyFunc' doesn't do anything at all.
*
* \return 'ulrc'
* - Return Code. This function has got no error
* handling. The only meaning is mentioned below:
*
* 0x000 RET_OK
*
*
*/
ULONG K8055_DummyFnc( ULONG *pulDummyParam )
{
ULONG ulrc;
//
ulrc = RET_OKAY;
return ulrc;
}