mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
update driver api
This commit is contained in:
parent
b1cbfe2326
commit
5e48f9c005
6 changed files with 34 additions and 37 deletions
|
@ -15,9 +15,9 @@ miio = miio.MiIo(MIIO_ADDR, 8, "IO", csr)
|
||||||
|
|
||||||
def led_anim0():
|
def led_anim0():
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
miio.write(0xA5)
|
miio.set(0xA5)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
miio.write(0x5A)
|
miio.set(0x5A)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
def led_anim1():
|
def led_anim1():
|
||||||
|
@ -25,13 +25,13 @@ def led_anim1():
|
||||||
#Led <<
|
#Led <<
|
||||||
ledData = 1
|
ledData = 1
|
||||||
for i in range(8):
|
for i in range(8):
|
||||||
miio.write(ledData)
|
miio.set(ledData)
|
||||||
time.sleep(i*i*0.0020)
|
time.sleep(i*i*0.0020)
|
||||||
ledData = (ledData<<1)
|
ledData = (ledData<<1)
|
||||||
#Led >>
|
#Led >>
|
||||||
ledData = 128
|
ledData = 128
|
||||||
for i in range(8):
|
for i in range(8):
|
||||||
miio.write(ledData)
|
miio.set(ledData)
|
||||||
time.sleep(i*i*0.0020)
|
time.sleep(i*i*0.0020)
|
||||||
ledData = (ledData>>1)
|
ledData = (ledData>>1)
|
||||||
|
|
||||||
|
@ -39,11 +39,11 @@ def led_anim1():
|
||||||
# T E S T M I G I O
|
# T E S T M I G I O
|
||||||
#==============================================================================
|
#==============================================================================
|
||||||
|
|
||||||
print("- Small Led Animation...")
|
print("- Led Animation...")
|
||||||
led_anim0()
|
led_anim0()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
led_anim1()
|
led_anim1()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
print("- Read Switch: ",end=' ')
|
print("- Read Switch: ",end=' ')
|
||||||
print("%02X" %miio.read())
|
print("%02X" %miio.get())
|
||||||
|
|
|
@ -35,10 +35,10 @@ def capture(size):
|
||||||
global recorder
|
global recorder
|
||||||
global dat_vcd
|
global dat_vcd
|
||||||
sum_tt = gen_truth_table("term")
|
sum_tt = gen_truth_table("term")
|
||||||
mila.trigger.sum.write(sum_tt)
|
mila.trigger.sum.set(sum_tt)
|
||||||
mila.recorder.reset()
|
mila.recorder.reset()
|
||||||
recorder.size(rec_size)
|
recorder.set_size(rec_size)
|
||||||
mila.recorder.offset(rec_offset)
|
mila.recorder.set_offset(rec_offset)
|
||||||
mila.recorder.arm()
|
mila.recorder.arm()
|
||||||
print("-Recorder [Armed]")
|
print("-Recorder [Armed]")
|
||||||
print("-Waiting Trigger...", end=' ')
|
print("-Waiting Trigger...", end=' ')
|
||||||
|
@ -48,12 +48,12 @@ def capture(size):
|
||||||
|
|
||||||
print("-Receiving Data...", end=' ')
|
print("-Receiving Data...", end=' ')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
dat_vcd += mila.recorder.read(size)
|
dat_vcd += mila.recorder.pull(size)
|
||||||
print("[Done]")
|
print("[Done]")
|
||||||
|
|
||||||
print("Capturing ...")
|
print("Capturing ...")
|
||||||
print("----------------------")
|
print("----------------------")
|
||||||
term.write(0x0000, 0xFFFF)
|
term.set(0x0000, 0xFFFF)
|
||||||
capture(rec_size)
|
capture(rec_size)
|
||||||
|
|
||||||
mila_layout = [
|
mila_layout = [
|
||||||
|
|
|
@ -35,10 +35,10 @@ class MiIo:
|
||||||
|
|
||||||
return Fragment(comb) + self.bank.get_fragment()
|
return Fragment(comb) + self.bank.get_fragment()
|
||||||
#
|
#
|
||||||
#Driver
|
# Driver
|
||||||
#
|
#
|
||||||
def write(self, data):
|
def set(self, data):
|
||||||
self.interface.write(self.bank.get_base(), data)
|
self.interface.write(self.bank.get_base(), data)
|
||||||
|
|
||||||
def read(self):
|
def get(self):
|
||||||
return self.interface.read(self.bank.get_base() + self.words)
|
return self.interface.read(self.bank.get_base() + self.words)
|
|
@ -28,8 +28,6 @@ class MiLa:
|
||||||
self.trigger.set_interface(interface)
|
self.trigger.set_interface(interface)
|
||||||
self.recorder.set_interface(interface)
|
self.recorder.set_interface(interface)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_fragment(self):
|
def get_fragment(self):
|
||||||
comb =[
|
comb =[
|
||||||
self.trigger.trig.eq(self.trig),
|
self.trigger.trig.eq(self.trig),
|
||||||
|
|
|
@ -129,7 +129,6 @@ class Sequencer:
|
||||||
self.enable.eq(1)
|
self.enable.eq(1)
|
||||||
)
|
)
|
||||||
|
|
||||||
# trig_hit rising_edge
|
|
||||||
hit_rising = RisingEdge(self.hit)
|
hit_rising = RisingEdge(self.hit)
|
||||||
|
|
||||||
# connexion
|
# connexion
|
||||||
|
@ -230,7 +229,7 @@ class Recorder:
|
||||||
_pull_stb_rising.get_fragment()
|
_pull_stb_rising.get_fragment()
|
||||||
|
|
||||||
#
|
#
|
||||||
#Driver
|
# Driver
|
||||||
#
|
#
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.interface.write(self.bank.get_base() + REC_RST_BASE, 1)
|
self.interface.write(self.bank.get_base() + REC_RST_BASE, 1)
|
||||||
|
@ -243,13 +242,13 @@ class Recorder:
|
||||||
def is_done(self):
|
def is_done(self):
|
||||||
return self.interface.read(self.bank.get_base() + REC_DONE_BASE) == 1
|
return self.interface.read(self.bank.get_base() + REC_DONE_BASE) == 1
|
||||||
|
|
||||||
def size(self, dat):
|
def set_size(self, dat):
|
||||||
self.interface.write_n(self.bank.get_base() + REC_SIZE_BASE, dat, 16)
|
self.interface.write_n(self.bank.get_base() + REC_SIZE_BASE, dat, 16)
|
||||||
|
|
||||||
def offset(self, dat):
|
def set_offset(self, dat):
|
||||||
self.interface.write_n(self.bank.get_base() + REC_OFFSET_BASE, dat, 16)
|
self.interface.write_n(self.bank.get_base() + REC_OFFSET_BASE, dat, 16)
|
||||||
|
|
||||||
def read(self, size):
|
def pull(self, size):
|
||||||
r = []
|
r = []
|
||||||
for i in range(size):
|
for i in range(size):
|
||||||
self.interface.write(self.bank.get_base() + REC_READ_BASE, 1)
|
self.interface.write(self.bank.get_base() + REC_READ_BASE, 1)
|
||||||
|
|
|
@ -39,20 +39,20 @@ class Term:
|
||||||
self.reg_p = RegParams("term_reg", 0, width, 2)
|
self.reg_p = RegParams("term_reg", 0, width, 2)
|
||||||
self.reg = None
|
self.reg = None
|
||||||
|
|
||||||
def get_registers_glue(self):
|
def get_registers_comb(self):
|
||||||
comb = [self.t.eq(self.reg.field.r[0*self.width:1*self.width])]
|
comb = [self.t.eq(self.reg.field.r[0*self.width:1*self.width])]
|
||||||
comb += [self.m.eq(self.reg.field.r[1*self.width:2*self.width])]
|
comb += [self.m.eq(self.reg.field.r[1*self.width:2*self.width])]
|
||||||
return comb
|
return comb
|
||||||
|
|
||||||
def get_fragment(self):
|
def get_fragment(self):
|
||||||
comb = [self.o.eq((self.m & self.i) == self.t)]
|
comb = [self.o.eq((self.m & self.i) == self.t)]
|
||||||
comb += self.get_registers_glue()
|
comb += self.get_registers_comb()
|
||||||
return Fragment(comb)
|
return Fragment(comb)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Driver
|
# Driver
|
||||||
#
|
#
|
||||||
def write(self, dat, mask=None):
|
def set(self, dat, mask=None):
|
||||||
if mask is None:
|
if mask is None:
|
||||||
mask = (2**self.width)-1
|
mask = (2**self.width)-1
|
||||||
self.interface.write_n(self.reg_p.base, mask, self.width)
|
self.interface.write_n(self.reg_p.base, mask, self.width)
|
||||||
|
@ -75,22 +75,22 @@ class RangeDetector:
|
||||||
self.high = Signal(width)
|
self.high = Signal(width)
|
||||||
self.o = Signal()
|
self.o = Signal()
|
||||||
|
|
||||||
def get_registers_glue(self):
|
def get_registers_comb(self):
|
||||||
comb = [self.low.eq(self.reg.field.r[0*self.width:1*self.width])]
|
comb = [self.low.eq(self.reg.field.r[0*self.width:1*self.width])]
|
||||||
comb += [self.low.eq(self.reg.field.r[1*self.width:2*self.width])]
|
comb += [self.low.eq(self.reg.field.r[1*self.width:2*self.width])]
|
||||||
return comb
|
return comb
|
||||||
|
|
||||||
def get_fragment(self):
|
def get_fragment(self):
|
||||||
comb = [self.o.eq((self.i >= self.low) & (self.i <= self.high))]
|
comb = [self.o.eq((self.i >= self.low) & (self.i <= self.high))]
|
||||||
comb += self.get_registers_glue()
|
comb += self.get_registers_comb()
|
||||||
return Fragment(comb)
|
return Fragment(comb)
|
||||||
#
|
#
|
||||||
# Driver
|
# Driver
|
||||||
#
|
#
|
||||||
def write_low(self, dat):
|
def set_low(self, dat):
|
||||||
self.interface.write_n(self.reg_p.base, dat ,self.width)
|
self.interface.write_n(self.reg_p.base, dat ,self.width)
|
||||||
|
|
||||||
def write_high(self, dat):
|
def set_high(self, dat):
|
||||||
self.interface.write_n(self.reg_p.base + self.reg_p.words, dat ,self.width)
|
self.interface.write_n(self.reg_p.base + self.reg_p.words, dat ,self.width)
|
||||||
|
|
||||||
class EdgeDetector:
|
class EdgeDetector:
|
||||||
|
@ -118,7 +118,7 @@ class EdgeDetector:
|
||||||
self.bo = Signal()
|
self.bo = Signal()
|
||||||
self.o = Signal()
|
self.o = Signal()
|
||||||
|
|
||||||
def get_registers_glue(self):
|
def get_registers_comb(self):
|
||||||
comb = []
|
comb = []
|
||||||
i = 0
|
i = 0
|
||||||
if "R" in self.mode:
|
if "R" in self.mode:
|
||||||
|
@ -158,7 +158,7 @@ class EdgeDetector:
|
||||||
comb += [self.o.eq(self.ro | self.fo | self.bo)]
|
comb += [self.o.eq(self.ro | self.fo | self.bo)]
|
||||||
|
|
||||||
# Registers
|
# Registers
|
||||||
comb += self.get_registers_glue()
|
comb += self.get_registers_comb()
|
||||||
|
|
||||||
return Fragment(comb, sync)
|
return Fragment(comb, sync)
|
||||||
|
|
||||||
|
@ -180,13 +180,13 @@ class EdgeDetector:
|
||||||
return r
|
return r
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def write_r(self, dat):
|
def set_r(self, dat):
|
||||||
self.interface.write_n(self.reg_p.base + self.get_offset("R"), dat ,self.width)
|
self.interface.write_n(self.reg_p.base + self.get_offset("R"), dat ,self.width)
|
||||||
|
|
||||||
def write_f(self, dat):
|
def set_f(self, dat):
|
||||||
self.interface.write_n(self.reg_p.base + self.get_offset("F"), dat ,self.width)
|
self.interface.write_n(self.reg_p.base + self.get_offset("F"), dat ,self.width)
|
||||||
|
|
||||||
def write_b(self, dat):
|
def set_b(self, dat):
|
||||||
self.interface.write_n(self.reg_p.base + self.get_offset("B"), dat ,self.width)
|
self.interface.write_n(self.reg_p.base + self.get_offset("B"), dat ,self.width)
|
||||||
|
|
||||||
class Sum:
|
class Sum:
|
||||||
|
@ -212,7 +212,7 @@ class Sum:
|
||||||
self._lut_port = self._mem.get_port()
|
self._lut_port = self._mem.get_port()
|
||||||
self._prog_port = self._mem.get_port(write_capable=True)
|
self._prog_port = self._mem.get_port(write_capable=True)
|
||||||
|
|
||||||
def get_registers_glue(self):
|
def get_registers_comb(self):
|
||||||
comb = [
|
comb = [
|
||||||
self.prog_adr.eq(self.reg.field.r[0:16]),
|
self.prog_adr.eq(self.reg.field.r[0:16]),
|
||||||
self.prog_dat.eq(self.reg.field.r[16]),
|
self.prog_dat.eq(self.reg.field.r[16]),
|
||||||
|
@ -231,13 +231,13 @@ class Sum:
|
||||||
|
|
||||||
self.o.eq(self._o)
|
self.o.eq(self._o)
|
||||||
]
|
]
|
||||||
comb += self.get_registers_glue()
|
comb += self.get_registers_comb()
|
||||||
return Fragment(comb, specials={self._mem})
|
return Fragment(comb, specials={self._mem})
|
||||||
|
|
||||||
#
|
#
|
||||||
#Driver
|
# Driver
|
||||||
#
|
#
|
||||||
def write(self, truth_table):
|
def set(self, truth_table):
|
||||||
for i in range(len(truth_table)):
|
for i in range(len(truth_table)):
|
||||||
val = truth_table[i]
|
val = truth_table[i]
|
||||||
we = 1<<17
|
we = 1<<17
|
||||||
|
|
Loading…
Reference in a new issue