Basically there is a state variable, holding the current state, and a table. The first part of the table has a 16 bit offset to the start of the entries for the current state. The state entries have an input mask, an input match which is compared to the AND value of the input and the mask, the next state (if there is a match), and a subroutine that is executed and passed the input value. It is essential that the last state entry for every state have a mask and match of zero, with the subroutine an error handler. I always coded this in assembler for speed. The assembler pseudo-code looked something like this, with the assumption of 16 bit input and 16 bit offsets: {Ed: Ron is quoting from memory here}
move.w inputValue, r1
move.w currentState, r2
leftshift #4, r2 ; multiply by 16
move.w (r2+tableBase), r3
$1: move.w (r3)+, r4
and.w r1, r4
cmp.w r4, (r3)+ ; r3 pointed at inputMatch, inc to nextState
jmp.eq $2
add #ENTRYOFFSET, r3 ; offset to start of next state entry
jmp $1
$2: move.w (r3)+, r2
move.w r2, currentState
call (r3) ; subroutine must end with a return
return
This is pretty fast and can handle pretty much anything. If this is the core of an interrupt service routine, don't forget to turn interrupts back on as soon as possible.
+
file: /Techref/method/process/states-rb.htm, 1KB, , updated: 2013/8/27 20:38, local time: 2024/11/24 21:09,
owner: JMN-EFP-786,
18.191.212.146:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://ecomorder.com/techref/method/process/states-rb.htm"> A compact state machine engine by Ron Braithwaite</A> |
Did you find what you needed? |
Welcome to ecomorder.com! |
Welcome to ecomorder.com! |
.