2 * Simulator of microcontrollers (wdt.cc)
4 * Copyright (C) 2024 Drotos Daniel
6 * To contact author send email to dr.dkdb@gmail.com
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
33 cl_wdt::cl_wdt(class cl_uc
*auc
, const char *aname
):
34 cl_hw(auc
, HW_TIMER
, 0, aname
)
36 puc
= (class cl_pdk
*)auc
;
42 mod
= register_cell(puc
->sfr
, 3);
43 misc
= register_cell(puc
->sfr
, 0x49);
45 uc
->mk_mvar(cfg
, wdt_cnt
, "WDT", cfg_help(wdt_cnt
));
51 cl_wdt::cfg_help(t_addr addr
)
53 switch ((enum wdt_cfg
)addr
)
55 case wdt_on
: return "Turn ticking of WDT on/off (bool, RW)";
56 case wdt_cnt
: return "WDT counter value (RW)";
57 case wdt_nuof
: return "";
85 case 0: len
= 8192; break;
86 case 1: len
= 16384; break;
87 case 2: len
= 65536; break;
88 case 3: len
= 262144; break;
93 cl_wdt::write(class cl_memory_cell
*cell
, t_mem
*val
)
99 if ((*val
& 0xff) != cell
->get())
105 else if (cell
== misc
)
107 if ((*val
& 0xff) != cell
->get())
113 /*else if (cell == irq)
120 cl_wdt::conf_op(cl_memory_cell
*cell
, t_addr addr
, t_mem
*val
)
124 case wdt_on
: // turn this HW on/off
132 cnt
= *val
& 0xffffff;
141 cl_wdt::tick(int cycles
)
143 t_mem act
= puc
->osc
->ilrc
;
144 if (run
&& (act
!= last
))
146 int d
= act
- last
, i
;
160 cl_wdt::print_info(class cl_console_base
*con
)
162 con
->dd_printf("WDT run=%s len=%u\n",
163 run
?"YES":"NO", MU(len
));
164 con
->dd_printf("cnt= %6u 0x%08x\n", MU(cnt
), MU(cnt
));
168 /* End of pdk.src/wdt.cc */