summaryrefslogtreecommitdiffstats
path: root/api/type.h
blob: d7cf2369c863a7f6e754d22de9abfac28eb43783 (plain)
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
#ifndef __TYPE_H__
#define __TYPE_H__

#include "userdef.h"// for Linux



#ifdef IN
#undef IN
#endif

#ifdef OUT
#undef OUT
#endif


#define IN
#define OUT
#define INOUT


/**
 * The type of handle.
 */
typedef void* Handle;


/**
 * The type defination of 8-bits unsigned type.
 */
typedef unsigned char Byte;


/**
 * The type defination of 16-bits unsigned type.
 */
typedef unsigned short Word;


/**
 * The type defination of 32-bits unsigned type.
 */
typedef unsigned long Dword;


/**
 * The type defination of 16-bits signed type.
 */
typedef short Short;


/**
 * The type defination of 32-bits signed type.
 */
typedef long Long;


#include "inttype.h"        /** releaseExternalRemove */

/**
 * The type defination of Bool
 */
typedef enum {
    False = 0,
    True = 1
} Bool;


/**
 * The type defination of Segment
 */
typedef struct {
    Byte segmentType;           /** 0:Firmware download 1:Rom copy 2:Direct command */
    Dword segmentLength;
} Segment;


/**
 * The type defination of Bandwidth.
 */
typedef enum {
    Bandwidth_6M = 0,           /** Signal bandwidth is 6MHz */
    Bandwidth_7M,               /** Signal bandwidth is 7MHz */
    Bandwidth_8M,               /** Signal bandwidth is 8MHz */
    Bandwidth_5M                /** Signal bandwidth is 5MHz */
} Bandwidth;


/**
 * The type defination of TransmissionMode.
 */
typedef enum {
    TransmissionMode_2K = 0,    /** OFDM frame consists of 2048 different carriers (2K FFT mode) */
    TransmissionMode_8K = 1,    /** OFDM frame consists of 8192 different carriers (8K FFT mode) */
    TransmissionMode_4K = 2     /** OFDM frame consists of 4096 different carriers (4K FFT mode) */
} TransmissionModes;


/**
 * The type defination of Constellation.
 */
typedef enum {
    Constellation_QPSK = 0,     /** Signal uses QPSK constellation  */
    Constellation_16QAM,        /** Signal uses 16QAM constellation */
    Constellation_64QAM         /** Signal uses 64QAM constellation */
} Constellation;


/**
 * The type defination of Interval.
 */
typedef enum {
    Interval_1_OVER_32 = 0,     /** Guard interval is 1/32 of symbol length */
    Interval_1_OVER_16,         /** Guard interval is 1/16 of symbol length */
    Interval_1_OVER_8,          /** Guard interval is 1/8 of symbol length  */
    Interval_1_OVER_4           /** Guard interval is 1/4 of symbol length  */
} Interval;


/**
 * The type defination of Priority.
 */
typedef enum {
    Priority_HIGH = 0,          /** DVB-T and DVB-H - identifies high-priority stream */
    Priority_LOW                /** DVB-T and DVB-H - identifies low-priority stream  */
} Priority;


/**
 * The type defination of CodeRate.
 */
typedef enum {
    CodeRate_1_OVER_2 = 0,      /** Signal uses FEC coding ratio of 1/2 */
    CodeRate_2_OVER_3,          /** Signal uses FEC coding ratio of 2/3 */
    CodeRate_3_OVER_4,          /** Signal uses FEC coding ratio of 3/4 */
    CodeRate_5_OVER_6,          /** Signal uses FEC coding ratio of 5/6 */
    CodeRate_7_OVER_8,          /** Signal uses FEC coding ratio of 7/8 */
    CodeRate_NONE               /** None, NXT doesn't have this one     */
} CodeRate;


/**
 * TPS Hierarchy and Alpha value.
 */
typedef enum {
    Hierarchy_NONE = 0,         /** Signal is non-hierarchical        */
    Hierarchy_ALPHA_1,          /** Signalling format uses alpha of 1 */
    Hierarchy_ALPHA_2,          /** Signalling format uses alpha of 2 */
    Hierarchy_ALPHA_4           /** Signalling format uses alpha of 4 */
} Hierarchy;


