/*
 * ( from "stgdefs.h" by ServoToGo )
 *
 */

typedef union
{
    unsigned short                          Word;
    struct   {unsigned char    high, low;}  Byte;
} STG_WORDBYTE;


// software direction bit definitions
#define STG_PORT_A_OUT		0x01
#define STG_PORT_B_OUT		0x02
#define STG_PORT_C_LO_OUT	0x04
#define STG_PORT_C_HI_OUT	0x08
#define STG_PORT_C_OUT		(STG_PORT_C_LO_OUT | STG_PORT_C_HI_OUT)
#define STG_PORT_D_LO_OUT	0x10
#define STG_PORT_D_HI_OUT	0x20
#define STG_PORT_D_OUT		(STG_PORT_D_LO_OUT | STG_PORT_D_HI_OUT)
#define STG_PORT_INPUT		0
#define STG_PORT_OUTPUT		1

// hardware direction bit definitions
#define STG_A_DIR      0x10
#define STG_B_DIR      0x02
#define STG_C_LOW_DIR  0x01
#define STG_C_HI_DIR   0x08
#define STG_D_DIR      0x10
#define STG_D_LOW_DIR  0x01
#define STG_D_HI_DIR   0x08

/* parameters to the SelectInterruptPeriod Command */
#define STG_500_MICROSECONDS        500
#define STG_1_MILLISECOND           1000
#define STG_2_MILLISECONDS          2000
#define STG_3_MILLISECONDS          3000
#define STG_4_MILLISECONDS          4000
#define STG_5_MILLISECONDS          5000
#define STG_10_MILLISECONDS         10000
#define STG_100_MILLISECONDS        100000L
#define STG_1_SECOND                1000000L
#define STG_MAX_PERIOD               -1L

#define STG_NO_BOARD       1
#define STG_BOARD_PRESENT  0

#define STG_MODEL1         1
#define STG_MODEL2         2


/*
 * ( from "stgoffsets.h" by ServoToGo )
 *
 * Define offsets for various registers on Servo To Go, Inc. Servo I/O card.
 *
 * Copyright (c) 1995, 1998 Servo To Go, Inc.
 * 1716  221st PL NE
 * Redmond, WA  98053
 *
 * For registers in the "high page", an offset of 0x400 is included.
 */
#define STG_CNT0_D     0x00
#define STG_CNT1_D     0x01
#define STG_CNT0_C     0x02
#define STG_CNT1_C     0x03
#define STG_CNT2_D     0x04
#define STG_CNT3_D     0x05
#define STG_CNT2_C     0x06
#define STG_CNT3_C     0x07
#define STG_CNT4_D     0x08
#define STG_CNT5_D     0x09
#define STG_CNT4_C     0x0a
#define STG_CNT5_C     0x0b
#define STG_CNT6_D     0x0c
#define STG_CNT7_D     0x0d
#define STG_CNT6_C     0x0e
#define STG_CNT7_C     0x0f
#define STG_DAC_0      0x10
#define STG_DAC_1      0x12
#define STG_DAC_2      0x14
#define STG_DAC_3      0x16
#define STG_DAC_4      0x18
#define STG_DAC_5      0x1a
#define STG_DAC_6      0x1c
#define STG_DAC_7      0x1e
#define STG_ADC        0x410
#define STG_ADC_0      0x410
#define STG_ADC_1      0x412
#define STG_ADC_2      0x414
#define STG_ADC_3      0x416
#define STG_ADC_4      0x418
#define STG_ADC_5      0x41a
#define STG_ADC_6      0x41c
#define STG_ADC_7      0x41e
#define STG_CNTRL0     0x401     /* Model 2 */
#define STG_DIO_A      0x400     /* Model 1 */
#define STG_DIO_B      0x402     /* Model 1 */
#define STG_DIO_C      0x404     /* Model 1 */
#define STG_DIO_D      0x401     /* Model 1 */
#define STG_PORT_A     0x400     /* Model 2, replaces DIO_A */
#define STG_PORT_B     0x402     /* Model 2, replaces DIO_B */
#define STG_PORT_C     0x404     /* Model 2, replaces DIO_C */
#define STG_PORT_D     0x405     /* Model 2, replaces DIO_D */
#define STG_INTC       0x405     /* Model 1 */
#define STG_BRDTST     0x403
#define STG_MIO_1      0x406
#define STG_MIO_2      0x407
#define STG_ODDRST     0x407
#define STG_TIMER_0    0x408
#define STG_TIMER_1    0x40a
#define STG_TIMER_2    0x40c
#define STG_TMRCMD     0x40e
#define STG_ICW1       0x409
#define STG_ICW2       0x40b
#define STG_OCW1       0x40b
#define STG_OCW2       0x409
#define STG_OCW3       0x409
#define STG_IRR        0x409
#define STG_ISR        0x409
#define STG_IDLEN      0x409
#define STG_IMR        0x40b
#define STG_SELDI      0x40b
#define STG_IDL        0x40d
#define STG_CNTRL1     0x40f

/*
 * Some bit masks for various registers
 */
// for IRR, ISR, and IMR
#define STG_IXEVN      0x80
#define STG_IXODD      0x40
#define STG_LIXEVN     0x20
#define STG_LIXODD     0x10
#define STG_EOC        0x08
#define STG_TP0        0x04
#define STG_USR_INT    0x02
#define STG_TP2        0x01
// for INTC
#define STG_AUTOZERO   0x80
#define STG_IXLVL      0x40
#define STG_IXS1       0x20
#define STG_IXS0       0x10
#define STG_USRINT     0x08
#define STG_IA2        0x04
#define STG_IA1        0x02
#define STG_IA0        0x01

#define STG_CNTRL0_AZ   0x80
#define STG_CNTRL0_AD2  0x40
#define STG_CNTRL0_AD1  0x20
#define STG_CNTRL0_AD0  0x10
#define STG_CNTRL0_CAL  0x08
#define STG_CNTRL0_IA2  0x04
#define STG_CNTRL0_IA1  0x02
#define STG_CNTRL0_IA0  0x01

#define STG_CNTRL1_WDTOUT    0x80
#define STG_CNTRL1_INT_G2    0x40
#define STG_CNTRL1_INT_T2    0x20
#define STG_CNTRL1_INT_T0    0x10
#define STG_CNTRL1_SLAVE     0x08
#define STG_CNTRL1_IEN_G2    0x04
#define STG_CNTRL1_IEN_T2    0x02
#define STG_CNTRL1_IEN_T0    0x01

#define STG_BRDTST_EOC       0x08

/*
 * We're hardwired to irq 5 (sorry).  This is normally reserved for
 * lpt2, but most people don't have two printers.  Sometimes a modem,
 * sound card, etc. will be using this interrupt.  It would be easiest
 * to remove any offending card temporarily.  Otherwise you'll have
 * to figure out how to change the following define's.
 */
/*
#define STG_INTR 13              // irq5 is short 13 
#define STG_INT_MASK 0x20        // mask for motherboard interrupt controller
#define STG_IC_ADD   0x20        // address of the interrupt controller on your
                             // motherboard (NOT the one on the Servo To Go
                             // board).  For low numbered interrupts (0-7)
                             // it's 0x20, for higher numbered interrupts
                             // (8-15) it's 0xa0
#define STG_EOI_5    0x65        // Specific EOI for IRQ 5 (used with above)                             
#define STG_IC_MASK  0x21        // The interrupt mask register on your
                             // motherboard
*/

#define STG_IRQSL   0x84        // IRQ selection for INTC register
// end of irq related defines
