summaryrefslogtreecommitdiffstats
path: root/api/Freescale_MC44CD02.c
blob: bf810ea604fd13760cfe6dd600e921c03e102d36 (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
/**
 * @(#)Freescale_MC44CD02.cpp
 *
 * ==========================================================
 * Version: 2.0
 * Date:    2008.07.02
 * ==========================================================
 *
 * ==========================================================
 * History:
 *
 * Date         Author      Description
 * ----------------------------------------------------------
 *
 * 2008.07.02   Tom Lin     added tuner version
 * ==========================================================
 *
 * Copyright 2005 Afatech, Inc. All rights reserved.
 *
 */


//#include <stdio.h> //for Linux
#include "type.h"
#include "error.h"
#include "user.h"
#include "register.h"
#include "standard.h"
#include "Freescale_MC44CD02_Script.h"


Bool powerDownMode = False;
Bool bandLockActivated = False;
Bool analogTestMode = False;
Byte referenceClock = 36;
Dword programmableDivider;
Short dischargingCurrent = 266;
Short chargingCurrent = 836;
Short offsetAdjustment = -109;
Short gainAdjustment = 221;
Bool singleEndBuffer = True;
Bool outputDriverDisabled = False;
Byte sineWaveAmplitude = 1;
Bool squareWaveShape = False;
Bool clockHasPriority = False;
Byte kneeVoltageShift = 0;
Bool antiAliasingDisabled = False;
Bool openDrainOutput = False;
Bool stateOfOutputPort = False;
Byte postAmplifierGain = 14;


Dword MC44CD02_open (
	IN  Demodulator*	demodulator,
	IN  Byte			chip
) {
    Dword error = Error_NO_ERROR;
	Byte values[7];

	values[0] = 0;
	if (powerDownMode == True)
		values[0] |= 0x04;
	if (bandLockActivated == True)
		values[0] |= 0x02;
	if (analogTestMode == True)
		values[0] |= 0x01;

	values[1] = 0;
	if (referenceClock == 26)
		values[1] |= 0x20;
	programmableDivider = (666 * 6) / 1000;
	values[1] |= (Byte) ((programmableDivider & 0x1F00) >> 8);

	values[2] = (Byte) (programmableDivider & 0x00FF);

	values[3] = 0;
	switch (chargingCurrent) {
		case 266 :
			values[3] |= 0x00;
			break;
		case 106 :
			values[3] |= 0x08;
			break;
		case 159 :
			values[3] |= 0x10;
			break;
		case 213 :
			values[3] |= 0x18;
			break;
		case 319 :
			values[3] |= 0x20;
			break;
		case 379 :
			values[3] |= 0x21;
			break;
		case 425 :
			values[3] |= 0x30;
			break;
		default :
			values[3] |= 0x31;
	}
	switch (chargingCurrent) {
		case 836 :
			values[3] |= 0x00;
			break;
		case 790 :
			values[3] |= 0x01;
			break;
		case 744 :
			values[3] |= 0x02;
			break;
		case 698 :
			values[3] |= 0x03;
			break;
		case 880 :
			values[3] |= 0x04;
			break;
		case 924 :
			values[3] |= 0x05;
			break;
		case 967 :
			values[3] |= 0x06;
			break;
		case 1011 :
			values[3] |= 0x07;
	}

	values[4] = 0;
	switch (offsetAdjustment) {
		case -109 :
			values[4] |= 0x00;
			break;
		case -73 :
			values[4] |= 0x08;
			break;
		case -36 :
			values[4] |= 0x10;
			break;
		case 0 :
			values[4] |= 0x18;
			break;
		case 39 :
			values[4] |= 0x20;
			break;
		case 77 :
			values[4] |= 0x21;
			break;
		case 116 :
			values[4] |= 0x30;
			break;
		case 154 :
			values[4] |= 0x31;
	}
	switch (gainAdjustment) {
		case 221 :
			values[4] |= 0x00;
			break;
		case 227 :
			values[4] |= 0x01;
			break;
		case 233 :
			values[4] |= 0x02;
			break;
		case 240 :
			values[4] |= 0x03;
			break;
		case 247 :
			values[4] |= 0x04;
			break;
		case 255 :
			values[4] |= 0x05;
			break;
		case 264 :
			values[4] |= 0x06;
			break;
		case 274 :
			values[4] |= 0x07;
	}

	values[5] = 0;
	if (singleEndBuffer == True)
		values[5] |= 0x80;
	if (outputDriverDisabled == True)
		values[5] |= 0x40;
	if (sineWaveAmplitude == 1)
		values[5] |= 0x20;
	if (squareWaveShape == True)
		values[5] |= 0x08;
	if (clockHasPriority == True)
		values[5] |= 0x04;
	if (kneeVoltageShift == 0)
		values[5] |= 0x00;

	values[6] = 0;
	if (antiAliasingDisabled == True)
		values[6] |= 0x40;
	if (openDrainOutput == True)
		values[6] |= 0x20;
	if (stateOfOutputPort == True)
		values[6] |= 0x10;
	switch (postAmplifierGain) {
		case 14 :
			values[6] |= 0x00;
			break;
		case 10 :
			values[6] |= 0x04;
			break;
		case 12 :
			values[6] |= 0x08;
			break;
	}
	switch (8) {
		case 8 :
			values[6] |= 0x00;
			break;
		case 7 :
			values[6] |= 0x02;
			break;
		case 6 :
			values[6] |= 0x03;
			break;
	}

	error = Standard_writeTunerRegisters (demodulator, chip, 0x00, 7, values); 

	return (error);
}


Dword MC44CD02_close (
	IN  Demodulator*	demodulator,
	IN  Byte			chip
) {
    Dword error = Error_NO_ERROR;
	return (error);
}


Dword MC44CD02_set (
	IN  Demodulator*	demodulator,
	IN  Byte			chip,
    IN  Word			bandwidth,
    IN  Dword			frequency
) {
    Dword error = Error_NO_ERROR;
	Byte values[2];

	values[0] = 0;
	if (referenceClock == 26)
		values[0] |= 0x20;
	programmableDivider = (frequency * 6) / 1000;
	values[0] |= (Byte) ((programmableDivider & 0x1F00) >> 8);

	values[1] = (Byte) (programmableDivider & 0x00FF);

	error = Standard_writeTunerRegisters (demodulator, chip, 0x01, 2, values); 
	if (error) goto exit;

	values[0] = 0;
	if (antiAliasingDisabled == True)
		values[0] |= 0x40;
	if (openDrainOutput == True)
		values[0] |= 0x20;
	if (stateOfOutputPort == True)
		values[0] |= 0x10;
	switch (postAmplifierGain) {
		case 14 :
			values[0] |= 0x00;
			break;
		case 10 :
			values[0] |= 0x04;
			break;
		case 12 :
			values[0] |= 0x08;
			break;
	}
	switch (bandwidth) {
		case 8000 :
			values[0] |= 0x00;
			break;
		case 7000 :
			values[0] |= 0x02;
			break;
		case 6000 :
			values[0] |= 0x03;
			break;
	}

	error = Standard_writeTunerRegisters (demodulator, chip, 0x06, 1, values); 

exit :
	return (error);
}


TunerDescription tuner_MC44CD02 = {
    MC44CD02_open,
    MC44CD02_close,
    MC44CD02_set,
    MC44CD02_scripts,
    MC44CD02_scriptSets,
    MC44CD02_ADDRESS,               /** tuner i2c address */
    1,                              /** length of tuner register address */
    0,                              /** tuner if */
    True,                           /** spectrum inverse */
    0x20,                           /** tuner id */
};