midivar.h 2.6 KB

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