litex/milkymist/timer/__init__.py

27 lines
712 B
Python
Raw Normal View History

2012-05-21 13:46:04 -04:00
from migen.fhdl.structure import *
from migen.fhdl.module import Module
2012-05-21 13:46:04 -04:00
from migen.bank.description import *
from migen.bank.eventmanager import *
class Timer(Module, AutoReg):
def __init__(self, width=32):
2013-03-12 10:47:54 -04:00
self._en = RegisterField()
self._value = RegisterField(width, access_dev=READ_WRITE)
self._reload = RegisterField(width)
2012-05-21 13:46:04 -04:00
self.submodules.ev = EventManager()
self.ev.zero = EventSourceLevel()
self.ev.finalize()
###
2012-05-21 13:46:04 -04:00
self.comb += [
2012-05-21 13:46:04 -04:00
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.ev.zero.trigger.eq(self._value.field.r != 0)
2012-05-21 13:46:04 -04:00
]