summaryrefslogtreecommitdiffstats
path: root/api/mt2266_userdef.c
blob: cd325aca89b65453deaf35e208a9256d0cb5358c (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
/*****************************************************************************
**
**  Name: mt_userdef.c
**
**  Description:    User-defined MicroTuner software interface 
**
**  Functions
**  Requiring
**  Implementation: MT_WriteSub
**                  MT_ReadSub
**                  MT_Sleep
**
**  References:     None
**
**  Exports:        None
**
**  CVS ID:         $Id: mt_userdef.c,v 1.2 2006/10/26 16:39:18 software Exp $
**  CVS Source:     $Source: /export/home/cvsroot/software/tuners/MT2266/mt_userdef.c,v $
**	               
**  Revision History:
**
**   SCR      Date      Author  Description
**  -------------------------------------------------------------------------
**   N/A   03-25-2004    DAD    Original
**
*****************************************************************************/
#include "mt2266_userdef.h"


/*****************************************************************************
**
**  Name: MT_WriteSub
**
**  Description:    Write values to device using a two-wire serial bus.
**
**  Parameters:     handle  - User-specific I/O parameter that was
**                               passed to tuner's Open function.
**                  addr       - device serial bus address  (value passed
**                               as parameter to MTxxxx_Open)
**                  subAddress - serial bus sub-address (Register Address)
**                  data      - pointer to the Data to be written to the 
**                               device 
**                  cnt        - number of bytes/registers to be written
**
**  Returns:        status:
**                      MT_OK            - No errors
**                      MT_COMM_ERR      - Serial bus communications error
**                      user-defined
**
**  Notes:          This is a callback function that is called from the
**                  the tuning algorithm.  You MUST provide code for this
**                  function to write data using the tuner's 2-wire serial 
**                  bus.
**
**                  The handle parameter is a user-specific argument.
**                  If additional arguments are needed for the user's
**                  serial bus read/write functions, this argument can be
**                  used to supply the necessary information.
**                  The handle parameter is initialized in the tuner's Open
**                  function.
**
**  Revision History:
**
**   SCR      Date      Author  Description
**  -------------------------------------------------------------------------
**   N/A   03-25-2004    DAD    Original
**
*****************************************************************************/
UData_t MT2266_WriteSub(Handle_t handle, 
                    UData_t addr, 
                    U8Data subAddress, 
                    U8Data *data, 
                    UData_t cnt)
{
    UData_t status = MT_OK;                  /* Status to be returned        */
    /*
    **  ToDo:  Add code here to implement a serial-bus write
    **         operation to the MTxxxx tuner.  If successful,
    **         return MT_OK.
    */
    PUserData   userData;
    U8Data *    buffer;
    U8Data      i;
    U8Data      blocks;
    U8Data      remains;

    blocks =  (U8Data) (cnt / 17);
    remains = (U8Data) (cnt % 17);

    userData = (PUserData) handle;

    buffer = data;
    for (i = 0; i < blocks; i++) {        
		status = Standard_writeTunerRegisters (userData->demodulator, userData->chip, (unsigned short)subAddress + (unsigned short)i * 17, 17, buffer);
        if (status) goto exit;

        buffer += 17;
    }

    if (remains)
    {
        status = Standard_writeTunerRegisters (userData->demodulator, userData->chip, (unsigned short)subAddress + (unsigned short)i * 17, remains, buffer);
        if (status) goto exit;
    }

exit:
    return (status);
}


/*****************************************************************************
**
**  Name: MT_ReadSub
**
**  Description:    Read values from device using a two-wire serial bus.
**
**  Parameters:     handle  - User-specific I/O parameter that was
**                               passed to tuner's Open function.
**                  addr       - device serial bus address  (value passed
**                               as parameter to MTxxxx_Open)
**                  subAddress - serial bus sub-address (Register Address)
**                  data      - pointer to the Data to be written to the 
**                               device 
**                  cnt        - number of bytes/registers to be written
**
**  Returns:        status:
**                      MT_OK            - No errors
**                      MT_COMM_ERR      - Serial bus communications error
**                      user-defined
**
**  Notes:          This is a callback function that is called from the
**                  the tuning algorithm.  You MUST provide code for this
**                  function to read data using the tuner's 2-wire serial 
**                  bus.
**
**                  The handle parameter is a user-specific argument.
**                  If additional arguments are needed for the user's
**                  serial bus read/write functions, this argument can be
**                  used to supply the necessary information.
**                  The handle parameter is initialized in the tuner's Open
**                  function.
**
**  Revision History:
**
**   SCR      Date      Author  Description
**  -------------------------------------------------------------------------
**   N/A   03-25-2004    DAD    Original
**
*****************************************************************************/
UData_t MT2266_ReadSub(Handle_t handle, 
                   UData_t addr, 
                   U8Data subAddress, 
                   U8Data *data, 
                   UData_t cnt)
{
    UData_t status = MT_OK;                        /* Status to be returned        */

    /*
    **  ToDo:  Add code here to implement a serial-bus read
    **         operation to the MTxxxx tuner.  If successful,
    **         return MT_OK.
    */
    PUserData   userData;
    U8Data      buffer[8];
    U8Data      i;

    /*
    **  ToDo:  Add code here to implement a serial-bus read
    **         operation to the MTxxxx tuner.  If successful,
    **         return true.
    */
    userData = (PUserData)handle;

    for (i = 0; i < cnt; i++)
    {
		status = Standard_readTunerRegisters (userData->demodulator, userData->chip, subAddress + i, (U8Data)1, &buffer[0]);
        if (status) goto exit;
        *(data + i) = buffer[0];
    }

exit:
    return (status);
}


/*****************************************************************************
**
**  Name: MT_Sleep
**
**  Description:    Delay execution for "nMinDelayTime" milliseconds
**
**  Parameters:     handle     - User-specific I/O parameter that was
**                                  passed to tuner's Open function.
**                  nMinDelayTime - Delay time in milliseconds
**
**  Returns:        None.
**
**  Notes:          This is a callback function that is called from the
**                  the tuning algorithm.  You MUST provide code that
**                  blocks execution for the specified period of time. 
**
**  Revision History:
**
**   SCR      Date      Author  Description
**  -------------------------------------------------------------------------
**   N/A   03-25-2004    DAD    Original
**
*****************************************************************************/
void MT2266_Sleep(Handle_t handle, 
              UData_t nMinDelayTime)
{
    PUserData   userData;
    /*
    **  ToDo:  Add code here to implement a OS blocking
    **         for a period of "nMinDelayTime" milliseconds.
    */
   userData = (PUserData)handle;

   User_delay (userData->demodulator, (unsigned long) nMinDelayTime);
}


#if defined(MT2060_CNT)
#if MT2060_CNT > 0
/*****************************************************************************
**
**  Name: MT_TunerGain  (MT2060 only)
**
**  Description:    Measure the relative tuner gain using the demodulator
**
**  Parameters:     handle  - User-specific I/O parameter that was
**                               passed to tuner's Open function.
**                  pMeas      - Tuner gain (1/100 of dB scale).
**                               ie. 1234 = 12.34 (dB)
**
**  Returns:        status:
**                      MT_OK  - No errors
**                      user-defined errors could be set
**
**  Notes:          This is a callback function that is called from the
**                  the 1st IF location routine.  You MUST provide
**                  code that measures the relative tuner gain in a dB
**                  (not linear) scale.  The return value is an integer
**                  value scaled to 1/100 of a dB.
**
**  Revision History:
**
**   SCR      Date      Author  Description
**  -------------------------------------------------------------------------
**   N/A   06-16-2004    DAD    Original
**   N/A   11-30-2004    DAD    Renamed from MT_DemodInputPower.  This name
**                              better describes what this function does.
**
*****************************************************************************/
int IfGainTable[256] = {
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	6000,
	5993,
	5987,
	5981,
	5975,
	5968,
	5962,
	5956,
	5950,
	5949,
	5948,
	5947,
	5946,
	5945,
	5944,
	5943,
	5942,
	5941,
	5940,
	5939,
	5938,
	5937,
	5937,
	5936,
	5935,
	5934,
	5933,
	5932,
	5931,
	5930,
	5929,
	5928,
	5927,
	5926,
	5925,
	5925,
	5924,
	5923,
	5922,
	5921,
	5920,
	5919,
	5918,
	5917,
	5916,
	5915,
	5914,
	5913,
	5912,
	5912,
	5911,
	5910,
	5909,
	5908,
	5907,
	5906,
	5905,
	5904,
	5903,
	5902,
	5901,
	5900,
	5900,
	5885,
	5871,
	5857,
	5842,
	5828,
	5814,
	5800,
	5785,
	5771,
	5757,
	5742,
	5728,
	5714,
	5700,
	5685,
	5671,
	5657,
	5642,
	5628,
	5614,
	5600,
	5585,
	5571,
	5557,
	5542,
	5528,
	5514,
	5500,
	5485,
	5471,
	5457,
	5442,
	5428,
	5414,
	5400,
	5381,
	5362,
	5344,
	5325,
	5307,
	5288,
	5270,
	5251,
	5233,
	5214,
	5196,
	5177,
	5159,
	5140,
	5122,
	5103,
	5085,
	5066,
	5048,
	5029,
	5011,
	4992,
	4974,
	4955,
	4937,
	4918,
	4900,
	4871,
	4842,
	4813,
	4784,
	4755,
	4726,
	4697,
	4668,
	4639,
	4610,
	4581,
	4552,
	4523,
	4494,
	4465,
	4436,
	4407,
	4378,
	4350,
	4318,
	4287,
	4256,
	4225,
	4193,
	4162,
	4131,
	4100,
	4068,
	4037,
	4006,
	3975,
	3943,
	3912,
	3881,
	3850,
	3809,
	3768,
	3727,
	3686,
	3645,
	3604,
	3563,
	3522,
	3481,
	3440,
	3400,
	3358,
	3316,
	3275,
	3233,
	3191,
	3150,
	3108,
	3066,
	3025,
	2983,
	2941,
	2900,
	2900,
	2900,
	2900,
	2900,
	2900,
	2900,
	2900,
	2900,
	2900,
	2900,
	2900,
	2900,
	2900,
	2900,
	2900,
	2900,
	2900,
	2900,
	2900,
	2900,
	2900,
	2900,
	2900,
	2900,
	2900,
	2900,
	2900
};

UData_t MT2266_TunerGain(Handle_t handle,
                     SData_t* pMeas)
{
    UData_t status = MT_OK;                        /* Status to be returned        */
    U8Data      rfAgc;
    U8Data      ifAgc;
    PUserData   userData;

    /*
    **  ToDo:  Add code here to return the gain / power level measured
    **         at the input to the demodulator.
    */


    /*
    **  ToDo:  Add code here to return the gain / power level measured
    **         at the input to the demodulator.
    */
    userData = (PUserData)handle;

    MT2060_Sleep(handle, 100);

    status = Standard_getIfAgcGain (userData->demodulator, userData->chip, &rfAgc, &ifAgc);
    if (status) goto exit;

    *pMeas = IfGainTable[ifAgc];

exit:
    return (status);
}
#endif
#endif