Root/m1/patches/rtems/milkymist-midi-opt.patch

1This patch moves MIDI message detection from higher layers to the MIDI
2interrupt handler. This way, MIDI receivers only need to wake up once
3per complete message and not for every single byte.
4
5The /dev/midi queue size is changed from 64 bytes to 32 messages
6(typically 3 bytes each).
7
8Index: rtems/c/src/lib/libbsp/lm32/shared/milkymist_midi/midi.c
9===================================================================
10--- rtems.orig/c/src/lib/libbsp/lm32/shared/milkymist_midi/midi.c 2011-12-01 19:45:37.000000000 -0300
11+++ rtems/c/src/lib/libbsp/lm32/shared/milkymist_midi/midi.c 2011-12-02 16:05:30.000000000 -0300
12@@ -26,6 +26,8 @@
13 #define DEVICE_NAME "/dev/midi"
14 
15 static rtems_id midi_q;
16+static unsigned char *midi_p = NULL;
17+static unsigned char midi_msg[3];
18 
19 static rtems_isr interrupt_handler(rtems_vector_number n)
20 {
21@@ -34,7 +36,23 @@
22   while (MM_READ(MM_MIDI_STAT) & MIDI_STAT_RX_EVT) {
23     msg = MM_READ(MM_MIDI_RXTX);
24     MM_WRITE(MM_MIDI_STAT, MIDI_STAT_RX_EVT);
25- rtems_message_queue_send(midi_q, &msg, 1);
26+
27+ if ((msg & 0xf8) == 0xf8)
28+ continue; /* ignore system real-time */
29+
30+ if (msg & 0x80)
31+ midi_p = midi_msg; /* status byte */
32+
33+ if (!midi_p)
34+ continue; /* ignore extra or unsynchronized data */
35+
36+ *midi_p++ = msg;
37+
38+ if (midi_p == midi_msg+3) {
39+ /* received a complete MIDI message */
40+ rtems_message_queue_send(midi_q, midi_msg, 3);
41+ midi_p = NULL;
42+ }
43   }
44   lm32_interrupt_ack(1 << MM_IRQ_MIDI);
45 }
46@@ -53,8 +71,8 @@
47 
48  sc = rtems_message_queue_create(
49     rtems_build_name('M', 'I', 'D', 'I'),
50- 64,
51- 1,
52+ 32,
53+ 3,
54     0,
55     &midi_q
56   );
57

Archive Download this file

Branches:
master



interactive