
//   vim:tw=110:ts=4:
#ifndef HCFDEFC_H
#define HCFDEFC_H 1

/*************************************************************************************************
*
* FILE	 : HCFDEF.H
*
* DATE   : $Date: 2004/03/18 16:36:15 $   $Revision: 1.167 $
* Original: 2004/03/18 16:36:15    Revision: 1.167      Tag: t20040318_02
* Original: 2004/02/16 10:32:07    Revision: 1.166      Tag: t20040318_01
*
* AUTHOR : Nico Valster
*
* SPECIFICATION: 025726 rev B
*
* DESC   : Definitions and Prototypes for HCF only
*
**************************************************************************************************
 *
 *
 * SOFTWARE LICENSE
 *
 * This software is provided subject to the following terms and conditions,
 * which you should read carefully before using the software.  Using this
 * software indicates your acceptance of these terms and conditions.  If you do
 * not agree with these terms and conditions, do not use the software.
 *
 * COPYRIGHT © 1994 - 1995	by AT&T.				All Rights Reserved
 * COPYRIGHT © 1996 - 2000 by Lucent Technologies.	All Rights Reserved
 * COPYRIGHT © 2001 - 2004	by Agere Systems Inc.	All Rights Reserved
 * All rights reserved.
 *
 * Redistribution and use in source or binary forms, with or without
 * modifications, are permitted provided that the following conditions are met:
 *
 * . Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following Disclaimer as comments in the code as
 *    well as in the documentation and/or other materials provided with the
 *    distribution.
 *
 * . Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following Disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * . Neither the name of Agere Systems Inc. nor the names of the contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * Disclaimer
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  ANY
 * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN
 * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 *
*************************************************************************************************/


/************************************************************************************************/
/*********************************  P R E F I X E S  ********************************************/
/************************************************************************************************/
//IFB_		Interface Block
//HCMD_		Hermes Command
//HFS_		Hermes (Transmit/Receive) Frame Structure
//HREG_		Hermes Register

/*************************************************************************************************/


/************************************************************************************************/
/********************************* GENERAL EQUATES **********************************************/
/************************************************************************************************/

#if ! defined HCF_STATIC
#define		  HCF_STATIC	static
#endif //	  HCF_STATIC

#define AUX_MAGIC_0				0xFE01
#define AUX_MAGIC_1				0xDC23
#define AUX_MAGIC_2				0xBA45
#define HCF_MAGIC				0x7D37	// "}7" Handle validation

#if (HCF_TYPE) & HCF_TYPE_HII
#define	PLUG_DATA_OFFSET        0x00000800L
#else
#define	PLUG_DATA_OFFSET        0x00390000L
#endif

#define INI_TICK_INI			0x00040000L

#define IO_IN					0		//hcfio_in_string
#define IO_OUT					1		//hcfio_out_string

//DO_ASSERT, create an artificial FALSE to force an ASSERT without the nasty compiler warning
#define DO_ASSERT				( assert_ifbp->IFB_Magic != HCF_MAGIC && assert_ifbp->IFB_Magic == HCF_MAGIC )
//;?#define DO_ASSERT				( ifbp->IFB_Magic != HCF_MAGIC && ifbp->IFB_Magic == HCF_MAGIC )
//;?ifbp is not known, hence we have to slightly redefine DO_MDDASSERT
//;?#define DO_MDDASSERT ( assert_ifb->IFB_Magic != HCF_MAGIC && assert_ifb->IFB_Magic == HCF_MAGIC )
#define DHF_FILE_NAME_OFFSET	10000		//to distinguish DHF from HCF asserts by means of line number
#define MMD_FILE_NAME_OFFSET	20000		//to distinguish MMD from HCF asserts by means of line number

// trace codes used to
// 1: profile execution times via HCF_TRACE and HCF_TRACE_VALUE
// 2: hierarchical flow information in HCF_ASSERT and hcf_debug_trigger via IFB_AssertTrace

//#define HCF_TRACE_CONNECT		useless
//#define HCF_TRACE_DISCONNECT	useless
#define HCF_TRACE_ACTION		0x0000  // 0x0001
#define HCF_TRACE_DISABLE		0x0001  // 0x0002
#define HCF_TRACE_ENABLE		0x0002  // 0x0004
#define HCF_TRACE_SPARE_2		0x0003  // 0x0008
#define HCF_TRACE_SPARE_4		0x0004  // 0x0010
#define HCF_TRACE_PUT_DATA		0x0005  // 0x0020
#define HCF_TRACE_GET_INFO		0x0006  // 0x0040
#define HCF_TRACE_PUT_INFO		0x0007  // 0x0080
#define HCF_TRACE_RCV_MSG		0x0008  // 0x0100
#define HCF_TRACE_SEND_MSG		0x0009  // 0x0200
#define HCF_TRACE_SERVICE_NIC	0x000A  // 0x0400
// #define HCF_TRACE_          	0x000B  // 0x0800
// #define HCF_TRACE_           0x000C  // 0x1000
// #define HCF_TRACE_           0x000D  // 0x2000
// #define HCF_TRACE_           0x000E  // 0x4000
// #define HCF_TRACE_           0x000F  // 0x8000
//	============================================ HCF_TRACE_... codes below 0x0010 are asserted on re-entry
#define HCF_TRACE_STRIO			0x0020
#define HCF_TRACE_ALLOC			0X0021
#define HCF_TRACE_DL			0X0023
#define HCF_TRACE_ISR_INFO		0X0024
#define HCF_TRACE_CALIBRATE		0x0026

#define HCF_TRACE_CMD_CPL 		0x0040
#define HCF_TRACE_CMD_EXE		0x0041
#define HCF_TRACE_GET_FID		0x0042
#define HCF_TRACE_GET_FRAG		0x0043
#define HCF_TRACE_INIT			0x0044
#define HCF_TRACE_PUT_FRAG		0x0045
#define HCF_TRACE_SETUP_BAP		0x0046

#define	HCF_TRACE_EXIT 			0x8000	// Keil C warns "long constant truncated to int"

//#define BAP_0					HREG_DATA_0		//Tx-related register set for WMAC buffer access
#define BAP_1					HREG_DATA_1		//non Tx-related register set for WMAC buffer access
/************************************************************************************************/
/***************************** STRUCTURES *******************************************************/
/************************************************************************************************/


//************************* Hermes Receive/Transmit Frame Structures
//HFS_STAT
//see MMD.H for HFS_STAT_ERR
#define 	HFS_STAT_MSG_TYPE	0xE000	//Hermes reported Message Type
#define 	HFS_STAT_MIC_KEY_ID	0x1800	//MIC key used (if any)
#define 	HFS_STAT_1042		0x2000	//RFC1042 Encoded
#define 	HFS_STAT_TUNNEL		0x4000	//Bridge-Tunnel Encoded
#define 	HFS_STAT_WMP_MSG	0x6000	//WaveLAN-II Management Protocol Frame
#if (HCF_TYPE) & HCF_TYPE_WPA
#define 	HFS_STAT_MIC		0x0010	//Frame contains MIC  //;? re-instate when F/W ready
#else
#define 	HFS_STAT_MIC		0x0000	//Frame contains MIC
#endif

