/*FILE HEADER*********************************************************
 *
 *  File Name           : css.h
 *  RCS Revision Number : 
 *  Last Modified	: oct-10-1994 by s.coudray MBARI/IFREMER
 *  Environment         : VxWorks
 *  CSCI Name           : Card-Specific Services
 *  History     :
 *      90-09-11 - Mark Guzewski
 *                 File created in parallel with CSS User's Manual.
 *	oct-10-1994 : Sylvain Coudray
 *		replacing defines relative to css_jump_table by
 *		unix functions for few of them.
 *
 *END FILE HEADER*****************************************************/

#ifdef MAKEHS
#undef MAKEHS
#include <dy4std.h> 
#endif

/**********************************************************************
 * The following values are written to the lowest long-word of RAM in
 * the event of a catastrophic failure in the minimum confidence test (MCT)
 * This test is run from Init_card()
 **********************************************************************/

#define CSS_MCT_NO_ERROR      0     /* MCT passed */
#define CSS_MCT_RAM_ERROR     1     /* RAM r/w or DCD error */
#define CSS_MCT_CPU_ERROR     2     /* CPU maze failure */


/**********************************************************************
 * The following values are returned from the services, or by a call to
 * Get_error()
 **********************************************************************/

#define CSS_UNIMPLEMENTED   ((uint32)(-1)) /* service not supported          */
#define CSS_OK              ((uint32)  0)  /* function completed normally    */
#define CSS_ERROR           ((uint32)  1)  /* error during service execution */



/**********************************************************************
 * The following constants relate to the interrupt support services.
 **********************************************************************/

/**********************************************************************
 * The following defines are the interrupt IDs used in calls to
 * the interrupt-related services Enable_int(), Clear_int(),
 * Int_status(), Set_int_map()
 **********************************************************************/

#define CSS_ACFAIL_INT        ((uint32) 0x00000001)
#define CSS_SYSFAIL_INT       ((uint32) 0x00000002)
#define CSS_WATCHDOG_INT      ((uint32) 0x00000004)
#define CSS_BI_INT            ((uint32) 0x00000008)
#define CSS_LM_INT            ((uint32) 0x00000010)
#define CSS_TICK_INT          ((uint32) 0x00000020)
#define CSS_DARF_INT          ((uint32) 0x00000040)
#define CSS_RAM_PARITY_INT    ((uint32) 0x00000080)
#define CSS_DARF_BUS_ERROR    ((uint32) 0x00000100)


/**********************************************************************
 * The following defines are the opcode for the control_watchdog()
 * function.
 **********************************************************************/

#define CSS_WATCHDOG_DISABLE  ((uint32) 0)
#define CSS_WATCHDOG_ENABLE   ((uint32) 1)
#define CSS_WATCHDOG_RESET    ((uint32) (-1))


/**********************************************************************
 * The following defines and structures are used by the Mark functions.
 **********************************************************************/

#define CSS_GENERAL_MARK      ((uint32) 0)
#define CSS_BUS_ERROR_MARK    ((uint32) 2)

typedef struct css_mark
{ 
    struct css_mark *next;     /* Pointer to next mark in stack.      */
    uint32          type;      /* The mark type (ie level).           */
    uint32          class;     /* The mark class: CALL or PUSH.       */
    uint32          pc;        /* The return address for PUSH_MARK.   */
    uint32          function;  /* The function for CALL_MARK.         */
    struct
    {
        uint32          d0;     /* Processor environment.         */
        uint32          d1;
        uint32          d2;
        uint32          d3;
        uint32          d4;
        uint32          d5;
        uint32          d6;
        uint32          d7;
        uint32          a0;
        uint32          a1;
        uint32          a2;
        uint32          a3;
        uint32          a4;
        uint32          a5;
        uint32          a6;
        uint32          a7;
    } context;
} css_mark_struct;




/**********************************************************************
 * The following defines are returned by the Get_local_map() function
 * in the darf_type and memory_type fields.
 **********************************************************************/

#define CSS_MAX_MEMORY_TYPES  16
#define CSS_SRAM              ((uint32) 1)
#define CSS_DRAM              ((uint32) 2)
#define CSS_EPROM             ((uint32) 3)
#define CSS_EEPROM            ((uint32) 4)
#define CSS_FLASH             ((uint32) 5)

