/** * Handle a breakpoint. The system is stopped until the user forces it * to continue, either by pressing 'p' in the debug console, or presses * the Escape Button. Interrupt-level functions continue to run while * paused; only regular task scheduling is paused. In order to poll for * the continue, we have to invoke the switch and debugger periodic * functions. */ void bpt_hit (void) { U8 key; db_paused = 1 - db_paused; if (db_paused == 1) { callset_invoke (debug_enter); db_tilt_flag = in_tilt; in_tilt = FALSE; bpt_display (); } else { in_tilt = db_tilt_flag; callset_invoke (debug_exit); } while (db_paused == 1) { if ((key = button_check (SW_ENTER))) { /* Enter = change active field */ bpt_display (); } else if ((key = button_check (SW_UP))) { /* Up = increase field value */ bpt_mem_addr += key * 4; bpt_mem_addr = (void *) (((U16)bpt_mem_addr) & 0x1FFFUL); bpt_display (); } else if ((key = button_check (SW_DOWN))) { /* Down = decrease field value */ bpt_mem_addr -= key * 4; bpt_mem_addr = (void *) (((U16)bpt_mem_addr) & 0x1FFFUL); bpt_display (); } else { switch_periodic (); db_periodic (); task_runs_long (); } } #ifdef CONFIG_DMD_OR_ALPHA dmd_alloc_low_clean (); dmd_show_low (); #endif }
/** Runs the periodic functions. This function is called * about once every 16ms, but it may run less often when * there are many tasks running. */ void do_periodic (void) { /* Switch processing is special, and will be called as often as possible. Everything else is called less frequently. */ switch_periodic (); /* See if at least 100ms has elapsed. If so, we advance the timeout for the next check. If more than 200ms elapsed, we will only process 1 'tick' on the current call, and do it again on the next run. */ if (time_reached_p (idle_ready_time)) idle_ready_time += TIME_100MS; else return; /* Throw the 100ms event */ callset_invoke (idle_every_100ms); /* Throw the 1 second event every 10 calls */ idle_second_timer++; if (idle_second_timer >= 10) { idle_second_timer -= 10; callset_invoke (idle_every_second); /* Throw the 10 second event if that has elapsed */ idle_10second_timer++; if (idle_10second_timer >= 10) { idle_10second_timer -= 10; callset_invoke (idle_every_ten_seconds); #ifndef CONFIG_RTC idle_minute_timer++; if (idle_minute_timer >= 6) { idle_minute_timer -= 6; callset_invoke (minute_elapsed); } #endif } } }
void debug_shell (void) { shell_cursor = 0; for (;;) { if (switch_poll (SW_ESCAPE)) { if (shell_cursor == shell_cmd) { } else { --shell_cursor; } shell_button_finish (); } else if (switch_poll (SW_UP)) { shell_cmd[shell_cursor]++; shell_button_finish (); } else if (switch_poll (SW_DOWN)) { shell_cmd[shell_cursor]--; shell_button_finish (); } else if (switch_poll (SW_ENTER)) { if (shell_ctx[shell_cursor].exec) { } else { shell_cursor++; } shell_button_finish (); } else { switch_periodic (); task_runs_long (); } } }
/** * Debounce a button press, waiting for it to clear. */ U8 button_check (U8 sw) { volatile U16 x; if (!switch_poll (sw)) return 0; for (x=bpt_debounce_timer; x ; --x) { task_runs_long (); barrier (); } switch_periodic (); if (!switch_poll (sw)) { bpt_repeat_count = 0; bpt_debounce_timer = 0x1C00; return 1; } else { bpt_repeat_count++; if (bpt_repeat_count >= 32) { bpt_repeat_count = 32; bpt_debounce_timer = 0x80; return 8; } else if (bpt_repeat_count >= 4) { bpt_debounce_timer = 0x600; return 4; } else return 1; } }