int main(int argc, char *argv[]) { enum state_codes cur_state = start; enum ret_codes rc; int (*state_fun)(void); for (;;) { state_fun = state[cur_state]; rc = state_fun(); if (end == cur_state) break; cur_state = lookup_transitions(cur_state, rc); } return 0; }
/* SUMMARY: * Main function * INFO: * [1] Start by init the watchdog, see wdt.h for macro options. * [2] Init the current state to the entry state and the collection of return * codes. * [3] Setup the function pointer for the diffrent states. * [4] Init the serial communication and enable global interrupts and * init timer0. * [5] Redirect the stdout and the stdin for serial streams through uart. * MAIN LOOP: * [1] Assign the function pointer a current state * [2] Call the pointed function, and collect it's return code * [3] Reset the watchdog * [4] Check if the current state is exit and break(This will terminate) * [5] If not, then move to the next state, declared in the transition table. * [6] Repeat */ int main(void) { enum state_codes cur_state = ENTRY_STATE; enum ret_codes rc; uint8_t (* state_fun)(void); UART0Init(); sei(); timer0_init(); stdin = stdout = &uart0_str; for (;;) { state_fun = state[cur_state]; rc = state_fun(); if (EXIT_STATE == cur_state) break; cur_state = lookup_transitions(cur_state, rc); } return 0; }