int main(void) { static date global; date local; date * dynamic = (date *)malloc(sizeof(*dynamic)); date_init(&global, 2008, 3, 6); date_init(&local, 2008, 3, 6); date_init(dynamic, 2008, 3, 7); demo_print("global", &global); demo_print("local", &local); demo_print("dynamic", dynamic); demo_compare("global", &global, "local", &local); demo_compare("local", &local, "dynamic", dynamic); free(dynamic); return 0; }
/*! main */ int main(void) { struct debug_t *debug; struct programs_t *progs; struct cmdli_t *cmdli; /* convenient pre-allocated structure */ struct tm *tm_clock; char c; /* anti warning for non initialized variables */ debug = NULL; progs = NULL; cmdli = NULL; tm_clock = NULL; /* Init sequence, turn on both led */ led_init(); led_set(BOTH, ON); io_init(); usb_init(); debug = debug_init(debug); progs = prog_init(progs); cmdli = cmdli_init(cmdli); tm_clock = date_init(tm_clock, debug); set_sleep_mode(SLEEP_MODE_PWR_SAVE); sei(); date_hwclock_start(); led_set(BOTH, OFF); while (1) { /* PC is connected but debug is off. */ if (usb_connected && (!debug->active)) debug_start(debug); if (debug->active && (!usb_connected)) debug_stop(debug); /* If PC is connected * then check for a command sent from the user * and execute it. * Anyway do NOT go to sleep. */ if (debug->active) { c = uart_getchar(0, 0); if (c) { /* echo */ uart_putchar(0, c); cmdli_exec(c, cmdli, progs, debug); } } else { go_to_sleep(progs->valve, debug); if (prog_alarm(progs) && flag_get(progs, FL_LED)) led_set(RED, BLINK); } /* if there is a job to do (open, close valves). */ if (date_timetorun(tm_clock, debug)) job_on_the_field(progs, debug, tm_clock); } /* This part should never be reached */ date_hwclock_stop(); cli(); date_free(tm_clock); cmdli_free(cmdli); prog_free(progs); debug_free(debug); return(0); }