2 * Simulator of microcontrollers (timer.cc)
4 * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
6 * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
10 /* This file is part of microcontroller simulator: ucsim.
12 UCSIM is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 UCSIM is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with UCSIM; see the file COPYING. If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
43 *----------------------------------------------------------------------------
47 cl_timer_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
51 if (cmdline->param(0) == 0)
54 con->printf("%s\n", long_help);
56 con->printf("What to do?\n");
59 if ((s= cmdline->param(0)->get_svalue()))
61 if (cmdline->param(1) == 0)
63 con->printf("Timer number is missing\n");
66 set_ticker(cmdline->param(1));
67 if (strstr(s, "c") == s ||
68 strstr(s, "m") == s ||
70 return(add(cmdline, con));
71 else if (strstr(s, "d") == s)
72 return(del(cmdline, con));
73 else if (strstr(s, "g") == s)
74 return(get(cmdline, con));
75 else if (strstr(s, "r") == s)
76 return(run(cmdline, con));
77 else if (strstr(s, "s") == s)
78 return(stop(cmdline, con));
79 else if (strstr(s, "v") == s)
80 return(val(cmdline, con));
82 con->printf("Undefined timer command: \"%s\". Try \"help timer\"\n",
89 cl_timer_cmd::set_ticker(class cl_cmd_arg *param)
91 if ((name= param->get_svalue()) == 0)
92 what= param->get_ivalue();
94 ticker= sim->uc->get_counter(name);
96 ticker= sim->uc->get_counter(what);
100 * Add a new timer to the list
104 cl_timer_cmd::add(class cl_cmdline *cmdline, class cl_console *con)
106 class cl_cmd_arg *params[4]= { cmdline->param(0),
110 int dir= +1, in_isr= 0;
115 con->printf("Timer id must be greater then zero or a string\n");
121 con->printf("Timer \"%s\" already exists\n", name);
123 con->printf("Timer %d already exists\n", what);
127 dir= (params[2])->get_ivalue();
129 in_isr= (params[3])->get_ivalue();
133 ticker= new cl_ticker(dir, in_isr, name);
134 sim->uc->add_counter(ticker, name);
138 ticker= new cl_ticker(dir, in_isr, 0);
139 sim->uc->add_counter(ticker, what);
146 * Delete a timer from the list
150 cl_timer_cmd::del(class cl_cmdline *cmdline, class cl_console *con)
155 con->printf("Timer \"%s\" does not exist\n", name);
157 con->printf("Timer %d does not exist\n", what);
161 sim->uc->del_counter(name);
163 sim->uc->del_counter(what);
169 * Get the value of just one timer or all of them
173 cl_timer_cmd::get(class cl_cmdline *cmdline, class cl_console *con)
176 ticker->dump(what, sim->uc->xtal, con);
179 sim->uc->ticks->dump(0, sim->uc->xtal, con);
180 sim->uc->isr_ticks->dump(0, sim->uc->xtal, con);
181 sim->uc->idle_ticks->dump(0, sim->uc->xtal, con);
182 for (what= 0; what < sim->uc->counters->count; what++)
184 ticker= sim->uc->get_counter(what);
186 ticker->dump(what, sim->uc->xtal, con);
194 * Allow a timer to run
198 cl_timer_cmd::run(class cl_cmdline *cmdline, class cl_console *con)
203 con->printf("Timer %d does not exist\n", name);
205 con->printf("Timer %d does not exist\n", what);
208 ticker->options|= TICK_RUN;
218 cl_timer_cmd::stop(class cl_cmdline *cmdline, class cl_console *con)
223 con->printf("Timer %d does not exist\n", name);
225 con->printf("Timer %d does not exist\n", what);
228 ticker->options&= ~TICK_RUN;
235 * Set a timer to a specified value
239 cl_timer_cmd::val(class cl_cmdline *cmdline, class cl_console *con)
241 class cl_cmd_arg *params[4]= { cmdline->param(0),
249 con->printf("Timer %d does not exist\n", name);
251 con->printf("Timer %d does not exist\n", what);
256 con->printf("Value is missing\n");
259 long val= (params[2])->get_ivalue();
266 /* End of timer.cc */