欢迎光临
我们一直在努力

树莓派Pico‌的pio指令

参考

树莓派Pico‌的pio例子

整体结构

RP2040
├── PIO0
│ ├── Instruction RAM (32 × 16bit)
│ ├── SM0
│ ├── SM1
│ ├── SM2
│ └── SM3
└── PIO1
├── Instruction RAM (32 × 16bit)
├── SM0
├── SM1
├── SM2
└── SM3

State Machine(SM)内部寄存器

名称位宽类型说明
PC 5 bit 寄存器 指令计数器
X 32 bit 寄存器 通用工作寄存器
Y 32 bit 寄存器 通用工作寄存器
ISR 32 bit 移位寄存器 输入移位缓存
OSR 32 bit 移位寄存器 输出移位缓存

SM FIFO

PULL(TX → OSR)
PUSH(ISR → RX)

名称方向位宽深度本质
TX FIFO CPU → SM 32 bit 4 硬件队列
RX FIFO SM → CPU 32 bit 4 硬件队列

指令宽度:16 bit|1 指令 = 1 cycle(+ delay)

一、PIO 指令

分布 delay / side-set 可重分配

位15–1312–87–0
含义 OPCODE OPERAND DELAY / SIDESET

指令表

指令作用示例
JMP 条件 / 无条件跳转 jmp x– loop
WAIT 等待 GPIO / IRQ wait 1 pin 0
IN 输入到 ISR in pins, 1
OUT 从 OSR 输出 out pins, 1
PUSH ISR → RX FIFO push
PULL TX FIFO → OSR pull
MOV 寄存器操作 mov x, osr
IRQ 触发 / 等待中断 irq 0
SET 立即数写寄存器 / GPIO set pins, 1

二、各指令详细表(含例子)

1️⃣ JMP —— 跳转

jmp condition, target

条件含义例子
always 无条件 jmp start
x– X–,不为 0 则跳 jmp x– loop
y– Y–,不为 0 则跳 jmp y– send
!x X == 0 jmp !x done
x!=y X ≠ Y jmp x!=y retry
pin pin 为 1 jmp pin high
!osre OSR 非空 jmp !osre more

2️⃣ WAIT —— 等待

wait polarity source index

项目说明例子
polarity 等待 0 / 1 wait 0 gpio 5
GPIO 指定 GPIO wait 1 gpio 2
PIN pin 映射 wait 1 pin 0
IRQ 等待 IRQ wait 1 irq 0

3️⃣ IN —— 输入移位

in source, bit_count

source说明例子
pins 从 GPIO 读 in pins, 1
x 从 X in x, 8
y 从 Y in y, 4
null 填 0 in null, 8
isr ISR → ISR in isr, 1

4️⃣ OUT —— 输出移位

out dest, bit_count

dest说明例子
pins 输出到 GPIO out pins, 1
x 输出到 X out x, 8
y 输出到 Y out y, 4
null 丢弃 out null, 32
pindirs 设置方向 out pindirs, 1

5️⃣ PUSH —— ISR → RX FIFO

push [if_full] [block]

形式说明例子
默认 阻塞 push
if_full ISR 满才推 push if_full
noblock 非阻塞 push noblock

6️⃣ PULL —— TX FIFO → OSR

pull [if_empty] [block]

形式说明例子
默认 阻塞 pull
if_empty OSR 空才拉 pull if_empty
noblock 非阻塞 pull noblock

7️⃣ MOV —— 寄存器操作

mov dest, src

src说明例子
x X mov y, x
y Y mov x, y
osr OSR mov x, osr
isr ISR mov osr, isr
null 0 mov x, null
~x 取反 mov x, ~x

8️⃣ IRQ —— 中断

irq [set|clear|wait] index

操作说明例子
set 触发 IRQ irq set 0
clear 清 IRQ irq clear 0
wait 等待 IRQ irq wait 0

9️⃣SET —— 立即数写

set dest, value

dest说明例子
pins GPIO 输出 set pins, 1
x X 寄存器 set x, 10
y Y 寄存器 set y, 3
pindirs GPIO 方向 set pindirs, 1
赞(0)
未经允许不得转载:171主机测评 » 树莓派Pico‌的pio指令
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址