/**********************************************************************
 * The following structure is used in the Get_local_map() function.
 **********************************************************************/

typedef struct css_local_map {
    uint32 acc_base;         /* base of the ACC                        */
    uint32 darf_base;        /* base of the DARF                       */
    uint32 reserved1;        /* reserved for future expansion          */
    uint32 clic_base;        /* base of the CLIC                       */
    uint32 vsb_base;         /* base of the VSB controller chip        */
    uint32 local_lm_base;    /* base of the local location monitor     */
    uint32 ram_base;         /* base of local RAM (CPU bank)           */
    uint32 ram_size;         /* size of local RAM (CPU bank)           */
    uint32 rom_base;         /* base of local ROM (low bank)           */
    uint32 rom_size;         /* size of local ROM (low bank)           */
    uint32 reserved2;        /* reserved for future expansion          */
    uint32 seeprom_size;
    struct css_local_memory {
        uint32 type;         /* the type of memory bank:               */
                             /* CSS_SRAM, CSS_DRAM, CSS_EPROM,         */
                             /* CSS_EEPROM, CSS_FLASH                  */
        uint32 base;         /* local memory bank base address         */
        uint32 size;         /* the size of the bank in bytes          */
        uint32 width;        /* the width of the bank in bytes         */
    } memory[CSS_MAX_MEMORY_TYPES];
} css_local_map_struct;



/**********************************************************************
 * The following structure is used in the Set_vme_map() and
 * Get_vme_map() functions for base addresses and image sizes.
 **********************************************************************/

typedef struct css_vme_map {
    uint32 a16_base;        /* A16 base address          */
    uint32 a16_size;        /* size of A16 image         */
    uint32 a16_lm;          /* A16 location monitor base */
    uint32 a24_base;        /* A24 base address          */
    uint32 a24_size;        /* size of A24 image         */
    uint32 a24_lm;          /* A24 location monitor base */
    uint32 a32_base;        /* A32 base address          */
    uint32 a32_size;        /* size of A32 image         */
    uint32 a32_lm;          /* A32 location monitor base */
    uint32 a64_base;        /* A64 base address          */
    uint32 a64_size;        /* size of A64 image         */
    uint32 a64_lm;          /* A64 location monitor base */
    uint32 vsb_base;        /* VSB base address          */
    uint32 vsb_size;        /* size of VSB image         */
    uint32 lm_type;         /* type of location monitor  */
} css_vme_map_struct;


/**********************************************************************
 * The following defines are used in the Set_vme_map() function to
 * specify the item who's base address and size is being set.
 **********************************************************************/

#define CSS_A16_BASE        0x00000001
#define CSS_A16_SIZE        0x00000002
#define CSS_A16_LM          0x00000004
#define CSS_A24_BASE        0x00000008
#define CSS_A24_SIZE        0x00000010
#define CSS_A24_LM          0x00000020
#define CSS_A32_BASE        0x00000040
#define CSS_A32_SIZE        0x00000080
#define CSS_A32_LM          0x00000100
#define CSS_A64_BASE        0x00000200
#define CSS_A64_SIZE        0x00000400
#define CSS_A64_LM          0x00000800
#define CSS_VSB_BASE        0x00001000
#define CSS_VSB_SIZE        0x00002000


/**********************************************************************
 * The following defines are returned by the Get_vme_map() function
 * in the lm_type field.
 **********************************************************************/

#define CSS_FIFO_LM        0
#define CSS_FLAT_LM        1


/**********************************************************************
 * The following defines are used in the Set_status() function to
 * specify the item who's status is being set .
 **********************************************************************/

#define CSS_SYSFAIL        ((uint32) 0x00000001)
#define CSS_BI_MODE        ((uint32) 0x00000002)
#define CSS_SYSCON         ((uint32) 0x00000003)
#define CSS_RESET_PWRUP    ((uint32) 0x00000004)
#define CSS_ACFAIL         ((uint32) 0x00000005)



/**********************************************************************
 * The following defines are returned from the Get_card_type()
 * service and specify the card's form factor.
 **********************************************************************/

#define CSS_SVME_CARD  0
#define CSS_DVME_CARD  1


/**********************************************************************
 * The following defines are used in calls to Control_bi_line() to 
 * assert or deassert the BI line on the VMEbus (TRUE & FALSE can also 
 * be used).
 **********************************************************************/

#define CSS_NEGATE_BI    0
#define CSS_ASSERT_BI    1


/**********************************************************************
 * The following defines are returned from calls to Get_cpu_type() and 
 * indicate the type of processor on the card. 
 **********************************************************************/

#define CSS_68000  0x68000
#define CSS_68010  0x68010
#define CSS_68020  0x68020
#define CSS_68030  0x68030
#define CSS_68040  0x68040


/**********************************************************************
 * The following defines are used in the I/O functions Fprintf(), 
 * Printf(), Sprintf(), Fscanf(), Scanf(), Sscanf(), Putc(), Getc(),
 * and Ungetc().
 **********************************************************************/

/**********************************************************************
 * Serial I/O services: standard device definitions.
 **********************************************************************/

#define CSS_SIO0   ((uint32) 0)    /* UART 1, channel A          */
#define CSS_SIO1   ((uint32) 1)    /* UART 1, channel B          */
#define CSS_SIO2   ((uint32) 2)    /* UART 2, channel A          */
#define CSS_SIO3   ((uint32) 3)    /* UART 2, channel B          */
#define CSS_SIO4   ((uint32) 4)    /* UART 3, channel A          */
#define CSS_SIO5   ((uint32) 5)    /* UART 3, channel B          */
#define CSS_SIO6   ((uint32) 6)    /* UART 4, channel A          */
#define CSS_SIO7   ((uint32) 7)    /* UART 4, channel B          */


/**********************************************************************
 * Interface configuration flags for Get_io_config() and Set_io_config()
 **********************************************************************/

#define CSS_DEFAULT_BAUD_RATE   ((uint32) (-1))

/**********************************************************************
 * This structure is used to pass SIO configuration information to
 * Set_io_config() and from Get_io_config().
 **********************************************************************/

typedef struct css_sio_config {
    uint32 baud;
    uint32 stop_bits;     
    uint32 data_bits;
    uint32 parity_enabled;
    uint32 parity_even;
    uint32 reset_device;
    uint32 echo_char;
    char   *eol_string;
    uint32 ignore_case;
    uint32 auto_crlf;
} css_sio_config_struct;


/**********************************************************************
 * These bit masks are used in the Io_status function for SIO standard
 * device configuration. 
 **********************************************************************/

# define MASK(bit)               (1 << (bit))
# define CSS_IO_PARITY_ERROR    MASK(24) /* a parity error occured          */
# define CSS_IO_RX_OVERRUN      MASK(23) /* an rx overrun occured           */
# define CSS_IO_FRAMING_ERROR   MASK(22) /* a framing error occured         */
# define CSS_IO_TX_EMPTY        MASK(21) /* the tx buffer is empty          */
# define CSS_IO_RX_AVAILABLE    MASK(20) /* a character can be read         */
# define CSS_IO_TERMINAL_READY  MASK(19) /* a terminal is connected         */
# define CSS_IO_BREAK           MASK(17) /* a break condition occurred      */

/**********************************************************************
 * The following structures are used in the time and date functions 
 * Get_time(), Set_time(), Get_date(), and Set_date()
 **********************************************************************/

typedef struct css_time {
  uint32 hours;          /* 0 to 23 or 0 to 11, depending on mode_12hr */
  uint32 minutes;        /* 0 to 59 */
  uint32 seconds;        /* 0 to 59 */
  uint32 hundredths;     /* 0 to 99 */
  uint32 mode_12hr;      /* TRUE if 12 hour mode */
} css_time_struct;


typedef struct css_date {
  uint32 year;           /* 0 to 99 */
  uint32 month;          /* 1 to 12 */
  uint32 day;            /* 1 to 31 */
  uint32 week_day;       /* 0 to 6  */
} css_date_struct;


/**********************************************************************
 * The following structure is used in the interrupt map functions 
 * Get_int_map(), Set_int_map()
 **********************************************************************/

