Skip to content

Commit 20d30d9

Browse files
authored
DriverSAM: let gmac_dev_read() return the proper length (version 2) (#1000)
* Atmel SAM driver: let gmac_dev_read() return the proper length (version 2) * Running uncrustify * A minor format change * Added a comment about a min() test
1 parent 169ae78 commit 20d30d9

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

source/portable/NetworkInterface/DriverSAM/NetworkInterface.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,10 @@ 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+
691+
/* Note that 'gmac_option.uc_copy_all_frame' is false, do not copy all frames.
692+
* And 'gmac_option.uc_no_boardcast' is false, meaning that broadcast is received.
693+
* 'boardcast' is a typo. */
692694
memcpy( gmac_option.uc_mac_addr, pxEndPoint->xMACAddress.ucBytes, sizeof( gmac_option.uc_mac_addr ) );
693695

694696
gs_gmac_dev.p_hw = GMAC;
@@ -697,7 +699,8 @@ static BaseType_t prvGMACInit( NetworkInterface_t * pxInterface )
697699
NVIC_SetPriority( GMAC_IRQn, configMAC_INTERRUPT_PRIORITY );
698700
NVIC_EnableIRQ( GMAC_IRQn );
699701

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

@@ -1031,6 +1034,7 @@ static uint32_t prvEMACRxPoll( void )
10311034
if( xSendEventStructToIPTask( &xRxEvent, xBlockTime ) != pdTRUE )
10321035
{
10331036
/* xSendEventStructToIPTask() timed out. Release the descriptor. */
1037+
FreeRTOS_printf( ( "prvEMACRxPoll: Can not queue a packet!\n" ) );
10341038
xRelease = pdTRUE;
10351039
}
10361040
}
@@ -1042,7 +1046,6 @@ static uint32_t prvEMACRxPoll( void )
10421046
* again. */
10431047
vReleaseNetworkBufferAndDescriptor( pxNextNetworkBufferDescriptor );
10441048
iptraceETHERNET_RX_EVENT_LOST();
1045-
FreeRTOS_printf( ( "prvEMACRxPoll: Can not queue return packet!\n" ) );
10461049
}
10471050

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

source/portable/NetworkInterface/DriverSAM/gmac_SAM.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -624,29 +624,36 @@ 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+
650+
/* The driver receives frames up to 1514 bytes long.
651+
* The actual value of ul_frame_size is 1536, so the
652+
* following test is not really necessary:
653+
*/
654+
655+
/* Read +2 bytes because buffers are aligned at -2 bytes */
656+
left = min( bytesLeft + 2, ( int32_t ) ul_frame_size );
650657
toCopy = ( GMAC_RX_BUFFERS - nextIdx ) * GMAC_RX_UNITSIZE;
651658

652659
if( toCopy > left )
@@ -696,8 +703,6 @@ uint32_t gmac_dev_read( gmac_device_t * p_gmac_dev,
696703

697704
p_gmac_dev->ul_rx_idx = nextIdx;
698705

699-
*p_rcv_size = bytesLeft;
700-
701706
return GMAC_OK;
702707
}
703708

0 commit comments

Comments
 (0)