/**
 * The defination of SubchannelType.
 */
typedef enum {
    SubchannelType_AUDIO = 0,           /** Signal in subchannel is audio format          */
    SubchannelType_VIDEO = 1,           /** Signal in subchannel is video format          */
    SubchannelType_PACKET = 3,          /** Signal in subchannel is packet format         */
    SubchannelType_ENHANCEPACKET = 4    /** Signal in subchannel is enhance packet format */
} SubchannelType;


/**
 * The defination of ProtectionLevel.
 */
typedef enum {
    ProtectionLevel_NONE = 0x00,    /** The protection level of subchannel is none     */
    ProtectionLevel_PL1 = 0x01,     /** The protection level of subchannel is level 1  */
    ProtectionLevel_PL2 = 0x02,     /** The protection level of subchannel is level 2  */
    ProtectionLevel_PL3 = 0x03,     /** The protection level of subchannel is level 3  */
    ProtectionLevel_PL4 = 0x04,     /** The protection level of subchannel is level 4  */
    ProtectionLevel_PL5 = 0x05,     /** The protection level of subchannel is level 5  */
    ProtectionLevel_PL1A = 0x1A,    /** The protection level of subchannel is level 1A */
    ProtectionLevel_PL2A = 0x2A,    /** The protection level of subchannel is level 2A */
    ProtectionLevel_PL3A = 0x3A,    /** The protection level of subchannel is level 3A */
    ProtectionLevel_PL4A = 0x4A,    /** The protection level of subchannel is level 4A */
    ProtectionLevel_PL1B = 0x1B,    /** The protection level of subchannel is level 1B */
    ProtectionLevel_PL2B = 0x2B,    /** The protection level of subchannel is level 2B */
    ProtectionLevel_PL3B = 0x3B,    /** The protection level of subchannel is level 3B */
    ProtectionLevel_PL4B = 0x4B     /** The protection level of subchannel is level 4B */
} ProtectionLevel;


/**
 * The defination of ChannelInformation.
 */
typedef struct {
    Dword frequency;                    /** Channel frequency in KHz.                                */
    TransmissionModes transmissionMode; /** Number of carriers used for OFDM signal                  */
    Constellation constellation;        /** Constellation scheme (FFT mode) in use                   */
    Interval interval;                  /** Fraction of symbol length used as guard (Guard Interval) */
    Priority priority;                  /** The priority of stream                                   */
    CodeRate highCodeRate;              /** FEC coding ratio of high-priority stream                 */
    CodeRate lowCodeRate;               /** FEC coding ratio of low-priority stream                  */
    Hierarchy hierarchy;                /** Hierarchy levels of OFDM signal                          */
    Bandwidth bandwidth;
} ChannelModulation;


/**
 * The defination of SubchannelModulation. This structure is used to
 * represent subchannel modulation when device is operate in T-DMB/DAB mode.
 *
 */
typedef struct {
    Byte subchannelId;                  /** The ID of subchannel.                                                 */
    Word subchannelSize;                /** The size of subchannel.                                               */
    Word bitRate;                       /** The bit rate of subchannel.                                           */
    Byte transmissionMode;              /** The transmission mode of subchannel, possible values are: 1, 2, 3, 4. */
    ProtectionLevel protectionLevel;    /** The protection level of subchannel.                                   */
    SubchannelType subchannelType;      /** The type of subchannel                                                */
    Byte conditionalAccess;             /** If a conditional access exist                                         */
    Byte tiiPrimary;                    /** TII primary                                                           */
    Byte tiiCombination;                /** TII combination                                                       */
} SubchannelModulation;


/**
 * The type defination of IpVersion.
 */
typedef enum {
    IpVersion_IPV4 = 0,         /** The IP version if IPv4 */
    IpVersion_IPV6 = 1          /** The IP version if IPv6 */
} IpVersion;


/**
 * The type defination of Ip.
 */
typedef struct {
    IpVersion version;          /** The version of IP. See the defination of IpVersion.                                               */
    Priority priority;          /** The priority of IP. See the defination of Priority.                                               */
    Bool cache;                 /** True: IP datagram will be cached in device's buffer. Fasle: IP datagram will be transfer to host. */
    Byte address[16];           /** The byte array to store IP address.                                                               */
} Ip;


/**
 * The type defination of Platform.
 * Mostly used is in DVB-H standard
 */
typedef struct {
    Dword platformId;           /** The ID of platform.                                    */
    char iso639LanguageCode[3]; /** The ISO 639 language code for platform name.           */
    Byte platformNameLength;    /** The length of platform name.                           */
    char platformName[32];      /** The char array to store platform name.                 */
    Word bandwidth;             /** The operating channel bandwith of this platform.       */
    Dword frequency;            /** The operating channel frequency of this platform.      */
    Byte* information;          /** The extra information about this platform.             */
    Word informationLength;     /** The length of information.                             */
    Bool hasInformation;        /** The flag to indicate if there exist extra information. */
    IpVersion ipVersion;        /** The IP version of this platform.                       */
} Platform;


/**
 * The type defination of Label.
 */
typedef struct {
    Byte charSet;
    Word charFlag;
    Byte string[16];
} Label;


/**
 * The type defination of Ensemble.
 */
typedef struct {
    Word ensembleId;
    Label ensembleLabel;
    Byte totalServices;
} Ensemble;


/**
 * The type defination of Service.
 * Mostly used is in T-DMB standard
 */
typedef struct {
    Byte serviceType;       /** Service Type(P/D): 0x00: Program, 0x80: Data */
    Dword serviceId;
    Dword frequency;
    Label serviceLabel;
    Byte totalComponents;
} Service;


/**
 * The type defination of Service Component.
 */
typedef struct {
    Byte serviceType;           /** Service Type(P/D): 0x00: Program, 0x80: Data         */
    Dword serviceId;            /** Service ID                                           */
    Word componentId;           /** Stream audio/data is subchid, packet mode is SCId    */
    Byte componentIdService;    /** Component ID within Service                          */
    Label componentLabel;       /** The label of component. See the defination of Label. */
    Byte language;              /** Language code                                        */
    Byte primary;               /** Primary/Secondary                                    */
    Byte conditionalAccess;     /** Conditional Access flag                              */
    Byte componentType;         /** Component Type (A/D)                                 */
    Byte transmissionId;        /** Transmission Mechanism ID                            */
} Component;


/**
 * The type defination of Target.
 */
typedef enum {
    SectionType_MPE = 0,        /** Stands for MPE data.                                         */
    SectionType_SIPSI,          /** Stands for SI/PSI table, but don't have to specify table ID. */
    SectionType_TABLE           /** Stands for SI/PSI table.                                     */
} SectionType;


/**
 * The type defination of FrameRow.
 */
typedef enum {
    FrameRow_256 = 0,           /** There should be 256 rows for each column in MPE-FEC frame.  */
    FrameRow_512,               /** There should be 512 rows for each column in MPE-FEC frame.  */
    FrameRow_768,               /** There should be 768 rows for each column in MPE-FEC frame.  */
    FrameRow_1024               /** There should be 1024 rows for each column in MPE-FEC frame. */
} FrameRow;


/**
 * The type defination of Pid.
 *
 * In DVB-T mode, only value is valid. In DVB-H mode,
 * as sectionType = SectionType_SIPSI: only value is valid.
 * as sectionType = SectionType_TABLE: both value and table is valid.
 * as sectionType = SectionType_MPE: except table all other fields is valid.
 */
typedef struct {
    Byte table;                 /** The table ID. Which is used to filter specific SI/PSI table.                                  */
    Byte duration;              /** The maximum burst duration. It can be specify to 0xFF if user don't know the exact value.     */
    FrameRow frameRow;          /** The frame row of MPE-FEC. It means the exact number of rows for each column in MPE-FEC frame. */
    SectionType sectionType;    /** The section type of pid. See the defination of SectionType.                                   */
    Priority priority;          /** The priority of MPE data. Only valid when sectionType is set to SectionType_MPE.              */
    IpVersion version;          /** The IP version of MPE data. Only valid when sectionType is set to SectionType_MPE.            */
    Bool cache;                 /** True: MPE data will be cached in device's buffer. Fasle: MPE will be transfer to host.        */
    Word value;                 /** The 13 bits Packet ID.                                                                        */
} Pid;


