Home | History | Annotate | Line # | Download | only in dev
midivar.h revision 1.11.14.6
      1 /*	$NetBSD: midivar.h,v 1.11.14.6 2006/05/20 03:16:48 chap Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Lennart Augustsson (augustss (at) NetBSD.org).
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #ifndef _SYS_DEV_MIDIVAR_H_
     40 #define _SYS_DEV_MIDIVAR_H_
     41 
     42 #define MIDI_BUFSIZE 1024
     43 
     44 #include "sequencer.h"
     45 
     46 #include <sys/callout.h>
     47 #include <sys/device.h>
     48 #include <sys/lock.h>
     49 
     50 struct midi_buffer {
     51 	u_char	*inp;
     52 	u_char	*outp;
     53 	u_char	*end;
     54 	int	used;
     55 	int	usedhigh;
     56 	u_char	start[MIDI_BUFSIZE];
     57 };
     58 
     59 #define MIDI_MAX_WRITE 32	/* max bytes written with busy wait */
     60 #define MIDI_WAIT 10000		/* microseconds to wait after busy wait */
     61 
     62 struct midi_state {
     63 	struct  evcnt bytesDiscarded;
     64 	struct  evcnt incompleteMessages;
     65 	int     state;
     66 	u_char *pos;
     67 	u_char *end;
     68 	u_char  msg[3];
     69 };
     70 
     71 struct midi_softc {
     72 	struct	device dev;
     73 	void	*hw_hdl;	/* Hardware driver handle */
     74 	struct	midi_hw_if *hw_if; /* Hardware interface */
     75 	struct	device *sc_dev;	/* Hardware device struct */
     76 	int	isopen;		/* Open indicator */
     77 	int	flags;		/* Open flags */
     78 	int	dying;
     79 	struct	midi_buffer outbuf;
     80 	struct	midi_buffer inbuf;
     81 	int	props;
     82 	int	rchan, wchan;
     83 	struct  simplelock out_lock; /* overkill or no? */
     84 	int     hw_interrupted;
     85 	int	pbus;
     86 	struct	selinfo wsel;	/* write selector */
     87 	struct	selinfo rsel;	/* read selector */
     88 	struct	proc *async;	/* process who wants audio SIGIO */
     89 
     90 	struct callout sc_callout;
     91 
     92 	/* MIDI input state machine; states are *s of 4 to allow | CAT bits */
     93 	struct midi_state rcv;
     94 	struct midi_state xmt;
     95 #define MIDI_IN_START	0
     96 #define MIDI_IN_RUN0_1	4
     97 #define MIDI_IN_RUN1_1	8
     98 #define MIDI_IN_RUN0_2 12
     99 #define MIDI_IN_RUN1_2 16
    100 #define MIDI_IN_RUN2_2 20
    101 #define MIDI_IN_COM0_1 24
    102 #define MIDI_IN_COM0_2 28
    103 #define MIDI_IN_COM1_2 32
    104 #define MIDI_IN_SYX1_3 36
    105 #define MIDI_IN_SYX2_3 40
    106 #define MIDI_IN_SYX0_3 44
    107 #define MIDI_IN_RNX0_1 48
    108 #define MIDI_IN_RNX0_2 52
    109 #define MIDI_IN_RNX1_2 56
    110 #define MIDI_IN_RNY1_2 60 /* not needed except for accurate error counts */
    111 
    112 #define MIDI_CAT_DATA 0
    113 #define MIDI_CAT_STATUS1 1
    114 #define MIDI_CAT_STATUS2 2
    115 #define MIDI_CAT_COMMON 3
    116 
    117 #if NSEQUENCER > 0
    118 	/* Synthesizer emulation stuff */
    119 	int	seqopen;
    120 	struct	midi_dev *seq_md; /* structure that links us with the seq. */
    121 #endif
    122 };
    123 
    124 #define MIDIUNIT(d) ((d) & 0xff)
    125 
    126 #endif /* _SYS_DEV_MIDIVAR_H_ */
    127