#if HFS_TX_CNTL_MIC != HFS_STAT_MIC
Layout of Status field of RxFS and Control field of TxFS should match ****
#endif

/* Note that the HCF_.... System Constants influence the HFS_.... values used in
 * HCF_TX_CNTL_MASK and HFS_TX_CNTL_MASK below
 * see mdd.h for a table of the HFS_.... values depending on H-I/H-II and WPA yes/no
 */
// bits allowed on WCI
#define 	HCF_TX_CNTL_MASK	\
( HFS_TX_CNTL_TX_DELAY  |                    HFS_TX_CNTL_PORT | HFS_TX_CNTL_PRIO |                  \
  HFS_TX_CNTL_TX_EX | HFS_TX_CNTL_TX_OK | HFS_TX_CNTL_SPECTRALINK )
// bits allowed on NIC I/F in TxFS
#define 	HFS_TX_CNTL_MASK	\
( HFS_TX_CNTL_CKIP | HFS_TX_CNTL_MIC_KEY_ID | HFS_TX_CNTL_PORT | HFS_TX_CNTL_PRIO | HFS_TX_CNTL_MIC | \
  HFS_TX_CNTL_TX_EX | HFS_TX_CNTL_TX_OK | HFS_TX_CNTL_SPECTRALINK )

//************************* Hermes Register Offsets and Command bits
#if (HCF_TYPE) & HCF_TYPE_HII
#define HREG_IO_RANGE			0x80		//I/O Range used by Hermes-II
#else
#define HREG_IO_RANGE			0x40		//I/O Range used by Hermes_I
#endif // HCF_TYPE_HII

//************************* Command/Status
#define HREG_CMD				0x00		//
#define 	HCMD_CMD_CODE			0x3F
#define HREG_PARAM_0			0x02		//
#define HREG_PARAM_1			0x04		//
#define HREG_PARAM_2			0x06		//
#define HREG_STAT				0x08		//
#define 	HREG_STAT_CMD_CODE		0x003F	//
#define		HREG_STAT_DIAG_ERR		0x0100
#define		HREG_STAT_INQUIRE_ERR	0x0500
#define 	HREG_STAT_CMD_RESULT	0x7F00	//
#define HREG_RESP_0				0x0A		//
#define HREG_RESP_1				0x0C		//
#define HREG_RESP_2				0x0E		//


//************************* FID Management
#define HREG_INFO_FID			0x10		//
#define HREG_RX_FID				0x20		//
#define HREG_ALLOC_FID  		0x22		//
#define HREG_TX_COMPL_FID  		0x24		//


//************************* BAP
//20031030 HWi Inserted this again because the dongle code uses this (GPIF.C)
#define HREG_SELECT_0			0x18		//
#define HREG_OFFSET_0			0x1C		//
#define HREG_DATA_0				0x36		//

//#define 	HREG_OFFSET_BUSY		0x8000	// use HCMD_BUSY
#define 	HREG_OFFSET_ERR			0x4000	//
//rsrvd #define 	HREG_OFFSET_DATA_OFFSET	0x0FFF	//

#define HREG_SELECT_1			0x1A		//
#define HREG_OFFSET_1			0x1E		//
#define HREG_DATA_1				0x38		//


//************************* Event
#define HREG_EV_STAT			0x30		//
#define HREG_INT_EN				0x32		//
#define HREG_EV_ACK				0x34		//


//************************* Host Software
#define HREG_SW_0				0x28		//
#define HREG_SW_1				0x2A		//
#define HREG_SW_2				0x2C		//
//rsrvd #define HREG_SW_3		0x2E		//
//************************* Control and Auxiliary Port

#define HREG_IO					0x12
#define		HREG_IO_SRESET			0x0001
#define		HREG_IO_WAKEUP_ASYNC	0x0002
#define HREG_CNTL				0x14		//
#define		HREG_CNTL_WAKEUP_SYNC	0x0001
#define		HREG_CNTL_AUX_ENA_STAT	0xC000
#define		HREG_CNTL_AUX_DIS_STAT	0x0000
#define		HREG_CNTL_AUX_ENA_CNTL	0x8000
#define		HREG_CNTL_AUX_DIS_CNTL	0x4000
#define		HREG_CNTL_AUX_DSD		0x2000
#define		HREG_CNTL_AUX_ENA		(HREG_CNTL_AUX_ENA_CNTL | HREG_CNTL_AUX_DIS_CNTL )
#define HREG_SPARE				0x16		//
#define HREG_AUX_PAGE			0x3A		//
#define HREG_AUX_OFFSET			0x3C		//
#define HREG_AUX_DATA			0x3E		//


/************************************************************************************************/
/***************************** END OF STRUCTURES ***********************************************/
/************************************************************************************************/


/************************************************************************************************/
/**********************************  EQUATES  ***************************************************/
/************************************************************************************************/


// SNAP header for E-II Encapsulation

// Hermes Command Codes and Qualifier bits
#define 	HCMD_BUSY			0x8000	// Busy bit, applicable for all commands
#define HCMD_INI				0x0000	//
#define 	HCMD_INI_0x0100		0x0100	//
#define HCMD_ENABLE				0x0001	//
#define HCMD_DISABLE			0x0002	//
#define HCMD_DIAG				0x0003	//
#define HCMD_EXECUTE			0x0004	//
#define HCMD_SLEEP				0x0006	//
#define HCMD_ALLOC				0x000A	//
#define HCMD_TX					0x000B	//
#define 	HCMD_RECL			0x0100	// Reclaim bit, applicable for Tx and Inquire
#if ( (HCF_TYPE) & ( HCF_TYPE_HII | HCF_TYPE_WPA ) ) == HCF_TYPE_WPA
/* apparently we can not get this right so the decision is to leave it alone
 * #define 	HCMD_DCP			0x0200	// DataCorruptionPattern bit
 */
#define 	HCMD_DCP			0x0000	// No DataCorruptionPattern for H_I although it is needed
#else
#define 	HCMD_DCP			0x0000	// No DataCorruptionPattern for H_II
#endif // HCF_TYPE
#define HCMD_NOTIFY				0x0010	//
#define HCMD_INQUIRE			0x0011	//
//#define 	HCMD_RECL			0x0100	// Reclaim bit, applicable for Tx and Inquire
#define HCMD_ACCESS				0x0021	//
#define 	HCMD_ACCESS_WRITE		0x0100	//
#define HCMD_PROGRAM			0x0022	//
#define 	HCMD_PROGRAM_DISABLE				0x0000	//
#define 	HCMD_PROGRAM_ENABLE_VOLATILE	 	0x0100	//
#define 	HCMD_PROGRAM_ENABLE_NON_VOLATILE	0x0200	//
#define 	HCMD_PROGRAM_NON_VOLATILE			0x0300	//
#define HCMD_READ_MIF			0x0030
#define HCMD_WRITE_MIF			0x0031
#define HCMD_THESEUS			0x0038


