From 8183ed1eb0d676e61ff111a0df5d8f309e72f386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Bourdeauducq?= Date: Mon, 19 Aug 2024 22:15:17 +0800 Subject: [PATCH] test/spi: port to NAC3 --- artiq/test/coredevice/test_spi.py | 35 ++++++++++++++++++------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/artiq/test/coredevice/test_spi.py b/artiq/test/coredevice/test_spi.py index 02429cf09..e6b38ebcd 100644 --- a/artiq/test/coredevice/test_spi.py +++ b/artiq/test/coredevice/test_spi.py @@ -3,16 +3,21 @@ from artiq.experiment import * from artiq.test.hardware_testbench import ExperimentCase from artiq.language.core import kernel from artiq.language.units import us -from artiq.coredevice import spi2 as spi +from artiq.coredevice.core import Core +from artiq.coredevice.spi2 import * -_SDCARD_SPI_CONFIG = (0*spi.SPI_OFFLINE | 0*spi.SPI_END | - 0*spi.SPI_INPUT | 0*spi.SPI_CS_POLARITY | - 0*spi.SPI_CLK_POLARITY | 0*spi.SPI_CLK_PHASE | - 0*spi.SPI_LSB_FIRST | 0*spi.SPI_HALF_DUPLEX) +_SDCARD_SPI_CONFIG = (0*SPI_OFFLINE | 0*SPI_END | + 0*SPI_INPUT | 0*SPI_CS_POLARITY | + 0*SPI_CLK_POLARITY | 0*SPI_CLK_PHASE | + 0*SPI_LSB_FIRST | 0*SPI_HALF_DUPLEX) +@nac3 class CardTest(EnvExperiment): + core: KernelInvariant[Core] + spi_mmc: KernelInvariant[SPIMaster] + def build(self): self.setattr_device("core") self.setattr_device("spi_mmc") @@ -20,18 +25,18 @@ class CardTest(EnvExperiment): @kernel def run(self): self.core.reset() - delay(1*ms) + self.core.delay(1.*ms) - freq = 1*MHz + freq = 1.*MHz cs = 1 # run a couple of clock cycles with miso high to wake up the card self.spi_mmc.set_config(_SDCARD_SPI_CONFIG, 32, freq, 0) for i in range(10): - self.spi_mmc.write(0xffffffff) - self.spi_mmc.set_config(_SDCARD_SPI_CONFIG | spi.SPI_END, 32, freq, 0) - self.spi_mmc.write(0xffffffff) - delay(200*us) + self.spi_mmc.write(-1) + self.spi_mmc.set_config(_SDCARD_SPI_CONFIG | SPI_END, 32, freq, 0) + self.spi_mmc.write(-1) + self.core.delay(200.*us) self.spi_mmc.set_config(_SDCARD_SPI_CONFIG, 8, freq, cs) self.spi_mmc.write(0x40 << 24) # CMD @@ -39,20 +44,20 @@ class CardTest(EnvExperiment): self.spi_mmc.write(0x00000000) # ARG self.spi_mmc.set_config(_SDCARD_SPI_CONFIG, 8, freq, cs) self.spi_mmc.write(0x95 << 24) # CRC - self.spi_mmc.set_config(_SDCARD_SPI_CONFIG | spi.SPI_INPUT, 8, freq, cs) + self.spi_mmc.set_config(_SDCARD_SPI_CONFIG | SPI_INPUT, 8, freq, cs) idle = False response = 0 for i in range(8): self.spi_mmc.write(0xff << 24) # NCR response = self.spi_mmc.read() - delay(100*us) + self.core.delay(100.*us) if response == 0x01: idle = True break - self.spi_mmc.set_config(_SDCARD_SPI_CONFIG | spi.SPI_END, 8, freq, cs) + self.spi_mmc.set_config(_SDCARD_SPI_CONFIG | SPI_END, 8, freq, cs) self.spi_mmc.write(0xff << 24) if not idle: - print(response) + print_rpc(response) raise ValueError("SD Card did not reply with IDLE")