@@ -234,7 +234,7 @@ def parse_rxfifo_brackets(arg, fifo_dir):
234234
235235 max_delay = 2 ** (5 - sideset_count - sideset_enable ) - 1
236236 assembled = []
237- for line in instructions :
237+ for line in instructions : # pylint: disable=too-many-nested-blocks
238238 instruction = splitter (line .strip ())
239239 delay = 0
240240 if (
@@ -299,21 +299,32 @@ def parse_rxfifo_brackets(arg, fifo_dir):
299299 assembled [- 1 ] |= num
300300 assembled [- 1 ] |= 0b11 << 5 # JMPPIN wait source
301301 else :
302+ idx = 3
302303 assembled [- 1 ] |= WAIT_SOURCES .index (instruction [2 ]) << 5
303- num = int (instruction [3 ], 0 )
304- if not 0 <= num <= 31 :
305- raise RuntimeError ("Wait num out of range" )
304+ if source == "irq" :
305+ if instruction [idx ] == "next" :
306+ require_version (1 , "wait irq next" )
307+ assembled [- 1 ] |= 0b11000
308+ idx += 1
309+ elif instruction [idx ] == "prev" :
310+ require_version (1 , "wait irq prev" )
311+ assembled [- 1 ] |= 0b01000
312+ idx += 1
313+
314+ limit = 8
315+ # The flag index is decoded in the same way as the IRQ
316+ # index field, decoding down from the two MSBs
317+ if instruction [- 1 ] == "rel" :
318+ if assembled [- 1 ] & 0b11000 :
319+ raise RuntimeError ("cannot use next/prev with rel" )
320+ assembled [- 1 ] |= 0b10000
321+ else :
322+ limit = 32
323+ num = int_in_range (
324+ instruction [idx ], 0 , limit , "wait {instruction[2]}"
325+ )
306326 assembled [- 1 ] |= num
307- # The flag index is decoded in the same way as the IRQ
308- # index field, decoding down from the two MSBs
309- if instruction [- 1 ] == "next" :
310- require_version (1 , "wait irq next" )
311- assembled [- 1 ] |= 0b11000
312- elif instruction [- 1 ] == "prev" :
313- require_version (1 , "wait irq prev" )
314- assembled [- 1 ] |= 0b01000
315- elif instruction [- 1 ] == "rel" :
316- assembled [- 1 ] |= 0b10000
327+
317328 elif instruction [0 ] == "in" :
318329 # instr delay src count
319330 assembled .append (0b010_00000_000_00000 )
@@ -352,15 +363,15 @@ def parse_rxfifo_brackets(arg, fifo_dir):
352363 elif instruction [0 ] == "mov" :
353364 # instr delay dst op src
354365 if instruction [1 ].startswith ("rxfifo[" ): # mov rxfifo[], isr
355- assembled .append (0b100_00000_0001_0_000 )
366+ assembled .append (0b100_00000_0001_1_000 )
356367 if instruction [2 ] != "isr" :
357368 raise ValueError ("mov rxfifo[] source must be isr" )
358- assembled [- 1 ] | = parse_rxfifo_brackets (instruction [1 ], "txput" )
369+ assembled [- 1 ] ^ = parse_rxfifo_brackets (instruction [1 ], "txput" )
359370 elif instruction [2 ].startswith ("rxfifo[" ): # mov osr, rxfifo[]
360- assembled .append (0b100_00000_1001_0_000 )
371+ assembled .append (0b100_00000_1001_1_000 )
361372 if instruction [1 ] != "osr" :
362373 raise ValueError ("mov ,rxfifo[] target must be osr" )
363- assembled [- 1 ] | = parse_rxfifo_brackets (instruction [2 ], "txget" )
374+ assembled [- 1 ] ^ = parse_rxfifo_brackets (instruction [2 ], "txget" )
364375 else :
365376 assembled .append (0b101_00000_000_00_000 )
366377 assembled [- 1 ] |= mov_destinations .index (instruction [1 ]) << 5
@@ -388,30 +399,35 @@ def parse_rxfifo_brackets(arg, fifo_dir):
388399 assembled .append (0b110_00000_0_0_0_00000 )
389400
390401 irq_type = 0
391- if instruction [- 1 ] == "prev" :
402+ idx = 1
403+ if instruction [idx ] == "wait" :
404+ assembled [- 1 ] |= 0x20
405+ idx += 1
406+ elif instruction [idx ] == "clear" :
407+ assembled [- 1 ] |= 0x40
408+ idx += 1
409+
410+ if instruction [idx ] == "prev" :
392411 irq_type = 1
393412 require_version (1 , "irq prev" )
394- instruction . pop ()
395- elif instruction [- 1 ] == "next" :
413+ idx += 1
414+ elif instruction [idx ] == "next" :
396415 irq_type = 3
397416 require_version (1 , "irq next" )
398- instruction .pop ()
399- elif instruction [- 1 ] == "rel" :
417+ idx += 1
418+
419+ if instruction [- 1 ] == "rel" :
420+ if irq_type != 0 :
421+ raise RuntimeError ("cannot use next/prev with rel" )
400422 irq_type = 2
401423 instruction .pop ()
402424
403425 assembled [- 1 ] |= irq_type << 3
404426
405- num = int_in_range (instruction [- 1 ], 0 , 8 , "irq index" )
427+ num = int_in_range (instruction [idx ], 0 , 8 , "irq index" )
406428 assembled [- 1 ] |= num
407429 instruction .pop ()
408430
409- if len (instruction ) > 1 : # after rel has been removed
410- if instruction [- 1 ] == "wait" :
411- assembled [- 1 ] |= 0x20
412- elif instruction [- 1 ] == "clear" :
413- assembled [- 1 ] |= 0x40
414- # All other values are the default of set without waiting
415431 elif instruction [0 ] == "set" :
416432 # instr delay dst data
417433 assembled .append (0b111_00000_000_00000 )
0 commit comments