/*
 *	$Header: bsd_audioirig.h,v 1.0 93/08/02 12:42:00
 */

#ifndef _BSD_AUDIOIRIG_H_
#define _BSD_AUDIOIRIG_H_

#include <sys/time.h>

/*
 * auib definitions
 */
#define AUIB_SIZE	(0x0080)
#define AUIB_INC	(0x0010)
#define AUIB_MOD(k)	((k) & 0x0070)
#define AUIB_INIT(ib)	((ib)->ib_head = (ib)->ib_tail = (ib)->ib_lock = \
			 (ib)->gcount = (ib)->high = \
			 (ib)->phase = (ib)->shi = (ib)->slo = (ib)->err = \
			 (ib)->ecount = (ib)->level0 = (ib)->level1 = 0)
#define AUIB_EMPTY(ib)	((ib)->ib_head == (ib)->ib_tail)
#define AUIB_LEN(ib)	(AUIB_MOD((ib)->ib_tail - (ib)->ib_head))
#define AUIB_LEFT(ib)	(AUIB_MOD((ib)->ib_head - (ib)->ib_tail - 1))
#define IRIGDELAY 3
#define IRIGLEVEL 1355

/*
 * irig ioctls
 */
#if (defined(sun) || defined(ibm032)) && !defined(__GNUC__)
#define AUDIO_IRIG_OPEN         _IO(A, 50)
#define AUDIO_IRIG_CLOSE        _IO(A, 51)
#define AUDIO_IRIG_SETFORMAT    _IOWR(A, 52, int)
#else
#define AUDIO_IRIG_OPEN         _IO('A', 50)
#define AUDIO_IRIG_CLOSE        _IO('A', 51)
#define AUDIO_IRIG_SETFORMAT    _IOWR('A', 52, int)
#endif

#ifndef LOCORE
/*
 * irig_time holds IRIG data for one second
 */
struct irig_time {
        struct timeval  stamp;          /* timestamp */
        u_char  bits[14];               /* 100 irig data bits */
        char    time[14];               /* time string (null terminated) */
};

/*
 * auib's are used for IRIG data communication between the trap
 * handler and the software interrupt.
 */
struct auib {
	/* hardware interrupt variables */
	struct	timeval tv,ts;		/* time stamp */
	int	level0,level1;		/* lo/hi input levels */
	int	level;			/* decision level */
	int	high;			/* recent largest sample */
	int	sl0,sl1;		/* recent sample levels */
	int	lasts;			/* last sample value */
	u_short	scount;			/* sample count */
	u_long	eacc;			/* 10-bit element accumulator */
	u_long	ebit;			/* current bit in element */
	u_long	element;		/* current element group */
	u_long	laste;			/* last element type */
	u_short	ecount;			/* element count */
	u_short	gcount;			/* index into groups */
	u_char	r_level;		/* recording level 0-255 */
	int	shi,slo,phase;
	u_short	err;			/* error status bits */

	int	ib_head;		/* queue head */
	int	ib_tail;		/* queue tail */
	u_short	ib_lock;		/* queue head lock */
	u_short	ib_data[AUIB_SIZE];	/* data buffer */
	/* driver variables */
	short	active;			/* 0=inactive, else=active */
	short	format;			/* time output format */
	struct	irig_time timestr;	/* time structure */
	char	buffer[14];		/* output formation buffer */
};
#endif

#endif /* _BSD_AUDIOIRIG_H_ */
