Skip to content

DriverSAM: let gmac_dev_read() return the proper length (version 2) #1000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions source/portable/NetworkInterface/DriverSAM/NetworkInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,9 @@ static BaseType_t prvGMACInit( NetworkInterface_t * pxInterface )
GMAC->GMAC_NCR |= GMAC_NCR_MPE;

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

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

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

Expand Down Expand Up @@ -1031,6 +1033,7 @@ static uint32_t prvEMACRxPoll( void )
if( xSendEventStructToIPTask( &xRxEvent, xBlockTime ) != pdTRUE )
{
/* xSendEventStructToIPTask() timed out. Release the descriptor. */
FreeRTOS_printf( ( "prvEMACRxPoll: Can not queue a packet!\n" ) );
xRelease = pdTRUE;
}
}
Expand All @@ -1042,7 +1045,6 @@ static uint32_t prvEMACRxPoll( void )
* again. */
vReleaseNetworkBufferAndDescriptor( pxNextNetworkBufferDescriptor );
iptraceETHERNET_RX_EVENT_LOST();
FreeRTOS_printf( ( "prvEMACRxPoll: Can not queue return packet!\n" ) );
}

/* Now the buffer has either been passed to the IP-task,
Expand Down
13 changes: 6 additions & 7 deletions source/portable/NetworkInterface/DriverSAM/gmac_SAM.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,29 +624,30 @@ uint32_t gmac_dev_read( gmac_device_t * p_gmac_dev,
return GMAC_RX_NO_DATA;
}

/* Return the number of bytes received. */
*p_rcv_size = bytesLeft;

/* gmac_dev_poll has confirmed that there is a complete frame at
* the current position 'ul_rx_idx'
*/
nextIdx = p_gmac_dev->ul_rx_idx;

/* Read +2 bytes because buffers are aligned at -2 bytes */
bytesLeft = min( bytesLeft + 2, ( int32_t ) ul_frame_size );

#if ( NETWORK_BUFFERS_CACHED != 0 ) && ( __DCACHE_PRESENT != 0 ) && defined( CONF_BOARD_ENABLE_CACHE )
SCB_InvalidateDCache();
#endif

#if ( ipconfigZERO_COPY_RX_DRIVER == 0 )
{
/* The frame will be copied in 1 or 2 memcpy's */
if( ( p_frame != NULL ) && ( bytesLeft != 0 ) )
if( p_frame != NULL )
{
const uint8_t * source;
int32_t left;
int32_t toCopy;

source = gs_uc_rx_buffer + nextIdx * GMAC_RX_UNITSIZE;
left = bytesLeft;
/* Read +2 bytes because buffers are aligned at -2 bytes */
left = min( bytesLeft + 2, ( int32_t ) ul_frame_size );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this code will normally not be executed, only when ipconfigZERO_COPY_RX_DRIVER = 1.
We leave it here for those who want to play with the copy-method.
The driver receives frames op to 1514 bytes long. The actual value of ul_frame_size is 1536, so the following test is not really necessary:

left = min( bytesLeft + 2, ( int32_t ) ul_frame_size );

toCopy = ( GMAC_RX_BUFFERS - nextIdx ) * GMAC_RX_UNITSIZE;

if( toCopy > left )
Expand Down Expand Up @@ -696,8 +697,6 @@ uint32_t gmac_dev_read( gmac_device_t * p_gmac_dev,

p_gmac_dev->ul_rx_idx = nextIdx;

*p_rcv_size = bytesLeft;

return GMAC_OK;
}

Expand Down