RA Flexible Software Package Documentation  Release v6.0.0

 
Ethernet (r_rmac)

Functions

fsp_err_t R_RMAC_Open (ether_ctrl_t *const p_ctrl, ether_cfg_t const *const p_cfg)
 After RMAC, Switch and PHY-LSI are reset in software, an auto negotiation of PHY-LSI is begun. Afterwards, the link signal change interrupt is permitted. Implements ether_api_t::open. More...
 
fsp_err_t R_RMAC_Close (ether_ctrl_t *const p_ctrl)
 Disables interrupts. Removes power and releases hardware lock. Implements ether_api_t::close. More...
 
fsp_err_t R_RMAC_BufferRelease (ether_ctrl_t *const p_ctrl)
 Move to the next buffer in the circular receive buffer list. Implements ether_api_t::bufferRelease. More...
 
fsp_err_t R_RMAC_RxBufferUpdate (ether_ctrl_t *const p_ctrl, void *const p_buffer)
 Change the buffer pointer of the current rx buffer descriptor. Implements ether_api_t::rxBufferUpdate. More...
 
fsp_err_t R_RMAC_LinkProcess (ether_ctrl_t *const p_ctrl)
 The Link up processing, the Link down processing, and the magic packet detection processing are executed. Implements ether_api_t::linkProcess. More...
 
fsp_err_t R_RMAC_WakeOnLANEnable (ether_ctrl_t *const p_ctrl)
 The setting of RMAC is changed from normal sending and receiving mode to magic packet detection mode. Implements ether_api_t::wakeOnLANEnable. More...
 
fsp_err_t R_RMAC_Read (ether_ctrl_t *const p_ctrl, void *const p_buffer, uint32_t *const length_bytes)
 Receive Ethernet frame. Receives data to the location specified by the pointer to the receive buffer. In zero copy mode, the address of the receive buffer is returned. In non zero copy mode, the received data in the internal buffer is copied to the pointer passed by the argument. Implements ether_api_t::read. More...
 
fsp_err_t R_RMAC_Write (ether_ctrl_t *const p_ctrl, void *const p_buffer, uint32_t const frame_length)
 Transmit Ethernet frame. Transmits data from the location specified by the pointer to the transmit buffer, with the data size equal to the specified frame length. In the non zero copy mode, transmits data after being copied to the internal buffer. Implements ether_api_t::write. More...
 
fsp_err_t R_RMAC_TxStatusGet (ether_ctrl_t *const p_ctrl, void *const p_buffer_address)
 
fsp_err_t R_RMAC_CallbackSet (ether_ctrl_t *const p_api_ctrl, void(*p_callback)(ether_callback_args_t *), void *const p_context, ether_callback_args_t *const p_callback_memory)
 

Detailed Description

Driver for the Ethernet peripheral on RA MCUs. This module implements the Ethernet Interface.

Overview

This module transmits and receives Ethernet (IEEE 802.3) frames. This module provides single MAC layer interface.

Features

The RMAC module supports the following features:

Configuration

Build Time Configurations for r_rmac

The following build time configurations are defined in fsp_cfg/r_rmac_cfg.h:

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.

Configurations for Networking > Ethernet MAC (r_rmac)

This module can be added to the Stacks tab via New Stack > Networking > Ethernet MAC (r_rmac). Non-secure callable guard functions can be generated for this module by right clicking the module in the RA Configuration tool and checking the "Non-secure Callable" box.

ConfigurationOptionsDefaultDescription
General
NameName must be a valid C symbolg_ether0 Module name.
ChannelMust be an integer greater than or equal to 0.0 Write the ether channel number.
Zero-copy Mode
  • Disable
  • Enable
Disable Enable or disable zero-copy mode.
Flow control functionality
  • Disable
  • Enable
Disable Enable or disable flow control.
MAC addressMust be a valid MAC address00:11:22:33:44:55 MAC address of this channel.
Filters
Multicast Mode
  • Disable
  • Enable
Enable Enable or disable multicast frame reception.
Promiscuous Mode
  • Disable
  • Enable
Disable Enable this option to receive packets addressed to other NICs.
Broadcast filterMust be a valid non-negative integer with maximum configurable value of 65535. 0 Limit of the number of broadcast frames received continuously
Buffers
Padding sizeDisableDisable The padding size that is automatically inserted into the received packets
Padding offsetMust be less than 64 bytes.0 The offset into a receive buffer to insert padding bytes.
TX queue lengthValue must be an integer4 TX queue length
RX queue lengthValue must be an integer4 RX queue length
TX queue numValue must be an integer2 TX queue num
RX queue numValue must be an integer2 RX queue num
Buffer sizeMust be at least 1514 which is the maximum Ethernet frame size.1514 Size of Ethernet buffer
Allocate RX buffer
  • Disable
  • Enable
