Skip to content

Commit 92f948c

Browse files
authored
Make kitchen_sink check param assertions, and include all headers - fix sign-compare warnings (#316)
1 parent 0911393 commit 92f948c

File tree

6 files changed

+53
-19
lines changed

6 files changed

+53
-19
lines changed

src/rp2_common/hardware_dma/dma.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ void print_dma_ctrl(dma_channel_hw_t *channel) {
6060
ctrl & DMA_CH0_CTRL_TRIG_HIGH_PRIORITY_BITS ? 1 : 0,
6161
ctrl & DMA_CH0_CTRL_TRIG_EN_BITS ? 1 : 0);
6262
}
63+
#endif
6364

64-
void check_dma_channel_param_impl(uint channel) {
65+
#if PARAM_ASSERTIONS_ENABLED(DMA)
66+
void check_dma_channel_param_impl(uint __unused channel) {
6567
valid_params_if(DMA, channel < NUM_DMA_CHANNELS);
6668
}
67-
6869
#endif

src/rp2_common/hardware_gpio/gpio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ int gpio_get_pad(uint gpio) {
2727
// This also clears the input/output/irq override bits.
2828
void gpio_set_function(uint gpio, enum gpio_function fn) {
2929
invalid_params_if(GPIO, gpio >= NUM_BANK0_GPIOS);
30-
invalid_params_if(GPIO, fn << IO_BANK0_GPIO0_CTRL_FUNCSEL_LSB & ~IO_BANK0_GPIO0_CTRL_FUNCSEL_BITS);
30+
invalid_params_if(GPIO, ((uint32_t)fn << IO_BANK0_GPIO0_CTRL_FUNCSEL_LSB) & ~IO_BANK0_GPIO0_CTRL_FUNCSEL_BITS);
3131
// Set input enable on, output disable off
3232
hw_write_masked(&padsbank0_hw->io[gpio],
3333
PADS_BANK0_GPIO0_IE_BITS,

src/rp2_common/hardware_pio/include/hardware/pio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ static inline void sm_config_set_out_shift(pio_sm_config *c, bool shift_right, b
320320
* \param join Specifies the join type. \see enum pio_fifo_join
321321
*/
322322
static inline void sm_config_set_fifo_join(pio_sm_config *c, enum pio_fifo_join join) {
323-
valid_params_if(PIO, join >= PIO_FIFO_JOIN_NONE && join <= PIO_FIFO_JOIN_RX);
323+
valid_params_if(PIO, join == PIO_FIFO_JOIN_NONE || join == PIO_FIFO_JOIN_TX || join == PIO_FIFO_JOIN_RX);
324324
c->shiftctrl = (c->shiftctrl & (uint)~(PIO_SM0_SHIFTCTRL_FJOIN_TX_BITS | PIO_SM0_SHIFTCTRL_FJOIN_RX_BITS)) |
325325
(((uint)join) << PIO_SM0_SHIFTCTRL_FJOIN_TX_LSB);
326326
}
@@ -350,7 +350,7 @@ static inline void sm_config_set_out_special(pio_sm_config *c, bool sticky, bool
350350
* \param status_n parameter for the mov status operation (currently a bit count)
351351
*/
352352
static inline void sm_config_set_mov_status(pio_sm_config *c, enum pio_mov_status_type status_sel, uint status_n) {
353-
valid_params_if(PIO, status_sel >= STATUS_TX_LESSTHAN && status_sel <= STATUS_RX_LESSTHAN);
353+
valid_params_if(PIO, status_sel == STATUS_TX_LESSTHAN || status_sel == STATUS_RX_LESSTHAN);
354354
c->execctrl = (c->execctrl
355355
& ~(PIO_SM0_EXECCTRL_STATUS_SEL_BITS | PIO_SM0_EXECCTRL_STATUS_N_BITS))
356356
| ((((uint)status_sel) << PIO_SM0_EXECCTRL_STATUS_SEL_LSB) & PIO_SM0_EXECCTRL_STATUS_SEL_BITS)

src/rp2_common/hardware_pwm/include/hardware/pwm.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ extern "C" {
4747
*/
4848
enum pwm_clkdiv_mode
4949
{
50-
PWM_DIV_FREE_RUNNING, ///< Free-running counting at rate dictated by fractional divider
51-
PWM_DIV_B_HIGH, ///< Fractional divider is gated by the PWM B pin
52-
PWM_DIV_B_RISING, ///< Fractional divider advances with each rising edge of the PWM B pin
53-
PWM_DIV_B_FALLING ///< Fractional divider advances with each falling edge of the PWM B pin
50+
PWM_DIV_FREE_RUNNING = 0, ///< Free-running counting at rate dictated by fractional divider
51+
PWM_DIV_B_HIGH = 1, ///< Fractional divider is gated by the PWM B pin
52+
PWM_DIV_B_RISING = 2, ///< Fractional divider advances with each rising edge of the PWM B pin
53+
PWM_DIV_B_FALLING = 3 ///< Fractional divider advances with each falling edge of the PWM B pin
5454
};
5555

5656
enum pwm_chan
@@ -144,7 +144,10 @@ static inline void pwm_config_set_clkdiv_int(pwm_config *c, uint div) {
144144
* high level, rising edge or falling edge of the B pin input.
145145
*/
146146
static inline void pwm_config_set_clkdiv_mode(pwm_config *c, enum pwm_clkdiv_mode mode) {
147-
valid_params_if(PWM, mode >= PWM_DIV_FREE_RUNNING && mode <= PWM_DIV_B_FALLING);
147+
valid_params_if(PWM, mode == PWM_DIV_FREE_RUNNING ||
148+
mode == PWM_DIV_B_RISING ||
149+
mode == PWM_DIV_B_HIGH ||
150+
mode == PWM_DIV_B_FALLING);
148151
c->csr = (c->csr & ~PWM_CH0_CSR_DIVMODE_BITS)
149152
| (((uint)mode) << PWM_CH0_CSR_DIVMODE_LSB);
150153
}
@@ -414,7 +417,10 @@ static inline void pwm_set_output_polarity(uint slice_num, bool a, bool b) {
414417
*/
415418
static inline void pwm_set_clkdiv_mode(uint slice_num, enum pwm_clkdiv_mode mode) {
416419
check_slice_num_param(slice_num);
417-
valid_params_if(PWM, mode >= PWM_DIV_FREE_RUNNING && mode <= PWM_DIV_B_FALLING);
420+
valid_params_if(PWM, mode == PWM_DIV_FREE_RUNNING ||
421+
mode == PWM_DIV_B_RISING ||
422+
mode == PWM_DIV_B_HIGH ||
423+
mode == PWM_DIV_B_FALLING);
418424
hw_write_masked(&pwm_hw->slice[slice_num].csr, ((uint)mode) << PWM_CH0_CSR_DIVMODE_LSB, PWM_CH0_CSR_DIVMODE_BITS);
419425
}
420426

test/kitchen_sink/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ target_compile_options(kitchen_sink_options INTERFACE
6666
-Wfloat-equal
6767
-Wmissing-format-attribute
6868
-Wconversion
69+
-Wsign-compare
6970
$<$<COMPILE_LANGUAGE:C>:-Wstrict-prototypes>
7071

7172
-Wno-inline
@@ -85,7 +86,7 @@ target_compile_options(kitchen_sink_options INTERFACE
8586
)
8687

8788
target_compile_definitions(kitchen_sink_libs INTERFACE
88-
NDEBUG
89+
PARAM_ASSERTIONS_ENABLE_ALL=1 # want to check all the assertions for compilation warnings
8990
PICO_AUDIO_DMA_IRQ=1
9091
)
9192

test/kitchen_sink/kitchen_sink.c

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,44 @@
55
*/
66

77
#include <stdio.h>
8-
#include "pico/stdlib.h"
9-
#include "pico/time.h"
8+
// Include all headers to check for compiler warnings
9+
#include "hardware/adc.h"
10+
#include "hardware/claim.h"
11+
#include "hardware/clocks.h"
12+
#include "hardware/divider.h"
1013
#include "hardware/dma.h"
11-
#include "pico/bit_ops.h"
14+
#include "hardware/flash.h"
15+
#include "hardware/gpio.h"
1216
#include "hardware/i2c.h"
13-
#include "hardware/pwm.h"
14-
#include "hardware/pio.h"
17+
#include "hardware/interp.h"
1518
#include "hardware/irq.h"
19+
#include "hardware/pio.h"
20+
#include "hardware/pll.h"
21+
#include "hardware/pwm.h"
22+
#include "hardware/resets.h"
23+
#include "hardware/rtc.h"
24+
#include "hardware/spi.h"
25+
#include "hardware/sync.h"
1626
#include "hardware/timer.h"
17-
#include "pico/divider.h"
18-
#include "pico/critical_section.h"
27+
#include "hardware/uart.h"
28+
#include "hardware/vreg.h"
29+
#include "hardware/watchdog.h"
30+
#include "hardware/xosc.h"
1931
#include "pico/binary_info.h"
32+
#include "pico/bit_ops.h"
33+
#include "pico/bootrom.h"
34+
#include "pico/divider.h"
35+
#include "pico/double.h"
36+
#include "pico/fix/rp2040_usb_device_enumeration.h"
37+
#include "pico/float.h"
38+
#include "pico/int64_ops.h"
39+
#include "pico/malloc.h"
40+
#include "pico/multicore.h"
41+
#include "pico/printf.h"
42+
#include "pico/stdlib.h"
43+
#include "pico/sync.h"
44+
#include "pico/time.h"
45+
#include "pico/unique_id.h"
2046

2147
bi_decl(bi_block_device(
2248
BINARY_INFO_MAKE_TAG('K', 'S'),

0 commit comments

Comments
 (0)