/**
 * The type defination of ValueSet.
 */
typedef struct {
    Dword address;      /** The address of target register */
    Byte value;         /** The value of target register   */
} ValueSet;


/**
 * The type defination of Datetime.
 */
typedef struct {
    Dword mjd;              /** The mjd of datetime           */
    Byte configuration;     /** The configuration of datetime */
    Byte hours;             /** The hours of datetime         */
    Byte minutes;           /** The minutes of datetime       */
    Byte seconds;           /** The seconds of datetime       */
    Word milliseconds;      /** The milli seconds of datetime */
} Datetime;


/**
 * The type defination of Interrupts.
 */
typedef Word Interrupts;


/**
 * The type defination of Interrupt.
 */
typedef enum {
    Interrupt_NONE      = 0x0000,   /** No interrupt. */
    Interrupt_SIPSI     = 0x0001,
    Interrupt_DVBH      = 0x0002,
    Interrupt_DVBT      = 0x0004,
    Interrupt_PLATFORM  = 0x0008,
    Interrupt_VERSION   = 0x0010,
    Interrupt_FREQUENCY = 0x0020,
    Interrupt_SOFTWARE1 = 0x0040,
    Interrupt_SOFTWARE2 = 0x0080,
    Interrupt_FIC       = 0x0100,
    Interrupt_MSC       = 0x0200,
    Interrupt_MCISI     = 0x0400
} Interrupt;


/**
 * The type defination of Multiplier.
 */
typedef enum {
    Multiplier_1X = 0,
    Multiplier_2X
} Multiplier;


/**
 * The type defination of StreamType.
 */
typedef enum {
    StreamType_NONE = 0,            /** Invalid (Null) StreamType                */
    StreamType_DVBT_DATAGRAM = 3,   /** DVB-T mode, store data in device buffer  */
    StreamType_DVBT_PARALLEL,       /** DVB-T mode, output via paralle interface */
    StreamType_DVBT_SERIAL,         /** DVB-T mode, output via serial interface  */
} StreamType;


/**
 * The type defination of StreamType.
 */
typedef enum {
    Architecture_NONE = 0,      /** Inavalid (Null) Architecture.                                    */
    Architecture_DCA,           /** Diversity combine architecture. Only valid when chip number > 1. */
    Architecture_PIP            /** Picture in picture. Only valid when chip number > 1.             */
} Architecture;


/**
 * The type defination of ClockTable.
 */
typedef struct {
    Dword crystalFrequency;     /** The frequency of crystal. */
    Dword adcFrequency;         /** The frequency of ADC.     */
} ClockTable;


/**
 * The type defination of BandTable.
 */
typedef struct {
    Dword minimum;          /** The minimum frequency of this band */
    Dword maximum;          /** The maximum frequency of this band */
} BandTable;


/**
 * The type defination of MeanTable.
 */
typedef struct {
    Dword mean;
    Dword errorCount;
} MeanTable;


/**
 * The type defination of Polarity.
 */
typedef enum {
    Polarity_NORMAL = 0,
    Polarity_INVERSE
} Polarity;


/**
 * The type defination of Processor.
 */
typedef enum {
    Processor_LINK = 0,
    Processor_OFDM = 8
} Processor;


/**
 * The type defination of BurstSize.
 */
typedef enum {
    BurstSize_1024 = 0,
    BurstSize_2048,
    BurstSize_4096
} BurstSize;


/**
 * The type defination of Demodulator.
 */
typedef struct {
    Handle userData;
    Handle driver;
} Demodulator;


#include "user.h"


/**
 * The type defination of Statistic.
 */
typedef struct {
    Bool signalPresented;       /** Signal is presented.                                                                         */
    Bool signalLocked;          /** Signal is locked.                                                                            */
    Byte signalQuality;         /** Signal quality, from 0 (poor) to 100 (good).                                                 */
    Byte signalStrength;        /** Signal strength from 0 (weak) to 100 (strong).                                               */
} Statistic;


