fixup __forceinline for cpp code and add kitchen_sink cpp test (#670)

* fix __force_inline for different GCC versions in cpp mode (the affected versions are different from c mode), and build kitchsink.c as a cpp file too for testing
* silly bug in host platform.h
This commit is contained in:
Graham Sanderson 2021-12-08 12:05:49 -06:00 committed by GitHub
parent 269332dc21
commit 0562089fab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 55 additions and 49 deletions

View File

@ -22,7 +22,7 @@ extern "C" {
#define __not_in_flash(group) #define __not_in_flash(group)
#define __not_in_flash_func(func) func #define __not_in_flash_func(func) func
#define __no_inline_not_in_flash_func(func) #define __no_inline_not_in_flash_func(func) func
#define __in_flash(group) #define __in_flash(group)
#define __scratch_x(group) #define __scratch_x(group)
#define __scratch_y(group) #define __scratch_y(group)

View File

@ -86,6 +86,6 @@ typedef struct {
io_ro_32 ints; io_ro_32 ints;
} adc_hw_t; } adc_hw_t;
#define adc_hw ((adc_hw_t *const)ADC_BASE) #define adc_hw ((adc_hw_t *)ADC_BASE)
#endif #endif

View File

@ -72,6 +72,6 @@ typedef struct {
bus_ctrl_perf_hw_t counter[4]; bus_ctrl_perf_hw_t counter[4];
} bus_ctrl_hw_t; } bus_ctrl_hw_t;
#define bus_ctrl_hw ((bus_ctrl_hw_t *const)BUSCTRL_BASE) #define bus_ctrl_hw ((bus_ctrl_hw_t *)BUSCTRL_BASE)
#endif #endif

View File

@ -319,7 +319,7 @@ typedef struct {
io_ro_32 ints; io_ro_32 ints;
} clocks_hw_t; } clocks_hw_t;
#define clocks_hw ((clocks_hw_t *const)CLOCKS_BASE) #define clocks_hw ((clocks_hw_t *)CLOCKS_BASE)
static_assert( CLK_COUNT == 10, ""); static_assert( CLK_COUNT == 10, "");

View File

@ -327,7 +327,7 @@ typedef struct {
io_ro_32 comp_type; io_ro_32 comp_type;
} i2c_hw_t; } i2c_hw_t;
#define i2c0_hw ((i2c_hw_t *const)I2C0_BASE) #define i2c0_hw ((i2c_hw_t *)I2C0_BASE)
#define i2c1_hw ((i2c_hw_t *const)I2C1_BASE) #define i2c1_hw ((i2c_hw_t *)I2C1_BASE)
#endif #endif

View File

@ -208,7 +208,7 @@ typedef struct {
io_irq_ctrl_hw_t dormant_wake_irq_ctrl; io_irq_ctrl_hw_t dormant_wake_irq_ctrl;
} iobank0_hw_t; } iobank0_hw_t;
#define iobank0_hw ((iobank0_hw_t *const)IO_BANK0_BASE) #define iobank0_hw ((iobank0_hw_t *)IO_BANK0_BASE)
/// \end::iobank0_hw[] /// \end::iobank0_hw[]
static_assert( NUM_BANK0_GPIOS == 30, ""); static_assert( NUM_BANK0_GPIOS == 30, "");

View File

@ -167,7 +167,7 @@ typedef struct {
io_qspi_ctrl_hw_t dormant_wake_qspi_ctrl; io_qspi_ctrl_hw_t dormant_wake_qspi_ctrl;
} ioqspi_hw_t; } ioqspi_hw_t;
#define ioqspi_hw ((ioqspi_hw_t *const)IO_QSPI_BASE) #define ioqspi_hw ((ioqspi_hw_t *)IO_QSPI_BASE)
static_assert( NUM_QSPI_GPIOS == 6, ""); static_assert( NUM_QSPI_GPIOS == 6, "");

View File

@ -56,6 +56,6 @@ typedef struct {
io_rw_32 rasr; io_rw_32 rasr;
} mpu_hw_t; } mpu_hw_t;
#define mpu_hw ((mpu_hw_t *const)(PPB_BASE + M0PLUS_MPU_TYPE_OFFSET)) #define mpu_hw ((mpu_hw_t *)(PPB_BASE + M0PLUS_MPU_TYPE_OFFSET))
#endif #endif

View File

