]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/CORTEX_M4_ATSAM4E_Atmel_Studio/src/main_full.c
Update version number to 8.1.2 after moving the defaulting of configUSE_PORT_OPTIMISE...
[freertos] / FreeRTOS / Demo / CORTEX_M4_ATSAM4E_Atmel_Studio / src / main_full.c
index 22376afca1d8e4a6bffa905aa4155d80a0ff823d..f936c97d7a3f9edbbc708d7dab4e6bffee3961f7 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-    FreeRTOS V7.6.0 - Copyright (C) 2013 Real Time Engineers Ltd. \r
+    FreeRTOS V8.1.2 - Copyright (C) 2014 Real Time Engineers Ltd.\r
     All rights reserved\r
 \r
     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\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
 \r
-    >>! NOTE: The modification to the GPL is included to allow you to distribute\r
-    >>! a combined work that includes FreeRTOS without being obliged to provide\r
-    >>! the source code for proprietary components outside of the FreeRTOS\r
-    >>! kernel.\r
+    >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
+    >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
+    >>!   obliged to provide the source code for proprietary components     !<<\r
+    >>!   outside of the FreeRTOS kernel.                                   !<<\r
 \r
     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
     1 tab == 4 spaces!\r
 */\r
 \r
+/******************************************************************************\r
+ * NOTE 1:  This project provides two demo applications.  A simple blinky style\r
+ * project, and a more comprehensive test and demo application that makes use of\r
+ * the FreeRTOS+CLI, FreeRTOS+UDP and FreeRTOS+FAT SL components.  The\r
+ * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select\r
+ * between the two.  See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY\r
+ * in main.c.  This file implements the comprehensive test and demo version,\r
+ * which is fully documented on the following URL:\r
+ * http://www.FreeRTOS.org/Atmel_SAM4E_RTOS_Demo.html\r
+ *\r
+ * NOTE 2:  This file only contains the source code that is specific to the\r
+ * full demo.  Generic functions, such FreeRTOS hook functions, and functions\r
+ * required to configure the hardware, are defined in main.c.\r
+ ******************************************************************************\r
+ *\r
+ * Full user instructions are provided on the following URL:\r
+ * http://www.FreeRTOS.org/Atmel_SAM4E_RTOS_Demo.html\r
+ *\r
+ * main_full():\r
+ *     + Uses FreeRTOS+FAT SL to create a set of example files on a RAM disk.\r
+ *  + Displays some bitmaps on the LCD.\r
+ *  + Registers sample generic, file system related and UDP related commands\r
+ *       with FreeRTOS+CLI.\r
+ *     + Creates all the standard demo application tasks and software timers.\r
+ *     + Starts the scheduler.\r
+ *\r
+ * A UDP command server and optionally two UDP echo client tasks are created\r
+ * from the network event hook after an IP address has been obtained.  The IP\r
+ * address is displayed on the LCD.\r
+ *\r
+ * A "check software timer" is created to provide visual feedback of the system\r
+ * status.  The timer's period is initially set to three seconds.  The callback\r
+ * function associated with the timer checks all the standard demo tasks are not\r
+ * only still executed, but are executing without reporting any errors.  If the\r
+ * timer discovers a task has either stalled, or reported an error, then it\r
+ * changes its own period from the initial three seconds, to just 200ms.  The\r
+ * check software timer also toggles the LED marked D4 - so if the LED toggles\r
+ * every three seconds then no potential errors have been found, and if the LED\r
+ * toggles every 200ms then a potential error has been found in at least one\r
+ * task.\r
+ *\r
+ * Information on accessing the CLI and file system, and using the UDP echo\r
+ * tasks is provided on http://www.FreeRTOS.org/Atmel_SAM4E_RTOS_Demo.html\r
+ *\r
+ */\r
+\r
 /* FreeRTOS includes. */\r
 #include "FreeRTOS.h"\r
 #include "task.h"\r
 \r
 /* FreeRTOS+UDP includes. */\r
 #include "FreeRTOS_UDP_IP.h"\r
+#include "FreeRTOS_Sockets.h"\r
 \r
-/* Demo application includes. */\r
+/* UDP demo includes. */\r
 #include "UDPCommandInterpreter.h"\r
+#include "TwoEchoClients.h"\r
+\r
+/* Standard demo includes. */\r
 #include "partest.h"\r
 #include "blocktim.h"\r
 #include "flash_timer.h"\r
 #include "QueueOverwrite.h"\r
 #include "QueueSet.h"\r
 #include "recmutex.h"\r