//Configuration Management
//

#if (HCF_TYPE) & HCF_TYPE_HII
#define CFG_DRV_ACT_RANGES_PRI_3_BOTTOM	1	// Default Bottom Compatibility for Primary Firmware - driver I/F
#define CFG_DRV_ACT_RANGES_PRI_3_TOP	1	// Default Top    Compatibility for Primary Firmware - driver I/F
#else
#define CFG_DRV_ACT_RANGES_PRI_1_BOTTOM	1	// Default Bottom Compatibility for Primary Firmware - driver I/F
#define CFG_DRV_ACT_RANGES_PRI_1_TOP	2	// Default Top    Compatibility for Primary Firmware - driver I/F
										   	// Hermes needs 2 as top, if top == 1, Shark only

#define CFG_DRV_ACT_RANGES_PRI_2_BOTTOM	1	// Default Bottom Compatibility for Primary Firmware - driver I/F
#define CFG_DRV_ACT_RANGES_PRI_2_TOP	1	// Default Top    Compatibility for Primary Firmware - driver I/F
#endif // HCF_TYPE_HII

#if (HCF_TYPE) & HCF_TYPE_HII
#define CFG_DRV_ACT_RANGES_HSI_4_BOTTOM	1	// Default Bottom Compatibility for H/W - driver I/F
#define CFG_DRV_ACT_RANGES_HSI_4_TOP	1	// Default Top    Compatibility for H/W - driver I/F

#define CFG_DRV_ACT_RANGES_HSI_5_BOTTOM	1	// Default Bottom Compatibility for H/W - driver I/F
#define CFG_DRV_ACT_RANGES_HSI_5_TOP	1	// Default Top    Compatibility for H/W - driver I/F
#else
#define CFG_DRV_ACT_RANGES_HSI_0_BOTTOM	1	// Default Bottom Compatibility for H/W - driver I/F
#define CFG_DRV_ACT_RANGES_HSI_0_TOP	1	// Default Top    Compatibility for H/W - driver I/F

#define CFG_DRV_ACT_RANGES_HSI_1_BOTTOM	1	// Default Bottom Compatibility for H/W - driver I/F
#define CFG_DRV_ACT_RANGES_HSI_1_TOP	2	// Default Top    Compatibility for H/W - driver I/F

#define CFG_DRV_ACT_RANGES_HSI_2_BOTTOM	1	// Default Bottom Compatibility for H/W - driver I/F
#define CFG_DRV_ACT_RANGES_HSI_2_TOP	1	// Default Top    Compatibility for H/W - driver I/F

#define CFG_DRV_ACT_RANGES_HSI_3_BOTTOM	1	// Default Bottom Compatibility for H/W - driver I/F
#define CFG_DRV_ACT_RANGES_HSI_3_TOP	1	// Default Top    Compatibility for H/W - driver I/F
#endif // HCF_TYPE_HII

#if (HCF_TYPE) & HCF_TYPE_HII
#define CFG_DRV_ACT_RANGES_APF_2_BOTTOM	2	// Default Bottom Compatibility for AP Firmware - driver I/F
#define CFG_DRV_ACT_RANGES_APF_2_TOP    2	// Default Top    Compatibility for AP Firmware - driver I/F

#define CFG_DRV_ACT_RANGES_APF_3_BOTTOM	1	// Default Bottom Compatibility for AP Firmware - driver I/F
#define CFG_DRV_ACT_RANGES_APF_3_TOP    1	// Default Top    Compatibility for AP Firmware - driver I/F

#define CFG_DRV_ACT_RANGES_APF_4_BOTTOM	1	// Default Bottom Compatibility for AP Firmware - driver I/F
#define CFG_DRV_ACT_RANGES_APF_4_TOP    1	// Default Top    Compatibility for AP Firmware - driver I/F
#else
#if (HCF_TYPE) & HCF_TYPE_WPA
#define CFG_DRV_ACT_RANGES_APF_1_BOTTOM	16	// Default Bottom Compatibility for AP Firmware - driver I/F
#define CFG_DRV_ACT_RANGES_APF_1_TOP    16	// Default Top    Compatibility for AP Firmware - driver I/F
#else
#define CFG_DRV_ACT_RANGES_APF_1_BOTTOM	1	// Default Bottom Compatibility for AP Firmware - driver I/F
#define CFG_DRV_ACT_RANGES_APF_1_TOP    1	// Default Top    Compatibility for AP Firmware - driver I/F
#endif // HCF_TYPE_WPA
#endif // HCF_TYPE_HII

#if (HCF_TYPE) & HCF_TYPE_HII
#define CFG_DRV_ACT_RANGES_STA_2_BOTTOM	1	// Default Bottom Compatibility for Station Firmware - driver I/F
#define CFG_DRV_ACT_RANGES_STA_2_TOP    2	// Default Top    Compatibility for Station Firmware - driver I/F

#define CFG_DRV_ACT_RANGES_STA_3_BOTTOM	1	// Default Bottom Compatibility for Station Firmware - driver I/F
#define CFG_DRV_ACT_RANGES_STA_3_TOP    1	// Default Top    Compatibility for Station Firmware - driver I/F

#define CFG_DRV_ACT_RANGES_STA_4_BOTTOM	1	// Default Bottom Compatibility for Station Firmware - driver I/F
#define CFG_DRV_ACT_RANGES_STA_4_TOP    1	// Default Top    Compatibility for Station Firmware - driver I/F
#else
#if (HCF_TYPE) & HCF_TYPE_WPA
#define CFG_DRV_ACT_RANGES_STA_1_BOTTOM	16	// Default Bottom Compatibility for Station Firmware - driver I/F
#define CFG_DRV_ACT_RANGES_STA_1_TOP    16	// Default Top    Compatibility for Station Firmware - driver I/F
#else
#define CFG_DRV_ACT_RANGES_STA_1_BOTTOM	 6	// Default Bottom Compatibility for Station Firmware - driver I/F
#define CFG_DRV_ACT_RANGES_STA_1_TOP    15	// Default Top    Compatibility for Station Firmware - driver I/F
#endif // HCF_TYPE_WPA
#endif // HCF_TYPE_HII

#if !((HCF_TYPE) & HCF_TYPE_HII)
#define CFG_DRV_ACT_RANGES_UBI_1_BOTTOM	1	// Default Bottom Compatibility for USB Converter board - driver I/F
#define CFG_DRV_ACT_RANGES_UBI_1_TOP	1	// Default Top    Compatibility for USB Converter board - driver I/F

											// variant 2
