]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/portable/RVDS/ARM_CM3/port.c
Update Cortex-M3 and Cortex-M4F ports to allow the SysTick to be clocked at a differe...
[freertos] / FreeRTOS / Source / portable / RVDS / ARM_CM3 / port.c
index 8e881953fbb44fdb502f6faf91aea4c321452e77..c3fe7088aa873f0845275f7634f46c6c543aecef 100644 (file)
@@ -243,6 +243,7 @@ __asm void vPortSVCHandler( void )
        ldr r0, [r1]                    /* The first item in pxCurrentTCB is the task top of stack. */\r
        ldmia r0!, {r4-r11}             /* Pop the registers that are not automatically saved on exception entry and the critical nesting count. */\r
        msr psp, r0                             /* Restore the task stack pointer. */\r
+       isb\r
        mov r0, #0\r
        msr     basepri, r0\r
        orr r14, #0xd\r
@@ -262,6 +263,8 @@ __asm void prvStartFirstTask( void )
        msr msp, r0\r
        /* Globally enable interrupts. */\r
        cpsie i\r
+       dsb\r
+       isb\r
        /* Call SVC to start the first task. */\r
        svc 0\r
        nop\r
@@ -385,6 +388,7 @@ __asm void xPortPendSVHandler( void )
        PRESERVE8\r
 \r
        mrs r0, psp\r
+       isb\r
 \r
        ldr     r3, =pxCurrentTCB               /* Get the location of the current TCB. */\r
        ldr     r2, [r3]\r
@@ -404,6 +408,7 @@ __asm void xPortPendSVHandler( void )
        ldr r0, [r1]                            /* The first item in pxCurrentTCB is the task top of stack. */\r
        ldmia r0!, {r4-r11}                     /* Pop the registers and the critical nesting count. */\r
        msr psp, r0\r
+       isb\r
        bx r14\r
        nop\r
 }\r
@@ -433,7 +438,7 @@ void xPortSysTickHandler( void )
 \r
        __weak void vPortSuppressTicksAndSleep( portTickType xExpectedIdleTime )\r
        {\r
-       unsigned long ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements;\r
+       unsigned long ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements, ulSysTickCTRL;\r
        portTickType xModifiableIdleTime;\r
 \r
                /* Make sure the SysTick reload value does not overflow the counter. */\r
@@ -446,7 +451,7 @@ void xPortSysTickHandler( void )
                is accounted for as best it can be, but using the tickless mode will\r
                inevitably result in some tiny drift of the time maintained by the\r
                kernel with respect to calendar time. */\r
-               portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT;\r
+               portNVIC_SYSTICK_CTRL_REG &= ~portNVIC_SYSTICK_ENABLE_BIT;\r
 \r
                /* Calculate the reload value required to wait xExpectedIdleTime\r
                tick periods.  -1 is used because this code will execute part way\r
@@ -470,7 +475,7 @@ void xPortSysTickHandler( void )
                        portNVIC_SYSTICK_LOAD_REG = portNVIC_SYSTICK_CURRENT_VALUE_REG;\r
 \r
                        /* Restart SysTick. */\r
-                       portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;\r
+                       portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;\r
 \r
                        /* Reset the reload register to the value required for normal tick\r
                        periods. */\r
@@ -490,7 +495,7 @@ void xPortSysTickHandler( void )
                        portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;\r
 \r
                        /* Restart SysTick. */\r
-                       portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;\r
+                       portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;\r
 \r
                        /* Sleep until something happens.  configPRE_SLEEP_PROCESSING() can\r
                        set its parameter to 0 to indicate that its implementation contains\r
@@ -511,13 +516,14 @@ void xPortSysTickHandler( void )
                        accounted for as best it can be, but using the tickless mode will\r
                        inevitably result in some tiny drift of the time maintained by the\r
                        kernel with respect to calendar time. */\r
-                       portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT;\r
+                       ulSysTickCTRL = portNVIC_SYSTICK_CTRL_REG;\r
+                       portNVIC_SYSTICK_CTRL_REG = ( ulSysTickCTRL & ~portNVIC_SYSTICK_ENABLE_BIT );\r
 \r
                        /* Re-enable interrupts - see comments above __disable_irq() call\r
                        above. */\r
                        __enable_irq();\r
 \r
-                       if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )\r
+                       if( ( ulSysTickCTRL & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )\r
                        {\r
                                unsigned long ulCalculatedLoadValue;\r
 \r
@@ -569,7 +575,7 @@ void xPortSysTickHandler( void )
                        portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;\r
                        portENTER_CRITICAL();\r
                        {\r
-                               portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;\r
+                               portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;\r
                                vTaskStepTick( ulCompleteTickPeriods );\r
                                portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;\r
                        }\r
@@ -600,7 +606,7 @@ void xPortSysTickHandler( void )
 \r
                /* Configure SysTick to interrupt at the requested rate. */\r
                portNVIC_SYSTICK_LOAD_REG = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL;;\r
-               portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;\r
+               portNVIC_SYSTICK_CTRL_REG |= ( portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT );\r
        }\r
 \r
 #endif /* configOVERRIDE_DEFAULT_TICK_CONFIGURATION */\r