/******************************************************************************
 *
 *	FX16FAX (DRAGON) DEFINTION FILE
 *
 * @(#)Copyright (C) 1991 National Semiconductor Corp.
 *
 *
 * This module contains the constants which define the DRAGON board.
 *
 * NOTE: It should not contain definition of any variables,  since it is
 *       included by the drivers too!
 *
 * History:
 *   +----------+------------+------------------------------------------------+
 *   |   Date   |     by     |     Description                                |
 *   +----------+------------+------------------------------------------------+
 *   |          | Lior       | Written                                        |
 *   +----------+------------+------------------------------------------------+
 *
 *****************************************************************************/

/****************************************************************************
 *
 *  The following definition are used in CMON.
 *  They MUST apear in any board definition file.
 *
 ****************************************************************************/

 
#   define CPU_TYPE NS32FX16
#   define FPU_TYPE NOFPU
#   define ICU_TYPE DRAGON_ICU
#   define BUSWIDTH	2	    /* bytes */
#   define ROM_BUSWIDTH	2
#   define MON_NAME "MONFX16FAX"
#   define VERSION  "4"
#   define REVISION "99"
#   define BOARD FX16FAX
#   define UART_TYPE      NS16550
#   define UART_0_ADDR    0xfffd80   /* J19 monitor uart */
#   define UART_1_ADDR    0xfffd90   /* J18 Terminal uart */
#   define UART0_INT       12
#   define UART1_INT       12
#   define SERIAL_FILE    "ns16550.h"
#   define ICU_ADDR       0xfffe00
#   define UART_BUS_OFFSET   2
#   ifndef RAM
#   define DIAG_PORT 0
#   else
#   define DIAG_PORT 1
#   endif

#   define   ROM_START 0x40000  /* begin address of rom */
#   define   ROM_SIZE  65536	   /*  for 64k EPROMs  */

/****************************************************************************
 *
 * C macroes
 *
 ***************************************************************************/

#   define BOARD_COM_MODE RS232


/****************************************************************************
 *
 *  Assembly macroes
 *
 ***************************************************************************/

#   define JMP_TO_DIAGNOS			/* no diagnos yet*/


#  define NO_UART_INT 			/* uart interrupt test disable */

/*
 *  Baud rate conversion table.  Setting of SW1 bits 0-3 serve
 *  as index into table.  Table holds value to be loaded into 
 *  divisor latches.  UART master clock = 	MHz.
 *  divisor # = (Frequency input) / baud-rate * 16
 *
 *  The setting of '0000' in the least significant bits of the
 *  configuration switch is a special case.  This will indicate
 *  that the ethernet board is active and the two serial channels
 *  are set for 9600 baud operation.
 */

#   define UART_DIVISOR  uart_table[ \
                            (((unsigned int) DIP_SWITCH) >> 3) & 0x1].divisor
 
#   define UART_INIT_TABLE const uart_table_entry uart_table[] = \
                            { {9600, 10} \
			    , {19200, 5} \
			    , {0, 0} }; 

#   define BAUD_9600   10
#   define BAUD_19200   5				   

/****************************************************************************
 *
 * Diagnostic macros and definitions 
 *  This part is  ifdefed DIAG 
 *
 ***************************************************************************/

#	define INIT_LCD
#	define PRINT_LCD(str)     /* macro to output string to LCD or alike. */


/**************************************************************************
 *
 * initialized const data definitions
 *
 *************************************************************************/
 
#ifdef DIAG_MAIN

extern	char *test_cpu__(), *test_dram__(), *test_16550__(),  
	     *test_eprom__(), *test_others__();

const struct diag_desc diag_test_list__[] = {
				    {" CPU TEST",        test_cpu__},
				    {" DRAM TEST", 	 test_dram__},
				    {" SERIAL I/O TEST", test_16550__}, 
				    {" EPROM TEST", 	 test_eprom__},
#ifdef OTHER_TESTS
				    {" EPROM TEST", 	 test_others__},
#endif
				    {0, 0}
};

/****************************************************************************
 *
 * 	dragon_dip_switch()
 *
 * The following function comunicate with the dragon ASIC in order to get
 * the dip_switch_value. This function return the register value, where the
 * second & third bits are the dip switch values.
 * Usage of dip switch for burned monitor according to the monitor manual
 * Jp6-ON  : 9600 Baud
 * Jp6-OFF : 19200 Baud
 * Jp7-ON  : Monitor
 * Jp7-OFF : Jump-to-Aplication
 *
 ***************************************************************************/

#   define   MWCTL       0xFFFC02
#   define   MWDAT       0xFFFC00
#   define MW_DO(x)      *mwdat_p = x; *mwctl_p = 0x51; \
    		         while( *mwctl_p & 0x10) 		/* Busy wait */

dragon_dip_switch()
{
    volatile unsigned char *mwctl_p;
    volatile unsigned char *mwdat_p;

    mwctl_p = (volatile unsigned char *) MWCTL;
    mwdat_p = (volatile unsigned char *) MWDAT;
    *mwctl_p = 0x41;
    MW_DO(0x12);                   		/* Config I/O pins 	*/
    MW_DO(0xf0);                  		/* I/O pins = OOOOIIXX 	*/
    MW_DO(0x0e);                 		/* Read I/O pins 	*/
    MW_DO(0x00);               			/* Dummy command 	*/
    return *mwdat_p;
}
#endif /* DIAG_MAIN */

/****************************************************************************
 *
 * On board Address regions
 *
 ***************************************************************************/

/****************************************************************************
 *
 *  misc. I/O in register 
 *
 *  configuration dip switch 
 *  The following macro return the values: 0, 4, 8, C.
 *  This values coresponds to the second & third bits return by
 *  the function Dragon_dip_switch
 ***************************************************************************/

#   define   DIP_SWITCH        (0x0C & (byte) dragon_dip_switch())

#    define   IMASK_ADD		    0xF80200    
#    define   IMASK		(* ((volatile byte  *) IMASK_ADD))

/****************************************************************************
 *
 * Board intialization and interface  macros.
 *
 ***************************************************************************/

#    define LED(X)	/* no LED on dragon */