typedef struct css_int_map {
  uint8 acfail_level;
  uint8 sysfail_level;
  uint8 watchdog_level;
  uint8 bi_level;
  uint8 lm_level;
  uint8 tick_level;
  uint8 darf_level;
  uint8 ram_parity_level;
} css_int_map_struct;


/**********************************************************************
 * The following defines are used to specify the item size in the
 * Fill_memory() service
 **********************************************************************/

#define CSS_BYTE  ((uint32) 0)
#define CSS_WORD  ((uint32) 1)
#define CSS_LONG  ((uint32) 2)

/**********************************************************************
 * The following structure represents the layout of the serial EEPROM
 * on a card.
 **********************************************************************/

typedef struct css_seeprom {
  uint32 signature;              /* 0xFEDCBA99 if contents valid      */
  uint8  checksum_array[8];      /* array of 8 checksums              */
  uint8  es_key;                 /* used to construct key for ES      */
  uint8  aid_bypass;             /* use this as card ID if not 0xff   */
  uint8  aid_xlate[32];          /* auto-ID translation table         */
  uint32 *ssp_table;             /* system startup program table ptr  */
  uint32 sld_lmt[20];            /* sld location monitor addr table   */
  uint8  reserved[126];          /* reserved for foundation firmware  */
} css_seeprom_struct;

#define CSS_VALID_SEEPROM_SIGNATURE 0xfedcba99
#define CSS_SEEPROM_SIZE 512


/**********************************************************************
 * The following structure describes the layout of the card services 
 * jump table. 
 **********************************************************************/

typedef struct css_jump_table {
    void    (*init_card)( void );
    uint32  (*get_cpu_type)( void );
    uint32  (*get_cpu_speed)( void );
    uint32  (*get_sr)( void );
    void    (*set_sr)( uint32 value );
    uint32  (*get_vbr)( void );
    void    (*set_vbr)( uint32 vbr_value );
    uint32  (*get_cacr)( void );
    void    (*set_cacr)( uint32 value );
    boolean (*fpp_sense)( void );
    uint32  (*reserved1[5])( void );
    int     (*fprintf)( uint32 dev, char *format_string, ... );
    int     (*fscanf)( uint32 dev, char *format_string, ... );
    int     (*printf)( char *format_string, ... );
    int     (*scanf)( char *format_string, ... );
    int     (*sprintf)( char *address, char *format_string, ... );
    int     (*sscanf)( char *address, char *format_string, ... );
    void    (*putc)( uint32 dev, int character );
    int     (*getc)( uint32 dev );
    void    (*ungetc)( uint32 dev, int character );
    void    (*get_io_config)( uint32 dev, void *config_info );
    void    (*set_io_config)( uint32 dev, void *config_info );
    void    (*install_io_device)( uint32 dev,
                uint32 (*set_config_fn)( uint32 dev, void *config_info ),
                uint32 (*get_config_fn)( uint32 dev, void *config_info ),
                uint32 (*iostat_fn)( uint32 dev ),
                uint32 (*putc_fn)( uint32 dev, uint32 c ),
                uint32 (*getc_fn)( uint32 dev, uint32 *c ),
                uint32 (*ungetc_fn)( uint32 dev, uint32 c ),
                uint32 (*getline_fn)( uint32 dev, uint8 *buffer ) );
    uint32  (*io_status)( uint32 dev );
    uint32  (*reserved2[4])( void );
    void    (*control_bi_line)( uint32 opcode );
    void    (*control_watchdog)( uint32 opcode );
    void    (*reset_system)( void );
    uint32  (*read_lm_fifo)( void );
    uint32  (*get_sys_id)( void );
    void    (*get_card_type)( uint32 *form, uint32 *type, uint32 *css_variant);
    uint32  (*reserved_3)( void );
    void    (*set_leds)( uint32 selected_mask, uint32 illuminated_mask );
    uint32  (*get_switches)( void );
    boolean (*get_status)( uint32 opcode );
    void    (*set_status)( uint32 opcode, boolean status );
    void    (*set_tick_rate)( int rate );
    void    (*get_local_map)( css_local_map_struct *map );
    void    (*get_vme_map)( css_vme_map_struct *map );
    void    (*set_vme_map)( uint32 selection_mask, css_vme_map_struct *map );
    int     (*get_vme_int_status)( void );
    uint32  (*reserved4[3])( void );
    void    (*write_eeprom)( uint8 *address, uint8 data );
    uint8   (*read_serial_eeprom)( int address );
    void    (*write_serial_eeprom)( int address, uint8 data, boolean csum );
    uint32  (*reserved5[4])( void );
    void    (*enable_int)( uint32 interrupt_id, boolean enable_flag );
    void    (*clear_int)( uint32 interrupt_id );
    boolean (*get_int_status)( uint32 int_id );
    void    (*enable_vme_ints)( int level, boolean enable_flag );
    void    (*generate_vme_int)( int level, int vector );
    void    (*get_int_map)( css_int_map_struct *mask );
    void    (*set_int_map)( uint32 int_mask, css_int_map_struct *int_map );
    uint32  (*reserved6[4])( void );
    boolean (*push_mark)( uint32 mark_type, css_mark_struct *context );
    uint32  (*pop_mark)( uint32 mark_type );
    uint32  (*call_mark)( uint32 mark_type, css_mark_struct *save,
                          void (*function)() );
    uint32  (*goto_mark)( uint32 mark_type, ... );
    void    (*get_mark_stack)( css_mark_struct ***mark_stack );
    void    (*set_mark_stack)( css_mark_struct **mark_stack );
    void    (*init_mark_evt)( uint32 *vector_ptr );
    uint32  (*reserved7[2])( void );
    uint32  (*calculate_checksum)( uint16 *start, int length );
    uint32  (*calculate_crc)( uint16 *start, int length );
    void    (*copy_memory)( void *source, void *destination, int length );
    void    (*fill_memory)( void *destination, int length, uint32 value,
                            uint32 type );
    void    (*wait)( int duration );
    void    (*get_time)( css_time_struct *time );
    void    (*set_time)( css_time_struct *time );
    void    (*get_date)( css_date_struct *date );
    void    (*set_date)( css_date_struct *date );
    uint32  (*get_error)( void );
    uint32  (*reserved8[39])( void );
    uint32  (*null_service)( void );
} css_jump_table_struct;


