4 Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
6 This file is part of simavr.
8 simavr is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 simavr is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with simavr. If not, see <http://www.gnu.org/licenses/>.
29 static avr_cycle_count_t
30 heatpot_evaluate_timer(
32 avr_cycle_count_t when,
35 heatpot_p p = (heatpot_p) param;
36 return when + p->cycle;
40 heatpot_tally_in_hook(
41 struct avr_irq_t * irq,
45 heatpot_p p = (heatpot_p)param;
46 heatpot_data_t v = {.v = value };
48 heatpot_tally(p, v.sid, v.cost);
51 static const char * irq_names[IRQ_HEATPOT_COUNT] = {
52 [IRQ_HEATPOT_TALLY] = "8<heatpot.tally",
63 strcpy(p->name, (char*)name);
64 p->irq = avr_alloc_irq(&avr->irq_pool, 0, IRQ_HEATPOT_COUNT, irq_names);
65 avr_irq_register_notify(p->irq + IRQ_HEATPOT_TALLY, heatpot_tally_in_hook, p);
67 p->cycle = avr_usec_to_cycles(avr, 100000 / 1000);
68 avr_cycle_timer_register_usec(avr, p->cycle, heatpot_evaluate_timer, p);
79 for (int si = 0; si < 32 && f == -1; si++)
80 if (p->tally[si].sid == 0)
82 else if (p->tally[si].sid == sid)
86 printf("%s(%s) no room for extra tally source id %d\n", __func__, p->name, sid);
91 p->tally[f].sid = sid;
92 p->tally[f].cost = cost;