From 954056da0ca4633d27f022858600164721963104 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 25 May 2021 21:02:40 +0700 Subject: [PATCH] fix warnings cast function type for nrf, fix pico osal warning add TODO for overflow in tusb_fifo.c --- examples/make.mk | 4 +++- hw/bsp/nrf/family.c | 7 ++++++- src/common/tusb_fifo.c | 2 ++ src/osal/osal_pico.h | 2 ++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/examples/make.mk b/examples/make.mk index 6366d6cef..df8bfd617 100644 --- a/examples/make.mk +++ b/examples/make.mk @@ -88,6 +88,7 @@ CFLAGS += \ -fno-strict-aliasing \ -Wdouble-promotion \ -Wstrict-prototypes \ + -Wstrict-overflow \ -Wall \ -Wextra \ -Werror \ @@ -100,7 +101,8 @@ CFLAGS += \ -Wsign-compare \ -Wmissing-format-attribute \ -Wunreachable-code \ - -Wcast-align + -Wcast-align \ + -Wcast-function-type # Debugging/Optimization ifeq ($(DEBUG), 1) diff --git a/hw/bsp/nrf/family.c b/hw/bsp/nrf/family.c index fc5e805d9..f117fbe33 100644 --- a/hw/bsp/nrf/family.c +++ b/hw/bsp/nrf/family.c @@ -55,6 +55,11 @@ static nrfx_uarte_t _uart_id = NRFX_UARTE_INSTANCE(0); // We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled. extern void tusb_hal_nrf_power_event(uint32_t event); +static void power_event_handler(nrfx_power_usb_evt_t event) +{ + tusb_hal_nrf_power_event((uint32_t) event); +} + void board_init(void) { // stop LF clock just in case we jump from application without reset @@ -121,7 +126,7 @@ void board_init(void) // Register tusb function as USB power handler // cause cast-function-type warning - const nrfx_power_usbevt_config_t config = { .handler = ((nrfx_power_usb_event_handler_t) tusb_hal_nrf_power_event) }; + const nrfx_power_usbevt_config_t config = { .handler = power_event_handler }; nrfx_power_usbevt_init(&config); nrfx_power_usbevt_enable(); diff --git a/src/common/tusb_fifo.c b/src/common/tusb_fifo.c index 81e11eb01..5f7b6a26d 100644 --- a/src/common/tusb_fifo.c +++ b/src/common/tusb_fifo.c @@ -325,6 +325,8 @@ static uint16_t advance_pointer(tu_fifo_t* f, uint16_t p, uint16_t offset) // We limit the index space of p such that a correct wrap around happens // Check for a wrap around or if we are in unused index space - This has to be checked first!! // We are exploiting the wrap around to the correct index + + // TODO warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false [-Wstrict-overflow] if ((p > p + offset) || (p + offset > f->max_pointer_idx)) { p = (p + offset) + f->non_used_index_space; diff --git a/src/osal/osal_pico.h b/src/osal/osal_pico.h index bae1217eb..1c3366e01 100644 --- a/src/osal/osal_pico.h +++ b/src/osal/osal_pico.h @@ -57,6 +57,7 @@ static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semde static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) { + (void) in_isr; sem_release(sem_hdl); return true; } @@ -158,6 +159,7 @@ static inline bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in // however osal_queue_recieve may be. therefore my assumption is that // the fifo mutex is not populated for queues used from an IRQ context //assert(!qhdl->ff.mutex); + (void) in_isr; _osal_q_lock(qhdl); bool success = tu_fifo_write(&qhdl->ff, data);