@web-font-path: "roboto-debian.css";
v2.2.0 (RP2040)
Loading...
Searching...
No Matches
pio_instructions
hardware_pio

PIO instruction encoding. More...

## Enumerations

enum | pio_src_dest { pio_pins = 0u , pio_x = 1u , pio_y = 2u , pio_null = 3u | 0x20u | 0x80u , pio_pindirs = 4u | 0x08u | 0x40u | 0x80u , pio_exec_mov = 4u | 0x08u | 0x10u | 0x20u | 0x40u , pio_status = 5u | 0x08u | 0x10u | 0x20u | 0x80u , pio_pc = 5u | 0x08u | 0x20u | 0x40u , pio_isr = 6u | 0x20u , pio_osr = 7u | 0x10u | 0x20u , pio_exec_out = 7u | 0x08u | 0x20u | 0x40u | 0x80u }
| Enumeration of values to pass for source/destination args for instruction encoding functions. More...

## Functions

static uint | pio_encode_delay (uint cycles)
| Encode just the delay slot bits of an instruction.
static uint | pio_encode_sideset (uint sideset_bit_count, uint value)
| Encode just the side set bits of an instruction (in non optional side set mode).
static uint | pio_encode_sideset_opt (uint sideset_bit_count, uint value)
| Encode just the side set bits of an instruction (in optional -opt side set mode).
static uint | pio_encode_jmp (uint addr)
| Encode an unconditional JMP instruction.
static uint | pio_encode_jmp_not_x (uint addr)
| Encode a conditional JMP if scratch X zero instruction.
static uint | pio_encode_jmp_x_dec (uint addr)
| Encode a conditional JMP if scratch X non-zero (and post-decrement X) instruction.
static uint | pio_encode_jmp_not_y (uint addr)
| Encode a conditional JMP if scratch Y zero instruction.
static uint | pio_encode_jmp_y_dec (uint addr)
| Encode a conditional JMP if scratch Y non-zero (and post-decrement Y) instruction.
static uint | pio_encode_jmp_x_ne_y (uint addr)
| Encode a conditional JMP if scratch X not equal scratch Y instruction.
static uint | pio_encode_jmp_pin (uint addr)
| Encode a conditional JMP if input pin high instruction.
static uint | pio_encode_jmp_not_osre (uint addr)
| Encode a conditional JMP if output shift register not empty instruction.
static uint | pio_encode_wait_gpio (bool polarity, uint gpio)
| Encode a WAIT for GPIO pin instruction.
static uint | pio_encode_wait_pin (bool polarity, uint pin)
| Encode a WAIT for pin instruction.
static uint | pio_encode_wait_irq (bool polarity, bool relative, uint irq)
| Encode a WAIT for IRQ instruction.
static uint | pio_encode_in (enum pio_src_dest src, uint count)
| Encode an IN instruction.
static uint | pio_encode_out (enum pio_src_dest dest, uint count)
| Encode an OUT instruction.
static uint | pio_encode_push (bool if_full, bool block)
| Encode a PUSH instruction.
static uint | pio_encode_pull (bool if_empty, bool block)
| Encode a PULL instruction.
static uint | pio_encode_mov (enum pio_src_dest dest, enum pio_src_dest src)
| Encode a MOV instruction.
static uint | pio_encode_mov_not (enum pio_src_dest dest, enum pio_src_dest src)
| Encode a MOV instruction with bit invert.
static uint | pio_encode_mov_reverse (enum pio_src_dest dest, enum pio_src_dest src)
| Encode a MOV instruction with bit reverse.
static uint | pio_encode_irq_set (bool relative, uint irq)
| Encode a IRQ SET instruction.
static uint | pio_encode_irq_wait (bool relative, uint irq)
| Encode a IRQ WAIT instruction.
static uint | pio_encode_irq_clear (bool relative, uint irq)
| Encode a IRQ CLEAR instruction.
static uint | pio_encode_set (enum pio_src_dest dest, uint value)
| Encode a SET instruction.
static uint | pio_encode_nop (void)
| Encode a NOP instruction.

## Detailed Description

PIO instruction encoding.

