Skip to content

Commit a6a8bac

Browse files
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>
1 parent daeb695 commit a6a8bac

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

portable/GCC/RISC-V/port.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ const size_t uxTimerIncrementsForOneTick = ( size_t ) ( ( configCPU_CLOCK_HZ ) /
9393
UBaseType_t const ullMachineTimerCompareRegisterBase = configMTIMECMP_BASE_ADDRESS;
9494
volatile uint64_t * pullMachineTimerCompareRegister = NULL;
9595

96+
volatile uint32_t * pulTimeHigh = ( volatile uint32_t * const ) ( ( configMTIME_BASE_ADDRESS ) + 4UL ); /* 8-byte type so high 32-bit word is 4 bytes up. */
97+
volatile uint32_t * pulTimeLow = ( volatile uint32_t * const ) ( configMTIME_BASE_ADDRESS );
98+
9699
/* Holds the critical nesting value - deliberately non-zero at start up to
97100
* ensure interrupts are not accidentally enabled before the scheduler starts. */
98101
size_t xCriticalNesting = ( size_t ) 0xaaaaaaaa;
@@ -130,13 +133,13 @@ ReturnFunctionType_t xTaskReturnAddress = ( ReturnFunctionType_t ) portTASK_RETU
130133
void vPortSetupTimerInterrupt( void )
131134
{
132135
uint32_t ulCurrentTimeHigh, ulCurrentTimeLow;
133-
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. */
134-
volatile uint32_t * const pulTimeLow = ( volatile uint32_t * const ) ( configMTIME_BASE_ADDRESS );
135-
volatile uint32_t ulHartId;
136-
137-
__asm volatile ( "csrr %0, mhartid" : "=r" ( ulHartId ) );
138-
139-
pullMachineTimerCompareRegister = ( volatile uint64_t * ) ( ullMachineTimerCompareRegisterBase + ( ulHartId * sizeof( uint64_t ) ) );
136+
#ifndef configMTIME_INIT_IN_BSP
137+
{
138+
volatile uint32_t ulHartId;
139+
__asm volatile ( "csrr %0, mhartid" : "=r" ( ulHartId ) );
140+
pullMachineTimerCompareRegister = ( volatile uint64_t * ) ( ullMachineTimerCompareRegisterBase + ( ulHartId * sizeof( uint64_t ) ) );
141+
}
142+
#endif
140143

141144
do
142145
{

0 commit comments

Comments
 (0)