]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/CORTEX_M4_ATSAM4E_Atmel_Studio/src/main_full.c
Add standard demo tasks to SAM4E demo.
[freertos] / FreeRTOS / Demo / CORTEX_M4_ATSAM4E_Atmel_Studio / src / main_full.c
index 34a0c5f7f72fb3e7aa41ff7d958fc23ba6de0eec..b03439c0f2f102741052c66f04d13cc70b9e87ab 100644 (file)
 \r
 /* Demo application includes. */\r
 #include "UDPCommandInterpreter.h"\r
+#include "partest.h"\r
+#include "blocktim.h"\r
+#include "flash_timer.h"\r
+#include "semtest.h"\r
+#include "GenQTest.h"\r
+#include "QPeek.h"\r
+#include "IntQueue.h"\r
+#include "countsem.h"\r
+#include "dynamic.h"\r
+#include "QueueOverwrite.h"\r
+#include "QueueSet.h"\r
+#include "recmutex.h"\r
+\r
+/* The period after which the check timer will expire, in ms, provided no errors\r
+have been reported by any of the standard demo tasks.  ms are converted to the\r
+equivalent in ticks using the portTICK_RATE_MS constant. */\r
+#define mainCHECK_TIMER_PERIOD_MS                      ( 3000UL / portTICK_RATE_MS )\r
+\r
+/* The period at which the check timer will expire, in ms, if an error has been\r
+reported in one of the standard demo tasks.  ms are converted to the equivalent\r
+in ticks using the portTICK_RATE_MS constant. */\r
+#define mainERROR_CHECK_TIMER_PERIOD_MS        ( 200UL / portTICK_RATE_MS )\r
+\r
+/* The priorities of the various demo application tasks. */\r
+#define mainSEM_TEST_PRIORITY                          ( tskIDLE_PRIORITY + 1 )\r
+#define mainBLOCK_Q_PRIORITY                           ( tskIDLE_PRIORITY + 2 )\r
+#define mainCOM_TEST_PRIORITY                          ( tskIDLE_PRIORITY + 2 )\r
+#define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )\r
+#define mainGEN_QUEUE_TASK_PRIORITY                    ( tskIDLE_PRIORITY )\r
+#define mainQUEUE_OVERWRITE_TASK_PRIORITY      ( tskIDLE_PRIORITY )\r
+\r
+/* The LED controlled by the 'check' software timer. */\r
+#define mainCHECK_LED                                          ( 2 )\r
+\r
+/* The number of LEDs that should be controlled by the flash software timer\r
+standard demo.  In this case it is only 1 as the starter kit has three LEDs, one\r
+of which is controlled by the check timer and one of which is controlled by the\r
+ISR triggered task. */\r
+#define mainNUM_FLASH_TIMER_LEDS                       ( 1 )\r
+\r
+/* Misc. */\r
+#define mainDONT_BLOCK                                         ( 0 )\r
 \r
 /* Note:  If the application is started without the network cable plugged in \r
 then ipconfigUDP_TASK_PRIORITY should be set to 0 in FreeRTOSIPConfig.h to\r
@@ -90,10 +132,16 @@ passed into the network event hook is eNetworkUp). */
 #define mainUDP_CLI_PORT_NUMBER                                                ( 5001UL )\r
 #define mainUDP_CLI_TASK_STACK_SIZE                                    ( configMINIMAL_STACK_SIZE * 2U )\r
 \r
-/* Simple toggles an LED to show the program is running. */\r
-static void prvFlashTimerCallback( xTimerHandle xTimer );\r
+/*-----------------------------------------------------------*/\r
+\r
+/*\r
+ * The check timer callback function, as described at the top of this file.\r
+ */\r
+static void prvCheckTimerCallback( xTimerHandle xTimer );\r
 \r
-/* Creates a set of sample files on a RAM disk. */\r
+/* \r
+ * Creates a set of sample files on a RAM disk. \r
+ */\r
 extern void vCreateAndVerifySampleFiles( void );\r
 \r
 /*\r
@@ -125,7 +173,7 @@ const uint8_t ucMACAddress[ 6 ] = { configMAC_ADDR0, configMAC_ADDR1, configMAC_
 /*-----------------------------------------------------------*/\r
 int main_full( void )\r
 {\r
-xTimerHandle xFlashTimer;\r
+xTimerHandle xTimer = NULL;\r
 \r
        /* If the file system is only going to be accessed from one task then\r
        F_FS_THREAD_AWARE can be set to 0 and the set of example files are created\r
@@ -150,15 +198,6 @@ xTimerHandle xFlashTimer;
        interpreter. */\r
        vRegisterFileSystemCLICommands();\r
 \r
-       /* Create the timer that just toggles an LED to indicate that the \r
-       application is running. */\r
-       xFlashTimer = xTimerCreate( ( const signed char * const ) "Flash", 200 / portTICK_RATE_MS, pdTRUE, NULL, prvFlashTimerCallback );\r
-       configASSERT( xFlashTimer );\r
-       \r
-       /* Start the timer.  As the scheduler is not running a block time cannot be\r
-       used and is set to 0. */\r
-       xTimerStart( xFlashTimer, 0 );\r
-\r
        /* Initialise the network interface.  Tasks that use the network are\r
        created in the network event hook when the network is connected and ready\r
        for use.  The address values passed in here are used if ipconfigUSE_DHCP is\r
@@ -167,6 +206,31 @@ xTimerHandle xFlashTimer;
        ipconfigFREERTOS_PLUS_NABTO is set to 1 in FreeRTOSIPConfig.h. */\r
        FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );\r
 \r
