-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmain.py
More file actions
131 lines (101 loc) · 3.8 KB
/
main.py
File metadata and controls
131 lines (101 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
'''
Created on Jan 9, 2024
Code here, in main.py, runs on every power-up.
You can put anything you like in here, including any utility functions
you might want to have access to when connecting to the REPL.
If you want to use the SDK, all
you really need is something like
DemoboardDetect.probe()
tt = DemoBoard.get()
Then you can
# enable test project
tt.shuttle.tt_um_factory_test.enable()
and play with i/o as desired.
@author: Pat Deegan
@copyright: Copyright (C) 2024 Pat Deegan, https://psychogenic.com
'''
print("BOOT: Tiny Tapeout SDK")
import gc
# stash the current value for garbage
# collection threshold (is -1/when full, by default)
GCThreshold = gc.threshold()
# start very aggressive, to keep thing defragged
# as we read in ini and JSON files, etc
gc.threshold(80000)
import ttboard.log as logging
# logging.ticksStart() # start-up tick delta counter
logging.basicConfig(level=logging.DEBUG, filename='boot.log')
import micropython
from ttboard.boot.demoboard_detect import DemoboardDetect
from ttboard.demoboard import DemoBoard
import ttboard.util.colors as colors
# logging.dumpTicksMsDelta('import')
gc.collect()
tt = None
def startup():
# construct DemoBoard
# either pass an appropriate RPMode, e.g. RPMode.ASIC_RP_CONTROL
# or have "mode = ASIC_RP_CONTROL" in ini DEFAULT section
ttdemoboard = DemoBoard.get()
print("\n\n")
print(f"The '{colors.color('tt', 'red')}' object is available.")
print()
print(f"Projects may be enabled with {colors.bold('tt.shuttle.PROJECT_NAME.enable()')}, e.g.")
print("tt.shuttle.tt_um_urish_simon.enable()")
print()
print(f"The io ports are named as in Verilog, {colors.bold('tt.ui_in')}, {colors.bold('tt.uo_out')}...")
print(f"and behave as with cocotb, e.g. {colors.bold('tt.uo_out.value = 0xAA')} or {colors.bold('print(tt.ui_in.value)')}")
print(f"Bits may be accessed by index, e.g. {colors.bold('tt.uo_out[7]')} (note: that's the {colors.color('high bit!', 'red')}) to read or {colors.bold('tt.ui_in[5] = 1')} to write.")
print(f"Direction of the bidir pins is set using {colors.bold('tt.uio_oe_pico')}, used in the same manner as the io ports themselves.")
print("\n")
print(f"{colors.color('TT SDK v' + ttdemoboard.version, 'cyan')}")
print("\n\n")
gc.collect()
return ttdemoboard
def autoClockProject(freqHz:int):
tt.clock_project_PWM(freqHz)
def stopClocking():
tt.clock_project_stop()
# Detect the demoboard version
detection_result = '(best guess)'
detection_color = 'red'
if DemoboardDetect.probe():
# detection was conclusive
detection_result = ''
detection_color = 'cyan'
detection_message = 'Detected ' + DemoboardDetect.PCB_str() + ' demoboard ' + detection_result
print(f"{colors.color(detection_message, detection_color)}")
tt = startup()
logging.basicConfig(filename=None)
gc.collect()
colors.color_start('magenta', False)
print("Mem info")
micropython.mem_info()
colors.color_end()
print(tt)
print()
logging.dumpTicksMsDelta('boot done')
print(f"tt.sdk_revision={tt.revision}")
print(f"tt.sdk_version={tt.version}")
# end by being so aggressive on collection
gc.threshold(GCThreshold)
# to run tests easily import a module of interest, as below, and then
# run() it
def run_testbench_basic():
import microcotb
import examples.basic as test
test.run()
return test
def run_testbench_factorytest():
import microcotb
import examples.tt_um_factory_test as test
runner = test.run()
err_msgs = []
for atest in runner.tests_to_run.values():
if atest.failed:
err_msgs.append(f'{atest.name} failed: {atest.failed_msg}')
if len(err_msgs):
err_str = "\n\t".join(err_msgs)
print(f'{len(err_msgs)}/{len(runner.tests_to_run)} test failures:\n\t{err_str}')
print()
return test