]> git.sur5r.net Git - freertos/commitdiff
Change the critical section handling (Fujitsu 32bit port).
authorrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Mon, 11 Feb 2008 21:02:40 +0000 (21:02 +0000)
committerrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Mon, 11 Feb 2008 21:02:40 +0000 (21:02 +0000)
git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@163 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

Source/portable/Softune/MB91460/port.c
Source/portable/Softune/MB91460/portmacro.h

index 00de8a98c7b9791ab71796766d4452dc5ed54c19..4c1d425fc11712ecf8b062f622366e152b6513e0 100644 (file)
@@ -51,6 +51,10 @@ any details of its type. */
 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
@@ -63,6 +67,10 @@ extern volatile tskTCB * volatile pxCurrentTCB;
         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
@@ -98,6 +106,10 @@ extern volatile tskTCB * volatile pxCurrentTCB;
 \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
@@ -124,8 +136,6 @@ static void prvSetupTimerInterrupt( void );
  */\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
@@ -185,8 +195,13 @@ unsigned portSHORT usAddress;
        *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
@@ -351,3 +366,31 @@ const unsigned portSHORT usReloadValue = ( unsigned portSHORT ) ( ( ( configPER_
        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
index d9f07ab42c934263569ed49686a7615ed9730993..cd8642332814f95b56dead2a31433ba77762556a 100644 (file)
@@ -59,7 +59,7 @@
 #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