typedef void tskTCB;\r
extern volatile tskTCB * volatile pxCurrentTCB;\r
\r
+/* Constants required to handle critical sections. */\r
+#define portNO_CRITICAL_NESTING ( ( unsigned portBASE_TYPE ) 0 )\r
+volatile unsigned portLONG ulCriticalNesting = 9999UL;\r
+\r
/*-----------------------------------------------------------*/\r
\r
\r
STM1 (R14,R13,R12,R11,R10,R9,R8) ;Store R14-R8\r
ST MDH, @-R15 ;Store MDH\r
ST MDL, @-R15 ;Store MDL\r
+\r
+ LDI #_ulCriticalNesting, R0 ;Get the address of the critical nesting counter\r
+ LD @R0, R0 ;Get the value of the critical nesting counter\r
+ ST R0, @-R15 ;Store the critical nesting value to the user stack.\r
\r
ANDCCR #0xDF ;Switch back to system stack\r
LD @R15+,R0 ;Store PC to R0 \r
\r
ORCCR #0x20 ;Switch back to retreive the remaining context\r
\r
+ LDI #_ulCriticalNesting, R0 ;Get the address of the critical nesting counter\r
+ LD @R15+, R1 ;Get the saved critical nesting value\r
+ ST R1, @R0 ;Save the critical nesting value into the ulCriticalNesting variable\r
+\r
LD @R15+, MDL ;Restore MDL\r
LD @R15+, MDH ;Restore MDH\r
LDM1 (R14,R13,R12,R11,R10,R9,R8) ;Restore R14-R8\r
*/\r
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )\r
{\r
-unsigned portSHORT usAddress;\r
-\r
/* Place a few bytes of known values on the bottom of the stack. \r
This is just useful for debugging. */\r
\r
*pxTopOfStack = ( portSTACK_TYPE ) 0x22220000; /* MDL */\r
pxTopOfStack--;\r
\r
- usAddress = ( unsigned portSHORT ) pxCode;\r
- *pxTopOfStack = ( portSTACK_TYPE ) usAddress ; /* PC */\r
+ /* The task starts with its ulCriticalNesting variable set to 0, interrupts\r
+ being enabled. */\r
+ *pxTopOfStack = portNO_CRITICAL_NESTING;\r
+ pxTopOfStack--;\r
+\r
+ /* The start of the task code. */\r
+ *pxTopOfStack = ( portSTACK_TYPE ) pxCode; /* PC */\r
pxTopOfStack--;\r
\r
/* PS - User Mode, USP, ILM=31, Interrupts enabled */\r
RETI\r
\r
#pragma endasm\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+void vPortEnterCritical( void )\r
+{\r
+ /* Disable interrupts */\r
+ portDISABLE_INTERRUPTS();\r
+\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
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vPortExitCritical( void )\r
+{\r
+ if( ulCriticalNesting > portNO_CRITICAL_NESTING )\r
+ {\r
+ ulCriticalNesting--;\r
+ if( ulCriticalNesting == portNO_CRITICAL_NESTING )\r
+ {\r
+ /* Enable all interrupt/exception. */\r
+ portENABLE_INTERRUPTS();\r
+ }\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
#define portDOUBLE double\r
#define portLONG long\r
#define portSHORT int\r
-#define portSTACK_TYPE unsigned portSHORT\r
+#define portSTACK_TYPE unsigned portLONG\r
#define portBASE_TYPE long\r
\r
/* This is required since SOFTUNE doesn't support inline directive as is. */\r
/*-----------------------------------------------------------*/ \r
\r
/* Critical section management. */\r
-\r
-\r
-#define portENTER_CRITICAL() \\r
- __asm(" ST PS,@-R15 "); \\r
- __asm(" ANDCCR #0xef "); \\r
-\r
-\r
-#define portEXIT_CRITICAL() \\r
- __asm(" LD @R15+,PS "); \\r
-\r
-\r
-#define portDISABLE_INTERRUPTS() __DI();\r
-\r
-#define portENABLE_INTERRUPTS() __EI();\r
+void vPortEnterCritical( void );\r
+void vPortExitCritical( void );\r
+#define portENTER_CRITICAL() vPortEnterCritical()\r
+#define portEXIT_CRITICAL() vPortExitCritical()\r
+#define portDISABLE_INTERRUPTS() __DI();\r
+#define portENABLE_INTERRUPTS() __EI();\r
\r
/*-----------------------------------------------------------*/\r
\r
/* portYIELD() uses SW interrupt */\r
#define portYIELD() __asm( " INT #40H " );\r
\r
-/* portYIELDFromISR() uses delayed interrupt */\r
-#define portYIELDFromISR() DICR_DLYI = 1;\r
+/* portYIELD_FROM_ISR() uses delayed interrupt */\r
+#define portYIELD_FROM_ISR() DICR_DLYI = 1\r
/*-----------------------------------------------------------*/\r
\r
/* Task function macros as described on the FreeRTOS.org WEB site. */\r