1 /* $OpenBSD: midivar.h,v 1.7 2013/03/15 09:10:52 ratchov Exp $ */ 2 3 /* 4 * Copyright (c) 2003, 2004 Alexandre Ratchov 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #ifndef _SYS_DEV_MIDIVAR_H_ 20 #define _SYS_DEV_MIDIVAR_H_ 21 22 #include <dev/midi_if.h> 23 #include <sys/device.h> 24 #include <sys/selinfo.h> 25 #include <sys/proc.h> 26 #include <sys/timeout.h> 27 28 #define MIDI_MAXWRITE 32 /* max bytes to give to the uart at once */ 29 #define MIDI_RATE 3125 /* midi uart baud rate in bytes/second */ 30 #define MIDI_UNIT(a) ((a) & 0xff) 31 #define MIDI_DEV2SC(a) (midi_cd.cd_devs[MIDI_UNIT(a)]) 32 33 /* 34 * simple ring buffer 35 */ 36 #define MIDIBUF_SIZE (1 << 10) 37 #define MIDIBUF_MASK (MIDIBUF_SIZE - 1) 38 struct midi_buffer { 39 unsigned char data[MIDIBUF_SIZE]; 40 unsigned start, used; 41 }; 42 #define MIDIBUF_START(buf) ((buf)->start) 43 #define MIDIBUF_END(buf) (((buf)->start + (buf)->used) & MIDIBUF_MASK) 44 #define MIDIBUF_USED(buf) ((buf)->used) 45 #define MIDIBUF_AVAIL(buf) (MIDIBUF_SIZE - (buf)->used) 46 #define MIDIBUF_ISFULL(buf) ((buf)->used >= MIDIBUF_SIZE) 47 #define MIDIBUF_ISEMPTY(buf) ((buf)->used == 0) 48 #define MIDIBUF_WRITE(buf, byte) \ 49 do { \ 50 (buf)->data[MIDIBUF_END(buf)] = (byte); \ 51 (buf)->used++; \ 52 } while(0) 53 #define MIDIBUF_READ(buf, byte) \ 54 do { \ 55 (byte) = (buf)->data[(buf)->start++]; \ 56 (buf)->start &= MIDIBUF_MASK; \ 57 (buf)->used--; \ 58 } while(0) 59 #define MIDIBUF_REMOVE(buf, count) \ 60 do { \ 61 (buf)->start += (count); \ 62 (buf)->start &= MIDIBUF_MASK; \ 63 (buf)->used -= (count); \ 64 } while(0) 65 #define MIDIBUF_INIT(buf) \ 66 do { \ 67 (buf)->start = (buf)->used = 0; \ 68 } while(0) 69 70 71 struct midi_softc { 72 struct device dev; 73 struct midi_hw_if *hw_if; 74 void *hw_hdl; 75 int isopen; 76 int isbusy; /* concerns only the output */ 77 int isdying; 78 int flags; /* open flags */ 79 int props; /* midi hw proprieties */ 80 int rchan; 81 int wchan; 82 struct selinfo rsel; 83 struct selinfo wsel; 84 struct proc *async; 85 struct timeout timeo; 86 struct midi_buffer inbuf; 87 struct midi_buffer outbuf; 88 }; 89 90 #endif /* _SYS_DEV_MIDIVAR_H_ */ 91