Skip to content

Commit e264554

Browse files
committed
Atmel SAM driver: let gmac_dev_read() return the proper length (version 2)
1 parent 5757e07 commit e264554

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

source/portable/NetworkInterface/DriverSAM/NetworkInterface.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,9 @@ static BaseType_t prvGMACInit( NetworkInterface_t * pxInterface )
687687
GMAC->GMAC_NCR |= GMAC_NCR_MPE;
688688

689689
memset( &gmac_option, '\0', sizeof( gmac_option ) );
690-
gmac_option.uc_copy_all_frame = 0;
691-
gmac_option.uc_no_boardcast = 0;
690+
/* Note that 'gmac_option.uc_copy_all_frame' is false, do not copy all frames.
691+
* And 'gmac_option.uc_no_boardcast' is false, meaning that broadcast is received.
692+
* 'boardcast' is a typo. */
692693
memcpy( gmac_option.uc_mac_addr, pxEndPoint->xMACAddress.ucBytes, sizeof( gmac_option.uc_mac_addr ) );
693694

694695
gs_gmac_dev.p_hw = GMAC;
@@ -697,7 +698,8 @@ static BaseType_t prvGMACInit( NetworkInterface_t * pxInterface )
697698
NVIC_SetPriority( GMAC_IRQn, configMAC_INTERRUPT_PRIORITY );
698699
NVIC_EnableIRQ( GMAC_IRQn );
699700

700-
/* Clear the hash table for multicast MAC addresses. */
701+
/* Clear the hash table for multicast MAC addresses.
702+
* OR set both to ~0H to receive all multicast packets. */
701703
GMAC->GMAC_HRB = 0U; /* Hash Register Bottom. */
702704
GMAC->GMAC_HRT = 0U; /* Hash Register Top. */
703705

@@ -1031,6 +1033,7 @@ static uint32_t prvEMACRxPoll( void )
10311033
if( xSendEventStructToIPTask( &xRxEvent, xBlockTime ) != pdTRUE )
10321034
{
10331035
/* xSendEventStructToIPTask() timed out. Release the descriptor. */
1036+
FreeRTOS_printf( ( "prvEMACRxPoll: Can not queue a packet!\n" ) );
10341037
xRelease = pdTRUE;
10351038
}
10361039
}
@@ -1042,7 +1045,6 @@ static uint32_t prvEMACRxPoll( void )
10421045
* again. */
10431046
vReleaseNetworkBufferAndDescriptor( pxNextNetworkBufferDescriptor );
10441047
iptraceETHERNET_RX_EVENT_LOST();
1045-
FreeRTOS_printf( ( "prvEMACRxPoll: Can not queue return packet!\n" ) );
10461048
}
10471049

10481050
/* Now the buffer has either been passed to the IP-task,

source/portable/NetworkInterface/DriverSAM/gmac_SAM.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -624,29 +624,30 @@ uint32_t gmac_dev_read( gmac_device_t * p_gmac_dev,
624624
return GMAC_RX_NO_DATA;
625625
}
626626

627+
/* Return the number of bytes received. */
628+
*p_rcv_size = bytesLeft;
629+
627630
/* gmac_dev_poll has confirmed that there is a complete frame at
628631
* the current position 'ul_rx_idx'
629632
*/
630633
nextIdx = p_gmac_dev->ul_rx_idx;
631634

632-
/* Read +2 bytes because buffers are aligned at -2 bytes */
633-
bytesLeft = min( bytesLeft + 2, ( int32_t ) ul_frame_size );
634-
635635
#if ( NETWORK_BUFFERS_CACHED != 0 ) && ( __DCACHE_PRESENT != 0 ) && defined( CONF_BOARD_ENABLE_CACHE )
636636
SCB_InvalidateDCache();
637637
#endif
638638

639639
#if ( ipconfigZERO_COPY_RX_DRIVER == 0 )
640640
{
641641
/* The frame will be copied in 1 or 2 memcpy's */
642-
if( ( p_frame != NULL ) && ( bytesLeft != 0 ) )
642+
if( p_frame != NULL )
643643
{
644644
const uint8_t * source;
645645
int32_t left;
646646
int32_t toCopy;
647647

648648
source = gs_uc_rx_buffer + nextIdx * GMAC_RX_UNITSIZE;
649-
left = bytesLeft;
649+
/* Read +2 bytes because buffers are aligned at -2 bytes */
650+
left = min( bytesLeft + 2, ( int32_t ) ul_frame_size );
650651
toCopy = ( GMAC_RX_BUFFERS - nextIdx ) * GMAC_RX_UNITSIZE;
651652

652653
if( toCopy > left )
@@ -696,8 +697,6 @@ uint32_t gmac_dev_read( gmac_device_t * p_gmac_dev,
696697

697698
p_gmac_dev->ul_rx_idx = nextIdx;
698699

699-
*p_rcv_size = bytesLeft;
700-
701700
return GMAC_OK;
702701
}
703702

0 commit comments

Comments
 (0)