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)
50 class cl_cmd_arg *params[4]= { cmdline->param(0),
57 con->dd_printf("Timer id is missing.");
60 if (params[0]->as_number())
63 id_nr= params[0]->value.number;
66 con->dd_printf("Error: "
67 "Timer id must be greater than zero or a string\n");
70 ticker= uc->get_counter(id_nr);
75 id_str= params[0]->s_value;
76 ticker= uc->get_counter(id_str);
85 *-----------------------------------------------------------------------------
86 * Add a new timer to the list
89 COMMAND_DO_WORK_UC(cl_timer_add_cmd)
90 //add(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con)
92 class cl_cmd_arg *params[4]= { cmdline->param(0),
96 long dir= +1, in_isr= 0;
98 if (cl_timer_cmd::do_work(uc, cmdline, con))
103 con->dd_printf("Error: Timer \"%s\" already exists\n", id_str);
105 con->dd_printf("Error: Timer %d already exists\n", id_nr);
109 if (cmdline->nuof_params() > 0)
111 if (cmdline->syntax_match(uc, NUMBER))
112 dir= params[0]->value.number;
113 else if (cmdline->syntax_match(uc, NUMBER NUMBER))
115 dir= params[0]->value.number;
116 in_isr= params[1]->value.number;
122 ticker= new cl_ticker(dir, in_isr, id_str);
123 uc->add_counter(ticker, id_str);
127 ticker= new cl_ticker(dir, in_isr, 0);
128 uc->add_counter(ticker, id_nr);
135 * Command: timer delete
136 *-----------------------------------------------------------------------------
137 * Delete a timer from the list
140 COMMAND_DO_WORK_UC(cl_timer_delete_cmd)
141 //del(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con)
143 if (cl_timer_cmd::do_work(uc, cmdline, con))
148 con->dd_printf("Timer \"%s\" does not exist\n", id_str);
150 con->dd_printf("Timer %d does not exist\n", id_nr);
154 uc->del_counter(id_str);
156 uc->del_counter(id_nr);
163 *-----------------------------------------------------------------------------
164 * Get the value of just one timer or all of them
167 COMMAND_DO_WORK_UC(cl_timer_get_cmd)
168 //get(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con)
170 if (cmdline->nuof_params())
172 if (cl_timer_cmd::do_work(uc, cmdline, con))
178 ticker->dump(id_nr, uc->xtal, con);
181 uc->ticks->dump(0, uc->xtal, con);
182 uc->isr_ticks->dump(0, uc->xtal, con);
183 uc->idle_ticks->dump(0, uc->xtal, con);
184 for (id_nr= 0; id_nr < uc->counters->count; id_nr++)
186 ticker= uc->get_counter(id_nr);
188 ticker->dump(id_nr, uc->xtal, con);
197 *-----------------------------------------------------------------------------
198 * Allow a timer to run
201 COMMAND_DO_WORK_UC(cl_timer_run_cmd)
202 //run(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con)
204 if (cl_timer_cmd::do_work(uc, cmdline, con))
209 con->dd_printf("Timer %d does not exist\n", id_str);
211 con->dd_printf("Timer %d does not exist\n", id_nr);
214 ticker->options|= TICK_RUN;
220 * Command: timer stop
221 *-----------------------------------------------------------------------------
225 COMMAND_DO_WORK_UC(cl_timer_stop_cmd)
226 //stop(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con)
228 if (cl_timer_cmd::do_work(uc, cmdline, con))
234 con->dd_printf("Timer %d does not exist\n", id_str);
236 con->dd_printf("Timer %d does not exist\n", id_nr);
239 ticker->options&= ~TICK_RUN;
246 * Command: timer value
247 *-----------------------------------------------------------------------------
248 * Set a timer to a specified value
251 COMMAND_DO_WORK_UC(cl_timer_value_cmd)
252 //val(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con)
254 class cl_cmd_arg *params[4]= { cmdline->param(0),
259 if (cl_timer_cmd::do_work(uc, cmdline, con))
264 con->dd_printf("Error: Timer %d does not exist\n", id_str);
266 con->dd_printf("Error: Timer %d does not exist\n", id_nr);
271 con->dd_printf("Error: Value is missing\n");
275 if (!params[2]->get_ivalue(&val))
277 con->dd_printf("Error: Wrong parameter\n");
286 /* End of cmd.src/timer.cc */