Skip to content

Commit 126608d

Browse files
committed
renamed low-level i/o r/w functions and related docs
1 parent 1880c3d commit 126608d

File tree

3 files changed

+60
-25
lines changed

3 files changed

+60
-25
lines changed

README.md

+36-1
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,44 @@ tt.ui_in[4:2] = 0b101
446446
Again, it's worth noting that this acts as in verilog, so ui_in[4:2] includes bits 4,3 and 2.
447447

448448

449+
### Fast I/O
450+
451+
All the I/O port abstractions and the cocotb compatibility aare nice, but sometimes there's a need for speed.
452+
453+
To read or write a byte in a single, low-level, call, use the fast micropython native functions from the platform, e.g.
454+
455+
```
456+
>>> import ttboard.util.platform as platform
457+
>>> platform.read_ui_in_byte()
458+
1
459+
>>> platform.write_ui_in_byte(4)
460+
>>> platform.read_ui_in_byte()
461+
4
462+
```
463+
464+
The naming is read/write_u*_byte, so the available functions are
465+
466+
* read_ui_in_byte()
467+
468+
* read_uio_byte()
469+
470+
* read_uo_out_byte()
471+
472+
* read_uio_outputenable()
473+
474+
* write_ui_in_byte(VAL)
475+
476+
* write_uio_byte(VAL)
477+
478+
* write_uo_out_byte(VAL)
479+
480+
* write_uio_outputenable(VAL)
481+
482+
483+
449484
### RP2040 pin objects
450485

451-
It's recommended that you stick with reading and writing values using the u* ports as described above.
486+
It's recommended that you stick with reading and writing values using the u* ports or the low-level platform calls, as described above.
452487

453488
Still, there may be cases where you want to play with micropython pin objects themselves, say to set pull-ups
454489

src/ttboard/pins/pins.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,19 @@ def _init_ioports(self):
153153
# Note: these are named according the the ASICs point of view
154154
# we can write ui_in, we read uo_out
155155
port_defs = [
156-
('uo_out', 8, platform.read_output_byte, None),
157-
('ui_in', 8, platform.read_input_byte, platform.write_input_byte),
158-
('uio_in', 8, platform.read_bidir_byte, platform.write_bidir_byte),
159-
('uio_out', 8, platform.read_bidir_byte, None)
156+
('uo_out', 8, platform.read_uo_out_byte, None),
157+
('ui_in', 8, platform.read_ui_in_byte, platform.write_ui_in_byte),
158+
('uio_in', 8, platform.read_uio_byte, platform.write_uio_byte),
159+
('uio_out', 8, platform.read_uio_byte, None)
160160
]
161161
self._ports = dict()
162162
for pd in port_defs:
163163
setattr(self, pd[0], VerilogIOPort(*pd))
164164

165165

166166
self.uio_oe_pico = VerilogOEPort('uio_oe_pico', 8,
167-
platform.read_bidir_outputenable,
168-
platform.write_bidir_outputenable)
167+
platform.read_uio_outputenable,
168+
platform.write_uio_outputenable)
169169

170170

171171

@@ -199,8 +199,8 @@ def mode(self, set_mode:int):
199199
beginFunc = startupMap[set_mode]
200200
beginFunc()
201201
if set_mode == RPMode.ASIC_RP_CONTROL:
202-
self.ui_in.byte_write = platform.write_input_byte
203-
self.uio_in.byte_write = platform.write_bidir_byte
202+
self.ui_in.byte_write = platform.write_ui_in_byte
203+
self.uio_in.byte_write = platform.write_uio_byte
204204
else:
205205
self.ui_in.byte_write = None
206206
self.uio_in.byte_write = None

src/ttboard/util/platform.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def set_RP_system_clock(freqHz:int):
117117
machine.freq(int(freqHz))
118118

119119
@micropython.native
120-
def write_input_byte(val):
120+
def write_ui_in_byte(val):
121121
# dump_portset('ui_in', val)
122122
# low level machine stuff
123123
# move the value bits to GPIO spots
@@ -131,12 +131,12 @@ def write_input_byte(val):
131131
machine.mem32[0xd000001c] = val
132132

