From a03adc4e5a6bd0ece2b5e6d3796649b381a347e4 Mon Sep 17 00:00:00 2001 From: rtel Date: Sun, 9 Apr 2017 20:13:48 +0000 Subject: [PATCH] Ensure the PIC32 interrupt stack is 8 byte aligned for all values of configISR_STACK_SIZE. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2497 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- FreeRTOS/Source/portable/MPLAB/PIC32MX/port.c | 4 ++-- FreeRTOS/Source/portable/MPLAB/PIC32MX/portmacro.h | 2 +- FreeRTOS/Source/portable/MPLAB/PIC32MZ/port.c | 14 ++++++++++---- FreeRTOS/Source/portable/MPLAB/PIC32MZ/portmacro.h | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/FreeRTOS/Source/portable/MPLAB/PIC32MX/port.c b/FreeRTOS/Source/portable/MPLAB/PIC32MX/port.c index 8a3b4fceb..913df4048 100644 --- a/FreeRTOS/Source/portable/MPLAB/PIC32MX/port.c +++ b/FreeRTOS/Source/portable/MPLAB/PIC32MX/port.c @@ -188,11 +188,11 @@ volatile UBaseType_t uxInterruptNesting = 0x01; UBaseType_t uxSavedTaskStackPointer = 0; /* The stack used by interrupt service routines that cause a context switch. */ -StackType_t xISRStack[ configISR_STACK_SIZE ] = { 0 }; +__attribute__ ((aligned(8))) StackType_t xISRStack[ configISR_STACK_SIZE ] = { 0 }; /* The top of stack value ensures there is enough space to store 6 registers on the callers stack, as some functions seem to want to do this. */ -const StackType_t * const xISRStackTop = &( xISRStack[ configISR_STACK_SIZE - 7 ] ); +const StackType_t * const xISRStackTop = &( xISRStack[ ( configISR_STACK_SIZE & ~portBYTE_ALIGNMENT_MASK ) - 8 ] ); /*-----------------------------------------------------------*/ diff --git a/FreeRTOS/Source/portable/MPLAB/PIC32MX/portmacro.h b/FreeRTOS/Source/portable/MPLAB/PIC32MX/portmacro.h index 994601b4c..801ed8731 100644 --- a/FreeRTOS/Source/portable/MPLAB/PIC32MX/portmacro.h +++ b/FreeRTOS/Source/portable/MPLAB/PIC32MX/portmacro.h @@ -198,7 +198,7 @@ extern void vPortClearInterruptMaskFromISR( UBaseType_t ); /*-----------------------------------------------------------*/ - #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31 - _clz( ( uxReadyPriorities ) ) ) + #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - _clz( ( uxReadyPriorities ) ) ) #endif /* taskRECORD_READY_PRIORITY */ diff --git a/FreeRTOS/Source/portable/MPLAB/PIC32MZ/port.c b/FreeRTOS/Source/portable/MPLAB/PIC32MZ/port.c index b573b16d3..69ab7bed6 100644 --- a/FreeRTOS/Source/portable/MPLAB/PIC32MZ/port.c +++ b/FreeRTOS/Source/portable/MPLAB/PIC32MZ/port.c @@ -1,5 +1,5 @@ /* - FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd. + FreeRTOS V9.0.1 - Copyright (C) 2017 Real Time Engineers Ltd. All rights reserved VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. @@ -71,8 +71,12 @@ * Implementation of functions defined in portable.h for the PIC32MZ port. *----------------------------------------------------------*/ +/* Microchip specific headers. */ #include +/* Standard headers. */ +#include + /* Scheduler include files. */ #include "FreeRTOS.h" #include "task.h" @@ -189,11 +193,13 @@ volatile UBaseType_t uxInterruptNesting = 0x01; UBaseType_t uxSavedTaskStackPointer = 0; /* The stack used by interrupt service routines that cause a context switch. */ -StackType_t xISRStack[ configISR_STACK_SIZE ] = { 0 }; +__attribute__ ((aligned(8))) StackType_t xISRStack[ configISR_STACK_SIZE ] = { 0 }; /* The top of stack value ensures there is enough space to store 6 registers on -the callers stack, as some functions seem to want to do this. */ -const StackType_t * const xISRStackTop = &( xISRStack[ configISR_STACK_SIZE - 7 ] ); +the callers stack, as some functions seem to want to do this. 8 byte alignment +is required to allow double word floating point stack pushes generated by the +compiler. */ +const StackType_t * const xISRStackTop = &( xISRStack[ ( configISR_STACK_SIZE & ~portBYTE_ALIGNMENT_MASK ) - 8 ] ); /* Saved as part of the task context. Set to pdFALSE if the task does not require an FPU context. */ diff --git a/FreeRTOS/Source/portable/MPLAB/PIC32MZ/portmacro.h b/FreeRTOS/Source/portable/MPLAB/PIC32MZ/portmacro.h index bb317f886..26e79b196 100644 --- a/FreeRTOS/Source/portable/MPLAB/PIC32MZ/portmacro.h +++ b/FreeRTOS/Source/portable/MPLAB/PIC32MZ/portmacro.h @@ -209,7 +209,7 @@ extern void vPortClearInterruptMaskFromISR( UBaseType_t ); /*-----------------------------------------------------------*/ - #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31 - _clz( ( uxReadyPriorities ) ) ) + #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - _clz( ( uxReadyPriorities ) ) ) #endif /* taskRECORD_READY_PRIORITY */ -- 2.39.2