#define CFG_DRV_ACT_RANGES_UBI_2_BOTTOM	1	// Default Bottom Compatibility for USB Converter board - driver I/F
#define CFG_DRV_ACT_RANGES_UBI_2_TOP	1	// Default Top    Compatibility for USB Converter board - driver I/F

#define CFG_DRV_ACT_RANGES_UDI_1_BOTTOM	1	// Default Bottom Compatibility for USB Bootloader  - driver I/F
#define CFG_DRV_ACT_RANGES_UDI_1_TOP	1	// Default Top    Compatibility for USB Bootloader  - driver I/F
#endif // HCF_TYPE_HII

//---------------------------------------------------------------------------------------------------------------------
#ifdef HCF_CFG_PRI_1_TOP									// Top Compatibility for Primary Firmware - driver I/F
#if HCF_CFG_PRI_1_TOP == 0  || \
	CFG_DRV_ACT_RANGES_PRI_1_BOTTOM <= HCF_CFG_PRI_1_TOP && HCF_CFG_PRI_1_TOP <= CFG_DRV_ACT_RANGES_PRI_1_TOP
#undef CFG_DRV_ACT_RANGES_PRI_1_TOP
#define CFG_DRV_ACT_RANGES_PRI_1_TOP	HCF_CFG_PRI_1_TOP
#else
error;
#endif
#endif // HCF_CFG_PRI_1_TOP

#ifdef HCF_CFG_PRI_1_BOTTOM                       			// Bottom Compatibility for Primary Firmware - driver I/F
#if CFG_DRV_ACT_RANGES_PRI_1_BOTTOM <= HCF_CFG_PRI_1_BOTTOM && HCF_CFG_PRI_1_BOTTOM <= CFG_DRV_ACT_RANGES_PRI_1_TOP
#undef CFG_DRV_ACT_RANGES_PRI_1_BOTTOM
#define CFG_DRV_ACT_RANGES_PRI_1_BOTTOM	HCF_CFG_PRI_1_BOTTOM
#else
error;
#endif
#endif // HCF_CFG_PRI_1_BOTTOM


#ifdef HCF_CFG_PRI_2_TOP									// Top Compatibility for Primary Firmware - driver I/F
#if HCF_CFG_PRI_2_TOP == 0 || \
	CFG_DRV_ACT_RANGES_PRI_2_BOTTOM <= HCF_CFG_PRI_2_TOP && HCF_CFG_PRI_2_TOP <= CFG_DRV_ACT_RANGES_PRI_2_TOP
#undef CFG_DRV_ACT_RANGES_PRI_2_TOP
#define CFG_DRV_ACT_RANGES_PRI_2_TOP	HCF_CFG_PRI_2_TOP
#else
error;
#endif
#endif // HCF_CFG_PRI_2_TOP

#ifdef HCF_CFG_PRI_2_BOTTOM                       			// Bottom Compatibility for Primary Firmware - driver I/F
#if CFG_DRV_ACT_RANGES_PRI_2_BOTTOM <= HCF_CFG_PRI_2_BOTTOM && HCF_CFG_PRI_2_BOTTOM <= CFG_DRV_ACT_RANGES_PRI_2_TOP
#undef CFG_DRV_ACT_RANGES_PRI_2_BOTTOM
#define CFG_DRV_ACT_RANGES_PRI_2_BOTTOM	HCF_CFG_PRI_2_BOTTOM
#else
error;
#endif
#endif // HCF_CFG_PRI_2_BOTTOM


#ifdef HCF_CFG_PRI_3_TOP									// Top Compatibility for Primary Firmware - driver I/F
#if HCF_CFG_PRI_3_TOP == 0 || \
	CFG_DRV_ACT_RANGES_PRI_3_BOTTOM <= HCF_CFG_PRI_3_TOP && HCF_CFG_PRI_3_TOP <= CFG_DRV_ACT_RANGES_PRI_3_TOP
#undef CFG_DRV_ACT_RANGES_PRI_3_TOP
#define CFG_DRV_ACT_RANGES_PRI_3_TOP	HCF_CFG_PRI_3_TOP
#else
error;
#endif
#endif // HCF_CFG_PRI_3_TOP

#ifdef HCF_CFG_PRI_3_BOTTOM                       			// Bottom Compatibility for Primary Firmware - driver I/F
#if CFG_DRV_ACT_RANGES_PRI_3_BOTTOM <= HCF_CFG_PRI_3_BOTTOM && HCF_CFG_PRI_3_BOTTOM <= CFG_DRV_ACT_RANGES_PRI_3_TOP
#undef CFG_DRV_ACT_RANGES_PRI_3_BOTTOM
#define CFG_DRV_ACT_RANGES_PRI_3_BOTTOM	HCF_CFG_PRI_3_BOTTOM
#else
error;
#endif
#endif // HCF_CFG_PRI_3_BOTTOM


//---------------------------------------------------------------------------------------------------------------------
#ifdef HCF_CFG_HSI_0_TOP 									// Top Compatibility for HSI I/F
#if HCF_CFG_HSI_0_TOP == 0 || \
	CFG_DRV_ACT_RANGES_HSI_0_BOTTOM <= CF_CFG_HSI_0_TOP && HCF_CFG_HSI_0_TOP <= CFG_DRV_ACT_RANGES_HSI_0_TOP
#undef CFG_DRV_ACT_RANGES_HSI_0_TOP
#define CFG_DRV_ACT_RANGES_HSI_0_TOP	HCF_CFG_HSI_0_TOP
#else
error;
#endif
#endif // HCF_CFG_HSI_0_TOP

#ifdef HCF_CFG_HSI_0_BOTTOM								// Bottom Compatibility for HSI I/F
#if CFG_DRV_ACT_RANGES_HSI_0_BOTTOM <= HCF_CFG_HSI_0_BOTTOM && HCF_CFG_HSI_0_BOTTOM <= CFG_DRV_ACT_RANGES_HSI_0_TOP
#undef CFG_DRV_ACT_RANGES_HSI_0_BOTTOM
#define CFG_DRV_ACT_RANGES_HSI_0_BOTTOM	HCF_CFG_HSI_0_BOTTOM
#else
error;
#endif
#endif // HCF_CFG_HSI_0_BOTTOM


#ifdef HCF_CFG_HSI_1_TOP 									// Top Compatibility for HSI I/F
#if HCF_CFG_HSI_1_TOP == 0 || \
	CFG_DRV_ACT_RANGES_HSI_1_BOTTOM <= CF_CFG_HSI_1_TOP && HCF_CFG_HSI_1_TOP <= CFG_DRV_ACT_RANGES_HSI_1_TOP
#undef CFG_DRV_ACT_RANGES_HSI_1_TOP
#define CFG_DRV_ACT_RANGES_HSI_1_TOP	HCF_CFG_HSI_1_TOP
#else
error;
#endif
#endif // HCF_CFG_HSI_1_TOP

