0
0
Embedded Cprogramming~10 mins

State transition table approach in Embedded C - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the number of states.

Embedded C
enum States { STATE_IDLE, STATE_PROCESS, STATE_DONE, [1] };
Drag options to blanks, or click blank then click option'
ASTATE_COUNT
BNUM_STATES
CTOTAL_STATES
DMAX_STATES
Attempts:
3 left
💡 Hint
Common Mistakes
Using a name that does not represent the count of states.
Forgetting to add a count identifier at the end.
2fill in blank
medium

Complete the code to declare the state transition function pointer type.

Embedded C
typedef void (*StateFunc)([1]);
Drag options to blanks, or click blank then click option'
Avoid
Bint
Cchar
Dvoid*
Attempts:
3 left
💡 Hint
Common Mistakes
Using int or other types instead of void.
Adding parameters when none are needed.
3fill in blank
hard

Fix the error in the state transition table declaration.

Embedded C
StateFunc state_table[[1]] = { state_idle, state_process, state_done };
Drag options to blanks, or click blank then click option'
A3
B4
CNUM_STATES
DSTATE_COUNT
Attempts:
3 left
💡 Hint
Common Mistakes
Hardcoding the size instead of using STATE_COUNT.
Using an incorrect size causing out-of-bounds errors.
4fill in blank
hard

Fill both blanks to correctly update the current state using the transition table.

Embedded C
current_state = [1];
state_table[[2]]();
Drag options to blanks, or click blank then click option'
Anext_state
Bcurrent_state
Cstate_table
DSTATE_COUNT
Attempts:
3 left
💡 Hint
Common Mistakes
Calling the function with next_state instead of current_state.
Not updating current_state before calling the function.
5fill in blank
hard

Fill all three blanks to define the state transition table with correct function pointers.

Embedded C
StateFunc state_table[STATE_COUNT] = { [1], [2], [3] };
Drag options to blanks, or click blank then click option'
Astate_idle
Bstate_process
Cstate_done
Dstate_error
Attempts:
3 left
💡 Hint
Common Mistakes
Including a function not defined in the enum.
Mixing the order of functions.