/**********************************************************************
 * The following defines can be used to call a service in the same  
 * manner as a normal C function, as described in section 2 example 3
 * of the User's Manual.
 * NOTE: The variable "R_Css_jump_table" MUST be defined in the application
 *       and initialized to point to the base of the CSS jump table.
 *       This table is typically at the base of the ROM plus 1 Kbyte.
 *       eg: css_jump_table_struct *W_Css_jump_table = BASE_OF_ROM + 0x400;
 *       Refer to the Execution Sequencer CIT or Programmer's Reference
 *       for exact address.
 **********************************************************************/

extern css_jump_table_struct      *W_Css_jump_table; 

# define Init_card                (*W_Css_jump_table->init_card)
# define Get_cpu_type             (*W_Css_jump_table->get_cpu_type)
# define Get_cpu_speed            (*W_Css_jump_table->get_cpu_speed)
# define Get_sr                   (*W_Css_jump_table->get_sr)
# define Set_sr                   (*W_Css_jump_table->set_sr)
# define Get_vbr                  (*W_Css_jump_table->get_vbr)
# define Set_vbr                  (*W_Css_jump_table->set_vbr)
# define Get_cacr                 (*W_Css_jump_table->get_cacr)
# define Set_cacr                 (*W_Css_jump_table->set_cacr)
# define Fpp_sense                (*W_Css_jump_table->fpp_sense)

/*MBARI-IFREMER ### This part of software is not provided with our card
 * # define Fprintf                  (*W_Css_jump_table->fprintf)
 * # define Fscanf                   (*W_Css_jump_table->fscanf)
 * # define Printf                   (*W_Css_jump_table->printf)
 * # define Scanf                    (*W_Css_jump_table->scanf)
 * # define Sprintf                  (*W_Css_jump_table->sprintf)
 * # define Sscanf                   (*W_Css_jump_table->sscanf)
 * # define Putc                     (*W_Css_jump_table->putc)
 * # define Getc                     (*W_Css_jump_table->getc)
 * # define Ungetc                   (*W_Css_jump_table->ungetc)
 *ENDMBARI-IFREMER*/