Enable Allocates the RX buffer when generating the configuration structure
Interrupts
Magic packet interrupt priorityMCU Specific OptionsSelect the magic packet detection interrupt priority.
CallbackName must be a valid C symbolNULL Callback provided when an ISR occurs

Interrupt Configuration

The first R_RMAC_Open function call sets GWDI interrupts. The user could provide callback function which would be invoked when GWDI interrupt handler has been completed. The callback arguments will contain information about a channel number, the event code and a pointer to the user defined context.

Callback Configuration

The user could provide callback function which would be invoked when either a magic packet or a link signal change is detected. When the callback function is called, a variable in which the channel number for which the detection occurred and a constant shown in Table 2.4 are stored is passed as an argument. If the value of this argument is to be used outside the callback function, its value should be copied into, for example, a global variable.

Clock Configuration

The ESWM peripheral uses ICLK, PCLKA, ESWCLK and ESWPHYCLK as clocks. These clocks must be set to frequencies within the ranges shown in the following table.

PHY speed [Mbps] ICLK [MHz] PCLKA [MHz] ESWCLK [MHz] ESWPHYCLK [MHz]
10/100 50 to 250 up to 125 50 to 250 Not required
1000 150 to 250 up to 125 150 to 250 500
Note
1. Clock restrictions are as follow: ICLK × 1.5 => ESWCLK, ESWCLK > PCLKA and ICLK > PCLKA.
2. When using a products in the HLQFP176 package, set ESWCLK to 125 MHz or less.

Pin Configuration

To use the RMAC module, input/output signals of the peripheral function have to be allocated to pins with the multi-function pin controller (MPC). Please perform the pin setting before calling the R_RMAC_Open function.

Usage Notes

Ethernet Frame Format

The RMAC module supports the Ethernet II/IEEE 802.3 frame format.

Frame Format for Data Transmission and Reception

frame_format_image.svg
Frame Format Image

The preamble and SFD signal the start of an Ethernet frame. The FCS contains the CRC of the Ethernet frame and is calculated on the transmitting side. When data is received the CRC value of the frame is calculated in hardware, and the Ethernet frame is discarded if the values do not match. When the hardware determines that the data is normal, the valid range of receive data is: (transmission destination address) + (transmission source address) + (length/type) + (data).

PAUSE Frame Format

pause_frame_format_image.svg
Pause Frame Format Image

The transmission destination address is specified as 01:80:C2:00:00:01 (a multicast address reserved for PAUSE frames). At the start of the payload the length/type is specified as 0x8808 and the operation code as 0x0001. The pause duration in the payload is specified by the value of the automatic PAUSE (AP) bits in the automatic PAUSE frame setting register (APR), or the manual PAUSE time setting (MP) bits in the manual PAUSE frame setting register (MPR).

Magic Packet Frame Format

magic_packet_frame_format_image.svg
Magic Packet Frame Format Image

In a Magic Packet, the value FF:FF:FF:FF:FF:FF followed by the transmission destination address repeated 16 times is inserted somewhere in the Ethernet frame data.

Examples

ETHER Basic Example

This is a basic example of minimal use of the ETHER in an application.

