-
Notifications
You must be signed in to change notification settings - Fork 85
/
__init__.py
30 lines (26 loc) · 929 Bytes
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from migen.fhdl.structure import *
from migen.bank.description import *
from migen.bank.eventmanager import *
from migen.bank import csrgen
class Timer:
def __init__(self, address, width=32):
self._en = RegisterField("en")
self._value = RegisterField("value", width, access_dev=READ_WRITE)
self._reload = RegisterField("reload", width)
regs = [self._en, self._value, self._reload]
self.event = EventSourceLevel()
self.events = EventManager(self.event)
self.bank = csrgen.Bank(regs + self.events.get_registers(), address=address)
def get_fragment(self):
comb = [
If(self._value.field.r == 0,
self._value.field.w.eq(self._reload.field.r)
).Else(
self._value.field.w.eq(self._value.field.r - 1)
),
self._value.field.we.eq(self._en.field.r),
self.event.trigger.eq(self._value.field.r != 0)
]
return Fragment(comb) \
+ self.events.get_fragment() \
+ self.bank.get_fragment()