2 * Simulator of microcontrollers (cmd.src/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
42 *----------------------------------------------------------------------------
46 //cl_timer_cmd::do_work(class cl_sim *sim,
47 // class cl_cmdline *cmdline, class cl_console *con)
48 COMMAND_DO_WORK_UC(cl_timer_cmd)
52 if (cmdline->param(0) == 0)
55 con->dd_printf("%s\n", long_help);
57 con->dd_printf("What to do?\n");
60 if ((s= cmdline->param(0)->get_svalue()))
62 if (cmdline->param(1) == 0)
64 con->dd_printf("Timer number is missing\n");
67 set_ticker(uc, cmdline->param(1));
68 if (strstr(s, "c") == s ||
69 strstr(s, "m") == s ||
71 return(add(uc, cmdline, con));
72 else if (strstr(s, "d") == s)
73 return(del(uc, cmdline, con));
74 else if (strstr(s, "g") == s)
75 return(get(uc, cmdline, con));
76 else if (strstr(s, "r") == s)
77 return(run(uc, cmdline, con));
78 else if (strstr(s, "s") == s)
79 return(stop(uc, cmdline, con));
80 else if (strstr(s, "v") == s)
81 return(val(uc, cmdline, con));
83 con->dd_printf("Undefined timer command: \"%s\". Try \"help timer\"\n",
90 cl_timer_cmd::set_ticker(class cl_uc *uc,
91 class cl_cmd_arg *param)
93 if ((name= param->get_svalue()))
94 ticker= uc->get_counter(name);
96 if (param->get_ivalue(&what))
97 ticker= uc->get_counter(what);
101 * Add a new timer to the list
105 cl_timer_cmd::add(class cl_uc *uc,
106 class cl_cmdline *cmdline, class cl_console *con)
108 class cl_cmd_arg *params[4]= { cmdline->param(0),
112 long dir= +1, in_isr= 0;
117 con->dd_printf("Error: "
118 "Timer id must be greater then zero or a string\n");
124 con->dd_printf("Error: Timer \"%s\" already exists\n", name);
126 con->dd_printf("Error: Timer %d already exists\n", what);
130 if (!params[2]->get_ivalue(&dir))
132 con->dd_printf("Error: Wrong direction\n");
136 if (!params[3]->get_ivalue(&in_isr))
138 con->dd_printf("Error: Wrong parameter\n");
144 ticker= new cl_ticker(dir, in_isr, name);
145 uc->add_counter(ticker, name);
149 ticker= new cl_ticker(dir, in_isr, 0);
150 uc->add_counter(ticker, what);
157 * Delete a timer from the list
161 cl_timer_cmd::del(class cl_uc *uc,
162 class cl_cmdline *cmdline, class cl_console *con)
167 con->dd_printf("Timer \"%s\" does not exist\n", name);
169 con->dd_printf("Timer %d does not exist\n", what);
173 uc->del_counter(name);
175 uc->del_counter(what);
181 * Get the value of just one timer or all of them
185 cl_timer_cmd::get(class cl_uc *uc,
186 class cl_cmdline *cmdline, class cl_console *con)
189 ticker->dump(what, uc->xtal, con);
192 uc->ticks->dump(0, uc->xtal, con);
193 uc->isr_ticks->dump(0, uc->xtal, con);
194 uc->idle_ticks->dump(0, uc->xtal, con);
195 for (what= 0; what < uc->counters->count; what++)
197 ticker= uc->get_counter(what);
199 ticker->dump(what, uc->xtal, con);
207 * Allow a timer to run
211 cl_timer_cmd::run(class cl_uc *uc,
212 class cl_cmdline *cmdline, class cl_console *con)
217 con->dd_printf("Timer %d does not exist\n", name);
219 con->dd_printf("Timer %d does not exist\n", what);
222 ticker->options|= TICK_RUN;
232 cl_timer_cmd::stop(class cl_uc *uc,
233 class cl_cmdline *cmdline, class cl_console *con)
238 con->dd_printf("Timer %d does not exist\n", name);
240 con->dd_printf("Timer %d does not exist\n", what);
243 ticker->options&= ~TICK_RUN;
250 * Set a timer to a specified value
254 cl_timer_cmd::val(class cl_uc *uc,
255 class cl_cmdline *cmdline, class cl_console *con)
257 class cl_cmd_arg *params[4]= { cmdline->param(0),
265 con->dd_printf("Error: Timer %d does not exist\n", name);
267 con->dd_printf("Error: Timer %d does not exist\n", what);
272 con->dd_printf("Error: Value is missing\n");
276 if (!params[2]->get_ivalue(&val))
278 con->dd_printf("Error: Wrong parameter\n");
287 /* End of cmd.src/timer.cc */