]> git.sur5r.net Git - freertos/blobdiff - Demo/CORTEX_LM3Sxxxx_IAR_Keil/main.c
New MicroBlaze port: Added a FreeRTOS exception handler, and installed it in each...
[freertos] / Demo / CORTEX_LM3Sxxxx_IAR_Keil / main.c
index 0b8795cc0627e02d87a170cf8f2430774878e14d..2fbf6f84712e64b0a7fd25a69183a1028a6d4a6c 100644 (file)
@@ -1,50 +1,54 @@
 /*\r
-       FreeRTOS.org V4.8.0 - Copyright (C) 2003-2008 Richard Barry.\r
-\r
-       This file is part of the FreeRTOS.org distribution.\r
-\r
-       FreeRTOS.org is free software; you can redistribute it and/or modify\r
-       it under the terms of the GNU General Public License as published by\r
-       the Free Software Foundation; either version 2 of the License, or\r
-       (at your option) any later version.\r
+    FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.\r
+       \r
 \r
-       FreeRTOS.org is distributed in the hope that it will be useful,\r
-       but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-       GNU General Public License for more details.\r
+    ***************************************************************************\r
+     *                                                                       *\r
+     *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
+     *    Complete, revised, and edited pdf reference manuals are also       *\r
+     *    available.                                                         *\r
+     *                                                                       *\r
+     *    Purchasing FreeRTOS documentation will not only help you, by       *\r
+     *    ensuring you get running as quickly as possible and with an        *\r
+     *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
+     *    the FreeRTOS project to continue with its mission of providing     *\r
+     *    professional grade, cross platform, de facto standard solutions    *\r
+     *    for microcontrollers - completely free of charge!                  *\r
+     *                                                                       *\r
+     *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
+     *                                                                       *\r
+     *    Thank you for using FreeRTOS, and thank you for your support!      *\r
+     *                                                                       *\r
+    ***************************************************************************\r
 \r
-       You should have received a copy of the GNU General Public License\r
-       along with FreeRTOS.org; if not, write to the Free Software\r
-       Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
 \r
-       A special exception to the GPL can be applied should you wish to distribute\r
-       a combined work that includes FreeRTOS.org, without being obliged to provide\r
-       the source code for any proprietary components.  See the licensing section\r
-       of http://www.FreeRTOS.org for full details of how and when the exception\r
-       can be applied.\r
+    This file is part of the FreeRTOS distribution.\r
 \r
-    ***************************************************************************\r
-    ***************************************************************************\r
-    *                                                                         *\r
-    * SAVE TIME AND MONEY!  We can port FreeRTOS.org to your own hardware,    *\r
-    * and even write all or part of your application on your behalf.          *\r
-    * See http://www.OpenRTOS.com for details of the services we provide to   *\r
-    * expedite your project.                                                  *\r
-    *                                                                         *\r
-    ***************************************************************************\r
-    ***************************************************************************\r
+    FreeRTOS is free software; you can redistribute it and/or modify it under\r
+    the terms of the GNU General Public License (version 2) as published by the\r
+    Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
+    >>>NOTE<<< The modification to the GPL is included to allow you to\r
+    distribute a combined work that includes FreeRTOS without being obliged to\r
+    provide the source code for proprietary components outside of the FreeRTOS\r
+    kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
+    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
+    more details. You should have received a copy of the GNU General Public\r
+    License and the FreeRTOS license exception along with FreeRTOS; if not it\r
+    can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
+    by writing to Richard Barry, contact details for whom are available on the\r
+    FreeRTOS WEB site.\r
 \r
-       Please ensure to read the configuration and relevant port sections of the\r
-       online documentation.\r
+    1 tab == 4 spaces!\r
 \r
-       http://www.FreeRTOS.org - Documentation, latest information, license and \r
-       contact details.\r
+    http://www.FreeRTOS.org - Documentation, latest information, license and\r
+    contact details.\r
 \r
-       http://www.SafeRTOS.com - A version that is certified for use in safety \r
-       critical systems.\r
+    http://www.SafeRTOS.com - A version that is certified for use in safety\r
+    critical systems.\r
 \r
-       http://www.OpenRTOS.com - Commercial support, development, porting, \r
-       licensing and training services.\r
+    http://www.OpenRTOS.com - Commercial support, development, porting,\r
+    licensing and training services.\r
 */\r
 \r
 \r
 \r
 \r
 \r