/*MBARI-IFREMER ### They are replaced by those : */
# define Fprintf                  fprintf
# define Fscanf                   fscanf
# define Printf                   printf
# define Scanf                    scanf
# define Sprintf                  sprintf
# define Sscanf                   sscanf
# define Putc                     putc
# define Getc                     getc
# define Getchar                  getchar
# define Ungetc                   ungetc
/*ENDMBARI-IFREMER*/


# define Get_io_config            (*W_Css_jump_table->get_io_config)
# define Set_io_config            (*W_Css_jump_table->set_io_config)
# define Install_io_device        (*W_Css_jump_table->install_io_device)
# define Io_status                (*W_Css_jump_table->io_status)
# define Control_bi_line          (*W_Css_jump_table->control_bi_line)
# define Control_watchdog         (*W_Css_jump_table->control_watchdog)
# define Reset_system             (*W_Css_jump_table->reset_system)
# define Read_lm_fifo             (*W_Css_jump_table->read_lm_fifo)
# define Get_sys_id               (*W_Css_jump_table->get_sys_id)
# define Get_card_type            (*W_Css_jump_table->get_card_type)
# define Set_leds                 (*W_Css_jump_table->set_leds)
# define Get_switches             (*W_Css_jump_table->get_switches)
# define Get_status               (*W_Css_jump_table->get_status)
# define Set_status               (*W_Css_jump_table->set_status)
# define Set_tick_rate            (*W_Css_jump_table->set_tick_rate)
# define Get_local_map            (*W_Css_jump_table->get_local_map)
# define Get_vme_map              (*W_Css_jump_table->get_vme_map)
# define Set_vme_map              (*W_Css_jump_table->set_vme_map)
# define Get_vme_int_status       (*W_Css_jump_table->get_vme_int_status)
# define Write_eeprom             (*W_Css_jump_table->write_eeprom)
# define Read_serial_eeprom       (*W_Css_jump_table->read_serial_eeprom)
# define Write_serial_eeprom      (*W_Css_jump_table->write_serial_eeprom)
# define Enable_int               (*W_Css_jump_table->enable_int)
# define Clear_int                (*W_Css_jump_table->clear_int)
# define Get_int_status           (*W_Css_jump_table->get_int_status)
# define Enable_vme_ints          (*W_Css_jump_table->enable_vme_ints)
# define Generate_vme_int         (*W_Css_jump_table->generate_vme_int)
# define Get_int_map              (*W_Css_jump_table->get_int_map)
# define Set_int_map              (*W_Css_jump_table->set_int_map)
# define Push_mark                (*W_Css_jump_table->push_mark)
# define Pop_mark                 (*W_Css_jump_table->pop_mark)
# define Call_mark                (*W_Css_jump_table->call_mark)
# define Goto_mark                (*W_Css_jump_table->goto_mark)
# define Get_mark_stack           (*W_Css_jump_table->get_mark_stack)
# define Set_mark_stack           (*W_Css_jump_table->set_mark_stack)
# define Init_mark_evt            (*W_Css_jump_table->init_mark_evt)
# define Calculate_checksum       (*W_Css_jump_table->calculate_checksum)
# define Calculate_crc            (*W_Css_jump_table->calculate_crc)
# define Copy_memory              (*W_Css_jump_table->copy_memory)
# define Fill_memory              (*W_Css_jump_table->fill_memory)


/*MBARI-IFREMER ### This part of software is not provided with our card
 * # define Wait                     (*W_Css_jump_table->wait)
 * # define Get_time                 (*W_Css_jump_table->get_time)
 * # define Set_time                 (*W_Css_jump_table->set_time)
 * # define Get_date                 (*W_Css_jump_table->get_date)
 * # define Set_date                 (*W_Css_jump_table->set_date)
 * # define Get_error                (*W_Css_jump_table->get_error)
 * # define Null_service             (*W_Css_jump_table->null_service)
 *ENDMBARI-IFREMER*/
/*MBARI-IFREMER ### They are replaced by those : */
# define Wait                     NULL
/*ENDMBARI-IFREMER*/

/* End of file */
