#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include struct console *user_con, *admin_con; struct shell user_shell, admin_shell; extern struct flash_dev *flash; extern struct mufs *mufs; extern struct buzzer buzzers[]; extern size_t nbuzzers; struct cmd user_cmds[] = { { "hi", shell_version }, { "buzzer", shell_buzzer }, { "led", shell_led }, { "reset", shell_alarm }, { "cat", shell_cat }, { "ls", shell_ls }, { "date", shell_date }, { "time", shell_time }, { "booting", shell_prepare }, { NULL, NULL }, }; struct cmd admin_cmds[] = { { "echo", shell_echo }, #ifdef STM32F1 { "jtag", shell_jtag }, #endif { "buzzer", shell_buzzer }, { "led", shell_led }, { "reset", shell_alarm }, { "flash_probe", shell_flash_probe }, { "flash_release", shell_flash_release }, { "flash_info", shell_flash_info }, { "flash_read", shell_flash_read }, { "flash_write", shell_flash_write }, { "flash_erase", shell_flash_erase }, { "ftl_probe", shell_ftl_probe }, { "date", shell_date }, { "time", shell_time }, { "set_date", shell_set_date }, { "set_time", shell_set_time }, { "mount", shell_mount }, { "umount", shell_unmount }, { "format", shell_format }, { "mkdir", shell_mkdir }, { "rmdir", shell_rmdir }, { "ls", shell_ls }, { "stat", shell_stat }, { "cat", shell_cat }, { "write", shell_write }, { "append", shell_append }, { "mv", shell_mv, }, { "cp", shell_cp, }, { "rm", shell_rm, }, { NULL, NULL }, }; //int main(void) int main(int argc, char **argv) { size_t i; rcc_init(); gpio_init(); rtc_init(NULL); for (i = 0; i < nbuzzers; ++i) { buzzer_init(buzzers + i); } FILE *admin_out = fopen(argv[1], "w"); if (admin_out == NULL) { perror("admin_out cannot be opened"); return 1; } FILE *admin_in = fopen(argv[1], "r"); if (admin_in == NULL) { perror("admin_in cannot be opened"); return 1; } //user_con = console_init_fd(1, user_in, user_out); admin_con = console_init_fd(0, admin_in, admin_out); if ((flash = flash_probe())) { flash = ftl_mount(flash); mufs = mufs_mount(flash); } else { fprintf(admin_con->fp, "error: unable to probe flash chip.\n"); } fprintf(stderr, "fds opened\n"); //fprintf(user_con->fp, "TBM-dev (built on " BUILD_VERSION ")\n"); fprintf(admin_con->fp, "TBM-dev (built on " BUILD_VERSION ")\n"); //fflush(user_con->fp); fflush(admin_con->fp); //shell_init(&user_shell, user_cmds, user_con, "tbm $", // SHELL_SHOW_EXIT_CODE); shell_init(&admin_shell, admin_cmds, admin_con, "tbm #", SHELL_SHOW_EXIT_CODE); while (1) { //shell_parse(&user_shell); shell_parse(&admin_shell); } return 0; }