1 /* $OpenBSD: midivar.h,v 1.9 2015/05/16 09:56:10 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 31 /* 32 * simple ring buffer 33 */ 34 #define MIDIBUF_SIZE (1 << 10) 35 #define MIDIBUF_MASK (MIDIBUF_SIZE - 1) 36 struct midi_buffer { 37 unsigned char data[MIDIBUF_SIZE]; 38 unsigned start, used; 39 }; 40 #define MIDIBUF_START(buf) ((buf)->start) 41 #define MIDIBUF_END(buf) (((buf)->start + (buf)->used) & MIDIBUF_MASK) 42 #define MIDIBUF_USED(buf) ((buf)->used) 43 #define MIDIBUF_AVAIL(buf) (MIDIBUF_SIZE - (buf)->used) 44 #define MIDIBUF_ISFULL(buf) ((buf)->used >= MIDIBUF_SIZE) 45 #define MIDIBUF_ISEMPTY(buf) ((buf)->used == 0) 46 #define MIDIBUF_WRITE(buf, byte) \ 47 do { \ 48 (buf)->data[MIDIBUF_END(buf)] = (byte); \ 49 (buf)->used++; \ 50 } while(0) 51 #define MIDIBUF_READ(buf, byte) \ 52 do { \ 53 (byte) = (buf)->data[(buf)->start++]; \ 54 (buf)->start &= MIDIBUF_MASK; \ 55 (buf)->used--; \ 56 } while(0) 57 #define MIDIBUF_REMOVE(buf, count) \ 58 do { \ 59 (buf)->start += (count); \ 60 (buf)->start &= MIDIBUF_MASK; \ 61 (buf)->used -= (count); \ 62 } while(0) 63 #define MIDIBUF_INIT(buf) \ 64 do { \ 65 (buf)->start = (buf)->used = 0; \ 66 } while(0) 67 68 69 struct midi_softc { 70 struct device dev; 71 struct midi_hw_if *hw_if; 72 void *hw_hdl; 73 int isbusy; /* concerns only the output */ 74 int flags; /* open flags */ 75 int props; /* midi hw proprieties */ 76 int rchan; 77 int wchan; 78 struct selinfo rsel; 79 struct selinfo wsel; 80 struct proc *async; 81 struct timeout timeo; 82 struct midi_buffer inbuf; 83 struct midi_buffer outbuf; 84 }; 85 86 #endif /* _SYS_DEV_MIDIVAR_H_ */ 87