int main(void) { /* * pgm_read_byte gets cached and there doesn't seem to be any other * way to dissuade gcc from doing this. */ volatile int zero = 0; uint32_t loop = 0; board_init(); spi_init(); _delay_ms(10); /* set MCP2515 clkdiv to /2 for 8MHz */ can_cs_l(); spi_io(INSTRUCTION_WRITE); spi_io(CANCTRL); spi_io(0x85); can_cs_h(); led_init(); usb_init(); dfu_init(); /* move interrupt vectors to the boot loader */ MCUCR = 1 << IVCE; MCUCR = 1 << IVSEL; sei(); while (loop < 5) { led_a_on(); led_b_on(); _delay_ms(50); led_a_off(); led_b_off(); _delay_ms(400); if (dfu.state == dfuIDLE && pgm_read_byte(zero) != 0xff) loop++; else loop = 0; } cli(); usb_reset(); run_payload(); while (1); }
void run_payload_timeout(struct payload *p, int timeout) { int t, ch, tval; for (t = timeout; t >= 0; t--) { printf(TIMEOUT_MESSAGE, t); tval = 1000; ch = getchar_timeout(&tval); if (ch == TIMEOUT_KEY) return; } run_payload(p); }
int main(void) { extern unsigned long _binary_builtin_lar_start; struct LAR *lar; print_banner(); lar = openlar((void *)&_binary_builtin_lar_start); if (lar == NULL) { printf("[CHOOSER]: Unable to scan the attached LAR file\n"); return -1; } get_configuration(lar); if (bayoucfg.n_entries == 0) { printf("[CHOOSER]: No payloads were found in the LAR\n"); return -1; } /* * If timeout == 0xFF, then show the menu immediately. * If timeout is zero, then find and run the default item immediately. * If there is no default item, then show the menu. * If timeout is anything else, then show a message and wait for a * keystroke. If there is no keystroke in time then run the default. * If there is no default then show the menu. */ if (bayoucfg.timeout != 0xFF) { struct payload *d = payload_get_default(); if (d != NULL) { if (bayoucfg.timeout == 0) run_payload(d); else run_payload_timeout(d, bayoucfg.timeout); } } menu(); return 0; }
void loop(void) { int key; while (1) { key = getch(); if (key == ERR) continue; if (key == KEY_DOWN) selected = (selected + 1) % m_entries; else if (key == KEY_UP) selected = (selected - 1) % m_entries; else if (key == KEY_ENTER) { run_payload(mpayloads[selected]); clear(); refresh(); } else continue; draw_menu(); } }