+       /* Create all the other standard demo tasks. */\r
+       vStartLEDFlashTimers( mainNUM_FLASH_TIMER_LEDS );\r
+       vCreateBlockTimeTasks();\r
+       vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
+       vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
+       vStartQueuePeekTasks();\r
+       vStartCountingSemaphoreTasks();\r
+       vStartDynamicPriorityTasks();\r
+       vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_TASK_PRIORITY );\r
+       vStartQueueSetTasks();\r
+       vStartRecursiveMutexTasks();\r
+\r
+       /* Create the software timer that performs the 'check' functionality, as\r
+       described at the top of this file. */\r
+       xTimer = xTimerCreate(  ( const signed char * ) "CheckTimer",/* A text name, purely to help debugging. */\r
+                                                       ( mainCHECK_TIMER_PERIOD_MS ),          /* The timer period, in this case 3000ms (3s). */\r
+                                                       pdTRUE,                                                         /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
+                                                       ( void * ) 0,                                           /* The ID is not used, so can be set to anything. */\r
+                                                       prvCheckTimerCallback );                        /* The callback function that inspects the status of all the other tasks. */\r
+\r
+       if( xTimer != NULL )\r
+       {\r
+               xTimerStart( xTimer, mainDONT_BLOCK );\r
+       }\r
+\r
        /* Start the scheduler itself. */\r
        vTaskStartScheduler();\r
 \r
@@ -179,14 +243,71 @@ xTimerHandle xFlashTimer;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static void prvFlashTimerCallback( xTimerHandle xTimer )\r
+static void prvCheckTimerCallback( xTimerHandle xTimer )\r
 {\r
-       /* The parameter is not used. */\r
+static long lChangedTimerPeriodAlready = pdFALSE;\r
+unsigned long ulErrorOccurred = pdFALSE;\r
+\r
+       /* Avoid compiler warnings. */\r
        ( void ) xTimer;\r
-       \r
-       /* Timer callback function that does nothing other than toggle an LED to\r
-       indicate that the application is still running. */\r
-       ioport_toggle_pin_level( LED0_GPIO );\r
+\r
+       /* Have any of the standard demo tasks detected an error in their\r
+       operation? */\r
+       if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
+       {\r
+               ulErrorOccurred |= ( 0x01UL << 3UL );\r
+       }\r
+       else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
+       {\r
+               ulErrorOccurred |= ( 0x01UL << 4UL );\r
+       }\r
+       else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
+       {\r
+               ulErrorOccurred |= ( 0x01UL << 5UL );\r
+       }\r
+       else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
+       {\r
+               ulErrorOccurred |= ( 0x01UL << 6UL );\r
+       }\r
+       else if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )\r
+       {\r
+               ulErrorOccurred |= ( 0x01UL << 8UL );\r
+       }\r
+       else if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
+       {\r
+               ulErrorOccurred |= ( 0x01UL << 9UL );\r
+       }\r
+       else if( xIsQueueOverwriteTaskStillRunning() != pdTRUE )\r
+       {\r
+               ulErrorOccurred |= ( 0x01UL << 10UL );\r
+       }\r
+       else if( xAreQueueSetTasksStillRunning() != pdTRUE )\r
+       {\r
+               ulErrorOccurred |= ( 0x01UL << 11UL );\r
+       }\r
+       else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
+       {\r
+               ulErrorOccurred |= ( 0x01UL << 12UL );\r
+       }\r
+\r
+       if( ulErrorOccurred != pdFALSE )\r
+       {\r
+               /* An error occurred.  Increase the frequency at which the check timer\r
+               toggles its LED to give visual feedback of the potential error\r
+               condition. */\r
+               if( lChangedTimerPeriodAlready == pdFALSE )\r
+               {\r
+                       lChangedTimerPeriodAlready = pdTRUE;\r
+\r
+                       /* This call to xTimerChangePeriod() uses a zero block time.\r
+                       Functions called from inside of a timer callback function must\r
+                       *never* attempt to block as to do so could impact other software\r
+                       timers. */\r
+                       xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );\r
+               }\r
+       }\r
+\r
+       vParTestToggleLED( mainCHECK_LED );\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -245,6 +366,16 @@ void vFullDemoIdleHook( void )
        }\r
        #endif\r
 }\r
+/*-----------------------------------------------------------*/\r
+\r
+void vFullDemoTickHook( void )\r
+{\r
+       /* Call the periodic queue overwrite from ISR demo. */\r
+       vQueueOverwritePeriodicISRDemo();\r
+\r
+       /* Call the queue set ISR test function. */\r
+       vQueueSetAccessQueueSetFromISR();\r
+}\r
 \r
 \r
 \r