Finite State Machine Maker5/12/2021
In the below code, you have placed the array elements aligning with the enumeration values.A finite state machine in C is one of the popular design patterns for the embedded system.
Some POS devices are used the event table in which events are registered with an event handler. This input could be timer expiry signal, hardware or software interrupt. In the finite state machine, the procedure to change one state to another state is called transition. The state of the ATM machine could be changed through the coming events. After the card processing, ATM again changes their state and ask the user to enter the pin number. When the user entered the pin then it asks for choice ( Balance inquiry, withdrawal, Deposit) and after that change the state and ask to enter the amount and dispatch the entered amount. The selection of both approaches depends on the requirement and situations. We have used if-else or the switch case to check the states and triggered the event. It depends on a requirement that checks first states or the event. If you want you can reverse the procedure that means you can check the event first and after that checks the states. Using the c language we can implement a lookup table in many ways. In the below section, I am describing some ways to implement the state machine using the function pointer and lookup table. In which rows and columns represented by the states and events of the finite state machine. The most important feature of this technique in the future if you want to add any new states or events, we can easily integrate with it without any huge hurdle. So before creating the state machine diagram we need to account all the things very precisely at the beginning of the design. The states and events of the state machine are encapsulated in a structure with a function pointer (Event handler) call at the proper state and event. Initialize array of structure with states and event with proper handler. I am an embedded c software engineer and a corporate trainer, currently, I am working as senior software engineer in a largest Software consulting company. I have working experience of different microcontrollers (stm32, LPC, PIC AVR and 8051), drivers (USB and virtual com-port), POS device (VeriFone) and payment gateway (global and first data). For example, In POS device we have read function which when you pressed the key, swipe the card or insert the card then it returns relevant event value. On the basis of this event value, you call the relevant function, like when you swipe the card in POS device then an event value (MAGCARDEVENT) return by the read function. For example, upon occurrence CardInsertEvent, the state will be changed to CardInsertedState, then let say we start two timers t1 and t2 (t1.
0 Comments
Leave a Reply. |