jcs's openbsd hax
openbsd
1/* $OpenBSD: midivar.h,v 1.15 2024/10/14 00:47:36 jsg 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/timeout.h>
26
27#define MIDI_RATE 3125 /* midi uart baud rate in bytes/second */
28
29/*
30 * simple ring buffer
31 */
32#define MIDIBUF_SIZE (1 << 10)
33#define MIDIBUF_MASK (MIDIBUF_SIZE - 1)
34
35struct midi_buffer {
36 struct klist klist; /* to record & wakeup poll(2) */
37 int blocking; /* read/write blocking */
38 unsigned char data[MIDIBUF_SIZE];
39 unsigned start, used;
40};
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
71struct midi_softc {
72 struct device dev;
73 const struct midi_hw_if *hw_if;
74 void *hw_hdl;
75 int isbusy; /* concerns only the output */
76 int flags; /* open flags */
77 int props; /* midi hw proprieties */
78 struct timeout timeo;
79 struct midi_buffer inbuf;
80 struct midi_buffer outbuf;
81};
82
83#endif /* _SYS_DEV_MIDIVAR_H_ */