summaryrefslogtreecommitdiff
path: root/software/octdeviceapi/oct6100api/oct6100_miscellaneous_priv.h
blob: 67828193201fc7cb91a5e92378edc2c24e91cce1 (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
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

File:  oct6100_miscellaneous_priv.h

    Copyright (c) 2001-2011 Octasic Inc.
    
Description: 

	File containing all private defines, macros, structures and prototypes 
	pertaining to the file oct6100_miscellaneous.c.  All elements defined in 
	this file are for private usage of the API.

This file is part of the Octasic OCT6100 GPL API . The OCT6100 GPL API  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 2 of the License, or (at your option) any later version.

The OCT6100 GPL API 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 the OCT6100 GPL API; if not, write to the Free Software 
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.

$Octasic_Release: OCT612xAPI-01.04.05 $

$Octasic_Revision: 20 $

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/

#ifndef __OCT6100_MISCELLANEOUS_PRIV_H__
#define __OCT6100_MISCELLANEOUS_PRIV_H__

/*****************************  INCLUDE FILES  *******************************/


/*****************************  DEFINES  *************************************/


/*---------------------------------------------------------------------------*\
	Macros used to shell the user function calls.  These macros are used to
	assert that the user does not change any of the members of the function's
	parameter structure, as required and indicated in the API specification.
	Ofcourse, these macros make the code heavier and thus slower.  That is why
	there is a compile option for disabling the extra checking.  These can be
	very helpful tools in debugging.
\*---------------------------------------------------------------------------*/

#ifndef cOCT6100_REMOVE_USER_FUNCTION_CHECK
#define mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )					\
{																			\
	PVOID	_pProcessContext;												\
	UINT32	_ulUserChipId;													\
	UINT32	_ulWriteAddress;												\
	UINT16	_usWriteData;													\
																			\
	/* Store the data that is to be passed to the user. */					\
	_pProcessContext = WriteParams.pProcessContext;							\
	_ulUserChipId = WriteParams.ulUserChipId;								\
	_ulWriteAddress = WriteParams.ulWriteAddress;							\
	_usWriteData = WriteParams.usWriteData;									\
																			\
	/* Call user function. */												\
	ulResult = Oct6100UserDriverWriteApi( &WriteParams );					\
																			\
	/* Check if user changed members of function's parameter structure. */	\
	if ( WriteParams.pProcessContext != _pProcessContext ||					\
		 WriteParams.ulUserChipId != _ulUserChipId ||						\
		 WriteParams.ulWriteAddress != _ulWriteAddress ||					\
		 WriteParams.ulWriteAddress != _ulWriteAddress ||					\
		 WriteParams.usWriteData != _usWriteData )							\
		ulResult = cOCT6100_ERR_FATAL_DRIVER_WRITE_API;						\
}
#else																		
#define mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult )					\
	ulResult = Oct6100UserDriverWriteApi( &WriteParams );
#endif /* cOCT6100_REMOVE_USER_FUNCTION_CHECK */


#ifndef cOCT6100_REMOVE_USER_FUNCTION_CHECK
#define mOCT6100_DRIVER_WRITE_SMEAR_API( SmearParams, ulResult )				\
{																				\
	PVOID	_pProcessContext;													\
	UINT32	_ulUserChipId;														\
	UINT32	_ulWriteAddress;													\
	UINT16	_usWriteData;														\
	UINT32	_ulWriteLength;														\
																				\
	/* Store the data that is to be passed to the user. */						\
	_pProcessContext = SmearParams.pProcessContext;								\
	_ulUserChipId = SmearParams.ulUserChipId;									\
	_ulWriteAddress = SmearParams.ulWriteAddress;								\
	_usWriteData = SmearParams.usWriteData;										\
	_ulWriteLength = SmearParams.ulWriteLength;									\
																				\
	/* Call user function. */													\
	ulResult = Oct6100UserDriverWriteSmearApi( &SmearParams );					\
																				\
	/* Check if user changed members of function's paraeter structure. */		\
	if ( SmearParams.pProcessContext != _pProcessContext ||						\
		 SmearParams.ulUserChipId != _ulUserChipId ||							\
		 SmearParams.usWriteData != _usWriteData ||								\
		 SmearParams.ulWriteLength != _ulWriteLength)							\
		ulResult = cOCT6100_ERR_FATAL_DRIVER_WRITE_SMEAR_API;					\
}
#else																		
#define mOCT6100_DRIVER_WRITE_SMEAR_API( SmearParams, ulResult )				\
	ulResult = Oct6100UserDriverWriteSmearApi( &SmearParams );
#endif /* cOCT6100_REMOVE_USER_FUNCTION_CHECK */


#ifndef cOCT6100_REMOVE_USER_FUNCTION_CHECK
#define mOCT6100_DRIVER_WRITE_BURST_API( BurstParams, ulResult )			\
{																			\
	PVOID	_pProcessContext;												\
	UINT32	_ulUserChipId;													\
	UINT32	_ulWriteAddress;												\
	PUINT16	_pusWriteData;													\
	UINT32	_ulWriteLength;													\
																			\
	/* Store the data that is to be passed to the user. */					\
	_pProcessContext = BurstParams.pProcessContext;							\
	_ulUserChipId = BurstParams.ulUserChipId;								\
	_ulWriteAddress = BurstParams.ulWriteAddress;							\
	_pusWriteData = BurstParams.pusWriteData;								\
	_ulWriteLength = BurstParams.ulWriteLength;								\
																			\
	/* Call user function. */												\
	ulResult = Oct6100UserDriverWriteBurstApi( &BurstParams );				\
																			\
	/* Check if user changed members of function's parameter structure. */	\
	if ( BurstParams.pProcessContext != _pProcessContext ||					\
		 BurstParams.ulUserChipId != _ulUserChipId ||						\
		 BurstParams.ulWriteAddress != _ulWriteAddress ||					\
		 BurstParams.pusWriteData != _pusWriteData ||						\
		 BurstParams.ulWriteLength != _ulWriteLength )						\
		ulResult = cOCT6100_ERR_FATAL_DRIVER_WRITE_BURST_API;				\
}
#else																		
#define mOCT6100_DRIVER_WRITE_BURST_API( BurstParams, ulResult )			\
	ulResult = Oct6100UserDriverWriteBurstApi( &BurstParams );
#endif /* cOCT6100_REMOVE_USER_FUNCTION_CHECK */


#ifndef cOCT6100_REMOVE_USER_FUNCTION_CHECK
#define mOCT6100_DRIVER_READ_API( ReadParams, ulResult )					\
{																			\
	PVOID	_pProcessContext;												\
	UINT32	_ulUserChipId;													\
	UINT32	_ulReadAddress;													\
	PUINT16	_pusReadData;													\
																			\
	/* Store the data that is to be passed to the user. */					\
	_pProcessContext = ReadParams.pProcessContext;							\
	_ulUserChipId = ReadParams.ulUserChipId;								\
	_ulReadAddress = ReadParams.ulReadAddress;								\
	_pusReadData = ReadParams.pusReadData;									\
																			\
	/* Call user function. */												\
	ulResult = Oct6100UserDriverReadApi( &ReadParams );						\
																			\
	/* Check if user changed members of function's parameter structure. */	\
	if ( ReadParams.pProcessContext != _pProcessContext ||					\
		 ReadParams.ulUserChipId != _ulUserChipId ||						\
		 ReadParams.ulReadAddress != _ulReadAddress ||						\
		 ReadParams.pusReadData != _pusReadData )							\
		ulResult = cOCT6100_ERR_FATAL_DRIVER_READ_API;						\
}
#else																		
#define mOCT6100_DRIVER_READ_API( ReadParams, ulResult )					\
	ulResult = Oct6100UserDriverReadApi( &ReadParams );
#endif /* cOCT6100_REMOVE_USER_FUNCTION_CHECK */


#ifndef cOCT6100_REMOVE_USER_FUNCTION_CHECK
#define mOCT6100_DRIVER_READ_BURST_API( BurstParams, ulResult )				\
{																			\
	PVOID	_pProcessContext;												\
	UINT32	_ulUserChipId;													\
	UINT32	_ulReadAddress;													\
	PUINT16	_pusReadData;													\
	UINT32	_ulReadLength;													\
																			\
	/* Store the data that is to be passed to the user. */					\
	_pProcessContext = BurstParams.pProcessContext;							\
	_ulUserChipId = BurstParams.ulUserChipId;								\
	_ulReadAddress = BurstParams.ulReadAddress;								\
	_pusReadData = BurstParams.pusReadData;									\
	_ulReadLength = BurstParams.ulReadLength;								\
																			\
	/* Call user function. */												\
	ulResult = Oct6100UserDriverReadBurstApi( &BurstParams );				\
																			\
	/* Check if user changed members of function's parameter structure. */	\
	if ( BurstParams.pProcessContext != _pProcessContext ||					\
		 BurstParams.ulUserChipId != _ulUserChipId ||						\
		 BurstParams.ulReadAddress != _ulReadAddress ||						\
		 BurstParams.pusReadData != _pusReadData ||							\
		 BurstParams.ulReadLength != _ulReadLength )						\
		ulResult = cOCT6100_ERR_FATAL_DRIVER_READ_BURST_API;				\
}
#else																		
#define mOCT6100_DRIVER_READ_BURST_API( BurstParams, ulResult )				\
	ulResult = Oct6100UserDriverReadBurstApi( &BurstParams );
#endif /* cOCT6100_REMOVE_USER_FUNCTION_CHECK */

#define mOCT6100_ASSIGN_USER_READ_WRITE_OBJ( f_pApiInst, Params )


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		mOCT6100_RETRIEVE_NLP_CONF_DWORD

Description:    This function is used by the API to store on a per channel basis
				the various confguration DWORD from the device. The API performs 
				less read to the chip that way since it is always in synch 
				with the chip.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------

IN	f_pApiInst				Pointer to API instance. This memory is used to keep
							the present state of the chip and all its resources.
IN	f_pChanEntry			Pointer to an API channel structure..
IN	f_ulAddress				Address that needs to be modified..
IN	f_pulConfigDword		Pointer to the content stored in the API located at the
							desired address.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
#define mOCT6100_RETRIEVE_NLP_CONF_DWORD( f_pApiInst, f_pChanEntry, f_ulAddress, f_pulConfigDword, f_ulResult )	\
{																												\
	UINT32	_ulFirstEmptyIndex = 0xFFFFFFFF;																	\
	UINT32	_i;																									\
																												\
	f_ulResult = cOCT6100_ERR_FATAL_8E;																			\
	(*f_pulConfigDword) = cOCT6100_INVALID_VALUE;																\
																												\
	/* Search for the Dword.*/																					\
	for ( _i = 0; _i < cOCT6100_MAX_NLP_CONF_DWORD; _i++ )														\
	{																											\
		if ( ( _ulFirstEmptyIndex == 0xFFFFFFFF ) && ( f_pChanEntry->aulNlpConfDword[ _i ][ 0 ] == 0x0 ) )		\
			_ulFirstEmptyIndex = _i;																			\
																												\
		if ( f_pChanEntry->aulNlpConfDword[ _i ][ 0 ] == f_ulAddress )											\
		{																										\
			/* We found the matching Dword.*/																	\
			(*f_pulConfigDword) = f_pChanEntry->aulNlpConfDword[ _i ][ 1 ];										\
			f_ulResult = cOCT6100_ERR_OK;																		\
		}																										\
	}																											\
																												\
	if ( ( _i == cOCT6100_MAX_NLP_CONF_DWORD ) && ( _ulFirstEmptyIndex == 0xFFFFFFFF ) )						\
	{																											\
		/* Nothing to do here, a fatal error occured, no memory was left. */									\
	}																											\
	else																										\
	{																											\
		if ( f_ulResult != cOCT6100_ERR_OK )																	\
		{																										\
			tOCT6100_READ_PARAMS	_ReadParams;																\
			UINT16					_usReadData;																\
																												\
			/* We did not found any entry, let's create a new entry.*/											\
			f_pChanEntry->aulNlpConfDword[ _ulFirstEmptyIndex ][ 0 ] = f_ulAddress;								\
																												\
			_ReadParams.pProcessContext = f_pApiInst->pProcessContext;											\
			mOCT6100_ASSIGN_USER_READ_WRITE_OBJ( f_pApiInst, _ReadParams );										\
			_ReadParams.ulUserChipId = f_pApiInst->pSharedInfo->ChipConfig.ulUserChipId;						\
			_ReadParams.pusReadData = &_usReadData;																\
																												\
			/* Read the first 16 bits.*/																		\
			_ReadParams.ulReadAddress = f_ulAddress;															\
			mOCT6100_DRIVER_READ_API( _ReadParams, f_ulResult );												\
			if ( f_ulResult == cOCT6100_ERR_OK )																\
			{																									\
				/* Save data.*/																					\
				(*f_pulConfigDword) = _usReadData << 16;														\
																												\
				/* Read the last 16 bits .*/																	\
				_ReadParams.ulReadAddress += 2;																	\
				mOCT6100_DRIVER_READ_API( _ReadParams, f_ulResult );											\
				if ( f_ulResult == cOCT6100_ERR_OK )															\
				{																								\
					/* Save data.*/																				\
					(*f_pulConfigDword) |= _usReadData;															\
					f_ulResult = cOCT6100_ERR_OK;																\
				}																								\
			}																									\
		}																										\
	}																											\
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		mOCT6100_SAVE_NLP_CONF_DWORD

Description:    This function stores a configuration Dword within an API channel
				structure and then writes it into the chip.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------

IN	f_pApiInst				Pointer to API instance. This memory is used to keep
							the present state of the chip and all its resources.
IN	f_pChanEntry			Pointer to an API channel structure..
IN	f_ulAddress				Address that needs to be modified..
IN	f_pulConfigDword		content to be stored in the API located at the
							desired address.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
#define mOCT6100_SAVE_NLP_CONF_DWORD( f_pApiInst, f_pChanEntry, f_ulAddress, f_ulConfigDword, f_ulResult )	\
{																											\
	UINT32	_i;																								\
	UINT32	_ulLastValue = 0x0;																				\
																											\
	/* Search for the Dword.*/																				\
	for ( _i = 0; _i < cOCT6100_MAX_NLP_CONF_DWORD; _i++ )													\
	{																										\
		if ( f_pChanEntry->aulNlpConfDword[ _i ][ 0 ] == f_ulAddress )										\
		{																									\
			/* We found the matching Dword.*/																\
			_ulLastValue = f_pChanEntry->aulNlpConfDword[ _i ][ 1 ];										\
			f_pChanEntry->aulNlpConfDword[ _i ][ 1 ] = f_ulConfigDword;										\
			break;																							\
		}																									\
	}																										\
																											\
	if ( _i == cOCT6100_MAX_NLP_CONF_DWORD )																\
	{																										\
		f_ulResult = cOCT6100_ERR_FATAL_8F;																	\
	}																										\
	else																									\
	{																										\
		/* Write the config DWORD. */																		\
		tOCT6100_WRITE_PARAMS	_WriteParams;																\
																											\
		_WriteParams.pProcessContext = f_pApiInst->pProcessContext;											\
		mOCT6100_ASSIGN_USER_READ_WRITE_OBJ( f_pApiInst, _WriteParams )										\
		_WriteParams.ulUserChipId = f_pApiInst->pSharedInfo->ChipConfig.ulUserChipId;						\
																											\
			/* Check if it is worth calling the user function. */											\
		if ( ( f_ulConfigDword & 0xFFFF0000 ) != ( _ulLastValue & 0xFFFF0000 ) )							\
		{																									\
			/* Write the first 16 bits. */																	\
			_WriteParams.ulWriteAddress = f_ulAddress;														\
			_WriteParams.usWriteData = (UINT16)((f_ulConfigDword >> 16) & 0xFFFF);							\
			mOCT6100_DRIVER_WRITE_API( _WriteParams, f_ulResult );											\
		}																									\
		else																								\
		{																									\
			f_ulResult = cOCT6100_ERR_OK;																	\
		}																									\
																											\
		if ( f_ulResult == cOCT6100_ERR_OK )																\
		{																									\
			if ( ( f_ulConfigDword & 0x0000FFFF ) != ( _ulLastValue & 0x0000FFFF ) )						\
			{																								\
				/* Write the last word. */																	\
				_WriteParams.ulWriteAddress = f_ulAddress + 2;												\
				_WriteParams.usWriteData = (UINT16)(f_ulConfigDword & 0xFFFF);								\
				mOCT6100_DRIVER_WRITE_API( _WriteParams, f_ulResult );										\
			}																								\
		}																									\
	}																										\
}


#define mOCT6100_CREATE_FEATURE_MASK( f_ulFieldSize, f_ulFieldBitOffset, f_pulFieldMask )					\
{																											\
	(*f_pulFieldMask) = ( 1 << f_ulFieldSize );																\
	(*f_pulFieldMask) --;																					\
	(*f_pulFieldMask) <<= f_ulFieldBitOffset;																\
}


/*****************************  TYPES  ***************************************/


/************************** FUNCTION PROTOTYPES  *****************************/

UINT32 Oct6100ApiWaitForTime(
				IN OUT	tPOCT6100_INSTANCE_API		f_pApiInstance,
				IN		UINT32						f_aulWaitTime[ 2 ] );

UINT32 Oct6100ApiWaitForPcRegisterBit(
				IN OUT	tPOCT6100_INSTANCE_API		f_pApiInstance,
				IN		UINT32						f_ulPcRegAdd,
				IN		UINT32						f_ulPcBitNum,
				IN		UINT32						f_ulValue,
				IN		UINT32						f_ulTimeoutUs,
				OUT		PBOOL						f_pfBitEqual );

UINT32 Oct6100ApiWriteDword( 
				IN OUT	tPOCT6100_INSTANCE_API		f_pApiInstance,
				IN		UINT32						f_ulAddress,
				IN		UINT32						f_ulWriteData );

UINT32 Oct6100ApiReadDword( 
				IN OUT	tPOCT6100_INSTANCE_API		f_pApiInstance,
				IN		UINT32						f_ulAddress,
				OUT		PUINT32						f_pulReadData );

VOID Oct6100ApiCreateFeatureMask( 
				IN		UINT32						f_ulFieldSize,
				IN		UINT32						f_ulFieldBitOffset,
				OUT		PUINT32						f_pulFieldMask );

PUINT8 Oct6100ApiStrStr( 
				IN		PUINT8						f_pszSource, 
				IN		PUINT8						f_pszString, 
				IN		PUINT8						f_pszLastCharPtr );

UINT32 Oct6100ApiStrLen( 
				IN		PUINT8						f_pszString );

UINT32 Oct6100ApiAsciiToHex( 
				IN		UINT8						f_chCharacter, 
				IN		PUINT32						f_pulValue );

UINT8 Oct6100ApiHexToAscii( 
				IN		UINT32						f_ulNumber );

UINT32 Oct6100ApiRand( 
				IN		UINT32						f_ulRange );

#endif /* __OCT6100_MISCELLANEOUS_PRIV_H__ */