+#include "EventGroupsDemo.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
+equivalent in ticks using the portTICK_PERIOD_MS constant. */\r
+#define mainCHECK_TIMER_PERIOD_MS                      ( 3000UL / portTICK_PERIOD_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
+in ticks using the portTICK_PERIOD_MS constant. */\r
+#define mainERROR_CHECK_TIMER_PERIOD_MS        ( 200UL / portTICK_PERIOD_MS )\r
 \r
 /* The priorities of the various demo application tasks. */\r
 #define mainSEM_TEST_PRIORITY                          ( tskIDLE_PRIORITY + 1 )\r
@@ -116,49 +167,64 @@ ISR triggered task. */
 /* Misc. */\r
 #define mainDONT_BLOCK                                         ( 0 )\r
 \r
-/* Note:  If the application is started without the network cable plugged in \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
-ensure the IP task is created at the idle priority.  This is because the Atmel \r
-ASF GMAC driver polls the GMAC looking for a connection, and doing so will \r
-prevent any lower priority tasks from executing.  In this demo the IP task is \r
-started at the idle priority, then set to configMAX_PRIORITIES - 2 in the \r
+ensure the IP task is created at the idle priority.  This is because the Atmel\r
+ASF GMAC driver polls the GMAC looking for a connection, and doing so will\r
+prevent any lower priority tasks from executing.  In this demo the IP task is\r
+started at the idle priority, then set to configMAX_PRIORITIES - 2 in the\r
 network event hook only after a connection has been established (when the event\r
-passed into the network event hook is eNetworkUp). */\r
-#define mainCONNECTED_IP_TASK_PRIORITY         ( configMAX_PRIORITIES - 2 )\r
+passed into the network event hook is eNetworkUp).\r
+http://www.FreeRTOS.org/udp */\r
+#define mainCONNECTED_IP_TASK_PRIORITY         ( configMAX_PRIORITIES - 1 )\r
 #define mainDISCONNECTED_IP_TASK_PRIORITY      ( tskIDLE_PRIORITY )\r
 \r
-/* UDP command server task parameters. */\r
-#define mainUDP_CLI_TASK_PRIORITY                                      ( tskIDLE_PRIORITY )\r
-#define mainUDP_CLI_PORT_NUMBER                                                ( 5001UL )\r
-#define mainUDP_CLI_TASK_STACK_SIZE                                    ( configMINIMAL_STACK_SIZE * 2U )\r
+/* UDP command server and echo task parameters. */\r
+#define mainUDP_CLI_TASK_PRIORITY                      ( tskIDLE_PRIORITY )\r
+#define mainUDP_CLI_PORT_NUMBER                                ( 5001UL )\r
+#define mainUDP_CLI_TASK_STACK_SIZE                    ( configMINIMAL_STACK_SIZE * 2U )\r
+#define mainECHO_CLIENT_STACK_SIZE                     ( configMINIMAL_STACK_SIZE + 30 )\r
+\r
+/* Set to 1 to include the UDP echo client tasks in the build.  The echo clients\r
+require the IP address of the echo server to be defined using the\r
+configECHO_SERVER_ADDR0 to configECHO_SERVER_ADDR3 constants in\r
+FreeRTOSConfig.h. */\r
+#define mainINCLUDE_ECHO_CLIENT_TASKS          1\r
 \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
+static void prvCheckTimerCallback( TimerHandle_t xTimer );\r
 \r
-/* \r
- * Creates a set of sample files on a RAM disk. \r
+/*\r
+ * Creates a set of sample files on a RAM disk.  http://www.FreeRTOS.org/fat_sl\r
  */\r
 extern void vCreateAndVerifySampleFiles( void );\r
 \r
 /*\r
- * Register the generic commands that can be used with FreeRTOS+CLI.\r
+ * Register sample generic commands that can be used with FreeRTOS+CLI.  Type\r
+ * 'help' in the command line to see a list of registered commands.\r
+ * http://www.FreeRTOS.org/cli\r
  */\r
 extern void vRegisterSampleCLICommands( void );\r
 \r
 /*\r
- * Register the file system commands that can be used with FreeRTOS+CLI.\r
+ * Register sample file system commands that can be used with FreeRTOS+CLI.\r
  */\r
 extern void vRegisterFileSystemCLICommands( void );\r
 \r
 /*\r
- * Register the UDP related commands that can be used with FreeRTOS+CLI.\r
+ * Register sample UDP related commands that can be used with FreeRTOS+CLI.\r
  */\r
 extern void vRegisterUDPCLICommands( void );\r
 \r
+/*\r
+ * Initialise the LCD and output a bitmap.\r
+ */\r
+extern void vInitialiseLCD( void );\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 /* The default IP and MAC address used by the demo.  The address configuration\r
@@ -176,28 +242,36 @@ Note each node on a network must have a unique MAC address. */
 const uint8_t ucMACAddress[ 6 ] = { configMAC_ADDR0, configMAC_ADDR1, configMAC_ADDR2, configMAC_ADDR3, configMAC_ADDR4, configMAC_ADDR5 };\r
 \r
 /*-----------------------------------------------------------*/\r
