1 /* $OpenBSD: midivar.h,v 1.14 2023/09/26 19:55:24 mvs 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/event.h> 25 #include <sys/proc.h> 26 #include <sys/timeout.h> 27 28 #define MIDI_RATE 3125 /* midi uart baud rate in bytes/second */ 29 30 /* 31 * simple ring buffer 32 */ 33 #define MIDIBUF_SIZE (1 << 10) 34 #define MIDIBUF_MASK (MIDIBUF_SIZE - 1) 35 36 struct midi_buffer { 37 struct klist klist; /* to record & wakeup poll(2) */ 38 int blocking; /* read/write blocking */ 39 unsigned char data[MIDIBUF_SIZE]; 40 unsigned start, used; 41 }; 42 43 #define MIDIBUF_START(buf) ((buf)->start) 44 #define MIDIBUF_END(buf) (((buf)->start + (buf)->used) & MIDIBUF_MASK) 45 #define MIDIBUF_USED(buf) ((buf)->used) 46 #define MIDIBUF_AVAIL(buf) (MIDIBUF_SIZE - (buf)->used) 47 #define MIDIBUF_ISFULL(buf) ((buf)->used >= MIDIBUF_SIZE) 48 #define MIDIBUF_ISEMPTY(buf) ((buf)->used == 0) 49 #define MIDIBUF_WRITE(buf, byte) \ 50 do { \ 51 (buf)->data[MIDIBUF_END(buf)] = (byte); \ 52 (buf)->used++; \ 53 } while(0) 54 #define MIDIBUF_READ(buf, byte) \ 55 do { \ 56 (byte) = (buf)->data[(buf)->start++]; \ 57 (buf)->start &= MIDIBUF_MASK; \ 58 (buf)->used--; \ 59 } while(0) 60 #define MIDIBUF_REMOVE(buf, count) \ 61 do { \ 62 (buf)->start += (count); \ 63 (buf)->start &= MIDIBUF_MASK; \ 64 (buf)->used -= (count); \ 65 } while(0) 66 #define MIDIBUF_INIT(buf) \ 67 do { \ 68 (buf)->start = (buf)->used = 0; \ 69 } while(0) 70 71 72 struct midi_softc { 73 struct device dev; 74 const struct midi_hw_if *hw_if; 75 void *hw_hdl; 76 int isbusy; /* concerns only the output */ 77 int flags; /* open flags */ 78 int props; /* midi hw proprieties */ 79 struct timeout timeo; 80 struct midi_buffer inbuf; 81 struct midi_buffer outbuf; 82 }; 83 84 #endif /* _SYS_DEV_MIDIVAR_H_ */ 85