RISC-V: add configMTIME_INIT_IN_BSP

Add a new configMTIME_INIT_IN_BSP configuration macro to allow BSPs and
demo applications to initialise the MMIO MTIME pointers within the
CLINT. This enables BSPs to provide custom addresses or properly typed
pointer values, rather than relying on plain integer constants coming
from macros as is currently the case. This change does not affect
existing assumptions and usage, but allows architectures that
differentiate between integers and pointers to work.

Signed-off-by: Hesham Almatary <Hesham.Almatary@cl.cam.ac.uk>
This commit is contained in:
Hesham Almatary 2026-02-18 07:37:52 +00:00 committed by Patrick Cook
parent ab6ccbb04e
commit 2fe3c61c26

View file

@ -93,6 +93,9 @@ const size_t uxTimerIncrementsForOneTick = ( size_t ) ( ( configCPU_CLOCK_HZ ) /
UBaseType_t const ullMachineTimerCompareRegisterBase = configMTIMECMP_BASE_ADDRESS; UBaseType_t const ullMachineTimerCompareRegisterBase = configMTIMECMP_BASE_ADDRESS;
volatile uint64_t * pullMachineTimerCompareRegister = NULL; volatile uint64_t * pullMachineTimerCompareRegister = NULL;
volatile uint32_t * pulTimeHigh = ( volatile uint32_t * const ) ( ( configMTIME_BASE_ADDRESS ) + 4UL ); /* 8-byte type so high 32-bit word is 4 bytes up. */
volatile uint32_t * pulTimeLow = ( volatile uint32_t * const ) ( configMTIME_BASE_ADDRESS );
/* Holds the critical nesting value - deliberately non-zero at start up to /* Holds the critical nesting value - deliberately non-zero at start up to
* ensure interrupts are not accidentally enabled before the scheduler starts. */ * ensure interrupts are not accidentally enabled before the scheduler starts. */
size_t xCriticalNesting = ( size_t ) 0xaaaaaaaa; size_t xCriticalNesting = ( size_t ) 0xaaaaaaaa;
@ -130,13 +133,13 @@ ReturnFunctionType_t xTaskReturnAddress = ( ReturnFunctionType_t ) portTASK_RETU
void vPortSetupTimerInterrupt( void ) void vPortSetupTimerInterrupt( void )
{ {
uint32_t ulCurrentTimeHigh, ulCurrentTimeLow; uint32_t ulCurrentTimeHigh, ulCurrentTimeLow;
volatile uint32_t * const pulTimeHigh = ( volatile uint32_t * const ) ( ( configMTIME_BASE_ADDRESS ) + 4UL ); /* 8-byte type so high 32-bit word is 4 bytes up. */ #ifndef configMTIME_INIT_IN_BSP
volatile uint32_t * const pulTimeLow = ( volatile uint32_t * const ) ( configMTIME_BASE_ADDRESS ); {
volatile uint32_t ulHartId; volatile uint32_t ulHartId;
__asm volatile ( "csrr %0, mhartid" : "=r" ( ulHartId ) );
__asm volatile ( "csrr %0, mhartid" : "=r" ( ulHartId ) ); pullMachineTimerCompareRegister = ( volatile uint64_t * ) ( ullMachineTimerCompareRegisterBase + ( ulHartId * sizeof( uint64_t ) ) );
}
pullMachineTimerCompareRegister = ( volatile uint64_t * ) ( ullMachineTimerCompareRegisterBase + ( ulHartId * sizeof( uint64_t ) ) ); #endif
do do
{ {