+\r
 int main_full( void )\r
 {\r
-xTimerHandle xTimer = NULL;\r
+TimerHandle_t xTimer = NULL;\r
+\r
+       /* Usage instructions on http://www.FreeRTOS.org/Atmel_SAM4E_RTOS_Demo.html */\r
+\r
+       /* Initialise the LCD and output a bitmap.  The IP address will also be\r
+       displayed on the LCD when it has been obtained. */\r
+       vInitialiseLCD();\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
        before the RTOS scheduler is started.  If the file system is going to be\r
        access from more than one task then F_FS_THREAD_AWARE must be set to 1 and\r
        the     set of sample files are created from the idle task hook function\r
-       vApplicationIdleHook() - which is defined in this file. */\r
+       vApplicationIdleHook(). */\r
        #if( F_FS_THREAD_AWARE == 0 )\r
        {\r
                /* Initialise the drive and file system, then create a few example\r
-               files.  The output from this function just goes to the stdout window,\r
-               allowing the output to be viewed when the UDP command console is not\r
-               connected. */\r
+               files.  The files can be viewed and accessed via the CLI.  View the\r
+               documentation page for this demo (link at the top of this file) for more\r
+               information. */\r
                vCreateAndVerifySampleFiles();\r
        }\r
        #endif\r
 \r
-       /* Register example generic, file system related and UDP related CLI \r
-       commands respectively. */\r
+       /* Register example generic, file system related and UDP related CLI\r
+       commands respectively.  Type 'help' into the command console to view a list\r
+       of registered commands. */\r
        vRegisterSampleCLICommands();\r
        vRegisterFileSystemCLICommands();\r
        vRegisterUDPCLICommands();\r
@@ -206,8 +280,8 @@ xTimerHandle xTimer = NULL;
        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
        set to 0, or if ipconfigUSE_DHCP is set to 1 but a DHCP server cannot be\r
-       contacted.  The Nabto service task is created automatically if\r
-       ipconfigFREERTOS_PLUS_NABTO is set to 1 in FreeRTOSIPConfig.h. */\r
+       contacted.  The IP address actually used is displayed on the LCD (after DHCP\r
+       has completed if DHCP is used). */\r
        FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );\r
 \r
        /* Create all the other standard demo tasks. */\r
@@ -221,14 +295,15 @@ xTimerHandle xTimer = NULL;
        vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_TASK_PRIORITY );\r
        vStartQueueSetTasks();\r
        vStartRecursiveMutexTasks();\r