Functions for generating PIO instruction encodings programmatically. In debug builds PARAM_ASSERTIONS_ENABLED_PIO_INSTRUCTIONS can be set to 1 to enable validation of encoding function parameters.

For fuller descriptions of the instructions in question see the "RP2040 Datasheet"

## Enumeration Type Documentation

## pio_src_dest

enum pio_src_dest

Enumeration of values to pass for source/destination args for instruction encoding functions.

Note
  Not all values are suitable for all functions. Validity is only checked in debug mode when PARAM_ASSERTIONS_ENABLED_PIO_INSTRUCTIONS is 1

## Function Documentation

## pio_encode_delay()

uint pio_encode_delay | ( | uint | cycles | ) |

inline static

Encode just the delay slot bits of an instruction.

Note
  This function does not return a valid instruction encoding; instead it returns an encoding of the delay slot suitable for ORing with the result of an encoding function for an actual instruction. Care should be taken when combining the results of this function with the results of pio_encode_sideset and pio_encode_sideset_opt as they share the same bits within the instruction encoding.

Parameters

  cycles | the number of cycles 0-31 (or less if side set is being used)

Returns
  the delay slot bits to be ORed with an instruction encoding

## pio_encode_in()

uint pio_encode_in | ( | enum pio_src_dest | src,
|  | uint | count )

inline static

Encode an IN instruction.

This is the equivalent of IN <src>, <count>

Parameters

  src | The source to take data from
  count | The number of bits 1-32

Returns
  The instruction encoding with 0 delay and no side set value

See also
  pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt

## pio_encode_irq_clear()

uint pio_encode_irq_clear | ( | bool | relative,
|  | uint | irq )

inline static

Encode a IRQ CLEAR instruction.

This is the equivalent of IRQ CLEAR <irq> <relative>

Parameters

  relative | true for a IRQ CLEAR <irq> REL, false for regular IRQ CLEAR <irq>
  irq | the irq number 0-7

Returns
  The instruction encoding with 0 delay and no side set value

See also
  pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt

## pio_encode_irq_set()

uint pio_encode_irq_set | ( | bool | relative,
|  | uint | irq )

inline static

Encode a IRQ SET instruction.

This is the equivalent of IRQ SET <irq> <relative>

Parameters

  relative | true for a IRQ SET <irq> REL, false for regular IRQ SET <irq>
  irq | the irq number 0-7

Returns
  The instruction encoding with 0 delay and no side set value

See also
  pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt

## pio_encode_irq_wait()

uint pio_encode_irq_wait | ( | bool | relative,
|  | uint | irq )

inline static

Encode a IRQ WAIT instruction.

This is the equivalent of IRQ WAIT <irq> <relative>

Parameters

  relative | true for a IRQ WAIT <irq> REL, false for regular IRQ WAIT <irq>
  irq | the irq number 0-7

Returns
  The instruction encoding with 0 delay and no side set value

See also
  pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt

## pio_encode_jmp()

uint pio_encode_jmp | ( | uint | addr | ) |

inline static

Encode an unconditional JMP instruction.

This is the equivalent of JMP <addr>

Parameters

  addr | The target address 0-31 (an absolute address within the PIO instruction memory)

Returns
  The instruction encoding with 0 delay and no side set value

See also
  pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt

## pio_encode_jmp_not_osre()

uint pio_encode_jmp_not_osre | ( | uint | addr | ) |

inline static

Encode a conditional JMP if output shift register not empty instruction.

This is the equivalent of JMP !OSRE <addr>

Parameters

  addr | The target address 0-31 (an absolute address within the PIO instruction memory)

Returns
  The instruction encoding with 0 delay and no side set value

See also
  pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt

## pio_encode_jmp_not_x()

uint pio_encode_jmp_not_x | ( | uint | addr | ) |

inline static

Encode a conditional JMP if scratch X zero instruction.

This is the equivalent of JMP !X <addr>

Parameters

  addr | The target address 0-31 (an absolute address within the PIO instruction memory)

Returns
  The instruction encoding with 0 delay and no side set value

See also
  pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt

## pio_encode_jmp_not_y()

uint pio_encode_jmp_not_y | ( | uint | addr | ) |

