/******************************************************************************\
*           Copyright (C) 2000 Texas Instruments Incorporated.
*                           All Rights Reserved
*------------------------------------------------------------------------------
* FILENAME...... bsl_dip.c
* DATE CREATED.. Thu 06/15/2001 
* LAST MODIFIED. Thu 06/15/2001 
*
\******************************************************************************/
#define _DIP_MOD_
#define _BOARD_MOD_ 

/****************************************\
* include files
\****************************************/

#include "bsl_dip.h"

#if (DIP_SUPPORT)
/******************************************************************************\
*                         L O C A L   S E C T I O N
\******************************************************************************/

/****************************************\
* DIP static macro declarations
\****************************************/

#if (BOARD_6711DSK | BOARD_6211DSK)
  /* DIP memory mapped address */
  #define DIP_PORT        _BOARD_IOPORT
  /* DIP right shift */
  #define DIP_SHIFT(x)    (x>>24)
#endif

#if (BOARD_6201EVM)
  /* DIP memory mapped address */
  #define DIP_PORT        _BOARD_DIP_REG
  /* DIP no shift */
  #define DIP_SHIFT(x)    x
#endif

/****************************************\
* DIP static typedef declarations
\****************************************/

/****************************************\
* DIP static function declarations
\****************************************/

/****************************************\
* DIP static variable definitions
\****************************************/

/****************************************\
* DIP static function definitions
\****************************************/
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/

/******************************************************************************\
*                        G L O B A L   S E C T I O N
\******************************************************************************/

/****************************************\
* DIP global variable definitions
\****************************************/

/****************************************\
* DIP global function definitions
\****************************************/
/*----------------------------------------------------------------------------*/

void _DIP_init() {
  static int initialized = 0;

  if (!initialized) {
    _BOARD_init();
    initialized = 1;
  }
}

/*----------------------------------------------------------------------------*/

Uint32 DIP_get(Uint32 dipNum){

  Uint32 oldCECTL1 = EMIF_RGET(CECTL1);
  Uint32 dipVal;

#if (BOARD_6711DSK | BOARD_6211DSK |BOARD_6201EVM)
  /* set CE1 space to 32-bit async mode */
  EMIF_RSET(CECTL1,(oldCECTL1 & (~0x000000F0)) | 0x00000020);
  while((EMIF_RGET(CECTL1) & 0x00F0) != 0x20);
#endif
               
  dipVal = DIP_PORT;
  dipVal = DIP_SHIFT(dipVal) & dipNum; 
  if (dipVal) dipVal = 1;

  EMIF_RSET(CECTL1, oldCECTL1);                    /* restore CE1 space          */

  return (dipVal);
}  

/*----------------------------------------------------------------------------*/

#endif /* DIP_SUPPORT */
/******************************************************************************\
* End of bsl_dip.c
\******************************************************************************/