133133
@micropython.native
134-
def read_input_byte():
134+
def read_ui_in_byte():
135135
# just read the high and low nibbles from GPIO and combine into a byte
136136
return ( (machine.mem32[0xd0000004] & (0xf << 17)) >> (17-4)) | ((machine.mem32[0xd0000004] & (0xf << 9)) >> 9)
137137

138138
@micropython.native
139-
def write_bidir_byte(val):
139+
def write_uio_byte(val):
140140
# dump_portset('uio', val)
141141
# low level machine stuff
142142
# move the value bits to GPIO spots
@@ -151,24 +151,24 @@ def write_bidir_byte(val):
151151

152152

153153
@micropython.native
154-
def read_bidir_byte():
154+
def read_uio_byte():
155155
return (machine.mem32[0xd0000004] & (0xff << 21)) >> 21
156156

157157
@micropython.native
158-
def read_bidir_outputenable():
158+
def read_uio_outputenable():
159159
# GPIO_OE register, masked for our bidir pins
160160
return (machine.mem32[0xd0000020] & 0x1FE00000) >> 21
161161

162162

163163
@micropython.native
164-
def write_bidir_outputenable(val):
164+
def write_uio_outputenable(val):
165165
# dump_portset('uio_oe', val)
166166
# GPIO_OE register, clearing bidir pins and setting any enabled
167167
val = (val << 21)
168168
machine.mem32[0xd0000020] = (machine.mem32[0xd0000020] & ((1 << 21) - 1)) | val
169169

170170
@micropython.native
171-
def write_output_byte(val):
171+
def write_uo_out_byte(val):
172172
# dump_portset('uo_out', val)
173173
# low level machine stuff
174174
# move the value bits to GPIO spots
@@ -181,7 +181,7 @@ def write_output_byte(val):
181181
machine.mem32[0xd000001c] = val
182182

183183
@micropython.native
184-
def read_output_byte():
184+
def read_uo_out_byte():
185185

186186
# sample code to deal with differences between
187187
# PCBs, not actually required as we didn't move anything
@@ -228,47 +228,47 @@ def set_RP_system_clock(freqHz:int):
228228
RP2040SystemClockDefaultHz = freqHz
229229

230230
_inbyte = 0
231-
def write_input_byte(val):
231+
def write_ui_in_byte(val):
232232
global _inbyte
233233
print(f'Sim write_input_byte {val}')
234234
_inbyte = val
235235

236-
def read_input_byte():
236+
def read_ui_in_byte():
237237
print('Sim read_output_byte')
238238
return _inbyte
239239

240240

241241
_uio_byte = 0
242-
def write_bidir_byte(val):
242+
def write_uio_byte(val):
243243
global _uio_byte
244244
print(f'Sim write_bidir_byte {val}')
245245
_uio_byte = val
246246

247247

248248

249-
def read_bidir_byte():
249+
def read_uio_byte():
250250
print('Sim read_output_byte')
251251
return _uio_byte
252252

253253
_outbyte = 0
254-
def write_output_byte(val):
254+
def write_uo_out_byte(val):
255255
global _outbyte
256256
print(f'Sim write_output_byte {val}')
257257
_outbyte = val
258258

259-
def read_output_byte():
259+
def read_uo_out_byte():
260260
global _outbyte
261261
v = _outbyte
262262
#_outbyte += 1
263263
print('Sim read_output_byte')
264264
return v
265265

266266
_uio_oe_pico = 0
267-
def read_bidir_outputenable():
267+
def read_uio_outputenable():
268268
print('Sim read_bidir_outputenable')
269269
return _uio_oe_pico
270270

271-
def write_bidir_outputenable(val):
271+
def write_uio_outputenable(val):
272272
global _uio_oe_pico
273273
print(f'Sim write_bidir_outputenable {val}')
274274
_uio_oe_pico = val

0 commit comments

Comments
 (0)