#ifdef HCF_CFG_HSI_1_BOTTOM								// Bottom Compatibility for HSI I/F
#if CFG_DRV_ACT_RANGES_HSI_1_BOTTOM <= HCF_CFG_HSI_1_BOTTOM && HCF_CFG_HSI_1_BOTTOM <= CFG_DRV_ACT_RANGES_HSI_1_TOP
#undef CFG_DRV_ACT_RANGES_HSI_1_BOTTOM
#define CFG_DRV_ACT_RANGES_HSI_1_BOTTOM	HCF_CFG_HSI_1_BOTTOM
#else
error;
#endif
#endif // HCF_CFG_HSI_1_BOTTOM


#ifdef HCF_CFG_HSI_2_TOP 									// Top Compatibility for HSI I/F
#if HCF_CFG_HSI_2_TOP == 0 || \
	CFG_DRV_ACT_RANGES_HSI_2_BOTTOM <= CF_CFG_HSI_2_TOP && HCF_CFG_HSI_2_TOP <= CFG_DRV_ACT_RANGES_HSI_2_TOP
#undef CFG_DRV_ACT_RANGES_HSI_2_TOP
#define CFG_DRV_ACT_RANGES_HSI_2_TOP	HCF_CFG_HSI_2_TOP
#else
error;
#endif
#endif // HCF_CFG_HSI_2_TOP

#ifdef HCF_CFG_HSI_2_BOTTOM								// Bottom Compatibility for HSI I/F
#if CFG_DRV_ACT_RANGES_HSI_2_BOTTOM <= HCF_CFG_HSI_2_BOTTOM && HCF_CFG_HSI_2_BOTTOM <= CFG_DRV_ACT_RANGES_HSI_2_TOP
#undef CFG_DRV_ACT_RANGES_HSI_2_BOTTOM
#define CFG_DRV_ACT_RANGES_HSI_2_BOTTOM	HCF_CFG_HSI_2_BOTTOM
#else
error;
#endif
#endif // HCF_CFG_HSI_2_BOTTOM


#ifdef HCF_CFG_HSI_3_TOP 									// Top Compatibility for HSI I/F
#if HCF_CFG_HSI_3_TOP == 0 || \
	CFG_DRV_ACT_RANGES_HSI_3_BOTTOM <= CF_CFG_HSI_3_TOP && HCF_CFG_HSI_3_TOP <= CFG_DRV_ACT_RANGES_HSI_3_TOP
#undef CFG_DRV_ACT_RANGES_HSI_3_TOP
#define CFG_DRV_ACT_RANGES_HSI_3_TOP	HCF_CFG_HSI_3_TOP
#else
error;
#endif
#endif // HCF_CFG_HSI_3_TOP

#ifdef HCF_CFG_HSI_3_BOTTOM								// Bottom Compatibility for HSI I/F
#if CFG_DRV_ACT_RANGES_HSI_3_BOTTOM <= HCF_CFG_HSI_3_BOTTOM && HCF_CFG_HSI_3_BOTTOM <= CFG_DRV_ACT_RANGES_HSI_3_TOP
#undef CFG_DRV_ACT_RANGES_HSI_3_BOTTOM
#define CFG_DRV_ACT_RANGES_HSI_3_BOTTOM	HCF_CFG_HSI_3_BOTTOM
#else
error;
#endif
#endif // HCF_CFG_HSI_3_BOTTOM

#ifdef HCF_CFG_HSI_4_TOP 									// Top Compatibility for HSI I/F
#if HCF_CFG_HSI_4_TOP == 0 || \
	CFG_DRV_ACT_RANGES_HSI_4_BOTTOM <= CF_CFG_HSI_4_TOP && HCF_CFG_HSI_4_TOP <= CFG_DRV_ACT_RANGES_HSI_4_TOP
#undef CFG_DRV_ACT_RANGES_HSI_4_TOP
#define CFG_DRV_ACT_RANGES_HSI_4_TOP	HCF_CFG_HSI_4_TOP
#else
error;
#endif
#endif // HCF_CFG_HSI_4_TOP

#ifdef HCF_CFG_HSI_4_BOTTOM								// Bottom Compatibility for HSI I/F
#if CFG_DRV_ACT_RANGES_HSI_4_BOTTOM <= HCF_CFG_HSI_4_BOTTOM && HCF_CFG_HSI_4_BOTTOM <= CFG_DRV_ACT_RANGES_HSI_4_TOP
#undef CFG_DRV_ACT_RANGES_HSI_4_BOTTOM
#define CFG_DRV_ACT_RANGES_HSI_4_BOTTOM	HCF_CFG_HSI_4_BOTTOM
#else
error;
#endif
#endif // HCF_CFG_HSI_4_BOTTOM

#ifdef HCF_CFG_HSI_5_TOP 									// Top Compatibility for HSI I/F
#if HCF_CFG_HSI_5_TOP == 0 || \
	CFG_DRV_ACT_RANGES_HSI_5_BOTTOM <= CF_CFG_HSI_5_TOP && HCF_CFG_HSI_5_TOP <= CFG_DRV_ACT_RANGES_HSI_5_TOP
#undef CFG_DRV_ACT_RANGES_HSI_5_TOP
#define CFG_DRV_ACT_RANGES_HSI_5_TOP	HCF_CFG_HSI_5_TOP
#else
error;
#endif
#endif // HCF_CFG_HSI_5_TOP

#ifdef HCF_CFG_HSI_5_BOTTOM								// Bottom Compatibility for HSI I/F
#if CFG_DRV_ACT_RANGES_HSI_5_BOTTOM <= HCF_CFG_HSI_5_BOTTOM && HCF_CFG_HSI_5_BOTTOM <= CFG_DRV_ACT_RANGES_HSI_5_TOP
#undef CFG_DRV_ACT_RANGES_HSI_5_BOTTOM
#define CFG_DRV_ACT_RANGES_HSI_5_BOTTOM	HCF_CFG_HSI_5_BOTTOM
#else
error;
#endif
#endif // HCF_CFG_HSI_5_BOTTOM
//---------------------------------------------------------------------------------------------------------------------


#ifdef HCF_CFG_UBI_1_TOP									// Top Compatibility for USB Converter board - driver I/F
#if HCF_CFG_UBI_1_TOP == 0 || \
	CFG_DRV_ACT_RANGES_UBI_1_BOTTOM <= HCF_CFG_UBI_1_TOP && HCF_CFG_UBI_1_TOP <= CFG_DRV_ACT_RANGES_UBI_1_TOP
#undef CFG_DRV_ACT_RANGES_UBI_1_TOP
#define CFG_DRV_ACT_RANGES_UBI_1_TOP	HCF_CFG_UBI_1_TOP
#else
error;
#endif
#endif // HCF_CFG_UBI_1_TOP

