static void command_run() { char cmd[256]; int cmdlen = 0; for (;;) { halt(); key_t key; bool avail; while ((avail = kb_getkey(&key)) != false) { // If a printable character was typed, append it to the command. if (key.ch >= 32 && key.ch < 127) { if (cmdlen < arrsize(cmd) - 1) { cmd[cmdlen] = key.ch; tty_printc(TTY_CONSOLE, cmd[cmdlen]); cmdlen++; } } // Handle special keys (like enter, backspace). else if (key.brk == KEYBRK_DOWN) { if (key.code == KEY_ENTER) { tty_printc(TTY_CONSOLE, '\n'); // Strip trailing whitespace. while (cmdlen > 0 && cmd[cmdlen - 1] == ' ') cmdlen--; cmd[cmdlen] = 0; // Execute the command. bool cont = command_exec(cmd); cmdlen = 0; if (cont) command_prompt(); else return; } else if (key.code == KEY_BACKSPACE && cmdlen > 0) { tty_printc(TTY_CONSOLE, '\b'); cmdlen--; } } } } }
void init_command_prompt(void) { // Initialize the command-counter. next = 0; // Add commands. add_command("help", &help_cmd); add_command("clear", &clear_cmd); add_command("args", &print_args_cmd); add_command("write", &free_text_cmd); add_command("mmap", &mmap_cmd); add_command("pview", &proc_view_cmd); add_command("inf", &inf_loop_cmd); add_command("killth", &kill_thread_cmd); add_command("edev", &enum_dev_cmd); add_command("list", &list_cmd); add_command("cd", &change_dir_cmd); add_command("read", &read_cmd); add_command("del", &delete_cmd); add_command("mkdir", &make_dir_cmd); // Initiate the command-prompt. command_prompt(); }
void main() { disable_interrupts(GLOBAL); setup_spi(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_16 ); setup_spi2(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_16 ); setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4|VSS_4V096); setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0); // TIMER 0 is being used to service the WTD setup_timer_0(T0_INTERNAL|T0_DIV_256); /* sets the internal clock as source and prescale 256. At 10 Mhz timer0 will increment every 0.4us (Fosc*4) in this setup and overflows every 6.71 seconds. Timer0 defaults to 16-bit if RTCC_8_BIT is not used. Fosc = 10 MHz, Fosc/4 = 2.5 Mhz, div 256 = 0.0001024 s, 65536 increments = 6.71 sec Fosc = 64 MHz, Fosc/4 = 16 Mhz, div 256 = 0.000016 s, 65536 increments = 1.05 sec .. pre-load with 3036 to get exact 1.0000 sec value */ // TIMER 1 is used to extinguish the LED setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); /* sets the internal clock as source and prescale 4. At 10Mhz timer0 will increment every 0.4us in this setup and overflows every 104.8 ms. Timer1 is 16-bit. Fosc = 10 Mhz ... 2.5 MHz / div 4 = 0.00000160 s * 65536 = 0.104858 sec Fosc = 64 Mhz ... 16 MHz / div 4 = 0.00000025 s * 65536 = 0.016384 sec Fosc = 64 Mhz ... 16 MHz / div 8 = 0.00000200 s * 65536 = 0.032768 sec */ setup_stepper_pwm(); // Uses TIMER 2 // TIMER 3 is used for stepper motor intervals setup_timer_3(T3_INTERNAL | T3_DIV_BY_1); // 16 bit timer // TIMER 4 is use for serial time-outs. 8-bit timer. setup_timer_4(T4_DIV_BY_4, 127, 1); setup_comparator(NC_NC_NC_NC); setup_oscillator(OSC_16MHZ | OSC_PLL_ON); // Fosc = 64 MHz ext_int_edge(0, H_TO_L); // Set up PIC18 EXT0 enable_interrupts(INT_EXT); start_heartbeat(); enable_interrupts(GLOBAL); init_hardware(); motor_sleep_rdy(); sleep_mode = FALSE; busy_set(); init_nv_vars(); get_step_vars(); init_aws(); blink(); //Add for TCP/IP interface //delay_ms(15000); signon(); RTC_read(); RTC_last_power(); RTC_reset_HT(); RTC_read(); RTC_read_flags(); if(nv_sd_status>0) fprintf(COM_A,"@SD=%Lu\r\n", nv_sd_status); init_rtc(); // This is the FAT RTC sd_status = init_sdcard(); if(sd_status>0) msg_card_fail(); reset_event(); if(m_error[0] > 0 || m_error[1] > 0) msg_mer(); if (m_comp[0]==FALSE) { e_port[0]=0; write16(ADDR_E1_PORT,0); fprintf(COM_A, "@MC1,%Lu,%Ld\r\n", m_comp[0],e_port[0]); } if (m_comp[1]==FALSE) { m_lin_pos[1]=-1; write16(ADDR_M2_LIN_POS, -1); fprintf(COM_A, "@MC2,%Lu,%Ld\r\n", m_comp[1],m_lin_pos[1]); } if (nv_cmd_mode == FALSE){ for(dt=0; dt<100; ++dt){ blip(); if (nv_cmd_mode == TRUE) { busy_clear(); fputs("@OK!", COM_A); command_prompt(); dt = 100; } } } else command_prompt(); user_quit = auto_sample_ready(); reset_cpu(); }