/**
 * General demodulator register-write function
 *
 * @param demodulator the handle of demodulator.
 * @param registerAddress address of register to be written.
 * @param bufferLength number, 1-8, of registers to be written.
 * @param buffer buffer used to store values to be written to specified
 *        registers.
 * @return Error_NO_ERROR: successful, non-zero error code otherwise.
 */
typedef Dword (*WriteRegisters) (
    IN  Demodulator*    demodulator,
    IN  Byte            chip,
    IN  Processor       processor,
    IN  Dword           registerAddress,
    IN  Byte            registerAddressLength,
    IN  Dword           writeBufferLength,
    IN  Byte*           writeBuffer
);


/**
 * General tuner register-write function
 *
 * @param demodulator the handle of demodulator.
 * @param registerAddress address of register to be written.
 * @param bufferLength number, 1-8, of registers to be written.
 * @param buffer buffer used to store values to be written to specified
 *        registers.
 * @return Error_NO_ERROR: successful, non-zero error code otherwise.
 */
typedef Dword (*WriteTunerRegisters) (
    IN  Demodulator*    demodulator,
    IN  Byte            chip,
    IN  Byte            tunerAddress,
    IN  Word            registerAddress,
    IN  Byte            registerAddressLength,
    IN  Byte            writeBufferLength,
    IN  Byte*           writeBuffer
);


/**
 * General write EEPROM function
 *
 * @param demodulator the handle of demodulator.
 * @param registerAddress address of register to be read.
 * @param bufferLength number, 1-8, of registers to be written.
 * @param buffer buffer used to store values to be written to specified
 *        registers.
 * @return Error_NO_ERROR: successful, non-zero error code otherwise.
 */
typedef Dword (*WriteEepromValues) (
    IN  Demodulator*    demodulator,
    IN  Byte            chip,
    IN  Byte            eepromAddress,
    IN  Word            registerAddress,
    IN  Byte            registerAddressLength,
    IN  Byte            writeBufferLength,
    IN  Byte*           writeBuffer
);


/**
 * General demodulator register-read function
 *
 * @param demodulator the handle of demodulator.
 * @param registerAddress address of register to be read.
 * @param bufferLength number, 1-8, of registers to be read.
 * @param buffer buffer used to store values to be read to specified
 *        registers.
 * @return Error_NO_ERROR: successful, non-zero error code otherwise.
 */
typedef Dword (*ReadRegisters) (
    IN  Demodulator*    demodulator,
    IN  Byte            chip,
    IN  Processor       processor,
    IN  Dword           registerAddress,
    IN  Byte            registerAddressLength,
    IN  Dword           readBufferLength,
    OUT Byte*           readBuffer
);


/**
 * General tuner register-read function
 *
 * @param demodulator the handle of demodulator.
 * @param registerAddress address of register to be read.
 * @param bufferLength number, 1-8, of registers to be read.
 * @param buffer buffer used to store values to be read to specified
 *        registers.
 * @return Error_NO_ERROR: successful, non-zero error code otherwise.
 */
typedef Dword (*ReadTunerRegisters) (
    IN  Demodulator*    demodulator,
    IN  Byte            chip,
    IN  Byte            tunerAddress,
    IN  Word            registerAddress,
    IN  Byte            registerAddressLength,
    IN  Byte            readBufferLength,
    IN  Byte*           readBuffer
);


/**
 * General read EEPROM function
 *
 * @param demodulator the handle of demodulator.
 * @param registerAddress address of register to be read.
 * @param bufferLength number, 1-8, of registers to be read.
 * @param buffer buffer used to store values to be read to specified
 *        registers.
 * @return Error_NO_ERROR: successful, non-zero error code otherwise.
 */
typedef Dword (*ReadEepromValues) (
    IN  Demodulator*    demodulator,
    IN  Byte            chip,
    IN  Byte            eepromAddress,
    IN  Word            registerAddress,
    IN  Byte            registerAddressLength,
    IN  Byte            readBufferLength,
    OUT Byte*           readBuffer
);


/**
 * General demodulator register-read function
 *
 * @param demodulator the handle of demodulator.
 * @param registerAddress address of register to be read.
 * @param bufferLength number, 1-8, of registers to be read.
 * @param buffer buffer used to store values to be read to specified
 *        registers.
 * @return Error_NO_ERROR: successful, non-zero error code otherwise.
 */
