414KB

The following document contains information on Cypress products.
Colophon
The products described in this document are designed, developed and manufactured as contemplated for general use,
including without limitation, ordinary industrial use, general office use, personal use, and household use, but are not
designed, developed and manufactured as contemplated (1) for any use that includes fatal risks or dangers that, unless
extremely high safety is secured, could have a serious effect to the public, and could lead directly to death, personal injury,
severe physical damage or other loss (i.e., nuclear reaction control in nuclear facility, aircraft flight control, air traffic control,
mass transport control, medical life support system, missile launch control in weapon system), or (2) for any use where
chance of failure is intolerable (i.e., submersible repeater and artificial satellite). Please note that Spansion will not be liable
to you and/or any third party for any claims or damages arising in connection with above-mentioned uses of the products.
Any semiconductor devices have an inherent chance of failure. You must protect against injury, damage or loss from such
failures by incorporating safety design measures into your facility and equipment such as redundancy, fire protection, and
prevention of over-current levels and other abnormal operating conditions. If any products described in this document
represent goods or technologies subject to certain restrictions on export under the Foreign Exchange and Foreign Trade Law
of Japan, the US Export Administration Regulations or the applicable laws of any other country, the prior authorization by the
respective government entity will be required for export of those products.
Trademarks and Notice
The contents of this document are subject to change without notice. This document may contain information on a Spansion
product under development by Spansion. Spansion reserves the right to change or discontinue work on any product without
notice. The information in this document is provided as is without warranty or guarantee of any kind as to its accuracy,
completeness, operability, fitness for particular purpose, merchantability, non-infringement of third-party rights, or any other
warranty, express, implied, or statutory. Spansion assumes no liability for any damages of any kind arising out of the use of
the information in this document.
®
®
®
TM
Copyright © 2013 Spansion Inc. All rights reserved. Spansion , the Spansion logo, MirrorBit , MirrorBit Eclipse ,
TM
ORNAND and combinations thereof, are trademarks and registered trademarks of Spansion LLC in the United States and
other countries. Other names used are for informational purposes only and may be trademarks of their respective owners.
Fujitsu Semiconductor Europe
Application Note
AN706-00059-1v0-E
FM3 FAMILY
32-BIT MICROCONTROLLER
MB9BFXXX
ETHERNET DRIVER MANUAL
APPLICATION NOTE
Ethernet Driver Manual
Revision History
Revision History
Date
2013-01-08
Issue
st
V1.0; CNo, YMo; 1 public version
This document contains 27 pages.
AN706-00059-1v0-E
-2-
© Fujitsu Semiconductor Europe GmbH
Ethernet Driver Manual
Warranty and Disclaimer
Warranty and Disclaimer
The use of the deliverables (e.g. software, application examples, target boards, evaluation boards,
starter kits, schematics, engineering samples of IC’s etc.) is subject to the conditions of Fujitsu
Semiconductor Europe GmbH (“FSEU”) as set out in (i) the terms of the License Agreement and/or
the Sale and Purchase Agreement under which agreements the Product has been delivered, (ii) the
technical descriptions and (iii) all accompanying written materials.
Please note that the deliverables are intended for and must only be used for reference in an
evaluation laboratory environment.
The software deliverables are provided on an as-is basis without charge and are subject to
alterations. It is the user’s obligation to fully test the software in its environment and to ensure proper
functionality, qualification and compliance with component specifications.
Regarding hardware deliverables, FSEU warrants that they will be free from defects in material and
workmanship under use and service as specified in the accompanying written materials for a duration
of 1 year from the date of receipt by the customer.
Should a hardware deliverable turn out to be defect, FSEU’s entire liability and the customer’s
exclusive remedy shall be, at FSEU’s sole discretion, either return of the purchase price and the
license fee, or replacement of the hardware deliverable or parts thereof, if the deliverable is returned
to FSEU in original packing and without further defects resulting from the customer’s use or the
transport. However, this warranty is excluded if the defect has resulted from an accident not
attributable to FSEU, or abuse or misapplication attributable to the customer or any other third party
not relating to FSEU or to unauthorised decompiling and/or reverse engineering and/or
disassembling.
FSEU does not warrant that the deliverables do not infringe any third party intellectual property right
(IPR). In the event that the deliverables infringe a third party IPR it is the sole responsibility of the
customer to obtain necessary licenses to continue the usage of the deliverable.
In the event the software deliverables include the use of open source components, the provisions of
the governing open source license agreement shall apply with respect to such software deliverables.
To the maximum extent permitted by applicable law FSEU disclaims all other warranties, whether
express or implied, in particular, but not limited to, warranties of merchantability and fitness for a
particular purpose for which the deliverables are not designated.
To the maximum extent permitted by applicable law, FSEU’s liability is restricted to intention and
gross negligence. FSEU is not liable for consequential damages.
Should one of the above stipulations be or become invalid and/or unenforceable, the remaining
stipulations shall stay in full effect.
The contents of this document are subject to change without a prior notice, thus contact FSEU about
the latest one.
© Fujitsu Semiconductor Europe GmbH
-3-
AN706-00059-1v0-E
Ethernet Driver Manual
Contents
Contents
REVISION HISTORY ............................................................................................................ 2
WARRANTY AND DISCLAIMER ......................................................................................... 3
CONTENTS .......................................................................................................................... 4
1 INTRODUCTION .............................................................................................................. 6
2 ETHERNET DRIVER STRUCTURE ................................................................................. 7
2.1
Driver File System ................................................................................................... 7
2.2
Additional Files (stand-alone version) ...................................................................... 7
2.3
Example Files (stand-alone version)........................................................................ 7
2.4
Driver System .......................................................................................................... 8
2.5
Interrupt Flow .......................................................................................................... 9
3 USING THE ETHERNET DRIVER ................................................................................. 10
3.1
3.2
User Settings in emac_user.h................................................................................ 10
3.1.1
Ethernet Instance Activation .................................................................... 10
3.1.2
Ethernet Instance Interrupt Mode ............................................................. 10
3.1.3
Ethernet Instance Interrupt Levels ........................................................... 10
3.1.4
Buffer Location (EMAC0 as example) ...................................................... 10
3.1.5
Transmission/Reception Ring Size (EMAC0 as example) ........................ 11
3.1.6
Transmission/Reception Buffer Size (EMAC0 as example) ...................... 11
3.1.7
Buffer Settings for EMAC1 ....................................................................... 11
3.1.8
Starterkits setting ..................................................................................... 11
3.1.9
Addresses of external PHYs .................................................................... 12
3.1.10
EMAC0 and EMAC1 MAC Address ......................................................... 12
3.1.11
Multicast address ..................................................................................... 12
3.1.12
External PHY reset pins ........................................................................... 12
3.1.13
PLL Clocking Mode.................................................................................. 13
3.1.14
PHY Management Bus Settings............................................................... 13
3.1.15
RMII PHY Interface Usage ....................................................................... 13
3.1.16
Buffer Fragmentation ............................................................................... 13
3.1.17
Checksum Insertion Control ..................................................................... 14
3.1.18
ICMP Checksum Bug Work-Around ......................................................... 14
3.1.19
Multicast Address Filter............................................................................ 15
Extra Settings in emac.c ........................................................................................ 16
3.2.1
Filter setting for Multicast MAC address ................................................... 16
AN706-00059-1v0-E
-4-
© Fujitsu Semiconductor Europe GmbH
Ethernet Driver Manual
Contents
3.3
Usage Examples ................................................................................................... 16
3.3.1
How to set up an Ethernet interface ......................................................... 16
3.3.2
How to Send a Frame .............................................................................. 17
3.3.3
How to Receive a Frame ......................................................................... 17
3.3.4
Interrupt Operation................................................................................... 18
4 ETHERNET DRIVER CONFIGURATION AND DATA TYPES ....................................... 19
4.1
Preface.................................................................................................................. 19
4.2
Configuration Structure.......................................................................................... 19
4.3
Link Status enumerated Type ................................................................................ 19
4.4
Link Mode enumerated Type ................................................................................. 19
5 ETHERNET DRIVER API ............................................................................................... 20
5.1
Preface.................................................................................................................. 20
5.1.1
Emac_Init() .............................................................................................. 20
5.1.2
Emac_DeInit().......................................................................................... 20
5.1.3
Emac_TxFrame() ..................................................................................... 21
5.1.4
Emac_GetRxFrameLength() .................................................................... 21
5.1.5
Emac_RxFrame() .................................................................................... 21
5.1.6
Emac_GetLinkStatus() ............................................................................. 22
5.1.7
Emac_GetLinkMode() .............................................................................. 22
5.1.8
Emac_SetLinkMode() .............................................................................. 23
5.1.9
Emac_Autonegotiate() ............................................................................. 23
5.1.10
Emac_SetDescToTxBuf() ........................................................................ 24
5.1.11
Emac_SetDescToRxBuf() ........................................................................ 24
5.1.12
Emac_SetEcout()..................................................................................... 25
5.1.13
Emac_RxFrame_GetBufPtr() ................................................................... 25
5.1.14
Emac_RxFrame_ReleaseBuf() ................................................................ 25
6 ADDITIONAL INFORMATION ....................................................................................... 26
LIST OF FIGURES ............................................................................................................. 27
© Fujitsu Semiconductor Europe GmbH
-5-
AN706-00059-1v0-E
Ethernet Driver Manual
Chapter 1 Introduction
1 Introduction
The Ethernet Driver is used as a low level driver for FM3 devices. It is available as a standalone version or integrated within the FM3 Low Level Library (LLL).
AN706-00059-1v0-E
-6-
© Fujitsu Semiconductor Europe GmbH
Ethernet Driver Manual
Chapter 2 Ethernet Driver Structure
2 Ethernet Driver Structure
THIS CHAPTER EXPLAINS THE STRUCTURE OF THE ETHERNET DRIVER
2.1
Driver File System
The Ethernet driver consists of the following files in its emac directory:

