X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=sim%2Fucsim%2Fcmd.src%2Ftimer.cc;h=3f8ad9d7201bd42e116e602c709abe53b1c4aaed;hb=90f4aedaef8a2310573eef905f95c671f84e5cde;hp=694c43da20bfccba0bc9501e14bb91b41cb76cd4;hpb=f27cbdc6513b26748661452e50ed3af99fac16a2;p=fw%2Fsdcc diff --git a/sim/ucsim/cmd.src/timer.cc b/sim/ucsim/cmd.src/timer.cc index 694c43da..3f8ad9d7 100644 --- a/sim/ucsim/cmd.src/timer.cc +++ b/sim/ucsim/cmd.src/timer.cc @@ -34,8 +34,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "simcl.h" // local -#include "cmdsetcl.h" -#include "newcmdcl.h" +#include "timercl.h" /* @@ -43,238 +42,239 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA *---------------------------------------------------------------------------- */ -int -cl_timer_cmd::do_work(class cl_sim *sim, - class cl_cmdline *cmdline, class cl_console *con) +//int +//cl_timer_cmd::do_work(class cl_sim *sim, +// class cl_cmdline *cmdline, class cl_console_base *con) +COMMAND_DO_WORK_UC(cl_timer_cmd) { - char *s; - - if (cmdline->param(0) == 0) + class cl_cmd_arg *params[4]= { cmdline->param(0), + cmdline->param(1), + cmdline->param(2), + cmdline->param(3) }; + + if (!params[0]) { - if (long_help) - con->printf("%s\n", long_help); - else - con->printf("What to do?\n"); - return(0); + con->dd_printf("Timer id is missing."); + return(DD_FALSE); } - if ((s= cmdline->param(0)->get_svalue())) + if (params[0]->as_number()) { - if (cmdline->param(1) == 0) - { - con->printf("Timer number is missing\n"); - return(0); - } - set_ticker(sim, cmdline->param(1)); - if (strstr(s, "c") == s || - strstr(s, "m") == s || - strstr(s, "a") == s) - return(add(sim, cmdline, con)); - else if (strstr(s, "d") == s) - return(del(sim, cmdline, con)); - else if (strstr(s, "g") == s) - return(get(sim, cmdline, con)); - else if (strstr(s, "r") == s) - return(run(sim, cmdline, con)); - else if (strstr(s, "s") == s) - return(stop(sim, cmdline, con)); - else if (strstr(s, "v") == s) - return(val(sim, cmdline, con)); - else - con->printf("Undefined timer command: \"%s\". Try \"help timer\"\n", - s); + as_nr= DD_TRUE; + id_nr= params[0]->value.number; + if (id_nr <= 0) + { + con->dd_printf("Error: " + "Timer id must be greater than zero or a string\n"); + return(DD_TRUE); + } + ticker= uc->get_counter(id_nr); } - return(0); -} - -void -cl_timer_cmd::set_ticker(class cl_sim *sim, - class cl_cmd_arg *param) -{ - if ((name= param->get_svalue())) - ticker= sim->uc->get_counter(name); else - if (param->get_ivalue(&what)) - ticker= sim->uc->get_counter(what); + { + as_nr= DD_FALSE; + id_str= params[0]->s_value; + ticker= uc->get_counter(id_str); + } + cmdline->shift(); + return(DD_FALSE); } + /* + * Command: timer add + *----------------------------------------------------------------------------- * Add a new timer to the list */ -int -cl_timer_cmd::add(class cl_sim *sim, - class cl_cmdline *cmdline, class cl_console *con) +COMMAND_DO_WORK_UC(cl_timer_add_cmd) + //add(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console_base *con) { class cl_cmd_arg *params[4]= { cmdline->param(0), - cmdline->param(1), - cmdline->param(2), - cmdline->param(3) }; + cmdline->param(1), + cmdline->param(2), + cmdline->param(3) }; long dir= +1, in_isr= 0; - - if (!name && - what < 1) + + if (cl_timer_cmd::do_work(uc, cmdline, con)) + return(DD_FALSE); + if (ticker) { - con->printf("Error: Timer id must be greater then zero or a string\n"); + if (!as_nr) + con->dd_printf("Error: Timer \"%s\" already exists\n", id_str); + else + con->dd_printf("Error: Timer %d already exists\n", id_nr); return(DD_FALSE); } - if (ticker) + + if (cmdline->nuof_params() > 0) { - if (name) - con->printf("Error: Timer \"%s\" already exists\n", name); - else - con->printf("Error: Timer %d already exists\n", what); - return(0); + if (cmdline->syntax_match(uc, NUMBER)) + dir= params[0]->value.number; + else if (cmdline->syntax_match(uc, NUMBER NUMBER)) + { + dir= params[0]->value.number; + in_isr= params[1]->value.number; + } } - if (params[2]) - if (!params[2]->get_ivalue(&dir)) - { - con->printf("Error: Wrong direction\n"); - return(DD_FALSE); - } - if (params[3]) - if (!params[3]->get_ivalue(&in_isr)) - { - con->printf("Error: Wrong parameter\n"); - return(DD_FALSE); - } - - if (name) + + if (!as_nr) { - ticker= new cl_ticker(dir, in_isr, name); - sim->uc->add_counter(ticker, name); + ticker= new cl_ticker(dir, in_isr, id_str); + uc->add_counter(ticker, id_str); } else { ticker= new cl_ticker(dir, in_isr, 0); - sim->uc->add_counter(ticker, what); + uc->add_counter(ticker, id_nr); } return(DD_FALSE); } /* + * Command: timer delete + *----------------------------------------------------------------------------- * Delete a timer from the list */ -int -cl_timer_cmd::del(class cl_sim *sim, - class cl_cmdline *cmdline, class cl_console *con) +COMMAND_DO_WORK_UC(cl_timer_delete_cmd) + //del(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console_base *con) { + if (cl_timer_cmd::do_work(uc, cmdline, con)) + return(DD_FALSE); if (!ticker) { - if (name) - con->printf("Timer \"%s\" does not exist\n", name); + if (!as_nr) + con->dd_printf("Timer \"%s\" does not exist\n", id_str); else - con->printf("Timer %d does not exist\n", what); - return(0); + con->dd_printf("Timer %d does not exist\n", id_nr); + return(DD_FALSE); } - if (name) - sim->uc->del_counter(name); + if (!as_nr) + uc->del_counter(id_str); else - sim->uc->del_counter(what); + uc->del_counter(id_nr); - return(0); + return(DD_FALSE); } /* + * Command: timer get + *----------------------------------------------------------------------------- * Get the value of just one timer or all of them */ -int -cl_timer_cmd::get(class cl_sim *sim, - class cl_cmdline *cmdline, class cl_console *con) +COMMAND_DO_WORK_UC(cl_timer_get_cmd) + //get(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console_base *con) { + if (cmdline->nuof_params()) + { + if (cl_timer_cmd::do_work(uc, cmdline, con)) + return(DD_FALSE); + } + else + ticker= 0; if (ticker) - ticker->dump(what, sim->uc->xtal, con); + ticker->dump(id_nr, uc->xtal, con); else { - sim->uc->ticks->dump(0, sim->uc->xtal, con); - sim->uc->isr_ticks->dump(0, sim->uc->xtal, con); - sim->uc->idle_ticks->dump(0, sim->uc->xtal, con); - for (what= 0; what < sim->uc->counters->count; what++) - { - ticker= sim->uc->get_counter(what); - if (ticker) - ticker->dump(what, sim->uc->xtal, con); - } + uc->ticks->dump(0, uc->xtal, con); + uc->isr_ticks->dump(0, uc->xtal, con); + uc->idle_ticks->dump(0, uc->xtal, con); + for (id_nr= 0; id_nr < uc->counters->count; id_nr++) + { + ticker= uc->get_counter(id_nr); + if (ticker) + ticker->dump(id_nr, uc->xtal, con); + } } - return(0); + return(DD_FALSE); } /* + * Command: timer run + *----------------------------------------------------------------------------- * Allow a timer to run */ -int -cl_timer_cmd::run(class cl_sim *sim, - class cl_cmdline *cmdline, class cl_console *con) +COMMAND_DO_WORK_UC(cl_timer_run_cmd) + //run(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console_base *con) { + if (cl_timer_cmd::do_work(uc, cmdline, con)) + return(DD_FALSE); if (!ticker) { - if (name) - con->printf("Timer %d does not exist\n", name); + if (!as_nr) + con->dd_printf("Timer %d does not exist\n", id_str); else - con->printf("Timer %d does not exist\n", what); + con->dd_printf("Timer %d does not exist\n", id_nr); return(0); } ticker->options|= TICK_RUN; - return(0); + return(DD_FALSE); } /* + * Command: timer stop + *----------------------------------------------------------------------------- * Stop a timer */ -int -cl_timer_cmd::stop(class cl_sim *sim, - class cl_cmdline *cmdline, class cl_console *con) +COMMAND_DO_WORK_UC(cl_timer_stop_cmd) + //stop(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console_base *con) { + if (cl_timer_cmd::do_work(uc, cmdline, con)) + return(DD_FALSE); + if (!ticker) { - if (name) - con->printf("Timer %d does not exist\n", name); + if (!as_nr) + con->dd_printf("Timer %d does not exist\n", id_str); else - con->printf("Timer %d does not exist\n", what); - return(0); + con->dd_printf("Timer %d does not exist\n", id_nr); + return(DD_FALSE); } ticker->options&= ~TICK_RUN; - return(0); + return(DD_FALSE); } /* + * Command: timer value + *----------------------------------------------------------------------------- * Set a timer to a specified value */ -int -cl_timer_cmd::val(class cl_sim *sim, - class cl_cmdline *cmdline, class cl_console *con) +COMMAND_DO_WORK_UC(cl_timer_value_cmd) + //val(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console_base *con) { class cl_cmd_arg *params[4]= { cmdline->param(0), - cmdline->param(1), - cmdline->param(2), - cmdline->param(3) }; + cmdline->param(1), + cmdline->param(2), + cmdline->param(3) }; + if (cl_timer_cmd::do_work(uc, cmdline, con)) + return(DD_FALSE); if (!ticker) { - if (name) - con->printf("Error: Timer %d does not exist\n", name); + if (!as_nr) + con->dd_printf("Error: Timer %d does not exist\n", id_str); else - con->printf("Error: Timer %d does not exist\n", what); - return(0); + con->dd_printf("Error: Timer %d does not exist\n", id_nr); + return(DD_FALSE); } if (params[2]) { - con->printf("Error: Value is missing\n"); + con->dd_printf("Error: Value is missing\n"); return(DD_FALSE); } long val; if (!params[2]->get_ivalue(&val)) { - con->printf("Error: Wrong parameter\n"); + con->dd_printf("Error: Wrong parameter\n"); return(DD_FALSE); } ticker->ticks= val;