+\r
+/*************************************************************************\r
+ * Please ensure to read http://www.freertos.org/portlm3sx965.html\r
+ * which provides information on configuring and running this demo for the\r
+ * various Luminary Micro EKs.\r
+ *************************************************************************/\r
+\r
+/* Set the following option to 1 to include the WEB server in the build.  By\r
+default the WEB server is excluded to keep the compiled code size under the 32K\r
+limit imposed by the KickStart version of the IAR compiler.  The graphics\r
+libraries take up a lot of ROM space, hence including the graphics libraries\r
+and the TCP/IP stack together cannot be accommodated with the 32K size limit. */\r
+#define mainINCLUDE_WEB_SERVER         0\r
+\r
+\r
 /* Standard includes. */\r
 #include <stdio.h>\r
 \r
 #include "queue.h"\r
 #include "semphr.h"\r
 \r
+/* Hardware library includes. */\r
+#include "hw_memmap.h"\r
+#include "hw_types.h"\r
+#include "hw_sysctl.h"\r
+#include "sysctl.h"\r
+#include "gpio.h"\r
+#include "grlib.h"\r
+#include "rit128x96x4.h"\r
+#include "osram128x64x4.h"\r
+#include "formike128x128x16.h"\r
+\r
 /* Demo app includes. */\r
 #include "BlockQ.h"\r
 #include "death.h"\r
 #include "bitmap.h"\r
 #include "GenQTest.h"\r
 #include "QPeek.h"\r
-\r
-/* Hardware library includes. */\r
-#include "hw_memmap.h"\r
-#include "hw_types.h"\r
-#include "hw_sysctl.h"\r
-#include "sysctl.h"\r
-#include "gpio.h"\r
-#include "rit128x96x4.h"\r
-#include "osram128x64x4.h"\r
+#include "recmutex.h"\r
+#include "IntQueue.h"\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
@@ -148,6 +171,7 @@ the jitter time in nano seconds. */
 \r
 /* Constants used when writing strings to the display. */\r
 #define mainCHARACTER_HEIGHT                           ( 9 )\r
+#define mainMAX_ROWS_128                                       ( mainCHARACTER_HEIGHT * 14 )\r
 #define mainMAX_ROWS_96                                                ( mainCHARACTER_HEIGHT * 10 )\r
 #define mainMAX_ROWS_64                                                ( mainCHARACTER_HEIGHT * 7 )\r
 #define mainFULL_SCALE                                         ( 15 )\r
@@ -178,7 +202,14 @@ static void prvSetupHardware( void );
  * Configures the high frequency timers - those used to measure the timing\r
  * jitter while the real time kernel is executing.\r
  */\r
-extern void vSetupTimer( void );\r
+extern void vSetupHighFrequencyTimer( void );\r
+\r
+/*\r
+ * Hook functions that can get called by the kernel.\r
+ */\r
+void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName );\r
+void vApplicationTickHook( void );\r
+\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
@@ -190,6 +221,12 @@ const portCHAR * const pcWelcomeMessage = "   www.FreeRTOS.org";
 \r
 /*-----------------------------------------------------------*/\r
 \r
