{"id":325,"date":"2013-09-14T06:15:19","date_gmt":"2013-09-14T06:15:19","guid":{"rendered":"http:\/\/www.electronic-products-development.com\/?p=325"},"modified":"2023-12-19T15:41:53","modified_gmt":"2023-12-19T15:41:53","slug":"state-machine","status":"publish","type":"post","link":"https:\/\/ibex.tech\/c\/c\/state-machine\/state-machine","title":{"rendered":"State Machine"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">\nA Mode State Machine<br>\n<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>typedef enum _SM_USER_MODE\n{\n    UM_POWERUP,\n    UM_IDLE\n} SM_USER_MODE;\n\nstatic uint8_t CurrentMode = UM_POWERUP;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\tstatic uint8_t CurrentModeLast = 0xff;\n\tuint8_t JustEnteredNewMode = 0;\n\n\n\n\t\/\/------------------------------\n\t\/\/----- CHECK FOR NEW MODE -----\n\t\/\/------------------------------\n\tJustEnteredNewMode= 0;\n\tif (CurrentMode != CurrentModeLast)\n\t{\n\t\t\/\/Flag that we've just entered a new mode\n\t\tJustEnteredNewMode = 1;\n\t\tCurrentModeLast = CurrentMode;\n\t}\n\n\n\t\/\/------------------------------------\n\t\/\/------------------------------------\n\t\/\/----- PROCESS THE CURRENT MODE -----\n\t\/\/------------------------------------\n\t\/\/------------------------------------\n\tswitch (CurrentMode)\n\t{\n\tcase UM_POWERUP:\n\t\t\/\/-------------------\n\t\t\/\/-------------------\n\t\t\/\/----- POWERUP -----\n\t\t\/\/-------------------\n\t\t\/\/-------------------\n\t\tif (JustEnteredNewMode)\n\t\t{\n\t\t\t\/\/----- JUST ENTERED THIS MODE -----\n\n\t\t}\n\t\t\/\/------------------------\n\t\t\/\/----- PROCESS MODE -----\n\t\t\/\/------------------------\n\n\t\tCurrentMode = UM_IDLE;\n\t\tbreak;\n\n\n\n\tcase UM_IDLE:\n\t\t\/\/-------------------------------\n\t\t\/\/-------------------------------\n\t\t\/\/----- IDLE - DEFAULT MODE -----\n\t\t\/\/-------------------------------\n\t\t\/\/-------------------------------\n\t\tif (JustEnteredNewMode)\n\t\t{\n\t\t\t\/\/----- JUST ENTERED THIS MODE -----\n\n\n\t\t}\n\t\t\/\/------------------------\n\t\t\/\/----- PROCESS MODE -----\n\t\t\/\/------------------------\n\n\n\n\t\tbreak;\n\n\n\n\n\n\/\/&lt;&lt;&lt;&lt;&lt; ADD OTHER MODES HERE\n\n\n\n\t} \/\/switch (CurrentMode)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A Mode State Machine<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[116],"tags":[],"class_list":["post-325","post","type-post","status-publish","format-standard","hentry","category-state-machine"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts\/325","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/comments?post=325"}],"version-history":[{"count":10,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts\/325\/revisions"}],"predecessor-version":[{"id":1507,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts\/325\/revisions\/1507"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/media?parent=325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/categories?post=325"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/tags?post=325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}