2021-12-08 16:21:46 +00:00
|
|
|
import sys, pathlib
|
|
|
|
sys.path.append(str(pathlib.Path(__file__).resolve().parents[1]))
|
|
|
|
|
|
|
|
from m1n1.setup import *
|
|
|
|
from m1n1 import asm
|
|
|
|
from m1n1.shell import run_shell
|
|
|
|
from m1n1.gpiola import GPIOLogicAnalyzer
|
2021-12-17 22:21:13 +00:00
|
|
|
from m1n1.hw.spi import *
|
2021-12-08 16:21:46 +00:00
|
|
|
|
|
|
|
p.smp_start_secondaries()
|
|
|
|
|
2023-04-16 11:52:06 +00:00
|
|
|
spi = u.adt["arm-io/spi2"].get_reg(0)[0] + 0x8000
|
2021-12-08 16:21:46 +00:00
|
|
|
regs = SPIRegs(u, spi)
|
|
|
|
|
|
|
|
aic = u.adt["arm-io/aic"].get_reg(0)[0]
|
|
|
|
|
|
|
|
gpio = u.adt["arm-io/gpio0"].get_reg(0)[0]
|
2023-04-16 11:52:06 +00:00
|
|
|
count = u.adt["arm-io/gpio0"].getprop("#gpio-pins")
|
2021-12-08 16:21:46 +00:00
|
|
|
|
2023-04-16 11:52:06 +00:00
|
|
|
pins={}
|
|
|
|
for i in range(150, 150+32):
|
|
|
|
pins[f"pin{i}"] = i
|
2021-12-08 16:21:46 +00:00
|
|
|
|
|
|
|
m = GPIOLogicAnalyzer(u, "arm-io/gpio0",
|
2023-04-16 11:52:06 +00:00
|
|
|
pins=pins,
|
|
|
|
regs={"a": gpio},
|
|
|
|
div=1,
|
|
|
|
cpu=1,
|
|
|
|
on_pin_change=True,
|
|
|
|
on_reg_change=False)
|
2021-12-08 16:21:46 +00:00
|
|
|
|
|
|
|
regs.CTRL.val = 0xc
|
|
|
|
regs.PIN.val = 0x2
|
2023-04-16 11:52:06 +00:00
|
|
|
regs.CFG.val = 0x20 | (1<<15) | 6
|
|
|
|
regs.CFG.val = 0x20 | (1<<15) | 4
|
|
|
|
regs.CFG.val = 0x20 | (1<<15) | 2
|
|
|
|
regs.CFG.val = 0x20 | (3<<15) | 0
|
2021-12-28 12:08:47 +00:00
|
|
|
|
|
|
|
m.regs = {}
|
|
|
|
|
2023-04-16 11:52:06 +00:00
|
|
|
m.start(30000000, bufsize=0x80000)
|
2021-12-28 12:08:47 +00:00
|
|
|
|
2021-12-08 16:21:46 +00:00
|
|
|
regs.STATUS.val = 0xffffffff
|
2023-04-16 11:52:06 +00:00
|
|
|
regs.IF_XFER.val = 0xffffffff
|
|
|
|
regs.IF_FIFO.val = 0xffffffff
|
2021-12-08 16:21:46 +00:00
|
|
|
|
|
|
|
regs.CLKDIV.val = 0xfff
|
2023-04-16 11:52:06 +00:00
|
|
|
regs.INTER_DELAY.val = 0x1000
|
2021-12-08 16:21:46 +00:00
|
|
|
|
2023-04-16 11:52:06 +00:00
|
|
|
regs.SHIFTCFG.val = 0x21fcf7
|
2021-12-28 12:08:47 +00:00
|
|
|
|
|
|
|
regs.PIN.val = 0x2
|
2023-04-16 11:52:06 +00:00
|
|
|
print("pinconfig", hex(regs.PINCFG.val))
|
|
|
|
regs.PINCFG.val = 0x100
|
2021-12-28 12:08:47 +00:00
|
|
|
#regs.PINCONFIG.val = 0x2-7
|
2023-04-16 11:52:06 +00:00
|
|
|
print("pinconfig", hex(regs.PINCFG.val))
|
|
|
|
print("shiftconfig", hex(regs.SHIFTCFG.val))
|
2021-12-28 12:08:47 +00:00
|
|
|
|
|
|
|
p.write32(spi + 0x3c, 0xffffffff)
|
|
|
|
|
2023-04-16 11:52:06 +00:00
|
|
|
regs.PINCFG.val = 0x002
|
|
|
|
regs.PINCFG.val = 0x200
|
2021-12-08 16:21:46 +00:00
|
|
|
|
2021-12-28 12:08:47 +00:00
|
|
|
#p.write32(0x28e0380bc, 0x80100000)
|
|
|
|
#p.write32(0x28e0380c4, 0x80100000)
|
2021-12-08 16:21:46 +00:00
|
|
|
|
2023-04-16 11:52:06 +00:00
|
|
|
data = b"\xff\xff\xff\xff\x00\x00\xff\xff"
|
2021-12-08 16:21:46 +00:00
|
|
|
|
|
|
|
for i in range(2):
|
|
|
|
for j in data:
|
2023-04-16 11:52:06 +00:00
|
|
|
regs.TXDATA.val = j | 0xffffff00
|
2021-12-08 16:21:46 +00:00
|
|
|
regs.RXCNT.val = len(data)
|
|
|
|
regs.TXCNT.val = len(data)
|
|
|
|
|
|
|
|
regs.STATUS.val = 0xffffffff
|
2023-04-16 11:52:06 +00:00
|
|
|
regs.IF_XFER.val = 0xffffffff
|
|
|
|
regs.IF_FIFO.val = 0xffffffff
|
2021-12-08 16:21:46 +00:00
|
|
|
|
|
|
|
regs.PIN.val = 0x0
|
|
|
|
regs.CTRL.val = 0x1
|
|
|
|
#regs.TXDATA.val = 0xff
|
|
|
|
#regs.TXDATA.val = 0xff
|
|
|
|
|
|
|
|
i = 0
|
|
|
|
while regs.TXCNT.val != 0:
|
2023-04-16 11:52:06 +00:00
|
|
|
print(f"{regs.TXCNT.val:#x} {regs.FIFOSTAT.reg} {regs.STATUS.val:#x} {regs.IF_FIFO.val:#x} {p.read32(spi + 0x134):#x}")
|
2021-12-08 16:21:46 +00:00
|
|
|
regs.STATUS.val = 0xffffffff
|
2023-04-16 11:52:06 +00:00
|
|
|
regs.IF_XFER.val = 0xffffffff
|
|
|
|
regs.IF_FIFO.val = 0xffffffff
|
2021-12-08 16:21:46 +00:00
|
|
|
#regs.CTRL.val = 0x0
|
|
|
|
#time.sleep(0.1)
|
|
|
|
#regs.CTRL.val = 0x1[
|
|
|
|
print(hex(i))
|
|
|
|
#p.write32(spi + i, 0xffffffff)
|
|
|
|
#p.write32(spi + i, 0)
|
|
|
|
i += 4
|
|
|
|
if i > 0x100:
|
|
|
|
break
|
|
|
|
time.sleep(0.001)
|
2023-04-16 11:52:06 +00:00
|
|
|
print(f"{regs.RXCNT.val:#x} {regs.FIFOSTAT.reg} {regs.STATUS.val:#x} {regs.IF_FIFO.val:#x}")
|
2021-12-08 16:21:46 +00:00
|
|
|
regs.STATUS.val = 0xffffffff
|
2023-04-16 11:52:06 +00:00
|
|
|
regs.IF_XFER.val = 0xffffffff
|
|
|
|
regs.IF_FIFO.val = 0xffffffff
|
2021-12-08 16:21:46 +00:00
|
|
|
|
2021-12-28 12:08:47 +00:00
|
|
|
mon.poll()
|
2021-12-08 16:21:46 +00:00
|
|
|
|
2023-04-16 11:52:06 +00:00
|
|
|
while regs.FIFOSTAT.reg.LEVEL_RX:
|
2021-12-28 12:08:47 +00:00
|
|
|
print("RX", hex(regs.RXDATA.val))
|
2021-12-08 16:21:46 +00:00
|
|
|
|
|
|
|
regs.CTRL.val = 0
|
|
|
|
|
|
|
|
m.complete()
|
|
|
|
m.show()
|
|
|
|
|
|
|
|
#run_shell(globals(), msg="Have fun!")
|
|
|
|
|
|
|
|
|