mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-19 21:11:57 -04:00
Update MAC drivers so they use a uIP specific zero copy mechanism.
This commit is contained in:
parent
5fbf3ab27e
commit
c1d000b654
|
@ -9,9 +9,14 @@
|
||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NOTE: This driver has been roughly modified specifically for use with the
|
||||||
|
* uIP stack. It is no longer a generic driver.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
|
@ -54,11 +59,11 @@ extern "C" {
|
||||||
/* Allocating this many buffers will always ensure there is one free as, even
|
/* Allocating this many buffers will always ensure there is one free as, even
|
||||||
though TX_RING_SIZE is set to two, the two Tx descriptors will only ever point
|
though TX_RING_SIZE is set to two, the two Tx descriptors will only ever point
|
||||||
to the same buffer. */
|
to the same buffer. */
|
||||||
#define macNUM_BUFFERS RX_RING_SIZE + TX_RING_SIZE + 1
|
#define macNUM_BUFFERS RX_RING_SIZE + TX_RING_SIZE + 2
|
||||||
#define macBUFFER_SIZE 1488
|
#define macBUFFER_SIZE 1488
|
||||||
|
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
MAC_instance_t g_mss_mac __attribute__((aligned(4)));
|
MAC_instance_t g_mss_mac;
|
||||||
|
|
||||||
/**************************** INTERNAL DATA ***********************************/
|
/**************************** INTERNAL DATA ***********************************/
|
||||||
#define ERROR_MESSAGE_COUNT 8
|
#define ERROR_MESSAGE_COUNT 8
|
||||||
|
@ -78,15 +83,16 @@ static const int8_t ErrorMessages[][MAX_ERROR_MESSAGE_WIDTH] = {
|
||||||
/*
|
/*
|
||||||
* Null variables
|
* Null variables
|
||||||
*/
|
*/
|
||||||
static MAC_instance_t* NULL_instance;
|
|
||||||
static uint8_t* NULL_buffer;
|
static uint8_t* NULL_buffer;
|
||||||
static MSS_MAC_callback_t NULL_callback;
|
static MSS_MAC_callback_t NULL_callback;
|
||||||
|
|
||||||
|
/* Declare the uip_buf as a pointer, rather than the traditional array, as this
|
||||||
|
is a zero copy driver. uip_buf just gets set to whichever buffer is being
|
||||||
|
processed. */
|
||||||
unsigned char *uip_buf = NULL;
|
unsigned char *uip_buf = NULL;
|
||||||
|
|
||||||
/**************************** INTERNAL FUNCTIONS ******************************/
|
/**************************** INTERNAL FUNCTIONS ******************************/
|
||||||
|
|
||||||
static int32_t MAC_test_instance( void );
|
|
||||||
|
|
||||||
static int32_t MAC_dismiss_bad_frames( void );
|
static int32_t MAC_dismiss_bad_frames( void );
|
||||||
static int32_t MAC_send_setup_frame( void );
|
static int32_t MAC_send_setup_frame( void );
|
||||||
|
|
||||||
|
@ -109,11 +115,16 @@ static void MAC_release_buffer( unsigned char *pcBufferToRelease );
|
||||||
#error This uIP Ethernet driver required TX_RING_SIZE to be set to 2
|
#error This uIP Ethernet driver required TX_RING_SIZE to be set to 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Buffers that will dynamically be allocated to/from the Tx and Rx descriptors. */
|
/* Buffers that will dynamically be allocated to/from the Tx and Rx descriptors.
|
||||||
static unsigned char ucMACBuffers[ macNUM_BUFFERS ][ macBUFFER_SIZE ] __attribute__((aligned(4)));
|
The union is used for alignment only. */
|
||||||
|
static union xMAC_BUFFERS
|
||||||
|
{
|
||||||
|
unsigned long ulAlignmentVariable; /* For alignment only, not used anywhere. */
|
||||||
|
unsigned char ucBuffer[ macNUM_BUFFERS ][ macBUFFER_SIZE ];
|
||||||
|
} xMACBuffers;
|
||||||
|
|
||||||
/* Each array position indicated whether or not the buffer of the same index
|
/* Each array position indicates whether or not the buffer of the same index
|
||||||
is currently allocated to a descriptor (pdFALSE) or is free for use (pdTRUE). */
|
is currently allocated to a descriptor (pdTRUE) or is free for use (pdFALSE). */
|
||||||
static unsigned char ucMACBufferInUse[ macNUM_BUFFERS ] = { 0 };
|
static unsigned char ucMACBufferInUse[ macNUM_BUFFERS ] = { 0 };
|
||||||
|
|
||||||
/***************************************************************************//**
|
/***************************************************************************//**
|
||||||
|
@ -169,7 +180,7 @@ MSS_MAC_init
|
||||||
|
|
||||||
/* Allocate a buffer to the descriptor, then mark the buffer as in use
|
/* Allocate a buffer to the descriptor, then mark the buffer as in use
|
||||||
(not free). */
|
(not free). */
|
||||||
g_mss_mac.rx_descriptors[a].buffer_1 = ( unsigned long ) &( ucMACBuffers[ a ][ 0 ] );
|
g_mss_mac.rx_descriptors[a].buffer_1 = ( unsigned long ) &( xMACBuffers.ucBuffer[ a ][ 0 ] );
|
||||||
ucMACBufferInUse[ a ] = pdTRUE;
|
ucMACBufferInUse[ a ] = pdTRUE;
|
||||||
}
|
}
|
||||||
g_mss_mac.rx_descriptors[RX_RING_SIZE-1].descriptor_1 |= RDES1_RER;
|
g_mss_mac.rx_descriptors[RX_RING_SIZE-1].descriptor_1 |= RDES1_RER;
|
||||||
|
@ -189,8 +200,6 @@ MSS_MAC_init
|
||||||
MAC_BITBAND->CSR0_BAR = (uint32_t)BUS_ARBITRATION_SCHEME;
|
MAC_BITBAND->CSR0_BAR = (uint32_t)BUS_ARBITRATION_SCHEME;
|
||||||
|
|
||||||
/* Fixed settings */
|
/* Fixed settings */
|
||||||
/* No automatic polling */
|
|
||||||
MAC->CSR0 = MAC->CSR0 &~ CSR0_TAP_MASK;
|
|
||||||
/* No space between descriptors */
|
/* No space between descriptors */
|
||||||
MAC->CSR0 = MAC->CSR0 &~ CSR0_DSL_MASK;
|
MAC->CSR0 = MAC->CSR0 &~ CSR0_DSL_MASK;
|
||||||
/* General-purpose timer works in continuous mode */
|
/* General-purpose timer works in continuous mode */
|
||||||
|
@ -198,19 +207,25 @@ MSS_MAC_init
|
||||||
/* Start general-purpose */
|
/* Start general-purpose */
|
||||||
MAC->CSR11 = (MAC->CSR11 & ~CSR11_TIM_MASK) | (0x0000FFFFuL << CSR11_TIM_SHIFT);
|
MAC->CSR11 = (MAC->CSR11 & ~CSR11_TIM_MASK) | (0x0000FFFFuL << CSR11_TIM_SHIFT);
|
||||||
|
|
||||||
/* Disable promiscuous mode */
|
/* Disable transmit interrupt mitigation. */
|
||||||
MAC_BITBAND->CSR6_PR = 0u;
|
MAC->CSR11 = ( MAC->CSR11 & ~CSR11_TT_MASK );
|
||||||
|
MAC->CSR11 = ( MAC->CSR11 & ~CSR11_NTP_MASK );
|
||||||
/* Enable store and forward */
|
|
||||||
MAC_BITBAND->CSR6_SF = 1u;
|
|
||||||
|
|
||||||
|
/* Automatic Tx descriptor polling. */
|
||||||
|
MAC->CSR0 = ( MAC->CSR0 & ~CSR0_TAP_MASK );
|
||||||
|
MAC->CSR0 = ( MAC->CSR0 | ( 0x01 << CSR0_TAP_SHIFT ) );
|
||||||
|
|
||||||
/* Set descriptors */
|
/* Set descriptors */
|
||||||
MAC->CSR3 = (uint32_t)&(g_mss_mac.rx_descriptors[0].descriptor_0);
|
MAC->CSR3 = (uint32_t)&(g_mss_mac.rx_descriptors[0].descriptor_0);
|
||||||
MAC->CSR4 = (uint32_t)&(g_mss_mac.tx_descriptors[0].descriptor_0);
|
MAC->CSR4 = (uint32_t)&(g_mss_mac.tx_descriptors[0].descriptor_0);
|
||||||
|
|
||||||
/* enable normal interrupts */
|
/* enable normal interrupts */
|
||||||
MAC_BITBAND->CSR7_NIE = 1u;
|
MAC_BITBAND->CSR7_NIE = 1u;
|
||||||
|
|
||||||
|
/* Set default MAC address and reset mac filters */
|
||||||
|
MAC_memcpy( g_mss_mac.mac_address, mac_address, 6u );
|
||||||
|
MSS_MAC_set_mac_address((uint8_t *)mac_address);
|
||||||
|
|
||||||
/* Detect PHY */
|
/* Detect PHY */
|
||||||
if( g_mss_mac.phy_address > MSS_PHY_ADDRESS_MAX )
|
if( g_mss_mac.phy_address > MSS_PHY_ADDRESS_MAX )
|
||||||
{
|
{
|
||||||
|
@ -221,21 +236,11 @@ MSS_MAC_init
|
||||||
/* Reset PHY */
|
/* Reset PHY */
|
||||||
PHY_reset();
|
PHY_reset();
|
||||||
|
|
||||||
/* Set flags */
|
|
||||||
g_mss_mac.flags = FLAG_MAC_INIT_DONE | FLAG_PERFECT_FILTERING;
|
|
||||||
|
|
||||||
/* Configure chip according to PHY status */
|
/* Configure chip according to PHY status */
|
||||||
MSS_MAC_auto_setup_link();
|
MSS_MAC_auto_setup_link();
|
||||||
|
|
||||||
/* Set default MAC address and reset mac filters */
|
|
||||||
MAC_memcpy( g_mss_mac.mac_address, mac_address, 6u );
|
|
||||||
MSS_MAC_set_mac_filters( 0u, NULL_buffer );
|
|
||||||
MAC_BITBAND->CSR6_RA = 1; /* Receive all. */
|
|
||||||
MAC_BITBAND->CSR6_PR = 1; /* Promiscuous mode. */
|
|
||||||
MSS_MAC_set_mac_address((uint8_t *)mac_address);
|
|
||||||
|
|
||||||
/* Ensure uip_buf starts by pointing somewhere. */
|
/* Ensure uip_buf starts by pointing somewhere. */
|
||||||
uip_buf = MAC_obtain_buffer();
|
uip_buf = MAC_obtain_buffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -264,8 +269,6 @@ MSS_MAC_configure
|
||||||
{
|
{
|
||||||
int32_t ret;
|
int32_t ret;
|
||||||
|
|
||||||
configASSERT( MAC_test_instance() == MAC_OK );
|
|
||||||
|
|
||||||
ret = MAC_stop_transmission();
|
ret = MAC_stop_transmission();
|
||||||
configASSERT( ret == MAC_OK );
|
configASSERT( ret == MAC_OK );
|
||||||
|
|
||||||
|
@ -275,7 +278,7 @@ MSS_MAC_configure
|
||||||
MAC_BITBAND->CSR6_RA = (uint32_t)(((configuration & MSS_MAC_CFG_RECEIVE_ALL) != 0u) ? 1u : 0u );
|
MAC_BITBAND->CSR6_RA = (uint32_t)(((configuration & MSS_MAC_CFG_RECEIVE_ALL) != 0u) ? 1u : 0u );
|
||||||
MAC_BITBAND->CSR6_TTM = (((configuration & MSS_MAC_CFG_TRANSMIT_THRESHOLD_MODE) != 0u) ? 1u : 0u );
|
MAC_BITBAND->CSR6_TTM = (((configuration & MSS_MAC_CFG_TRANSMIT_THRESHOLD_MODE) != 0u) ? 1u : 0u );
|
||||||
MAC_BITBAND->CSR6_SF = (uint32_t)(((configuration & MSS_MAC_CFG_STORE_AND_FORWARD) != 0u) ? 1u : 0u );
|
MAC_BITBAND->CSR6_SF = (uint32_t)(((configuration & MSS_MAC_CFG_STORE_AND_FORWARD) != 0u) ? 1u : 0u );
|
||||||
|
|
||||||
switch( configuration & MSS_MAC_CFG_THRESHOLD_CONTROL_11 ) {
|
switch( configuration & MSS_MAC_CFG_THRESHOLD_CONTROL_11 ) {
|
||||||
case MSS_MAC_CFG_THRESHOLD_CONTROL_00:
|
case MSS_MAC_CFG_THRESHOLD_CONTROL_00:
|
||||||
MAC->CSR6 = MAC->CSR6 & ~CSR6_TR_MASK;
|
MAC->CSR6 = MAC->CSR6 & ~CSR6_TR_MASK;
|
||||||
|
@ -327,8 +330,6 @@ MSS_MAC_get_configuration( void )
|
||||||
{
|
{
|
||||||
uint32_t configuration;
|
uint32_t configuration;
|
||||||
|
|
||||||
configASSERT( MAC_test_instance() == MAC_OK );
|
|
||||||
|
|
||||||
configuration = 0u;
|
configuration = 0u;
|
||||||
if( MAC_BITBAND->CSR6_RA != 0u ) {
|
if( MAC_BITBAND->CSR6_RA != 0u ) {
|
||||||
configuration |= MSS_MAC_CFG_RECEIVE_ALL;
|
configuration |= MSS_MAC_CFG_RECEIVE_ALL;
|
||||||
|
@ -375,7 +376,7 @@ MSS_MAC_get_configuration( void )
|
||||||
if( MAC_BITBAND->CSR6_HP != 0u ) {
|
if( MAC_BITBAND->CSR6_HP != 0u ) {
|
||||||
configuration |= MSS_MAC_CFG_HASH_PERFECT_RECEIVE_FILTERING_MODE;
|
configuration |= MSS_MAC_CFG_HASH_PERFECT_RECEIVE_FILTERING_MODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int32_t)configuration;
|
return (int32_t)configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,11 +388,11 @@ MSS_MAC_get_configuration( void )
|
||||||
the transmit FIFO and then activates the transmitter for this packet. If space
|
the transmit FIFO and then activates the transmitter for this packet. If space
|
||||||
is available in the FIFO, the function will return once pac_len bytes of the
|
is available in the FIFO, the function will return once pac_len bytes of the
|
||||||
packet have been placed into the FIFO and the transmitter has been started.
|
packet have been placed into the FIFO and the transmitter has been started.
|
||||||
This function will not wait for the transmission to complete.
|
This function will not wait for the transmission to complete.
|
||||||
|
|
||||||
@return
|
@return
|
||||||
The function returns zero if a timeout occurs otherwise it returns size of the packet.
|
The function returns zero if a timeout occurs otherwise it returns size of the packet.
|
||||||
|
|
||||||
@see MAC_rx_packet()
|
@see MAC_rx_packet()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -404,9 +405,6 @@ MSS_MAC_tx_packet
|
||||||
uint32_t desc;
|
uint32_t desc;
|
||||||
unsigned long ulDescriptor;
|
unsigned long ulDescriptor;
|
||||||
int32_t error = MAC_OK;
|
int32_t error = MAC_OK;
|
||||||
extern unsigned char *uip_buf;
|
|
||||||
|
|
||||||
configASSERT( MAC_test_instance() == MAC_OK );
|
|
||||||
|
|
||||||
configASSERT( uip_buf != NULL_buffer );
|
configASSERT( uip_buf != NULL_buffer );
|
||||||
|
|
||||||
|
@ -419,28 +417,34 @@ MSS_MAC_tx_packet
|
||||||
|
|
||||||
/* Check if second descriptor is free, if it is then the first must
|
/* Check if second descriptor is free, if it is then the first must
|
||||||
also be free. */
|
also be free. */
|
||||||
if(((g_mss_mac.tx_descriptors[ 1 ].descriptor_0) & TDES0_OWN) == TDES0_OWN )
|
if( ( ( (g_mss_mac.tx_descriptors[ 0 ].descriptor_0) & TDES0_OWN) == TDES0_OWN ) || ( ( (g_mss_mac.tx_descriptors[ 1 ].descriptor_0) & TDES0_OWN) == TDES0_OWN ) )
|
||||||
{
|
{
|
||||||
error = MAC_BUFFER_IS_FULL;
|
error = MAC_BUFFER_IS_FULL;
|
||||||
|
|
||||||
|
/* Check the buffers pointed to by the Tx descriptors, just in case a Tx
|
||||||
|
interrupt has been missed and a free buffer remains marked as in use. */
|
||||||
|
MSS_MAC_CheckTxBufferStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if( error == MAC_OK )
|
if( error == MAC_OK )
|
||||||
{
|
{
|
||||||
/* Assumed TX_RING_SIZE == 2. */
|
/* Assumed TX_RING_SIZE == 2. A #error directive checks this is the
|
||||||
|
case. */
|
||||||
for( ulDescriptor = 0; ulDescriptor < TX_RING_SIZE; ulDescriptor++ )
|
for( ulDescriptor = 0; ulDescriptor < TX_RING_SIZE; ulDescriptor++ )
|
||||||
{
|
{
|
||||||
g_mss_mac.tx_descriptors[ ulDescriptor ].descriptor_1 = 0u;
|
g_mss_mac.tx_descriptors[ g_mss_mac.tx_desc_index ].descriptor_1 = 0u;
|
||||||
|
|
||||||
if( (g_mss_mac.flags & FLAG_CRC_DISABLE) != 0u ) {
|
if( (g_mss_mac.flags & FLAG_CRC_DISABLE) != 0u ) {
|
||||||
g_mss_mac.tx_descriptors[ ulDescriptor ].descriptor_1 |= TDES1_AC;
|
g_mss_mac.tx_descriptors[ g_mss_mac.tx_desc_index ].descriptor_1 |= TDES1_AC;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Every buffer can hold a full frame so they are always first and last
|
/* Every buffer can hold a full frame so they are always first and last
|
||||||
descriptor */
|
descriptor */
|
||||||
g_mss_mac.tx_descriptors[ ulDescriptor ].descriptor_1 |= TDES1_LS | TDES1_FS | TDES1_IC;
|
g_mss_mac.tx_descriptors[ g_mss_mac.tx_desc_index ].descriptor_1 |= TDES1_LS | TDES1_FS | TDES1_IC;
|
||||||
|
|
||||||
/* set data size */
|
/* set data size */
|
||||||
g_mss_mac.tx_descriptors[ ulDescriptor ].descriptor_1 |= usLength;
|
g_mss_mac.tx_descriptors[ g_mss_mac.tx_desc_index ].descriptor_1 |= usLength;
|
||||||
|
|
||||||
/* reset end of ring */
|
/* reset end of ring */
|
||||||
g_mss_mac.tx_descriptors[TX_RING_SIZE-1].descriptor_1 |= TDES1_TER;
|
g_mss_mac.tx_descriptors[TX_RING_SIZE-1].descriptor_1 |= TDES1_TER;
|
||||||
|
@ -451,10 +455,10 @@ MSS_MAC_tx_packet
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The data buffer is assigned to the Tx descriptor. */
|
/* The data buffer is assigned to the Tx descriptor. */
|
||||||
g_mss_mac.tx_descriptors[ ulDescriptor ].buffer_1 = ( unsigned long ) uip_buf;
|
g_mss_mac.tx_descriptors[ g_mss_mac.tx_desc_index ].buffer_1 = ( unsigned long ) uip_buf;
|
||||||
|
|
||||||
/* update counters */
|
/* update counters */
|
||||||
desc = g_mss_mac.tx_descriptors[ ulDescriptor ].descriptor_0;
|
desc = g_mss_mac.tx_descriptors[ g_mss_mac.tx_desc_index ].descriptor_0;
|
||||||
if( (desc & TDES0_LO) != 0u ) {
|
if( (desc & TDES0_LO) != 0u ) {
|
||||||
g_mss_mac.statistics.tx_loss_of_carrier++;
|
g_mss_mac.statistics.tx_loss_of_carrier++;
|
||||||
}
|
}
|
||||||
|
@ -474,25 +478,22 @@ MSS_MAC_tx_packet
|
||||||
(desc >> TDES0_CC_OFFSET) & TDES0_CC_MASK;
|
(desc >> TDES0_CC_OFFSET) & TDES0_CC_MASK;
|
||||||
|
|
||||||
/* Give ownership of descriptor to the MAC */
|
/* Give ownership of descriptor to the MAC */
|
||||||
g_mss_mac.tx_descriptors[ ulDescriptor ].descriptor_0 = RDES0_OWN;
|
g_mss_mac.tx_descriptors[ g_mss_mac.tx_desc_index ].descriptor_0 = RDES0_OWN;
|
||||||
}
|
|
||||||
|
g_mss_mac.tx_desc_index = (g_mss_mac.tx_desc_index + 1u) % (uint32_t)TX_RING_SIZE;
|
||||||
/* Start transmission */
|
|
||||||
MAC_start_transmission();
|
MAC_start_transmission();
|
||||||
g_mss_mac.tx_desc_index = 0;
|
MAC->CSR1 = 1u;
|
||||||
/* transmit poll demand */
|
}
|
||||||
MAC->CSR1 = 1u;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (error == MAC_OK)
|
if (error == MAC_OK)
|
||||||
{
|
{
|
||||||
/* The buffer uip_buf was pointing to is now under the control of the
|
|
||||||
MAC (it is being transmitted). Set uip_buf to point to a free buffer. */
|
|
||||||
uip_buf = MAC_obtain_buffer();
|
|
||||||
error = (int32_t)usLength;
|
error = (int32_t)usLength;
|
||||||
|
|
||||||
|
/* The buffer pointed to by uip_buf is now assigned to a Tx descriptor.
|
||||||
|
Find anothere free buffer for uip_buf. */
|
||||||
|
uip_buf = MAC_obtain_buffer();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -517,8 +518,6 @@ MSS_MAC_rx_pckt_size
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int32_t retval;
|
int32_t retval;
|
||||||
configASSERT( MAC_test_instance() == MAC_OK );
|
|
||||||
|
|
||||||
MAC_dismiss_bad_frames();
|
MAC_dismiss_bad_frames();
|
||||||
|
|
||||||
if( (g_mss_mac.rx_descriptors[ g_mss_mac.rx_desc_index ].descriptor_0 & RDES0_OWN) != 0u )
|
if( (g_mss_mac.rx_descriptors[ g_mss_mac.rx_desc_index ].descriptor_0 & RDES0_OWN) != 0u )
|
||||||
|
@ -540,7 +539,7 @@ MSS_MAC_rx_pckt_size
|
||||||
* Receives a packet from the Ethernet Controller into the uIP stack.
|
* Receives a packet from the Ethernet Controller into the uIP stack.
|
||||||
* This function reads a packet from the receive FIFO of the controller and
|
* This function reads a packet from the receive FIFO of the controller and
|
||||||
* places it into uip_buf.
|
* places it into uip_buf.
|
||||||
|
|
||||||
* @return Size of packet if packet fits in uip_buf.
|
* @return Size of packet if packet fits in uip_buf.
|
||||||
* 0 if there is no received packet.
|
* 0 if there is no received packet.
|
||||||
* @see MAC_rx_pckt_size()
|
* @see MAC_rx_pckt_size()
|
||||||
|
@ -554,8 +553,6 @@ MSS_MAC_rx_packet
|
||||||
{
|
{
|
||||||
uint16_t frame_length=0u;
|
uint16_t frame_length=0u;
|
||||||
|
|
||||||
configASSERT( MAC_test_instance() == MAC_OK );
|
|
||||||
|
|
||||||
MAC_dismiss_bad_frames();
|
MAC_dismiss_bad_frames();
|
||||||
|
|
||||||
if( (g_mss_mac.rx_descriptors[ g_mss_mac.rx_desc_index ].descriptor_0 & RDES0_OWN) == 0u )
|
if( (g_mss_mac.rx_descriptors[ g_mss_mac.rx_desc_index ].descriptor_0 & RDES0_OWN) == 0u )
|
||||||
|
@ -570,7 +567,7 @@ MSS_MAC_rx_packet
|
||||||
if( frame_length > macBUFFER_SIZE ) {
|
if( frame_length > macBUFFER_SIZE ) {
|
||||||
return MAC_NOT_ENOUGH_SPACE;
|
return MAC_NOT_ENOUGH_SPACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* uip_buf is about to point to the buffer that contains the received
|
/* uip_buf is about to point to the buffer that contains the received
|
||||||
data, mark the buffer that uip_buf is currently pointing to as free
|
data, mark the buffer that uip_buf is currently pointing to as free
|
||||||
again. */
|
again. */
|
||||||
|
@ -590,7 +587,7 @@ MSS_MAC_rx_packet
|
||||||
/***************************************************************************//**
|
/***************************************************************************//**
|
||||||
* Receives a packet from the Ethernet Controller.
|
* Receives a packet from the Ethernet Controller.
|
||||||
* This function reads a packet from the receive FIFO of the controller and
|
* This function reads a packet from the receive FIFO of the controller and
|
||||||
* sets the address of pacData to the received data.
|
* sets the address of pacData to the received data.
|
||||||
* If time_out parameter is zero the function will return
|
* If time_out parameter is zero the function will return
|
||||||
* immediately (after the copy operation if data is available. Otherwise the function
|
* immediately (after the copy operation if data is available. Otherwise the function
|
||||||
* will keep trying to read till time_out expires or data is read, if MSS_MAC_BLOCKING
|
* will keep trying to read till time_out expires or data is read, if MSS_MAC_BLOCKING
|
||||||
|
@ -619,8 +616,6 @@ MSS_MAC_rx_packet_ptrset
|
||||||
uint16_t frame_length = 0u;
|
uint16_t frame_length = 0u;
|
||||||
int8_t exit = 0;
|
int8_t exit = 0;
|
||||||
|
|
||||||
configASSERT( MAC_test_instance() == MAC_OK );
|
|
||||||
|
|
||||||
configASSERT( (time_out == MSS_MAC_BLOCKING) ||
|
configASSERT( (time_out == MSS_MAC_BLOCKING) ||
|
||||||
(time_out == MSS_MAC_NONBLOCKING) ||
|
(time_out == MSS_MAC_NONBLOCKING) ||
|
||||||
((time_out >= 1) && (time_out <= 0x01000000UL)) );
|
((time_out >= 1) && (time_out <= 0x01000000UL)) );
|
||||||
|
@ -658,11 +653,11 @@ MSS_MAC_rx_packet_ptrset
|
||||||
|
|
||||||
/* Here we are setting the buffer 'pacData' address to the address
|
/* Here we are setting the buffer 'pacData' address to the address
|
||||||
RX descriptor address. After this is called, the following function
|
RX descriptor address. After this is called, the following function
|
||||||
must be called 'MAC_prepare_rx_descriptor'
|
must be called 'MAC_prepare_rx_descriptor'
|
||||||
to prepare the current rx descriptor for receiving the next packet.
|
to prepare the current rx descriptor for receiving the next packet.
|
||||||
*/
|
*/
|
||||||
*pacData = (uint8_t *)g_mss_mac.rx_descriptors[ g_mss_mac.rx_desc_index ].buffer_1 ;
|
*pacData = (uint8_t *)g_mss_mac.rx_descriptors[ g_mss_mac.rx_desc_index ].buffer_1 ;
|
||||||
|
|
||||||
}
|
}
|
||||||
return ((int32_t)frame_length);
|
return ((int32_t)frame_length);
|
||||||
}
|
}
|
||||||
|
@ -684,8 +679,6 @@ MSS_MAC_link_status
|
||||||
{
|
{
|
||||||
uint32_t link;
|
uint32_t link;
|
||||||
|
|
||||||
configASSERT( MAC_test_instance() == MAC_OK );
|
|
||||||
|
|
||||||
link = PHY_link_status();
|
link = PHY_link_status();
|
||||||
if( link == MSS_MAC_LINK_STATUS_LINK ) {
|
if( link == MSS_MAC_LINK_STATUS_LINK ) {
|
||||||
link |= PHY_link_type();
|
link |= PHY_link_type();
|
||||||
|
@ -711,7 +704,6 @@ MSS_MAC_auto_setup_link
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int32_t link;
|
int32_t link;
|
||||||
configASSERT( MAC_test_instance() == MAC_OK );
|
|
||||||
|
|
||||||
PHY_auto_negotiate();
|
PHY_auto_negotiate();
|
||||||
|
|
||||||
|
@ -746,7 +738,6 @@ MSS_MAC_set_mac_address
|
||||||
const uint8_t *new_address
|
const uint8_t *new_address
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
configASSERT( MAC_test_instance() == MAC_OK );
|
|
||||||
/* Check if the new address is unicast */
|
/* Check if the new address is unicast */
|
||||||
configASSERT( (new_address[0]&1) == 0 );
|
configASSERT( (new_address[0]&1) == 0 );
|
||||||
|
|
||||||
|
@ -782,8 +773,6 @@ MSS_MAC_get_mac_address
|
||||||
uint8_t *address
|
uint8_t *address
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
configASSERT( MAC_test_instance() == MAC_OK );
|
|
||||||
|
|
||||||
MAC_memcpy( address, g_mss_mac.mac_address, 6u );
|
MAC_memcpy( address, g_mss_mac.mac_address, 6u );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -801,7 +790,6 @@ MSS_MAC_set_mac_filters
|
||||||
const uint8_t *filters
|
const uint8_t *filters
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
configASSERT( MAC_test_instance() == MAC_OK );
|
|
||||||
configASSERT( (filter_count==0) || (filters != NULL_buffer) );
|
configASSERT( (filter_count==0) || (filters != NULL_buffer) );
|
||||||
/* Check if the mac addresses is multicast */
|
/* Check if the mac addresses is multicast */
|
||||||
{
|
{
|
||||||
|
@ -857,8 +845,6 @@ void EthernetMAC_IRQHandler( void )
|
||||||
uint32_t events;
|
uint32_t events;
|
||||||
uint32_t intr_status;
|
uint32_t intr_status;
|
||||||
|
|
||||||
configASSERT( MAC_test_instance() == MAC_OK );
|
|
||||||
|
|
||||||
events = 0u;
|
events = 0u;
|
||||||
intr_status = MAC->CSR5;
|
intr_status = MAC->CSR5;
|
||||||
|
|
||||||
|
@ -876,7 +862,7 @@ void EthernetMAC_IRQHandler( void )
|
||||||
|
|
||||||
/* Clear interrupts */
|
/* Clear interrupts */
|
||||||
MAC->CSR5 = CSR5_INT_BITS;
|
MAC->CSR5 = CSR5_INT_BITS;
|
||||||
|
|
||||||
if( (events != 0u) && (g_mss_mac.listener != NULL_callback) ) {
|
if( (events != 0u) && (g_mss_mac.listener != NULL_callback) ) {
|
||||||
g_mss_mac.listener( events );
|
g_mss_mac.listener( events );
|
||||||
}
|
}
|
||||||
|
@ -901,12 +887,10 @@ MSS_MAC_set_callback
|
||||||
MSS_MAC_callback_t listener
|
MSS_MAC_callback_t listener
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
configASSERT( MAC_test_instance() == MAC_OK );
|
|
||||||
|
|
||||||
/* disable tx and rx interrupts */
|
/* disable tx and rx interrupts */
|
||||||
MAC_BITBAND->CSR7_RIE = 0u;
|
MAC_BITBAND->CSR7_RIE = 0u;
|
||||||
MAC_BITBAND->CSR7_TIE = 0u;
|
MAC_BITBAND->CSR7_TIE = 0u;
|
||||||
|
|
||||||
g_mss_mac.listener = listener;
|
g_mss_mac.listener = listener;
|
||||||
|
|
||||||
if( listener != NULL_callback ) {
|
if( listener != NULL_callback ) {
|
||||||
|
@ -934,8 +918,6 @@ MSS_MAC_last_error
|
||||||
{
|
{
|
||||||
int8_t error_msg_nb;
|
int8_t error_msg_nb;
|
||||||
const int8_t* returnvalue;
|
const int8_t* returnvalue;
|
||||||
|
|
||||||
configASSERT( MAC_test_instance() == MAC_OK );
|
|
||||||
|
|
||||||
error_msg_nb = -(g_mss_mac.last_error);
|
error_msg_nb = -(g_mss_mac.last_error);
|
||||||
if( error_msg_nb >= ERROR_MESSAGE_COUNT ) {
|
if( error_msg_nb >= ERROR_MESSAGE_COUNT ) {
|
||||||
|
@ -962,7 +944,6 @@ MSS_MAC_get_statistics
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
uint32_t returnval = 0u;
|
uint32_t returnval = 0u;
|
||||||
configASSERT( MAC_test_instance() == MAC_OK );
|
|
||||||
|
|
||||||
switch( stat_id ) {
|
switch( stat_id ) {
|
||||||
case MSS_MAC_RX_INTERRUPTS:
|
case MSS_MAC_RX_INTERRUPTS:
|
||||||
|
@ -1029,31 +1010,6 @@ MSS_MAC_get_statistics
|
||||||
|
|
||||||
/**************************** INTERNAL FUNCTIONS ******************************/
|
/**************************** INTERNAL FUNCTIONS ******************************/
|
||||||
|
|
||||||
/***************************************************************************//**
|
|
||||||
* Checks if instace is valid.
|
|
||||||
*/
|
|
||||||
static int32_t
|
|
||||||
MAC_test_instance
|
|
||||||
(
|
|
||||||
void
|
|
||||||
)
|
|
||||||
{
|
|
||||||
uint32_t val1;
|
|
||||||
uint32_t val2;
|
|
||||||
int32_t retval = MAC_WRONG_PARAMETER;
|
|
||||||
|
|
||||||
val1 = MAC->CSR3;
|
|
||||||
val2 = MAC->CSR4;
|
|
||||||
|
|
||||||
if( (&g_mss_mac != NULL_instance) &&
|
|
||||||
((g_mss_mac.flags & FLAG_MAC_INIT_DONE) != 0u) &&
|
|
||||||
( val1 == (uint32_t)g_mss_mac.rx_descriptors) &&
|
|
||||||
(val2 == (uint32_t)g_mss_mac.tx_descriptors ) )
|
|
||||||
{
|
|
||||||
retval = MAC_OK;
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***************************************************************************//**
|
/***************************************************************************//**
|
||||||
* Prepares current rx descriptor for receiving.
|
* Prepares current rx descriptor for receiving.
|
||||||
|
@ -1092,7 +1048,7 @@ MSS_MAC_prepare_rx_descriptor
|
||||||
if( (desc & RDES0_CE) != 0u ) {
|
if( (desc & RDES0_CE) != 0u ) {
|
||||||
g_mss_mac.statistics.rx_crc_error++;
|
g_mss_mac.statistics.rx_crc_error++;
|
||||||
}
|
}
|
||||||
|
|
||||||
desc = MAC->CSR8;
|
desc = MAC->CSR8;
|
||||||
g_mss_mac.statistics.rx_fifo_overflow +=
|
g_mss_mac.statistics.rx_fifo_overflow +=
|
||||||
(desc & (CSR8_OCO_MASK|CSR8_FOC_MASK)) >> CSR8_FOC_SHIFT;
|
(desc & (CSR8_OCO_MASK|CSR8_FOC_MASK)) >> CSR8_FOC_SHIFT;
|
||||||
|
@ -1178,15 +1134,15 @@ MAC_send_setup_frame
|
||||||
|
|
||||||
/* Set descriptor */
|
/* Set descriptor */
|
||||||
MAC->CSR4 = (uint32_t)&descriptor;
|
MAC->CSR4 = (uint32_t)&descriptor;
|
||||||
|
|
||||||
/* Start transmission */
|
/* Start transmission */
|
||||||
MAC_start_transmission();
|
MAC_start_transmission();
|
||||||
|
|
||||||
/* Wait until transmission over */
|
/* Wait until transmission over */
|
||||||
ret = MAC_OK;
|
ret = MAC_OK;
|
||||||
MAC_set_time_out( (uint32_t)SETUP_FRAME_TIME_OUT );
|
MAC_set_time_out( (uint32_t)SETUP_FRAME_TIME_OUT );
|
||||||
|
|
||||||
while( (((MAC->CSR5 & CSR5_TS_MASK) >> CSR5_TS_SHIFT) !=
|
while( (((MAC->CSR5 & CSR5_TS_MASK) >> CSR5_TS_SHIFT) !=
|
||||||
CSR5_TS_SUSPENDED) && (MAC_OK == ret) )
|
CSR5_TS_SUSPENDED) && (MAC_OK == ret) )
|
||||||
{
|
{
|
||||||
/* transmit poll demand */
|
/* transmit poll demand */
|
||||||
|
@ -1200,7 +1156,7 @@ MAC_send_setup_frame
|
||||||
|
|
||||||
/* Set tx descriptor */
|
/* Set tx descriptor */
|
||||||
MAC->CSR4 = (uint32_t)g_mss_mac.tx_descriptors;
|
MAC->CSR4 = (uint32_t)g_mss_mac.tx_descriptors;
|
||||||
|
|
||||||
/* Start receiving and transmission */
|
/* Start receiving and transmission */
|
||||||
MAC_start_receiving();
|
MAC_start_receiving();
|
||||||
MAC_start_transmission();
|
MAC_start_transmission();
|
||||||
|
@ -1224,7 +1180,7 @@ MAC_stop_transmission
|
||||||
{
|
{
|
||||||
int32_t retval = MAC_OK;
|
int32_t retval = MAC_OK;
|
||||||
MAC_set_time_out( (uint16_t)STATE_CHANGE_TIME_OUT );
|
MAC_set_time_out( (uint16_t)STATE_CHANGE_TIME_OUT );
|
||||||
|
|
||||||
while( (((MAC->CSR5 & CSR5_TS_MASK) >> CSR5_TS_SHIFT) !=
|
while( (((MAC->CSR5 & CSR5_TS_MASK) >> CSR5_TS_SHIFT) !=
|
||||||
CSR5_TS_STOPPED) && (retval == MAC_OK) )
|
CSR5_TS_STOPPED) && (retval == MAC_OK) )
|
||||||
{
|
{
|
||||||
|
@ -1305,7 +1261,7 @@ MAC_dismiss_bad_frames
|
||||||
{
|
{
|
||||||
int32_t dc = 0;
|
int32_t dc = 0;
|
||||||
int8_t cont = 1;
|
int8_t cont = 1;
|
||||||
|
|
||||||
if( MAC_BITBAND->CSR6_PB != 0u ) {
|
if( MAC_BITBAND->CSR6_PB != 0u ) {
|
||||||
/* User wants bad frames too, don't dismiss anything */
|
/* User wants bad frames too, don't dismiss anything */
|
||||||
cont = 0;
|
cont = 0;
|
||||||
|
@ -1362,14 +1318,14 @@ MAC_get_time_out
|
||||||
{
|
{
|
||||||
uint32_t timer;
|
uint32_t timer;
|
||||||
uint32_t time = 0u;
|
uint32_t time = 0u;
|
||||||
|
|
||||||
timer = ( MAC->CSR11 & CSR11_TIM_MASK );
|
timer = ( MAC->CSR11 & CSR11_TIM_MASK );
|
||||||
|
|
||||||
if( timer > g_mss_mac.last_timer_value ) {
|
if( timer > g_mss_mac.last_timer_value ) {
|
||||||
time = 0x0000ffffUL;
|
time = 0x0000ffffUL;
|
||||||
}
|
}
|
||||||
time += g_mss_mac.last_timer_value - timer;
|
time += g_mss_mac.last_timer_value - timer;
|
||||||
|
|
||||||
if( MAC_BITBAND->CSR6_TTM == 0u ) {
|
if( MAC_BITBAND->CSR6_TTM == 0u ) {
|
||||||
time *= 10u;
|
time *= 10u;
|
||||||
}
|
}
|
||||||
|
@ -1414,10 +1370,6 @@ static void MAC_memset_All(MAC_instance_t *s, uint32_t c)
|
||||||
MAC_memset( s->mac_address, (uint8_t)c, 6u );
|
MAC_memset( s->mac_address, (uint8_t)c, 6u );
|
||||||
MAC_memset( s->mac_filter_data, (uint8_t)c, 90u );
|
MAC_memset( s->mac_filter_data, (uint8_t)c, 90u );
|
||||||
s->phy_address = (uint8_t)c;
|
s->phy_address = (uint8_t)c;
|
||||||
// for(count = 0; count<RX_RING_SIZE ;count++)
|
|
||||||
// {
|
|
||||||
// MAC_memset(s->rx_buffers[count], (uint8_t)c, (MSS_RX_BUFF_SIZE + 4u) );
|
|
||||||
// }
|
|
||||||
s->rx_desc_index =c;
|
s->rx_desc_index =c;
|
||||||
for(count = 0; count<RX_RING_SIZE ;count++)
|
for(count = 0; count<RX_RING_SIZE ;count++)
|
||||||
{
|
{
|
||||||
|
@ -1445,10 +1397,6 @@ static void MAC_memset_All(MAC_instance_t *s, uint32_t c)
|
||||||
s->statistics.tx_no_carrier = c;
|
s->statistics.tx_no_carrier = c;
|
||||||
s->statistics.tx_underflow_error = c;
|
s->statistics.tx_underflow_error = c;
|
||||||
s->time_out_value = c;
|
s->time_out_value = c;
|
||||||
// for(count = 0; count < TX_RING_SIZE ;count++)
|
|
||||||
// {
|
|
||||||
// MAC_memset( s->tx_buffers[count], (uint8_t)c, MSS_TX_BUFF_SIZE );
|
|
||||||
// }
|
|
||||||
s->tx_desc_index = c;
|
s->tx_desc_index = c;
|
||||||
for(count = 0; count < TX_RING_SIZE ;count++)
|
for(count = 0; count < TX_RING_SIZE ;count++)
|
||||||
{
|
{
|
||||||
|
@ -1475,25 +1423,42 @@ static void MAC_memcpy(uint8_t *dest, const uint8_t *src, uint32_t n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MSS_MAC_TxBufferCompleted( void )
|
/***************************************************************************//**
|
||||||
|
* Check the buffers assigned to the Tx descriptors to ensure that none remain
|
||||||
|
* marked as in use even though the Tx has completed. This could happen if a
|
||||||
|
* Tx interrupt was missed.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void MSS_MAC_CheckTxBufferStatus( void )
|
||||||
{
|
{
|
||||||
unsigned char *pxTransmittedBuffer;
|
unsigned char *pxTransmittedBuffer;
|
||||||
|
long lDescriptor, lIndex;
|
||||||
|
|
||||||
/* Was it the second transmission that has completed? */
|
for( lDescriptor = 1; lDescriptor < TX_RING_SIZE; lDescriptor++ )
|
||||||
if( ( g_mss_mac.tx_descriptors[ 1 ].descriptor_0 & TDES0_OWN ) == 0UL )
|
|
||||||
{
|
{
|
||||||
pxTransmittedBuffer = ( unsigned char * ) g_mss_mac.tx_descriptors[ 1 ].buffer_1;
|
if( ( g_mss_mac.tx_descriptors[ lDescriptor ].descriptor_0 & TDES0_OWN ) == 0UL )
|
||||||
|
{
|
||||||
|
pxTransmittedBuffer = ( unsigned char * ) g_mss_mac.tx_descriptors[ lDescriptor ].buffer_1;
|
||||||
|
|
||||||
/* The buffer has been transmitted and is no longer in use. */
|
for( lIndex = 0; lIndex < macNUM_BUFFERS; lIndex++ )
|
||||||
MAC_release_buffer( pxTransmittedBuffer );
|
{
|
||||||
}
|
if( pxTransmittedBuffer == &( xMACBuffers.ucBuffer[ lIndex ][ 0 ] ) )
|
||||||
else
|
{
|
||||||
{
|
ucMACBufferInUse[ lIndex ] = pdFALSE;
|
||||||
// configASSERT( 0 );
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned char *MAC_obtain_buffer( void )
|
/***************************************************************************//**
|
||||||
|
* Look through the array of buffers until one is found that is free for use -
|
||||||
|
* that is, not currently assigned to an Rx or a Tx descriptor. Mark the buffer
|
||||||
|
* as in use, then return its address.
|
||||||
|
*
|
||||||
|
* @return a pointer to a free buffer.
|
||||||
|
*/
|
||||||
|
unsigned char *MAC_obtain_buffer( void )
|
||||||
{
|
{
|
||||||
long lIndex;
|
long lIndex;
|
||||||
unsigned char *pcReturn = NULL;
|
unsigned char *pcReturn = NULL;
|
||||||
|
@ -1504,7 +1469,7 @@ unsigned char *pcReturn = NULL;
|
||||||
{
|
{
|
||||||
if( ucMACBufferInUse[ lIndex ] == pdFALSE )
|
if( ucMACBufferInUse[ lIndex ] == pdFALSE )
|
||||||
{
|
{
|
||||||
pcReturn = &( ucMACBuffers[ lIndex ][ 0 ] );
|
pcReturn = &( xMACBuffers.ucBuffer[ lIndex ][ 0 ] );
|
||||||
ucMACBufferInUse[ lIndex ] = pdTRUE;
|
ucMACBufferInUse[ lIndex ] = pdTRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1514,6 +1479,10 @@ unsigned char *pcReturn = NULL;
|
||||||
return pcReturn;
|
return pcReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***************************************************************************//**
|
||||||
|
* Return a buffer to the list of free buffers, it was in use, but is not now.
|
||||||
|
*
|
||||||
|
*/
|
||||||
void MAC_release_buffer( unsigned char *pucBufferToRelease )
|
void MAC_release_buffer( unsigned char *pucBufferToRelease )
|
||||||
{
|
{
|
||||||
long lIndex;
|
long lIndex;
|
||||||
|
@ -1522,7 +1491,7 @@ long lIndex;
|
||||||
it is currently pointing to is marked as being free again. */
|
it is currently pointing to is marked as being free again. */
|
||||||
for( lIndex = 0; lIndex < macNUM_BUFFERS; lIndex++ )
|
for( lIndex = 0; lIndex < macNUM_BUFFERS; lIndex++ )
|
||||||
{
|
{
|
||||||
if( pucBufferToRelease == &( ucMACBuffers[ lIndex ][ 0 ] ) )
|
if( pucBufferToRelease == &( xMACBuffers.ucBuffer[ lIndex ][ 0 ] ) )
|
||||||
{
|
{
|
||||||
/* This is the buffer in use, mark it as being free. */
|
/* This is the buffer in use, mark it as being free. */
|
||||||
ucMACBufferInUse[ lIndex ] = pdFALSE;
|
ucMACBufferInUse[ lIndex ] = pdFALSE;
|
||||||
|
@ -1530,6 +1499,10 @@ long lIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check the buffers pointed to by the Tx descriptors, just in case a Tx
|
||||||
|
interrupt has been missed and a free buffer remains marked as in use. */
|
||||||
|
MSS_MAC_CheckTxBufferStatus();
|
||||||
|
|
||||||
configASSERT( lIndex < macNUM_BUFFERS );
|
configASSERT( lIndex < macNUM_BUFFERS );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/******************************** DEFINES *************************************/
|
/******************************** DEFINES *************************************/
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ extern "C" {
|
||||||
#define MSS_PHY_ADDRESS_AUTO_DETECT 255u
|
#define MSS_PHY_ADDRESS_AUTO_DETECT 255u
|
||||||
|
|
||||||
/***************************************************************************//**
|
/***************************************************************************//**
|
||||||
* Listener function type defines the function prototype that might be followed
|
* Listener function type defines the function prototype that might be followed
|
||||||
* by MAC_isr which is triggered with each receive and transmit related interrupts.
|
* by MAC_isr which is triggered with each receive and transmit related interrupts.
|
||||||
* Listener functions should follow the following prototype:
|
* Listener functions should follow the following prototype:
|
||||||
* void MAC_Listener( uint32_t events );
|
* void MAC_Listener( uint32_t events );
|
||||||
|
@ -168,7 +168,7 @@ extern "C" {
|
||||||
* or events. Events input to the system are:
|
* or events. Events input to the system are:
|
||||||
* #define MSS_MAC_EVENT_PACKET_SEND 1
|
* #define MSS_MAC_EVENT_PACKET_SEND 1
|
||||||
* #define MSS_MAC_EVENT_PACKET_RECEIVED 2
|
* #define MSS_MAC_EVENT_PACKET_RECEIVED 2
|
||||||
* Listener function should be defined by the application using this driver if
|
* Listener function should be defined by the application using this driver if
|
||||||
* needed. This function may be assigned to the driver using MAC_set_callback
|
* needed. This function may be assigned to the driver using MAC_set_callback
|
||||||
* routine and may be un assigned again by using the same routine with a NULL pointer
|
* routine and may be un assigned again by using the same routine with a NULL pointer
|
||||||
* as the event listener function. It is recommended to use this property for interrupt
|
* as the event listener function. It is recommended to use this property for interrupt
|
||||||
|
@ -177,7 +177,7 @@ extern "C" {
|
||||||
typedef void (*MSS_MAC_callback_t)(uint32_t events);
|
typedef void (*MSS_MAC_callback_t)(uint32_t events);
|
||||||
|
|
||||||
/***************************************************************************//**
|
/***************************************************************************//**
|
||||||
* Statistics counter identifiers are used with MAC_get_statistics routine to
|
* Statistics counter identifiers are used with MAC_get_statistics routine to
|
||||||
* receive the count of the requested errors/interrupts occurrences.
|
* receive the count of the requested errors/interrupts occurrences.
|
||||||
*
|
*
|
||||||
* MSS_MAC_RX_INTERRUPTS
|
* MSS_MAC_RX_INTERRUPTS
|
||||||
|
@ -270,7 +270,7 @@ typedef enum {
|
||||||
MSS_MAC_TX_EXCESSIVE_COLLISION,
|
MSS_MAC_TX_EXCESSIVE_COLLISION,
|
||||||
MSS_MAC_TX_COLLISION_COUNT,
|
MSS_MAC_TX_COLLISION_COUNT,
|
||||||
MSS_MAC_TX_UNDERFLOW_ERROR
|
MSS_MAC_TX_UNDERFLOW_ERROR
|
||||||
} mss_mac_statistics_id_t;
|
} mss_mac_statistics_id_t;
|
||||||
|
|
||||||
/******************************* FUNCTIONS ************************************/
|
/******************************* FUNCTIONS ************************************/
|
||||||
|
|
||||||
|
@ -317,7 +317,7 @@ MSS_MAC_configure
|
||||||
|
|
||||||
/***************************************************************************//**
|
/***************************************************************************//**
|
||||||
* Returns the configuration of the Ethernet Controller.
|
* Returns the configuration of the Ethernet Controller.
|
||||||
* After the MAC_init function has been called, this API function can be used to
|
* After the MAC_init function has been called, this API function can be used to
|
||||||
* get the configuration of the Ethernet Controller.
|
* get the configuration of the Ethernet Controller.
|
||||||
*
|
*
|
||||||
* @return The logical OR of the following values:
|
* @return The logical OR of the following values:
|
||||||
|
@ -366,7 +366,7 @@ MSS_MAC_tx_packet
|
||||||
* Returns available packet's size.
|
* Returns available packet's size.
|
||||||
*
|
*
|
||||||
* @return Size of packet, bigger than 0, if a packet is available,
|
* @return Size of packet, bigger than 0, if a packet is available,
|
||||||
* if not, returns 0.
|
* if not, returns 0.
|
||||||
* @see MAC_rx_packet()
|
* @see MAC_rx_packet()
|
||||||
*/
|
*/
|
||||||
int32_t
|
int32_t
|
||||||
|
@ -416,26 +416,26 @@ MSS_MAC_rx_packet
|
||||||
used by the user application or copied to another buffer, the
|
used by the user application or copied to another buffer, the
|
||||||
MSS_MAC_prepare_rx_descriptor() function must be called to free up the receive
|
MSS_MAC_prepare_rx_descriptor() function must be called to free up the receive
|
||||||
memory buffer used by the MSS Ethernet MAC
|
memory buffer used by the MSS Ethernet MAC
|
||||||
|
|
||||||
@param pacData
|
@param pacData
|
||||||
The pacData parameter is a pointer to a memory buffer pointer. The uint8_t
|
The pacData parameter is a pointer to a memory buffer pointer. The uint8_t
|
||||||
pointer pointed to by the pacData parameter will contain the address of the
|
pointer pointed to by the pacData parameter will contain the address of the
|
||||||
memory buffer containing the received packet after this function returns. The
|
memory buffer containing the received packet after this function returns. The
|
||||||
value of pacData is only valid if the return value is larger than zero,
|
value of pacData is only valid if the return value is larger than zero,
|
||||||
indicating that a packet was received.
|
indicating that a packet was received.
|
||||||
|
|
||||||
@param time_out
|
@param time_out
|
||||||
The time_out parameter is the timeout value for the transmission in milliseconds.
|
The time_out parameter is the timeout value for the transmission in milliseconds.
|
||||||
The time_out parameter value can be one of the following values:
|
The time_out parameter value can be one of the following values:
|
||||||
• Unsigned integer greater than 0 and less than 0x01000000
|
• Unsigned integer greater than 0 and less than 0x01000000
|
||||||
• MSS_MAC_BLOCKING – there will be no timeout.
|
• MSS_MAC_BLOCKING – there will be no timeout.
|
||||||
• MSS_MAC_NONBLOCKING – the function will return immediately if no packets
|
• MSS_MAC_NONBLOCKING – the function will return immediately if no packets
|
||||||
have been received.
|
have been received.
|
||||||
|
|
||||||
@return
|
@return
|
||||||
The function returns the size of the packet if the packet fits in pacData.
|
The function returns the size of the packet if the packet fits in pacData.
|
||||||
Returns zero if there is no received packet.
|
Returns zero if there is no received packet.
|
||||||
|
|
||||||
@see MAC_rx_pckt_size()
|
@see MAC_rx_pckt_size()
|
||||||
@see MAC_tx_packet()
|
@see MAC_tx_packet()
|
||||||
*/
|
*/
|
||||||
|
@ -537,10 +537,10 @@ MSS_MAC_set_callback
|
||||||
/***************************************************************************//**
|
/***************************************************************************//**
|
||||||
* Returns description of latest error happened.
|
* Returns description of latest error happened.
|
||||||
*
|
*
|
||||||
* @return A string describing the error. This string must not be
|
* @return A string describing the error. This string must not be
|
||||||
* modified by the application.
|
* modified by the application.
|
||||||
*/
|
*/
|
||||||
const int8_t*
|
const int8_t*
|
||||||
MSS_MAC_last_error
|
MSS_MAC_last_error
|
||||||
(
|
(
|
||||||
void
|
void
|
||||||
|
@ -549,7 +549,7 @@ MSS_MAC_last_error
|
||||||
|
|
||||||
/***************************************************************************//**
|
/***************************************************************************//**
|
||||||
* Returns statistics counter of stat_id identifier.
|
* Returns statistics counter of stat_id identifier.
|
||||||
*
|
*
|
||||||
* @param stat_id Identifier of statistics counter.
|
* @param stat_id Identifier of statistics counter.
|
||||||
* @return Statistics counter of stat_id identifier.
|
* @return Statistics counter of stat_id identifier.
|
||||||
* On error returns 0.
|
* On error returns 0.
|
||||||
|
@ -560,23 +560,11 @@ MSS_MAC_get_statistics
|
||||||
mss_mac_statistics_id_t stat_id
|
mss_mac_statistics_id_t stat_id
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
|
||||||
* Ensure uip_buf is pointing to a valid and free buffer before any transmissions
|
|
||||||
* initiated by the uIP stack occur.
|
|
||||||
*/
|
|
||||||
unsigned char *MSS_MAC_GetTxDescriptor( void );
|
|
||||||
|
|
||||||
/*
|
|
||||||
* A buffer is no longer required by the application. Hand it back to the
|
|
||||||
* control of the MAC hardware.
|
|
||||||
*/
|
|
||||||
void MSS_MAC_ReleaseBuffer( unsigned char *pucBuffer );
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The double Tx has completed. Hand back the Tx buffer to the control of
|
* The double Tx has completed. Hand back the Tx buffer to the control of
|
||||||
* the MAC hardware.
|
* the MAC hardware.
|
||||||
*/
|
*/
|
||||||
void MSS_MAC_TxBufferCompleted( void );
|
void MSS_MAC_CheckTxBufferStatus( void );
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -66,12 +66,10 @@ typedef struct {
|
||||||
|
|
||||||
/* transmit related info: */
|
/* transmit related info: */
|
||||||
uint32_t tx_desc_index; /**< index of the transmit descriptor getting used*/
|
uint32_t tx_desc_index; /**< index of the transmit descriptor getting used*/
|
||||||
// uint8_t tx_buffers[TX_RING_SIZE][MSS_TX_BUFF_SIZE];/**< array of transmit buffers*/
|
|
||||||
MAC_descriptor_t tx_descriptors[TX_RING_SIZE];/**< array of transmit descriptors*/
|
MAC_descriptor_t tx_descriptors[TX_RING_SIZE];/**< array of transmit descriptors*/
|
||||||
|
|
||||||
/* receive related info: */
|
/* receive related info: */
|
||||||
uint32_t rx_desc_index; /**< index of the receive descriptor getting used*/
|
uint32_t rx_desc_index; /**< index of the receive descriptor getting used*/
|
||||||
// uint8_t rx_buffers[RX_RING_SIZE][MSS_RX_BUFF_SIZE+4];/**< array of receive buffers*/
|
|
||||||
MAC_descriptor_t rx_descriptors[RX_RING_SIZE];/**< array of receive descriptors*/
|
MAC_descriptor_t rx_descriptors[RX_RING_SIZE];/**< array of receive descriptors*/
|
||||||
|
|
||||||
uint8_t phy_address; /**< MII address of the connected PHY*/
|
uint8_t phy_address; /**< MII address of the connected PHY*/
|
||||||
|
|
Loading…
Reference in a new issue