From: rtel Date: Wed, 12 Sep 2018 16:33:05 +0000 (+0000) Subject: RISC-V: X-Git-Tag: V10.2.0~59 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=3341a29bfc974113e126cbf374cc52282627c898;p=freertos RISC-V: Added code to setup the timer interrupt - not tested yet. Added the taskYIELD() implementation - so far just checked it generates an interrupt. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2583 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- diff --git a/FreeRTOS/Source/portable/GCC/RISC-V-RV32/port.c b/FreeRTOS/Source/portable/GCC/RISC-V-RV32/port.c index 4fab2fd6a..17dbb0d80 100644 --- a/FreeRTOS/Source/portable/GCC/RISC-V-RV32/port.c +++ b/FreeRTOS/Source/portable/GCC/RISC-V-RV32/port.c @@ -39,7 +39,7 @@ * file is weak to allow application writers to change the timer used to * generate the tick interrupt. */ -void vPortSetupTimerInterrupt( void ); +void vPortSetupTimerInterrupt( void ) __attribute__(( weak )); /* * Used to catch tasks that attempt to return from their implementing function. @@ -48,10 +48,16 @@ static void prvTaskExitError( void ); /*-----------------------------------------------------------*/ +/* Used to program the machine timer compare register. */ +static uint64_t ullNextTime = 0ULL; +static volatile uint64_t * const pullMachineTimerCompareRegister = ( volatile uint64_t * const ) 0x2004000; + +/*-----------------------------------------------------------*/ + void prvTaskExitError( void ) { volatile uint32_t ulx = 0; - +#warning prvTaskExitError not used yet. /* A function that implements a task must not exit or attempt to return to its caller as there is nothing to return to. If a task wants to exit it should instead call vTaskDelete( NULL ). @@ -154,6 +160,29 @@ StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t px } /*-----------------------------------------------------------*/ +void vPortSetupTimerInterrupt( void ) +{ +uint32_t ulCurrentTimeHigh, ulCurrentTimeLow; +volatile uint32_t * const pulTimeHigh = ( volatile uint32_t * const ) 0x200BFF8; +volatile uint32_t * const pulTimeLow = ( volatile uint32_t * const ) 0x200BFFc; + + do + { + ulCurrentTimeHigh = *pulTimeHigh; + ulCurrentTimeLow = *pulTimeLow; + } while( ulCurrentTimeHigh != *pulTimeHigh ); + + ullNextTime = ( uint64_t ) ulCurrentTimeHigh; + ullNextTime <<= 32ULL; + ullNextTime |= ( uint64_t ) ulCurrentTimeLow; + ullNextTime += ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ); + *pullMachineTimerCompareRegister = ullNextTime; + + /* Enable timer interrupt */ + __asm volatile( "csrs mie, %0" :: "r"(0x80) ); +} +/*-----------------------------------------------------------*/ + BaseType_t xPortStartScheduler( void ) { __asm volatile @@ -189,6 +218,7 @@ BaseType_t xPortStartScheduler( void ) "lw x6, 100( sp ) \r\n" /* X6 */ "lw x5, 104( sp ) \r\n" /* X5 */ "lw x1, 108( sp ) \r\n" /* X1 */ + "csrs mie, 8 \r\n" /* Enable soft interrupt. */ "csrs mstatus, 8 \r\n" /* Enable interrupts. */ "ret " ); @@ -198,8 +228,5 @@ BaseType_t xPortStartScheduler( void ) } /*-----------------------------------------------------------*/ -void vPortYield( void ) -{ -} diff --git a/FreeRTOS/Source/portable/GCC/RISC-V-RV32/portmacro.h b/FreeRTOS/Source/portable/GCC/RISC-V-RV32/portmacro.h index 5d18ba34a..7132bf4ba 100644 --- a/FreeRTOS/Source/portable/GCC/RISC-V-RV32/portmacro.h +++ b/FreeRTOS/Source/portable/GCC/RISC-V-RV32/portmacro.h @@ -70,8 +70,7 @@ not need to be guarded with a critical section. */ /* Scheduler utilities. */ -extern void vPortYield( void ); -#define portYIELD() vPortYield() +#define portYIELD() { volatile uint32_t * const ulSoftInterrupt = ( uint32_t * ) 0x2000000; *ulSoftInterrupt = 1UL; } #define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired ) vPortYield() #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) /*-----------------------------------------------------------*/