/******************************************************************************
 *
 *	SWIFT DEFINTION FILE
 *
 * @(#)Copyright (C) 1991 National Semiconductor Corp.
 *
 * This module contains the constants which define the SWIFT 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 NS32CG160
#   define FPU_TYPE NS32181
#   define ICU_TYPE ON_CHIP_ICU
#   define BUSWIDTH	2	    /* bytes */
#   define ROM_BUSWIDTH	2
#   define MON_NAME "MONCG160LX"
#   define VERSION  "4"
#   define REVISION "99"
#   define BOARD CG160LX
#   define UART_TYPE      Z8530
#   define UART_0_ADDR    0xF80002
#   define UART_1_ADDR    0xF80000
#   define PORT_0_STAT    (* (volatile byte *) (UART_0_ADDR + 4))
#   define PORT_0_IO      (* (volatile byte *) UART_0_ADDR)
#   define PORT_1_STAT    (* (volatile byte *) (UART_1_ADDR + 4))
#   define PORT_1_IO      (* (volatile byte *) UART_1_ADDR )
#   define WAIT(micro_sec) 
#   define SCC0_R14_VAL	  0x2
#   define SCC1_R14_VAL	  0x2
#   define PORT_0_R9_VAL  0x40 
#   define PORT_1_R9_VAL  0x80
#   define SCC_INT	  0x2

#   define SERIAL_FILE    "z8530.h"

#   ifndef RAM
#   define DIAG_PORT 0
#   else
#   define DIAG_PORT 1
#   endif

#   define   ROM_START 0x400000  /* begin address of rom */
#   define   ROM_SIZE  524288	   /*  for 32k EPROMs  */

#define DMA_INT   14 	        /* Interrupt from DMA (Video - ch.0  */
 
#   ifndef RAM
#	define CMON_MOD   0x7ff0
#	define CMON_SB    0x8000
#   else
#	define CMON_MOD  0x0
#	define CMON_SB   0x10
#   endif


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


#define BOARD_COM_MODE RS232

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

#   define TURN_OFF_SHADOW	   movqw   $0,  CFR  

#   define JMP_TO_DIAGNOS			/* no diagnos yet*/

/*
 *  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) & 0x1].divisor
 
#   define UART_INIT_TABLE const uart_table_entry uart_table[] = \
                            { {38400, 4} \
			    , {9600, 22} \
			    , {0, 0} }; 

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


				/* macro to output string to LCD or alike. */
				/* macro to output number to 7-SEGMENT-LED */
#	define INIT_LCD		init_lcd__()
#	define PRINT_LCD(str)	print_lcd__(str) 
#	define LCD_RAM_DELAY	900000
#	define LCD_ROM_DELAY	30000
#	define PRINT_LED(num)   


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


extern	char *test_cpu__(), *test_z8530__(), *test_eprom__(),  
	     *test_eeprom__(), 
	     *test_dram__(), *test_icu__(), *test_fpu__(), 
	     *test_led__(), *test_lcd__(), *test_centronics__();

const struct diag_desc diag_test_list__[] = {
				{" CPU TEST",        test_cpu__},
				{" DRAM TEST",       test_dram__},
				{" SERIAL I/O TEST", test_z8530__},
				{" ICU TEST",        test_icu__},
				{" FPU TEST",        test_fpu__},
				{" EPROM TEST",      test_eprom__},
				{" LED TEST", 	     test_led__},
				{" LCD TEST",        test_lcd__},
				{" EEPROM TEST",     test_eeprom__},
				{" CENTRONICS TEST", test_centronics__},
				{0, 0}
				};

     /* The default tests in loop operations       **
     ** does not include eeprom & centronics tests */
#define LOOP_LIST 0x00ff

#endif /* DIAG_MAIN */

/****************************************************************************
 *
 *  The following definitions are NOT used in CMON directly.
 *  They might be used in the above definitions to define CMON used macros
 *  or be used temporrarly for debbuging.
 *
 ****************************************************************************/


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

/****************************************************************************
 *
 *  misc. I/O in register 
 *
 ****************************************************************************/


/****************************************************
 * Configuration Register (CFR) - write only 
 ****************************************************/

#define CFR     *((volatile unsigned short *) 0xf88000)

#define CFR_BITSET(pattern)     { shadow.cfr |= (pattern) ;  \
                                  CFR = shadow.cfr; }
#define CFR_BITCLEAR(pattern)   { shadow.cfr &= ~(pattern) ; \
                                  CFR = shadow.cfr ; }
#define CFR_IS_SET(pattern)     ( (pattern) == (shadow.cfr & (pattern)))
#define CFR_IS_CLEAR(pattern)   ( !(shadow.cfr & (pattern)))
#define CFR_SET_ROM_WAIT(val)   { shadow.cfr &= 0xffcf; \
                                  shadow.cfr |= ((~(val) << 4)&0x0030);}

/****************************************************
 *  LCD control/data register (LCR)
 *  bits 8, 11 of CFR are the LCD data bits
 ***************************************************/
  
