Datasheet

Table Of Contents
18 mm_pio->instr_mem[i] = auto_push_pull_program[i];
19 mm_pio->sm[0].shiftctrl =
20 (1u << PIO_SM0_SHIFTCTRL_AUTOPUSH_LSB) |
21 (1u << PIO_SM0_SHIFTCTRL_AUTOPULL_LSB) |
22 (0u << PIO_SM0_SHIFTCTRL_PUSH_THRESH_LSB) |
23 (0u << PIO_SM0_SHIFTCTRL_PULL_THRESH_LSB);
24 mm_pio->sm[0].execctrl =
25 (auto_push_pull_wrap_target << PIO_SM0_EXECCTRL_WRAP_BOTTOM_LSB) |
26 (auto_push_pull_wrap << PIO_SM0_EXECCTRL_WRAP_TOP_LSB);
27
28 // Start state machine 0
29 hw_set_bits(&mm_pio->ctrl, 1u << (PIO_CTRL_SM_ENABLE_LSB + 0));
30
31 // Push data into TX FIFO, and pop from RX FIFO
32 for (int i = 0; i < 5; ++i)
33 mm_pio->txf[0] = i;
34 for (int i = 0; i < 5; ++i)
35 printf("%d\n", mm_pio->rxf[0]);
36
37 return 0;
38 }
Figure 42 shows how the state machine executes the example program. Initially the OSR is empty, so the state machine
stalls on the first OUT instruction. Once data is available in the TX FIFO, the state machine transfers this into the OSR. On
the next cycle, the OUT can execute using the data in the OSR (in this case, transferring this data to the X scratch register),
and the state machine simultaneously refills the OSR with fresh data from the FIFO. Since every IN instruction
immediately fills the ISR, the ISR remains empty, and IN transfers data directly from scratch X to the RX FIFO.
clock
0 0 0 0 3232 0
0 0 0 0 00
2 3 4 51
Current Instruction
Stall
TX FIFO Empty
TX FIFO Pop
OSR Count (0=full)
RX FIFO Push
ISR Count (0=empty)
RX FIFO Push
INOUT OUT IN OUT
IN OUT IN INOUT OUT
Figure 42. Execution
of auto_push_pull
program. The state
machine stalls on an
OUT until data has
travelled through the
TX FIFO into the OSR.
Subsequently, the OSR
is refilled
simultaneously with
each OUT operation
(due to bit count of
32), and IN data
bypasses the ISR and
goes straight to the RX
FIFO. The state
machine stalls again
when the FIFO has
drained, and the OSR
is once again empty.
To trigger automatic push or pull at the correct time, the state machine tracks the total shift count of the ISR and OSR,
using a pair of saturating 6 bit counters.
At reset, or upon CTRL_SM_RESTART assertion, ISR shift counter is set to 0 (nothing shifted in), and OSR to 32 (nothing
left to be shifted out)
An OUT instruction increases the OSR shift counter by Bit count
An IN instruction increases the ISR shift counter by Bit count
A PULL instruction or autopull clears the OSR counter to 0
A PUSH instruction or autopush clears the ISR counter to 0
A MOV OSR, x or MOV ISR, x clears the OSR or ISR shift counter to 0, respectively
A OUT ISR, n instruction sets the ISR shift counter to n
On any OUT or IN instruction, the state machine compares the shift counters to the values of SHIFTCTRL_PULL_THRESH and
SHIFTCTRL_PUSH_THRESH to decide whether action is required. Autopull and autopush are individually enabled by the
SHIFTCTRL_AUTOPULL and SHIFTCTRL_AUTOPUSH fields.
RP2040 Datasheet
3.5. Functional Details 337