@@ -54,6 +54,17 @@ void cyw43_set_pio_clkdiv_int_frac8(uint32_t clock_div_int, uint8_t clock_div_fr
54
54
}
55
55
#endif
56
56
57
+ #if CYW43_PIO_SLEEP_MIN_US
58
+ static uint32_t bit_rate_khz ;
59
+ static void sleep_if_long_transfer (uint32_t xfr_length )
60
+ {
61
+ // Estimate transfer delay & sleep for about that long if it's long enough
62
+ unsigned xfr_us = (xfr_length * 8 * 1000 ) / bit_rate_khz ;
63
+ if (xfr_us > CYW43_PIO_SLEEP_MIN_US )
64
+ cyw43_delay_us (xfr_us );
65
+ }
66
+ #endif
67
+
57
68
#define PADS_DRIVE_STRENGTH PADS_BANK0_GPIO0_DRIVE_VALUE_12MA
58
69
59
70
#if !CYW43_USE_SPI
@@ -122,6 +133,10 @@ int cyw43_spi_init(cyw43_int_t *self) {
122
133
}
123
134
pio_sm_config config = SPI_PROGRAM_GET_DEFAULT_CONFIG_FUNC (bus_data -> pio_offset );
124
135
136
+ #if CYW43_PIO_SLEEP_MIN_US
137
+ // 2 PIO cycles per bit, PIO clock scaled
138
+ bit_rate_khz = clock_get_hz (clk_sys ) / (cyw43_pio_clock_div_int * 2 * 1000 );
139
+ #endif
125
140
sm_config_set_clkdiv_int_frac8 (& config , cyw43_pio_clock_div_int , cyw43_pio_clock_div_frac8 );
126
141
hw_write_masked (& pads_bank0_hw -> io [CYW43_PIN_WL_CLOCK ],
127
142
(uint )PADS_DRIVE_STRENGTH << PADS_BANK0_GPIO0_DRIVE_LSB ,
@@ -277,6 +292,9 @@ int cyw43_spi_transfer(cyw43_int_t *self, const uint8_t *tx, size_t tx_length, u
277
292
pio_sm_set_enabled (bus_data -> pio , bus_data -> pio_sm , true);
278
293
__compiler_memory_barrier ();
279
294
295
+ #if CYW43_PIO_SLEEP_MIN_US
296
+ sleep_if_long_transfer (MAX (tx_length , rx_length ));
297
+ #endif
280
298
dma_channel_wait_for_finish_blocking (bus_data -> dma_out );
281
299
dma_channel_wait_for_finish_blocking (bus_data -> dma_in );
282
300
@@ -309,6 +327,9 @@ int cyw43_spi_transfer(cyw43_int_t *self, const uint8_t *tx, size_t tx_length, u
309
327
dma_channel_configure (bus_data -> dma_out , & out_config , & bus_data -> pio -> txf [bus_data -> pio_sm ], tx , tx_length / 4 , true);
310
328
311
329
pio_sm_set_enabled (bus_data -> pio , bus_data -> pio_sm , true);
330
+ #if CYW43_PIO_SLEEP_MIN_US
331
+ sleep_if_long_transfer (tx_length );
332
+ #endif
312
333
dma_channel_wait_for_finish_blocking (bus_data -> dma_out );
313
334
314
335
uint32_t fdebug_tx_stall = 1u << (PIO_FDEBUG_TXSTALL_LSB + bus_data -> pio_sm );
0 commit comments