Additional param-validation for PIO (#805)

The RP2040 datasheet says "If INT is 0, FRAC must also be 0."
This commit is contained in:
Andrew Scheller 2022-05-04 21:25:43 +01:00 committed by GitHub
parent 6149b9e4ec
commit 3c450011da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -211,6 +211,7 @@ static inline void sm_config_set_sideset(pio_sm_config *c, uint bit_count, bool
* \sa sm_config_set_clkdiv() * \sa sm_config_set_clkdiv()
*/ */
static inline void sm_config_set_clkdiv_int_frac(pio_sm_config *c, uint16_t div_int, uint8_t div_frac) { static inline void sm_config_set_clkdiv_int_frac(pio_sm_config *c, uint16_t div_int, uint8_t div_frac) {
invalid_params_if(PIO, div_int == 0 && div_frac != 0);
c->clkdiv = c->clkdiv =
(((uint)div_frac) << PIO_SM0_CLKDIV_FRAC_LSB) | (((uint)div_frac) << PIO_SM0_CLKDIV_FRAC_LSB) |
(((uint)div_int) << PIO_SM0_CLKDIV_INT_LSB); (((uint)div_int) << PIO_SM0_CLKDIV_INT_LSB);
@ -1151,6 +1152,7 @@ void pio_sm_drain_tx_fifo(PIO pio, uint sm);
static inline void pio_sm_set_clkdiv_int_frac(PIO pio, uint sm, uint16_t div_int, uint8_t div_frac) { static inline void pio_sm_set_clkdiv_int_frac(PIO pio, uint sm, uint16_t div_int, uint8_t div_frac) {
check_pio_param(pio); check_pio_param(pio);
check_sm_param(sm); check_sm_param(sm);
invalid_params_if(PIO, div_int == 0 && div_frac != 0);
pio->sm[sm].clkdiv = pio->sm[sm].clkdiv =
(((uint)div_frac) << PIO_SM0_CLKDIV_FRAC_LSB) | (((uint)div_frac) << PIO_SM0_CLKDIV_FRAC_LSB) |
(((uint)div_int) << PIO_SM0_CLKDIV_INT_LSB); (((uint)div_int) << PIO_SM0_CLKDIV_INT_LSB);