#ifdef HCF_CFG_UBI_1_BOTTOM                       			// Bottom Compatibility for USB Converter board - driver I/F
#if CFG_DRV_ACT_RANGES_UBI_1_BOTTOM <= HCF_CFG_UBI_1_BOTTOM && HCF_CFG_UBI_1_BOTTOM <= CFG_DRV_ACT_RANGES_UBI_1_TOP
#undef CFG_DRV_ACT_RANGES_UBI_1_BOTTOM
#define CFG_DRV_ACT_RANGES_UBI_1_BOTTOM	HCF_CFG_UBI_1_BOTTOM
#else
error;
#endif
#endif // HCF_CFG_UBI_1_BOTTOM


#ifdef HCF_CFG_UDI_1_TOP									// Top Compatibility for USB Bootloader  - driver I/F
#if HCF_CFG_UDI_1_TOP == 0 || \
	CFG_DRV_ACT_RANGES_UDI_1_BOTTOM <= HCF_CFG_UDI_1_TOP && HCF_CFG_UDI_1_TOP <= CFG_DRV_ACT_RANGES_UDI_1_TOP
#undef CFG_DRV_ACT_RANGES_UDI_1_TOP
#define CFG_DRV_ACT_RANGES_UDI_1_TOP	HCF_CFG_UDI_1_TOP
#else
error;
#endif
#endif // HCF_CFG_UDI_1_TOP

#ifdef HCF_CFG_UDI_1_BOTTOM                       			// Bottom Compatibility for USB Bootloader  - driver I/F
#if CFG_DRV_ACT_RANGES_UDI_1_BOTTOM <= HCF_CFG_UDI_1_BOTTOM && HCF_CFG_UDI_1_BOTTOM <= CFG_DRV_ACT_RANGES_UDI_1_TOP
#undef CFG_DRV_ACT_RANGES_UDI_1_BOTTOM
#define CFG_DRV_ACT_RANGES_UDI_1_BOTTOM	HCF_CFG_UDI_1_BOTTOM
#else
error;
#endif
#endif // HCF_CFG_UDI_1_BOTTOM

//---------------------------------------------------------------------------------------------------------------------
#ifdef HCF_CFG_APF_1_TOP                  					// Top Compatibility for AP Firmware - driver I/F
#if HCF_CFG_APF_1_TOP == 0 || \
	CFG_DRV_ACT_RANGES_APF_1_BOTTOM <= HCF_CFG_APF_1_TOP && HCF_CFG_APF_1_TOP <= CFG_DRV_ACT_RANGES_APF_1_TOP
#undef CFG_DRV_ACT_RANGES_APF_1_TOP
#define CFG_DRV_ACT_RANGES_APF_1_TOP	HCF_CFG_APF_1_TOP
#else
error;
#endif
#endif // HCF_CFG_APF_TOP

#ifdef HCF_CFG_APF_1_BOTTOM                       			// Bottom Compatibility for AP Firmware - driver I/F
#if CFG_DRV_ACT_RANGES_APF_1_BOTTOM <= HCF_CFG_APF_1_BOTTOM && HCF_CFG_APF_1_BOTTOM <= CFG_DRV_ACT_RANGES_APF_1_TOP
#undef CFG_DRV_ACT_RANGES_APF_1_BOTTOM
#define CFG_DRV_ACT_RANGES_APF_1_BOTTOM	HCF_CFG_APF_1_BOTTOM
#else
error;
#endif
#endif // HCF_CFG_APF_BOTTOM

#ifdef HCF_CFG_APF_2_TOP                  					// Top Compatibility for AP Firmware - driver I/F
#if HCF_CFG_APF_2_TOP == 0 || \
	CFG_DRV_ACT_RANGES_APF_2_BOTTOM <= HCF_CFG_APF_2_TOP && HCF_CFG_APF_2_TOP <= CFG_DRV_ACT_RANGES_APF_2_TOP
#undef CFG_DRV_ACT_RANGES_APF_2_TOP
#define CFG_DRV_ACT_RANGES_APF_2_TOP	HCF_CFG_APF_2_TOP
#else
error;
#endif
#endif // HCF_CFG_APF_TOP

#ifdef HCF_CFG_APF_2_BOTTOM                       			// Bottom Compatibility for AP Firmware - driver I/F
#if CFG_DRV_ACT_RANGES_APF_2_BOTTOM <= HCF_CFG_APF_2_BOTTOM && HCF_CFG_APF_2_BOTTOM <= CFG_DRV_ACT_RANGES_APF_2_TOP
#undef CFG_DRV_ACT_RANGES_APF_2_BOTTOM
#define CFG_DRV_ACT_RANGES_APF_2_BOTTOM	HCF_CFG_APF_2_BOTTOM
#else
error;
#endif
#endif // HCF_CFG_APF_BOTTOM

#ifdef HCF_CFG_STA_1_TOP                  					// Top Compatibility for Station Firmware - driver I/F
#if HCF_CFG_STA_1_TOP == 0 || \
	CFG_DRV_ACT_RANGES_STA_1_BOTTOM <= HCF_CFG_STA_1_TOP && HCF_CFG_STA_1_TOP <= CFG_DRV_ACT_RANGES_STA_1_TOP
#undef CFG_DRV_ACT_RANGES_STA_1_TOP
#define CFG_DRV_ACT_RANGES_STA_1_TOP	HCF_CFG_STA_1_TOP
#else
error;
#endif
#endif // HCF_CFG_STA_TOP

#ifdef HCF_CFG_STA_1_BOTTOM                       			// Bottom Compatibility for Station Firmware - driver I/F
#if CFG_DRV_ACT_RANGES_STA_1_BOTTOM <= HCF_CFG_STA_1_BOTTOM && HCF_CFG_STA_1_BOTTOM <= CFG_DRV_ACT_RANGES_STA_1_TOP
#undef CFG_DRV_ACT_RANGES_STA_1_BOTTOM
#define CFG_DRV_ACT_RANGES_STA_1_BOTTOM	HCF_CFG_STA_1_BOTTOM
#else
error;
#endif
#endif // HCF_CFG_STA_BOTTOM


#ifdef HCF_CFG_STA_2_TOP                  					// Top Compatibility for Station Firmware - driver I/F
#if HCF_CFG_STA_2_TOP == 0 || \
	CFG_DRV_ACT_RANGES_STA_2_BOTTOM <= HCF_CFG_STA_2_TOP && HCF_CFG_STA_2_TOP <= CFG_DRV_ACT_RANGES_STA_2_TOP
#undef CFG_DRV_ACT_RANGES_STA_2_TOP
#define CFG_DRV_ACT_RANGES_STA_2_TOP	HCF_CFG_STA_2_TOP
#else
error;
#endif
#endif // HCF_CFG_STA_TOP

