Escolar Documentos
Profissional Documentos
Cultura Documentos
Ethernet Frame
Transmission Using The
eZ80F915050 Module
AN021201-1104
ZiLOG is a registered trademark of ZiLOG Inc. in the United States and in other countries. All other
products and/or service names mentioned herein may be trademarks of the companies with which they are
associated.
Information Integrity
The information contained within this document has been verified according to the general principles of
electrical and mechanical engineering. Any applicable source code illustrated in the document was either
written by an authorized ZiLOG employee or licensed consultant. Permission to use these codes in any
form, besides the intended application, must be approved through a license agreement between both
parties. ZiLOG will not be responsible for any code(s) used beyond the intended application. Contact the
local ZiLOG Sales Office to obtain necessary license agreements.
Document Disclaimer
© 2004 by ZiLOG, Inc. All rights reserved. Information in this publication concerning the devices,
applications, or technology described is intended to suggest possible uses and may be superseded.
ZiLOG, INC. DOES NOT ASSUME LIABILITY FOR OR PROVIDE A REPRESENTATION OF ACCURACY
OF THE INFORMATION, DEVICES, OR TECHNOLOGY DESCRIBED IN THIS DOCUMENT. ZiLOG
ALSO DOES NOT ASSUME LIABILITY FOR INTELLECTUAL PROPERTY INFRINGEMENT RELATED
IN ANY MANNER TO USE OF INFORMATION, DEVICES, OR TECHNOLOGY DESCRIBED HEREIN OR
OTHERWISE. Except with the express written approval ZiLOG, use of information, devices, or technology
as critical components of life support systems is not authorized. No licenses or other rights are conveyed,
implicitly or otherwise, by this document under any intellectual property rights.
AN021201-1104
Application Note
Ethernet Frame Transmission Using The eZ80F915050 Module
iii
Table of Contents
List of Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iv
List of Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iv
Abstract . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
eZ80Acclaim!™ Flash Microcontrollers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Hardware Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
eZ80F91 50 MHz Module Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
eZ80F91 MCU Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
eZ80® CPU Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Ethernet Data Transmission . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Developing an eZ80F91 MCU Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Hardware Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Software Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Testing/Demonstrating the Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Appendix A—References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Appendix B—Flowcharts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Appendix C—Source Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
C Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Header Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
iv
List of Figures
Figure 1. Top-Level View of Hardware Components . . . . . . . . . . . . . . . . . . . . . 2
Figure 2. The Role of the eZ80F915050 Module in Ethernet Connectivity . . . . . 4
Figure 3. The eZ80F915050 Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Figure 4. Ethernet Connectivity Blocks on the eZ80F91 MCU . . . . . . . . . . . . . . 5
Figure 5. EMAC Shared Memory Configuration . . . . . . . . . . . . . . . . . . . . . . . . . 9
Figure 6. Buffers in EMAC Shared Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 7. Contents of Descriptor Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Figure 8. Block Diagram Representation of Hardware Setup . . . . . . . . . . . . . . 14
Figure 9. The Main Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
List of Tables
Table 1. Receive Descriptor Status Bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Table 2. Transmit Descriptor Status Bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Table 3. List of References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Abstract
This Application Note demonstrates the use of ZiLOG products to communicate
over the Ethernet by transferring a frame consisting of data from one unit to
another.
The eZ80F91 MCU features an on-chip Ethernet Media Access Controller
(EMAC) unit with a full-functional 10/100 Mbps Media-Independent Interface (MII).
The eZ80F91 50 MHz (eZ80F915050) module includes an eZ80F91 MCU as well
as a PHY from Advanced Micro Devices that forms the physical transceiver layer
for Ethernet communication. An RJ45 connector is used to plug in standard Ether-
net cables. These features make it easier to use the eZ80F91 MCU for transmit-
ting data over the Ethernet.
Two eZ80F91 development kits, each with eZ80F915050 modules, are connected
using a crossover Ethernet cable. Data is transmitted from one eZ80F91 device to
the other. On the transmission side, user-entered data is compiled into an IEEE
802.3 frame; on the reception side, data is extracted from the frame and displayed
to the user via the HyperTerminal application.
AN021201-1104 Abstract
Application Note
Ethernet Frame Transmission Using The eZ80F915050 Module
Discussion
This Application Note is intended to demonstrate the capability of the EMAC unit
on the eZ80F91 MCU. Transmitting data over the Ethernet offers multiple options
that can be configured using the eZ80F91 MCU’s many registers. In addition, this
document also discusses the framing of data in accordance with IEEE 802.3 stan-
dards.
An IEEE 802.3 frame consists of a 14-byte header, 46 to 1500 bytes of data, and
an optional 4-byte cyclic redundancy check. The 14-byte header consists of a 6-
byte source address, a 6-byte destination address, and a 2-byte type/length field.
To explain data transmission requires a brief discussion of the OSI Model, which
consists of seven layers, as described below, in order from the top layer to the
bottom layer.
Application. Governs how a particular application uses a network
Presentation. Governs how data is represented
Session. Governs the establishment of communication with a remote system
Transport. Governs how data is transferred
Network. Governs how assignments and the forwarding of packets are addressed
Data Link. Governs how frames are sent over a network
Physical. Governs basic network hardware
For Ethernet data transmission, information from the upper five layers is compiled
into the Data field of an IEEE 802.3 frame. The Data Link and Physical layers
depend very closely on the hardware, and must be understood clearly to imple-
ment the top layers. This Application Note will show how the Physical and Data
Link layers are implemented using ZiLOG development kits.
Hardware Components
A top-level view of the application’s required hardware components is shown in
Figure 1.
®
eZ80
eZ80F915050
Development
Module
Platform Ethernet
cable
AN021201-1104 Discussion
Application Note
Ethernet Frame Transmission Using The eZ80F915050 Module
eZ80F915050 Module
ZiLOG’s eZ80F915050 Module includes AMD’s NetPHY AM79C874, a RJ45 con-
nector to connect to the Ethernet via cable, and the eZ80F91 MCU, which fea-
tures an on-chip Ethernet Media Access Controller (EMAC) unit. The PHY and the
EMAC unit together implement the Physical Layer for Ethernet data transmission.
Figure 3 shows the eZ80F915050 Module with the eZ80F91 MCU, the AMD
79C874 PHY, and the RJ45 connector. In addition, the eZ80F915050 module con-
tains 512 KB SRAM that can be used to store programming instructions. The
range of module memory can be set by the user.
Ethernet Cables
The Ethernet cable that connects the eZ80® Development Platform and the
eZ80F81 Module to the Ethernet can either be a patch cable or a crossover cable,
depending on the configuration of the network, as explained below.
Patch Cable. When an Ethernet hub is used, CAT5 patch cables are used to trans-
mit data. An Ethernet hub takes care of connecting the signals to make an Ether-
net network. While transferring frames an IP address is not used. For this
application, patch cables are therefore used only in the programming interface.
Patch cables are usually blue in color and occasionally green.
Crossover Cable. Crossover cables allow connection without a hub. In a crossover
cable, the signal lines are crossed over so that the Transmit pin on one side gets
connected to the Receive pin on other side and vice versa. These cables are usu-
ally orange in color to differentiate them from patch cables.
AN021201-1104 Discussion
Application Note
Ethernet Frame Transmission Using The eZ80F915050 Module
MII
eZ80F91 RJ45
PHY
MCU Connector
Ethernet
cable
RJ45
Connector
eZ80F91 AMD
with 79C874
On-Chip PHY
EMAC
Module
eZ80F91 MCU
The eZ80F91 MCU is based on the eZ80® CPU core. The eZ80F91 MCU blocks
used in this application are the EMAC unit, the EMAC Control Registers, a mem-
ory address decoder, the UART block, an interrupt controller, and on-chip mem-
ory. Further details about the eZ80® blocks are discussed in the eZ80F91 MCU
Description section on the next page.
AN021201-1104 Discussion
Application Note
Ethernet Frame Transmission Using The eZ80F915050 Module
PHY
PHY is a Physical Layer Transceiver device. Different manufacturers produce
PHYs with different characteristics. The hardware described in this Application
note uses an eZ80F915050 Module that includes AMD’s Am79C874 PHY. The
AMD PHY can receive and transmit data reliably at over 130 meters. It also
includes input filtering and output wave shaping for unshielded twisted pair opera-
tion. In addition, if set to autonegotiation mode, it can determine network speed
and the full or half-duplex modes of operation. For more information related to the
AMD PHY, refer to AMD documentation.
MII Interface
The MII interface provides a simple standard connection between the EMAC and
the PHY. The MII is designed to make the differences more transparent between
various media, such as shielded or unshielded differential wire pairs, Ethernet
cables, and the MAC sublayer. The end result is that the CPU can act indepen-
dently of media type.
The MII consists of 15 signals, including a 4-bit-wide receive data bus, a 4-bit-
wide transmit data bus, and control signals to facilitate data transfers between the
PHY and the EMAC.
RJ45 Connector
A RJ45 connector is used to connect the Ethernet cables to the PHY for the pur-
pose of transmitting data over the Ethernet.
Internal EMAC
Memory Registers
® EMAC
External eZ80 EMAC
Shared
Memory CPU Unit
Memory MII
AN021201-1104 Discussion
Application Note
Ethernet Frame Transmission Using The eZ80F915050 Module
The eZ80F91 MCU consists of eZ80® CPU, on-chip memory, and an Ethernet
Media Access Controller consisting of EMAC registers, EMAC shared memory,
and an EMAC unit.
Memory Description
Memory provides for the storage of instructions that, when executed by the eZ80®
CPU, set up and command the EMAC and the PHY to send and receive Ethernet
frames. Memory is included on the eZ80F91 MCU, the eZ80F915050 Module,
and on the eZ80® Development Platform. For a map of the memory available on
the chip, module, and platform, refer to the eZ80F91 Product Specification
(PS0192) and the eZ80F91 Module Product Specification (PS0193). The code
used for this application is listed in Appendix C on page 25.
On-Chip Memory. The eZ80F91 MCU features 8 KB of on-chip SRAM that, on
power-up, is mapped to the address range FFE000h–FFFFFFh. This RAM memory
can be mapped to the top of any 64 KB block, or it can be disabled.
The eZ80F91 MCU also features 256 KB of Flash memory that can be used to
store programming instructions. This memory can be mapped anywhere in the
address space.
Module Memory. The eZ80F915050 Module contains 512 KB of SRAM for storing
program instructions. The user can map this memory to a different address range,
if appropriate.
Platform Memory. The eZ80® Development Platform contains 512 KB of SRAM in
the address range B80000h–BFFFFFh that can be used to store programming
instructions.
AN021201-1104 Discussion
Application Note
Ethernet Frame Transmission Using The eZ80F915050 Module
below. For more details, please refer to the EMAC chapter of the eZ80F91 Prod-
uct Specification (PS0192).
EMAC Test Register. The EMAC_TEST register is used to configure the test
modes for various functionalities.
EMAC Configuration Register 1. The EMAC_CFG1 register allows control of the
padding, autodetection, cyclic redundancy checking, full-duplex or half-duplex
mode, field length checking, maximum packet ignores, and proprietary header
options.
EMAC Configuration Register 2. The EMAC_CFG2 register controls the behavior
of the back pressure and late collision data from the descriptor table.
EMAC Configuration Register 3. The EMAC_CFG3 register controls preamble
length and value, excessive deferment, and the number of retransmission tries
before the packet is aborted.
EMAC Configuration Register 4. The EMAC_CFG4 register controls pause control
frame behavior, back pressure, and receive frame acceptance.
EMAC Station Address Registers. The six EMAC_STAD_0 to EMAC_STAD_5 reg-
isters are used as the source address when transmitting frames and compared to
destination address when receiving frames.
EMAC Transmit Pause Timer Value Registers. The EMAC_TPTV_H and
EMAC_TPTV_L registers are inserted into outgoing pause control frames as the
pause timer value upon asserting a Transmit Pause Control Frame (TPCF—bit 2
of EMAC Configuration Register 4).
EMAC Maximum Frame Length Registers. The EMAC_MAXF_H and
EMAC_MAXF_L registers determine the length of the maximum frame that can be
received.
EMAC Address Filter Register. The EMAC_AFR register functions as a filter to
control promiscuous mode as well as multicast and broadcast messaging.
EMAC Hash Table Registers. For the eight EMAC_HTBL_0 to EMAC_HTBL_7
registers, when a multicast message is received, the first 6 bits of the CRC are
decoded and added to a table that points to a single bit within the hash table
matrix. If the selected bit = 1, the multicast packet is accepted, if the bit = 0, the
multicast packet is rejected. This application allows reception of all multicast mes-
sages by configuring it in the EMAC Address Filter Register.
EMAC MII Management Register. The EMAC_MIIMGT register is used to control
the external PHY attached to the MII. A rising edge on bit 7 causes
[EMAC_CTLD_H, EMAC_CTLD_L] control data to be transmitted to an external
PHY if the MII is not busy. Similarly, a rising edge on bit 6 causes status to be read
from the external PHY via [EMAC_PRSD_H, EMAC_PRSD_L] if the MII is not
busy.
AN021201-1104 Discussion
Application Note
Ethernet Frame Transmission Using The eZ80F915050 Module
AN021201-1104 Discussion
Application Note
Ethernet Frame Transmission Using The eZ80F915050 Module
RHBP
Rx Buffer
BP
Tx Buffer
TLBP
Lower Memory Address
The eZ80® CPU places packets to be transmitted into this shared memory and
reads received packets from shared memory. The EMAC reads packets to be
transmitted from shared memory and stores received packets in shared memory.
Access to shared memory is through a semaphore bit (bit 16) in the descriptor
table at the beginning of each packet. Details for the descriptor table and sema-
phore bit are explained in the following paragraphs.
EMAC shared memory is divided into transmit buffer and receive buffer areas, as
defined by the following three registers:
EMAC TLBP. This register points to the start of the transmit buffer in EMAC shared
memory.
EMAC BP. This register points to the start of the receiver buffer.
EMAC RHBP. This register points to the end of the receiver buffer + 1.
AN021201-1104 Discussion
Application Note
Ethernet Frame Transmission Using The eZ80F915050 Module
10
In Figure 5, EMAC shared memory is divided into transmit buffer and receive
buffer areas, as defined by the following three registers:
EMAC TLBP. This register points to the start of the transmit buffer in EMAC shared
memory.
EMAC BP. This register points to the start of the receiver buffer.
EMAC RHBP. This register points to the end of the receiver buffer + 1.
The Transmit and Receive shared memory is divided into buffers of 32, 64, 128,
or 256 bytes in size, based on the contents of the EMAC_BUFSZ register. Each
buffer contains a descriptor table, and packet data as can be seen in Figure 6.
Offset
Ethernet
Packet
consisting of
one or more
buffers
0007h
Descriptor
Table
TLBP 0000h
The Transmit and Receive buffer areas are subdivided into packet buffers of 32,
64, 128, or 256 bytes in size. The size of the packet buffer is set in bits 7 and 8 of
the EMAC_BUFSZ register. An Ethernet packet can accommodate multiple buff-
ers. Each packet begins at the next available buffer boundary. At the start of each
packet is the packet descriptor, a 7-byte field that describes the packet. The actual
Ethernet packet follows the descriptor.
The descriptor table contains three entries: the Next pointer (np), the packet size
(pkt_size), and the packet status (stat), as illustrated in Figure 7.
AN021201-1104 Discussion
Application Note
Ethernet Frame Transmission Using The eZ80F915050 Module
11
Offset
stat
0005h
pkt_size
0003h
np
0000h
• np is a 24-bit pointer to the start of the next packet. The next packet will start
at the beginning of the next available buffer, following the end of this packet.
• pkt_size contains the number of bytes of data that make up the Ethernet
packet not including the seven descriptor table bytes.
• stat contains the status of the packet. The status is different for transmit and
receive packets.
AN021201-1104 Discussion
Application Note
Ethernet Frame Transmission Using The eZ80F915050 Module
12
Receive descriptor status is described in Table 2. The receive descriptor fields are
written by the EMAC when the packet has been completely written into the
receive buffer.
AN021201-1104 Discussion
Application Note
Ethernet Frame Transmission Using The eZ80F915050 Module
13
For more information regarding the various bits in the transmit and receive
descriptor table status bytes, refer to the EMAC chapter in eZ80F91 MCU Product
Specification (PS0192).
AN021201-1104 Discussion
Application Note
Ethernet Frame Transmission Using The eZ80F915050 Module
14
A flow chart representing the process of Ethernet frame transmission and reception,
as has been demonstrated in this application, is shown in Appendix B on page 24.
Hardware Architecture
Figure 8 shows the hardware setup required for this application.
\
User Interface
eZ80F91
PC running MCU
HyperTerminal UART RJ45 Ethernet
Connector
Platform PHY
Memory eZ80F915050
PC running Module
ZDS II for
eZ80Acclaim! ZPAK II TIM
v4.8.0 ®
eZ80 Development Platform Crossover
Cable
Ethernet hub
eZ80F91
Programming ZPAK II TIM MCU
Interface
Platform PHY
Memory eZ80F915050 RJ45 Ethernet
PC running Module Connector
UART
HyperTerminal
®
eZ80 Development Platform
User Interface
Application Hardware
15
As shown in Figure 8, the hardware setup can be segmented into three main
parts:
Programming Interface. These blocks, used to program the microcontroller,
include the ZDI port on the eZ80® Development Platform connected to a target
interface module. The target interface module is connected to a ZPAK II unit via a
ribbon cable. The ZPAK II unit is connected to an Ethernet hub via an Ethernet
patch cable. Programming of the microcontrollers is controlled via a computer run-
ning ZDS II for eZ80Acclaim!™ connected to the Ethernet hub using an Ethernet
patch cable. ZDS II can be installed from the CD that is contained in the
eZ80Acclaim!™ Development Kit. The hardware components for this section are
all included in the eZ80Acclaim!™ Development Kit. Details regarding setting up
the programming interface are described in the eZ80Acclaim!™ Development Kits
Quick Start Guide (QS0020) and are beyond the scope of this Application Note.
Application Hardware. These blocks, used to implement Ethernet transmission
and reception, include the eZ80® Development Platform and the eZ80F915050
Module. The module includes an eZ80F91 MCU, a PHY to implement the Physi-
cal Layer for transmission and reception, and an RJ45 connector to connect
Ethernet cables that can transmit signals over long distances.
User Interface. Data can be exchanged with the user by running the HyperTermi-
nal application on a PC and connecting a serial port on the PC to the console port
on the eZ80® Development Platform using a RS-232 serial cable. The user inter-
face is provided through the UART0 block of the eZ80F91 MCU; this interface is
configured for 57600 bits per second, 8 data bits, no parity, 1 stop bit, and no flow
control. Details regarding setting up a user interface via the UART block and the
HyperTerminal application are provided in the sample program on the
eZ80Acclaim!™Development Kit CD.
EMAC shared memory can be enabled within the ZDS II Integrated Development
Environment using the Enable EMAC Shared Memory checkbox. This checkbox
can be found in the Configuration Settings dialog box, which the user can navi-
gate to via the following ZDS II menu path: Project → Settings → Debugger →
Target → Configure. The upper byte of the EMAC shared memory registers must
also be entered in the project settings. EMAC shared memory can also be initial-
ized by setting the EMAC RHBP, EMAC BP, and EMAC TLBP registers using soft-
ware.
Software Implementation
As discussed in the Ethernet Data Transmission section on page 13, the entire
application can be segmented into three main phases:
• Initialization of the EMAC, the PHY, and the CPU
• Frame transmission
16
• Frame reception
Each of the above phases is explained in detail below, along with a discussion of
the software functions used for this application. A code listing of the software func-
tion, including comments, is presented in Appendix C on page 25.
After initialization, the user is asked to enter a letter to indicate usage either as a
transmitter or as a receiver. If the Transmit option is selected, functions related to
transmission are executed. If the Receive option is selected, functions related to
the reception of Ethernet frame are executed.
17
While the user can set these registers directly, the following paragraph
describes how they are set using the program listed in Appendix C on
page 25 and using the project settings in ZDS II.
The application described in this document sets TLBP to C7C000h and
RHBP to C7E000h. C7 is selected in the project settings by entering C7 as
the upper byte when enabling EMAC shared memory in the following
ZDS II menu path: Project → Settings → Debugger → Target → Config-
ure. The RAM Address offset, currently set to C000h in the F91_emac.h
file, is added to the C70000h address value to obtain a value for TLBP. As
a result, TLBP is configured to a value of C7C000h.
RHBP is obtained by adding the EMAC RAM size, which is currently set to
2000h in the F91_emac.h file. As a result, the value of RHBP is set to
C7E000h. BP is determined using equations so as to allow at least one
packet and an additional buffer.
d. Initialize the EMAC_PTMR register, which is currently set to 1 to reflect a
minimum time between successive polls of EMAC shared memory.
e. Initialize the EMAC_TEST register. which is configured in the application
to disable the EMAC test modes by writing a 0 to this register.
f. Initialize the following EMAC_CFG registers to specify the mode of opera-
tion:
EMAC_CFG1. Set to 02h to allow reception of frames and disable padding
and CRC, half-duplex mode, CSMA/CD enabled.
EMAC_CFG2. Set to 56h to allow late collisions until 56 bytes are success-
fully transmitted.
EMAC_CFG3. Set to 15h to specify 15 retransmission attempts.
18
3. PHY is initialized using the PhyInit function. The following steps are pro-
grammed into the PhyInit function:
a. Initialize EMAC_FIAD register with the PHY address to access the PHY.
b. Check the values in the PHY_ID1_REG and PHY_ID2_REG registers.
c. Reset the PHY by writing to the PHY_CREG register.
d. Read the PHY_SREG and PHY status registers to check if autonegotia-
tion is enabled.
e. Establish a link/connection according to user-defined options if autonegoti-
ation mode is not enabled.
f. Check whether a link is established, and indicate the result to the user via
HyperTerminal.
Frame Transmission
The Transmit process consists of the following main operations.
19
2. Check for the availability of the buffers in the EMAC shared memory transmit
buffer section (see Figure 5).
3. Generate entries for the Tx buffer descriptor table.
4. Copy the data, including the descriptor table, into EMAC shared memory.
5. Enable interrupts.
6. Transfer control to the EMAC by setting bit 8 of the first byte in the descriptor
table.
7. The frame is transmitted by the hardware, and an EMAC Tx interrupt is gener-
ated. At this time, the status in the descriptor table and the EMAC_ISTAT reg-
ister can be verified to ensure transmission of the frame.
8. After completing transmission, the program accompanying this Application
Note transfers control back to the main program where the user can transmit
data or wait for the system to receive data. If the user chooses to exit the pro-
gram, he/she is prompted to enter X.
20
Frame Reception
The Receive process consists of the following main operations.
1. The PHY and the EMAC are already initialized. Therefore, the link is estab-
lished, and the EMAC unit on the eZ80F91 MCU receives a frame over the
Ethernet MII and generates an EMAC Rx interrupt. When the EMAC Rx inter-
rupt occurs, control is transferred to the user-defined ethisr_rx interrupt ser-
vice routine.
2. Read the EMAC_ISTAT register to clear the status register.
3. Control is transferred to the RxNotify function, the location of which is speci-
fied when EthInitfunc is called by the main program.
4. RxNotify creates a buffer in memory and calls the ReceivePkt function.
5. The amount of data received is found by reading the number of packet size
bytes in the descriptor table. The flags in the Ethernet packet (order/type field)
are initialized to status bytes from the descriptor table. Data is copied from
EMAC shared memory to the buffer specified by RxNotify when calling
ReceivePkt.
6. Data is recovered from the received frame and the first byte is displayed in the
HyperTerminal window.
7. The displayed fields are the destination address, the source address, the
length of data, and the character that is intended to be transmitted by the user.
8. Upon returning from the RxNotify function, the ethisr_rx interrupt service
routine updates rrp to point to the next packet specified in the descriptor
table.
9. Control is then transferred to the main.c file. The user is prompted to either
wait for the system to receive data, enter X to exit the program, or enter a key
to transmit data.
21
3. In the HyperTerminal window, you should see a prompt asking you to enter T
for transmit or R for Receive. Enter R to configure the eZ80F91 MCU as a
receiver.
4. Open another copy of ZDS II and navigate via the Project → Settings →
Debugger → ZPAK II Driver Configuration menus to modify the IP address
to 192.168.1.60. Build and run the project.
5. The HyperTerminal application prompts the user to enter T for transmitter or R
for receiver. Entering T to begin a transmit operation prompts the user to enter
a character to be transmitted via the Ethernet. Entering this character in
HyperTerminal will show RxData, as well as the character (in the HyperTermi-
nal program) on the receiving PC.
Conclusion
This Application Note demonstrates how to use ZiLOG’s eZ80F91 MCU to send
and receive information across the Ethernet medium at the hardware level. A low-
level driver function can be written to accept a single byte of data from the user
(via HyperTerminal), generate a frame, and transmit it over the Ethernet. Recep-
tion of an Ethernet frame is also incorporated into the application, and the recov-
ery of data is demonstrated.
Summary
The eZ80F91 MCU includes an on-chip Ethernet MAC, which greatly enhances
the possibility of sending and receiving data over the Ethernet. While a user can
send data using a number of TCP/IP protocols that are demonstrated in the ZTP
software package (such as UDP, PPP, etc.), all data transmission is essentially
performed at the hardware level by encoding the information into the data field of
the Ethernet frame. By using data in the form of an Ethernet frame, the user can
eliminate the additional complexity required to encode and decode data according
to the protocol used. This application can also aid in debugging and toward devel-
oping an understanding of how the protocol actually works by adding that func-
tionality during frame generation and reception.
AN021201-1104 Conclusion
Application Note
Ethernet Frame Transmission Using The eZ80F915050 Module
22
Notes
AN021201-1104 Notes
Application Note
Ethernet Frame Transmission Using The eZ80F915050 Module
23
Appendix A—References
Further details about the eZ80F91 MCU, EMAC operation, and the eZ80Acclaim!™
development system can be found in the references listed in Table 3.
24
Appendix B—Flowcharts
The main battery-charging routine is illustrated in Figure 9.
Start
Tx Tx/Rx? Rx
25
C Files
The following C files are listed in this section:
• main.c
• bothfns.c
• F91_phy.c
• macfns.c
• uart_main.c
main.c
/*
* Copyright 2004, ZiLOG Inc.
* All Rights Reserved
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of ZiLOG Inc., and might
* contain proprietary, confidential and trade secret information of
* ZiLOG, our partners and parties from which this code has been licensed.
*
* The contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of ZiLOG Inc.
*/
#include <stdio.h>
#include "new_uart.h"
#include "_eZ80.h"
#include "F91_emac.h"
#include "AMD79C874_phy.h"
#include "new_ether.h"
void txpacket(void);
26
void txrx(void);
void main(void)
{
SYSCALL EMACinit;
char * ieeeaddr;
char func;
uart_init();
printf ("\n\n\n\n
************************************************************");
printf ("\n Zilog development board eZ80F91 EMAC Module demonstration\n");
//call ethinitfunc
EMACinit = ETHINITFUNC(ieeeaddr, rxnotify);
if (EMACinit != PEMAC_INIT_DONE)
{
printf ("\n Error in EMAC initialization, Exiting program");
abort();
txrx();
}
void txrx(void)
{
printf ("\n\n TO EXIT : Press X");
printf ("\n RECEIVER : Wait for data to be received");
printf ("\n TRANSMITTER : Enter key representing data for transmission \n ");
txpacket();
}
void txpacket(void)
{
BYTE message;
struct ep txframe;
struct ep * ptxframe;
BYTE i;
SYSCALL txpktstatus;
27
message = getchar();
if (message == 'x' || message == 'X')
{
asm("di");
printf( "\n ************************************************************"
);
abort();
}
txframe.ep_eh.eh_dst[0] = 0xFF;
txframe.ep_eh.eh_dst[1] = 0xFF;
txframe.ep_eh.eh_dst[2] = 0xFF;
txframe.ep_eh.eh_dst[3] = 0xFF;
txframe.ep_eh.eh_dst[4] = 0xFF;
txframe.ep_eh.eh_dst[5] = 0xFF;
txframe.ep_eh.eh_type = 0x002E;
for(i=1;i<=46;i++)
{
txframe.ep_data[i-1] = message;
}
ptxframe = &(txframe);
//call transmitpkt
txpktstatus = TransmitPkt (ptxframe);
if (txpktstatus == PKTTOOBIG)
printf("\n packet too big\n");
}
bothfns.c
/*
28
struct ep rxdfrm;
29
/*
* Save the interrupt callback addresses
*/
if( rxnotifyaddr == 0 )
{
printf("\n illegal callbacks\n");
return (ILLEGAL_CALLBACKS);
}
/*
* Ensure internal EMAC Ram is enabled. Calculate memory base address and
clear it.
*/
p_internal_sram_base = (BYTE *)((((DWORD)RAM_ADDR_U) << 16) +
(BYTE*)EMAC_RAM_OFFSET);
RAM_CTL |= ERAM_EN;
emac_reset();
30
/*
* Ensure there is enough room in the Tx buffer for at least 1
* full sized ethernet frame + one extra emac packet buffer.
*/
temp = (MAXDATASIZE + HEADERSIZE + sizeof(struct desctbl) + (buf_size<<1) -1)
& buf_mask;
if( ((F91_emac_config.tx_buf_size & buf_mask) >= temp)
&& ((F91_emac_config.tx_buf_size & buf_mask) <= EMAC_RAM_SIZE) )
{
temp = F91_emac_config.tx_buf_size & buf_mask;
}
if( F91_emac_config.tx_buf_size != temp )
{
printf( "Adjusted F91 Tx buffer size to %u\n", temp );
}
31
32
EMAC_MIIMGT = CLKDIV20;
if( PhyInit() != OK )
{
printf( "Phy initialization error\n" );
return( SYSERR );
}
return (PEMAC_INIT_DONE);
}
void rxnotify(void)
{
struct ep * databuff;
databuff = &rxdfrm;
//call receivepkt
ReceivePkt(databuff);
}
33
F91_phy.c
/*
* Copyright 2004, ZiLOG Inc.
* All Rights Reserved
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of ZiLOG Inc., and might
* contain proprietary, confidential and trade secret information of
* ZiLOG, our partners and parties from which this code has been licensed.
*
* The contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of ZiLOG Inc.
*/
#include <stdio.h>
#include "_eZ80F91.h"
#include "F91_emac.h"
#include "AMD79C874_phy.h"
/*
* Configure Phy address on the F91
*/
EMAC_FIAD = PHY_ADDRESS;
34
/*
* Re-initialize the Phy controller
*/
write_phy_reg(PHY_CREG, PHY_RST);
sleep100(10);
/*
* Set desired link capabilities
*/
switch( F91_emac_config.mode )
{
case( F91_AUTO ):
{
if( Auto )
{
write_phy_reg(PHY_ANEG_ADV_REG,
PHY_ANEG_100_FD
| PHY_ANEG_100_HD
| PHY_ANEG_10_FD
| PHY_ANEG_10_HD
| PHY_ANEG_802_3 );
}
else
{
printf( "\nHW modifications required to enable Auto-Negotiation\n" );
}
break;
}
case( F91_100_FD ):
{
phy_data |= PHY_100BT | PHY_FULLD;
write_phy_reg(PHY_ANEG_ADV_REG,
PHY_ANEG_100_FD
| PHY_ANEG_100_HD
35
| PHY_ANEG_10_FD
| PHY_ANEG_10_HD
| PHY_ANEG_802_3 );
break;
}
case( F91_100_HD ):
{
phy_data |= PHY_100BT | PHY_HALFD;
write_phy_reg(PHY_ANEG_ADV_REG,
PHY_ANEG_100_HD
| PHY_ANEG_10_FD
| PHY_ANEG_10_HD
| PHY_ANEG_802_3 );
break;
}
case( F91_10_FD ):
{
phy_data |= PHY_10BT | PHY_FULLD;
write_phy_reg(PHY_ANEG_ADV_REG,
PHY_ANEG_10_FD
| PHY_ANEG_10_HD
| PHY_ANEG_802_3 );
break;
}
case( F91_10_HD ):
default:
{
phy_data |= PHY_10BT | PHY_HALFD;
write_phy_reg(PHY_ANEG_ADV_REG,
PHY_ANEG_10_HD
| PHY_ANEG_802_3 );
break;
}
}
write_phy_reg(PHY_CREG, phy_data);
/*
* Wait for a link to be established
*/
read_phy_reg( PHY_SREG, &phy_data );
i = 50;
while( !(phy_data & (PHY_AUTO_NEG_COMPLETE | PHY_LINK_ESTABLISHED)) )
{
sleep100(10);
read_phy_reg( PHY_SREG, &phy_data );
if( i==0 )
{
printf( "\nUnable to establish Ethernet Connection\n" );
36
break;
}
i--;
if( i%10 == 0 )
printf( "." );
}
37
TMR2_CTL = 0x00;
TMR2_RR_H = 0x0C;
TMR2_RR_L = 0x35;
uclear = TMR2_IIR;
TMR2_CTL = 0x0F;
do {
if (TMR2_IIR & 0x01)
timer++;
} while (timer != time);
}
macfns.c
/*
* Copyright 2003-04, ZiLOG Inc.
* All Rights Reserved
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of ZiLOG Inc., and might
* contain proprietary, confidential and trade secret information of
* ZiLOG, our partners and parties from which this code has been licensed.
*
38
* The contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of ZiLOG Inc.
*/
#include <stdio.h>
#include "new_uart.h"
#include "_ez80f91.h"
#include "F91_emac.h"
#include "AMD79C874_phy.h"
#include "new_ether.h"
/*
* Function Prototypes
*/
/*
* Global Variables
*/
const F91_EMAC_CONF_SF91_emac_config =
{
1568, // Size of Mac transmit buffer
F91_10_HD,// Default to 10 Mbps Half Duplex
BUF32 // Each packet buffer in EMAC_RAM will be 32 bytes long
};
/*
* Pointers into EMAC shared memory for buffer management.
* Currently these are unprotected.
*/
extern struct desctbl * twp;
extern struct desctbl * trp;
extern struct desctbl * rwp;
extern struct desctbl * rrp;
extern struct desctbl * tlbp;
extern struct desctbl * bp;
extern struct desctbl *rhbp;
39
extern voidrxnotify(void);
struct ep * pep;
// ---------------------------------------------------------------------------
--
/*
* Calculate the address of the emac packet buffer that will immediately
* follow the one about to transmitted. Before giving the current
* packet to the emac HW, set the ownership of the next packet buffer to
* Host Owns so the emac HW does not try to transmit the frame.
*
* Note: this implementation only sends 1 packet at a time and the the
* init routine has already verified that a max sized frame can fit in the
* emac Tx buffer. Therefore there is no need to track how many ehternet
* buffers remain.
*/
NextPkt = (struct desctbl*) ((BYTE*)twp + ((Len+buf_size-1+DATA_OS) &
(buf_mask)));
if( NextPkt >= bp )
{
NextPkt = (struct desctbl*)((BYTE*)tlbp + ((BYTE*)NextPkt - (BYTE*)bp));
}
NextPkt->stat = HOST_OWNS;
twp->np = NextPkt;
twp->pktsz = Len;
/*
* Copy packet data into the emac Tx buffer. Check to see if the data will
* wrap around the end of the transmit buffer.
*/
pSrc = (BYTE*)&databuff->ep_eh;
40
pDst = (BYTE*)twp+DATA_OS;
emac_enable_irq();
/*
* Set the status to Emac owns so the HW will begin trnamitting the frame.
*/
twp->stat = EMAC_OWNS;
twp = NextPkt;
}
lengthcompare = pep->ep_len;
return( status );
}
void ethisr_tx(void)
{
BYTE CritFlag;
struct desctbl * HW_TRP;
BYTE temp;
temp = EMAC_ISTAT;
41
EMAC_ISTAT = TX_DONE;
temp = EMAC_ISTAT;
asm("ei");
txrx();
}
temp = rrp->stat;
rxnotify();
asm("ei");
txrx();
}
42
uart_init();
temp1 = EMAC_ISTAT;
asm("di");
txferSz = rrp->pktsz;
// move the data from the rx ring buffers into system buffer
pdst = (BYTE*)&databuff->ep_eh;
psrc = (BYTE*)rrp+DATA_OS;
43
ptr++;
datalen_h = *ptr;
datalen = 0x0000;
datalen = (datalen_h*16)+datalen_l;
printf("%04d", datalen);
ptr++;
printf("\n\t\t Received data\t\t\t");
for (i=0; i<datalen;i++)
{
if (datalen == 0x002E)
printf("%c ", *ptr);
else printf("%#x ", *ptr);
}
uart_main.c
/*****************************************************************************
* This program will exercise the eZ80Acclaim! UART. The UART will be used
* to print a few messages and echo any character it receives from the
* Console port.
*
****************************************************************************/
#include <eZ80F91.h>
#include "new_uart.h"
44
void uart_init(void)
{
#if (SIMULATE==0)
unsigned short int i;
unsigned short brg;
PD_ALT2 = 0x03;
PD_ALT1 = 0x00;
PD_DDR = 0xEB;
PD_DR = 0x00;
PB_DR = 0x40;
PB_ALT2 = 0x00;
PB_ALT1 = 0x00;
PB_DDR = 0xBF;
UART0_LCTL |= LCTL_DLAB;
UART0_BRG_L = (brg & (unsigned short)0x00FF);
UART0_BRG_H = (brg & (unsigned short)0xFF00) >> (unsigned short)8;
UART0_LCTL &= ~LCTL_DLAB;
UART0_THR = ch;
if (ch == LF)
{
while ((UART0_LSR & LSR_THRE) == (unsigned char)0);
UART0_THR = CR;
}
return (ch);
}
45
int getch(void)
{
while ((UART0_LSR & LSR_DR) == (unsigned char)0);
return (UART0_RBR);
}
Header Files
The following header files are listed in this section:
• AMD79C874_phy.h
• basetypes.h
• F91_emac.h
• generic_phy.h
• new_ether.h
• new_uart.h
• uart_main.h
• _ez80.h
• _eZ80F91.h
AMD79C874_phy.h
/*
* Copyright 2003-04, ZiLOG Inc.
* All Rights Reserved
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of ZiLOG Inc., and might
* contain proprietary, confidential and trade secret information of
* ZiLOG, our partners and parties from which this code has been licensed.
*
* The contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of ZiLOG Inc.
*/
/*
* Copyright 2001-04, Metro Link, Inc.
* All Rights Reserved
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Metro Link, Inc. and may
* contain proprietary, confidential and trade secret information of
* Metro Link, Inc. and/or its partners.
46
*
* The contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Metro Link, Inc.
*
*/
/
******************************************************************************
**src: AMD79C874_phy.h
**
**DPC7/19/01Initial
**
** Description: header file for ethernet phy (AMD 79c874)
**
*****************************************************************************
*/
#ifndef _AMD79C874_PHY_H_
#define _AMD79C874_PHY_H_
#include "generic_phy.h"
/*
* Default Phy address
*/
#define PHY_ADDRESS 0x001F
/*
* Phy registers unique to the AMD79C874.
*/
#define PHY_DIAG_REG 18
#define PHY_MODE_CTRL_REG21
/*
* ID register values to identify the Phy.
* PHY_ID1 is the expected value from PHY_ID1_REG.
* PHY_ID2 is the expected value from PHY_ID2_REG.
*/
#define PHY_ID1 0x0022
#define PHY_ID2 0x561B
/*
* Diagnostic Register (Register 18) bit definitions
*/
#define PHY_FULL_DUPLEX 0x0800
#define PHY_100_MBPS 0x0400
#define PHY_RX_PASS 0x0200
47
/*
* Mode Control Register (Register 21) bit definitions
*/
#define PHY_GPSI_EN 0x0800
#define SYSERR -1
#endif
basetypes.h
/*
* Copyright 2004, ZiLOG Inc.
* All Rights Reserved
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of ZiLOG Inc., and might
* contain proprietary, confidential and trade secret information of
* ZiLOG, our partners and parties from which this code has been licensed.
*
* The contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of ZiLOG Inc.
*/
#ifndef _BASETYPES_H_
#define _BASETYPES_H_
/*
* Macro Definitions
*/
#define NULLPTR (void *) 0
#define TRUE 1
#define FALSE 0
#define SYSCALLINT16
#define PROCESSINT16
#define COMMANDINT16
#define LOCALstatic
/*
* Structures and Type Definitions
*/
typedef void * HANDLE;
48
#endif
F91_emac.h
/*
* Copyright 2003-04, ZiLOG Inc.
* All Rights Reserved
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of ZiLOG Inc., and might
* contain proprietary, confidential and trade secret information of
* ZiLOG, our partners and parties from which this code has been licensed.
*
* The contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of ZiLOG Inc.
*/
/*
**src: F91_emac.h
**
**DPC2/20/01Initial
**
** ez80s191 header file for ethernet mac
**Packet descriptor struct with corresponding bit definitions
** Timer/Timeout bit values
*/
#ifndef _F91_EMAC_H_
#define _F91_EMAC_H_
#include "basetypes.h"
49
// buffer mask
#define BUFMSK256 0xFF00
#define BUFMSK128 0xFF80
#define BUFMSK64 0xFFC0
#define BUFMSK32 0xFFE0
#define ABITS 13
#define MIN_NUM_RX_BUFS 2
50
#define PEMAC_NOT_FOUND -1
#define PEMAC_PHY_NOT_FOUND -2
#define PEMAC_PHYREAD_ERROR -3
#define PEMAC_PHYINIT_FAILED -4
#define PEMAC_SMEM_FAIL -5
#define ILLEGAL_CALLBACKS -6
#define PEMAC_INIT_DONE 0
#define OUT_OF_BUFS 4
#define TX_FULLBUF 3
#define TX_WAITING 2
#define TX_DONE 1
#define PKTTOOBIG -2
/*
* Macros for Mode member of F91_EMAC_CONF_S
*/
#define F91_10_HD 0
#define F91_10_FD 1
#define F91_100_HD 2
#define F91_100_FD 3
#define F91_AUTO 4
51
#endif
generic_phy.h
/*
* Copyright 2004, ZiLOG Inc.
* All Rights Reserved
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of ZiLOG Inc., and might
* contain proprietary, confidential and trade secret information of
* ZiLOG, our partners and parties from which this code has been licensed.
*
* The contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of ZiLOG Inc.
*/
#ifndef _GENERIC_PHY_H_
#define _GENERIC_PHY_H_
#include "basetypes.h"
/*
* Common Phy registers.
*/
#define PHY_CREG 0
#define PHY_SREG 1
#define PHY_ID1_REG 2
#define PHY_ID2_REG 3
#define PHY_ANEG_ADV_REG4
/*
* MII Management Control Register (Register 0) bit definitions
*/
52
/*
* MII Management Status Register (Register 1) bit definitions
*/
#define PHY_AUTO_NEG_COMPLETE0x0020
#define PHY_CAN_AUTO_NEG 0x0008
#define PHY_LINK_ESTABLISHED0x0004
/*
* Aut-Negotiation Advertisement Register (Register 4) bit definitions
*/
#define PHY_ANEG_100_FD 0x0100
#define PHY_ANEG_100_HD 0x0080
#define PHY_ANEG_10_FD 0x0040
#define PHY_ANEG_10_HD 0x0020
#define PHY_ANEG_802_3 0x0001
/*
* Function prototypes
*/
extern WORD write_phy_reg(WORD phy_reg, WORD data);
extern WORD read_phy_reg(WORD phy_reg, WORD* data);
/*
* Global Variables
*/
extern const F91_EMAC_CONF_SF91_emac_config;
#endif
new_ether.h
#include "basetypes.h"
53
new_uart.h
// new_uart.h
#define UART 0
#define UART_BPS 57600
#define UART_DATA_BITS 8
#define UART_PARITY 0
#define UART_STOP_BITS 1
#define LF '\n'
#define CR '\r'
void uart_init(void);
uart_main.h
#include <eZ80F91.h>
#include <stdio.h>
54
#define UART 0
#define UART_BPS 57600
#define UART_DATA_BITS 8
#define UART_PARITY 0
#define UART_STOP_BITS 1
void uart_init(void);
int putch(int ch);
int getch(void);
void test(void);
int getchar(void);
int putchar(int c);
#if (UART==1)&&(SIMULATE==0)
55
#define LF '\n'
#define CR '\r'
_ez80.h
/*
* Copyright 2003-2004, ZiLOG Inc.
* All Rights Reserved
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of ZiLOG Inc., and might
* contain proprietary, confidential and trade secret information of
* ZiLOG, our partners and parties from which this code has been licensed.
*
* The contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of ZiLOG Inc.
*/
/*
* Copyright 2001-2004, Metro Link, Inc.
* All Rights Reserved
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Metro Link, Inc. and may
* contain proprietary, confidential and trade secret information of
* Metro Link, Inc. and/or its partners.
*
* The contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Metro Link, Inc.
*
*/
#ifndef __EZ80_H_
#define __EZ80_H_
#include <basetypes.h>
/*
* Pointer type definitions for the eZ80 Compiler to access I/O.
* Note that all on-chip IO devices are internal. However, some IO macros
* use the __EXTIO keyword. These macros are intended to be used with a
* variable that holds the base address of the peripheral. This allows the
* same code fragment to operate on identical peripherals located at different
* places in the IO map. For example, if your code neede to write the value
56
/* UART_IER bits */
#define IER_MIIE0x08
#define IER_LSIE0x04
#define IER_TIE 0x02
#define IER_RIE 0x01
/* UART_IIR bits */
#define IIR_FIFOEN0xC0
#define IIR_ISCMASK0x0E
#define IIR_RLS0x06
#define IIR_RDR0x04
#define IIR_CTO0x0C
#define IIR_TBE0x02
#define IIR_MS0x00
#define IIR_INTBIT0x01
/* UART_FCTL bits */
#define FCTL_TRIGMASK0x00
57
#define FCTL_TRIG_10x00
#define FCTL_TRIG_40x40
#define FCTL_TRIG_80x80
#define FCTL_TRIG_140xC0
#define FCTL_CLRTXF0x04
#define FCTL_CLRRXF0x02
#define FCTL_FIFOEN0x01
/* UART_LCTL bits */
//#define LCTL_DLAB0x80
#define LCTL_SB 0x40 /* Send Break */
#define LCTL_FPE0x20 /* Force Parity Error */
#define LCTL_EPS0x10 /* Even Parity */
#define LCTL_PEN0x08 /* Parity Enable */
#define LCTL_2STOPBITS0x04
#define LCTL_5DATABITS0x00
#define LCTL_6DATABITS0x01
#define LCTL_7DATABITS0x02
#define LCTL_8DATABITS0x03
/* UART_MCTL bits */
#define MCTL_LOOP0x10
#define MCTL_OUT20x08
#define MCTL_OUT10x04
#define MCTL_RTS0x02
#define MCTL_DTR0x01
/* UART_LSR bits */
#define LSR_ERR 0x80
#define LSR_TEMT0x40
//#define LSR_THRE0x20
#define LSR_BI 0x10
#define LSR_FE 0x08
#define LSR_PE 0x04
#define LSR_OE 0x02
//#define LSR_DR0x01
/* UART_MSR bits */
#define MSR_DCD 0x80
#define MSR_RI 0x40
#define MSR_DSR 0x20
#define MSR_CTS 0x10
#define MSR_DDCD0x08
#define MSR_TERI0x04
#define MSR_DDSR0x02
#define MSR_DCTS0x01
/* WDT_CTL bits */
58
#define WDTCTL_EN0x80
#define WDTCTL_NMI0x40
#define WDCTL_RST_FLAG0x20
#define WDTCTL_TWO180x03
#define WDTCTL_TWO220x02
#define WDTCTL_TWO250x01
#define WDTCTL_TWO270x00
/* WDT_RR bits */
#define WDTRR_RESET10xA5
#define WDTRR_RESET20x5A
/*
* Chip select Control Register bit definitions
*/
#define CSCTL_WAIT_STATE_MASK0xE0
#define CSCTL_7_WAIT_STATES0xE0
#define CSCTL_6_WAIT_STATES0xC0
#define CSCTL_5_WAIT_STATES0xA0
#define CSCTL_4_WAIT_STATES0x80
#define CSCTL_3_WAIT_STATES0x60
#define CSCTL_2_WAIT_STATES0x40
#define CSCTL_1_WAIT_STATES0x20
#define CSCTL_0_WAIT_STATES0x00
#define CSCTL_MEMORY_ACCESS0x00
#define CSCTL_IO_ACCESS0x10
#define CSCTL_ENABLE_CS0x08
#define CSCTL_DISABLE_CS0x00
#endif
_eZ80F91.h
/*
* Copyright 2003-2004, ZiLOG Inc.
* All Rights Reserved
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of ZiLOG Inc., and might
* contain proprietary, confidential and trade secret information of
* ZiLOG, our partners and parties from which this code has been licensed.
*
* The contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of ZiLOG Inc.
*/
/*
59
**src: ez80s191.h
**
**DPC2/20/01Initial
**
** ez80s191 header file for internal I/O registers
**
*/
#ifndef __EZ80F91_H_
#define __EZ80F91_H_
#include <ez80f91.h>
#include "_eZ80.h"
#define OK1
/* EMAC */
#define EmacStad(q)*((IORegExt8)(0x25+q))
#define EmacHtbl(q)*((IORegExt8)(0x33+q))
#define EmacCtld*((IORegInt16)((BYTE)0x3c))
#define EmacRrp*((IORegInt16)((BYTE)0x49))
// test reg
#define TESTFIFO0x40 // enable fifo test
#define TXSEL0x20 // select fifo for test_fifo
#define RXSEL0x00 // select fifo for test_fifo
#define SSTCT0x10 // shorcut slot timer counter when 1
#define SIMR0x08 // simulation reset - reset random number generator in
PETFUN
#define FRC_OVR_ERR 0x04// force rx overrun error
#define FRC_UND_ERR 0x02// force tx underrun error
#define LPBK0x01 // internal loop back enable
// cfg1 reg
#define PADEN0x80 // 1=pad short packets
#define ADPAD0x40 // Auto detect pad enable
#define VLPAD0x20 // VLAN pad enable
#define CRCEN0x10 // crc enable
#define FULLD0x08 // Full Duplex - mac ignores crs and col when 1
#define FLCHK0x04 // Frame length check
#define HUGEN0x02 // huge packet enable
#define DCRCC0x01 // Delayed crc check
// cfg2 reg
#define BPNB0x80 // backpreswsure no back off - if set, mac will
automatically retry
// if a collision occurs
#define NOBO0x40 // no back off
#define LCOL_MASK0x3f // late collision window
60
// cfg3 reg
#define LONGP0x80 // Long preamble enforcement
#define PUREP0x40 // Pure preamble enforcement
#define XSDFR0x20 // Excess Defer
#define BITMD0x10 // Bit mode 10 mb/s ENDEC mode
#define RETRY_MASK0x0f // Retry count mask
// cfg4 reg
#define TPCF0x40 // tx pause control frame
#define THDF0x20 // tx half duplex (jams incoming packets)
#define PARF0x10 // Pass all Receive frames
#define RXFC0x08 // rx flow control
#define TXFC0x04 // tx flow control (allow pause frames)
#define TPAUSE0x02 // Test pause - mac control is paused
#define RXEN0x01 // allows mac to output srxen
// reset reg
#define SRST0x20 // s/w reset
#define HRTFN0x10 // host reset tx function
#define HRRFN0x08 // host reset rx function
#define HRTMC0x04 // host reset tx MCS
#define HRRMC0x02 // host reset rx MCS
#define HRMGT0x01 // host reet MII MGT
// mii reg
#define LCTLD0x80 // load control data
#define RSTAT0x40 // read status
#define SCINC0x20 // Scan Increment across multiple PHY's
#define SCAN0x10 // 1=scan mgmt cycles continuously
#define SPRE0x08 //suppress preamble
#define CLK_MASK0x07 // clock select
#define CLKDIV280x07
#define CLKDIV200x06
#define CLKDIV140x05
#define CLKDIV100x04
#define CLKDIV80x03
#define CLKDIV60x02
#define CLKDIV40x01
61
#define TXDONEIEN0x01
// bufsz reg
#define BUFSZMASK0xc0
#define TPCF_LEVEL0x3f
/* TIMER */
#define TMR00x60
#define TMR10x65
#define TMR20x6F
#define TMR30x74
#define TMR_CTL(base)(*((IORegExt8)(base+0)))
62
#define TMR_IER(base)(*((IORegExt8)(base+1)))
#define TMR_IIR(base)(*((IORegExt8)(base+2)))
#define TMR_DRL(base)(*((IORegExt8)(base+3)))
#define TMR_DRH(base)(*((IORegExt8)(base+4)))
#define TMR_RRL(base)(*((IORegExt8)(base+3)))
#define TMR_RRH(base)(*((IORegExt8)(base+4)))
/* Ram Control */
#define GPRM_EN0x80
#define ERAM_EN0x40
/* Flash Control */
#define FLASH_CTRL_7_WS0xE0
#define FLASH_CTRL_6_WS0xC0
#define FLASH_CTRL_5_WS0xA0
#define FLASH_CTRL_4_WS0x80
#define FLASH_CTRL_3_WS0x60
#define FLASH_CTRL_2_WS0x40
63
#define FLASH_CTRL_1_WS0x20
#define FLASH_CTRL_0_WS0x00
#define FLASH_ENABLE0x08
#define FLASH_DISABLE0x00
/* UART */
#define UART_RBR(base)(*((IORegExt8)(base+0)))
#define UART_THR(base)(*((IORegExt8)(base+0)))
#define BRG_DLRL(base)(*((IORegExt8)(base+0)))
#define BRG_DLRH(base)(*((IORegExt8)(base+1)))
#define UART_IER(base)(*((IORegExt8)(base+1)))
#define UART_IIR(base)(*((IORegExt8)(base+2)))
#define UART_FCTL(base)(*((IORegExt8)(base+2)))
#define UART_LCTL(base)(*((IORegExt8)(base+3)))
#define UART_MCTL(base)(*((IORegExt8)(base+4)))
#define UART_LSR(base)(*((IORegExt8)(base+5)))
#define UART_MSR(base)(*((IORegExt8)(base+6)))
#define UART_SPR(base)(*((IORegExt8)(base+7)))
/* PLL Control 0 */
#define PLL_CHARGE_PUMP_MASK0xC0
#define PLL_100uA 0x00
#define PLL_500uA 0x40
#define PLL_1mA 0x80
64
#define PLL_CLK_MUX_MASK0x03
#define PLL_CLK_IS_EXT 0x00
#define PLL_CLK_IS_PLL 0x01
#define PLL_CLK_IS_RTC 0x02
/* PLL Control 1 */
#define PLL_LOCKED_STATUS0x20
#define PLL_LOCKED_INT 0x10
#define PLL_UNLOCKED_INT0x08
#define PLL_LOCKED_IE 0x04
#define PLL_UNLOCKED_IE 0x02
#define PLL_ENABLE_PLL 0x01
#define PLL_DISABLE_PLL 0x00
65
#define IV_PB10xA4
#define IV_PB20xA8
#define IV_PB30xAC
#define IV_PB40xB0
#define IV_PB50xB4
#define IV_PB60xB8
#define IV_PB70xBC
#define IV_PC00xC0
#define IV_PC10xC4
#define IV_PC20xC8
#define IV_PC30xCC
#define IV_PC40xD0
#define IV_PC50xD4
#define IV_PC60xD8
#define IV_PC70xDC
#define IV_PD00xE0
#define IV_PD10xE4
#define IV_PD20xE8
#define IV_PD30xEC
#define IV_PD40xF0
#define IV_PD50xF4
#define IV_PD60xF8
#define IV_PD70xFC
#endif