epio
A cycle-accurate RP2350 PIO emulator
Loading...
Searching...
No Matches
Functions
Peek API

Functions for reading internal state machine and block state for testing. More...

Functions

EPIO_EXPORT uint8_t epio_peek_sm_pc (epio_t *epio, uint8_t block, uint8_t sm)
 Get the current program counter (PC) for a state machine.
 
EPIO_EXPORT uint32_t epio_peek_sm_x (epio_t *epio, uint8_t block, uint8_t sm)
 Get the current X register value for a state machine.
 
EPIO_EXPORT uint32_t epio_peek_sm_y (epio_t *epio, uint8_t block, uint8_t sm)
 Get the current Y register value for a state machine.
 
EPIO_EXPORT uint32_t epio_peek_sm_isr (epio_t *epio, uint8_t block, uint8_t sm)
 Get the current Input Shift Register (ISR) value for a state machine.
 
EPIO_EXPORT uint32_t epio_peek_sm_osr (epio_t *epio, uint8_t block, uint8_t sm)
 Get the current Output Shift Register (OSR) value for a state machine.
 
EPIO_EXPORT uint8_t epio_peek_sm_isr_count (epio_t *epio, uint8_t block, uint8_t sm)
 Get the current ISR bit counter for a state machine.
 
EPIO_EXPORT uint8_t epio_peek_sm_osr_count (epio_t *epio, uint8_t block, uint8_t sm)
 Get the current OSR bit counter for a state machine.
 
EPIO_EXPORT uint8_t epio_peek_sm_osr_empty (epio_t *epio, uint8_t block, uint8_t sm)
 Check whether the OSR is considered empty for a state machine.
 
EPIO_EXPORT uint8_t epio_peek_sm_stalled (epio_t *epio, uint8_t block, uint8_t sm)
 Check if a state machine is currently stalled.
 
EPIO_EXPORT uint8_t epio_peek_sm_delay (epio_t *epio, uint8_t block, uint8_t sm)
 Get the current delay counter for a state machine.
 
EPIO_EXPORT uint8_t epio_peek_sm_exec_pending (epio_t *epio, uint8_t block, uint8_t sm)
 Check if a state machine has a pending EXEC instruction.
 
EPIO_EXPORT uint16_t epio_peek_sm_exec_instr (epio_t *epio, uint8_t block, uint8_t sm)
 Get the pending EXEC instruction for a state machine.
 
EPIO_EXPORT uint32_t epio_peek_block_irq (epio_t *epio, uint8_t block)
 Get the current IRQ state bitmask for a PIO block.
 
EPIO_EXPORT uint8_t epio_peek_block_irq_num (epio_t *epio, uint8_t block, uint8_t irq_num)
 Check if a specific IRQ flag is set for a PIO block.
 
EPIO_EXPORT uint32_t epio_peek_rx_fifo (epio_t *epio, uint8_t block, uint8_t sm, uint8_t entry)
 Peek at an entry in the RX FIFO of a state machine without popping it.
 
EPIO_EXPORT uint32_t epio_peek_tx_fifo (epio_t *epio, uint8_t block, uint8_t sm, uint8_t entry)
 Peek at an entry in the TX FIFO of a state machine without popping it.
 

Detailed Description

Functions for reading internal state machine and block state for testing.

Function Documentation

◆ epio_peek_block_irq()

EPIO_EXPORT uint32_t epio_peek_block_irq ( epio_t epio,
uint8_t  block 
)

Get the current IRQ state bitmask for a PIO block.

Each PIO block has 8 IRQ flags (0-7) that can be set, cleared, and waited on by state machines. IRQs can be used for synchronization between state machines within a block or across blocks.

Parameters
epioThe epio instance.
blockPIO block index (0 to NUM_PIO_BLOCKS-1).
Returns
32-bit bitmask where bits 0-7 represent IRQ states (1=set, 0=clear). Bits 8-31 are reserved and always 0.

◆ epio_peek_block_irq_num()

EPIO_EXPORT uint8_t epio_peek_block_irq_num ( epio_t epio,
uint8_t  block,
uint8_t  irq_num 
)

Check if a specific IRQ flag is set for a PIO block.

Convenience function equivalent to checking the bit in epio_peek_block_irq().

Parameters
epioThe epio instance.
blockPIO block index (0 to NUM_PIO_BLOCKS-1).
irq_numIRQ number to check (0 to NUM_IRQS_PER_BLOCK-1).
Returns
1 if the specified IRQ flag is set, 0 otherwise.

◆ epio_peek_rx_fifo()

EPIO_EXPORT uint32_t epio_peek_rx_fifo ( epio_t epio,
uint8_t  block,
uint8_t  sm,
uint8_t  entry 
)

