From f3316074e9d6f9f93318ac52587e193723719f3a Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Fri, 2 Dec 2011 17:18:16 -0300 Subject: [PATCH] m1/patches/rtems: added milkymist-midi-opt.patch Optimizes MIDI processing. --- m1/patches/rtems/milkymist-midi-opt.patch | 56 +++++++++++++++++++++++ m1/patches/rtems/series | 1 + 2 files changed, 57 insertions(+) create mode 100644 m1/patches/rtems/milkymist-midi-opt.patch diff --git a/m1/patches/rtems/milkymist-midi-opt.patch b/m1/patches/rtems/milkymist-midi-opt.patch new file mode 100644 index 0000000..4bf5544 --- /dev/null +++ b/m1/patches/rtems/milkymist-midi-opt.patch @@ -0,0 +1,56 @@ +This patch moves MIDI message detection from higher layers to the MIDI +interrupt handler. This way, MIDI receivers only need to wake up once +per complete message and not for every single byte. + +The /dev/midi queue size is changed from 64 bytes to 32 messages +(typically 3 bytes each). + +Index: rtems/c/src/lib/libbsp/lm32/shared/milkymist_midi/midi.c +=================================================================== +--- rtems.orig/c/src/lib/libbsp/lm32/shared/milkymist_midi/midi.c 2011-12-01 19:45:37.000000000 -0300 ++++ rtems/c/src/lib/libbsp/lm32/shared/milkymist_midi/midi.c 2011-12-02 16:05:30.000000000 -0300 +@@ -26,6 +26,8 @@ + #define DEVICE_NAME "/dev/midi" + + static rtems_id midi_q; ++static unsigned char *midi_p = NULL; ++static unsigned char midi_msg[3]; + + static rtems_isr interrupt_handler(rtems_vector_number n) + { +@@ -34,7 +36,23 @@ + while (MM_READ(MM_MIDI_STAT) & MIDI_STAT_RX_EVT) { + msg = MM_READ(MM_MIDI_RXTX); + MM_WRITE(MM_MIDI_STAT, MIDI_STAT_RX_EVT); +- rtems_message_queue_send(midi_q, &msg, 1); ++ ++ if ((msg & 0xf8) == 0xf8) ++ continue; /* ignore system real-time */ ++ ++ if (msg & 0x80) ++ midi_p = midi_msg; /* status byte */ ++ ++ if (!midi_p) ++ continue; /* ignore extra or unsynchronized data */ ++ ++ *midi_p++ = msg; ++ ++ if (midi_p == midi_msg+3) { ++ /* received a complete MIDI message */ ++ rtems_message_queue_send(midi_q, midi_msg, 3); ++ midi_p = NULL; ++ } + } + lm32_interrupt_ack(1 << MM_IRQ_MIDI); + } +@@ -53,8 +71,8 @@ + + sc = rtems_message_queue_create( + rtems_build_name('M', 'I', 'D', 'I'), +- 64, +- 1, ++ 32, ++ 3, + 0, + &midi_q + ); diff --git a/m1/patches/rtems/series b/m1/patches/rtems/series index 12bb962..460c5a4 100644 --- a/m1/patches/rtems/series +++ b/m1/patches/rtems/series @@ -15,3 +15,4 @@ # milkymist-videoformat.patch - applied 2011-11-27 #fix-timer-includes.patch milkymist-usb-midi.patch +milkymist-midi-opt.patch