{"id":2687,"date":"2017-02-26T14:45:14","date_gmt":"2017-02-26T12:45:14","guid":{"rendered":"http:\/\/www.final-memory.org\/?p=2687"},"modified":"2017-02-26T14:45:14","modified_gmt":"2017-02-26T12:45:14","slug":"finite-state-machine-generator-for-c","status":"publish","type":"post","link":"https:\/\/www.final-memory.org\/?p=2687","title":{"rendered":"Finite State Machine Generator for C"},"content":{"rendered":"<p>For quite a long time I&#8217;m thinking about simple code generating tools. I don&#8217;t want to use a special XML syntax or descriptive language but a simple Excel or OpenOffice sheet instead.<\/p>\n<p>The aim is to generated C source code for small microcontroller applications or retrocomputing systems.<\/p>\n<p>For the start I made a simple generator for finite state machines (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Finite-state_machine\" target=\"_blank\">Wikipedia entry<\/a>)<\/p>\n<p>It is also my first script written in Python and thus not really as tidy and neat as I prefer. But it is working for now.<\/p>\n<p>It takes the sheet from an OpenOffice .ods table like this:<\/p>\n<table border=\"0\" cellspacing=\"0\">\n<colgroup width=\"134\"><\/colgroup>\n<colgroup width=\"163\"><\/colgroup>\n<colgroup width=\"120\"><\/colgroup>\n<tbody>\n<tr>\n<td align=\"left\" height=\"17\"><b>@brief<\/b><\/td>\n<td colspan=\"2\" align=\"left\">autofire button statemachine<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" height=\"17\"><b>@see<\/b><\/td>\n<td align=\"left\"><b>\u00a0<\/b><\/td>\n<td align=\"left\"><b>\u00a0<\/b><\/td>\n<\/tr>\n<tr>\n<td align=\"left\" height=\"17\"><b>\u00a0<\/b><\/td>\n<td align=\"left\"><b>\u00a0<\/b><\/td>\n<td align=\"left\"><b>\u00a0<\/b><\/td>\n<\/tr>\n<tr>\n<td align=\"left\" bgcolor=\"#B2B2B2\" height=\"17\"><b>State<\/b><\/td>\n<td align=\"left\" bgcolor=\"#B2B2B2\"><b>Event<\/b><\/td>\n<td align=\"left\" bgcolor=\"#B2B2B2\"><b>Next State<\/b><\/td>\n<\/tr>\n<tr>\n<td align=\"left\" height=\"17\">INIT<\/td>\n<td align=\"left\">KeyPressed<\/td>\n<td align=\"left\">PULSE_ON<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" height=\"17\">INIT<\/td>\n<td align=\"left\">KeyNotPressed<\/td>\n<td align=\"left\">AUTOFIRE_OFF<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" height=\"17\"><\/td>\n<td align=\"left\"><\/td>\n<td align=\"left\"><\/td>\n<\/tr>\n<tr>\n<td align=\"left\" height=\"17\">AUTOFIRE_OFF<\/td>\n<td align=\"left\">KeyPressed<\/td>\n<td align=\"left\">PULSE_ON<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" height=\"17\"><\/td>\n<td align=\"left\"><\/td>\n<td align=\"left\"><\/td>\n<\/tr>\n<tr>\n<td align=\"left\" height=\"17\">PULSE_ON<\/td>\n<td align=\"left\">KeyNotPressed<\/td>\n<td align=\"left\">AUTOFIRE_OFF<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" height=\"17\">PULSE_ON<\/td>\n<td align=\"left\">PulseTimeElapsed<\/td>\n<td align=\"left\">PULSE_OFF<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" height=\"17\"><\/td>\n<td align=\"left\"><\/td>\n<td align=\"left\"><\/td>\n<\/tr>\n<tr>\n<td align=\"left\" height=\"17\">PULSE_OFF<\/td>\n<td align=\"left\">KeyNotPressed<\/td>\n<td align=\"left\">AUTOFIRE_OFF<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" height=\"17\">PULSE_OFF<\/td>\n<td align=\"left\">PulseTimeElapsed<\/td>\n<td align=\"left\">PULSE_ON<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>and generates a switch-case style state machine in C with callback functions for state and event handling.<\/p>\n<p>A version with support for object oriented programming with pointers to statemachine objects is planned aswell. Check the github for functional updates.<\/p>\n<p>The actual code can be found on Github:\u00a0<a href=\"https:\/\/github.com\/simonsunnyboy\/gen-fsm\">https:\/\/github.com\/simonsunnyboy\/gen-fsm<\/a><\/p>\n<div id=\"facebook_like\"><iframe src=\"http:\/\/www.facebook.com\/plugins\/like.php?href=https%3A%2F%2Fwww.final-memory.org%2F%3Fp%3D2687&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; width:500px; height:80px;\" allowTransparency=\"true\"><\/iframe><\/div>","protected":false},"excerpt":{"rendered":"<p>For quite a long time I&#8217;m thinking about simple code generating tools. I don&#8217;t want to use a special XML syntax or descriptive language but a simple Excel or OpenOffice sheet instead. The aim is to generated C source code for small microcontroller applications or retrocomputing systems. For the start I made a simple generator &hellip; <a href=\"https:\/\/www.final-memory.org\/?p=2687\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Finite State Machine Generator for C&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[65,34,76,87,27,57,98,35,56,100,36],"tags":[],"class_list":["post-2687","post","type-post","status-publish","format-standard","hentry","category-68hc11","category-34","category-ansi-c","category-arduino","category-asm-software","category-avr","category-github","category-mikrocontroller","category-openoffice","category-phyton","category-sdcc"],"_links":{"self":[{"href":"https:\/\/www.final-memory.org\/index.php?rest_route=\/wp\/v2\/posts\/2687","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.final-memory.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.final-memory.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.final-memory.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.final-memory.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2687"}],"version-history":[{"count":4,"href":"https:\/\/www.final-memory.org\/index.php?rest_route=\/wp\/v2\/posts\/2687\/revisions"}],"predecessor-version":[{"id":2691,"href":"https:\/\/www.final-memory.org\/index.php?rest_route=\/wp\/v2\/posts\/2687\/revisions\/2691"}],"wp:attachment":[{"href":"https:\/\/www.final-memory.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.final-memory.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2687"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.final-memory.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}