Lines Matching +full:led +full:-

26 #include "hw/misc/mps2-fpgaio.h"
27 #include "hw/misc/led.h"
28 #include "hw/qdev-properties.h"
44 return muldiv64(now - tick_offset, frq, NANOSECONDS_PER_SECOND); in counter_from_tickoff()
49 return now - muldiv64(count, NANOSECONDS_PER_SECOND, frq); in tickoff_from_counter()
55 * Update s->counter and s->pscntr to their true current values in resync_counter()
60 int64_t elapsed = now - s->pscntr_sync_ticks; in resync_counter()
66 uint64_t ticks = muldiv64(elapsed, s->prescale_clk, NANOSECONDS_PER_SECOND); in resync_counter()
70 * PSCNTR reloads from PRESCALE one tick-period after it hits zero, in resync_counter()
76 } else if (ticks < s->pscntr) { in resync_counter()
78 s->pscntr -= ticks; in resync_counter()
80 if (s->prescale == 0) { in resync_counter()
86 s->counter += ticks - s->pscntr; in resync_counter()
87 s->pscntr = 0; in resync_counter()
99 * where x = y % (s->prescale + 1) in resync_counter()
100 * and so PSCNTR = s->prescale - x in resync_counter()
101 * and COUNTER is incremented by y / (s->prescale + 1) in resync_counter()
104 * though we must be careful to calculate y as 64-bit unsigned in resync_counter()
106 * y < 0 is not possible because that implies ticks < s->pscntr. in resync_counter()
108 uint64_t y = ticks - s->pscntr + s->prescale; in resync_counter()
109 s->pscntr = s->prescale - (y % (s->prescale + 1)); in resync_counter()
110 s->counter += y / (s->prescale + 1); in resync_counter()
119 s->pscntr_sync_ticks += muldiv64(ticks, NANOSECONDS_PER_SECOND, in resync_counter()
120 s->prescale_clk); in resync_counter()
131 r = s->led0; in mps2_fpgaio_read()
134 if (!s->has_dbgctrl) { in mps2_fpgaio_read()
137 r = s->dbgctrl; in mps2_fpgaio_read()
140 /* User-pressable board buttons. We don't model that, so just return in mps2_fpgaio_read()
146 r = s->prescale; in mps2_fpgaio_read()
149 r = s->misc; in mps2_fpgaio_read()
153 r = counter_from_tickoff(now, s->clk1hz_tick_offset, 1); in mps2_fpgaio_read()
157 r = counter_from_tickoff(now, s->clk100hz_tick_offset, 100); in mps2_fpgaio_read()
161 r = s->counter; in mps2_fpgaio_read()
165 r = s->pscntr; in mps2_fpgaio_read()
168 if (!s->has_switches) { in mps2_fpgaio_read()
171 /* User-togglable board switches. We don't model that, so report 0. */ in mps2_fpgaio_read()
196 if (s->num_leds != 0) { in mps2_fpgaio_write()
199 s->led0 = value & MAKE_64BIT_MASK(0, s->num_leds); in mps2_fpgaio_write()
200 for (i = 0; i < s->num_leds; i++) { in mps2_fpgaio_write()
201 led_set_state(s->led[i], extract64(value, i, 1)); in mps2_fpgaio_write()
206 if (!s->has_dbgctrl) { in mps2_fpgaio_write()
211 s->dbgctrl = value; in mps2_fpgaio_write()
215 s->prescale = value; in mps2_fpgaio_write()
224 s->misc = value; in mps2_fpgaio_write()
228 s->clk1hz_tick_offset = tickoff_from_counter(now, value, 1); in mps2_fpgaio_write()
232 s->clk100hz_tick_offset = tickoff_from_counter(now, value, 100); in mps2_fpgaio_write()
236 s->counter = value; in mps2_fpgaio_write()
240 s->pscntr = value; in mps2_fpgaio_write()
262 s->led0 = 0; in mps2_fpgaio_reset()
263 s->prescale = 0; in mps2_fpgaio_reset()
264 s->misc = 0; in mps2_fpgaio_reset()
265 s->clk1hz_tick_offset = tickoff_from_counter(now, 0, 1); in mps2_fpgaio_reset()
266 s->clk100hz_tick_offset = tickoff_from_counter(now, 0, 100); in mps2_fpgaio_reset()
267 s->counter = 0; in mps2_fpgaio_reset()
268 s->pscntr = 0; in mps2_fpgaio_reset()
269 s->pscntr_sync_ticks = now; in mps2_fpgaio_reset()
271 for (size_t i = 0; i < s->num_leds; i++) { in mps2_fpgaio_reset()
272 device_cold_reset(DEVICE(s->led[i])); in mps2_fpgaio_reset()
281 memory_region_init_io(&s->iomem, obj, &mps2_fpgaio_ops, s, in mps2_fpgaio_init()
282 "mps2-fpgaio", 0x1000); in mps2_fpgaio_init()
283 sysbus_init_mmio(sbd, &s->iomem); in mps2_fpgaio_init()
291 if (s->num_leds > MPS2FPGAIO_MAX_LEDS) { in mps2_fpgaio_realize()
292 error_setg(errp, "num-leds cannot be greater than %d", in mps2_fpgaio_realize()
297 for (i = 0; i < s->num_leds; i++) { in mps2_fpgaio_realize()
299 s->led[i] = led_create_simple(OBJECT(dev), GPIO_POLARITY_ACTIVE_HIGH, in mps2_fpgaio_realize()
305 .name = "mps2-fpgaio",
324 DEFINE_PROP_UINT32("prescale-clk", MPS2FPGAIO, prescale_clk, 20000000),
326 DEFINE_PROP_UINT32("num-leds", MPS2FPGAIO, num_leds, 2),
327 DEFINE_PROP_BOOL("has-switches", MPS2FPGAIO, has_switches, false),
328 DEFINE_PROP_BOOL("has-dbgctrl", MPS2FPGAIO, has_dbgctrl, false),
335 dc->vmsd = &mps2_fpgaio_vmstate; in mps2_fpgaio_class_init()
336 dc->realize = mps2_fpgaio_realize; in mps2_fpgaio_class_init()