/******************************************************************************
 *
 *                      VECTOR (for SWORDFISH NS32SF641)
 *
 * This module contains the constants which define the VECTOR 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 NS32SF641
#define FPU_TYPE ON_CHIP_FPU
#define ICU_TYPE ON_CHIP_ICU
#define BUSWIDTH     8           /* bytes */
#define MON_NAME "CMONSF641"
#define VERSION  "4SF"
#define REVISION "99"
#define BOARD VECTOR
#define CACHE

/*-----------------------------------------------------------------------------
 * 
 * On Board Peripherals & I/O
 *
 *---------------------------------------------------------------------------*/

/*
 *	RS232
 */
#define UART_TYPE      Z8530
#define SERIAL_FILE    "z8530.h"
#define UART_0_ADDR    0xff500001
#define UART_1_ADDR    0xff500000

/*
 * The Z8530 SCC on the VECTOR board uses four consecutive bytes.
 * The A/B line of Z8530  is connected on the VECTOR to addr0 line.
 * The C/D line of Z8530  is connected on the VECTOR to addr1 line.
 *      This mean that: port B - Control register is in *UART-ADDRESS*
 *                      port A - Control register is in *UART-ADDRESS* + 1
 *                      port B - Data register is in    *UART-ADDRESS* + 2
 *                      port A - Data register is in    *UART-ADDRESS* + 3
 */
#define PORT_0_STAT    (* (volatile byte *) UART_0_ADDR)
#define PORT_0_IO      (* (volatile byte *) (UART_0_ADDR + 2))
#define PORT_1_STAT    (* (volatile byte *) UART_1_ADDR)
#define PORT_1_IO      (* (volatile byte *) (UART_1_ADDR + 2))

#define SCC0_R14_VAL	0x2 
#define SCC1_R14_VAL	0x2 
#define PORT_0_R9_VAL	0x80 
#define PORT_1_R9_VAL	0x40 
#define SCC_INT         0x5


/*
 *	SRAM
 */
#define LAST_ELEMENT	0x969696
#define SRAM_START      0xc0000000 
#define SRAM_START1     0xc1000000 
#define SRAM_START2     0xe0000000 
#define SRAM_START3     LAST_ELEMENT 

/*
 *	NVRAM
 */
#define NVRAM_START     0xff700000
#define NVRAM_SIZE      0x2000

/*
 *      LAN
 */
#define LAN_IOBASE  0xA2000300
#ifdef DEBUG
#define MAXRETRY    160000	    /* Max retries for packet reception */
#else
#define MAXRETRY    20000          /* Max retries for packet reception */
#endif


/*
 *      EPROM
 */
#define ROM_START 0x20000000  /* Begin address of rom */
#define ROM_SIZE  0x20000     /* For 128K EPROMs      */
#define ROM_BUSWIDTH 1

/*
 *      DMA
 */
#define DMA_INT   14            /* Interrupt from DMA (Video - ch.0  */



/*-----------------------------------------------------------------------------
 * 
 * On Board  I/O  Registers
 *
 *---------------------------------------------------------------------------*/

/*
 *  Board Control Register,  Write Only (BCR)
 */
#define   BD_CTRL_ADD	    0xFF300000
#define   BD_CTRL           (*((volatile byte *) BD_CTRL_ADD))	

/*
 *  LCD control/data Register,  Write Only (LCR)
 */
#define LCR_ADDR	0xff200000
#define LCR     *((volatile unsigned char *) LCR_ADDR)

/*
 *  Board Status Register, Read Only (BSR)
 */
#define BSR_ADDR	0xff200000
#define BSR     *((volatile unsigned char *) BSR_ADDR)

/*
 *  CENTRONICS data (CND).
 */
#define CND_ADDR        0xff400000
#define CND   *((volatile unsigned char *) CND_ADDR)



/*----------------------------------------------------------------------------
 * C macroes
 *--------------------------------------------------------------------------*/
/*
 * Dip Switch Usage:
 * Usage of dip switch for burned monitor according to the monitor manual.
 * For debuged monitor switch D8  == ON SERIAL  9600
 *                            D8  == OFF THICK ETHERNET
 */

#define   DIP_SWITCH        BD_CTRL

#ifndef	DEBUG
#   define BOARD_COM_MODE  ( ((DIP_SWITCH & 0xe0) == 0x0) || \
			     ((DIP_SWITCH & 0xe0) == 0x80) ) ? LAN : RS232
#   define ETHERNET_TYPE    (NOT (DIP_SWITCH & 0x80))
#   define UART_DIVISOR  uart_table[ \
			  ((((unsigned int) DIP_SWITCH) & 0xe0) >> 5)].divisor
#else
#   define BOARD_COM_MODE  ((DIP_SWITCH & 0x1) == 0x1) ? LAN : RS232
#   define ETHERNET_TYPE   1
#   define UART_DIVISOR	  46
#endif 

#   define UART_INIT_TABLE const uart_table_entry uart_table[] = \
                            {  {9600,    46} \
                            ,   {9600,    46} \
                            ,   {38400,   10}\
                            ,   {2400,   190}\
                            ,   {9600,    46}\
                            ,   {4800,    94}\
                            ,   {19200,   22}\
                            ,   {1200,   382}\
                            ,   {0,   0} };

#   define DEMO_ON	    (DIP_SWITCH & 0x2)	/* switch #7 is (OFF) */
#   define DEMO_ADDR        0x10000000


#ifndef DEBUG
#define DELAY_FACTOR 10
#undef  DELAY
#define DELAY(m) {volatile int j; for (j = m; j > 0; j -= DELAY_FACTOR);}
#endif

