2 * Simulator of microcontrollers (t16.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
34 cl_t16::cl_t16(class cl_uc
*auc
, const char *aname
):
35 cl_hw(auc
, HW_TIMER
, 0, aname
)
37 puc
= (class cl_pdk
*)auc
;
44 mod
= register_cell(puc
->sfr
, 6);
45 edg
= register_cell(puc
->sfr
, 0xc);
46 irq
= register_cell(puc
->sfr
, 5);
48 uc
->mk_mvar(cfg
, t16_cnt
, "T16", cfg_help(t16_cnt
));
54 cl_t16::cfg_help(t_addr addr
)
56 switch ((enum t16_cfg
)addr
)
58 case t16_on
: return "Turn ticking of T16 on/off (bool, RW)";
59 case t16_cnt
: return "T16 counter value (RW)";
60 case t16_nuof
: return "";
80 case 0: clk_source
="None"; src
= NULL
; break;
81 case 1: clk_source
="SysClk"; src
= &(puc
->osc
->sys
); break;
82 case 2: clk_source
="None"; src
= NULL
; break;
83 case 3: /* TODO PA4 */ clk_source
="PA4"; src
= NULL
; break;
84 case 4: clk_source
="ihrc"; src
= &(puc
->osc
->ihrc
); break;
85 case 5: clk_source
="eosc"; src
= &(puc
->osc
->eosc
); break;
86 case 6: clk_source
="ilrc"; src
= &(puc
->osc
->ilrc
); break;
87 case 7: /* TODO PA0 */ clk_source
="PA0"; src
= NULL
; break;
102 case 0: div
= 1; break;
103 case 1: div
= 4; break;
104 case 2: div
= 16; break;
105 case 3: div
= 64; break;
110 cl_t16::write(class cl_memory_cell
*cell
, t_mem
*val
)
116 if ((*val
& 0xff) != cell
->get())
122 /*else if (cell == egs)
125 /*else if (cell == irq)
132 cl_t16::conf_op(cl_memory_cell
*cell
, t_addr addr
, t_mem
*val
)
136 case t16_on
: // turn this HW on/off
153 cl_t16::tick(int cycles
)
160 int d
= act
- last
, i
;
170 if ((prev
& mask
) != (cnt
& mask
))
172 // 0= rising, 1= falling
173 u8_t edge
= edg
->get() & 0x10;
174 if (( edge
&& !(cnt
& mask
)) ||
175 (!edge
&& (cnt
& mask
)))
177 irq
->write(irq
->get() | 4);
189 cl_t16::print_info(class cl_console_base
*con
)
191 con
->dd_printf("T16 Src=%s/%d pre=%u mask=%04x edge=%s irq=%d\n",
192 clk_source
.c_str(), div
, pre
, mask
,
193 (edg
->get()&0x10)?"fall":"rise",
195 con
->dd_printf("cnt= %5u 0x%04x\n", cnt
, cnt
);
199 /* End of pdk.src/t16.cc */