emac.c
Ethernet user API

emac.h
Ethernet API header file

emac_reg.h
Ethernet macro register bitfield redefinition

emac_user.h
Ethernet driver user setting file

ethphy.c
Ethernet PHY functions

ethphy,h
Ethernet PHY functions header file
2.2
Additional Files (stand-alone version)
The following files have to be used, if the driver is used in a stand-alone version, meaning
not being integrated in the FM3 Low Level Library (LLL):

interrupts.c
Excerpt from LLL interrupts.c for Ethernet ISRs

interrupts.h
Ethernet ISR header file

l3.c
Excerpt from LLL l3.c for LLL functions (Hook)

l3.h
l3.c header file

usbethernetclock.c
LLL clock module (w/o changes)

usbethernetclock.h
LLL clock module header (w/o changes)
2.3
Example Files (stand-alone version)
To give an example of the Ethernet driver usage, the software package also contains
besides main.c module a directory testframework:

port.c
GPIO functions for SK-FM3-176PMC-ETHERNET

ports.h
GPIO header file

scheduler.c
Scheduler functions

scheduler.h
Scheduler header file

stacklessudp.c
Small UDP functions

stacklessudp.h
UDP function header

tasks.c
Example Task functions

tasks.h
Example Task functions header

uart.c
UART init and printf() low level functions