/*-----------------------------------------------------------------------------
 *  Assembly macroes
 *---------------------------------------------------------------------------*/
#define TURN_OFF_SHADOW	    .set    BCR,    BD_CTRL_ADD; \
			     orb    $0x80, c0, r0;  storb   r0, @BCR
 
#define JMP_TO_DIAGNOS			/* no diagnos yet*/


/*-----------------------------------------------------------------------------
 * Diagnostic macros and definitions 
 *  This part is  ifdefed DIAG 
 *---------------------------------------------------------------------------*/
#ifdef DIAG

#ifdef DIAG_MAIN
extern  char *test_cpu__(),     *test_z8530__(),  *test_eprom__(),  
             *test_dram__(),    *test_sram__(),   *test_icu__(),  
             *test_fpu__(),     *test_eeprom__(),  *test_led__(), 
             *test_nvram__(),   *test_scsi__(), 
             *test_lcd__(),     *test_centronics__();

const struct diag_desc diag_test_list__[] = {
                                 {" CPU TEST",   	test_cpu__},  
                                 {" DRAM TEST",   	test_dram__}, 
                                 {" SRAM TEST",   	test_sram__}, 
                                 {" 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__}, 
                                 {" NVRAM TEST",   	test_nvram__}, 
                                 {" SCSI TEST",   	test_scsi__}, 
                                 {" EEPROM TEST",  	test_eeprom__}, 
                                 {" CENTRONICS TEST",   test_centronics__}, 
                                 {0,  0}
                                 };

#define LOOP_LIST 0x07ff


/*
 * Board intialization and interface  macros.
 */
#endif
#define INIT_SHADOW  {shadow.ecr = 0 ;shadow.cfr = 0; shadow.vcr = 0; \
                      shadow.lcr = 0; shadow.cnd = 0; }
#endif



/*----------------------------------------------------------------------------
 *  LCD Macros
 *---------------------------------------------------------------------------*/
#define LCD0    0x01
#define LCD1    0x02
#define LCD2    0x04
#define LCD3    0x08
#define LCE     0x40            /* LCD write enable  */
#define LCDRS   0x80            /* Reg Select 0 = LCD Command,  1 = Data */

#define LCD_BIT_SET(pattern)    { shadow.lcr |= pattern ;  \
                                  LCR = shadow.lcr; }
#define LCD_BIT_CLEAR(pattern)  { shadow.lcr &= ~(pattern) ; \
                                  LCR = shadow.lcr ; }
#define LCD_BYTE_SET(val)       { shadow.lcr &= 0xf0 ; \
                                 shadow.lcr |= ((val) & 0x0f) ;\
                                 LCR = shadow.lcr ; }
                                /* 'nibble' below is 4 bits */
#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);}
#define INIT_LCD         init_lcd__()
#define PRINT_LCD(str)   print_lcd__(str) 

#define LCD_ROM_DELAY 30000
#define LCD_RAM_DELAY 900000

/*----------------------------------------------------------------------------
 *  EEprom Macros
 *  EEprom Control Register (ECR) - write only. 
 *  In the board spec` called  BCR (board control reg`).
 *  EEprom Status Register (ESR) - read only
 *  In the board spec` called BSR (board status reg`).
 *---------------------------------------------------------------------------*/
#define ECR     BD_CTRL
#define EEDO    0x01            /* serial data from EEPROM */
#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);}
#define ESR    BSR 
#define ESR_IS_SET(pattern)     ( (pattern) == (ESR & (pattern)))
#define ESR_IS_CLEAR(pattern)   ( !(ESR & (pattern)))


/*----------------------------------------------------------------------------
 *  CENTRONICS Macros
 *---------------------------------------------------------------------------*/
#define CENT_BITSET(pattern)     { shadow.cnd |= (pattern) ;  \
                                  CND = shadow.cnd; }
#define CENT_BITCLEAR(pattern)   { shadow.cnd &= ~(pattern) ; \
                                  CND = shadow.cnd ; }
#define PE      0x10          /* Out of Paper     */
#define OL      0x08          /* Printer on-line  */
#define ERR     0x20          /* Printer Error    */
#define CEN     0x80          /* Centronics enable */





/*----------------------------------------------------------------------------
 *  LED Macros
 *---------------------------------------------------------------------------*/
#    define   LED_PORT  BD_CTRL
#    define LED(X)      LED_PORT = (X)

#   define    LED_0     0x1e            /*       0      */
#   define    LED_1     0x1c            /*       1      */
#   define    LED_2     0x1a            /*       2      */
#   define    LED_3     0x18            /*       3      */
#   define    LED_4     0x16            /*       4      */
#   define    LED_5     0x14            /*       5      */
#   define    LED_6     0x12            /*       6      */
#   define    LED_7     0x10            /*       7      */
#   define    LED_8     0x0e            /*       8      */
#   define    LED_9     0x0c            /*       9      */
#   define    LED_A     0x0a            /*       A      */
#   define    LED_B     0x08            /*       B      */
#   define    LED_C     0x06            /*       C      */
#   define    LED_D     0x04            /*       D      */
#   define    LED_E     0x02            /*       E      */
#   define    LED_F     0x00            /*       F      */
#   define    LED_P     0x00            /*       P      */


/*-----------------------------------------------------------------------------
 * 
 *  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.
 *
 *---------------------------------------------------------------------------*/

/*
 *  start of AT bus I/O space 
 */
#define   AT_BUS_IO          0xA2000000	