typedef Dword (*ModifyRegister) (
    IN  Demodulator*    demodulator,
    IN  Byte            chip,
    IN  Processor       processor,
    IN  Dword           registerAddress,
    IN  Byte            registerAddressLength,
    IN  Byte            position,
    IN  Byte            length,
    IN  Byte            value
);


/**
 * General load firmware function
 *
 * @param demodulator the handle of demodulator.
 * @param length The length of firmware.
 * @param firmware The byte array of firmware.
 * @return Error_NO_ERROR: successful, non-zero error code otherwise.
 */
typedef Dword (*LoadFirmware) (
    IN  Demodulator*    demodulator,
    IN  Dword           firmwareLength,
    IN  Byte*           firmware
);


/**
 * General reboot function
 *
 * @param demodulator the handle of demodulator.
 * @param length The length of firmware.
 * @param firmware The byte array of firmware.
 * @return Error_NO_ERROR: successful, non-zero error code otherwise.
 */
typedef Dword (*Reboot) (
    IN  Demodulator*    demodulator,
    IN  Byte            chip
);


/**
 * Find and Get bus handle used to control bus
 *
 * @param demodulator the handle of demodulator.
 * @param handle The bus handle.
 * @return Error_NO_ERROR: successful, non-zero error code otherwise.
 */
typedef Dword (*GetBus) (
    IN  Demodulator*    demodulator,
    OUT Handle*         handle
);


/**
 * Find and Get bus handle used to control bus
 *
 * @param demodulator the handle of demodulator.
 * @param bufferLength The length to transmit.
 * @param buffer The buffer which we store the data to send.
 * @return Error_NO_ERROR: successful, non-zero error code otherwise.
 */
typedef Dword (*BusTx) (
    IN  Demodulator*    demodulator,
    IN  Dword           bufferLength,
    IN  Byte*           buffer
);


/**
 * Find and Get bus handle used to control bus
 *
 * @param demodulator the handle of demodulator.
 * @param bufferLength The length to transmit.
 * @param buffer The buffer which we store the data to send.
 * @return Error_NO_ERROR: successful, non-zero error code otherwise.
 */
typedef Dword (*BusRx) (
    IN  Demodulator*    demodulator,
    IN  Dword           bufferLength,
    IN  Byte*           buffer
);


/**
 * Find and Get bus handle used to control bus
 *
 * @param demodulator the handle of demodulator.
 * @param registerAddress The starting address of memory to get.
 * @param readBufferLength The length of buffer to receive data.
 * @param readBuffer The buffer use to store received data
 * @return Error_NO_ERROR: successful, non-zero error code otherwise.
 */
typedef Dword (*BusRxData) (
    IN  Demodulator*    demodulator,
    IN  Dword           readBufferLength,
    OUT Byte*           readBuffer
);

/**
 * General send command function
 *
 * @param demodulator the handle of demodulator.
 * @param command The command which you wan.
 * @param valueLength value length.
 * @param valueBuffer value buffer.
 * @param referenceLength reference length.
 * @param referenceBuffer reference buffer.
 * @return Error_NO_ERROR: successful, non-zero error code otherwise.
 */
typedef Dword (*SendCommand) (
    IN  Demodulator*    demodulator,
    IN  Word            command,
    IN  Byte            chip,
    IN  Processor       processor,
    IN  Dword           writeBufferLength,
    IN  Byte*           writeBuffer,
    IN  Dword           readBufferLength,
    OUT Byte*           readBuffer
);


/**
 * General read EEPROM function
 *
 * @param demodulator the handle of demodulator.
 * @param registerAddress address of register to be read.
 * @param bufferLength number, 1-8, of registers to be read.
 * @param buffer buffer used to store values to be read to specified
 *        registers.
 * @return Error_NO_ERROR: successful, non-zero error code otherwise.
 */
typedef Dword (*ReceiveData) (
    IN  Demodulator*    demodulator,
    IN  Dword           registerAddress,
    IN  Dword           readBufferLength,
    OUT Byte*           readBuffer
);


