2 * Simulator of microcontrollers (interrupt.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
35 #include "interruptcl.h"
41 cl_interrupt::cl_interrupt(class cl_uc *auc):
42 cl_hw(auc, HW_INTERRUPT, 0, "irq")
48 cl_interrupt::init(void)
52 sfr= uc->mem(MEM_SFR);
55 //sfr->register_hw(IE, this, 0);
56 register_cell(sfr, IE, 0, wtd_restore);
57 register_cell(sfr, TCON, &cell_tcon, wtd_restore_write);
58 bit_INT0= sfr->read(P3) & bm_INT0;
59 bit_INT1= sfr->read(P3) & bm_INT1;
65 cl_interrupt::added_to_uc(void)
67 uc->it_sources->add(new cl_it_src(bmEX0, TCON, bmIE0, 0x0003, true,
69 uc->it_sources->add(new cl_it_src(bmEX1, TCON, bmIE1, 0x0013, true,
74 cl_interrupt::write(class cl_cell *cell, t_mem *val)
76 if (cell == cell_tcon)
78 bit_IT0= *val & bmIT0;
79 bit_IT1= *val & bmIT1;
87 cl_interrupt::mem_cell_changed(class cl_mem *mem, t_addr addr)
92 cl_interrupt::tick(int cycles)
94 if (!bit_IT0 && !bit_INT0)
95 cell_tcon->set_bit1(bmIE0);
96 if (!bit_IT1 && !bit_INT1)
97 cell_tcon->set_bit1(bmIE1);
102 cl_interrupt::reset(void)
108 cl_interrupt::happen(class cl_hw *where, enum hw_event he, void *params)
110 struct ev_port_changed *ep= (struct ev_port_changed *)params;
112 if (where->cathegory == HW_PORT &&
113 he == EV_PORT_CHANGED &&
116 t_mem p3n= ep->new_pins & ep->new_value;
117 t_mem p3o= ep->pins & ep->prev_value;
121 cell_tcon->set_bit1(bmIE0);
125 cell_tcon->set_bit1(bmIE1);
126 bit_INT0= p3n & bm_INT0;
127 bit_INT1= p3n & bm_INT1;
133 cl_interrupt::print_info(class cl_console *con)
135 int ie= uc->get_mem(MEM_SFR, IE);
138 con->dd_printf("Interrupts are %s. Interrupt sources:\n",
139 (ie&bmEA)?"enabled":"disabled");
140 con->dd_printf(" Handler En Pr Req Act Name\n");
141 for (i= 0; i < uc->it_sources->count; i++)
143 class cl_it_src *is= (class cl_it_src *)(uc->it_sources->at(i));
144 con->dd_printf(" 0x%06x", is->addr);
145 con->dd_printf(" %-3s", (ie&(is->ie_mask))?"en":"dis");
146 con->dd_printf(" %2d", uc->it_priority(is->ie_mask));
147 con->dd_printf(" %-3s",
148 (uc->get_mem(MEM_SFR, is->src_reg)&(is->src_mask))?
150 con->dd_printf(" %-3s", (is->active)?"act":"no");
151 con->dd_printf(" %s", object_name(is));
152 con->dd_printf("\n");
154 con->dd_printf("Active interrupt service(s):\n");
155 con->dd_printf(" Pr Handler PC Source\n");
156 for (i= 0; i < uc->it_levels->count; i++)
158 class it_level *il= (class it_level *)(uc->it_levels->at(i));
161 con->dd_printf(" %2d", il->level);
162 con->dd_printf(" 0x%06x", il->addr);
163 con->dd_printf(" 0x%06x", il->PC);
164 con->dd_printf(" %s", (il->source)?(object_name(il->source)):
166 con->dd_printf("\n");
172 /* End of s51.src/interrupt.cc */