};
StoreStatusByte,NOTE_ON_OR_OFF},
{NOTE_ON_OR_OFF,DATA_RECEIVED,
MidiSM_StoreNoteNumber,NOTE_ON_OR
_OFF_NUMBER},
{NOTE_ON_OR_OFF_NUMBER,
NOTE_ON_OR_OFF_RECEIVED,MidiSM_St
oreStatusByte, NOTE_ON_OR_OFF},
{NOTE_ON_OR_OFF_NUMBER,
DATA_RECEIVED,MidiSM
_NoteOnOrOffComplete,
NOTE_ON_OR_OFF},
{INHIBITED,ENABLE,
MidiSM_DoNothing,INIT},
{LAST_STATE, LAST_EVENT, 0,
LAST_STATE},
The first entry in the struct is the current
state; the second entry, the event that
has arrived; the third entry, the state transition
function needed to handle the event;
and the fourth entry, the next state.
The code that implements the business
end of the state machine looks something
like this:
XStatus MidiSM_
DoStateTransition
(midi_state_machine_t *pInstance,
u8 event)
{
XPERIMENT
const midi_state_table_
entry_t *pTable = pInstance-
>pStateTable;
// Search for a match in the
state table
do {
We’ve successfully played some very complex and fast
pieces of music, from classical to rock; there doesn’t seem to be
any serious limitation in the speed of the solenoids and drivers.
if ((event == pTable-
>received_event)
&& ((pInstance-
>current_state == pTable-
>state)
PHOTO: MARTIN LING
}
{
}
|| (pTable->state ==
ANY_STATE)))
(*pTable-
>transition_function)((v
oid *)pInstance);
pInstance->current_state
= pTable->next_state;
return XST_
SUCCESS;
pTable++;
} while (pTable->state !=
LAST_STATE);
// Aaargh, something bad happened
- should never get here
XASSERT_NONVOID_ALWAYS();
Figure 6 - The finished controller in place; the robotic organist plays everything from rhapsodies to rock.
48 Xcell Journal First Quarter 2009
The event loop supplies an event as an argument
to this function and, depending on
the current state and the event, some action
is taken and the state of the system
changed. The types of events include the
arrival of bytes on the MIDI interface, the
arrival of characters on the console and
presses of the panic button. All experienced
MIDI hackers know a panic button is a
must-have feature to save your ears and
your power supplies—it unconditionally
turns off all the solenoids and returns the
system to a known-safe state.
Waldflöte in Action
Figure 6 is a photograph of the organ with
the contraption in place. Hiding the keys at
the bottom are the solenoids’ wooden backplanes—each
plank has 30 or more solenoids
mounted on it, along with some
recycled can capacitors to provide the energy
reservoirs for the solenoids. We Cclamped
the whole driver assembly to the
organ. At the top you can see the Spartan-
3E Starter Kit board and the interface strip-