1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
|
/*
* Simulator of microcontrollers (cmd.src/timer.cc)
*
* Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
*
* To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
*
*/
/* This file is part of microcontroller simulator: ucsim.
UCSIM is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
UCSIM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with UCSIM; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
/*@1@*/
#include "ddconfig.h"
#include "stdio.h"
#include "i_string.h"
// sim
#include "simcl.h"
// local
#include "cmd_timercl.h"
/*
* Command: timer
*----------------------------------------------------------------------------
*/
//int
//cl_timer_cmd::do_work(class cl_sim *sim,
// class cl_cmdline *cmdline, class cl_console *con)
COMMAND_DO_WORK_UC(cl_timer_cmd)
{
class cl_cmd_arg *params[4]= { cmdline->param(0),
cmdline->param(1),
cmdline->param(2),
cmdline->param(3) };
if (!params[0])
{
con->dd_printf("Timer id is missing.");
return(false);
}
if (params[0]->as_number())
{
as_nr= 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(true);
}
ticker= uc->get_counter(id_nr);
}
else
{
as_nr= false;
id_str= params[0]->s_value;
ticker= uc->get_counter(id_str);
}
cmdline->shift();
return(false);
}
/*
* Command: timer add
*-----------------------------------------------------------------------------
* Add a new timer to the list
*/
COMMAND_DO_WORK_UC(cl_timer_add_cmd)
//add(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con)
{
class cl_cmd_arg *params[4]= { cmdline->param(0),
cmdline->param(1),
cmdline->param(2),
cmdline->param(3) };
long dir= +1, in_isr= 0;
if (cl_timer_cmd::do_work(uc, cmdline, con))
return(false);
if (ticker)
{
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(false);
}
if (cmdline->nuof_params() > 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 (!as_nr)
{
ticker= new cl_ticker(dir, in_isr, id_str);
uc->add_counter(ticker, id_str);
}
else
{
ticker= new cl_ticker(dir, in_isr, 0);
uc->add_counter(ticker, id_nr);
}
return(false);
}
/*
* Command: timer delete
*-----------------------------------------------------------------------------
* Delete a timer from the list
*/
COMMAND_DO_WORK_UC(cl_timer_delete_cmd)
//del(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con)
{
if (cl_timer_cmd::do_work(uc, cmdline, con))
return(false);
if (!ticker)
{
if (!as_nr)
con->dd_printf("Timer \"%s\" does not exist\n", id_str);
else
con->dd_printf("Timer %d does not exist\n", id_nr);
return(false);
}
if (!as_nr)
uc->del_counter(id_str);
else
uc->del_counter(id_nr);
return(false);
}
/*
* Command: timer get
*-----------------------------------------------------------------------------
* Get the value of just one timer or all of them
*/
COMMAND_DO_WORK_UC(cl_timer_get_cmd)
//get(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con)
{
if (cmdline->nuof_params())
{
if (cl_timer_cmd::do_work(uc, cmdline, con))
return(false);
}
else
ticker= 0;
if (ticker)
ticker->dump(id_nr, uc->xtal, con);
else
{
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(false);
}
/*
* Command: timer run
*-----------------------------------------------------------------------------
* Allow a timer to run
*/
COMMAND_DO_WORK_UC(cl_timer_run_cmd)
//run(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con)
{
if (cl_timer_cmd::do_work(uc, cmdline, con))
return(false);
if (!ticker)
{
if (!as_nr)
con->dd_printf("Timer %d does not exist\n", id_str);
else
con->dd_printf("Timer %d does not exist\n", id_nr);
return(0);
}
ticker->options|= TICK_RUN;
return(false);
}
/*
* Command: timer stop
*-----------------------------------------------------------------------------
* Stop a timer
*/
COMMAND_DO_WORK_UC(cl_timer_stop_cmd)
//stop(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con)
{
if (cl_timer_cmd::do_work(uc, cmdline, con))
return(false);
if (!ticker)
{
if (!as_nr)
con->dd_printf("Timer %d does not exist\n", id_str);
else
con->dd_printf("Timer %d does not exist\n", id_nr);
return(false);
}
ticker->options&= ~TICK_RUN;
return(false);
}
/*
* Command: timer value
*-----------------------------------------------------------------------------
* Set a timer to a specified value
*/
COMMAND_DO_WORK_UC(cl_timer_value_cmd)
//val(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con)
{
class cl_cmd_arg *params[4]= { cmdline->param(0),
cmdline->param(1),
cmdline->param(2),
cmdline->param(3) };
if (cl_timer_cmd::do_work(uc, cmdline, con))
return(false);
if (!ticker)
{
if (!as_nr)
con->dd_printf("Error: Timer %d does not exist\n", id_str);
else
con->dd_printf("Error: Timer %d does not exist\n", id_nr);
return(false);
}
if (params[2])
{
con->dd_printf("Error: Value is missing\n");
return(false);
}
long val;
if (!params[2]->get_ivalue(&val))
{
con->dd_printf("Error: Wrong parameter\n");
return(false);
}
ticker->ticks= val;
return(false);
}
/* End of cmd.src/cmd_timer.cc */
|