uart.h
UART header file
© Fujitsu Semiconductor Europe GmbH
-7-
AN706-00059-1v0-E
Ethernet Driver Manual
Chapter 2 Ethernet Driver Structure
2.4
Driver System
The following graphic illustrates the Ethernet driver for a single instance.
User Applicaiton
Ethernet
Configuration Data
Ethernet User API
(emac.c/.h)
Internal Data
EMAC PHY functions
(ethphy.c/.h)
internal
external
Ethernet-PHY
Figure 2-1: Resource Driver Structure Example
AN706-00059-1v0-E
-8-
© Fujitsu Semiconductor Europe GmbH
Ethernet Driver Manual
Chapter 2 Ethernet Driver Structure
2.5
Interrupt Flow
The following flow shows how interrupts are handled in the L3:
Application
ISR-Callback
Interrupted
interrupts.c
ResourceName.c
IRQ
Ether_Macx_Handler(void)
Read the IRQxxMON for
confirming which IRQ
function should be called.
Call
EmacIrqHandler((stc_emacn_t*)&EMACx,
&(m_astcEmacInstanceDataLut \
[EmacInstanceIndexEmacx] \
.stcInternData))
pstcEmacInternData->pfn***Callback ()
Emac***CallbackFunction()
Return
Return
Resume
Figure 2-2: Interrupt and Callback Flow Diagram
© Fujitsu Semiconductor Europe GmbH
-9-
AN706-00059-1v0-E
Ethernet Driver Manual
Chapter 3 Using the Ethernet Driver
3 Using the Ethernet Driver
HOW TO SET-UP THE ETHERNET DRIVER
3.1
User Settings in emac_user.h
The file emac_user.h allows the user to configure the Ethernet driver at compile time. Later
configurations on runtime can be done by the API configuration, which is described in
chapter 4.2.
3.1.1 Ethernet Instance Activation
If dual Ethernet is supported by the FM3 MCU the instances can be activated individually by
using L3_ON macro.
/**
******************************************************************************
** \brief User Defines for EMAC resource enable
**
** Possible definitions are L3_ON and L3_OFF.
**
******************************************************************************/
// EMAC
#define L3_PERIPHERAL_ENABLE_EMAC0 L3_ON
#define L3_PERIPHERAL_ENABLE_EMAC1 L3_ON
3.1.2 Ethernet Instance Interrupt Mode
If using Ethernet IRQ support, the instances should be activated by using L3_ON macro. In
that case, ETHER_MACx_IRQHandler() is called when interrupt causes occurred.
/**
******************************************************************************
** \brief Activate IRQ support for Ethernet driver
**
** Possible definitions are L3_ON and L3_OFF.
**
******************************************************************************/
#define EMAC_INTERRUPT_MODE
L3_OFF
3.1.3 Ethernet Instance Interrupt Levels
The interrupt level for each instance can be set individually.
/**
******************************************************************************
** \brief User Emac Interrupt level settings
**
** Possible values are 0 (high priority) to 15 (low priority)
******************************************************************************/
#define L3_IRQ_LEVEL_EMAC0
2
#define L3_IRQ_LEVEL_EMAC1
4
3.1.4 Buffer Location (EMAC0 as example)
The user can select whether to use driver internal buffers or provide pointers to own buffers.
If set to L3_ON the driver buffers are used.
AN706-00059-1v0-E
- 10 -
© Fujitsu Semiconductor Europe GmbH
Ethernet Driver Manual
Chapter 3 Using the Ethernet Driver
/**
******************************************************************************
** \brief EMAC0 User/Driver Buffer location
**
** L3_ON: Driver buffer are used
** L3_OFF: User has to provide buffer memory
******************************************************************************/
#define EMAC0_BUFFERS_IN_DRIVERSPACE L3_ON
3.1.5 Transmission/Reception Ring Size (EMAC0 as example)
The transmission and reception ring size can be adjusted by the following definitions.
/**
******************************************************************************
** \brief EMAC0 Transmission/Reception Ring size
******************************************************************************/
#define EMAC0_TX_RING_SIZE
2
#define EMAC0_RX_RING_SIZE
4
3.1.6 Transmission/Reception Buffer Size (EMAC0 as example)
The transmission and reception buffer size can be set. Note that it must be a multiple of 4.
/**
******************************************************************************
** \brief EMAC0 Transmission/Reception Buffer size
**
** Only used if EMAC0_BUFFERS_IN_DRIVERSPACE == L3_ON
** Must be multiple of 4, 13 Bit value, page 159
******************************************************************************/
#define EMAC0_TX_BUF_SIZE
1520
#define EMAC0_RX_BUF_SIZE
1520
3.1.7 Buffer Settings for EMAC1
The buffer location and Tx/Rx ring and buffer sizes can also be adjusted by defines for
EMAC1.
3.1.8 Starterkits setting
The user can choose a Fujitsu starterkit to use. These are used for setting to each boards.
/**
******************************************************************************
** \brief Support for Fujitsu starterkits
**
** Activate board specific settings by defining exactly one of these symbols:
**
** SK_FM3_176PMC_ETHERNET from Fujitsu Semiconductor Europe:
** STARTERKIT_SK_FM3_176PMC_ETHERNET
**
** If version 1.0 is used, please use additionally:
** SK_FM3_176PMC_ETHERNET_BOARDVERSION10
**
** FSSDC-9B618-EVB from Fujitsu Semiconductor Limited Asia:
** STARTERKIT_FSSDC9B618EVB
**
******************************************************************************/
#define STARTERKIT_SK_FM3_176PMC_ETHERNET
//#define SK_FM3_176PMC_ETHERNET_BOARDVERSION10
//#define STARTERKIT_FSSDC9B618EVB
© Fujitsu Semiconductor Europe GmbH
- 11 -
AN706-00059-1v0-E
Ethernet Driver Manual
Chapter 3 Using the Ethernet Driver
3.1.9 Addresses of external PHYs
The addresses of the used external PHYs for each instance can be adjusted as follows. This
setting varies according to the used board.
/**
******************************************************************************
** \brief Addresses of the used external PHYs
******************************************************************************/
#define EMAC0_PHY_ADDRESS
0
#define EMAC1_PHY_ADDRESS
1
3.1.10 EMAC0 and EMAC1 MAC Address
The so-called physical MAC addresses can be set for each instance.
/**
******************************************************************************
** \brief EMAC0 MAC address
******************************************************************************/
#define EMAC0_MAC_ADDRESS0 0x00
#define EMAC0_MAC_ADDRESS1 0x01
#define EMAC0_MAC_ADDRESS2 0x01
#define EMAC0_MAC_ADDRESS3 0x66
#define EMAC0_MAC_ADDRESS4 0x73
#define EMAC0_MAC_ADDRESS5 0x42
/**
******************************************************************************
** \brief EMAC1 MAC address
******************************************************************************/
#define EMAC1_MAC_ADDRESS0 0x00
#define EMAC1_MAC_ADDRESS1 0x01
#define EMAC1_MAC_ADDRESS2 0x01
#define EMAC1_MAC_ADDRESS3 0x66
#define EMAC1_MAC_ADDRESS4 0x73
#define EMAC1_MAC_ADDRESS5 0x38
3.1.11 Multicast address
The so-called Multicast address can be set for instance.
/**
******************************************************************************
** \brief Multicast address
******************************************************************************/
#define MULTICAST_ADDRESS0 0x00
#define MULTICAST_ADDRESS1 0x00
#define MULTICAST_ADDRESS2 0x00
#define MULTICAST_ADDRESS3 0x00
#define MULTICAST_ADDRESS4 0x00
#define MULTICAST_ADDRESS5 0x00
3.1.12 External PHY reset pins
To tell the driver at which port pin the reset inputs of the external PHYs are connected, an
address pointer to the GPIO bit-band alias address of the device’s header file has to be
used. The following definition shows an example of how to do this. Here Port Pin P45 is
used for PHY0 and P44 for PHY1.
AN706-00059-1v0-E
- 12 -
© Fujitsu Semiconductor Europe GmbH
Ethernet Driver Manual
Chapter 3 Using the Ethernet Driver
/**
******************************************************************************
** \brief External PHY reset pins
**
** Use GPIO addresses of the bit-band alias definitions of the device header
** file.
******************************************************************************/
#define EMAC0_PHY_RESET_PIN ((uint32_t*) &bFM3_GPIO_PDOR4_P5)
#define EMAC1_PHY_RESET_PIN ((uint32_t*) &bFM3_GPIO_PDOR4_P4)
3.1.13 PLL Clocking Mode
To set the PLL for Ethernet clock to on or off, the following definition is used.
/**
******************************************************************************
** \brief PLL for External PHY
**
** L3_ON: PLL is used for PHY clock
** L3_OFF: PLL is not used for PHY clock
******************************************************************************/
#define EMAC_ECOUT L3_OFF
3.1.14 PHY Management Bus Settings
To determine, which EMAC instance uses the management bus for the external PHYs the
following definitions are used. This can be useful if both PHYs shall be connected to a
common management bus.
/**
******************************************************************************
** \brief Management Bus Definition
******************************************************************************/
#define EMAC0_MANAGEMENTBUS
EMAC0
#define EMAC1_MANAGEMENTBUS
EMAC1
3.1.15 RMII PHY Interface Usage
The PHY interface can be set to RMII by using L3_ON for the following definition. Otherwise
(L3_ON), MII is used. Please note that RMII is necessary in order to use both Ethernet
interfaces simultaneously.
/**
******************************************************************************
** \brief RMII PHY interface usage
******************************************************************************/
#define EMAC_PHYINTERFACE_RMII
L3_ON
3.1.16 Buffer Fragmentation
If L3_ON is used for EMAC_BUFFERS_NOT_FRAGMENTED the driver assumes, that all
buffers are not fragmented. This option must be set to L3_ON.
/**
******************************************************************************
** \brief EMAC Buffer fragmentation
**
** All buffers are large enough to contain a whole Ethernet frame (MTU size)
******************************************************************************/
#define EMAC_BUFFERS_NOT_FRAGMENTED
L3_ON
© Fujitsu Semiconductor Europe GmbH
- 13 -
AN706-00059-1v0-E
Ethernet Driver Manual
Chapter 3 Using the Ethernet Driver
3.1.17 Checksum Insertion Control
The following controls can be used:
0
Checksum insertion disabled
1
Only IP header checksum calculation and insertion are enabled
2
IP header checksum and payload checksum and insertion are enabled, but pseudoheader checksum is not calculated in hardware
3
IP header checksum and payload checksum and insertion are enabled, and pseudoheader checksum is not calculated in hardware
/**
******************************************************************************
** \brief CIC (Checksum Insertion Control)
**
** These bits control the checksum calculation and insertion. Bit encodings
** are as shown below.
** - 0 Checksum Insertion Disabled.
** - 1 Only IP header checksum calculation and insertion are enabled.
** - 2 IP header checksum and payload checksum calculation and insertion are
**
enabled, but pseudo-header checksum is not calculated in hardware.
** - 3 IP Header checksum and payload checksum calculation and insertion are
**
enabled, and pseudo-header checksum is calculated in hardware.
******************************************************************************/
#define EMAC_COE_MODE
3
3.1.18 ICMP Checksum Bug Work-Around
If L3_ON is used for EMAC_ENABLE_ICMP_CHECKSUM_BUG_WORKAROUND,the driver will
overwrite the checksum field of a ping reply (ICMP echo reply) header with zeros. This
option can be useful if EMAC_COE_MODE is set to 3 and you observe checksum errors while
using the ping command toward the embedded system.
AN706-00059-1v0-E
- 14 -
© Fujitsu Semiconductor Europe GmbH
Ethernet Driver Manual
Chapter 3 Using the Ethernet Driver
/**
******************************************************************************
** \brief Activate work-around for bug in uIP and LwIP TCP/IP stacks
**
** For the Checksum Offload Engine to work correctly, the checksum fields in
** the IP header, as well as in the TCP, UDP or ICMP header must be 0.
**
** LwIP up to the recent stable 1.4.0 version, and current uIP have an option
** to disable software checksum calculation for IP, UDP and TCP.
** A similar option ICMP was (apparently by accident) omitted.
**
** If EMAC_ENABLE_ICMP_CHECKSUM_BUG_WORKAROUND is set to L3_ON,
** every frame to be sent will be checked if it is an ICMP echo reply
** and if so, its checksum field cleared.
**
** This slows down every packet transmission and should be fixed in the
** original code. This is a known bug and is expected to be fixed
** in future releases of LwIP.
**
** For other TCP/IP stacks, this work-around is usually not necessary
** and should be disabled.
**
** Fujitsu tries to retain third-party software in software examples in its
** original state as far as possible in order to retain compatibility to the
** maximum possible extend.
**
******************************************************************************/
#define EMAC_ENABLE_ICMP_CHECKSUM_BUG_WORKAROUND
L3_ON
3.1.19 Multicast Address Filter
If L3_ON is used for EMAC_MULTICAST_FILTER the driver assumes, the user can filter
receiving frame in multicast address.
/**
******************************************************************************
** \brief Activate multicast filtering
**
** L3_ON: Multicast filtering is used
** L3_OFF: Multicast filtering is not used
**
******************************************************************************/
#define EMAC_MULTICAST_FILTER
L3_OFF
© Fujitsu Semiconductor Europe GmbH
- 15 -
AN706-00059-1v0-E
Ethernet Driver Manual
Chapter 3 Using the Ethernet Driver
3.2
Extra Settings in emac.c
The user can use various functions by adding following sample cords.
3.2.1 Filter setting for Multicast MAC address
If adding following sample cords in Emac_Autonegotiate(), the user can receive a frame
which is filtered in multicast address. In this case, the MAC filters the value that masked bit0bit7 of multicast address.
pstcEmac->MAR1H = (uint32_t)(((au8GenericMulticast[5])
|((au8GenericMulticast[4])
);
pstcEmac->MAR1L = (uint32_t)(((au8GenericMulticast[3])
|((au8GenericMulticast[2])
|((au8GenericMulticast[1])
|((au8GenericMulticast[0])
<<
<<
8)
0)
<< 24)
<< 16)
<< 8)
<< 0));
pstcEmac->MAR1H |= (uint32_t)0x20000000;
pstcEmac->MAR1H |= (uint32_t)0x80000000;
3.3
Usage Examples
This section explains the usage of the FM3 Ethernet driver by concrete example.
3.3.1 How to set up an Ethernet interface
If the user wants to use both EMAC0 and EMAC1, initialize them as follows. This setting
must be done after the initialization of board pins. If necessary, set callback functions
beforehand.
stc_emac_config_t stcEmacConfig;
// Board pins setting for using Ethernet
ConfigureEthernetPins();
// callback functions setting for EMAC0
stcEmacConfig.pfnRxCallback = EMAC0RxCallbackFunc;
stcEmacConfig.pfnTxCallback = EMAC0TxCallbackFunc;
// Ethernet MAC 0 initialization
Emac_Init(&EMAC0, &stcEmacConfig);
Emac_Autonegotiate(&EMAC0);
// callback functions setting for EMAC1
stcEmacConfig.pfnRxCallback = EMAC1RxCallbackFunc;
stcEmacConfig.pfnTxCallback = EMAC1TxCallbackFunc;
// Ethernet MAC 1 initialization
Emac_Init(&EMAC1, &stcEmacConfig);
Emac_Autonegotiate(&EMAC1);
It is recommended to call Emac_Autonegotiate() regularly to react to changed
connection states.
AN706-00059-1v0-E
- 16 -
© Fujitsu Semiconductor Europe GmbH
Ethernet Driver Manual
Chapter 3 Using the Ethernet Driver
3.3.2 How to Send a Frame
The user can transmit a frame by calling Emac_TxFrame()after initialization. This function
has three parameters; 1st a pointer, which selects the EMAC (0 or 1), 2nd the address of the
buffer to be sent, and 3rd the number of bytes to be sent by this function.
The buffer must contain the protocol headers and payload beforehand. The following
example sets up and transmits a UDP frame.
uint8_t ua8EthBuf[1500];
uint8_t ua8Payload[] = "Hello World!”;
// creating an Ethernet frame with IP and UDP header
TxBufferUDPFill(ua8EthBuf, ua8Payload, sizeof(ua8Payload));
ua8EthBuf[42 + sizeof(ua8Payload) - 3] = (u8NumberOfCalls + '0');
// transmit the frame
Emac_TxFrame(&EMAC0, ua8EthBuf, 42 + sizeof(ua8Payload));
3.3.3 How to Receive a Frame
If interrupt mode is activated, the user can receive a frame by using memcpy() after calling
Emac_RxFrame_GetBufPtr(). Afterwards, It is necessary to set next descriptor by calling
Emac_RxFrame_ReleaseBuf().
If interrupt mode is not activated, the user can receive a frame by calling Emac_Rx().
#if (EMAC_INTERRUPT_MODE == L3_ON)
u8pbuffer =(uint8_t *) Emac_RxFrame_GetBufPtr(pstcEmac);
if (NULL != u8pbuffer)
{
memcpy((uint8_t*)p->payload, buffer, p->len);
}
Emac_RxFrame_ReleaseBuf(pstcEmac);
#else
p->len = Emac_RxFrame(pstcEmac,p->payload);
#endif
© Fujitsu Semiconductor Europe GmbH
- 17 -
AN706-00059-1v0-E
Ethernet Driver Manual
Chapter 3 Using the Ethernet Driver
3.3.4 Interrupt Operation
For using interrupt mode, the user must set EMAC_INTERRUPT_MODE to L3_ON.
#define EMAC_INTERRUPT_MODE
L3_ON
Please add a necessary interrupt in Emac_InitIrq(). By the default setting the abnormal
interrupt is not admitted.
pstcEmac->stcIER.NIE = 1;
pstcEmac->stcIER.RIE = 1;
pstcEmac->stcIER.TIE = 1;
When an interrupt occurs, EmacIrqHandler() is called. Please change the following code
in Emac_IrqHandler() as needed. By the default code, in the case of transmission or
reception completion, a callback function is called.
if(pstcEmac->stcSR.RI != 0)
{
pstcEmac->stcSR.RI = 1;
if(pstcEmacInternData->pfnRxCallback != NULL)
{
pstcEmacInternData->pfnRxCallback();
}
}
if(pstcEmac->stcSR.TI != 0)
{
pstcEmac->stcSR.TI = 1;
if(pstcEmacInternData->pfnTxCallback != NULL)
{
pstcEmacInternData->pfnTxCallback();
}
}
AN706-00059-1v0-E
- 18 -
© Fujitsu Semiconductor Europe GmbH
Ethernet Driver Manual
Chapter 4 Ethernet Driver Configuration and Data Types
4 Ethernet Driver Configuration and Data Types
THE DATA STRUCTURE OF THE ETHERNET INSTANCE CONFIGURATION
4.1
Preface
Besides the static compiler definitions the user can configure dynamically an Ethernet
instance by using an individual configuration. The data contents of this configuration are
used by the initialization function to set the hardware and internal data. Afterwards this
configuration is not needed to be saved.
4.2
Configuration Structure
The following data is
stc_emac_config_t.
used
for
the
Ethernet
driver’s
configuration
structure
Type
Field
Possible Values
Description
func_ptr_t
pfnRxCallback
-
Function pointer to user’s
reception callback function
func_ptr_t
pfnTxCallback
-
Function pointer to user’s
transmission callback
function
func_ptr_t
pfnErrorCallback
-
Function pointer to user’s
error callback function
4.3
Link Status enumerated Type
The Ethernet driver uses an own enumerated type for the link status. It is defined in
en_emac_link_t as follows:
Enumerator
Description
EMAC_LinkStatusLinkDown
No connection established
EMAC_LinkStatusLinkUp
Connection established, ready for data
exchange, MAC has been configured
EMAC_LinkStatusAutonegotiationInProgress
Auto-negotiation started and in progress
EMAC_LinkStatusAutonegotiationSuccessful
Auto-negotiation agreement with remote
nodes completed
EMAC_LinkStatusAutonegotiationNotSupported
Remote node does not support autonegotiation
EMAC_LinkStatusInvalidParameter
One or more user configuration illegal
EMAC_LinkStatusUnknownError
In indeterminable error occurred
4.4
Link Mode enumerated Type
Also the link mode is defined as
en_emac_link_mode_t. Its content is:
an
enumerated
Enumerator
Description
EMAC_LinkModeHalfDuplex10M
Half-Duplex Mode 10 MBit/s
EMAC_LinkModeFullDuplex10M
Full-Duplex Mode 10 MBit/s
EMAC_LinkModeHalfDuplex100M
Half-Duplex Mode 100 MBit/s
EMAC_LinkModeFullDuplex100M
Full-Duplex Mode 100 MBit/s
© Fujitsu Semiconductor Europe GmbH
- 19 -
type
with
the
name
AN706-00059-1v0-E
Ethernet Driver Manual
Chapter 5 Ethernet Driver API
5 Ethernet Driver API
DETAILED DESCRIPTION OF THE ETHERNET DRIVER API AND EXAMPLE CODE
5.1
Preface
This chapter explains the user API functions of the Ethernet driver in detail.
5.1.1 Emac_Init()
This function initializes and Ethernet instance. pstcEmac must be either
(stc_emacn_t*)&EMAC0 or (stc_emacn_t*)&EMAC1. pstcConfig is just the address
to the user configuration, e.g. &stcEmacConfig.
Prototype
en_result_t Emac_Init( volatile stc_emacn_t* pstcEmac,
stc_emac_config_t*
pstcConfig
)
Parameter Name
[in] pstcEmac
Description
[in] pstcConfig
Ethernet configuration parameters
Return Values
Description
Ok
Channel disabled
ErrorInvalidParameter
If one of the following conditions is met:
pstcEmac == NULL
pstcEmacInternData == NULL
(invalid or disabled Ethernet unit)
Ethernet macro instance pointer
5.1.2 Emac_DeInit()
This function de-initializes and Ethernet instance.
Prototype
en_result_t Emac_DeInit( volatile stc_emacn_t* pstcEmac )
Parameter Name
Description
[in] pstcEmac
Ethernet macro instance pointer
Return Values
Ok
Description
ErrorInvalidParameter
If the following condition is met:
pstcEmac == NULL
AN706-00059-1v0-E
Channel disabled
- 20 -
© Fujitsu Semiconductor Europe GmbH
Ethernet Driver Manual
Chapter 5 Ethernet Driver API
5.1.3 Emac_TxFrame()
This function is used to send a transmission frame.
Prototype
en_result_t Emac_TxFrame( volatile stc_emacn_t* pstcEmac,
uint8_t*
pu8Buf,
uint16_t
u16Len
)
Parameter Name
Description
[in] pstcEmac
Ethernet macro instance pointer
[in] pu8Buf
Pointer to a byte array buffer
[in] u16Len
Length of the byte array buffer
Return Values
Description
Ok
Channel disabled
ErrorInvalidParameter
If the following condition is met:
pstcEmac == NULL
5.1.4 Emac_GetRxFrameLength()
This function returns the length of a received frame.
Prototype
uint16_t Emac_GetRxFrameLength( volatile stc_emacn_t* pstcEmac )
Parameter Name
[in] pstcEmac
Description
Return Values
Description
uint16_t
Length of the received frame or 0 if nothing was
received or pstcEmac == NULL
Ethernet macro instance pointer
5.1.5 Emac_RxFrame()
Copies a received frame into a buffer.
Prototype
uint16_t Emac_RxFrame( volatile stc_emacn_t* pstcEmac,
uint8_t*
pu8Buf
)
Parameter Name
Description
[in] pstcEmac
Ethernet macro instance pointer
[in] pu8Buf
Pointer to a byte array buffer
Return Values
Description
uint16_t
Length of the received frame or 0 if nothing was
received or pstcEmac == NULL
© Fujitsu Semiconductor Europe GmbH
- 21 -
AN706-00059-1v0-E
Ethernet Driver Manual
Chapter 5 Ethernet Driver API
5.1.6 Emac_GetLinkStatus()
This function returns the recent link status. It uses the type en_emac_link_status_t
described in chapter 0.
Prototype
en_emac_link_status_t Emac_GetLinkStatus( volatile stc_emacn_t* pstcEmac )
Parameter Name
[in] pstcEmac
Description
Return Values
Description
en_emac_link_status_t
Returns:
Ethernet macro instance pointer







