+++ /dev/null
-/*\r
- * FreeRTOS Kernel V10.1.0\r
- * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
- *\r
- * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
- * this software and associated documentation files (the "Software"), to deal in\r
- * the Software without restriction, including without limitation the rights to\r
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
- * the Software, and to permit persons to whom the Software is furnished to do so,\r
- * subject to the following conditions:\r
- *\r
- * The above copyright notice and this permission notice shall be included in all\r
- * copies or substantial portions of the Software.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- *\r
- * http://www.FreeRTOS.org\r
- * http://aws.amazon.com/freertos\r
- *\r
- * 1 tab == 4 spaces!\r
- */\r
-\r
-/* Standard includes. */\r
-#include <string.h>\r
-\r
-/* Scheduler includes. */\r
-#include "FreeRTOS.h"\r
-#include "task.h"\r
-#include "timers.h"\r
-#include "queue.h"\r
-\r
-/* uip includes. */\r
-#include "net/uip.h"\r
-#include "net/uip_arp.h"\r
-#include "apps/httpd/httpd.h"\r
-#include "sys/timer.h"\r
-#include "net/clock-arch.h"\r
-#include "r_ether.h"\r
-\r
-/* Demo includes. */\r
-#include "ParTest.h"\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-/* How long to wait before attempting to connect the MAC again. */\r
-#define uipINIT_WAIT ( 100 / portTICK_PERIOD_MS )\r
-\r
-/* Shortcut to the header within the Rx buffer. */\r
-#define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])\r
-\r
-/* Standard constant. */\r
-#define uipTOTAL_FRAME_HEADER_SIZE 54\r
-\r
-/* The ARP timer and the periodic timer share a callback function, so the\r
-respective timer IDs are used to determine which timer actually expired. These\r
-constants are assigned to the timer IDs. */\r
-#define uipARP_TIMER 0\r
-#define uipPERIODIC_TIMER 1\r
-\r
-/* A block time of zero ticks simply means, "don't block". */\r
-#define uipDONT_BLOCK 0UL\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-/*\r
- * Setup the MAC address in the MAC itself, and in the uIP stack.\r
- */\r
-static void prvSetMACAddress( void );\r
-\r
-/*\r
- * Perform any uIP initialisation necessary.\r
- */\r
-static void prvInitialise_uIP( void );\r
-\r
-/*\r
- * The callback function that is assigned to both the periodic timer and the\r
- * ARP timer.\r
- */\r
-static void prvUIPTimerCallback( TimerHandle_t xTimer );\r
-\r
-/*\r
- * Port functions required by the uIP stack.\r
- */\r
-clock_time_t clock_time( void );\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-/* The queue used to send TCP/IP events to the uIP stack. */\r
-QueueHandle_t xEMACEventQueue = NULL;\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-clock_time_t clock_time( void )\r
-{\r
- return xTaskGetTickCount();\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-void vuIP_Task( void *pvParameters )\r
-{\r
-portBASE_TYPE i;\r
-unsigned long ulNewEvent = 0UL;\r
-unsigned long ulUIP_Events = 0UL;\r
-\r
- ( void ) pvParameters;\r
-\r
- /* Initialise the uIP stack. */\r
- prvInitialise_uIP();\r
-\r
- /* Initialise the MAC. */\r
- vInitEmac();\r
-\r
- while( lEMACWaitForLink() != pdPASS )\r
- {\r
- vTaskDelay( uipINIT_WAIT );\r
- }\r
-\r
- for( ;; )\r
- {\r
- if( ( ulUIP_Events & uipETHERNET_RX_EVENT ) != 0UL )\r
- {\r
- /* Is there received data ready to be processed? */\r
- uip_len = ( unsigned short ) ulEMACRead();\r
-\r
- if( ( uip_len > 0 ) && ( uip_buf != NULL ) )\r
- {\r
- /* Standard uIP loop taken from the uIP manual. */\r
- if( xHeader->type == htons( UIP_ETHTYPE_IP ) )\r
- {\r
- uip_arp_ipin();\r
- uip_input();\r
-\r
- /* If the above function invocation resulted in data that\r
- should be sent out on the network, the global variable\r
- uip_len is set to a value > 0. */\r
- if( uip_len > 0 )\r
- {\r
- uip_arp_out();\r
- vEMACWrite();\r
- }\r
- }\r
- else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )\r
- {\r
- uip_arp_arpin();\r
-\r
- /* If the above function invocation resulted in data that\r
- should be sent out on the network, the global variable\r
- uip_len is set to a value > 0. */\r
- if( uip_len > 0 )\r
- {\r
- vEMACWrite();\r
- }\r
- }\r
- }\r
- else\r
- {\r
- ulUIP_Events &= ~uipETHERNET_RX_EVENT;\r
- }\r
- }\r
-\r
- if( ( ulUIP_Events & uipPERIODIC_TIMER_EVENT ) != 0UL )\r
- {\r
- ulUIP_Events &= ~uipPERIODIC_TIMER_EVENT;\r
-\r
- for( i = 0; i < UIP_CONNS; i++ )\r
- {\r
- uip_periodic( i );\r
-\r
- /* If the above function invocation resulted in data that\r
- should be sent out on the network, the global variable\r
- uip_len is set to a value > 0. */\r
- if( uip_len > 0 )\r
- {\r
- uip_arp_out();\r
- vEMACWrite();\r
- }\r
- }\r
- }\r
-\r
- /* Call the ARP timer function every 10 seconds. */\r
- if( ( ulUIP_Events & uipARP_TIMER_EVENT ) != 0 )\r
- {\r
- ulUIP_Events &= ~uipARP_TIMER_EVENT;\r
- uip_arp_timer();\r
- }\r
-\r
- if( ulUIP_Events == pdFALSE )\r
- {\r
- xQueueReceive( xEMACEventQueue, &ulNewEvent, portMAX_DELAY );\r
- ulUIP_Events |= ulNewEvent;\r
- }\r
- }\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvInitialise_uIP( void )\r
-{\r
-TimerHandle_t xARPTimer, xPeriodicTimer;\r
-uip_ipaddr_t xIPAddr;\r
-const unsigned long ul_uIPEventQueueLength = 10UL;\r
-\r
- /* Initialise the uIP stack. */\r
- uip_init();\r
- uip_ipaddr( &xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );\r
- uip_sethostaddr( &xIPAddr );\r
- uip_ipaddr( &xIPAddr, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );\r
- uip_setnetmask( &xIPAddr );\r
- prvSetMACAddress();\r
- httpd_init();\r
-\r
- /* Create the queue used to sent TCP/IP events to the uIP stack. */\r
- xEMACEventQueue = xQueueCreate( ul_uIPEventQueueLength, sizeof( unsigned long ) );\r
-\r
- /* Create and start the uIP timers. */\r
- xARPTimer = xTimerCreate( "ARPTimer", /* Just a name that is helpful for debugging, not used by the kernel. */\r
- ( 10000UL / portTICK_PERIOD_MS ), /* Timer period. */\r
- pdTRUE, /* Autor-reload. */\r
- ( void * ) uipARP_TIMER,\r
- prvUIPTimerCallback\r
- );\r
-\r
- xPeriodicTimer = xTimerCreate( "PeriodicTimer",\r
- ( 50 / portTICK_PERIOD_MS ),\r
- pdTRUE, /* Autor-reload. */\r
- ( void * ) uipPERIODIC_TIMER,\r
- prvUIPTimerCallback\r
- );\r
-\r
- configASSERT( xARPTimer );\r
- configASSERT( xPeriodicTimer );\r
-\r
- xTimerStart( xARPTimer, portMAX_DELAY );\r
- xTimerStart( xPeriodicTimer, portMAX_DELAY );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvUIPTimerCallback( TimerHandle_t xTimer )\r
-{\r
-static const unsigned long ulARPTimerExpired = uipARP_TIMER_EVENT;\r
-static const unsigned long ulPeriodicTimerExpired = uipPERIODIC_TIMER_EVENT;\r
-\r
- /* This is a time callback, so calls to xQueueSend() must not attempt to\r
- block. */\r
- switch( ( int ) pvTimerGetTimerID( xTimer ) )\r
- {\r
- case uipARP_TIMER : xQueueSend( xEMACEventQueue, &ulARPTimerExpired, uipDONT_BLOCK );\r
- break;\r
-\r
- case uipPERIODIC_TIMER : xQueueSend( xEMACEventQueue, &ulPeriodicTimerExpired, uipDONT_BLOCK );\r
- break;\r
-\r
- default : /* Should not get here. */\r
- break;\r
- }\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvSetMACAddress( void )\r
-{\r
-struct uip_eth_addr xAddr;\r
-\r
- /* Configure the MAC address in the uIP stack. */\r
- xAddr.addr[ 0 ] = configMAC_ADDR0;\r
- xAddr.addr[ 1 ] = configMAC_ADDR1;\r
- xAddr.addr[ 2 ] = configMAC_ADDR2;\r
- xAddr.addr[ 3 ] = configMAC_ADDR3;\r
- xAddr.addr[ 4 ] = configMAC_ADDR4;\r
- xAddr.addr[ 5 ] = configMAC_ADDR5;\r
- uip_setethaddr( xAddr );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-void vApplicationProcessFormInput( char *pcInputString )\r
-{\r
-char *c;\r
-\r
- /* Only interested in processing form input if this is the IO page. */\r
- c = strstr( pcInputString, "io.shtml" );\r
-\r
- if( c )\r
- {\r
- /* Is there a command in the string? */\r
- c = strstr( pcInputString, "?" );\r
- if( c )\r
- {\r
- /* Turn the LED's on or off in accordance with the check box status. */\r
- if( strstr( c, "LED0=1" ) != NULL )\r
- {\r
- /* Turn the LEDs on. */\r
- vParTestSetLED( 7, 1 );\r
- vParTestSetLED( 8, 1 );\r
- vParTestSetLED( 9, 1 );\r
- vParTestSetLED( 10, 1 );\r
- }\r
- else\r
- {\r
- /* Turn the LEDs off. */\r
- vParTestSetLED( 7, 0 );\r
- vParTestSetLED( 8, 0 );\r
- vParTestSetLED( 9, 0 );\r
- vParTestSetLED( 10, 0 );\r
- }\r
- }\r
- else\r
- {\r
- /* Commands to turn LEDs off are not always explicit. */\r
- vParTestSetLED( 7, 0 );\r
- vParTestSetLED( 8, 0 );\r
- vParTestSetLED( 9, 0 );\r
- vParTestSetLED( 10, 0 );\r
- }\r
- }\r
-}\r
-\r