Peek at an entry in the RX FIFO of a state machine without popping it.

Allows inspection of the contents of the RX FIFO without modifying it. The entry parameter specifies how far back in the FIFO to peek, with 0 being the next entry to be popped.

Asserts if entry is greater than or equal to the current RX FIFO depth.

Parameters
epioThe epio instance.
blockPIO block index (0 to NUM_PIO_BLOCKS-1).
smState machine index within the block (0 to NUM_SMS_PER_BLOCK-1).
entryFIFO entry index to peek (0 = next to pop, up to depth-1).
Returns
The 32-bit value at that position in the RX FIFO.

◆ epio_peek_sm_delay()

EPIO_EXPORT uint8_t epio_peek_sm_delay ( epio_t epio,
uint8_t  block,
uint8_t  sm 
)

Get the current delay counter for a state machine.

PIO instructions can include a delay field that causes the state machine to wait for 0-31 additional cycles before executing the next instruction. This returns the number of delay cycles remaining.

After the intruction that included the delay, but before any delay cycles have elapsed, this will return the full delay value. After all delay cycles have elapsed, this will return 0.

Parameters
epioThe epio instance.
blockPIO block index (0 to NUM_PIO_BLOCKS-1).
smState machine index within the block (0 to NUM_SMS_PER_BLOCK-1).
Returns
Number of delay cycles remaining (0 to 31).

◆ epio_peek_sm_exec_instr()

EPIO_EXPORT uint16_t epio_peek_sm_exec_instr ( epio_t epio,
uint8_t  block,
uint8_t  sm 
)

Get the pending EXEC instruction for a state machine.

When OUT EXEC or MOV EXEC is executed, this returns the instruction that will be executed on the next cycle. Only valid when exec_pending is true.

Parameters
epioThe epio instance.
blockPIO block index (0 to NUM_PIO_BLOCKS-1).
smState machine index within the block (0 to NUM_SMS_PER_BLOCK-1).
Returns
The 16-bit instruction that will execute next cycle.

◆ epio_peek_sm_exec_pending()

EPIO_EXPORT uint8_t epio_peek_sm_exec_pending ( epio_t epio,
uint8_t  block,
uint8_t  sm 
)

Check if a state machine has a pending EXEC instruction.

When OUT EXEC or MOV EXEC is executed, the state machine stores the instruction to execute on the next cycle rather than fetching from instruction memory. This returns whether such an instruction is pending.

Parameters
epioThe epio instance.
blockPIO block index (0 to NUM_PIO_BLOCKS-1).
smState machine index within the block (0 to NUM_SMS_PER_BLOCK-1).
Returns
1 if an EXEC instruction is pending, 0 otherwise.

◆ epio_peek_sm_isr()

EPIO_EXPORT uint32_t epio_peek_sm_isr ( epio_t epio,
uint8_t  block,
uint8_t  sm 
)

Get the current Input Shift Register (ISR) value for a state machine.

The ISR accumulates data from IN instructions before being pushed to the RX FIFO.

Parameters
epioThe epio instance.
blockPIO block index (0 to NUM_PIO_BLOCKS-1).
smState machine index within the block (0 to NUM_SMS_PER_BLOCK-1).
Returns
Current ISR value.

◆ epio_peek_sm_isr_count()

EPIO_EXPORT uint8_t epio_peek_sm_isr_count ( epio_t epio,
uint8_t  block,
uint8_t  sm 
)

Get the current ISR bit counter for a state machine.

Tracks how many bits have been shifted into the ISR since the last PUSH or autopush. Used to determine when autopush threshold is reached.

Parameters
epioThe epio instance.
blockPIO block index (0 to NUM_PIO_BLOCKS-1).
smState machine index within the block (0 to NUM_SMS_PER_BLOCK-1).
Returns
Number of bits currently in ISR (0 to 32).

◆ epio_peek_sm_osr()

EPIO_EXPORT uint32_t epio_peek_sm_osr ( epio_t epio,
uint8_t  block,
uint8_t  sm 
)

Get the current Output Shift Register (OSR) value for a state machine.

The OSR is loaded from the TX FIFO via PULL instructions and provides data to OUT instructions.

Parameters
epioThe epio instance.
blockPIO block index (0 to NUM_PIO_BLOCKS-1).
smState machine index within the block (0 to NUM_SMS_PER_BLOCK-1).
Returns
Current OSR value.

◆ epio_peek_sm_osr_count()

EPIO_EXPORT uint8_t epio_peek_sm_osr_count ( epio_t epio,
uint8_t  block,
uint8_t  sm 
)

Get the current OSR bit counter for a state machine.

Tracks how many bits have been shifted out of the OSR since the last PULL or autopull. Used to determine when autopull threshold is reached.

