Last active
September 14, 2024 18:35
-
-
Save rtfb/e09064f74de43251d724be5b5f13bc6d to your computer and use it in GitHub Desktop.
A script to run the Collatz design on TT05 with a fixed input
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 | |
BITS = 144 | |
BYTES = BITS >> 3 | |
# enable the design | |
tt.shuttle.tt_um_rtfb_collatz.enable() | |
# tt.clock_project_stop() | |
# reset the design | |
tt.reset_project(True) | |
for i in range(10): | |
tt.clock_project_once() | |
tt.bidir_mode = [Pin.OUT] * 8 | |
tt.bidir_byte = 0 | |
tt.input_byte = 0 | |
tt.output_byte = 0 | |
tt.reset_project(False) | |
for i in range(10): | |
tt.clock_project_once() | |
def extract_ith_byte(number, i): | |
return (number >> (i*8)) & 0xff | |
def pulse_write_enable(): | |
tt.uio7(1) | |
tt.clock_project_once() | |
tt.uio7(0) | |
def set_input(val): | |
for i in range(BYTES): | |
data_byte = extract_ith_byte(val, i) | |
print(f'{i}th byte = {data_byte}') | |
tt.bidir_byte = i # set address of i'th byte | |
tt.input_byte = data_byte # set the data byte | |
tt.clock_project_once() | |
pulse_write_enable() | |
# set input to 12 | |
# tt.bidir_byte = 0 | |
# tt.input_byte = 12 | |
# tt.clock_project_once() | |
set_input(12) | |
# pulse write enable | |
tt.uio7(1) | |
tt.clock_project_once() | |
tt.uio7(0) | |
tt.clock_project_once() | |
# start computing | |
assert tt.uio7.value() == False | |
tt.uio7.mode = Pin.IN | |
tt.uio7.pull = Pin.PULL_DOWN | |
tt.uio6(1) | |
tt.clock_project_once() | |
# run until done computing | |
iters = 0 | |
while tt.uio7.value(): | |
iters += 1 | |
tt.clock_project_once() | |
print(f'Iters: {iters}') | |
# read output | |
tt.bidir_mode = [Pin.OUT] * 8 | |
tt.bidir_byte = 0 | |
tt.clock_project_once() | |
tt.clock_project_once() | |
out = tt.output_byte | |
print(f'Output: {out}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment