From 3feb1a369bdba9868c92185b389cf5ddb397cb51 Mon Sep 17 00:00:00 2001 From: Frederik Haxel Date: Thu, 11 Jan 2024 12:01:21 +0100 Subject: [PATCH] drivers: 64 bit compatibility Fixed compilation errors for pointer casting. --- drivers/mtd_flashpage/mtd_flashpage.c | 9 ++++++--- drivers/soft_uart/soft_uart.c | 12 ++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/drivers/mtd_flashpage/mtd_flashpage.c b/drivers/mtd_flashpage/mtd_flashpage.c index 98db281b1d..f7bf1efd31 100644 --- a/drivers/mtd_flashpage/mtd_flashpage.c +++ b/drivers/mtd_flashpage/mtd_flashpage.c @@ -35,7 +35,7 @@ #define ENABLE_DEBUG 0 #include "debug.h" -#define MTD_FLASHPAGE_END_ADDR ((uint32_t) CPU_FLASH_BASE + (FLASHPAGE_NUMOF * FLASHPAGE_SIZE)) +#define MTD_FLASHPAGE_END_ADDR ((uintptr_t) CPU_FLASH_BASE + (FLASHPAGE_NUMOF * FLASHPAGE_SIZE)) static int _init(mtd_dev_t *dev) { @@ -44,11 +44,14 @@ static int _init(mtd_dev_t *dev) assert(dev->pages_per_sector * dev->page_size == FLASHPAGE_SIZE); assert(!(super->offset % dev->pages_per_sector)); - assert((int)flashpage_addr(super->offset / dev->pages_per_sector) >= (int)CPU_FLASH_BASE); + /* Use separate variable to avoid '>= 0 is always true' warning */ + static const uintptr_t cpu_flash_base = CPU_FLASH_BASE; + + assert((uintptr_t)flashpage_addr(super->offset / dev->pages_per_sector) >= cpu_flash_base); assert((uintptr_t)flashpage_addr(super->offset / dev->pages_per_sector) + dev->pages_per_sector * dev->page_size * dev->sector_count <= MTD_FLASHPAGE_END_ADDR); assert((uintptr_t)flashpage_addr(super->offset / dev->pages_per_sector) - + dev->pages_per_sector * dev->page_size * dev->sector_count > CPU_FLASH_BASE); + + dev->pages_per_sector * dev->page_size * dev->sector_count > cpu_flash_base); return 0; } diff --git a/drivers/soft_uart/soft_uart.c b/drivers/soft_uart/soft_uart.c index 23d0a25dc1..b5c4c168b9 100644 --- a/drivers/soft_uart/soft_uart.c +++ b/drivers/soft_uart/soft_uart.c @@ -65,7 +65,7 @@ struct uart_ctx { static void _tx_timer_cb(void *arg, int chan) { - soft_uart_t uart = (soft_uart_t)arg; + soft_uart_t uart = (soft_uart_t)(uintptr_t)arg; const soft_uart_conf_t *cfg = &soft_uart_config[uart]; struct uart_ctx *ctx = &soft_uart_ctx[uart]; @@ -81,7 +81,7 @@ static void _tx_timer_cb(void *arg, int chan) static void _rx_timer_cb(void *arg, int chan) { - soft_uart_t uart = (soft_uart_t)arg; + soft_uart_t uart = (soft_uart_t)(uintptr_t)arg; const soft_uart_conf_t *cfg = &soft_uart_config[uart]; struct uart_ctx *ctx = &soft_uart_ctx[uart]; @@ -101,7 +101,7 @@ static void _rx_timer_cb(void *arg, int chan) static void _rx_gpio_cb(void *arg) { - soft_uart_t uart = (soft_uart_t)arg; + soft_uart_t uart = (soft_uart_t)(uintptr_t)arg; const soft_uart_conf_t *cfg = &soft_uart_config[uart]; struct uart_ctx *ctx = &soft_uart_ctx[uart]; @@ -166,18 +166,18 @@ int soft_uart_init(soft_uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void ctx->state_rx = STATE_RX_IDLE; if (gpio_is_valid(cfg->tx_pin)) { - timer_init(cfg->tx_timer, cfg->timer_freq, _tx_timer_cb, (void *)uart); + timer_init(cfg->tx_timer, cfg->timer_freq, _tx_timer_cb, (void *)(uintptr_t)uart); gpio_write(cfg->tx_pin, !(cfg->flags & SOFT_UART_FLAG_INVERT_TX)); gpio_init(cfg->tx_pin, GPIO_OUT); } if (rx_cb) { - timer_init(cfg->rx_timer, cfg->timer_freq, _rx_timer_cb, (void *)uart); + timer_init(cfg->rx_timer, cfg->timer_freq, _rx_timer_cb, (void *)(uintptr_t)uart); timer_stop(cfg->rx_timer); /* timer should fire at the end of the byte */ timer_set_periodic(cfg->rx_timer, 0, ctx->bit_time * (BITS_DATA(ctx) + BITS_PARITY(ctx) + 1), TIM_FLAG_RESET_ON_MATCH | TIM_FLAG_RESET_ON_SET); - gpio_init_int(cfg->rx_pin, GPIO_IN, GPIO_BOTH, _rx_gpio_cb, (void*) uart); + gpio_init_int(cfg->rx_pin, GPIO_IN, GPIO_BOTH, _rx_gpio_cb, (void*)(uintptr_t)uart); } return 0;