5353 **********************************************************************************************************************/
5454#define ETHER_BUFSIZE_MIN 60
5555
56- #if defined( BSP_MCU_RX65N ) || defined( BSP_MCU_RX64M ) || defined( BSP_MCU_RX71M ) || defined( BSP_MCU_RX72M )
56+ #if defined( BSP_MCU_RX65N ) || defined( BSP_MCU_RX64M ) || defined( BSP_MCU_RX71M ) || defined( BSP_MCU_RX72M ) || defined( BSP_MCU_RX72N )
5757 #if ETHER_CFG_MODE_SEL == 0
5858 #define R_ETHER_PinSet_CHANNEL_0 () R_ETHER_PinSet_ETHERC0_MII()
5959 #elif ETHER_CFG_MODE_SEL == 1
@@ -100,6 +100,9 @@ static BaseType_t xPHYLinkStatus;
100100static BaseType_t xReportedStatus ;
101101static eMAC_INIT_STATUS_TYPE xMacInitStatus = eMACInit ;
102102
103+ /* Pointer to the interface object of this NIC */
104+ static NetworkInterface_t * pxMyInterface = NULL ;
105+
103106static int16_t SendData ( uint8_t * pucBuffer ,
104107 size_t length );
105108static int InitializeNetwork ( void );
@@ -113,18 +116,57 @@ void get_random_number( uint8_t * data,
113116
114117void prvLinkStatusChange ( BaseType_t xStatus );
115118
119+ /*-----------------------------------------------------------*/
120+
121+ NetworkInterface_t * pxRX_FillInterfaceDescriptor ( BaseType_t xEMACIndex ,
122+ NetworkInterface_t * pxInterface );
123+
124+ /* Function to initialise the network interface */
125+ BaseType_t xRX_NetworkInterfaceInitialise ( NetworkInterface_t * pxInterface );
126+
127+ BaseType_t xRX_NetworkInterfaceOutput ( NetworkInterface_t * pxInterface ,
128+ NetworkBufferDescriptor_t * const pxDescriptor ,
129+ BaseType_t bReleaseAfterSend );
130+
131+ static inline BaseType_t xRX_PHYGetLinkStatus ( NetworkInterface_t * pxInterface );
132+
133+ NetworkInterface_t * pxRX_FillInterfaceDescriptor ( BaseType_t xEMACIndex ,
134+ NetworkInterface_t * pxInterface )
135+ {
136+ static char pcName [ 17 ];
137+
138+ /* This function pxRX_FillInterfaceDescriptor() adds a network-interface.
139+ * Make sure that the object pointed to by 'pxInterface'
140+ * is declared static or global, and that it will remain to exist. */
141+
142+ snprintf ( pcName , sizeof ( pcName ), "eth%u" , ( unsigned ) xEMACIndex );
143+
144+ memset ( pxInterface , '\0' , sizeof ( * pxInterface ) );
145+ pxInterface -> pcName = pcName ; /* Just for logging, debugging. */
146+ pxInterface -> pvArgument = ( void * ) xEMACIndex ; /* Has only meaning for the driver functions. */
147+ pxInterface -> pfInitialise = xRX_NetworkInterfaceInitialise ;
148+ pxInterface -> pfOutput = xRX_NetworkInterfaceOutput ;
149+ pxInterface -> pfGetPhyLinkStatus = xRX_PHYGetLinkStatus ;
150+
151+ FreeRTOS_AddNetworkInterface ( pxInterface );
152+
153+ return pxInterface ;
154+ }
155+
116156/***********************************************************************************************************************
117- * Function Name: xNetworkInterfaceInitialise ()
157+ * Function Name: xRX_NetworkInterfaceInitialise ()
118158 * Description : Initialization of Ethernet driver.
119- * Arguments : none
159+ * Arguments : Pointer to the interface desc
120160 * Return Value : pdPASS, pdFAIL
121161 **********************************************************************************************************************/
122- BaseType_t xNetworkInterfaceInitialise ( void )
162+ BaseType_t xRX_NetworkInterfaceInitialise ( NetworkInterface_t * pxInterface )
123163{
124164 BaseType_t xReturn ;
125165
126166 if ( xMacInitStatus == eMACInit )
127167 {
168+ pxMyInterface = pxInterface ;
169+
128170 /*
129171 * Perform the hardware specific network initialization here using the Ethernet driver library to initialize the
130172 * Ethernet hardware, initialize DMA descriptors, and perform a PHY auto-negotiation to obtain a network link.
@@ -160,16 +202,20 @@ BaseType_t xNetworkInterfaceInitialise( void )
160202
161203
162204/***********************************************************************************************************************
163- * Function Name: xNetworkInterfaceOutput ()
205+ * Function Name: xRX_NetworkInterfaceOutput ()
164206 * Description : Simple network output interface.
165- * Arguments : pxDescriptor, xReleaseAfterSend
207+ * Arguments : pxInterface, pxDescriptor, xReleaseAfterSend
166208 * Return Value : pdTRUE, pdFALSE
167209 **********************************************************************************************************************/
168- BaseType_t xNetworkInterfaceOutput ( NetworkBufferDescriptor_t * const pxDescriptor ,
169- BaseType_t xReleaseAfterSend )
210+ BaseType_t xRX_NetworkInterfaceOutput ( NetworkInterface_t * pxInterface ,
211+ NetworkBufferDescriptor_t * const pxDescriptor ,
212+ BaseType_t xReleaseAfterSend )
170213{
171214 BaseType_t xReturn = pdFALSE ;
172215
216+ /* As there is only a single instance of the EMAC, there is only one pxInterface object. */
217+ ( void ) pxInterface ;
218+
173219 /* Simple network interfaces (as opposed to more efficient zero copy network
174220 * interfaces) just use Ethernet peripheral driver library functions to copy
175221 * data from the FreeRTOS+TCP buffer into the peripheral driver's own buffer.
@@ -259,7 +305,7 @@ static void prvEMACDeferredInterruptHandlerTask( void * pvParameters )
259305 if ( xBytesReceived < 0 )
260306 {
261307 /* This is an error. Logged. */
262- FreeRTOS_printf ( ( "R_ETHER_Read_ZC2: rc = %d\n" , xBytesReceived ) );
308+ FreeRTOS_debug_printf ( ( "R_ETHER_Read_ZC2: rc = %d\n" , xBytesReceived ) );
263309 }
264310 else if ( xBytesReceived > 0 )
265311 {
@@ -284,14 +330,16 @@ static void prvEMACDeferredInterruptHandlerTask( void * pvParameters )
284330
285331 /* Set the actual packet length, in case a larger buffer was returned. */
286332 pxBufferDescriptor -> xDataLength = ( size_t ) xBytesReceived ;
333+ pxBufferDescriptor -> pxInterface = pxMyInterface ;
334+ pxBufferDescriptor -> pxEndPoint = FreeRTOS_MatchingEndpoint ( pxMyInterface , pxBufferDescriptor -> pucEthernetBuffer );
287335
288336 R_ETHER_Read_ZC2_BufRelease ( ETHER_CHANNEL_0 );
289337
290338 /* See if the data contained in the received Ethernet frame needs
291339 * to be processed. NOTE! It is preferable to do this in
292340 * the interrupt service routine itself, which would remove the need
293341 * to unblock this task for packets that don't need processing. */
294- if ( eConsiderFrameForProcessing ( pxBufferDescriptor -> pucEthernetBuffer ) == eProcessBuffer )
342+ if ( ( eConsiderFrameForProcessing ( pxBufferDescriptor -> pucEthernetBuffer ) == eProcessBuffer ) && ( pxBufferDescriptor -> pxEndPoint != NULL ) )
295343 {
296344 /* The event about to be sent to the TCP/IP is an Rx event. */
297345 xRxEvent .eEventType = eNetworkRxEvent ;
@@ -380,26 +428,34 @@ static void prvEMACDeferredInterruptHandlerTask( void * pvParameters )
380428 * Arguments : pxNetworkBuffers
381429 * Return Value : none
382430 **********************************************************************************************************************/
431+
383432void vNetworkInterfaceAllocateRAMToBuffers ( NetworkBufferDescriptor_t pxNetworkBuffers [ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] )
384433{
385434 uint32_t ul ;
386435 uint8_t * buffer_address ;
436+ portPOINTER_SIZE_TYPE uxStartAddress ;
387437
388- R_BSP_SECTION_OPERATORS_INIT ( B_ETHERNET_BUFFERS_1 )
438+ static uint8_t ETH_BUFFERS [ ( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * ETHER_CFG_BUFSIZE ) + portBYTE_ALIGNMENT ];
389439
390- buffer_address = R_BSP_SECTOP ( B_ETHERNET_BUFFERS_1 );
440+ /* Align the buffer start address to portBYTE_ALIGNMENT bytes */
441+ uxStartAddress = ( portPOINTER_SIZE_TYPE ) & ETH_BUFFERS [ 0 ];
442+ uxStartAddress += portBYTE_ALIGNMENT ;
443+ uxStartAddress &= ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK );
444+
445+ buffer_address = ( uint8_t * ) uxStartAddress ;
391446
392447 for ( ul = 0 ; ul < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ; ul ++ )
393448 {
394- pxNetworkBuffers [ ul ].pucEthernetBuffer = ( buffer_address + ( ETHER_CFG_BUFSIZE * ul ) );
449+ pxNetworkBuffers [ ul ].pucEthernetBuffer = buffer_address + ipBUFFER_PADDING ;
450+ * ( ( unsigned * ) buffer_address ) = ( unsigned ) ( & ( pxNetworkBuffers [ ul ] ) );
451+ buffer_address += ETHER_CFG_BUFSIZE ;
395452 }
396453} /* End of function vNetworkInterfaceAllocateRAMToBuffers() */
397454
398-
399455/***********************************************************************************************************************
400456 * Function Name: prvLinkStatusChange ()
401457 * Description : Function will be called when the Link Status of the phy has changed ( see ether_callback.c )
402- * Arguments : xStatus : true when statyus has become high
458+ * Arguments : xStatus : true when status has become high
403459 * Return Value : void
404460 **********************************************************************************************************************/
405461void prvLinkStatusChange ( BaseType_t xStatus )
@@ -427,7 +483,8 @@ static int InitializeNetwork( void )
427483 * as the mac address is usually read from the EEPROM, and it might be different to the mac address in
428484 * the defines, especially in production environments
429485 */
430- const uint8_t * myethaddr = FreeRTOS_GetMACAddress ();
486+ configASSERT ( pxMyInterface );
487+ const uint8_t * myethaddr = & pxMyInterface -> pxEndPoint -> xMACAddress .ucBytes [ 0 ];
431488
432489 R_ETHER_PinSet_CHANNEL_0 ();
433490 R_ETHER_Initial ();
@@ -575,6 +632,13 @@ static void clear_all_ether_rx_discriptors( uint32_t event )
575632 }
576633}
577634
635+ static inline BaseType_t xRX_PHYGetLinkStatus ( NetworkInterface_t * pxInterface )
636+ {
637+ ( void ) pxInterface ;
638+ return ( xPHYLinkStatus != 0 );
639+ }
640+
641+
578642/***********************************************************************************************************************
579643 * End of file "NetworkInterface.c"
580644 **********************************************************************************************************************/
0 commit comments