File:  [NeXTSTEP 3.3 examples] / Examples / DriverKit / Adaptec1542B / Adaptec1542B_reloc.tproj / AHAInline.h
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:49:02 2018 UTC (8 years, 1 month ago) by root
Branches: NeXT, MAIN
CVS tags: NeXTSTEP33, HEAD
Sample Programs from NeXSTEP 3.3

/*
 * Copyright (c) 1992 NeXT Computer, Inc.
 *
 * Adaptec AHA-1542 SCSI controller inline functions.
 *
 * HISTORY
 *
 * 12 July 1992 David E. Bohman at NeXT
 *	Created.
 */

#import <driverkit/i386/ioPorts.h>

/*
 * Primitives to access the
 * board registers.
 */

static inline
void
aha_put_ctrl(
    unsigned short	base,
    aha_ctrl_reg_t	reg
)
{
    union {
	aha_ctrl_reg_t		reg;
	unsigned char		data;
    } tconv;
    
    tconv.reg = reg;

    outb(base + AHA_CTRL_REG_OFF, tconv.data);
}

static inline
aha_stat_reg_t
aha_get_stat(
    unsigned short	base
)
{
    union {
	aha_stat_reg_t		reg;
	unsigned char		data;
    } tconv;

    tconv.data = inb(base + AHA_STAT_REG_OFF);

    return (tconv.reg);
}

static inline
aha_intr_reg_t
aha_get_intr(
    unsigned short	base
)
{
    union {
	aha_intr_reg_t		reg;
	unsigned char		data;
    } tconv;

    tconv.data = inb(base + AHA_INTR_REG_OFF);

    return (tconv.reg);
}

static inline
void
aha_put_cmd(
    unsigned short	base,
    aha_cmd_reg_t	reg
)
{
    outb(base + AHA_CMD_REG_OFF, reg);
}

static inline
aha_cmd_reg_t
aha_get_cmd(
    unsigned short	base
)
{
    return (inb(base + AHA_CMD_REG_OFF));
}

/*
 * Functions built on top
 * of the primatives above.
 */

static inline
void
aha_clr_intr(
    unsigned short	base
)
{
    aha_ctrl_reg_t	ctrl = { 0 };

    ctrl.intr_clr = 1;

    aha_put_ctrl(base, ctrl);
}


static inline
boolean_t
aha_await_datain(
    IOEISAPortAddress	base,
    unsigned int	how_long
)
{
    aha_stat_reg_t	stat;
 
    do {
    	stat = aha_get_stat(base);
    } while (!stat.datain_full && how_long--);
    return how_long;
}


static inline
boolean_t
aha_get_bytes(
    IOEISAPortAddress	base,
    unsigned char	*addr,
    unsigned int	length
)
{
    while (length--) {
    	if (!aha_await_datain(base, 1000))
		return FALSE;
    	*addr++ = inb(base);
    }
    return TRUE;
}


/*
 *  24-bit accessor functions (with byte swapping)
 */
static inline void
aha_put_24(unsigned int source, volatile unsigned char *dest)
{
	dest[2] = source & 0xff;
	dest[1] = (source >> 8) & 0xff;
	dest[0] = (source >> 16) & 0xff;
}


static inline unsigned int
aha_get_24(volatile unsigned char *source)
{
	return (source[0] << 16) | (source[1] << 8) | source[2];
}



unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.