inline static

Encode a conditional JMP if scratch Y zero instruction.

This is the equivalent of JMP !Y <addr>

Parameters

  addr | The target address 0-31 (an absolute address within the PIO instruction memory)

Returns
  The instruction encoding with 0 delay and no side set value

See also
  pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt

## pio_encode_jmp_pin()

uint pio_encode_jmp_pin | ( | uint | addr | ) |

inline static

Encode a conditional JMP if input pin high instruction.

This is the equivalent of JMP PIN <addr>

Parameters

  addr | The target address 0-31 (an absolute address within the PIO instruction memory)

Returns
  The instruction encoding with 0 delay and no side set value

See also
  pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt

## pio_encode_jmp_x_dec()

uint pio_encode_jmp_x_dec | ( | uint | addr | ) |

inline static

Encode a conditional JMP if scratch X non-zero (and post-decrement X) instruction.

This is the equivalent of JMP X-- <addr>

Parameters

  addr | The target address 0-31 (an absolute address within the PIO instruction memory)

Returns
  The instruction encoding with 0 delay and no side set value

See also
  pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt

## pio_encode_jmp_x_ne_y()

uint pio_encode_jmp_x_ne_y | ( | uint | addr | ) |

inline static

Encode a conditional JMP if scratch X not equal scratch Y instruction.

This is the equivalent of JMP X!=Y <addr>

Parameters

  addr | The target address 0-31 (an absolute address within the PIO instruction memory)

Returns
  The instruction encoding with 0 delay and no side set value

See also
  pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt

## pio_encode_jmp_y_dec()

uint pio_encode_jmp_y_dec | ( | uint | addr | ) |

inline static

Encode a conditional JMP if scratch Y non-zero (and post-decrement Y) instruction.

This is the equivalent of JMP Y-- <addr>

Parameters

  addr | The target address 0-31 (an absolute address within the PIO instruction memory)

Returns
  The instruction encoding with 0 delay and no side set value

See also
  pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt

## pio_encode_mov()

uint pio_encode_mov | ( | enum pio_src_dest | dest,
|  | enum pio_src_dest | src )

inline static

Encode a MOV instruction.

This is the equivalent of MOV <dest>, <src>

Parameters

  dest | The destination to write data to
  src | The source to take data from

Returns
  The instruction encoding with 0 delay and no side set value

See also
  pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt

## pio_encode_mov_not()

uint pio_encode_mov_not | ( | enum pio_src_dest | dest,
|  | enum pio_src_dest | src )

inline static

Encode a MOV instruction with bit invert.

This is the equivalent of MOV <dest>, ~<src>

Parameters

  dest | The destination to write inverted data to
  src | The source to take data from

Returns
  The instruction encoding with 0 delay and no side set value

See also
  pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt

## pio_encode_mov_reverse()

uint pio_encode_mov_reverse | ( | enum pio_src_dest | dest,
|  | enum pio_src_dest | src )

inline static

Encode a MOV instruction with bit reverse.

This is the equivalent of MOV <dest>, ::<src>

Parameters

  dest | The destination to write bit reversed data to
  src | The source to take data from

Returns
  The instruction encoding with 0 delay and no side set value

See also
  pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt

## pio_encode_nop()

uint pio_encode_nop | ( | void |  | ) |

inline static

Encode a NOP instruction.

This is the equivalent of NOP which is itself encoded as MOV y, y

Returns
  The instruction encoding with 0 delay and no side set value

See also
  pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt

## pio_encode_out()

uint pio_encode_out | ( | enum pio_src_dest | dest,
|  | uint | count )

inline static

Encode an OUT instruction.

This is the equivalent of OUT <src>, <count>

Parameters

  dest | The destination to write data to
  count | The number of bits 1-32

Returns
  The instruction encoding with 0 delay and no side set value

See also
  pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt

## pio_encode_pull()

uint pio_encode_pull | ( | bool | if_empty,
|  | bool | block )

inline static

Encode a PULL instruction.

This is the equivalent of PULL <if_empty>, <block>

Parameters

  if_empty | true for PULL IF_EMPTY ..., false for PULL ...
  block | true for PULL ... BLOCK, false for PULL ...

