From 73ad4387e252a663f0f12900fc5a15906903ef02 Mon Sep 17 00:00:00 2001
From: Richard Barry <ribarry@amazon.com>
Date: Sun, 12 Aug 2012 17:05:23 +0000
Subject: [PATCH] Remove the remnants of the legacy trace functionality (since
 replaced with FreeRTOS+Trace). Replaced the #error that traps
 configMAX_SYSCALL_INTERRUPT_PRIORITY being set to 0 with a configASSERT() for
 GCC Cortex-M3/4 ports as the #error does not work if
 configMAX_SYSCALL_INTERRUPT_PRIORITY includes any casting.  Not a problem for
 other compilers as they cannot have casting anyway as that would break the
 assembly code.

---
 FreeRTOS/Source/include/mpu_wrappers.h        |  2 -
 FreeRTOS/Source/include/task.h                | 34 -----------
 FreeRTOS/Source/portable/GCC/ARM_CM3/port.c   |  8 +--
 .../Source/portable/GCC/ARM_CM3_MPU/port.c    | 60 +++++--------------
 FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c  |  8 +--
 FreeRTOS/Source/portable/GCC/NiosII/port.c    |  8 +--
 FreeRTOS/Source/portable/IAR/ATMega323/port.c |  1 -
 FreeRTOS/Source/portable/MemMang/heap_1.c     |  3 +
 .../Source/portable/Tasking/ARM_CM4F/port.c   |  8 +--
 FreeRTOS/Source/tasks.c                       |  2 +-
 10 files changed, 35 insertions(+), 99 deletions(-)

diff --git a/FreeRTOS/Source/include/mpu_wrappers.h b/FreeRTOS/Source/include/mpu_wrappers.h
index 12246b8d9..6538c91a5 100644
--- a/FreeRTOS/Source/include/mpu_wrappers.h
+++ b/FreeRTOS/Source/include/mpu_wrappers.h
@@ -92,8 +92,6 @@ only for ports that are using the MPU. */
 		#define uxTaskGetNumberOfTasks			MPU_uxTaskGetNumberOfTasks
 		#define vTaskList						MPU_vTaskList
 		#define vTaskGetRunTimeStats			MPU_vTaskGetRunTimeStats
-		#define vTaskStartTrace					MPU_vTaskStartTrace
-		#define ulTaskEndTrace					MPU_ulTaskEndTrace
 		#define vTaskSetApplicationTaskTag		MPU_vTaskSetApplicationTaskTag
 		#define xTaskGetApplicationTaskTag		MPU_xTaskGetApplicationTaskTag
 		#define xTaskCallApplicationTaskHook	MPU_xTaskCallApplicationTaskHook
diff --git a/FreeRTOS/Source/include/task.h b/FreeRTOS/Source/include/task.h
index 3f462ff3e..9f27bd13f 100644
--- a/FreeRTOS/Source/include/task.h
+++ b/FreeRTOS/Source/include/task.h
@@ -1085,40 +1085,6 @@ void vTaskList( signed char *pcWriteBuffer ) PRIVILEGED_FUNCTION;
  */
 void vTaskGetRunTimeStats( signed char *pcWriteBuffer ) PRIVILEGED_FUNCTION;
 
-/**
- * task. h
- * <PRE>void vTaskStartTrace( char * pcBuffer, unsigned portBASE_TYPE uxBufferSize );</PRE>
- *
- * Starts a real time kernel activity trace.  The trace logs the identity of
- * which task is running when.
- *
- * The trace file is stored in binary format.  A separate DOS utility called
- * convtrce.exe is used to convert this into a tab delimited text file which
- * can be viewed and plotted in a spread sheet.
- *
- * @param pcBuffer The buffer into which the trace will be written.
- *
- * @param ulBufferSize The size of pcBuffer in bytes.  The trace will continue
- * until either the buffer in full, or ulTaskEndTrace () is called.
- *
- * \page vTaskStartTrace vTaskStartTrace
- * \ingroup TaskUtils
- */
-void vTaskStartTrace( signed char * pcBuffer, unsigned long ulBufferSize ) PRIVILEGED_FUNCTION;
-
-/**
- * task. h
- * <PRE>unsigned long ulTaskEndTrace( void );</PRE>
- *
- * Stops a kernel activity trace.  See vTaskStartTrace ().
- *
- * @return The number of bytes that have been written into the trace buffer.
- *
- * \page usTaskEndTrace usTaskEndTrace
- * \ingroup TaskUtils
- */
-unsigned long ulTaskEndTrace( void ) PRIVILEGED_FUNCTION;
-
 /**
  * task.h
  * <PRE>unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask );</PRE>
diff --git a/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c b/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c
index 344b381eb..0b0fc86da 100644
--- a/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c
+++ b/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c
@@ -79,10 +79,6 @@ FreeRTOS.org versions prior to V4.4.0 did not include this definition. */
 	#define configKERNEL_INTERRUPT_PRIORITY 255
 #endif
 
-#if configMAX_SYSCALL_INTERRUPT_PRIORITY == 0
-	#error configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to 0.  See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html
-#endif
-
 /* Constants required to manipulate the NVIC. */
 #define portNVIC_SYSTICK_CTRL		( ( volatile unsigned long *) 0xe000e010 )
 #define portNVIC_SYSTICK_LOAD		( ( volatile unsigned long *) 0xe000e014 )
@@ -184,6 +180,10 @@ static void prvPortStartFirstTask( void )
  */
 portBASE_TYPE xPortStartScheduler( void )
 {
+	/* configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to 0.  
+	See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
+	configASSERT( configMAX_SYSCALL_INTERRUPT_PRIORITY );
+
 	/* Make PendSV, CallSV and SysTick the same priroity as the kernel. */
 	*(portNVIC_SYSPRI2) |= portNVIC_PENDSV_PRI;
 	*(portNVIC_SYSPRI2) |= portNVIC_SYSTICK_PRI;
diff --git a/FreeRTOS/Source/portable/GCC/ARM_CM3_MPU/port.c b/FreeRTOS/Source/portable/GCC/ARM_CM3_MPU/port.c
index 9c424bcc6..f1cd17caf 100644
--- a/FreeRTOS/Source/portable/GCC/ARM_CM3_MPU/port.c
+++ b/FreeRTOS/Source/portable/GCC/ARM_CM3_MPU/port.c
@@ -40,7 +40,7 @@
     FreeRTOS WEB site.
 
     1 tab == 4 spaces!
-    
+
     ***************************************************************************
      *                                                                       *
      *    Having a problem?  Start by reading the FAQ "My application does   *
@@ -50,17 +50,17 @@
      *                                                                       *
     ***************************************************************************
 
-    
-    http://www.FreeRTOS.org - Documentation, training, latest information, 
+
+    http://www.FreeRTOS.org - Documentation, training, latest information,
     license and contact details.
-    
+
     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
     including FreeRTOS+Trace - an indispensable productivity tool.
 
-    Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell 
-    the code with commercial support, indemnification, and middleware, under 
+    Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
+    the code with commercial support, indemnification, and middleware, under
     the OpenRTOS brand: http://www.OpenRTOS.com.  High Integrity Systems also
-    provide a safety engineered and independently SIL3 certified version under 
+    provide a safety engineered and independently SIL3 certified version under
     the SafeRTOS brand: http://www.SafeRTOS.com.
 */
 
@@ -78,10 +78,6 @@ task.h is included from an application file. */
 #include "task.h"
 #include "queue.h"
 
-#if configMAX_SYSCALL_INTERRUPT_PRIORITY == 0
-	#error configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to 0.  See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html
-#endif
-
 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
 
 /* Constants required to access and manipulate the NVIC. */
@@ -191,8 +187,6 @@ portTickType MPU_xTaskGetTickCount( void );
 unsigned portBASE_TYPE MPU_uxTaskGetNumberOfTasks( void );
 void MPU_vTaskList( signed char *pcWriteBuffer );
 void MPU_vTaskGetRunTimeStats( signed char *pcWriteBuffer );
-void MPU_vTaskStartTrace( signed char * pcBuffer, unsigned long ulBufferSize );
-unsigned long MPU_ulTaskEndTrace( void );
 void MPU_vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxTagValue );
 pdTASK_HOOK_CODE MPU_xTaskGetApplicationTaskTag( xTaskHandle xTask );
 portBASE_TYPE MPU_xTaskCallApplicationTaskHook( xTaskHandle xTask, void *pvParameter );
@@ -261,13 +255,9 @@ void vPortSVCHandler( void )
 		#else
 			"	mrs r0, psp						\n"
 		#endif
-			"	b prvSVCHandler					\n"
-			:::"r0"
+			"	b %0							\n"
+			::"i"(prvSVCHandler):"r0"
 	);
-
-	/* This will never get executed, but is required to prevent prvSVCHandler
-	being removed by the optimiser. */
-	prvSVCHandler( NULL );
 }
 /*-----------------------------------------------------------*/
 
@@ -336,7 +326,11 @@ static void prvRestoreContextOfFirstTask( void )
  */
 portBASE_TYPE xPortStartScheduler( void )
 {
-	/* Make PendSV and SysTick the same priroity as the kernel. */
+	/* configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to 0.  See
+	http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
+	configASSERT( ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) );
+
+	/* Make PendSV and SysTick the same priority as the kernel. */
 	*(portNVIC_SYSPRI2) |= portNVIC_PENDSV_PRI;
 	*(portNVIC_SYSPRI2) |= portNVIC_SYSTICK_PRI;
 
@@ -838,30 +832,6 @@ portBASE_TYPE xRunningPrivileged = prvRaisePrivilege();
 #endif
 /*-----------------------------------------------------------*/
 
-#if ( configUSE_TRACE_FACILITY == 1 )
-	void MPU_vTaskStartTrace( signed char * pcBuffer, unsigned long ulBufferSize )
-	{
-    portBASE_TYPE xRunningPrivileged = prvRaisePrivilege();
-
-		vTaskStartTrace( pcBuffer, ulBufferSize );
-        portRESET_PRIVILEGE( xRunningPrivileged );
-	}
-#endif
-/*-----------------------------------------------------------*/
-
-#if ( configUSE_TRACE_FACILITY == 1 )
-	unsigned long MPU_ulTaskEndTrace( void )
-	{
-	unsigned long ulReturn;
-    portBASE_TYPE xRunningPrivileged = prvRaisePrivilege();
-
-		ulReturn = ulTaskEndTrace();
-        portRESET_PRIVILEGE( xRunningPrivileged );
-		return ulReturn;
-	}
-#endif
-/*-----------------------------------------------------------*/
-
 #if ( configUSE_APPLICATION_TASK_TAG == 1 )
 	void MPU_vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxTagValue )
 	{
@@ -1077,7 +1047,7 @@ void MPU_vQueueDelete( xQueueHandle xQueue )
 portBASE_TYPE xRunningPrivileged = prvRaisePrivilege();
 
 	vQueueDelete( xQueue );
-	
+
 	portRESET_PRIVILEGE( xRunningPrivileged );
 }
 /*-----------------------------------------------------------*/
diff --git a/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c b/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c
index b9fd31c30..2b44ce012 100644
--- a/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c
+++ b/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c
@@ -76,10 +76,6 @@
 	#error This port can only be used when the project options are configured to enable hardware floating point support.
 #endif
 
-#if configMAX_SYSCALL_INTERRUPT_PRIORITY == 0
-	#error configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to 0.  See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html
-#endif
-
 /* Constants required to manipulate the NVIC. */
 #define portNVIC_SYSTICK_CTRL		( ( volatile unsigned long * ) 0xe000e010 )
 #define portNVIC_SYSTICK_LOAD		( ( volatile unsigned long * ) 0xe000e014 )
