Last active
October 23, 2023 12:19
-
-
Save urish/6ef3105803284bc2483a92b12bfcc265 to your computer and use it in GitHub Desktop.
TinyTapeout 02 External Scanchain controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from machine import Pin | |
import time | |
CLK_PERIOD_MS = 1 | |
NUM_DESIGNS = 250 # should be higher | |
# from chip's perspective | |
# pinout here: https://projects.raspberrypi.org/en/projects/getting-started-with-the-pico/1 | |
ext_clk = Pin(6, Pin.OUT) | |
ext_latch = Pin(7, Pin.OUT) | |
ext_scan = Pin(8, Pin.OUT) | |
ext_data_in = Pin(9, Pin.OUT) # data driven by us into the chip | |
ext_data_out = Pin(10, Pin.IN) # data captured by us from the chip | |
def scanchain_io(design_index, input_value): | |
""" | |
design_index is the index of the design in the scan chain (0 to 249), | |
input_value is the value to drive into the scan chain (0 to 255). | |
Returns the digital value read from the design through the scanchain. | |
""" | |
ext_data_in.value(0) | |
ext_latch.value(0) | |
ext_scan.value(0) | |
ext_clk.value(0) | |
# shift the input value into the scan chain | |
for i in range(8): | |
ext_data_in.value(1 if (input_value & (1 << i)) > 0 else 0) | |
ext_clk.value(1) | |
time.sleep_ms(CLK_PERIOD_MS) | |
ext_clk.value(0) | |
time.sleep_ms(CLK_PERIOD_MS) | |
# now shift the data input the selected design | |
for i in range(8 * design_index): | |
ext_clk.value(1) | |
time.sleep_ms(CLK_PERIOD_MS) | |
ext_clk.value(0) | |
time.sleep_ms(CLK_PERIOD_MS) | |
# latch data into the dut | |
ext_latch.value(1) | |
time.sleep_ms(CLK_PERIOD_MS) | |
ext_latch.value(0) | |
time.sleep_ms(CLK_PERIOD_MS) | |
# capture data by setting scan high and toggle the clock | |
ext_scan.value(1) | |
time.sleep_ms(CLK_PERIOD_MS) | |
ext_clk.value(1) | |
time.sleep_ms(CLK_PERIOD_MS) | |
ext_clk.value(0) | |
time.sleep_ms(CLK_PERIOD_MS) | |
ext_scan.value(0) | |
# drive data out through the chain | |
for i in range(8 * (NUM_DESIGNS - design_index - 1)): | |
ext_clk.value(1) | |
time.sleep_ms(CLK_PERIOD_MS) | |
ext_clk.value(0) | |
time.sleep_ms(CLK_PERIOD_MS) | |
out_value = 0 | |
for i in range(8): | |
ext_clk.value(1) | |
time.sleep_ms(CLK_PERIOD_MS) | |
out_value |= ext_data_out.value() << i | |
ext_clk.value(0) | |
time.sleep_ms(CLK_PERIOD_MS) | |
return out_value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment