]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/portable/GCC/RISC-V/port.c
Remove driver files that generate compiler warnings from the RISC-V_Renode_Emulator_S...
[freertos] / FreeRTOS / Source / portable / GCC / RISC-V / port.c
index 10350a99368a09801bee94d10adfd73e0236756a..652a8071ec036fbe9d7f08fc4279cd8d4f06d55a 100644 (file)
@@ -34,6 +34,9 @@
 #include "task.h"\r
 #include "portmacro.h"\r
 \r
+/* Standard includes. */\r
+#include "string.h"\r
+\r
 #ifndef configCLINT_BASE_ADDRESS\r
        #warning configCLINT_BASE_ADDRESS must be defined in FreeRTOSConfig.h.  If the target chip includes a Core Local Interrupter (CLINT) then set configCLINT_BASE_ADDRESS to the CLINT base address.  Otherwise set configCLINT_BASE_ADDRESS to 0.\r
 #endif\r
@@ -56,7 +59,12 @@ stack that was used by main before the scheduler was started for use as the
 interrupt stack after the scheduler has started. */\r
 #ifdef configISR_STACK_SIZE_WORDS\r
        static __attribute__ ((aligned(16))) StackType_t xISRStack[ configISR_STACK_SIZE_WORDS ] = { 0 };\r
-       const StackType_t xISRStackTop = ( StackType_t ) &( xISRStack[ ( configISR_STACK_SIZE_WORDS & ~portBYTE_ALIGNMENT_MASK ) - 1 ] );\r
+       const StackType_t xISRStackTop = ( StackType_t ) &( xISRStack[ configISR_STACK_SIZE_WORDS & ~portBYTE_ALIGNMENT_MASK ] );\r
+\r
+       /* Don't use 0xa5 as the stack fill bytes as that is used by the kernerl for\r
+       the task stacks, and so will legitimately appear in many positions within\r
+       the ISR stack. */\r
+       #define portISR_STACK_FILL_BYTE 0xee    \r
 #else\r
        extern const uint32_t __freertos_irq_stack_top[];\r
        const StackType_t xISRStackTop = ( StackType_t ) __freertos_irq_stack_top;\r
@@ -75,18 +83,15 @@ void vPortSetupTimerInterrupt( void ) __attribute__(( weak ));
 uint64_t ullNextTime = 0ULL;\r
 const uint64_t *pullNextTime = &ullNextTime;\r
 const size_t uxTimerIncrementsForOneTick = ( size_t ) ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ); /* Assumes increment won't go over 32-bits. */\r
-volatile uint64_t * const pullMachineTimerCompareRegister = ( volatile uint64_t * const ) ( configCLINT_BASE_ADDRESS + 0x4000 );\r
+volatile uint64_t * const pullMachineTimerCompareRegisterBase = ( volatile uint64_t * const ) ( configCLINT_BASE_ADDRESS + 0x4000 );\r
+volatile uint64_t * pullMachineTimerCompareRegister = 0;\r
 \r
 /* Set configCHECK_FOR_STACK_OVERFLOW to 3 to add ISR stack checking to task\r
 stack checking.  A problem in the ISR stack will trigger an assert, not call the\r
 stack overflow hook function (because the stack overflow hook is specific to a\r
 task stack, not the ISR stack). */\r
-#if( configCHECK_FOR_STACK_OVERFLOW > 2 )\r
+#if defined( configISR_STACK_SIZE_WORDS ) && ( configCHECK_FOR_STACK_OVERFLOW > 2 )\r
        #warning This path not tested, or even compiled yet.\r
-       /* Don't use 0xa5 as the stack fill bytes as that is used by the kernerl for\r
-       the task stacks, and so will legitimately appear in many positions within\r
-       the ISR stack. */\r
-       #define portISR_STACK_FILL_BYTE 0xee\r
 \r
        static const uint8_t ucExpectedStackBytes[] = {\r
                                                                        portISR_STACK_FILL_BYTE, portISR_STACK_FILL_BYTE, portISR_STACK_FILL_BYTE, portISR_STACK_FILL_BYTE,             \\r
@@ -110,6 +115,10 @@ task stack, not the ISR stack). */
        uint32_t ulCurrentTimeHigh, ulCurrentTimeLow;\r
        volatile uint32_t * const pulTimeHigh = ( volatile uint32_t * const ) ( configCLINT_BASE_ADDRESS + 0xBFFC );\r
        volatile uint32_t * const pulTimeLow = ( volatile uint32_t * const ) ( configCLINT_BASE_ADDRESS + 0xBFF8 );\r
+       volatile uint32_t ulHartId = 0;\r
+\r
+               __asm volatile( "csrr %0, mhartid" : "=r"( ulHartId ) );\r
+               pullMachineTimerCompareRegister  = &( pullMachineTimerCompareRegisterBase[ ulHartId ] );\r
 \r
                do\r
                {\r
@@ -147,6 +156,12 @@ extern void xPortStartFirstTask( void );
                stack that was being used by main() prior to the scheduler being\r
                started. */\r
                configASSERT( ( xISRStackTop & portBYTE_ALIGNMENT_MASK ) == 0 );\r
+\r
+               #ifdef configISR_STACK_SIZE_WORDS\r
+               {\r
+                       memset( ( void * ) xISRStack, portISR_STACK_FILL_BYTE, sizeof( xISRStack ) );\r
+               }\r
+               #endif   /* configISR_STACK_SIZE_WORDS */\r
        }\r
        #endif /* configASSERT_DEFINED */\r
 \r