***************************************************************************\r
\r
\r
- http://www.FreeRTOS.org - Documentation, books, training, latest versions, \r
+ http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
license and Real Time Engineers Ltd. contact details.\r
\r
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
including FreeRTOS+Trace - an indispensable productivity tool, and our new\r
fully thread aware and reentrant UDP/IP stack.\r
\r
- http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High \r
- Integrity Systems, who sell the code with commercial support, \r
+ http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
+ Integrity Systems, who sell the code with commercial support,\r
indemnification and middleware, under the OpenRTOS brand.\r
- \r
- http://www.SafeRTOS.com - High Integrity Systems also provide a safety \r
- engineered and independently SIL3 certified version for use in safety and \r
+\r
+ http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
+ engineered and independently SIL3 certified version for use in safety and\r
mission critical applications that require provable dependability.\r
*/\r
\r
\r
/*\r
Changes from V2.5.2\r
- \r
+\r
+ The critical section management functions have been changed. These no\r
longer modify the stack and are safe to use at all optimisation levels.\r
The functions are now also the same for both ARM and THUMB modes.\r
\r
Changes from V2.6.0\r
\r
- + Removed the 'static' from the definition of vNonPreemptiveTick() to \r
+ + Removed the 'static' from the definition of vNonPreemptiveTick() to\r
allow the demo to link when using the cooperative scheduler.\r
\r
Changes from V3.2.4\r
/* ISR to handle manual context switches (from a call to taskYIELD()). */\r
void vPortYieldProcessor( void ) __attribute__((interrupt("SWI"), naked));\r
\r
-/* \r
+/*\r
* The scheduler can only be started from ARM mode, hence the inclusion of this\r
* function here.\r
*/\r
/*\r
* Called by portYIELD() or taskYIELD() to manually force a context switch.\r
*\r
- * When a context switch is performed from the task level the saved task \r
+ * When a context switch is performed from the task level the saved task\r
* context is made to look as if it occurred from within the tick ISR. This\r
* way the same restore context function can be used when restoring the context\r
* saved from the ISR or that saved from a call to vPortYieldProcessor.\r
*/\r
void vPortYieldProcessor( void )\r
{\r
- /* Within an IRQ ISR the link register has an offset from the true return \r
- address, but an SWI ISR does not. Add the offset manually so the same \r
+ /* Within an IRQ ISR the link register has an offset from the true return\r
+ address, but an SWI ISR does not. Add the offset manually so the same\r
ISR return code can be used in both cases. */\r
__asm volatile ( "ADD LR, LR, #4" );\r
\r
__asm volatile ( "bl vTaskSwitchContext" );\r
\r
/* Restore the context of the new task. */\r
- portRESTORE_CONTEXT(); \r
+ portRESTORE_CONTEXT();\r
}\r
/*-----------------------------------------------------------*/\r
\r
-/* \r
+/*\r
* The ISR used for the scheduler tick.\r
*/\r
void vTickISR( void ) __attribute__((naked));\r
void vTickISR( void )\r
{\r
/* Save the context of the interrupted task. */\r
- portSAVE_CONTEXT(); \r
+ portSAVE_CONTEXT();\r
\r
- /* Increment the RTOS tick count, then look for the highest priority \r
+ /* Increment the RTOS tick count, then look for the highest priority\r
task that is ready to run. */\r
- __asm volatile( "bl xTaskIncrementTick" );\r
-\r
- #if configUSE_PREEMPTION == 1\r
- __asm volatile( "bl vTaskSwitchContext" );\r
- #endif\r
+ __asm volatile\r
+ (\r
+ " bl xTaskIncrementTick \t\n" \\r
+ " cmp r0, #0 \t\n" \\r
+ " beq SkipContextSwitch \t\n" \\r
+ " bl vTaskSwitchContext \t\n" \\r
+ "SkipContextSwitch: \t\n"\r
+ );\r
\r
/* Ready for the next interrupt. */\r
T0_IR = portTIMER_MATCH_ISR_BIT;\r
VICVectAddr = portCLEAR_VIC_INTERRUPT;\r
- \r
+\r
/* Restore the context of the new task. */\r
portRESTORE_CONTEXT();\r
}\r
\r
void vPortDisableInterruptsFromThumb( void )\r
{\r
- __asm volatile ( \r
+ __asm volatile (\r
"STMDB SP!, {R0} \n\t" /* Push R0. */\r
"MRS R0, CPSR \n\t" /* Get CPSR. */\r
"ORR R0, R0, #0xC0 \n\t" /* Disable IRQ, FIQ. */\r
"LDMIA SP!, {R0} \n\t" /* Pop R0. */\r
"BX R14" ); /* Return back to thumb. */\r
}\r
- \r
+\r
void vPortEnableInterruptsFromThumb( void )\r
{\r
- __asm volatile ( \r
- "STMDB SP!, {R0} \n\t" /* Push R0. */ \r
- "MRS R0, CPSR \n\t" /* Get CPSR. */ \r
- "BIC R0, R0, #0xC0 \n\t" /* Enable IRQ, FIQ. */ \r
- "MSR CPSR, R0 \n\t" /* Write back modified value. */ \r
+ __asm volatile (\r
+ "STMDB SP!, {R0} \n\t" /* Push R0. */\r
+ "MRS R0, CPSR \n\t" /* Get CPSR. */\r
+ "BIC R0, R0, #0xC0 \n\t" /* Enable IRQ, FIQ. */\r
+ "MSR CPSR, R0 \n\t" /* Write back modified value. */\r
"LDMIA SP!, {R0} \n\t" /* Pop R0. */\r
"BX R14" ); /* Return back to thumb. */\r
}\r
void vPortEnterCritical( void )\r
{\r
/* Disable interrupts as per portDISABLE_INTERRUPTS(); */\r
- __asm volatile ( \r
+ __asm volatile (\r
"STMDB SP!, {R0} \n\t" /* Push R0. */\r
"MRS R0, CPSR \n\t" /* Get CPSR. */\r
"ORR R0, R0, #0xC0 \n\t" /* Disable IRQ, FIQ. */\r
"MSR CPSR, R0 \n\t" /* Write back modified value. */\r
"LDMIA SP!, {R0}" ); /* Pop R0. */\r
\r
- /* Now interrupts are disabled ulCriticalNesting can be accessed \r
+ /* Now interrupts are disabled ulCriticalNesting can be accessed\r
directly. Increment ulCriticalNesting to keep a count of how many times\r
portENTER_CRITICAL() has been called. */\r
ulCriticalNesting++;\r
if( ulCriticalNesting == portNO_CRITICAL_NESTING )\r
{\r
/* Enable interrupts as per portEXIT_CRITICAL(). */\r
- __asm volatile ( \r
- "STMDB SP!, {R0} \n\t" /* Push R0. */ \r
- "MRS R0, CPSR \n\t" /* Get CPSR. */ \r
- "BIC R0, R0, #0xC0 \n\t" /* Enable IRQ, FIQ. */ \r
- "MSR CPSR, R0 \n\t" /* Write back modified value. */ \r
+ __asm volatile (\r
+ "STMDB SP!, {R0} \n\t" /* Push R0. */\r
+ "MRS R0, CPSR \n\t" /* Get CPSR. */\r
+ "BIC R0, R0, #0xC0 \n\t" /* Enable IRQ, FIQ. */\r
+ "MSR CPSR, R0 \n\t" /* Write back modified value. */\r
"LDMIA SP!, {R0}" ); /* Pop R0. */\r
}\r
}\r
\r
/* Increment the RTOS tick count, then look for the highest priority \r
task that is ready to run. */\r
- __asm volatile( "bl xTaskIncrementTick" );\r
- __asm volatile( "bl vTaskSwitchContext" );\r
+ __asm volatile\r
+ (\r
+ " bl xTaskIncrementTick \t\n" \\r
+ " cmp r0, #0 \t\n" \\r
+ " beq SkipContextSwitch \t\n" \\r
+ " bl vTaskSwitchContext \t\n" \\r
+ "SkipContextSwitch: \t\n"\r
+ );\r
\r
/* Ready for the next interrupt. */\r
T0IR = 2;\r
; Manual context switch function. This is the SWI hander.\r
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
vPortYieldProcessor:\r
- ADD LR, LR, #4 ; Add 4 to the LR to make the LR appear exactly \r
- ; as if the context was saved during and IRQ \r
+ ADD LR, LR, #4 ; Add 4 to the LR to make the LR appear exactly\r
+ ; as if the context was saved during and IRQ\r
; handler.\r
- \r
+\r
portSAVE_CONTEXT ; Save the context of the current task...\r
LDR R0, =vTaskSwitchContext ; before selecting the next task to execute.\r
mov lr, pc\r
LDR R0, =xTaskIncrementTick ; Increment the tick count - this may wake a task.\r
mov lr, pc\r
BX R0\r
+\r
+ CMP R0, #0\r
+ BEQ SkipContextSwitch\r
LDR R0, =vTaskSwitchContext ; Select the next task to execute.\r
mov lr, pc\r
BX R0\r
-\r
+SkipContextSwitch\r
LDR R14, =AT91C_BASE_PITC ; Clear the PIT interrupt\r
LDR R0, [R14, #PITC_PIVR ]\r
\r
***************************************************************************\r
\r
\r
- http://www.FreeRTOS.org - Documentation, books, training, latest versions, \r
+ http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
license and Real Time Engineers Ltd. contact details.\r
\r
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
including FreeRTOS+Trace - an indispensable productivity tool, and our new\r
fully thread aware and reentrant UDP/IP stack.\r
\r
- http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High \r
- Integrity Systems, who sell the code with commercial support, \r
+ http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
+ Integrity Systems, who sell the code with commercial support,\r
indemnification and middleware, under the OpenRTOS brand.\r
- \r
- http://www.SafeRTOS.com - High Integrity Systems also provide a safety \r
- engineered and independently SIL3 certified version for use in safety and \r
+\r
+ http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
+ engineered and independently SIL3 certified version for use in safety and\r
mission critical applications that require provable dependability.\r
*/\r
#include "FreeRTOSConfig.h"\r
EXPORT vTickISR\r
EXPORT vPortYield\r
EXPORT xPortStartScheduler\r
- \r
+\r
RSEG CODE\r
\r
/*\r
*/\r
vTickISR:\r
portSAVE_CONTEXT\r
- \r
+\r
call #xTaskIncrementTick\r
+ cmp.w #0x0, R12\r
+ jeq SkipContextSwitch\r
+ call #vTaskSwitchContext\r
+SkipContextSwitch:\r
\r
- #if configUSE_PREEMPTION == 1\r
- call #vTaskSwitchContext\r
- #endif\r
- \r
portRESTORE_CONTEXT\r
/*-----------------------------------------------------------*/\r
\r
vPortYield:\r
\r
/* Mimic an interrupt by pushing the SR. */\r
- push SR \r
+ push SR\r
\r
/* Now the SR is stacked we can disable interrupts. */\r
- dint \r
- \r
+ dint\r
+\r
/* Save the context of the current task. */\r
- portSAVE_CONTEXT \r
+ portSAVE_CONTEXT\r
\r
/* Switch to the highest priority task that is ready to run. */\r
- call #vTaskSwitchContext \r
+ call #vTaskSwitchContext\r
\r
/* Restore the context of the new task. */\r
portRESTORE_CONTEXT\r
/* Restore the context of the first task that is going to run. */\r
portRESTORE_CONTEXT\r
/*-----------------------------------------------------------*/\r
- \r
+\r
\r
/* Install vTickISR as the timer A0 interrupt. */\r
ASEG\r
ORG 0xFFE0 + TIMERA0_VECTOR\r
- \r
+\r
_vTickISR_: DC16 vTickISR\r
- \r
+\r
\r
END\r
- \r
+\r
***************************************************************************\r
\r
\r
- http://www.FreeRTOS.org - Documentation, books, training, latest versions, \r
+ http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
license and Real Time Engineers Ltd. contact details.\r
\r
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
including FreeRTOS+Trace - an indispensable productivity tool, and our new\r
fully thread aware and reentrant UDP/IP stack.\r
\r
- http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High \r
- Integrity Systems, who sell the code with commercial support, \r
+ http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
+ Integrity Systems, who sell the code with commercial support,\r
indemnification and middleware, under the OpenRTOS brand.\r
- \r
- http://www.SafeRTOS.com - High Integrity Systems also provide a safety \r
- engineered and independently SIL3 certified version for use in safety and \r
+\r
+ http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
+ engineered and independently SIL3 certified version for use in safety and\r
mission critical applications that require provable dependability.\r
*/\r
#include "msp430.h"\r
mov_x sp, 0( r12 )\r
endm\r
/*-----------------------------------------------------------*/\r
- \r
+\r
portRESTORE_CONTEXT macro\r
\r
mov_x &pxCurrentTCB, r12\r
portSAVE_CONTEXT\r
\r
calla #xTaskIncrementTick\r
-\r
- #if configUSE_PREEMPTION == 1\r
- calla #vTaskSwitchContext\r
- #endif\r
-\r
+ cmp.w #0x0, R12\r
+ jeq SkipContextSwitch\r
+ calla #vTaskSwitchContext\r
+SkipContextSwitch:\r
portRESTORE_CONTEXT\r
/*-----------------------------------------------------------*/\r
\r
RSEG CODE:CODE\r
vPortTickISR:\r
\r
- portSAVE_CONTEXT ; Save the context of the current task.\r
- call xTaskIncrementTick ; Call the timer tick function.\r
-#if configUSE_PREEMPTION == 1\r
- call vTaskSwitchContext ; Call the scheduler to select the next task.\r
-#endif\r
- portRESTORE_CONTEXT ; Restore the context of the next task to run.\r
+ portSAVE_CONTEXT ; Save the context of the current task.\r
+ call xTaskIncrementTick ; Call the timer tick function.\r
+ cmpw ax, #0x00\r
+ skz\r
+ call vTaskSwitchContext ; Call the scheduler to select the next task.\r
+ portRESTORE_CONTEXT ; Restore the context of the next task to run.\r
reti\r
\r
\r
***************************************************************************\r
\r
\r
- http://www.FreeRTOS.org - Documentation, books, training, latest versions, \r
+ http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
license and Real Time Engineers Ltd. contact details.\r
\r
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
including FreeRTOS+Trace - an indispensable productivity tool, and our new\r
fully thread aware and reentrant UDP/IP stack.\r
\r
- http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High \r
- Integrity Systems, who sell the code with commercial support, \r
+ http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
+ Integrity Systems, who sell the code with commercial support,\r
indemnification and middleware, under the OpenRTOS brand.\r
- \r
- http://www.SafeRTOS.com - High Integrity Systems also provide a safety \r
- engineered and independently SIL3 certified version for use in safety and \r
+\r
+ http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
+ engineered and independently SIL3 certified version for use in safety and\r
mission critical applications that require provable dependability.\r
*/\r
\r
#define configKERNEL_INTERRUPT_PRIORITY 1\r
#endif\r
\r
+/* Use _T1Interrupt as the interrupt handler name if the application writer has\r
+not provided their own. */\r
+#ifndef configTICK_INTERRUPT_HANDLER\r
+ #define configTICK_INTERRUPT_HANDLER _T1Interrupt\r
+#endif /* configTICK_INTERRUPT_HANDLER */\r
+\r
/* The program counter is only 23 bits. */\r
#define portUNUSED_PR_BITS 0x7f\r
\r
#error If configKERNEL_INTERRUPT_PRIORITY is not 1 then the #32 in the following macros needs changing to equal the portINTERRUPT_BITS value, which is ( configKERNEL_INTERRUPT_PRIORITY << 5 )\r
#endif\r
\r
-#ifdef MPLAB_PIC24_PORT\r
+#if defined( __PIC24E__ ) || defined ( __PIC24F__ ) || defined( __PIC24FK__ ) || defined( __PIC24H__ )\r
\r
#ifdef __HAS_EDS__\r
#define portRESTORE_CONTEXT() \\r
#endif /* __HAS_EDS__ */\r
#endif /* MPLAB_PIC24_PORT */\r
\r
-#ifdef MPLAB_DSPIC_PORT\r
+#if defined( __dsPIC30F__ ) || defined ( __dsPIC33E__ ) || defined( __dsPIC33F__ )\r
\r
#define portRESTORE_CONTEXT() \\r
asm volatile( "MOV _pxCurrentTCB, W0 \n" /* Restore the stack pointer for the task. */ \\r
\r
#endif /* MPLAB_DSPIC_PORT */\r
\r
+#ifndef portRESTORE_CONTEXT\r
+ #error Unrecognised device selected\r
+#endif\r
+\r
/*\r
* Setup the timer used to generate the tick interrupt.\r
*/\r
-static void prvSetupTimerInterrupt( void );\r
+void vApplicationSetupTickTimerInterrupt( void );\r
\r
/*\r
* See header file for description.\r
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )\r
{\r
unsigned short usCode;\r
-portBASE_TYPE i;\r
+unsigned portBASE_TYPE i;\r
\r
const portSTACK_TYPE xInitialStack[] =\r
{\r
portBASE_TYPE xPortStartScheduler( void )\r
{\r
/* Setup a timer for the tick ISR. */\r
- prvSetupTimerInterrupt();\r
+ vApplicationSetupTickTimerInterrupt();\r
\r
/* Restore the context of the first task to run. */\r
portRESTORE_CONTEXT();\r
/*\r
* Setup a timer for a regular tick.\r
*/\r
-static void prvSetupTimerInterrupt( void )\r
+__attribute__(( weak )) void vApplicationSetupTickTimerInterrupt( void )\r
{\r
const unsigned long ulCompareMatch = ( ( configCPU_CLOCK_HZ / portTIMER_PRESCALE ) / configTICK_RATE_HZ ) - 1;\r
\r
}\r
/*-----------------------------------------------------------*/\r
\r
-void __attribute__((__interrupt__, auto_psv)) _T1Interrupt( void )\r
+void __attribute__((__interrupt__, auto_psv)) configTICK_INTERRUPT_HANDLER( void )\r
{\r
/* Clear the timer interrupt. */\r
IFS0bits.T1IF = 0;\r
LDR R0, =xTaskIncrementTick ; Increment the tick count. \r
MOV LR, PC ; This may make a delayed task ready\r
BX R0 ; to run.\r
- \r
+\r
+ CMP R0, #0\r
+ BEQ SkipContextSwitch\r
LDR R0, =vTaskSwitchContext ; Find the highest priority task that \r
MOV LR, PC ; is ready to run.\r
BX R0\r
- \r
+SkipContextSwitch\r
MOV R0, #T0MATCHBIT ; Clear the timer event\r
LDR R1, =T0IR\r
STR R0, [R1] \r
portSAVE_CONTEXT\r
\r
call #_xTaskIncrementTick\r
-\r
- #if configUSE_PREEMPTION == 1\r
- call #_vTaskSwitchContext\r
- #endif\r
- \r
+ cmp.w #0x00, r15\r
+ jeq _SkipContextSwitch\r
+ call #_vTaskSwitchContext\r
+_SkipContextSwitch: \r
portRESTORE_CONTEXT\r
/*-----------------------------------------------------------*/\r
\r