Search   
Home  Print View  

 

GP-LOGIC

Branch Content

Main Loop

The main task of the Main Loop is to monitor and debounce GPI inputs. When a valid (stable) change is detected, the status of all GPIs is saved into memory variable GPI_STATUS as a bit-map. This variable will later be used by the Command Semantics routines to generate responses to GET STATUS query commands.

The Main Loop is structured as a Finite State Machine (FSM).

Being in state 1, it reads the GPIO ports masking the GPOs to obtain a bit-map of GPIs which is compared with a temporary variable GPI_TMP. This variable had previously been initialized as zero (no active GPIs). While no change is detected, the FSM remains in state 1.

As soon as GPIs reading mismatches GPI_TMP, the FSM starts a Debounce Timer and changes to state 2 in which it will remain indefinetly.

The timeout routine of the Debounce Timer will simply set the FSM state to 3. Being in this state, the FSM will read the GPIs port again and repeat the comparison. A match means that the now debounced input is statable, so GPI_TMP is copied to GPI_STATUS, and returns to initial state 1. A mismatch means that the reading is not stable; in this case, the Debounce Timer is started again and status is changed to 2 to give it another try.

The number of tries is limited, but that is not part of the FSM; instead, a counter is checked against a literal DEBOUNCE_TRIES_MAX.

Online Manuals -- this software is based on Help Books running at melissa