--- /dev/null
+/*\r
+ FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd.\r
+ \r
+\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
+\r
+ This file is part of the FreeRTOS distribution.\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
+ 1 tab == 4 spaces!\r
+\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
+\r
+ http://www.OpenRTOS.com - Commercial support, development, porting,\r
+ licensing and training services.\r
+*/\r
+\r
+/* Standard includes. */\r
+#include <string.h>\r
+\r
+/* FreeRTOS includes. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+#include "semphr.h"\r
+\r
+/* lwIP core includes */\r
+#include "lwip/opt.h"\r
+#include "lwip/tcpip.h"\r
+#include "lwip/inet.h"\r
+#include "lwip/dhcp.h"\r
+\r
+/* applications includes */\r
+#include "apps/httpserver_raw_from_lwIP_download/httpd.h"\r
+\r
+/* include the port-dependent configuration */\r
+#include "lwipcfg_msvc.h"\r
+\r
+/* Dimensions the cTxBuffer array - which is itself used to hold replies from \r
+command line commands. cTxBuffer is a shared buffer, so protected by the \r
+xTxBufferMutex mutex. */\r
+#define lwipappsTX_BUFFER_SIZE 1024\r
+\r
+/* The maximum time to block waiting to obtain the xTxBufferMutex to become\r
+available. */\r
+#define lwipappsMAX_TIME_TO_WAIT_FOR_TX_BUFFER_MS ( 100 / portTICK_RATE_MS )\r
+\r
+/* Definitions of the various SSI callback functions within the pccSSITags \r
+array. If pccSSITags is updated, then these definitions must also be updated. */\r
+#define ssiTASK_STATS_INDEX 0\r
+#define ssiRUN_TIME_STATS_INDEX 1\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/*\r
+ * The function that implements the lwIP based sockets command interpreter\r
+ * server.\r
+ */\r
+extern void vBasicSocketsCommandInterpreterTask( void *pvParameters );\r
+\r
+/*\r
+ * The SSI handler callback function passed to lwIP.\r
+ */\r
+static unsigned short uslwIPAppsSSIHandler( int iIndex, char *pcBuffer, int iBufferLength );\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/* The SSI strings that are embedded in the served html files. If this array\r
+is changed, then the index position defined by the #defines such as \r
+ssiTASK_STATS_INDEX above must also be updated. */\r
+static const char *pccSSITags[] = \r
+{\r
+ "rtos_stats",\r
+ "run_stats"\r
+};\r
+\r
+/* Semaphore used to guard the Tx buffer. */\r
+static xSemaphoreHandle xTxBufferMutex = NULL;\r
+\r
+/* The Tx buffer itself. This is used to hold the text generated by the \r
+execution of command line commands, and (hopefully) the execution of \r
+server side include callbacks. It is a shared buffer so protected by the\r
+xTxBufferMutex mutex. pcLwipAppsBlockingGetTxBuffer() and \r
+vLwipAppsReleaseTxBuffer() are provided to obtain and release the \r
+xTxBufferMutex respectively. pcLwipAppsBlockingGetTxBuffer() must be used with\r
+caution as it has the potential to block. */\r
+static signed char cTxBuffer[ lwipappsTX_BUFFER_SIZE ];\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+void vStatusCallback( struct netif *pxNetIf )\r
+{\r
+char pcMessage[20];\r
+struct in_addr* pxIPAddress;\r
+\r
+ if( netif_is_up( pxNetIf ) != 0 )\r
+ {\r
+ strcpy( pcMessage, "IP=" );\r
+ pxIPAddress = ( struct in_addr* ) &( pxNetIf->ip_addr );\r
+ strcat( pcMessage, inet_ntoa( ( *pxIPAddress ) ) );\r
+ xil_printf( pcMessage );\r
+ }\r
+ else\r
+ {\r
+ xil_printf( "Network is down" );\r
+ }\r
+}\r
+\r
+/* Called from the TCP/IP thread. */\r
+void lwIPAppsInit( void *pvArgument )\r
+{\r
+ip_addr_t xIPAddr, xNetMask, xGateway;\r
+extern err_t xemacliteif_init(struct netif *netif);\r
+extern void xemacif_input_thread( void *netif );\r
+static struct netif xNetIf;\r
+\r
+ ( void ) pvArgument;\r
+\r
+ /* Set up the network interface. */\r
+ ip_addr_set_zero( &xGateway );\r
+ ip_addr_set_zero( &xIPAddr );\r
+ ip_addr_set_zero( &xNetMask );\r
+\r
+ LWIP_PORT_INIT_GW(&xGateway);\r
+ LWIP_PORT_INIT_IPADDR( &xIPAddr );\r
+ LWIP_PORT_INIT_NETMASK(&xNetMask);\r
+\r
+ /* Set mac address */\r
+ xNetIf.hwaddr_len = 6;\r
+ xNetIf.hwaddr[ 0 ] = configMAC_ADDR0;\r
+ xNetIf.hwaddr[ 1 ] = configMAC_ADDR1;\r
+ xNetIf.hwaddr[ 2 ] = configMAC_ADDR2;\r
+ xNetIf.hwaddr[ 3 ] = configMAC_ADDR3;\r
+ xNetIf.hwaddr[ 4 ] = configMAC_ADDR4;\r
+ xNetIf.hwaddr[ 5 ] = configMAC_ADDR5;\r
+\r
+ netif_set_default( netif_add( &xNetIf, &xIPAddr, &xNetMask, &xGateway, ( void * ) XPAR_AXI_ETHERNETLITE_0_BASEADDR, xemacliteif_init, tcpip_input ) );\r
+ netif_set_status_callback( &xNetIf, vStatusCallback );\r
+ #if LWIP_DHCP\r
+ {\r
+ dhcp_start( &xNetIf );\r
+ }\r
+ #else\r
+ {\r
+ netif_set_up( &xNetIf );\r
+ }\r
+ #endif\r
+\r
+ /* Install the server side include handler. */\r
+ http_set_ssi_handler( uslwIPAppsSSIHandler, pccSSITags, sizeof( pccSSITags ) / sizeof( char * ) );\r
+\r
+ /* Create the mutex used to ensure mutual exclusive access to the Tx \r
+ buffer. */\r
+ xTxBufferMutex = xSemaphoreCreateMutex();\r
+ configASSERT( xTxBufferMutex );\r
+\r
+ /* Create the httpd server from the standard lwIP code. This demonstrates\r
+ use of the lwIP raw API. */\r
+ httpd_init();\r
+\r
+ sys_thread_new( "lwIP_In", xemacif_input_thread, &xNetIf, configMINIMAL_STACK_SIZE, configMAC_INPUT_TASK_PRIORITY );\r
+\r
+ /* Create the FreeRTOS defined basic command server. This demonstrates use\r
+ of the lwIP sockets API. */\r
+ xTaskCreate( vBasicSocketsCommandInterpreterTask, "CmdInt", configMINIMAL_STACK_SIZE * 5, NULL, configCLI_TASK_PRIORITY, NULL );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static unsigned short uslwIPAppsSSIHandler( int iIndex, char *pcBuffer, int iBufferLength )\r
+{\r
+static unsigned int uiUpdateCount = 0;\r
+static char cUpdateString[ 200 ];\r
+extern char *pcMainGetTaskStatusMessage( void );\r
+\r
+ /* Unused parameter. */\r
+ ( void ) iBufferLength;\r
+\r
+ /* The SSI handler function that generates text depending on the index of\r
+ the SSI tag encountered. */\r
+ \r
+ switch( iIndex )\r
+ {\r
+ case ssiTASK_STATS_INDEX :\r
+ vTaskList( pcBuffer );\r
+ break;\r
+\r
+ case ssiRUN_TIME_STATS_INDEX :\r
+ vTaskGetRunTimeStats( pcBuffer );\r
+ break;\r
+ }\r
+\r
+ /* Include a count of the number of times an SSI function has been executed\r
+ in the returned string. */\r
+ uiUpdateCount++;\r
+ sprintf( cUpdateString, "\r\n\r\n%u\r\nStatus - %s", uiUpdateCount, pcMainGetTaskStatusMessage() );\r
+ strcat( pcBuffer, cUpdateString );\r
+\r
+ return strlen( pcBuffer );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+signed char *pcLwipAppsBlockingGetTxBuffer( void )\r
+{\r
+signed char *pcReturn;\r
+\r
+ /* Attempt to obtain the semaphore that guards the Tx buffer. */\r
+ if( xSemaphoreTakeRecursive( xTxBufferMutex, lwipappsMAX_TIME_TO_WAIT_FOR_TX_BUFFER_MS ) == pdFAIL )\r
+ {\r
+ /* The semaphore could not be obtained before timing out. */\r
+ pcReturn = NULL;\r
+ }\r
+ else\r
+ {\r
+ /* The semaphore was obtained successfully. Return a pointer to the\r
+ Tx buffer. */\r
+ pcReturn = cTxBuffer;\r
+ }\r
+\r
+ return pcReturn;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vLwipAppsReleaseTxBuffer( void )\r
+{\r
+ /* Finished with the Tx buffer. Return the mutex. */\r
+ xSemaphoreGiveRecursive( xTxBufferMutex );\r
+}\r
+\r
+\r
+\r