+       vStartEventGroupTasks();\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
+       xTimer = xTimerCreate(  "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
@@ -247,7 +322,7 @@ xTimerHandle xTimer = NULL;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static void prvCheckTimerCallback( xTimerHandle xTimer )\r
+static void prvCheckTimerCallback( TimerHandle_t xTimer )\r
 {\r
 static long lChangedTimerPeriodAlready = pdFALSE;\r
 unsigned long ulErrorOccurred = pdFALSE;\r
@@ -293,6 +368,10 @@ unsigned long ulErrorOccurred = pdFALSE;
        {\r
                ulErrorOccurred |= ( 0x01UL << 12UL );\r
        }\r
+       else if( xAreEventGroupTasksStillRunning() != pdTRUE )\r
+       {\r
+               ulErrorOccurred |= ( 0x01UL << 13UL );\r
+       }\r
 \r
        if( ulErrorOccurred != pdFALSE )\r
        {\r
@@ -311,6 +390,9 @@ unsigned long ulErrorOccurred = pdFALSE;
                }\r
        }\r
 \r
+       /* Toggle the LED to give visual feedback of the system status.  The rate at\r
+       which the LED toggles will increase to mainERROR_CHECK_TIMER_PERIOD_MS if a\r
+       suspected error has been found in any of the standard demo tasks. */\r
        vParTestToggleLED( mainCHECK_LED );\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -319,6 +401,9 @@ unsigned long ulErrorOccurred = pdFALSE;
 void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )\r
 {\r
 static long lTasksAlreadyCreated = pdFALSE;\r
+const unsigned long ulXCoord = 3, ulYCoord = 3, ulIPAddressOffset = 45;\r
+unsigned long ulIPAddress;\r
+char cIPAddress[ 20 ];\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
@@ -330,25 +415,55 @@ static long lTasksAlreadyCreated = pdFALSE;
        passed into the network event hook is eNetworkUp). */\r
        if( eNetworkEvent == eNetworkUp )\r
        {\r
-               vTaskPrioritySet( NULL, mainCONNECTED_IP_TASK_PRIORITY );\r
-\r
+               /* Ensure tasks are only created once. */\r
                if( lTasksAlreadyCreated == pdFALSE )\r
-               {               \r
-                       /* Create the task that handles the CLI on a UDP port.  The port number\r
-                       is set using the configUDP_CLI_PORT_NUMBER setting in FreeRTOSConfig.h. */\r
+               {\r
+                       /* Create the task that handles the CLI on a UDP port.  The port\r
+                       number is set using the configUDP_CLI_PORT_NUMBER setting in\r
+                       FreeRTOSConfig.h. */\r
                        vStartUDPCommandInterpreterTask( mainUDP_CLI_TASK_STACK_SIZE, mainUDP_CLI_PORT_NUMBER, mainUDP_CLI_TASK_PRIORITY );\r
+\r
+                       #if( mainINCLUDE_ECHO_CLIENT_TASKS == 1 )\r
+                       {\r
+                               /* Create the UDP echo tasks.  The UDP echo tasks require the IP\r
+                               address of the echo server to be defined using the\r
+                               configECHO_SERVER_ADDR0 to configECHO_SERVER_ADDR3 constants in\r
+                               FreeRTOSConfig.h. */\r
+                               vStartEchoClientTasks( mainECHO_CLIENT_STACK_SIZE, tskIDLE_PRIORITY );\r
+                       }\r
+                       #endif\r
                }\r
+\r
+               /* Obtain the IP address, convert it to a string, then display it on the\r
+               LCD. */\r
+               FreeRTOS_GetAddressConfiguration( &ulIPAddress, NULL, NULL, NULL );\r
+               FreeRTOS_inet_ntoa( ulIPAddress, cIPAddress );\r
+               ili93xx_draw_string( ulXCoord, ulYCoord, ( uint8_t * ) "IP: " );\r
+               ili93xx_draw_string( ulXCoord + ulIPAddressOffset, ulYCoord, ( uint8_t * ) cIPAddress );\r
+\r
+               /* Set the priority of the IP task up to the desired priority now it has\r
+               connected. */\r
+               vTaskPrioritySet( NULL, mainCONNECTED_IP_TASK_PRIORITY );\r
        }\r
 \r
+       /* NOTE:  At the time of writing the Ethernet driver does not report the\r
+       cable being unplugged - so the following if() condition will never be met.\r
+       It is included for possible future updates to the driver. */\r
        if( eNetworkEvent == eNetworkDown )\r
        {\r
+               /* Ensure the Atmel GMAC drivers don't hog all the CPU time as they look\r
+               for a new connection by lowering the priority of the IP task to that of\r
+               the Idle task. */\r
                vTaskPrioritySet( NULL, tskIDLE_PRIORITY );\r
+\r
+               /* Disconnected - so no IP address. */\r
+               ili93xx_draw_string( ulXCoord, ulYCoord, ( uint8_t * ) "IP:                  " );\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
 void vFullDemoIdleHook( void )\r
-{      \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 is created\r
        before the RTOS scheduler is started.  If the file system is going to be\r
@@ -374,38 +489,24 @@ void vFullDemoIdleHook( void )
 \r
 void vFullDemoTickHook( void )\r
 {\r
-       /* Call the periodic queue overwrite from ISR demo. */\r
+       /* Call the periodic queue overwrite from ISR test function. */\r
        vQueueOverwritePeriodicISRDemo();\r
 \r
-       /* Call the queue set ISR test function. */\r
+       /* Call the periodic queue set ISR test function. */\r
        vQueueSetAccessQueueSetFromISR();\r
+       \r
+       /* Call the event group ISR tests. */\r
+       vPeriodicEventGroupsProcessing();\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
 /* Called automatically when a reply to an outgoing ping is received. */\r
 void vApplicationPingReplyHook( ePingReplyStatus_t eStatus, uint16_t usIdentifier )\r
 {\r
-       /* This demo has nowhere to output any information so does nothing. */\r
+       /* This demo has nowhere to output any information so does nothing, but the\r
+       IP address resolved for the pined URL is displayed in the CLI. */\r
        ( void ) usIdentifier;\r
-       \r
-       switch( eStatus )\r
-       {\r
-               case eSuccess   :\r
-                       break;\r
-\r
-               case eInvalidChecksum :\r
-                       break;\r
-\r
-               case eInvalidData :\r
-                       break;\r
-\r
-               default :\r
-                       /* It is not possible to get here as all enums have their own\r
-                       case. */\r
-                       break;\r
-       }\r
+       ( void ) eStatus;\r
 }\r
-\r
-\r
-\r
+/*-----------------------------------------------------------*/\r
 \r