Note
In this example zero-copy mode is disabled and there are no restrictions on buffer alignment.
#define RMAC_EXAMPLE_MAXIMUM_ETHERNET_FRAME_SIZE (1514)
#define RMAC_EXAMPLE_TRANSMIT_ETHERNET_FRAME_SIZE (60)
#define RMAC_EXAMPLE_SOURCE_MAC_ADDRESS 0x74, 0x90, 0x50, 0x00, 0x79, 0x01
#define RMAC_EXAMPLE_DESTINATION_MAC_ADDRESS 0x74, 0x90, 0x50, 0x00, 0x79, 0x02
#define RMAC_EXAMPLE_FRAME_TYPE 0x00, 0x2E
#define RMAC_EXAMPLE_PAYLOAD 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
/* Receive data buffer */
static uint8_t gp_read_buffer[RMAC_EXAMPLE_MAXIMUM_ETHERNET_FRAME_SIZE] = {0};
/* Transmit data buffer */
static uint8_t gp_send_data[RMAC_EXAMPLE_TRANSMIT_ETHERNET_FRAME_SIZE] =
{
RMAC_EXAMPLE_DESTINATION_MAC_ADDRESS, /* Destination MAC address */
RMAC_EXAMPLE_SOURCE_MAC_ADDRESS, /* Source MAC address */
RMAC_EXAMPLE_FRAME_TYPE, /* Type field */
RMAC_EXAMPLE_PAYLOAD /* Payload value (46byte) */
};
void rmac_basic_example (void)
{
fsp_err_t err = FSP_SUCCESS;
uint32_t read_data_size = 0;
/* Open the rmac instance with initial configuration. */
err = R_RMAC_Open(&g_ether0_ctrl, &g_ether0_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
do
{
/* When the Ethernet link status read from the PHY-LSI Basic Status register is link-up,
* Initializes the module and make auto negotiation. */
err = R_RMAC_LinkProcess(&g_ether0_ctrl);
} while (FSP_SUCCESS != err);
/* Transmission is non-blocking. */
/* User data copy to internal buffer and is transferred by DMA in the background. */
err = R_RMAC_Write(&g_ether0_ctrl, (void *) gp_send_data, sizeof(gp_send_data));
assert(FSP_SUCCESS == err);
/* Received data copy to user buffer from internal buffer. */
err = R_RMAC_Read(&g_ether0_ctrl, (void *) gp_read_buffer, &read_data_size);
assert(FSP_SUCCESS == err);
/* Disable transmission and receive function and close the rmac instance. */
R_RMAC_Close(&g_ether0_ctrl);
}

Function Documentation

◆ R_RMAC_Open()

fsp_err_t R_RMAC_Open ( ether_ctrl_t *const  p_ctrl,
ether_cfg_t const *const  p_cfg 
)

After RMAC, Switch and PHY-LSI are reset in software, an auto negotiation of PHY-LSI is begun. Afterwards, the link signal change interrupt is permitted. Implements ether_api_t::open.

Initializes the ether module and applies configurations. Implements ether_api_t::open.

Return values
FSP_SUCCESSChannel opened successfully.
FSP_ERR_ASSERTIONPointer to ETHER control block or configuration structure is NULL.
FSP_ERR_ALREADY_OPENControl block has already been opened or channel is being used by another instance. Call close() then open() to reconfigure.
FSP_ERR_ETHER_ERROR_PHY_COMMUNICATIONInitialization of PHY-LSI failed.
FSP_ERR_INVALID_CHANNELInvalid channel number is given.
FSP_ERR_INVALID_POINTERPointer to extend config structure or MAC address is NULL.
FSP_ERR_INVALID_ARGUMENTInterrupt is not enabled.
FSP_ERR_ETHER_PHY_ERROR_LINKInitialization of PHY-LSI failed.

◆ R_RMAC_Close()

fsp_err_t R_RMAC_Close ( ether_ctrl_t *const  p_ctrl)

Disables interrupts. Removes power and releases hardware lock. Implements ether_api_t::close.

Return values
FSP_SUCCESSChannel successfully closed.
FSP_ERR_ASSERTIONPointer to ETHER control block is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened

◆ R_RMAC_BufferRelease()

fsp_err_t R_RMAC_BufferRelease ( ether_ctrl_t *const  p_ctrl)

Move to the next buffer in the circular receive buffer list. Implements ether_api_t::bufferRelease.

Return values
FSP_SUCCESSProcessing completed successfully.
FSP_ERR_ASSERTIONPointer to ETHER control block is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened
FSP_ERR_ETHER_ERROR_LINKAuto-negotiation is not completed, and reception is not enabled.

◆ R_RMAC_RxBufferUpdate()

fsp_err_t R_RMAC_RxBufferUpdate ( ether_ctrl_t *const  p_ctrl,
void *const  p_buffer 
)

Change the buffer pointer of the current rx buffer descriptor. Implements ether_api_t::rxBufferUpdate.

Return values
FSP_SUCCESSProcessing completed successfully.
FSP_ERR_ASSERTIONA pointer argument is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_INVALID_POINTERThe pointer of buffer is NULL or not aligned on a 32-bit boundary.
FSP_ERR_INVALID_MODEDriver is configured to non zero copy mode.
FSP_ERR_ETHER_RECEIVE_BUFFER_ACTIVEAll descriptor is active.

◆ R_RMAC_LinkProcess()

fsp_err_t R_RMAC_LinkProcess ( ether_ctrl_t *const  p_ctrl)

The Link up processing, the Link down processing, and the magic packet detection processing are executed. Implements ether_api_t::linkProcess.

Return values
FSP_SUCCESSLink is up.
FSP_ERR_ASSERTIONPointer to ETHER control block is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_ETHER_ERROR_LINKLink is down.
FSP_ERR_ETHER_ERROR_PHY_COMMUNICATIONWhen reopening the PHY interface initialization of the PHY-LSI failed.
FSP_ERR_ALREADY_OPENWhen reopening the PHY interface it was already opened.
FSP_ERR_INVALID_CHANNELWhen reopening the PHY interface an invalid channel was passed.
FSP_ERR_INVALID_POINTERWhen reopening the PHY interface the MAC address pointer was NULL.
FSP_ERR_INVALID_ARGUMENTWhen reopening the PHY interface the interrupt was not enabled.
FSP_ERR_ETHER_PHY_ERROR_LINKInitialization of the PHY-LSI failed.

◆ R_RMAC_WakeOnLANEnable()

fsp_err_t R_RMAC_WakeOnLANEnable ( ether_ctrl_t *const  p_ctrl)

The setting of RMAC is changed from normal sending and receiving mode to magic packet detection mode. Implements ether_api_t::wakeOnLANEnable.

Return values
FSP_SUCCESSProcessing completed successfully.
FSP_ERR_ASSERTIONPointer to ETHER control block is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_ETHER_ERROR_LINKAuto-negotiation is not completed, and reception is not enabled.
FSP_ERR_ETHER_PHY_ERROR_LINKInitialization of PHY-LSI failed.

◆ R_RMAC_Read()

fsp_err_t R_RMAC_Read ( ether_ctrl_t *const  p_ctrl,
void *const  p_buffer,
uint32_t *const  length_bytes 
)

Receive Ethernet frame. Receives data to the location specified by the pointer to the receive buffer. In zero copy mode, the address of the receive buffer is returned. In non zero copy mode, the received data in the internal buffer is copied to the pointer passed by the argument. Implements ether_api_t::read.

Return values
FSP_SUCCESSProcessing completed successfully.
FSP_ERR_ASSERTIONPointer to ETHER control block is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_ETHER_ERROR_NO_DATAThere is no data in receive buffer.
FSP_ERR_ETHER_ERROR_LINKAuto-negotiation is not completed, and reception is not enabled.
FSP_ERR_ETHER_ERROR_FILTERINGMulticast Frame filter is enable, and Multicast Address Frame is received.
FSP_ERR_INVALID_POINTERValue of the pointer is NULL.

◆ R_RMAC_Write()

fsp_err_t R_RMAC_Write ( ether_ctrl_t *const  p_ctrl,
void *const  p_buffer,
uint32_t const  frame_length 
)

Transmit Ethernet frame. Transmits data from the location specified by the pointer to the transmit buffer, with the data size equal to the specified frame length. In the non zero copy mode, transmits data after being copied to the internal buffer. Implements ether_api_t::write.

Return values
FSP_SUCCESSProcessing completed successfully.
FSP_ERR_ASSERTIONPointer to ETHER control block is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_ETHER_ERROR_LINKAuto-negotiation is not completed, and reception is not enabled.
FSP_ERR_ETHER_ERROR_TRANSMIT_BUFFER_FULLTransmit buffer is not empty.
FSP_ERR_INVALID_POINTERValue of the pointer is NULL.
FSP_ERR_INVALID_ARGUMENTValue of the send frame size is out of range.

◆ R_RMAC_TxStatusGet()

fsp_err_t R_RMAC_TxStatusGet ( ether_ctrl_t *const  p_ctrl,
void *const  p_buffer_address 
)

Provides status of Ethernet driver in the user provided pointer. Implements ether_api_t::txStatusGet.

Return values
FSP_SUCCESSTransmit buffer address is stored in provided p_buffer_address.
FSP_ERR_ASSERTIONPointer to ETHER control block is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_INVALID_POINTERp_status is NULL.
FSP_ERR_NOT_FOUNDTransmit buffer address has been overwritten in transmit descriptor.

◆ R_RMAC_CallbackSet()

fsp_err_t R_RMAC_CallbackSet ( ether_ctrl_t *const  p_api_ctrl,
void(*)(ether_callback_args_t *)  p_callback,
void *const  p_context,
ether_callback_args_t *const  p_callback_memory 
)

Updates the user callback with the option to provide memory for the callback argument structure. Implements ether_api_t::callbackSet.

Return values
FSP_SUCCESSCallback updated successfully.
FSP_ERR_ASSERTIONA required pointer is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_NO_CALLBACK_MEMORYp_callback is non-secure and p_callback_memory is either secure or NULL.