#define LCE	0x0040		/* LCD write enable  */
#define LCDRS	0x0080		/* Reg Select 0 = LCD Command, 1 = Data */
#define LCD0	0x0100
#define LCD1	0x0200
#define LCD2	0x0400
#define LCD3	0x0800

#define LCD_BIT_SET(pattern)     { shadow.cfr |= (pattern) ;  \
                                  CFR = shadow.cfr; }
#define LCD_BIT_CLEAR(pattern)   { shadow.cfr &= ~(pattern) ; \
                                  CFR = shadow.cfr ; }
#define LCD_BYTE_SET(val)      { shadow.cfr &= 0xf0ff ; \
				 shadow.cfr |= (((val) << 8) & 0x0f00) ;\
				 CFR = shadow.cfr ;\
			       }

#define SET_LCD_CMND(nibble) { LCD_BIT_CLEAR(LCDRS); LCD_BYTE_SET(nibble); \
               LCD_BIT_SET(LCE); DELAY(1000); LCD_BIT_CLEAR(LCE); DELAY(1000);}

#define SET_LCD_DATA(nibble) { LCD_BIT_SET(LCDRS); LCD_BYTE_SET(nibble); \
               LCD_BIT_SET(LCE); DELAY(1000); LCD_BIT_CLEAR(LCE); DELAY(1000);}


/***************************************************
 *  EEprom Control Register (ECR) - write only.	
 *  In the board spec` called  EDR (external data reg`).
 **************************************************/

#define EEDO	0x08		/* serial data from EEPROM */

#define ECR     *((volatile unsigned char *) 0xf80200)

#define ECR_BITSET(pattern)     { shadow.ecr |= (pattern) ;  \
                                  ECR = shadow.ecr; }
#define ECR_BITCLEAR(pattern)   { shadow.ecr &= ~(pattern) ; \
                                  ECR = shadow.ecr ; }
#define ECR_IS_SET(pattern)     ( (pattern) == (shadow.ecr & (pattern)))
#define ECR_IS_CLEAR(pattern)   {( !(shadow.ecr & (pattern))) \
                                  shadow.cfr |= ((~(val) << 4)&0x0030);}
 
/***************************************************
 *  EEprom Status Register (ESR) - read only
 *  In the board spec` called ESR (external status reg`).
 ***************************************************/
 
#define ESR     *((volatile unsigned char *) 0xf80200)
 
#define ESR_IS_SET(pattern)     ( (pattern) == (ESR & (pattern)))
#define ESR_IS_CLEAR(pattern)   ( !(ESR & (pattern)))
 
/***************************************************
 *  CENTRONICS macros  addressing the (CFR).
 ***************************************************/

#define DMSRC   0x0001          /* 0: DMA channel 1 services SCC
                                 * 1: DMA channel 1 services Centronics   */
#define PE      0x1000          /* Out of Paper     */
#define OL      0x2000          /* Printer on-line  */
#define ERR     0x4000          /* Printer Error    */

#define CND   *((volatile unsigned char *) 0xf80100)  /* Centronics data */  
                                       /* usually read by DMA not by S/W */

#define CENT_BITSET(pattern)     { shadow.cfr |= (pattern) ;  \
                                  CFR = shadow.cfr; }
#define CENT_BITCLEAR(pattern)   { shadow.cfr &= ~(pattern) ; \
                                  CFR = shadow.cfr ; }


    /***************************
     *  configuration dip switch 
     ***************************/
#   define   DIP_SWITCH_ADD    0xF80200  /* External Status Register (Read) */
#   define   DIP_SWITCH        (*((volatile byte *) DIP_SWITCH_ADD))	

    /***************************
     *  four LEDs
     ***************************/
#    define   LED_PORT_ADD     0xF80200  /* External Data Register (Write) */
#    define   LED_PORT         (*((volatile byte *) LED_PORT_ADD))	
    
/****************************************************************************
 *
 * Board intialization and interface  macros.
 *
 ****************************************************************************/

#define  INIT_SHADOW  { shadow.ecr = 0; shadow.cfr = 0; shadow.vcr = 0; }

#ifdef ASEM
#define LED(X)      movb        $(X),   @LED_PORT_ADD
#else
#define LED(X)	LED_PORT = (X)
#endif


#   define    LED_0	0x0f            /*       0	*/
#   define    LED_1	0x0e            /*       1	*/
#   define    LED_2	0x0d            /*       2	*/
#   define    LED_3	0x0c            /*       3	*/
#   define    LED_4	0x0b            /*       4	*/
#   define    LED_5	0x0a            /*       5	*/
#   define    LED_6	0x09            /*       6	*/
#   define    LED_7	0x08            /*       7	*/
#   define    LED_8	0x07            /*       8	*/
#   define    LED_9	0x06            /*       9	*/
#   define    LED_A	0x05            /*       A	*/
#   define    LED_B	0x04            /*       B	*/
#   define    LED_C	0x03            /*       C	*/
#   define    LED_D	0x02            /*       D	*/
#   define    LED_E	0x01            /*       E	*/
#   define    LED_F	0x00            /*       F	*/
#   define    LED_P	0x00            /*       P	*/