OSR count indicates 32 when the OSR is empty (32 bits shifted out)

Parameters
epioThe epio instance.
blockPIO block index (0 to NUM_PIO_BLOCKS-1).
smState machine index within the block (0 to NUM_SMS_PER_BLOCK-1).
Returns
Number of bits shifted out from OSR (0 to 32).

◆ epio_peek_sm_osr_empty()

EPIO_EXPORT uint8_t epio_peek_sm_osr_empty ( epio_t epio,
uint8_t  block,
uint8_t  sm 
)

Check whether the OSR is considered empty for a state machine.

Returns true if the OSR shift count has reached or exceeded the configured PULL_THRESH. This matches the condition used by JMP !OSRE and autopull.

Parameters
epioThe epio instance.
blockPIO block index (0 to NUM_PIO_BLOCKS-1).
smState machine index within the block (0 to NUM_SMS_PER_BLOCK-1).
Returns
1 if OSR is empty (at or beyond threshold), 0 otherwise.

◆ epio_peek_sm_pc()

EPIO_EXPORT uint8_t epio_peek_sm_pc ( epio_t epio,
uint8_t  block,
uint8_t  sm 
)

Get the current program counter (PC) for a state machine.

Returns the instruction address that the state machine will execute next. The PC is automatically incremented after each instruction unless a jump or wrap occurs.

Remember that the PC is relative to the block's instruction memory, so it ranges from 0 to NUM_INSTRS_PER_BLOCK-1.

The PC is updated during at the end of the cycle when the previous instruction executed, if there is a delay, but not a stall. This is in line with the data sheet, which indicates that for a JMP, the delay happens after PC is updated.

Parameters
epioThe epio instance.
blockPIO block index (0 to NUM_PIO_BLOCKS-1).
smState machine index within the block (0 to NUM_SMS_PER_BLOCK-1).
Returns
Current PC value (0 to NUM_INSTRS_PER_BLOCK-1).

◆ epio_peek_sm_stalled()

EPIO_EXPORT uint8_t epio_peek_sm_stalled ( epio_t epio,
uint8_t  block,
uint8_t  sm 
)

Check if a state machine is currently stalled.

A state machine stalls when waiting for a condition that hasn't been met, such as:

  • WAIT instruction condition not satisfied
  • PULL with empty TX FIFO (blocking)
  • PUSH with full RX FIFO (blocking)
  • IRQ WAIT instruction waiting for IRQ to clear

When stalled, the PC does not advance and the same instruction is re-evaluated each cycle until the stall condition clears.

Parameters
epioThe epio instance.
blockPIO block index (0 to NUM_PIO_BLOCKS-1).
smState machine index within the block (0 to NUM_SMS_PER_BLOCK-1).
Returns
1 if stalled, 0 if running normally.

◆ epio_peek_sm_x()

EPIO_EXPORT uint32_t epio_peek_sm_x ( epio_t epio,
uint8_t  block,
uint8_t  sm 
)

Get the current X register value for a state machine.

The X register is a general-purpose 32-bit scratch register that can be read and written by PIO instructions.

Parameters
epioThe epio instance.
blockPIO block index (0 to NUM_PIO_BLOCKS-1).
smState machine index within the block (0 to NUM_SMS_PER_BLOCK-1).
Returns
Current X register value.

◆ epio_peek_sm_y()

EPIO_EXPORT uint32_t epio_peek_sm_y ( epio_t epio,
uint8_t  block,
uint8_t  sm 
)

Get the current Y register value for a state machine.

The Y register is a general-purpose 32-bit scratch register that can be read and written by PIO instructions.

Parameters
epioThe epio instance.
blockPIO block index (0 to NUM_PIO_BLOCKS-1).
smState machine index within the block (0 to NUM_SMS_PER_BLOCK-1).
Returns
Current Y register value.

◆ epio_peek_tx_fifo()

EPIO_EXPORT uint32_t epio_peek_tx_fifo ( epio_t epio,
uint8_t  block,
uint8_t  sm,
uint8_t  entry 
)

Peek at an entry in the TX FIFO of a state machine without popping it.

Allows inspection of the contents of the TX FIFO without modifying it. The entry parameter specifies how far back in the FIFO to peek, with 0 being the next entry to be popped by the SM.

Asserts if entry is greater than or equal to the current TX FIFO depth.

Parameters
epioThe epio instance.
blockPIO block index (0 to NUM_PIO_BLOCKS-1).
smState machine index within the block (0 to NUM_SMS_PER_BLOCK-1).
entryFIFO entry index to peek (0 = next to pop, up to depth-1).
Returns
The 32-bit value at that position in the TX FIFO.