/* Called by FreeRTOS+UDP when the network connects. */ void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent ) { static BaseType_t xTaskAlreadyCreated = pdFALSE; if( eNetworkEvent == eNetworkUp ) { /* Create the tasks that transmit to and receive from a standard echo server (see the web documentation for this port) in both standard and zero copy mode. */ if( xTaskAlreadyCreated == pdFALSE ) { vStartEchoClientTasks( mainECHO_CLIENT_TASK_STACK_SIZE, mainECHO_CLIENT_TASK_PRIORITY ); xTaskAlreadyCreated = pdTRUE; } } }
/* Called by FreeRTOS+UDP when the network connects. */ void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent ) { uint32_t ulIPAddress, ulNetMask, ulGatewayAddress, ulDNSServerAddress; int8_t cBuffer[ 16 ]; static portBASE_TYPE xTasksAlreadyCreated = pdFALSE; if( eNetworkEvent == eNetworkUp ) { /* Create the tasks that use the IP stack if they have not already been created. */ if( xTasksAlreadyCreated == pdFALSE ) { #if( mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS == 1 ) { /* Create tasks that demonstrate sending and receiving in both standard and zero copy mode. */ vStartSimpleUDPClientServerTasks( mainSIMPLE_CLIENT_SERVER_TASK_STACK_SIZE, mainSIMPLE_CLIENT_SERVER_PORT, mainSIMPLE_CLIENT_SERVER_TASK_PRIORITY ); } #endif /* mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS */ #if( mainCREATE_SELECT_UDP_SERVER_TASKS == 1 ) { /* Create tasks that demonstrate sending and receiving in both standard and zero copy mode. */ vStartSelectUDPServerTasks( mainSELECT_SERVER_TASK_STACK_SIZE, mainSELECT_SERVER_PORT, mainSELECT_SERVER_TASK_PRIORITY ); } #endif /* mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS */ #if( mainCREATE_UDP_ECHO_TASKS == 1 ) { /* Create the tasks that transmit to and receive from a standard echo server (see the web documentation for this port) in both standard and zero copy mode. */ vStartEchoClientTasks( mainECHO_CLIENT_TASK_STACK_SIZE, mainECHO_CLIENT_TASK_PRIORITY ); } #endif /* mainCREATE_UDP_ECHO_TASKS */ #if( mainCREATE_UDP_CLI_TASKS == 1 ) { /* Create the task that handles the CLI on a UDP port. The port number is set using the configUDP_CLI_PORT_NUMBER setting in FreeRTOSConfig.h. */ vStartUDPCommandInterpreterTask( mainUDP_CLI_TASK_STACK_SIZE, mainUDP_CLI_PORT_NUMBER, mainUDP_CLI_TASK_PRIORITY ); } #endif /* mainCREATE_UDP_CLI_TASKS */ xTasksAlreadyCreated = pdTRUE; } /* Print out the network configuration, which may have come from a DHCP server. */ FreeRTOS_GetAddressConfiguration( &ulIPAddress, &ulNetMask, &ulGatewayAddress, &ulDNSServerAddress ); vOutputString( "IP Address: " ); FreeRTOS_inet_ntoa( ulIPAddress, cBuffer ); vOutputString( ( char * ) cBuffer ); vOutputString( "\r\nSubnet Mask: " ); FreeRTOS_inet_ntoa( ulNetMask, cBuffer ); vOutputString( ( char * ) cBuffer ); vOutputString( "\r\nGateway Address: " ); FreeRTOS_inet_ntoa( ulGatewayAddress, cBuffer ); vOutputString( ( char * ) cBuffer ); vOutputString( "\r\nDNS Server Address: " ); FreeRTOS_inet_ntoa( ulDNSServerAddress, cBuffer ); vOutputString( ( char * ) cBuffer ); vOutputString( "\r\n\r\n" ); } }
/* Called by FreeRTOS+UDP when the network connects. */ void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent ) { static long lTasksAlreadyCreated = pdFALSE; const unsigned long ulXCoord = 3, ulYCoord = 3, ulIPAddressOffset = 45; unsigned long ulIPAddress; char cIPAddress[ 20 ]; /* Note: If the application is started without the network cable plugged in then ipconfigUDP_TASK_PRIORITY should be set to 0 in FreeRTOSIPConfig.h to ensure the IP task is created at the idle priority. This is because the Atmel ASF GMAC driver polls the GMAC looking for a connection, and doing so will prevent any lower priority tasks from executing. In this demo the IP task is started at the idle priority, then set to configMAX_PRIORITIES - 2 in the network event hook only after a connection has been established (when the event passed into the network event hook is eNetworkUp). */ if( eNetworkEvent == eNetworkUp ) { /* Ensure tasks are only created once. */ if( lTasksAlreadyCreated == pdFALSE ) { /* Create the task that handles the CLI on a UDP port. The port number is set using the configUDP_CLI_PORT_NUMBER setting in FreeRTOSConfig.h. */ vStartUDPCommandInterpreterTask( mainUDP_CLI_TASK_STACK_SIZE, mainUDP_CLI_PORT_NUMBER, mainUDP_CLI_TASK_PRIORITY ); #if( mainINCLUDE_ECHO_CLIENT_TASKS == 1 ) { /* Create the UDP echo tasks. The UDP echo tasks require the IP address of the echo server to be defined using the configECHO_SERVER_ADDR0 to configECHO_SERVER_ADDR3 constants in FreeRTOSConfig.h. */ vStartEchoClientTasks( mainECHO_CLIENT_STACK_SIZE, tskIDLE_PRIORITY ); } #endif } /* Obtain the IP address, convert it to a string, then display it on the LCD. */ FreeRTOS_GetAddressConfiguration( &ulIPAddress, NULL, NULL, NULL ); FreeRTOS_inet_ntoa( ulIPAddress, cIPAddress ); ili93xx_draw_string( ulXCoord, ulYCoord, ( uint8_t * ) "IP: " ); ili93xx_draw_string( ulXCoord + ulIPAddressOffset, ulYCoord, ( uint8_t * ) cIPAddress ); /* Set the priority of the IP task up to the desired priority now it has connected. */ vTaskPrioritySet( NULL, mainCONNECTED_IP_TASK_PRIORITY ); } /* NOTE: At the time of writing the Ethernet driver does not report the cable being unplugged - so the following if() condition will never be met. It is included for possible future updates to the driver. */ if( eNetworkEvent == eNetworkDown ) { /* Ensure the Atmel GMAC drivers don't hog all the CPU time as they look for a new connection by lowering the priority of the IP task to that of the Idle task. */ vTaskPrioritySet( NULL, tskIDLE_PRIORITY ); /* Disconnected - so no IP address. */ ili93xx_draw_string( ulXCoord, ulYCoord, ( uint8_t * ) "IP: " ); } }