@@ -203,6 +199,10 @@ static void vPortStartFirstTask( void )
  */
 portBASE_TYPE xPortStartScheduler( void )
 {
+	/* configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to 0.  
+	See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
+	configASSERT( configMAX_SYSCALL_INTERRUPT_PRIORITY );
+
 	/* Make PendSV and SysTick the lowest priority interrupts. */
 	*(portNVIC_SYSPRI2) |= portNVIC_PENDSV_PRI;
 	*(portNVIC_SYSPRI2) |= portNVIC_SYSTICK_PRI;
diff --git a/FreeRTOS/Source/portable/GCC/NiosII/port.c b/FreeRTOS/Source/portable/GCC/NiosII/port.c
index 84adb7852..41ab224da 100644
--- a/FreeRTOS/Source/portable/GCC/NiosII/port.c
+++ b/FreeRTOS/Source/portable/GCC/NiosII/port.c
@@ -98,10 +98,10 @@ void vPortSysTickHandler( void * context, alt_u32 id );
 
 /*-----------------------------------------------------------*/
 
-void prvReadGp( unsigned long *ulValue )
-{ 
-	asm( "stw gp, (r4) " );
-};
+static void prvReadGp( unsigned long *ulValue )
+{
+	asm( "stw gp, (%0)" :: "r"(ulValue) );
+}
 /*-----------------------------------------------------------*/
 
 /* 
diff --git a/FreeRTOS/Source/portable/IAR/ATMega323/port.c b/FreeRTOS/Source/portable/IAR/ATMega323/port.c
index e9c1d451e..8ecf29663 100644
--- a/FreeRTOS/Source/portable/IAR/ATMega323/port.c
+++ b/FreeRTOS/Source/portable/IAR/ATMega323/port.c
@@ -280,7 +280,6 @@ portBASE_TYPE xPortStartScheduler( void )
 	compiler does not fully support inline assembler we have to make a call.*/
 	vPortStart();
 
-
 	/* Should not get here! */
 	return pdTRUE;
 }
diff --git a/FreeRTOS/Source/portable/MemMang/heap_1.c b/FreeRTOS/Source/portable/MemMang/heap_1.c
index 6bb963439..60c989919 100644
--- a/FreeRTOS/Source/portable/MemMang/heap_1.c
+++ b/FreeRTOS/Source/portable/MemMang/heap_1.c
@@ -146,6 +146,9 @@ void vPortFree( void *pv )
 	heap_4.c for alternative implementations, and the memory management pages of 
 	http://www.FreeRTOS.org for more information. */
 	( void ) pv;
+	
+	/* Force an assert as it is invalid to call this function. */
+	configASSERT( pv == NULL );
 }
 /*-----------------------------------------------------------*/
 
diff --git a/FreeRTOS/Source/portable/Tasking/ARM_CM4F/port.c b/FreeRTOS/Source/portable/Tasking/ARM_CM4F/port.c
index aa3ed04f7..de09c2a68 100644
--- a/FreeRTOS/Source/portable/Tasking/ARM_CM4F/port.c
+++ b/FreeRTOS/Source/portable/Tasking/ARM_CM4F/port.c
@@ -72,10 +72,6 @@
 #include "FreeRTOS.h"
 #include "task.h"
 
-#if configMAX_SYSCALL_INTERRUPT_PRIORITY == 0
-	#error configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to 0.  See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html
-#endif
-
 /* Constants required to manipulate the NVIC. */
 #define portNVIC_SYSTICK_CTRL		( ( volatile unsigned long * ) 0xe000e010 )
 #define portNVIC_SYSTICK_LOAD		( ( volatile unsigned long * ) 0xe000e014 )
@@ -164,6 +160,10 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE
  */
 portBASE_TYPE xPortStartScheduler( void )
 {
+	/* configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to 0.
+	See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
+	configASSERT( ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) );
+
 	/* Make PendSV and SysTick the lowest priority interrupts. */
 	*(portNVIC_SYSPRI2) |= portNVIC_PENDSV_PRI;
 	*(portNVIC_SYSPRI2) |= portNVIC_SYSTICK_PRI;
diff --git a/FreeRTOS/Source/tasks.c b/FreeRTOS/Source/tasks.c
index 85e41a05f..f13c70e01 100644
--- a/FreeRTOS/Source/tasks.c
+++ b/FreeRTOS/Source/tasks.c
@@ -399,7 +399,7 @@ signed portBASE_TYPE xReturn;
 tskTCB * pxNewTCB;
 
 	configASSERT( pxTaskCode );
-	configASSERT( ( uxPriority < configMAX_PRIORITIES ) );
+	configASSERT( ( ( uxPriority & ( ~portPRIVILEGE_BIT ) ) < configMAX_PRIORITIES ) );
 
 	/* Allocate the memory required by the TCB and stack for the new task,
 	checking that the allocation was successful. */