xref: /freebsd/contrib/ntp/kernel/sys/bsd_audioirig.h (revision aca5021d5f7dcab1e11692923266373e35322d9a)
1 /*
2  *	$Header: bsd_audioirig.h,v 1.0 93/08/02 12:42:00
3  */
4 
5 #ifndef _BSD_AUDIOIRIG_H_
6 #define _BSD_AUDIOIRIG_H_
7 
8 #include <sys/time.h>
9 
10 /********************************************************************/
11 /* user interface */
12 
13 /*
14  * irig ioctls
15  */
16 #if defined(__STDC__) || (!defined(sun) && !defined(ibm032) && !defined(__GNUC))
17 #define AUDIO_IRIG_OPEN         _IO('A', 50)
18 #define AUDIO_IRIG_CLOSE        _IO('A', 51)
19 #define AUDIO_IRIG_SETFORMAT    _IOWR('A', 52, int)
20 #else
21 #define AUDIO_IRIG_OPEN         _IO(A, 50)
22 #define AUDIO_IRIG_CLOSE        _IO(A, 51)
23 #define AUDIO_IRIG_SETFORMAT    _IOWR(A, 52, int)
24 #endif
25 
26 /*
27  * irig error codes
28  */
29 #define AUDIO_IRIG_BADSIGNAL	0x01
30 #define AUDIO_IRIG_BADDATA	0x02
31 #define AUDIO_IRIG_BADSYNC	0x04
32 #define AUDIO_IRIG_BADCLOCK	0x08
33 #define AUDIO_IRIG_OLDDATA	0x10
34 
35 /********************************************************************/
36 
37 /*
38  * auib definitions
39  */
40 #define AUIB_SIZE	(0x0040)
41 #define AUIB_INC	(0x0008)
42 #define AUIB_MOD(k)	((k) & 0x0038)
43 #define AUIB_INIT(ib)	((ib)->ib_head = (ib)->ib_tail = (ib)->ib_lock = \
44 			 (ib)->phase = (ib)->shi = (ib)->slo = (ib)->high = \
45 			 (ib)->level0 = (ib)->level1 = \
46 			 (ib)->shift[0] = (ib)->shift[1] = (ib)->shift[2] = \
47 			 (ib)->shift[3] = (ib)->sdata[0] = (ib)->sdata[1] = \
48 			 (ib)->sdata[2] = (ib)->sdata[3] = (ib)->err = 0)
49 #define AUIB_EMPTY(ib)	((ib)->ib_head == (ib)->ib_tail)
50 #define AUIB_LEN(ib)	(AUIB_MOD((ib)->ib_tail - (ib)->ib_head))
51 #define AUIB_LEFT(ib)	(AUIB_MOD((ib)->ib_head - (ib)->ib_tail - 1))
52 #define IRIGDELAY 3
53 #define IRIGLEVEL 1355
54 
55 #ifndef LOCORE
56 /*
57  * irig_time holds IRIG data for one second
58  */
59 struct irig_time {
60         struct timeval  stamp;          /* timestamp */
61         u_char  bits[13];               /* 100 irig data bits */
62 	u_char	status;			/* status byte */
63         char    time[14];               /* time string */
64 };
65 
66 /*
67  * auib's are used for IRIG data communication between the trap
68  * handler and the software interrupt.
69  */
70 struct auib {
71 	/* driver variables */
72 	u_short	active;			/* 0=inactive, else=active */
73 	u_short	format;			/* time output format */
74 	struct	irig_time timestr;	/* time structure */
75 	char	buffer[14];		/* output formation buffer */
76 
77 	/* hardware interrupt variables */
78 	struct	timeval tv1,tv2,tv3;	/* time stamps (median filter) */
79 	int	level0,level1;		/* lo/hi input levels */
80 	int	level;			/* decision level */
81 	int	high;			/* recent largest sample */
82 	int	sl0,sl1;		/* recent sample levels */
83 	int	lasts;			/* last sample value */
84 	u_short	scount;			/* sample count */
85 	u_long	eacc;			/* 10-bit element accumulator */
86 	u_long	ebit;			/* current bit in element */
87 	u_char	r_level,mmr1;		/* recording level 0-255 */
88 	int	shi,slo,phase;		/* AGC variables */
89 	u_long	err;			/* error status bits */
90 	int	ecount;			/* count of elements this second */
91 	long	shift[4];		/* shift register of pos ident */
92 	long	sdata[4];		/* shift register of symbols */
93 
94 	int	ib_head;		/* queue head */
95 	int	ib_tail;		/* queue tail */
96 	u_short	ib_lock;		/* queue head lock */
97 	u_long	ib_data[AUIB_SIZE];	/* data buffer */
98 };
99 #endif
100 
101 #endif /* _BSD_AUDIOIRIG_H_ */
102