static void do_alias(int argc, char *argv[]) { char name[80]; char *val; struct config_option opt; switch (argc) { case 2: make_alias(name, argv[1]); if (flash_get_config(name, &val, CONFIG_STRING)) { diag_printf("'%s' = '%s'\n", argv[1], val); } else { diag_printf("'%s' not found\n", argv[1]); } break; case 3: if (strlen(argv[2]) >= MAX_STRING_LENGTH) { diag_printf("Sorry, value is too long\n"); break; } make_alias(name, argv[1]); opt.type = CONFIG_STRING; opt.enable = (char *)0; opt.enable_sense = 1; opt.key = name; opt.dflt = (CYG_ADDRESS)argv[2]; flash_add_config(&opt, true); break; default: diag_printf("usage: alias name [value]\n"); } }
void do_baud_rate(int argc, char *argv[]) { int new_rate, ret, old_rate; bool new_rate_set; hal_virtual_comm_table_t *__chan; struct option_info opts[1]; #ifdef CYGSEM_REDBOOT_FLASH_CONFIG struct config_option opt; #endif init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM, (void **)&new_rate, (bool *)&new_rate_set, "new baud rate"); if (!scan_opts(argc, argv, 1, opts, 1, 0, 0, "")) { return; } __chan = CYGACC_CALL_IF_CONSOLE_PROCS(); if (new_rate_set) { diag_printf("Baud rate will be changed to %d - update your settings\n", new_rate); _sleep(500); // Give serial time to flush old_rate = CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_GETBAUD); ret = set_console_baud_rate(new_rate); if (ret < 0) { if (old_rate > 0) { // Try to restore set_console_baud_rate(old_rate); _sleep(500); // Give serial time to flush diag_printf("\nret = %d\n", ret); } return; // Couldn't set the desired rate } old_rate = ret; // Make sure this new rate works or back off to previous value // Sleep for a few seconds, then prompt to see if it works _sleep(3000); // Give serial time to flush if (!verify_action_with_timeout(5000, "Baud rate changed to %d", new_rate)) { _sleep(500); // Give serial time to flush set_console_baud_rate(old_rate); _sleep(500); // Give serial time to flush return; } #ifdef CYGSEM_REDBOOT_FLASH_CONFIG opt.type = CONFIG_INT; opt.enable = (char *)0; opt.enable_sense = 1; opt.key = "console_baud_rate"; opt.dflt = new_rate; flash_add_config(&opt, true); #endif } else { ret = CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_GETBAUD); diag_printf("Baud rate = "); if (ret <= 0) { diag_printf("unknown\n"); } else { diag_printf("%d\n", ret); } } }
// // Reset/initialize configuration data - used only when starting from scratch // static void config_init(void) { // Well known option strings struct config_option *optend = __CONFIG_options_TAB_END__; struct config_option *opt = __CONFIG_options_TAB__; memset(config, 0, sizeof(struct _config)); while (opt != optend) { if (!flash_add_config(opt, false)) { return; } opt++; } config_ok = true; }