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->printf("%s\n", long_help);
57 con->printf("What to do?\n");
60 if ((s= cmdline->param(0)->get_svalue()))
62 if (cmdline->param(1) == 0)
64 con->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->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->printf("Error: Timer id must be greater then zero or a string\n");
123 con->printf("Error: Timer \"%s\" already exists\n", name);
125 con->printf("Error: Timer %d already exists\n", what);
129 if (!params[2]->get_ivalue(&dir))
131 con->printf("Error: Wrong direction\n");
135 if (!params[3]->get_ivalue(&in_isr))
137 con->printf("Error: Wrong parameter\n");
143 ticker= new cl_ticker(dir, in_isr, name);
144 uc->add_counter(ticker, name);
148 ticker= new cl_ticker(dir, in_isr, 0);
149 uc->add_counter(ticker, what);
156 * Delete a timer from the list
160 cl_timer_cmd::del(class cl_uc *uc,
161 class cl_cmdline *cmdline, class cl_console *con)
166 con->printf("Timer \"%s\" does not exist\n", name);
168 con->printf("Timer %d does not exist\n", what);
172 uc->del_counter(name);
174 uc->del_counter(what);
180 * Get the value of just one timer or all of them
184 cl_timer_cmd::get(class cl_uc *uc,
185 class cl_cmdline *cmdline, class cl_console *con)
188 ticker->dump(what, uc->xtal, con);
191 uc->ticks->dump(0, uc->xtal, con);
192 uc->isr_ticks->dump(0, uc->xtal, con);
193 uc->idle_ticks->dump(0, uc->xtal, con);
194 for (what= 0; what < uc->counters->count; what++)
196 ticker= uc->get_counter(what);
198 ticker->dump(what, uc->xtal, con);
206 * Allow a timer to run
210 cl_timer_cmd::run(class cl_uc *uc,
211 class cl_cmdline *cmdline, class cl_console *con)
216 con->printf("Timer %d does not exist\n", name);
218 con->printf("Timer %d does not exist\n", what);
221 ticker->options|= TICK_RUN;
231 cl_timer_cmd::stop(class cl_uc *uc,
232 class cl_cmdline *cmdline, class cl_console *con)
237 con->printf("Timer %d does not exist\n", name);
239 con->printf("Timer %d does not exist\n", what);
242 ticker->options&= ~TICK_RUN;
249 * Set a timer to a specified value
253 cl_timer_cmd::val(class cl_uc *uc,
254 class cl_cmdline *cmdline, class cl_console *con)
256 class cl_cmd_arg *params[4]= { cmdline->param(0),
264 con->printf("Error: Timer %d does not exist\n", name);
266 con->printf("Error: Timer %d does not exist\n", what);
271 con->printf("Error: Value is missing\n");
275 if (!params[2]->get_ivalue(&val))
277 con->printf("Error: Wrong parameter\n");
286 /* End of cmd.src/timer.cc */