EMAC_LinkStatusLinkDown
EMAC_LinkStatusLinkUp
EMAC_LinkStatusAutonegotiationInProgress
EMAC_LinkStatusAutonegotiationSuccessful
EMAC_LinkStatusAutonegotiationNotSupported
EMAC_LinkStatusInvalidParameter
EMAC_LinkStatusUnknownError
See also description in chapter 4.3.
5.1.7 Emac_GetLinkMode()
This function returns the recent link mode. It uses the type en_emac_link_mode_t
described in chapter 4.4.
Prototype
en_emac_link_mode_t Emac_GetLinkMode( volatile stc_emacn_t* pstcEmac )
Parameter Name
[in] pstcEmac
Description
Return Values
Description
en_emac_link_mode_t
Returns:
Ethernet macro instance pointer





EMAC_LinkModeAutonegotiation
EMAC_LinkModeHalfDuplex10M
EMAC_LinkModeFullDuplex10M
EMAC_LinkModeHalfDuplex100M
EMAC_LinkModeFullDuplex100M
See also description in chapter 4.4.
AN706-00059-1v0-E
- 22 -
© Fujitsu Semiconductor Europe GmbH
Ethernet Driver Manual
Chapter 5 Ethernet Driver API
5.1.8 Emac_SetLinkMode()
This function sets the link mode. It uses the type en_emac_link_mode_t described in
chapter 4.4 as an argument and return value
Prototype
en_emac_link_mode_t Emac_SetLinkMode( volatile stc_emacn_t* pstcEmac,
en_emac_link_mode_t
enLinkMode
)
Parameter Name
Description
[in] pstcEmac
Ethernet macro instance pointer
[in] enLinkMode
Desired link mode. See below at Return Values
description for enumerated value list.
Return Values
Description
en_emac_link_mode_t
Returns successful mode:





