From d010f6ae8bc4e2ccfcc162b256e18ed61b71820d Mon Sep 17 00:00:00 2001 From: Matteo Concas Date: Mon, 16 Jun 2025 12:37:18 +0200 Subject: [PATCH] bsps/sparc/leon3: Fix GPTIMER timer index logic The old logic would lead to an error when multiprocessing was enabled and `LEON3_GPTIMER_BASE` was defined due to `leon3_timer_core_index` being undefined. The new logic fixes this and keeps the same intent: - If multiprocessing is not enabled, the timer index is 0 - If multiprocessing is enabled and `LEON3_GPTIMER_BASE` is defined, the timer index is twice the CPU boot index - If multiprocessing is enabled and `LEON3_GPTIMER_BASE` is not defined, we fallback to the old logic using the GPTIMER core index. Close #5281 --- bsps/sparc/leon3/btimer/btimer.c | 12 ++---------- bsps/sparc/leon3/include/bsp/leon3.h | 9 +++++---- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/bsps/sparc/leon3/btimer/btimer.c b/bsps/sparc/leon3/btimer/btimer.c index 9f2a7ede74..28701ae8af 100644 --- a/bsps/sparc/leon3/btimer/btimer.c +++ b/bsps/sparc/leon3/btimer/btimer.c @@ -21,14 +21,6 @@ #include #include -#if defined(RTEMS_MULTIPROCESSING) - #define LEON3_TIMER_INDEX \ - ((rtems_configuration_get_user_multiprocessing_table()) ? \ - (rtems_configuration_get_user_multiprocessing_table()->node) - 1 : 1) -#else - #define LEON3_TIMER_INDEX 0 -#endif - bool benchmark_timer_find_average_overhead; bool benchmark_timer_is_initialized = false; @@ -39,7 +31,7 @@ void benchmark_timer_initialize(void) * Timer runs long and accurate enough not to require an interrupt. */ if (LEON3_Timer_Regs) { - gptimer_timer *timer = &LEON3_Timer_Regs->timer[LEON3_TIMER_INDEX]; + gptimer_timer *timer = &LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX]; if ( benchmark_timer_is_initialized == false ) { /* approximately 1 us per countdown */ grlib_store_32( &timer->trldval, 0xffffff ); @@ -61,7 +53,7 @@ benchmark_timer_t benchmark_timer_read(void) if (LEON3_Timer_Regs) { total = - grlib_load_32( &LEON3_Timer_Regs->timer[LEON3_TIMER_INDEX].tcntval ); + grlib_load_32( &LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].tcntval ); total = 0xffffff - total; diff --git a/bsps/sparc/leon3/include/bsp/leon3.h b/bsps/sparc/leon3/include/bsp/leon3.h index df36e043bd..46926255ae 100644 --- a/bsps/sparc/leon3/include/bsp/leon3.h +++ b/bsps/sparc/leon3/include/bsp/leon3.h @@ -216,11 +216,12 @@ extern unsigned int leon3_timer_prescaler; * @brief This constant defines the index of the GPTIMER timer used by the * clock driver. */ -#if defined(RTEMS_MULTIPROCESSING) -#define LEON3_CLOCK_INDEX \ - ( leon3_timer_core_index != 0 ? 0 : 2 * LEON3_Cpu_Index ) -#else +#if !defined(RTEMS_MULTIPROCESSING) #define LEON3_CLOCK_INDEX 0 +#elif defined(LEON3_GPTIMER_BASE) +#define LEON3_CLOCK_INDEX ( 2 * LEON3_Cpu_Index ) +#else +#define LEON3_CLOCK_INDEX ( leon3_timer_core_index != 0 ? 0 : 2 * LEON3_Cpu_Index ) #endif /**