-/*******************************************************************************
-* Network Interface file
-*
-* Summary:
-* Network Interface file for FreeRTOS-Plus-TCP stack
-*
-* Description:
-* - Interfaces PIC32 to the FreeRTOS TCP/IP stack
-*******************************************************************************/
-
-/*******************************************************************************
-* File Name: pic32_NetworkInterface.c
-* Copyright 2017 Microchip Technology Incorporated and its subsidiaries.
-*
-* Permission is hereby granted, free of charge, to any person obtaining a copy of
-* this software and associated documentation files (the "Software"), to deal in
-* the Software without restriction, including without limitation the rights to
-* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-* of the Software, and to permit persons to whom the Software is furnished to do
-* so, subject to the following conditions:
-* The above copyright notice and this permission notice shall be included in all
-* copies or substantial portions of the Software.
-*
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-* SOFTWARE
-*******************************************************************************/
-#ifndef PIC32_USE_ETHERNET
-#include <sys/kmem.h>
-
-#include "FreeRTOS.h"
-#include "semphr.h"
-#include "event_groups.h"
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_IP_Private.h"
-
-#include "NetworkInterface.h"
-#include "NetworkBufferManagement.h"
-#include "peripheral/eth/plib_eth.h"
-
-#include "system_config.h"
-#include "system/console/sys_console.h"
-#include "system/debug/sys_debug.h"
-#include "system/command/sys_command.h"
-
-#include "driver/ethmac/drv_ethmac.h"
-#include "driver/miim/drv_miim.h"
-#include "m2m_types.h"
-
-#include "tcpip/tcpip.h"
-#include "tcpip/src/tcpip_private.h"
-#include "tcpip/src/link_list.h"
-#include "wilc1000_task.h"
-
-#include "NetworkConfig.h"
-
-
- #include "iot_wifi.h"
-
- /* local definitions and data */
-
-
- /* FreeRTOS implementation functions */
- BaseType_t xNetworkInterfaceInitialise( void )
- {
- WIFINetworkParams_t xNetworkParams;
-
- xNetworkParams.pcSSID = clientcredentialWIFI_SSID;
- xNetworkParams.ucSSIDLength = sizeof( clientcredentialWIFI_SSID );
- xNetworkParams.pcPassword = clientcredentialWIFI_PASSWORD;
- xNetworkParams.ucPasswordLength = sizeof( clientcredentialWIFI_PASSWORD );
- xNetworkParams.xSecurity = clientcredentialWIFI_SECURITY;
- xNetworkParams.cChannel = M2M_WIFI_CH_ALL; /* Scan all channels (255) */
-
- /*Turn WiFi ON */
- if( WIFI_On() != eWiFiSuccess )
- {
- return pdFAIL;
- }
-
- /* Connect to the AP */
- if( WIFI_ConnectAP( &xNetworkParams ) != eWiFiSuccess )
- {
- return pdFAIL;
- }
-
- return pdPASS;
- }
-
-
- /*-----------------------------------------------------------*/
-
- BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxDescriptor,
- BaseType_t xReleaseAfterSend )
- {
- BaseType_t retRes = pdFALSE;
-
- if( ( pxDescriptor != 0 ) && ( pxDescriptor->pucEthernetBuffer != 0 ) && ( pxDescriptor->xDataLength != 0 ) )
- {
- /* There you go */
- if( WDRV_EXT_DataSend( pxDescriptor->xDataLength, pxDescriptor->pucEthernetBuffer ) == 0 )
- {
- retRes = pdTRUE;
- }
-
- /* The buffer has been sent so can be released. */
- if( xReleaseAfterSend != pdFALSE )
- {
- vReleaseNetworkBufferAndDescriptor( pxDescriptor );
- }
- }
-
- return retRes;
- }
-
-
- /************************************* Section: helper functions ************************************************** */
- /* */
-
-
-
- /************************************* Section: worker code ************************************************** */
- /* */
-
- void xNetworkFrameReceived( uint32_t len,
- uint8_t const * const frame )
- {
- bool pktSuccess, pktLost;
- NetworkBufferDescriptor_t * pxNetworkBuffer = NULL;
- IPStackEvent_t xRxEvent = { eNetworkRxEvent, NULL };
-
- pktSuccess = pktLost = false;
-
- while( true )
- {
- if( eConsiderFrameForProcessing( frame ) != eProcessBuffer )
- {
- break;
- }
-
- /* get the network descriptor (no data buffer) to hold this packet */
- pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( len, 0 );
-
- if( pxNetworkBuffer == NULL )
- {
- pktLost = true;
- break;
- }
-
- /* Set the actual packet length, in case a larger buffer was
- returned. */
- pxNetworkBuffer->xDataLength = len;
-
- /* Copy the packet. */
- memcpy( pxNetworkBuffer->pucEthernetBuffer, frame, len );
-
- /* Send the data to the TCP/IP stack. */
- xRxEvent.pvData = ( void * ) pxNetworkBuffer;
-
- if( xSendEventStructToIPTask( &xRxEvent, 0 ) == pdFALSE )
- { /* failed */
- pktLost = true;
- }
- else
- { /* success */
- pktSuccess = true;
- iptraceNETWORK_INTERFACE_RECEIVE();
- }
-
- break;
- }
-
- if( !pktSuccess )
- { /* smth went wrong; nothing sent to the */
- if( pxNetworkBuffer != NULL )
- {
- pxNetworkBuffer->pucEthernetBuffer = 0;
- vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
- }
-
- if( pktLost )
- {
- iptraceETHERNET_RX_EVENT_LOST();
- }
- }
- }
-
-#endif /* #ifndef PIC32_USE_ETHERNET */
+/*******************************************************************************\r
+* Network Interface file\r
+*\r
+* Summary:\r
+* Network Interface file for FreeRTOS-Plus-TCP stack\r
+*\r
+* Description:\r
+* - Interfaces PIC32 to the FreeRTOS TCP/IP stack\r
+*******************************************************************************/\r
+\r
+/*******************************************************************************\r
+* File Name: pic32_NetworkInterface.c\r
+* Copyright 2017 Microchip Technology Incorporated and its subsidiaries.\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\r
+* of the Software, and to permit persons to whom the Software is furnished to do\r
+* so, subject to the following conditions:\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,\r
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+* SOFTWARE\r
+*******************************************************************************/\r
+#ifndef PIC32_USE_ETHERNET\r
+#include <sys/kmem.h>\r
+\r
+#include "FreeRTOS.h"\r
+#include "semphr.h"\r
+#include "event_groups.h"\r
+#include "FreeRTOS_IP.h"\r
+#include "FreeRTOS_IP_Private.h"\r
+\r
+#include "NetworkInterface.h"\r
+#include "NetworkBufferManagement.h"\r
+#include "peripheral/eth/plib_eth.h"\r
+\r
+#include "system_config.h"\r
+#include "system/console/sys_console.h"\r
+#include "system/debug/sys_debug.h"\r
+#include "system/command/sys_command.h"\r
+\r
+#include "driver/ethmac/drv_ethmac.h"\r
+#include "driver/miim/drv_miim.h"\r
+#include "m2m_types.h"\r
+\r
+#include "tcpip/tcpip.h"\r
+#include "tcpip/src/tcpip_private.h"\r
+#include "tcpip/src/link_list.h"\r
+#include "wilc1000_task.h"\r
+\r
+#include "NetworkConfig.h"\r
+\r
+\r
+ #include "iot_wifi.h"\r
+\r
+ /* local definitions and data */\r
+\r
+\r
+ /* FreeRTOS implementation functions */\r
+ BaseType_t xNetworkInterfaceInitialise( void )\r
+ {\r
+ WIFINetworkParams_t xNetworkParams;\r
+\r
+ xNetworkParams.pcSSID = clientcredentialWIFI_SSID;\r
+ xNetworkParams.ucSSIDLength = sizeof( clientcredentialWIFI_SSID );\r
+ xNetworkParams.pcPassword = clientcredentialWIFI_PASSWORD;\r
+ xNetworkParams.ucPasswordLength = sizeof( clientcredentialWIFI_PASSWORD );\r
+ xNetworkParams.xSecurity = clientcredentialWIFI_SECURITY;\r
+ xNetworkParams.cChannel = M2M_WIFI_CH_ALL; /* Scan all channels (255) */\r
+\r
+ /*Turn WiFi ON */\r
+ if( WIFI_On() != eWiFiSuccess )\r
+ {\r
+ return pdFAIL;\r
+ }\r
+\r
+ /* Connect to the AP */\r
+ if( WIFI_ConnectAP( &xNetworkParams ) != eWiFiSuccess )\r
+ {\r
+ return pdFAIL;\r
+ }\r
+\r
+ return pdPASS;\r
+ }\r
+\r
+\r
+ /*-----------------------------------------------------------*/\r
+\r
+ BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxDescriptor,\r
+ BaseType_t xReleaseAfterSend )\r
+ {\r
+ BaseType_t retRes = pdFALSE;\r
+\r
+ if( ( pxDescriptor != 0 ) && ( pxDescriptor->pucEthernetBuffer != 0 ) && ( pxDescriptor->xDataLength != 0 ) )\r
+ {\r
+ /* There you go */\r
+ if( WDRV_EXT_DataSend( pxDescriptor->xDataLength, pxDescriptor->pucEthernetBuffer ) == 0 )\r
+ {\r
+ retRes = pdTRUE;\r
+ }\r
+\r
+ /* The buffer has been sent so can be released. */\r
+ if( xReleaseAfterSend != pdFALSE )\r
+ {\r
+ vReleaseNetworkBufferAndDescriptor( pxDescriptor );\r
+ }\r
+ }\r
+\r
+ return retRes;\r
+ }\r
+\r
+\r
+ /************************************* Section: helper functions ************************************************** */\r
+ /* */\r
+\r
+\r
+\r
+ /************************************* Section: worker code ************************************************** */\r
+ /* */\r
+\r
+ void xNetworkFrameReceived( uint32_t len,\r
+ uint8_t const * const frame )\r
+ {\r
+ bool pktSuccess, pktLost;\r
+ NetworkBufferDescriptor_t * pxNetworkBuffer = NULL;\r
+ IPStackEvent_t xRxEvent = { eNetworkRxEvent, NULL };\r
+\r
+ pktSuccess = pktLost = false;\r
+\r
+ while( true )\r
+ {\r
+ if( eConsiderFrameForProcessing( frame ) != eProcessBuffer )\r
+ {\r
+ break;\r
+ }\r
+\r
+ /* get the network descriptor (no data buffer) to hold this packet */\r
+ pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( len, 0 );\r
+\r
+ if( pxNetworkBuffer == NULL )\r
+ {\r
+ pktLost = true;\r
+ break;\r
+ }\r
+\r
+ /* Set the actual packet length, in case a larger buffer was \r
+ returned. */\r
+ pxNetworkBuffer->xDataLength = len;\r
+ \r
+ /* Copy the packet. */\r
+ memcpy( pxNetworkBuffer->pucEthernetBuffer, frame, len );\r
+\r
+ /* Send the data to the TCP/IP stack. */\r
+ xRxEvent.pvData = ( void * ) pxNetworkBuffer;\r
+\r
+ if( xSendEventStructToIPTask( &xRxEvent, 0 ) == pdFALSE )\r
+ { /* failed */\r
+ pktLost = true;\r
+ }\r
+ else\r
+ { /* success */\r
+ pktSuccess = true;\r
+ iptraceNETWORK_INTERFACE_RECEIVE();\r
+ }\r
+\r
+ break;\r
+ }\r
+\r
+ if( !pktSuccess )\r
+ { /* smth went wrong; nothing sent to the */\r
+ if( pxNetworkBuffer != NULL )\r
+ {\r
+ pxNetworkBuffer->pucEthernetBuffer = 0;\r
+ vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );\r
+ }\r
+\r
+ if( pktLost )\r
+ {\r
+ iptraceETHERNET_RX_EVENT_LOST();\r
+ }\r
+ }\r
+ }\r
+\r
+#endif /* #ifndef PIC32_USE_ETHERNET */\r