/**
 * The type defination of BusDescription
 */
typedef struct {
    GetBus              getBus;
    BusTx               busTx;
    BusRx               busRx;
    BusRxData           busRxData;
} BusDescription;


/**
 * The type defination of BusDescription
 */
typedef struct {
    Dword                   mailBoxSize;
    BusDescription*         busDescription;
    WriteRegisters          writeRegisters;
    WriteTunerRegisters     writeTunerRegisters;
    WriteEepromValues       writeEepromValues;
    ReadRegisters           readRegisters;
    ReadTunerRegisters      readTunerRegisters;
    ReadEepromValues        readEepromValues;
    ModifyRegister          modifyRegister;
    LoadFirmware            loadFirmware;
    Reboot                  reboot;
    SendCommand             sendCommand;
    ReceiveData             receiveData;
} CmdDescription;


/**
 * General tuner opening function
 *
 * @param demodulator the handle of demodulator.
 * @return Error_NO_ERROR: successful, non-zero error code otherwise.
 */
typedef Dword (*OpenTuner) (
    IN  Demodulator*    demodulator,
    IN  Byte            chip
);


/**
 * General tuner closing function
 *
 * @param demodulator the handle of demodulator.
 * @return Error_NO_ERROR: successful, non-zero error code otherwise.
 */
typedef Dword (*CloseTuner) (
    IN  Demodulator*    demodulator,
    IN  Byte            chip
);


/**
 * General tuner setting function
 *
 * @param demodulator the handle of demodulator.
 * @return Error_NO_ERROR: successful, non-zero error code otherwise.
 */
typedef Dword (*SetTuner) (
    IN  Demodulator*    demodulator,
    IN  Byte            chip,
    IN  Word            bandwidth,
    IN  Dword           frequency
);


/**
 * The type defination of TunerDescription
 */
typedef struct {
    OpenTuner       openTuner;
    CloseTuner      closeTuner;
    SetTuner        setTuner;
    ValueSet*       tunerScript;
    Word*           tunerScriptSets;
    Byte            tunerAddress;
    Byte            registerAddressLength;
    Dword           ifFrequency;
    Bool            inversion;
    Word            tunerId;
} TunerDescription;


/**
 * The data structure of DefaultDemodulator
 */
typedef struct {
    /** Basic structure */
    Handle userData;
    Handle driver;
    Dword options;
    Word busId;
    CmdDescription* cmdDescription;
    Word tunerId;
    TunerDescription *tunerDescription;
} DefaultDemodulator;


/**
 * The data structure of Ganymede
 */
typedef struct {
    /** Basic structure */
    Handle userData;
    Handle driver;
    Dword options;
    Word busId;
    CmdDescription* cmdDescription;
    TunerDescription *tunerDescription;
    Byte* firmwareCodes;
    Segment* firmwareSegments;
    Byte* firmwarePartitions;
    Word* scriptSets;
    ValueSet* scripts;
    Word* tunerScriptSets;
    ValueSet* tunerScripts;
    Byte chipNumber;
    Dword crystalFrequency;
    Dword adcFrequency;
    StreamType streamType;
    Architecture architecture;
    Word bandwidth[2];
    Dword frequency[2];
    Dword fcw;
    Statistic statistic[2];
    ChannelStatistic channelStatistic[2];   /** releaseExternalRemove */
    Byte hostInterface[2];
    Bool booted;
    Bool initialized;

    /** DVB-T structure */
    Bool dataReady;
    BurstSize burstSize;
} Ganymede;


extern const Byte Standard_bitMask[8];
#define REG_MASK(pos, len)                (Standard_bitMask[len-1] << pos)
#define REG_CLEAR(temp, pos, len)         (temp & (~REG_MASK(pos, len)))
#define REG_CREATE(val, temp, pos, len)   ((val << pos) | (REG_CLEAR(temp, pos, len)))
#define REG_GET(value, pos, len)          ((value & REG_MASK(pos, len)) >> pos)
#define LOWBYTE(w)      ((Byte)((w) & 0xff))
#define HIGHBYTE(w)     ((Byte)((w >> 8) & 0xff))

#endif