Line 279... |
Line 279... |
printf("All threads were stopped!\n");
|
printf("All threads were stopped!\n");
|
core_.shutdown();
|
core_.shutdown();
|
return 0;
|
return 0;
|
}
|
}
|
|
|
|
struct TimerType {
|
|
timer_callback_type cb;
|
|
void *args;
|
|
int interval;
|
|
int delta;
|
|
int single_shot;
|
|
};
|
|
|
|
static const int TIMERS_MAX = 2;
|
|
static TimerType timers_[TIMERS_MAX] = {{0}};
|
|
|
extern "C" void RISCV_break_simulation() {
|
extern "C" void RISCV_break_simulation() {
|
if (core_.isExiting()) {
|
if (core_.isExiting()) {
|
return;
|
return;
|
}
|
}
|
core_.setExiting();
|
core_.setExiting();
|
Line 290... |
Line 301... |
data.func = reinterpret_cast<lib_thread_func>(safe_exit_thread);
|
data.func = reinterpret_cast<lib_thread_func>(safe_exit_thread);
|
data.args = 0;
|
data.args = 0;
|
RISCV_thread_create(&data);
|
RISCV_thread_create(&data);
|
}
|
}
|
|
|
extern "C" int RISCV_is_active() {
|
|
return core_.isActive();
|
extern "C" void RISCV_dispatcher_start() {
|
|
TimerType *tmr;
|
|
int sleep_interval = 20;
|
|
int delta;
|
|
while (core_.isActive()) {
|
|
delta = 20;
|
|
for (int i = 0; i < TIMERS_MAX; i++) {
|
|
tmr = &timers_[i];
|
|
if (!tmr->cb || !tmr->interval) {
|
|
continue;
|
|
}
|
|
|
|
tmr->delta -= sleep_interval;
|
|
if (tmr->delta <= 0) {
|
|
tmr->cb(tmr->args);
|
|
tmr->delta += tmr->interval;
|
|
if (tmr->single_shot) {
|
|
RISCV_unregister_timer(tmr->cb);
|
|
continue;
|
|
}
|
|
}
|
|
if (delta > tmr->delta) {
|
|
delta = tmr->delta;
|
|
}
|
|
}
|
|
sleep_interval = delta;
|
|
RISCV_sleep_ms(sleep_interval);
|
|
}
|
|
}
|
|
|
|
extern "C" void RISCV_register_timer(int msec, int single_shot,
|
|
timer_callback_type cb, void *args) {
|
|
TimerType *tmr = 0;
|
|
for (int i = 0; i < TIMERS_MAX; i++) {
|
|
if (timers_[i].cb == 0) {
|
|
tmr = &timers_[i];
|
|
break;
|
|
}
|
|
}
|
|
if (tmr == 0) {
|
|
RISCV_error("%s", "No available timer slot");
|
|
return;
|
|
}
|
|
tmr->cb = cb;
|
|
tmr->args = args;
|
|
tmr->interval = msec;
|
|
tmr->delta = msec;
|
|
tmr->single_shot = single_shot;
|
|
}
|
|
|
|
extern "C" void RISCV_unregister_timer(timer_callback_type cb) {
|
|
for (int i = 0; i < TIMERS_MAX; i++) {
|
|
if (timers_[i].cb == cb) {
|
|
timers_[i].cb = 0;
|
|
timers_[i].args = 0;
|
|
timers_[i].interval = 0;
|
|
timers_[i].delta = 0;
|
|
timers_[i].single_shot = 0;
|
|
}
|
|
}
|
}
|
}
|
|
|
} // namespace debugger
|
} // namespace debugger
|
|
|
No newline at end of file
|
No newline at end of file
|