From 200a1a18ee980aad32c3239acc66af64d10c5a2b Mon Sep 17 00:00:00 2001 From: Andrew Dennison Date: Wed, 31 May 2023 17:17:04 +1000 Subject: [PATCH] soc/software: move helpers to hw/common.h Fixes warning: liblitespi/spiflash.c: In function 'spiflash_erase_range': liblitespi/spiflash.c:202:4: warning: implicit declaration of function 'cdelay' [-Wimplicit-function-declaration] cdelay(CONFIG_CLOCK_FREQUENCY/25); ^~~~~~ Fixes link failure with spiflash and without liblitedram after commit: 118dd6ed08 ld: ../liblitespi/liblitespi.a(spiflash.o): in function `spiflash_erase_range': ../liblitespi/spiflash.c:209: undefined reference to `cdelay' --- litex/soc/software/bios/boot.c | 7 ------- litex/soc/software/include/hw/common.h | 16 ++++++++++++++++ litex/soc/software/libbase/memtest.h | 3 --- litex/soc/software/liblitedram/sdram.c | 16 ---------------- litex/soc/software/liblitesdcard/sdcard.c | 7 ------- litex/soc/software/liblitesdcard/spisdcard.c | 7 ------- 6 files changed, 16 insertions(+), 40 deletions(-) diff --git a/litex/soc/software/bios/boot.c b/litex/soc/software/bios/boot.c index d30df1385..39233fcee 100755 --- a/litex/soc/software/bios/boot.c +++ b/litex/soc/software/bios/boot.c @@ -36,13 +36,6 @@ #include #include -/*-----------------------------------------------------------------------*/ -/* Helpers */ -/*-----------------------------------------------------------------------*/ - -#define max(x, y) (((x) > (y)) ? (x) : (y)) -#define min(x, y) (((x) < (y)) ? (x) : (y)) - /*-----------------------------------------------------------------------*/ /* Boot */ /*-----------------------------------------------------------------------*/ diff --git a/litex/soc/software/include/hw/common.h b/litex/soc/software/include/hw/common.h index 1d59794f9..927c13d1f 100644 --- a/litex/soc/software/include/hw/common.h +++ b/litex/soc/software/include/hw/common.h @@ -4,6 +4,22 @@ #include #include +/*-----------------------------------------------------------------------*/ +/* Helpers */ +/*-----------------------------------------------------------------------*/ + +#define max(x, y) (((x) > (y)) ? (x) : (y)) +#define min(x, y) (((x) < (y)) ? (x) : (y)) + +static inline void cdelay(int i) { +#ifndef CONFIG_BIOS_NO_DELAYS + while(i > 0) { + __asm__ volatile(CONFIG_CPU_NOP); + i--; + } +#endif // CONFIG_BIOS_NO_DELAYS +} + /* To overwrite CSR subregister accessors, define extern, non-inlined versions * of csr_[read|write]_simple(), and define CSR_ACCESSORS_DEFINED. */ diff --git a/litex/soc/software/libbase/memtest.h b/litex/soc/software/libbase/memtest.h index 955ed80c7..3a9a81005 100644 --- a/litex/soc/software/libbase/memtest.h +++ b/litex/soc/software/libbase/memtest.h @@ -10,9 +10,6 @@ extern "C" { #include #include -#define max(x, y) (((x) > (y)) ? (x) : (y)) -#define min(x, y) (((x) < (y)) ? (x) : (y)) - #ifndef MEMTEST_DATA_SIZE #define MEMTEST_DATA_SIZE (2*1024*1024) #endif diff --git a/litex/soc/software/liblitedram/sdram.c b/litex/soc/software/liblitedram/sdram.c index 0a00ed5fa..3d69d16cf 100644 --- a/litex/soc/software/liblitedram/sdram.c +++ b/litex/soc/software/liblitedram/sdram.c @@ -50,22 +50,6 @@ #define MODULO (1) #endif // SDRAM_PHY_DELAYS > 32 -/*-----------------------------------------------------------------------*/ -/* Helpers */ -/*-----------------------------------------------------------------------*/ - -#define max(x, y) (((x) > (y)) ? (x) : (y)) -#define min(x, y) (((x) < (y)) ? (x) : (y)) - -__attribute__((unused)) void cdelay(int i) { -#ifndef CONFIG_BIOS_NO_DELAYS - while(i > 0) { - __asm__ volatile(CONFIG_CPU_NOP); - i--; - } -#endif // CONFIG_BIOS_NO_DELAYS -} - /*-----------------------------------------------------------------------*/ /* Constants */ /*-----------------------------------------------------------------------*/ diff --git a/litex/soc/software/liblitesdcard/sdcard.c b/litex/soc/software/liblitesdcard/sdcard.c index 990d20572..05be4e670 100644 --- a/litex/soc/software/liblitesdcard/sdcard.c +++ b/litex/soc/software/liblitesdcard/sdcard.c @@ -33,13 +33,6 @@ #define SDCARD_CLK_FREQ 25000000 #endif -/*-----------------------------------------------------------------------*/ -/* Helpers */ -/*-----------------------------------------------------------------------*/ - -#define max(x, y) (((x) > (y)) ? (x) : (y)) -#define min(x, y) (((x) < (y)) ? (x) : (y)) - /*-----------------------------------------------------------------------*/ /* SDCard command helpers */ /*-----------------------------------------------------------------------*/ diff --git a/litex/soc/software/liblitesdcard/spisdcard.c b/litex/soc/software/liblitesdcard/spisdcard.c index 44cf231ea..9cdc1bad5 100644 --- a/litex/soc/software/liblitesdcard/spisdcard.c +++ b/litex/soc/software/liblitesdcard/spisdcard.c @@ -28,13 +28,6 @@ #define SPISDCARD_CLK_FREQ 20000000 #endif -/*-----------------------------------------------------------------------*/ -/* Helpers */ -/*-----------------------------------------------------------------------*/ - -#define max(x, y) (((x) > (y)) ? (x) : (y)) -#define min(x, y) (((x) < (y)) ? (x) : (y)) - /*-----------------------------------------------------------------------*/ /* SPI SDCard clocker functions */ /*-----------------------------------------------------------------------*/