void blink_all_leds(void) { all_led_on(); _delay_ms(500); all_led_off(); _delay_ms(100); caps_lock_led_on(); _delay_ms(100); num_lock_led_on(); _delay_ms(100); scroll_lock_led_on(); _delay_ms(100); keypad_led_on(); _delay_ms(100); //back scroll_lock_led_on(); _delay_ms(100); num_lock_led_on(); _delay_ms(100); caps_lock_led_on(); _delay_ms(100); all_led_off(); }
static void blink_sys_led(int stage) { all_led_off(); if(stage) { int d=100; int count=stage; int rest=1000-(stage*2*d); int i=0; for(; i < count; ++i) { all_led_on(); milisecdelay(d); all_led_off(); milisecdelay(d); } milisecdelay(rest); } else { milisecdelay(1000); } }
// info about current progress of failsafe mode int do_http_progress(const int state){ unsigned char i = 0; /* toggle LED's here */ switch(state){ case WEBFAILSAFE_PROGRESS_START: // blink LED fast 10 times for(i = 0; i < 10; ++i){ all_led_on(); milisecdelay(25); all_led_off(); milisecdelay(25); } printf("HTTP server is ready!\n\n"); break; case WEBFAILSAFE_PROGRESS_TIMEOUT: //printf("Waiting for request...\n"); break; case WEBFAILSAFE_PROGRESS_UPLOAD_READY: printf("HTTP upload is done! Upgrading...\n"); break; case WEBFAILSAFE_PROGRESS_UPGRADE_READY: printf("HTTP ugrade is done! Rebooting...\n\n"); break; case WEBFAILSAFE_PROGRESS_UPGRADE_FAILED: printf("## Error: HTTP ugrade failed!\n\n"); // blink LED fast for 4 sec for(i = 0; i < 80; ++i){ all_led_on(); milisecdelay(25); all_led_off(); milisecdelay(25); } // wait 1 sec milisecdelay(1000); break; } return(0); }
static void blink_led(int count,int delay) { int i=0; all_led_off(); for(; i < count; ++i) { all_led_on(); milisecdelay(delay); all_led_off(); milisecdelay(delay); } }
int flash_erase(flash_info_t *info, int s_first, int s_last){ int i, j, sector_size = info->size / info->sector_count; printf("Erasing: "); j = 0; for(i = s_first; i <= s_last; i++){ ar7240_spi_sector_erase(i * sector_size); if(j == 39){ puts("\n "); j = 0; } puts("#"); led_toggle(); j++; } ar7240_spi_done(); all_led_off(); printf("\n\n"); return(0); }
int flash_erase_4k(int start, int end) { int i = 0; int base = 0x9F000000; start = ALIGN(start - base); end = ALIGN(end - base); printf("Erasing: %08X-%08X\n", start, end); while (start <= end) { ar7240_spi_erase_4k(start); start += SECTOR_ERASE_SIZE; if((i + 1) % 40 == 0){ printf("\n"); } printf("#"); led_toggle(); i++; } ar7240_spi_done(); all_led_off(); printf("\n\n"); return(0); }
static void blink_sys_led(int counter) { all_led_off(); if((counter) && !(counter%2)) { all_led_on(); milisecdelay(300); all_led_off(); milisecdelay(700); } else { milisecdelay(1000); } }
uint8_t matrix_scan(void) { uint8_t layer = biton32(layer_state); switch (layer) { case 0: all_led_off(); break; case 1: if (!(host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK))) { all_led_off(); caps_lock_led_on(); } break; case 2: all_led_off(); num_lock_led_on(); break; default: break; } for (uint8_t i = 0; i < MATRIX_ROWS; i++) { select(i); uint8_t row = read(i); if (matrix_debouncing[i] != row) { matrix_debouncing[i] = row; if (debouncing) { debug("bounce!: "); debug_hex(debouncing); debug("\n"); } debouncing = DEBOUNCE; } unselect(); } if (debouncing) { if (--debouncing) { _delay_ms(1); } else { for (uint8_t i = 0; i < MATRIX_ROWS; i++) { matrix[i] = matrix_debouncing[i]; } } } return 1; }
int ar7240_mem_config(void){ #ifndef CONFIG_SKIP_LOWLEVEL_INIT #ifndef COMPRESSED_UBOOT hornet_ddr_init(); #endif /* Default tap values for starting the tap_init*/ ar7240_reg_wr(AR7240_DDR_TAP_CONTROL0, CFG_DDR_TAP0_VAL); ar7240_reg_wr(AR7240_DDR_TAP_CONTROL1, CFG_DDR_TAP1_VAL); #endif gpio_config(); all_led_off(); #ifndef CONFIG_SKIP_LOWLEVEL_INIT hornet_ddr_tap_init(); #endif // return memory size return(ar7240_ddr_find_size()); }
int ar7240_mem_config(void){ #ifndef COMPRESSED_UBOOT ar7240_ddr_initial_config(CFG_DDR_REFRESH_VAL); #endif /* Default tap values for starting the tap_init*/ ar7240_reg_wr(AR7240_DDR_TAP_CONTROL0, CFG_DDR_TAP0_VAL); ar7240_reg_wr(AR7240_DDR_TAP_CONTROL1, CFG_DDR_TAP1_VAL); gpio_config(); all_led_off(); #ifndef COMPRESSED_UBOOT ar7240_ddr_tap_init(); #else hornet_ddr_tap_init(); #endif // return memory size return(ar7240_ddr_find_size()); }
void main_loop(void){ #ifndef CFG_HUSH_PARSER static char lastcommand[CFG_CBSIZE] = { 0, }; int len; int rc = 1; int flag; #endif int counter = 0; int stage=0; #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0) char *s; int bootdelay; #endif /* defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0) */ #ifdef CFG_HUSH_PARSER u_boot_hush_start(); #endif #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0) // get boot delay (seconds) s = getenv("bootdelay"); bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY; // get boot command s = getenv("bootcmd"); #if !defined(CONFIG_BOOTCOMMAND) #error "CONFIG_BOOTCOMMAND not defined!" #endif if(!s){ setenv("bootcmd", CONFIG_BOOTCOMMAND); } s = getenv("bootcmd"); // are we going to run web failsafe mode, U-Boot console, U-Boot netconsole or just boot command? if(reset_button_status()){ #ifdef CONFIG_SILENT_CONSOLE if(gd->flags & GD_FLG_SILENT){ /* Restore serial console */ console_assign(stdout, "serial"); console_assign(stderr, "serial"); } /* enable normal console output */ gd->flags &= ~(GD_FLG_SILENT); #endif all_led_off(); // wait 0,5s // milisecdelay(500); printf("Press reset button for at least:\n" "- %d sec. to run upgrade from USB flash\n" "- %d sec. to run U-Boot console\n" "- %d sec. to run HTTP server\n" "- %d sec. to run netconsole\n\n", CONFIG_DELAY_TO_AUTORUN_USB, CONFIG_DELAY_TO_AUTORUN_CONSOLE, CONFIG_DELAY_TO_AUTORUN_HTTPD, CONFIG_DELAY_TO_AUTORUN_NETCONSOLE); printf("Reset button is pressed for: %2d ", counter); while(reset_button_status()){ blink_sys_led(stage); // 1 second! if(!reset_button_status()){ break; } counter++; if(counter >= CONFIG_DELAY_TO_AUTORUN_USB) { if(counter >= CONFIG_DELAY_TO_AUTORUN_CONSOLE) { if(counter >= CONFIG_DELAY_TO_AUTORUN_HTTPD) { if(counter >= CONFIG_DELAY_TO_AUTORUN_NETCONSOLE) { stage=4; } else { stage=3; } } else { stage=2; } } else { stage=1; } } // how long the button is pressed? printf("\b\b\b%2d ", counter); if(counter >= CONFIG_MAX_BUTTON_PRESSING){ stage=0; // normal boot break; } } all_led_off(); if(counter > 0){ // run web failsafe mode if(stage == 1){ printf("\n\nButton was pressed for %d sec...\nStarting upgrage from USB flash...\n\n", counter); bootdelay = -1; usb_upgrade(); } else if(stage == 2){ printf("\n\nButton was pressed for %d sec...\nStarting U-Boot console...\n\n", counter); bootdelay = -1; } else if(stage == 3){ printf("\n\nButton was pressed for %d sec...\nHTTP server is starting for firmware update...\n\n", counter); NetLoopHttpd(); bootdelay = -1; } else if(stage == 4){ printf("\n\nButton was pressed for %d sec...\nStarting U-Boot netconsole...\n\n", counter); bootdelay = -1; run_command("startnc", 0); } else { printf("\n\n## Error: button wasn't pressed long enough!\nContinuing normal boot...\n\n"); } } else { printf("\n\n## Error: button wasn't pressed long enough!\nContinuing normal boot...\n\n"); } } if(bootdelay >= 0 && s && !abortboot(bootdelay)){ try_runonce(1); try_autorun(); try_runonce(2); // try to boot #ifndef CFG_HUSH_PARSER run_command(s, 0); #else parse_string_outer(s, FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP); #endif // something goes wrong! printf("\n## Error: failed to execute 'bootcmd'!\nHTTP server is starting for firmware update...\n\n"); NetLoopHttpd(); } #endif /* CONFIG_BOOTDELAY */ /* * Main Loop for Monitor Command Processing */ #ifdef CFG_HUSH_PARSER parse_file_outer(); /* This point is never reached */ for (;;); #else for(;;){ len = readline(CFG_PROMPT); flag = 0; /* assume no special flags for now */ if(len > 0){ strcpy(lastcommand, console_buffer); } else if(len == 0){ flag |= CMD_FLAG_REPEAT; } if(len == -1){ puts("<INTERRUPT>\n"); } else { rc = run_command(lastcommand, flag); } if(rc <= 0){ /* invalid command or not repeatable, forget it */ lastcommand[0] = 0; } } #endif /* CFG_HUSH_PARSER */ }
static __inline__ int abortboot(int bootdelay){ char stopc; int abort = 0; #ifdef CONFIG_SILENT_CONSOLE if(gd->flags & GD_FLG_SILENT){ /* Restore serial console */ console_assign(stdout, "serial"); console_assign(stderr, "serial"); } #endif if(bootdelay > 0){ #ifdef CONFIG_MENUPROMPT printf(CONFIG_MENUPROMPT, bootdelay); #else printf("Hit any key to stop autoboot: %d ", bootdelay); #endif while((bootdelay > 0) && (!abort)){ int i; --bootdelay; /* delay 100 * 10ms */ for(i = 0; !abort && i < 100; ++i){ /* we got a key press */ if(tstc()){ stopc = getc(); #ifdef CONFIG_AUTOBOOT_STOP_CHAR if (stopc == CONFIG_AUTOBOOT_STOP_CHAR) { #else if (stopc != 0) { #endif abort = 1; bootdelay = 0; break; } } udelay(10000); } printf("\b\b%d ", bootdelay); } printf("\n\n"); } #ifdef CONFIG_SILENT_CONSOLE if(abort){ /* permanently enable normal console output */ gd->flags &= ~(GD_FLG_SILENT); } else if(gd->flags & GD_FLG_SILENT){ /* Restore silent console */ console_assign(stdout, "nulldev"); console_assign(stderr, "nulldev"); } #endif return(abort); } #endif /* CONFIG_BOOTDELAY >= 0 */ /****************************************************************************/ void main_loop(void){ #ifndef CFG_HUSH_PARSER static char lastcommand[CFG_CBSIZE] = { 0, }; int len; int rc = 1; int flag; #endif int counter = 0; #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0) char *s; int bootdelay; #endif /* defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0) */ #ifdef CFG_HUSH_PARSER u_boot_hush_start(); #endif #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0) // get boot delay (seconds) s = getenv("bootdelay"); bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY; // get boot command s = getenv("bootcmd"); #if !defined(CONFIG_BOOTCOMMAND) #error "CONFIG_BOOTCOMMAND not defined!" #endif if(!s){ setenv("bootcmd", CONFIG_BOOTCOMMAND); } s = getenv("bootcmd"); // are we going to run web failsafe mode, U-Boot console, U-Boot netconsole or just boot command? if(reset_button_status()){ #ifdef CONFIG_SILENT_CONSOLE if(gd->flags & GD_FLG_SILENT){ /* Restore serial console */ console_assign(stdout, "serial"); console_assign(stderr, "serial"); } /* enable normal console output */ gd->flags &= ~(GD_FLG_SILENT); #endif // wait 0,5s milisecdelay(500); printf("Press reset button for at least:\n- %d sec. to run web failsafe mode\n- %d sec. to run U-Boot console\n- %d sec. to run U-Boot netconsole\n\n", CONFIG_DELAY_TO_AUTORUN_HTTPD, CONFIG_DELAY_TO_AUTORUN_CONSOLE, CONFIG_DELAY_TO_AUTORUN_NETCONSOLE); printf("Reset button is pressed for: %2d ", counter); while(reset_button_status()){ // LED ON and wait 0,15s all_led_on(); milisecdelay(150); // LED OFF and wait 0,85s all_led_off(); milisecdelay(850); counter++; // how long the button is pressed? printf("\b\b\b%2d ", counter); if(!reset_button_status()){ break; } if(counter >= CONFIG_MAX_BUTTON_PRESSING){ break; } } all_led_off(); if(counter > 0){ // run web failsafe mode if(counter >= CONFIG_DELAY_TO_AUTORUN_HTTPD && counter < CONFIG_DELAY_TO_AUTORUN_CONSOLE){ printf("\n\nButton was pressed for %d sec...\nHTTP server is starting for firmware update...\n\n", counter); NetLoopHttpd(); bootdelay = -1; } else if(counter >= CONFIG_DELAY_TO_AUTORUN_CONSOLE && counter < CONFIG_DELAY_TO_AUTORUN_NETCONSOLE){ printf("\n\nButton was pressed for %d sec...\nStarting U-Boot console...\n\n", counter); bootdelay = -1; } else if(counter >= CONFIG_DELAY_TO_AUTORUN_NETCONSOLE){ printf("\n\nButton was pressed for %d sec...\nStarting U-Boot netconsole...\n\n", counter); bootdelay = -1; run_command("startnc", 0); } else { printf("\n\n## Error: button wasn't pressed long enough!\nContinuing normal boot...\n\n"); } } else { printf("\n\n## Error: button wasn't pressed long enough!\nContinuing normal boot...\n\n"); } } if(bootdelay >= 0 && s && !abortboot(bootdelay)){ // try to boot #ifndef CFG_HUSH_PARSER run_command(s, 0); #else parse_string_outer(s, FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP); #endif // something goes wrong! printf("\n## Error: failed to execute 'bootcmd'!\nHTTP server is starting for firmware update...\n\n"); NetLoopHttpd(); } #endif /* CONFIG_BOOTDELAY */ /* * Main Loop for Monitor Command Processing */ #ifdef CFG_HUSH_PARSER parse_file_outer(); /* This point is never reached */ for (;;); #else for(;;){ len = readline(CFG_PROMPT); flag = 0; /* assume no special flags for now */ if(len > 0){ strcpy(lastcommand, console_buffer); } else if(len == 0){ flag |= CMD_FLAG_REPEAT; } if(len == -1){ puts("<INTERRUPT>\n"); } else { rc = run_command(lastcommand, flag); } if(rc <= 0){ /* invalid command or not repeatable, forget it */ lastcommand[0] = 0; } } #endif /* CFG_HUSH_PARSER */ } /****************************************************************************/ /* * Prompt for input and read a line. * If CONFIG_BOOT_RETRY_TIME is defined and retry_time >= 0, * time out when time goes past endtime (timebase time in ticks). * Return: number of read characters * -1 if break * -2 if timed out */ int readline(const char * const prompt){ char *p = console_buffer; int n = 0; /* buffer index */ int plen = 0; /* prompt length */ int col; /* output column cnt */ char c; /* print prompt */ if(prompt){ plen = strlen(prompt); puts(prompt); } col = plen; for(;;){ c = getc(); /* * Special character handling */ switch(c){ case '\r': /* Enter */ case '\n': *p = '\0'; puts("\r\n"); return(p - console_buffer); case '\0': /* nul */ continue; case 0x03: /* ^C - break */ console_buffer[0] = '\0'; /* discard input */ return(-1); case 0x15: /* ^U - erase line */ while(col > plen){ puts(erase_seq); --col; } p = console_buffer; n = 0; continue; case 0x17: /* ^W - erase word */ p = delete_char(console_buffer, p, &col, &n, plen); while((n > 0) && (*p != ' ')){ p = delete_char(console_buffer, p, &col, &n, plen); } continue; case 0x08: /* ^H - backspace */ case 0x7F: /* DEL - backspace */ p = delete_char(console_buffer, p, &col, &n, plen); continue; default: /* * Must be a normal character then */ if(n < CFG_CBSIZE - 2){ if(c == '\t'){ /* expand TABs */ puts(tab_seq + (col & 07)); col += 8 - (col & 07); } else { ++col; /* echo input */ putc(c); } *p++ = c; ++n; } else { /* Buffer full */ putc('\a'); } } } }