Returns
  The instruction encoding with 0 delay and no side set value

See also
  pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt

## pio_encode_push()

uint pio_encode_push | ( | bool | if_full,
|  | bool | block )

inline static

Encode a PUSH instruction.

This is the equivalent of PUSH <if_full>, <block>

Parameters

  if_full | true for PUSH IF_FULL ..., false for PUSH ...
  block | true for PUSH ... BLOCK, false for PUSH ...

Returns
  The instruction encoding with 0 delay and no side set value

See also
  pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt

## pio_encode_set()

uint pio_encode_set | ( | enum pio_src_dest | dest,
|  | uint | value )

inline static

Encode a SET instruction.

This is the equivalent of SET <dest>, <value>

Parameters

  dest | The destination to apply the value to
  value | The value 0-31

Returns
  The instruction encoding with 0 delay and no side set value

See also
  pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt

## pio_encode_sideset()

uint pio_encode_sideset | ( | uint | sideset_bit_count,
|  | uint | value )

inline static

Encode just the side set bits of an instruction (in non optional side set mode).

Note
  This function does not return a valid instruction encoding; instead it returns an encoding of the side set bits suitable for ORing with the result of an encoding function for an actual instruction. Care should be taken when combining the results of this function with the results of pio_encode_delay as they share the same bits within the instruction encoding.

Parameters

  sideset_bit_count | number of side set bits as would be specified via .sideset in pioasm
  value | the value to sideset on the pins

Returns
  the side set bits to be ORed with an instruction encoding

## pio_encode_sideset_opt()

uint pio_encode_sideset_opt | ( | uint | sideset_bit_count,
|  | uint | value )

inline static

Encode just the side set bits of an instruction (in optional -opt side set mode).

Note
  This function does not return a valid instruction encoding; instead it returns an encoding of the side set bits suitable for ORing with the result of an encoding function for an actual instruction. Care should be taken when combining the results of this function with the results of pio_encode_delay as they share the same bits within the instruction encoding.

Parameters

  sideset_bit_count | number of side set bits as would be specified via .sideset <n> opt in pioasm
  value | the value to sideset on the pins

Returns
  the side set bits to be ORed with an instruction encoding

## pio_encode_wait_gpio()

uint pio_encode_wait_gpio | ( | bool | polarity,
|  | uint | gpio )

inline static

Encode a WAIT for GPIO pin instruction.

This is the equivalent of WAIT <polarity> GPIO <gpio>

Note
  gpio here refers to the raw instruction encoding, which only supports 32 GPIOs. So, if you had a PIO program with WAIT <polarity> GPIO 42 and a GPIO_BASE (see pio_set_gpio_base) of 16, then you'd want to do pio_encode_wait_gpio(polarity, 42-16) assuming you are using this function to craft instructions for pio_sm_exec.

Parameters

  polarity | true for WAIT 1, false for WAIT 0
  gpio | The GPIO number 0-31 relative to the state machine's GPIO_BASE (see pio_set_gpio_base)

Returns
  The instruction encoding with 0 delay and no side set value

See also
  pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt

## pio_encode_wait_irq()

uint pio_encode_wait_irq | ( | bool | polarity,
|  | bool | relative,
|  | uint | irq )

inline static

Encode a WAIT for IRQ instruction.

This is the equivalent of WAIT <polarity> IRQ <irq> <relative>

Parameters

  polarity | true for WAIT 1, false for WAIT 0
  relative | true for a WAIT IRQ <irq> REL, false for regular WAIT IRQ <irq>
  irq | the irq number 0-7

Returns
  The instruction encoding with 0 delay and no side set value

See also
  pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt

## pio_encode_wait_pin()

uint pio_encode_wait_pin | ( | bool | polarity,
|  | uint | pin )

inline static

Encode a WAIT for pin instruction.

This is the equivalent of WAIT <polarity> PIN <pin>

Parameters

  polarity | true for WAIT 1, false for WAIT 0
  pin | The pin number 0-31 relative to the executing SM's input pin mapping

Returns
  The instruction encoding with 0 delay and no side set value

See also
  pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt