[ucsim] Update email and file info, fix stm8 flash controller
[sdcc.git] / sdcc / sim / ucsim / src / sims / s51.src / wdt.cc
blob2b302e5951117d6fd23c56f3f1a05cb14c910391
1 /*
2 * Simulator of microcontrollers (wdt.cc)
4 * Copyright (C) 1999 Drotos Daniel
5 *
6 * To contact author send email to dr.dkdb@gmail.com
8 */
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
25 02111-1307, USA. */
26 /*@1@*/
28 #include <stdio.h>
29 //#include <ctype.h>
31 // local
32 #include "wdtcl.h"
33 #include "regs51.h"
36 cl_wdt::cl_wdt(class cl_uc *auc, long resetvalue):
37 cl_hw(auc, HW_WDT, 0, "wdt")
39 reset_value= resetvalue;
40 wdt= -1;
41 written_since_reset= false;
44 int
45 cl_wdt::init(void)
47 class cl_address_space *sfr= uc->address_space(MEM_SFR_ID);
49 cl_hw::init();
50 if (!sfr)
52 fprintf(stderr, "No SFR to register WDT into\n");
54 wdtrst= register_cell(sfr, WDTRST);
55 return(0);
58 void
59 cl_wdt::write(class cl_memory_cell *cell, t_mem *val)
61 if (cell == wdtrst &&
62 (((*val)&0xff) == 0xe1) &&
63 (wdtrst->get() == 0x1e) &&
64 written_since_reset)
66 wdt= 0;
68 written_since_reset= true;
71 int
72 cl_wdt::tick(int cycles)
74 if (wdt >= 0)
76 wdt+= cycles;
77 if (wdt > reset_value)
79 uc->reset();
80 //return(resWDTRESET);
83 return(0);
86 void
87 cl_wdt::reset(void)
89 written_since_reset= false;
90 wdt= -1;
93 void
94 cl_wdt::print_info(class cl_console_base *con)
96 con->dd_printf("%s[%d] %s counter=%d (remains=%d)\n", id_string, id,
97 (wdt>=0)?"ON":"OFF", wdt, (wdt>=0)?(reset_value-wdt):0);
98 //print_cfg_info(con);
102 /* End of s51.src/wdt.cc */