EMAC_LinkModeAutonegotiation
EMAC_LinkModeHalfDuplex10M
EMAC_LinkModeFullDuplex10M
EMAC_LinkModeHalfDuplex100M
EMAC_LinkModeFullDuplex100M
See also description in chapter 4.4.
5.1.9 Emac_Autonegotiate()
This function performs the auto-negotiation of the Ethernet macro. It should be called
periodically.
Prototype
en_emac_link_status_t Emac_Autonegotiate( volatile stc_emacn_t* pstcEmac )
Parameter Name
[in] pstcEmac
Description
Return Values
Description
en_emac_link_status_t
Returns:
Ethernet macro instance pointer







EMAC_LinkStatusLinkDown
EMAC_LinkStatusLinkUp
EMAC_LinkStatusAutonegotiationInProgress
EMAC_LinkStatusAutonegotiationSuccessful
EMAC_LinkStatusAutonegotiationNotSupported
EMAC_LinkStatusInvalidParameter
EMAC_LinkStatusUnknownError
See also description in chapter 4.3.
© Fujitsu Semiconductor Europe GmbH
- 23 -
AN706-00059-1v0-E
Ethernet Driver Manual
Chapter 5 Ethernet Driver API
5.1.10 Emac_SetDescToTxBuf()
This function is only available if the buffer locations are defined in Ethernet driver space by
user via EMAC0_BUFFERS_IN_DRIVERSPACE and EMAC1_BUFFERS_IN_DRIVERSPACE.
Prototype
en_result_t Emac_SetDescToTxBuf( volatile stc_emacn_t* pstcEmac,
uint16_t
u16DescNumber
uint8_t*
pu8UserBuf,
uint16_t
u16BufLength
)
Parameter Name
[in] pstcEmac
Description
[in] u16DescNumber
DMA descriptor number
[in] pu8UserBuf
Pointer to a byte array buffer
[in] u16BufLength
Length of the byte array buffer
Return Values
Ok
Description
ErrorInvalidParameter
If the following condition is met:
pstcEmac == NULL
Ethernet macro instance pointer
Channel disabled
5.1.11 Emac_SetDescToRxBuf()
This function is only available if the buffer locations are defined in Ethernet driver space by
user via EMAC0_BUFFERS_IN_DRIVERSPACE and EMAC1_BUFFERS_IN_DRIVERSPACE.
Prototype
en_result_t Emac_SetDescToRxBuf( volatile stc_emacn_t* pstcEmac,
uint16_t
u16DescNumber
uint8_t*
pu8UserBuf,
uint16_t
u16BufLength
)
Parameter Name
[in] pstcEmac
Description
[in] u16DescNumber
DMA descriptor number
[in] pu8UserBuf
Pointer to a byte array buffer
[in] u16BufLength
Length of the byte array buffer
Return Values
Ok
Description
ErrorInvalidParameter
If the following condition is met:
pstcEmac == NULL
AN706-00059-1v0-E
Ethernet macro instance pointer
Channel disabled
- 24 -
© Fujitsu Semiconductor Europe GmbH
Ethernet Driver Manual
Chapter 5 Ethernet Driver API
5.1.12 Emac_SetEcout()
This function allows the PLL clock to be used. If EMAC_ECOUT is set to L3_ON, the E_COUT
pin is configured as output and USB/Ethernet Clock activated.
Prototype
en_result_t Emac_SetEcout( void )
Parameter Name
Description
void
-
Return Values
Description
Ok
Completed
5.1.13 Emac_RxFrame_GetBufPtr()
This function returns a pointer to the buffer containing the received frame. It allows the
usage of an optimized rx routine to save copy operations. This function is only available if
interrupt mode is enabled. (Please refer to chapter 3.3.3)
Prototype
void * Emac_RxFrame_GetBufPtr( volatile stc_emacn_t* pstcEmac )
Parameter Name
[in] pstcEmac
Description
Return Values
void *
Description
Ethernet macro instance pointer
Pointer of the received frame buffer or 0 if nothing
was received or pstcEmac == NULL
5.1.14 Emac_RxFrame_ReleaseBuf()
This function sets next descriptor. It can be used to release a buffer after its contents have
been processed by an optimized rx routine. This function is only available if interrupt mode is
enabled. (Please refer capter3.3.3)
Prototype
void Emac_RxFrame_ReleaseBuf( volatile stc_emacn_t* pstcEmac )
Parameter Name
[in] pstcEmac
Description
Return Values
Description
void
-
© Fujitsu Semiconductor Europe GmbH
Ethernet macro instance pointer
- 25 -
AN706-00059-1v0-E
Ethernet Driver Manual
Chapter 6 Additional Information
6 Additional Information
Information about FUJITSU Semiconductor’s Microcontroller can be found on the following
Internet page:
http://mcu.emea.fujitsu.com/
The software examples related to this application note are:
mb9bfxxx_l3
mb9bfxxx_ethernet_driver
mb9bfxxx_ethernet_uip
mb9bfxxx_ethernet_lwip
mb9bfxxx_ethernet_uip_freertos
All examples can be found on the following Internet page:
http://mcu.emea.fujitsu.com/mcu_product/mcu_all_software.htm
AN706-00059-1v0-E
- 26 -
© Fujitsu Semiconductor Europe GmbH
Ethernet Driver Manual
List of Figures
List of Figures
Figure 2-1: Resource Driver Structure Example ..................................................................... 8
Figure 2-2: Interrupt and Callback Flow Diagram ................................................................... 9
© Fujitsu Semiconductor Europe GmbH
- 27 -
AN706-00059-1v0-E
Similar pages