+\r
+/*************************************************************************\r
+ * Please ensure to read http://www.freertos.org/portlm3sx965.html\r
+ * which provides information on configuring and running this demo for the\r
+ * various Luminary Micro EKs.\r
+ *************************************************************************/\r
 int main( void )\r
 {\r
        prvSetupHardware();\r
@@ -198,22 +235,32 @@ int main( void )
        are received via this queue. */\r
        xOLEDQueue = xQueueCreate( mainOLED_QUEUE_SIZE, sizeof( xOLEDMessage ) );\r
 \r
-       /* Create the uIP task if running on a processor that includes a MAC and\r
-       PHY. */\r
-       if( SysCtlPeripheralPresent( SYSCTL_PERIPH_ETH ) )\r
-       {\r
-               xTaskCreate( vuIP_Task, ( signed portCHAR * ) "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );\r
-       }\r
-\r
        /* Start the standard demo tasks. */\r
-       vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
-    vCreateBlockTimeTasks();\r
-    vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
-    vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
     vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );\r
     vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
-    vStartQueuePeekTasks();\r
-\r
+    vStartInterruptQueueTasks();\r
+       vStartRecursiveMutexTasks();    \r
+       vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
+       vCreateBlockTimeTasks();\r
+       vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
+       vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
+       vStartQueuePeekTasks();         \r
+\r
+       /* Exclude some tasks if using the kickstart version to ensure we stay within\r
+       the 32K code size limit. */\r
+       #if mainINCLUDE_WEB_SERVER != 0\r
+       {\r
+               /* Create the uIP task if running on a processor that includes a MAC and\r
+               PHY. */\r
+               if( SysCtlPeripheralPresent( SYSCTL_PERIPH_ETH ) )\r
+               {\r
+                       xTaskCreate( vuIP_Task, ( signed portCHAR * ) "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );\r
+               }\r
+       }\r
+       #endif\r
+       \r
+       \r
+       \r
        /* Start the tasks defined within this file/specific to this demo. */\r
        xTaskCreate( vOLEDTask, ( signed portCHAR * ) "OLED", mainOLED_TASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
 \r
@@ -223,10 +270,9 @@ int main( void )
     vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
 \r
        /* Configure the high frequency interrupt used to measure the interrupt\r
-       jitter time.  The Keil port does not yet include the\r
-       configKERNEL_INTERRUPT_PRIORITY functionality so cannot perform this test. */\r
-       vSetupTimer();\r
-       \r
+       jitter time. */\r
+       vSetupHighFrequencyTimer();\r
+\r
        /* Start the scheduler. */\r
        vTaskStartScheduler();\r
 \r
@@ -263,6 +309,7 @@ void vApplicationTickHook( void )
 {\r
 static xOLEDMessage xMessage = { "PASS" };\r
 static unsigned portLONG ulTicksSinceLastDisplay = 0;\r
+portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
 \r
        /* Called from every tick interrupt.  Have enough ticks passed to make it\r
        time to perform our health status check again? */\r
@@ -276,9 +323,17 @@ static unsigned portLONG ulTicksSinceLastDisplay = 0;
                {\r
                        xMessage.pcMessage = "ERROR IN GEN Q";\r
                }\r
-               else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
+           else if( xIsCreateTaskStillRunning() != pdTRUE )\r
+           {\r
+               xMessage.pcMessage = "ERROR IN CREATE";\r
+           }\r
+           else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
+           {\r
+               xMessage.pcMessage = "ERROR IN MATH";\r
+           }\r
+               else if( xAreIntQueueTasksStillRunning() != pdTRUE )\r
                {\r
-                       xMessage.pcMessage = "ERROR IN PEEK Q";\r
+                       xMessage.pcMessage = "ERROR IN INT QUEUE";\r
                }\r
                else if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
                {\r
@@ -288,25 +343,26 @@ static unsigned portLONG ulTicksSinceLastDisplay = 0;
                {\r
                        xMessage.pcMessage = "ERROR IN BLOCK TIME";\r
                }\r
-           else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
-           {\r
-               xMessage.pcMessage = "ERROR IN SEMAPHORE";\r
-           }\r
-           else if( xArePollingQueuesStillRunning() != pdTRUE )\r
-           {\r
-               xMessage.pcMessage = "ERROR IN POLL Q";\r
-           }\r
-           else if( xIsCreateTaskStillRunning() != pdTRUE )\r
-           {\r
-               xMessage.pcMessage = "ERROR IN CREATE";\r
-           }\r
-           else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
-           {\r
-               xMessage.pcMessage = "ERROR IN MATH";\r
-           }\r
-       \r
+               else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
+               {\r
+                       xMessage.pcMessage = "ERROR IN SEMAPHORE";\r
+               }\r
+               else if( xArePollingQueuesStillRunning() != pdTRUE )\r
+               {\r
+                       xMessage.pcMessage = "ERROR IN POLL Q";\r
+               }\r
+               else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
+               {\r
+                       xMessage.pcMessage = "ERROR IN PEEK Q";\r
+               }                       \r
+               else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
+               {\r
+                       xMessage.pcMessage = "ERROR IN REC MUTEX";\r
+               }                       \r
+               \r
                /* Send the message to the OLED gatekeeper for display. */\r
-               xQueueSendFromISR( xOLEDQueue, &xMessage, pdFALSE );\r
+               xHigherPriorityTaskWoken = pdFALSE;\r
+               xQueueSendFromISR( xOLEDQueue, &xMessage, &xHigherPriorityTaskWoken );\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -316,14 +372,19 @@ void vOLEDTask( void *pvParameters )
 xOLEDMessage xMessage;\r
 unsigned portLONG ulY, ulMaxY;\r
 static portCHAR cMessage[ mainMAX_MSG_LEN ];\r
-extern unsigned portLONG ulMaxJitter;\r
+extern volatile unsigned portLONG ulMaxJitter;\r
+unsigned portBASE_TYPE uxUnusedStackOnEntry;\r
+const unsigned portCHAR *pucImage;\r
 \r
 /* Functions to access the OLED.  The one used depends on the dev kit\r
 being used. */\r
-void ( *vOLEDInit )( unsigned portLONG );\r
-void ( *vOLEDStringDraw )( const portCHAR *, unsigned portLONG, unsigned portLONG, unsigned portCHAR );\r
-void ( *vOLEDImageDraw )( const unsigned portCHAR *, unsigned portLONG, unsigned portLONG, unsigned portLONG, unsigned portLONG );\r
-void ( *vOLEDClear )( void );\r
+void ( *vOLEDInit )( unsigned portLONG ) = NULL;\r
+void ( *vOLEDStringDraw )( const portCHAR *, unsigned portLONG, unsigned portLONG, unsigned portCHAR ) = NULL;\r
+void ( *vOLEDImageDraw )( const unsigned portCHAR *, unsigned portLONG, unsigned portLONG, unsigned portLONG, unsigned portLONG ) = NULL;\r
+void ( *vOLEDClear )( void ) = NULL;\r
+\r
+       /* Just for demo purposes. */\r
+       uxUnusedStackOnEntry = uxTaskGetStackHighWaterMark( NULL );\r
 \r
        /* Map the OLED access functions to the driver functions that are appropriate\r
        for the evaluation kit being used. */   \r
@@ -335,21 +396,33 @@ void ( *vOLEDClear )( void );
                                                                                vOLEDImageDraw = OSRAM128x64x4ImageDraw;\r
                                                                                vOLEDClear = OSRAM128x64x4Clear;\r
                                                                                ulMaxY = mainMAX_ROWS_64;\r
+                                                                               pucImage = pucBasicBitmap;\r
                                                                                break;\r
                                                                                \r
-               default                                         :       vOLEDInit = RIT128x96x4Init;\r
+               case SYSCTL_DID1_PRTNO_1968     :       \r
+               case SYSCTL_DID1_PRTNO_8962 :   vOLEDInit = RIT128x96x4Init;\r
                                                                                vOLEDStringDraw = RIT128x96x4StringDraw;\r
                                                                                vOLEDImageDraw = RIT128x96x4ImageDraw;\r
                                                                                vOLEDClear = RIT128x96x4Clear;\r
-                                                                               ulMaxY = mainMAX_ROWS_96;                                                                               \r
+                                                                               ulMaxY = mainMAX_ROWS_96;\r
+                                                                               pucImage = pucBasicBitmap;\r
                                                                                break;\r
+                                                                               \r
+               default                                         :       vOLEDInit = vFormike128x128x16Init;\r
+                                                                               vOLEDStringDraw = vFormike128x128x16StringDraw;\r
+                                                                               vOLEDImageDraw = vFormike128x128x16ImageDraw;\r
+                                                                               vOLEDClear = vFormike128x128x16Clear;\r
+                                                                               ulMaxY = mainMAX_ROWS_128;\r
+                                                                               pucImage = pucGrLibBitmap;\r
+                                                                               break;\r
+                                                                               \r
        }\r
 \r
        ulY = ulMaxY;\r
        \r
        /* Initialise the OLED and display a startup message. */\r
        vOLEDInit( ulSSI_FREQUENCY );   \r
-       vOLEDStringDraw( " POWERED BY FreeRTOS", 0, 0, mainFULL_SCALE );\r
+       vOLEDStringDraw( "POWERED BY FreeRTOS", 0, 0, mainFULL_SCALE );\r
        vOLEDImageDraw( pucImage, 0, mainCHARACTER_HEIGHT + 1, bmpBITMAP_WIDTH, bmpBITMAP_HEIGHT );\r
        \r
        for( ;; )\r
@@ -372,3 +445,12 @@ void ( *vOLEDClear )( void );
                vOLEDStringDraw( cMessage, 0, ulY, mainFULL_SCALE );\r
        }\r
 }\r
+/*-----------------------------------------------------------*/\r
+\r
+void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName )\r
+{\r
+       ( void ) pxTask;\r
+       ( void ) pcTaskName;\r
+\r
+       for( ;; );\r
+}\r