@ -40,7 +40,7 @@ typedef struct {
io_rw_32 io[NUM_QSPI_GPIOS]; // 6 io_rw_32 io[NUM_QSPI_GPIOS]; // 6
} pads_qspi_hw_t; } pads_qspi_hw_t;
#define pads_qspi_hw ((pads_qspi_hw_t *const)PADS_QSPI_BASE) #define pads_qspi_hw ((pads_qspi_hw_t *)PADS_QSPI_BASE)
static_assert( NUM_QSPI_GPIOS == 6, ""); static_assert( NUM_QSPI_GPIOS == 6, "");

View File

@ -40,7 +40,7 @@ typedef struct {
io_rw_32 io[NUM_BANK0_GPIOS]; // 30 io_rw_32 io[NUM_BANK0_GPIOS]; // 30
} padsbank0_hw_t; } padsbank0_hw_t;
#define padsbank0_hw ((padsbank0_hw_t *const)PADS_BANK0_BASE) #define padsbank0_hw ((padsbank0_hw_t *)PADS_BANK0_BASE)
static_assert( NUM_BANK0_GPIOS == 30, ""); static_assert( NUM_BANK0_GPIOS == 30, "");

View File

@ -275,8 +275,8 @@ typedef struct {
io_ro_32 ints1; io_ro_32 ints1;
} pio_hw_t; } pio_hw_t;
#define pio0_hw ((pio_hw_t *const)PIO0_BASE) #define pio0_hw ((pio_hw_t *)PIO0_BASE)
#define pio1_hw ((pio_hw_t *const)PIO1_BASE) #define pio1_hw ((pio_hw_t *)PIO1_BASE)
static_assert( NUM_PIO_STATE_MACHINES == 4, ""); static_assert( NUM_PIO_STATE_MACHINES == 4, "");
static_assert( PIO_INSTRUCTION_COUNT == 32, ""); static_assert( PIO_INSTRUCTION_COUNT == 32, "");

View File

@ -49,8 +49,8 @@ typedef struct {
io_rw_32 prim; io_rw_32 prim;
} pll_hw_t; } pll_hw_t;
#define pll_sys_hw ((pll_hw_t *const)PLL_SYS_BASE) #define pll_sys_hw ((pll_hw_t *)PLL_SYS_BASE)
#define pll_usb_hw ((pll_hw_t *const)PLL_USB_BASE) #define pll_usb_hw ((pll_hw_t *)PLL_USB_BASE)
/// \end::pll_hw[] /// \end::pll_hw[]
#endif #endif

View File

@ -106,6 +106,6 @@ typedef struct {
io_ro_32 done; io_ro_32 done;
} psm_hw_t; } psm_hw_t;
#define psm_hw ((psm_hw_t *const)PSM_BASE) #define psm_hw ((psm_hw_t *)PSM_BASE)
#endif #endif

View File

@ -119,7 +119,7 @@ typedef struct {
io_ro_32 ints; io_ro_32 ints;
} pwm_hw_t; } pwm_hw_t;
#define pwm_hw ((pwm_hw_t *const)PWM_BASE) #define pwm_hw ((pwm_hw_t *)PWM_BASE)
static_assert( NUM_PWM_SLICES == 8, ""); static_assert( NUM_PWM_SLICES == 8, "");

View File

@ -110,7 +110,7 @@ typedef struct {
io_ro_32 reset_done; io_ro_32 reset_done;
} resets_hw_t; } resets_hw_t;
#define resets_hw ((resets_hw_t *const)RESETS_BASE) #define resets_hw ((resets_hw_t *)RESETS_BASE)
/// \end::resets_hw[] /// \end::resets_hw[]
#endif #endif

View File

@ -81,6 +81,6 @@ typedef struct {
io_rw_32 count; io_rw_32 count;
} rosc_hw_t; } rosc_hw_t;
#define rosc_hw ((rosc_hw_t *const)ROSC_BASE) #define rosc_hw ((rosc_hw_t *)ROSC_BASE)
#endif #endif

View File

@ -109,6 +109,6 @@ typedef struct {
io_ro_32 ints; io_ro_32 ints;
} rtc_hw_t; } rtc_hw_t;
#define rtc_hw ((rtc_hw_t *const)RTC_BASE) #define rtc_hw ((rtc_hw_t *)RTC_BASE)
#endif #endif

View File

@ -64,6 +64,6 @@ typedef struct {
io_rw_32 scr; io_rw_32 scr;
} armv6m_scb_t; } armv6m_scb_t;
#define scb_hw ((armv6m_scb_t *const)(PPB_BASE + M0PLUS_CPUID_OFFSET)) #define scb_hw ((armv6m_scb_t *)(PPB_BASE + M0PLUS_CPUID_OFFSET))
#endif #endif

View File

@ -171,6 +171,6 @@ typedef struct {
interp_hw_t interp[2]; interp_hw_t interp[2];
} sio_hw_t; } sio_hw_t;
#define sio_hw ((sio_hw_t *const)SIO_BASE) #define sio_hw ((sio_hw_t *)SIO_BASE)
#endif #endif

View File

@ -94,7 +94,7 @@ typedef struct {
io_rw_32 dmacr; io_rw_32 dmacr;
} spi_hw_t; } spi_hw_t;
#define spi0_hw ((spi_hw_t *const)SPI0_BASE) #define spi0_hw ((spi_hw_t *)SPI0_BASE)
#define spi1_hw ((spi_hw_t *const)SPI1_BASE) #define spi1_hw ((spi_hw_t *)SPI1_BASE)
#endif #endif

View File

@ -205,6 +205,6 @@ typedef struct {
io_rw_32 txd_drive_edge; io_rw_32 txd_drive_edge;
} ssi_hw_t; } ssi_hw_t;
#define ssi_hw ((ssi_hw_t *const)XIP_SSI_BASE) #define ssi_hw ((ssi_hw_t *)XIP_SSI_BASE)
#endif #endif

View File

@ -72,6 +72,6 @@ typedef struct {
io_rw_32 mempowerdown; io_rw_32 mempowerdown;
} syscfg_hw_t; } syscfg_hw_t;
#define syscfg_hw ((syscfg_hw_t *const)SYSCFG_BASE) #define syscfg_hw ((syscfg_hw_t *)SYSCFG_BASE)
#endif #endif

View File

@ -47,6 +47,6 @@ typedef struct {
io_ro_32 calib; io_ro_32 calib;
} systick_hw_t; } systick_hw_t;
#define systick_hw ((systick_hw_t *const)(PPB_BASE + M0PLUS_SYST_CSR_OFFSET)) #define systick_hw ((systick_hw_t *)(PPB_BASE + M0PLUS_SYST_CSR_OFFSET))
#endif #endif

View File

@ -100,7 +100,7 @@ typedef struct {
io_ro_32 ints; io_ro_32 ints;
} timer_hw_t; } timer_hw_t;
#define timer_hw ((timer_hw_t *const)TIMER_BASE) #define timer_hw ((timer_hw_t *)TIMER_BASE)
static_assert( NUM_TIMERS == 4, ""); static_assert( NUM_TIMERS == 4, "");

View File

@ -171,7 +171,7 @@ typedef struct {
io_rw_32 dmacr; io_rw_32 dmacr;
} uart_hw_t; } uart_hw_t;
#define uart0_hw ((uart_hw_t *const)UART0_BASE) #define uart0_hw ((uart_hw_t *)UART0_BASE)
#define uart1_hw ((uart_hw_t *const)UART1_BASE) #define uart1_hw ((uart_hw_t *)UART1_BASE)
#endif #endif

View File

@ -568,7 +568,7 @@ typedef struct {
io_ro_32 ints; io_ro_32 ints;
} usb_hw_t; } usb_hw_t;
#define usb_hw ((usb_hw_t *const)USBCTRL_REGS_BASE) #define usb_hw ((usb_hw_t *)USBCTRL_REGS_BASE)
#define usb_dpram ((usb_device_dpram_t *)USBCTRL_DPRAM_BASE) #define usb_dpram ((usb_device_dpram_t *)USBCTRL_DPRAM_BASE)
#define usbh_dpram ((usb_host_dpram_t *)USBCTRL_DPRAM_BASE) #define usbh_dpram ((usb_host_dpram_t *)USBCTRL_DPRAM_BASE)

View File

@ -44,6 +44,6 @@ typedef struct {
io_rw_32 chip_reset; io_rw_32 chip_reset;
} vreg_and_chip_reset_hw_t; } vreg_and_chip_reset_hw_t;
#define vreg_and_chip_reset_hw ((vreg_and_chip_reset_hw_t *const)VREG_AND_CHIP_RESET_BASE) #define vreg_and_chip_reset_hw ((vreg_and_chip_reset_hw_t *)VREG_AND_CHIP_RESET_BASE)
#endif #endif

View File

@ -57,6 +57,6 @@ typedef struct {
io_rw_32 tick; io_rw_32 tick;
} watchdog_hw_t; } watchdog_hw_t;
#define watchdog_hw ((watchdog_hw_t *const)WATCHDOG_BASE) #define watchdog_hw ((watchdog_hw_t *)WATCHDOG_BASE)
#endif #endif

View File

@ -63,7 +63,7 @@ typedef struct {
io_ro_32 stream_fifo; io_ro_32 stream_fifo;
} xip_ctrl_hw_t; } xip_ctrl_hw_t;
#define xip_ctrl_hw ((xip_ctrl_hw_t *const)XIP_CTRL_BASE) #define xip_ctrl_hw ((xip_ctrl_hw_t *)XIP_CTRL_BASE)
#define XIP_STAT_FIFO_FULL XIP_STAT_FIFO_FULL_BITS #define XIP_STAT_FIFO_FULL XIP_STAT_FIFO_FULL_BITS
#define XIP_STAT_FIFO_EMPTY XIP_STAT_FIFO_EMPTY_BITS #define XIP_STAT_FIFO_EMPTY XIP_STAT_FIFO_EMPTY_BITS

View File

@ -54,7 +54,7 @@ typedef struct {
io_rw_32 count; io_rw_32 count;
} xosc_hw_t; } xosc_hw_t;
#define xosc_hw ((xosc_hw_t *const)XOSC_BASE) #define xosc_hw ((xosc_hw_t *)XOSC_BASE)
/// \end::xosc_hw[] /// \end::xosc_hw[]
#endif #endif

View File

@ -53,7 +53,7 @@ typedef struct spi_inst spi_inst_t;
* *
* \ingroup hardware_spi * \ingroup hardware_spi
*/ */
#define spi0 ((spi_inst_t * const)spi0_hw) #define spi0 ((spi_inst_t *)spi0_hw)
/** Identifier for the second (SPI 1) hardware SPI instance (for use in SPI functions). /** Identifier for the second (SPI 1) hardware SPI instance (for use in SPI functions).
* *
@ -61,7 +61,7 @@ typedef struct spi_inst spi_inst_t;
* *
* \ingroup hardware_spi * \ingroup hardware_spi
*/ */
#define spi1 ((spi_inst_t * const)spi1_hw) #define spi1 ((spi_inst_t *)spi1_hw)
#if !defined(PICO_DEFAULT_SPI_INSTANCE) && defined(PICO_DEFAULT_SPI) #if !defined(PICO_DEFAULT_SPI_INSTANCE) && defined(PICO_DEFAULT_SPI)
#define PICO_DEFAULT_SPI_INSTANCE (__CONCAT(spi,PICO_DEFAULT_SPI)) #define PICO_DEFAULT_SPI_INSTANCE (__CONCAT(spi,PICO_DEFAULT_SPI))

View File

@ -78,8 +78,8 @@ typedef struct uart_inst uart_inst_t;
* \ingroup hardware_uart * \ingroup hardware_uart
* @{ * @{
*/ */
#define uart0 ((uart_inst_t * const)uart0_hw) ///< Identifier for UART instance 0 #define uart0 ((uart_inst_t *)uart0_hw) ///< Identifier for UART instance 0
#define uart1 ((uart_inst_t * const)uart1_hw) ///< Identifier for UART instance 1 #define uart1 ((uart_inst_t *)uart1_hw) ///< Identifier for UART instance 1
/** @} */ /** @} */

View File

@ -233,7 +233,7 @@ extern "C" {
* int __force_inline my_function(int x) { * int __force_inline my_function(int x) {
* *
*/ */
#if defined(__GNUC__) && __GNUC__ <= 7 #if defined(__GNUC__) && (__GNUC__ <= 6 || (__GNUC__ == 7 && (__GNUC_MINOR__ < 3 || !defined(__cplusplus))))
#define __force_inline inline __always_inline #define __force_inline inline __always_inline
#else #else
#define __force_inline __always_inline #define __force_inline __always_inline

View File

@ -1,7 +1,4 @@
add_library(kitchen_sink_libs INTERFACE) add_library(kitchen_sink_libs INTERFACE)
target_sources(kitchen_sink_libs INTERFACE
${CMAKE_CURRENT_LIST_DIR}/kitchen_sink.c
)
target_link_libraries(kitchen_sink_libs INTERFACE target_link_libraries(kitchen_sink_libs INTERFACE
hardware_adc hardware_adc
hardware_clocks hardware_clocks
@ -91,12 +88,12 @@ target_compile_definitions(kitchen_sink_libs INTERFACE
PICO_AUDIO_DMA_IRQ=1 PICO_AUDIO_DMA_IRQ=1
) )
add_executable(kitchen_sink) add_executable(kitchen_sink ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink.c)
target_link_libraries(kitchen_sink kitchen_sink_libs kitchen_sink_options) target_link_libraries(kitchen_sink kitchen_sink_libs kitchen_sink_options)
pico_set_program_name(kitchen_sink "Wombat tentacles") pico_set_program_name(kitchen_sink "Wombat tentacles")
pico_add_extra_outputs(kitchen_sink) pico_add_extra_outputs(kitchen_sink)
add_executable(kitchen_sink_extra_stdio) add_executable(kitchen_sink_extra_stdio ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink.c)
if (COMMAND suppress_tinyusb_warnings) if (COMMAND suppress_tinyusb_warnings)
# Explicitly suppress warnings in TinyUSB files which have them (this has to be done # Explicitly suppress warnings in TinyUSB files which have them (this has to be done
# from the project that uses them per CMake "feature"). Note the function comes from # from the project that uses them per CMake "feature"). Note the function comes from
@ -108,13 +105,17 @@ pico_add_extra_outputs(kitchen_sink_extra_stdio)
pico_enable_stdio_usb(kitchen_sink_extra_stdio 1) pico_enable_stdio_usb(kitchen_sink_extra_stdio 1)
pico_enable_stdio_semihosting(kitchen_sink_extra_stdio 1) pico_enable_stdio_semihosting(kitchen_sink_extra_stdio 1)
add_executable(kitchen_sink_copy_to_ram) add_executable(kitchen_sink_copy_to_ram ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink.c)
pico_set_binary_type(kitchen_sink_copy_to_ram copy_to_ram) pico_set_binary_type(kitchen_sink_copy_to_ram copy_to_ram)
target_link_libraries(kitchen_sink_copy_to_ram kitchen_sink_libs kitchen_sink_options) target_link_libraries(kitchen_sink_copy_to_ram kitchen_sink_libs kitchen_sink_options)
pico_add_extra_outputs(kitchen_sink_copy_to_ram) pico_add_extra_outputs(kitchen_sink_copy_to_ram)
add_executable(kitchen_sink_no_flash) add_executable(kitchen_sink_no_flash ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink.c)
pico_set_binary_type(kitchen_sink_no_flash no_flash) pico_set_binary_type(kitchen_sink_no_flash no_flash)
target_link_libraries(kitchen_sink_no_flash kitchen_sink_libs kitchen_sink_options) target_link_libraries(kitchen_sink_no_flash kitchen_sink_libs kitchen_sink_options)
pico_add_extra_outputs(kitchen_sink_no_flash) pico_add_extra_outputs(kitchen_sink_no_flash)
add_executable(kitchen_sink_cpp ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink_cpp.cpp)
target_link_libraries(kitchen_sink_cpp kitchen_sink_libs kitchen_sink_options)
pico_set_program_name(kitchen_sink_cpp "Wombat tentacles CPP")
pico_add_extra_outputs(kitchen_sink_cpp)

View File

@ -97,7 +97,7 @@ uint32_t *foo = (uint32_t *) 200;
uint32_t dma_to = 0; uint32_t dma_to = 0;
uint32_t dma_from = 0xaaaa5555; uint32_t dma_from = 0xaaaa5555;
void spiggle(void) { void __noinline spiggle(void) {
dma_channel_config c = dma_channel_get_default_config(1); dma_channel_config c = dma_channel_get_default_config(1);
channel_config_set_bswap(&c, true); channel_config_set_bswap(&c, true);
channel_config_set_transfer_data_size(&c, DMA_SIZE_16); channel_config_set_transfer_data_size(&c, DMA_SIZE_16);
@ -106,6 +106,10 @@ void spiggle(void) {
dma_channel_transfer_from_buffer_now(1, foo, 23); dma_channel_transfer_from_buffer_now(1, foo, 23);
} }
__force_inline int something_inlined(int x) {
return x * 2;
}
void __isr dma_handler_a(void) { void __isr dma_handler_a(void) {
printf("HELLO A\n"); printf("HELLO A\n");
if (dma_hw->ints1 & 1) { if (dma_hw->ints1 & 1) {
@ -131,7 +135,7 @@ int main(void) {
stdio_init_all(); stdio_init_all();
printf("HI %d\n", (int)time_us_32()); printf("HI %d\n", something_inlined((int)time_us_32()));
puts("Hello Everything!"); puts("Hello Everything!");
puts("Hello Everything2!"); puts("Hello Everything2!");

View File

@ -0,0 +1 @@
#include "kitchen_sink.c"