Unless I am missing your point, using a PIO program is the exact reason for achieving what you are describing: achieving atomic operations. This pio program allows you to change the number of bits shifted out in one instruction cycle: which is 8nS if clock divider is 1.
It can set the out 16bits and then 8nS later shift out 16 bits. So maybe I am not understanding you objective: in other words why not let the PIO program deals with writing to register atomically by simply using PIO instructions.
Some SD functions allow you make atomic operations on registers: example, change state of gpio pins atomically in one clock cycle.
Example the following function change the state of a group of gpio pins to high atomically.
It can set the out 16bits and then 8nS later shift out 16 bits. So maybe I am not understanding you objective: in other words why not let the PIO program deals with writing to register atomically by simply using PIO instructions.
Code:
// PIO program to output 8 bits and then 16 bits// This program assumes you have set up the OUT_COUNT// in the SHIFTCTRL register appropriately in C code.// .program pio_output// .wrap_target// // Output 8 bits// out pins, 8// // Output 16 bits// out pins, 16// .wrap_end//// To assemble with pioasm:// pioasm -o c pio_output.pioasm > pio_output.h// Assembled PIO program (from pio_output.pioasm)static const uint16_t pio_output_program[] = { 0x6007, // OUT PINS, 8 0x600f, // OUT PINS, 16};Some SD functions allow you make atomic operations on registers: example, change state of gpio pins atomically in one clock cycle.
Example the following function change the state of a group of gpio pins to high atomically.
Code:
#include "pico/stdlib.h"/** * @brief Atomically sets a group of GPIO pins to high (1). * * @param mask A 32-bit mask where each bit, if set to 1, corresponds to a GPIO pin to be turned on. */void atomically_set_gpio_high(uint32_t mask) { // Use the gpio_set_mask function to atomically set the specified GPIOs high. gpio_set_mask(mask);}Statistics: Posted by Henderson Hood — Tue Apr 08, 2025 1:27 am