#ifdef HCF_CFG_STA_2_BOTTOM                       			// Bottom Compatibility for Station Firmware - driver I/F
#if CFG_DRV_ACT_RANGES_STA_2_BOTTOM <= HCF_CFG_STA_2_BOTTOM && HCF_CFG_STA_2_BOTTOM <= CFG_DRV_ACT_RANGES_STA_2_TOP
#undef CFG_DRV_ACT_RANGES_STA_2_BOTTOM
#define CFG_DRV_ACT_RANGES_STA_2_BOTTOM	HCF_CFG_STA_2_BOTTOM
#else
error;
#endif
#endif // HCF_CFG_STA_BOTTOM


/************************************************************************************************/
/**********************************  END OF EQUATES  ********************************************/
/************************************************************************************************/


/************************************************************************************************/
/**************************************  MACROS  ************************************************/
/************************************************************************************************/

/* min and max macros */
#if !defined(max)
#define max(a,b)  		(((a) > (b)) ? (a) : (b))
#endif
#if !defined(min)
#define min(a,b)  		(((a) < (b)) ? (a) : (b))
#endif

#define LOF(x) 			(sizeof(x)/sizeof(hcf_16)-1)

#define MUL_BY_2( x )	( (x) << 1 )						//used to multiply by 2
#define DIV_BY_2( x )	( (x) >> 1 )						//used to divide by 2

#if ((HCF_TYPE) & ( HCF_TYPE_HII | HCF_TYPE_HII5 ) ) == HCF_TYPE_HII
#define DAWA_ACK( mask) {													\
	OPW( HREG_EV_ACK, mask | HREG_EV_ACK_REG_READY );						\
	OPW( HREG_EV_ACK, (mask & ~HREG_EV_ALLOC) | HREG_EV_ACK_REG_READY ); 	}
#define DAWA_ZERO_FID(reg) OPW( reg, 0 );
#else
#define DAWA_ACK( mask)   OPW( HREG_EV_ACK, mask );
#define DAWA_ZERO_FID(reg)
#endif // HCF_TYPE_HII / HCF_TYPE_HII5

#if (HCF_TYPE) & HCF_TYPE_HII
#define HI_AUX_CNTL(ifbp, cmd)
#else
#define HI_AUX_CNTL(ifbp, cmd) aux_cntl( ifbp, cmd );
#endif // HCF_TYPE_HII

#if (HCF_TYPE) & HCF_TYPE_WPA
//after testing to prove its correctness: #define MIC_RX_RTN( mic, dw ) update_mic( mic, dw )
#define MIC_RX_RTN( mic, dw ) ifbp->IFB_MICRxRtn( mic, dw );
#define MIC_TX_RTN( mic, dw ) ifbp->IFB_MICTxRtn( mic, dw );
#define IF_SSN(x)  x
#define IF_NOT_SSN(x)
#else
#define MIC_RX_RTN( mic, dw )
#define MIC_TX_RTN( mic, dw )
#define IF_SSN(x)
#define IF_NOT_SSN(x) x
#endif // HCF_TYPE_WPA

#if HCF_TALLIES & 0x0002		//HCF tally support
#define IF_TALLY(x)  x
#else
#define IF_TALLY(x)
#endif //HCF_TALLIES

//!-
#if (HCF_TYPE) & HCF_TYPE_USB	// ********************** USB  **********************
#define IF_USB(x)  x
#define IF_NOT_USB(x)
#define HCF_WAIT_WHILE( x )
#define IPW(x) *usb_simp++
#define OPW(x, y) { \
	hcf_16 z = y; \
/*;? this is needed when "simulating" USB as a test with the DOS ODI	OUT_PORT_WORD( ifbp->IFB_IOBase + (x), z );*/\
	HCFASSERT( x == HREG_DATA_1, x )\
	if ( x == HREG_DATA_1 ) *usb_simp++ = z;\
/*	usb_tx_len += 2; ;?not very runtime efficient*/ \
}
#else 						 	// ******************** No USB  ********************
#define IF_USB(x)
#define IF_NOT_USB(x) x
#define IPW(x) ((hcf_16)IN_PORT_WORD( ifbp->IFB_IOBase + (x) ) )
#define OPW(x, y) OUT_PORT_WORD( ifbp->IFB_IOBase + (x), y )
	/* make sure the implementation of HCF_WAIT_WHILE is such that there may be multiple HCF_WAIT_WHILE calls
	 * in a row and that when one fails all subsequent fail immediately without reinitialization of prot_cnt
	 */
#if HCF_PROT_TIME == 0
#define PROT_CNT_INI
#define IF_PROT_TIME(x)
#if defined HCF_YIELD
#define HCF_WAIT_WHILE( x ) while ( (x) && (HCF_YIELD) ) /*NOP*/;
#else
#define HCF_WAIT_WHILE( x ) while ( x ) /*NOP*/;
#endif // HCF_YIELD
#else
#define PROT_CNT_INI 	hcf_32 prot_cnt = ifbp->IFB_TickIni;
#define IF_PROT_TIME(x)	x
#if defined HCF_YIELD
#define HCF_WAIT_WHILE( x ) while ( prot_cnt && (x) && (HCF_YIELD) ) prot_cnt--;
#else
#define HCF_WAIT_WHILE( x ) while ( prot_cnt && (x) ) prot_cnt--;
#endif // HCF_YIELD
#endif // HCF_PROT_TIME
#endif // HCF_TYPE_USB

#if defined HCF_EX_INT
#if HCF_EX_INT & ~( HCF_EX_INT_TX_EX | HCF_EX_INT_TX_OK | HCF_EX_INT_TICK )
error, you used an invalid bitmask;
#endif // HCF_EX_INT validation
#else
#define HCF_EX_INT 0x000
#endif // HCF_EX_INT

#if HCF_EX_INT_TICK	!= HREG_EV_TICK
error, someone redefined these macros while the implemenation assumes they are equal;
#endif
#if HCF_EX_INT_TX_OK != HFS_TX_CNTL_TX_OK || HFS_TX_CNTL_TX_OK != HREG_EV_TX_OK
error, someone redefined these macros while the implemenation assumes they are equal;
#endif
#if HCF_EX_INT_TX_EX != HFS_TX_CNTL_TX_EX || HFS_TX_CNTL_TX_EX != HREG_EV_TX_EX
error, someone redefined these macros while the implemenation assumes they are equal;
#endif

#if defined HCF_MB_OFF && defined HCF_MB_ON
error: at most 1 of these macros should be defined;
#endif //HCF_MB_OFF /HCF_MB_ON

#if (HCF_EX_INT) & (HCF_EX_INT_TX_OK | HCF_EX_INT_TX_EX)
#undef HCF_MB_OFF
#endif // HCF_EX_INT

#if defined 	HCF_MB_OFF
#undef			HCF_MB_OFF
#undef			HCF_MB_ON
#define 		HCF_MB_ON	0
#endif // 		HCF_MB_OFF

#if !defined 	HCF_MB_ON
#define 		HCF_MB_ON	1
#endif // 		HCF_MB_ON

/* The assert in HCFLOGENTRY checks against re-entrancy. Re-entrancy could be caused by a MSF logic at
 * task-level calling hcf_functions without shielding with HCF_ACT_ON/_OFF. When an interrupt occurs,
 * the ISR could (either directly or indirectly) cause re-entering of the interrupted HCF-routine.
 *
 * The "(ifbp->IFB_AssertWhere = where)" test in HCFLOGENTRY services ALSO as a statement to get around:
 * #pragma warning: conditional expression is constant
 * on the if-statement
 */
#if HCF_ASSERT
#define HCFASSERT(x,q) if (!(x)) {mdd_assert(        ifbp, __LINE__                   , q );}
#define MMDASSERT(x,q) if (!(x)) {mdd_assert( assert_ifbp, __LINE__ + FILE_NAME_OFFSET, q );}

//================================================= values below 0x0010 invoke HCF_ENTRY and HCF_EXIT HCF_EXIT( ifP )
#define HCFLOGENTRY( where, what ) 														\
{if ( (ifbp->IFB_AssertWhere = where) <= 15 ) {											\
	HCF_ENTRY( ifbp ); 																	\
	HCFASSERT( (ifbp->IFB_AssertTrace & 1<<(where)) == 0, ifbp->IFB_AssertTrace );		\
	ifbp->IFB_AssertTrace |= 1<<(where);												\
	}																					\
HCFTRACE(ifbp, where )																	\
HCFTRACEVALUE(ifbp, what )																\
}

#define HCFLOGEXIT( where ) 															\
{if ( (ifbp->IFB_AssertWhere = where) <= 15 ) {											\
  	HCF_EXIT( ifbp ); 																	\
	ifbp->IFB_AssertTrace &= ~(1<<(where));												\
  }						 																\
HCFTRACE(ifbp, (where)|HCF_TRACE_EXIT )													\
}

#else // HCF_ASSERT
#define HCFASSERT( x, q )
#define MMDASSERT( x, q )
#define HCFLOGENTRY( where, what ) 	  	{HCF_ENTRY( ifbp );}
#define HCFLOGEXIT( where ) 		  	{HCF_EXIT( ifbp );}
#endif // HCF_ASSERT

//;?	JS:  disable this stupid assert!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#if HCF_INT_ON
#if HCF_DDS
#define HCFASSERT_INT HCFASSERT( ifbp->IFB_IntOffCnt != 0xFFFF && ifbp->IFB_IntOffCnt != 0xFFFE, \
								 ifbp->IFB_IntOffCnt )
#else
#define HCFASSERT_INT HCFASSERT( ifbp->IFB_IntOffCnt != 0xFFFF, ifbp->IFB_IntOffCnt )
#endif // HCF_DDS
#else
#define HCFASSERT_INT
#endif // HCF_INT_ON


#ifdef HCF_TRACE
/*;? nv huh????
#ifndef _WIN32_WCE	//;? these MACROS should not be here in the first place !!!!!!!!!!!!!!!!!!
// were these not defined in hcfcfg.h?
#define IN_PORT_WORD(port)			((hcf_16)_inpw( (hcf_io)(port) ))		//;?kludge to get wcitst to run
#define OUT_PORT_WORD(port, value)	((void)_outpw( (hcf_io)(port), value ))
#endif
nv*/
//#define HCFTRACE(ifbp, where ) {OPW( HREG_SW_1, where );}
#define HCFTRACE(ifbp, where )	   {OPW( HREG_SW_1, where );}
#define HCFTRACEVALUE(ifbp, what ) {OPW( HREG_SW_2, what  );}
#else
#define HCFTRACE(ifbp, where )
#define HCFTRACEVALUE(ifbp, what )
#endif // HCF_TRACE


/*	Endianess
 *	Little Endian (a.k.a. Intel), least significant byte first
 *	Big Endian (a.k.a. Motorola), most significant byte first
 *
 * The following macros are supplied
 *  o CNV_LITTLE_TO_INT(w)			interprets the 16-bits input value as Little Endian, returns an hcf_16
 * 	o CNV_BIG_TO_INT(w)				interprets the 16-bits input value as Big Endian, returns an hcf_16
 *
 * At a number of places in the HCF code, the CNV_INT_TO_BIG_NP macro is used. While it does have the desired
 * effect on all platforms, it's naming is misleading, so revisit all places where these CNV macros are used
 * to assure the right name is used at the right place.
 *
 */

/* To increase portability, use unsigned char and unsigned char * when accessing parts of larger
 * types to convert their Endianess
 */

#define CNV_END_INT(w)    ( ((hcf_16)(w) & 0x00FF) << 8 | ((hcf_16)(w) & 0xFF00) >> 8 )
#define CNV_END_LONG(dw)  (hcf_32)( (dw >> 24) | ((dw >> 8) & 0xff00) | ((dw << 8) & 0xff0000) | (dw << 24) )
#if defined HCF_BIG_ENDIAN
#undef		HCF_BIG_ENDIAN
#define 	HCF_BIG_ENDIAN 1					//just for convenience of generating cfg_hcf_opt
#else
#define 	HCF_BIG_ENDIAN 0
#endif // 	HCF_BIG_ENDIAN

#if HCF_BIG_ENDIAN
//******************************************** B I G   E N D I A N *******************************************
#define BE_PAR(x)				,x
#define CNV_LITTLE_TO_INT(w)	CNV_END_INT(w)	//    endianess conversion needed
#define CNV_BIG_TO_INT(w)		(w)				// no endianess conversion needed
#define CNV_LITTLE_TO_LONG(dw)	CNV_END_LONG(dw)
#define CNV_LONG_TO_LITTLE(dw)	CNV_END_LONG(dw)
#else
//****************************************** L I T T L E   E N D I A N ****************************************
#define BE_PAR(x)
#define CNV_LITTLE_TO_INT(w) 	(w)				// no endianess conversion needed
#define CNV_BIG_TO_INT(w)		CNV_END_INT(w)	//    endianess conversion needed
#define CNV_LITTLE_TO_LONG(dw)	(dw)
#define CNV_LONG_TO_LITTLE(dw)	(dw)
#endif // HCF_BIG_ENDIAN

// conversion macros which can be expressed in other macros
#define CNV_INT_TO_LITTLE(w)	CNV_LITTLE_TO_INT(w)
#define CNV_INT_TO_BIG(w)		CNV_BIG_TO_INT(w)

/************************************************************************************************/
/**************************************  END OF MACROS  *****************************************/
/************************************************************************************************/

/************************************************************************************************/
/***************************************  PROTOTYPES  *******************************************/
/************************************************************************************************/

#endif	//HCFDEFC_H

