Файл: Embedded system development and labs for ARM (R. Muresan, 2005).pdf
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 13.06.2025
Просмотров: 2338
Скачиваний: 4
Embedded Systems Development and Labs; The English Edition
6.1.7 Sample Programs
1. Initialization Program
/* IIC */
#define rIICCON |
(*(volatile unsigned *)0x1d60000) |
#define rIICSTAT |
(*(volatile unsigned *)0x1d60004) |
#define rIICADD |
(*(volatile unsigned *)0x1d60008) |
#define rIICDS |
(*(volatile unsigned *)0x1d6000c) |
/* S3C44B0X slave address */ rIICADD=0x10;
/*Enable ACK,interrupt, IICCLK=MCLK/16, Enable ACK//64Mhz/16/(15+1) = 257Khz */ rIICCON=0xaf;
/* enbale TX/RX */ rIICSTAT=0x10;
2.Interrupt Declaration
/* enable interrupt */ pISR_IIC=(unsigned)IicInt;
3.Interrupt Routine
/***********************************************************************
* name: |
IicInt |
* func: |
IIC interrupt handler |
* para: |
none |
* ret: |
none |
*modify:
*comment:
*********************************************************************/
void IicInt(void)
{
rI_ISPC=BIT_IIC; iGetACK = 1;
}
4. IIC Write AT24C04 Program
/***********************************************************************
* name: |
Wr24C040 |
* func: |
write data to 24C080 |
239
Embedded Systems Development and Labs; The English Edition
* para: |
slvAddr --- |
chip slave address |
*addr --- data address
* |
data |
--- data value |
* ret: |
none |
*modify:
*comment:
*********************************************************************/
void Wr24C040(U32 slvAddr,U32 addr,U8 data)
{
iGetACK = 0;
/* send control byte */ rIICDS = slvAddr; rIICSTAT=0xf0;
while(iGetACK == 0); iGetACK = 0;
/* send address */ rIICDS = addr; rIICCON = 0xaf;
while(iGetACK == 0); iGetACK = 0;
/* send data */ rIICDS = data; rIICCON = 0xaf;
while(iGetACK == 0); iGetACK = 0;
/* end send */ rIICSTAT = 0xd0; rIICCON = 0xaf; DelayMs(5);
}
//send the device address 0xa0
//Master Tx,Start
//wait ACK
//resumes IIC operation.
//wait ACK
//resumes IIC operation.
//wait ACK
//stop Master Tx condition
//resumes IIC operation.
//wait until stop condtion is in effect.
4. IIC Read AT24C04 Program
/***********************************************************************
* name: |
Rd24C080 |
240
Embedded Systems Development and Labs; The English Edition
* func: |
read data from 24C080 |
* para: |
slvAddr --- chip slave address |
*addr --- data address
* |
data |
--- data pointer |
* ret: |
none |
*modify:
*comment:
********************************************************************/
void Rd24C040(U32 slvAddr,U32 addr,U8 *data)
{
char recv_byte;
iGetACK = 0;
/* send control byte */ rIICDS = slvAddr; rIICSTAT=0xf0;
while(iGetACK == 0); iGetACK = 0;
/* send address */ rIICDS = addr; rIICCON = 0xaf;
while(iGetACK == 0); iGetACK = 0;
/* send control byte */ rIICDS = slvAddr; rIICSTAT=0xb0; rIICCON=0xaf;
while(iGetACK == 0); iGetACK = 0;
/* get data */ recv_byte = rIICDS; rIICCON = 0x2f;
DelayMs(1);
//send the device address 0xa0
//Master Tx, Start
//wait ACK
//resumes IIC operation.
//wait ACK
//send the device address 0xa0 again
//Master Rx, Start
//resumes IIC operation.
//wait ACK
//delay
241
Embedded Systems Development and Labs; The English Edition
/* get data */ recv_byte = rIICDS;
/* end receive */ |
|
rIICSTAT = 0x90; |
// stop Master Rx condition |
rIICCON = 0xaf; |
// resumes IIC operation. |
DelayMs(5); |
// wait until stop condition is in effect. |
*data = recv_byte; |
// store the data |
}
6.1.8 Exercises
Write a program to write words such as date, etc. and read them out through serial port or LCD panel.
6.2 Ethernet Communication Lab
6.2.1 Purpose
● Get familiar with Ethernet communication principles and driver program development.
● Learn the IP network protocol and network application software development using the Embest development system.
6.2.2 Lab Equipment
● Hardware: Embest S3CEV40 hardware platform, Embest Standard/Power Emulator, PC, Ethernet hub. ● Software: Embest IDE 2003, Windows 98/2000/NT/XP operation system.
6.2.3 Content of the Lab
Download the code to the target board through the local LAN using TFTP/IP protocol.
6.2.4 Principles of the Lab
1. Principles of Ethernet Communication
The company Xerox developed the Ethernet protocol based on the Carrier Sense Multiple Access / Collision Detection (CSMA/CD) mechanism. The communication medium is a coaxial cable. The data transfer rate could be 10Mb/s. If using twisted pair wires, the data transfer rate could be 100Mb/s. Currently the Ethernet follows the IEEE802.3 standard.
1) Architecture
The architecture of an Ethernet based system is shown in Figure 6-10.
242
Embedded Systems Development and Labs; The English Edition
Ethernet Li
Figure 6-10. Ethernet architecture, schematic drawing.
2) Types
● |
Ethernet/IEEE802.3: |
using coaxial cable; the data transfer rate could be 10Mb/s. |
● |
100M Ethernet: |
uses twisted pair wire; data transfer rate could be 100Mb/s. |
● |
1000M Ethernet: |
using optical cable or twisted pair wire. |
3) Work Principles
The transportation method in Ethernet is Media Access Control technology that is also called Carrier Sense Multiple Access / Collision Detection (CSMA/CD). The following are the descriptions of this technology:
●Carrier Sense: When your computer is trying to send information to another computer on the networks, your computer should first monitor if there are information currently transferring on the network or if the channel id idle.
●Channel Busy: If the channel is busy, then wait until the network channel is idle.
●Channel Idle: If the channel is idle, then transmit the message. Because the whole network is being shared the same communication bus, all the network station can receive your message, but only the network station you selected can receive your message.
●Collision Detection: When a network station is transmitting message, it needs to monitor the network channels, detects if other network station are transmitting messages on the network. If yes, the messages sent from two stations will be in collision that cause the message be damaged.
●Busy Stop: If there is network collision on the network, the transmission should stop immediately and a “collision” signal should be sent to the network to let other stations know the collision has happen.
●Multiple Access: If the network station encountered collisions and stop transmission, it should wait for a while and return to the first step, start the carrier sensing and transmission, until the data is successfully transmitted.
All the network stations are transmitting messages through the above 6 steps.
Because at the same time, there is only one network station transmitting messages and other stations can only receive or wait, the collision chances are increase when more network station added to the network. The network stations will alternately follow the process monitorÆtransmitÆstop transmitÆwaitÆretransmit…
4) Ethernet/IEEE 802.3 Frame
The frame structure of the Ethernet/IEEE 802.3 protocol is shown in the following figure.
243
Embedded Systems Development and Labs; The English Edition
Figure 6-11 Ethernet/802.3 Frame Architecture
●Preamble consists of alternative 0 and 1 that informs network stations to get ready. The IEEE802.3 preamble is 7 bytes followed by one byte of SOF. The Preamble includes the SOF, so its total length is 8 bytes.
●Start of Frame (SOF) is one byte ended with two consequent 1. This byte stands for the start of the frame.
●Destination and Source Addresses means the addresses of the sending workstation and receiving workstation. The destination address is a single address or a broadcast address.
●Data (Ethernet) will be transferred to higher protocols after the data has been processed in the physical layer and the logic link layer. The minimum length of data is 46 bytes.
●Data (802.3) will be filled to 64 bytes if the length of data is not more than 64 bytes.
●Frame Check Sequence (FCS) consists of a 4-byte CRC that is generated by the sending device. The receiving device will recalculate the CRC and compare is with the received CRC in order to make sure that data has been transferred correctly.
5) Ethernet Driver Development Methods
Developing Ethernet drivers involves initializing and programming the RTL8019AS Ethernet interface chip and providing data input/output and control interface to higher-level protocols. The RTL8019 chip is an Ethernet controller made by the Realtek company of Taiwan. Because of its high performance and low price, it is widely used in commercial products.
The main features of the RTL8019AS are:
●Meets Ethernet II and 802.3 (10 Base, 10 Base2 and 10 BaseT) standards.
●Full duplex and maximum 10 Mb/s in sending and receiving.
●Supports 8/16 bits data bus, 8-interrupt line and 16 base I/O addresses.
●Supports ITP, AUI and BNC automatic detection, Supports auto polarity correction for 10BaseT.
●Support 4 diagnostic LED pins with programmable outputs
244
Embedded Systems Development and Labs; The English Edition
●100 pins PQFQ package.
RTL8019 consists of the following interfaces: remote DMA, local DMA, MAC (media access control) logic, data CODEC, and others.
The remote DMA interface is an ISA bus that the processor write/read data to/from the RAM inside the RTL8019. Microprocessor deals with remote DMA interface only. The local DMA interface is an interconnection channel between RTL8019AS and network cable.
Bellow the MAC (media access control) logic completes the function:
•when the processor transmits data to the network, the processor transmits first a frame of data to the transmit buffer via the remote DMA channel;
•then the processor sends a transmit command; when the RTL8019AS finishes the current frame transmission, it starts to transmit the next frame;
•the RTL8019As receives the data the MAC comparison. After the CRC verification, the data is transferred to buffer via FIFO;
•when the frame is full, the RTL8019As will inform the microprocessor through the interrupt or the register flag bit.
FIFO receive/send 16 bytes data is used as a tampon buffer to reduce the DMA request frequency. The RTL8019 has two internal RAM blocks. One is 16Kb and occupies the address space 0x4000-0x7FFF. The other is 32Kb and occupies the address space 0x0000-0x001F. The RAM is divided into pages of 256 bytes. Generally the first 12 pages (0x4000-0x4BFF) are used as the transmission buffer. The following 52 pages (0x4C00-0x7FFF) are used as the receiver buffer. The page 0 is only 32 bytes (0x0000-0x001F) and is the PROM page. The PROM page is used for storing the Ethernet physical address. In order to read/write data packages, the DMA mode is needed to read/write the data to the 16 Kb RAM in the RTL8019AS. The RTL8019 has 32-bit input/output addresses. The address offset is 0x00-0x1F where x00-0x0F are 16 register addresses. These registers hold the pages addresses. They are PAGE0, PAGE1, PAGE2 and PAGE3. The bit PS1 and bit PS2 of CR (Command Register) determines which page will be visited. But only the first 3 pages are compatible with NE2000. Page 3 is RTL8019 self defined page and is not compatible with other NE2000 chips (such as DM9008). The remote DMA address is 0x10-0x17 and is used as remote DMA port. The reset port is 0x18-0x1F (8 addresses) that is used to reset RTL8019AS. The application diagram of ATL8019As is shown in Figure 6-12.
245
Embedded Systems Development and Labs; The English Edition
Figure 6-12. RTL8019A C application schematic diagram.
Ethernet.c is the driver program of the RTL8019AS chip. The following describes briefly its functions:
●NicInit() 8019 initialization. The initialization steps are: (1) configure the chip to the jumper mode, half-duplex. (2) Configure the receive/send buffer. Two buffers are used for sending data. Each buffer occupies 6 pages (256 bytes) of internal RAM and it can transmit a maximum of 1536 bytes of Ethernet data package. Another buffer is used for receiving data and consists of 20 pages (256 bytes/page) of internal RAM block. (3) Set MAC address and broadcast address. MAC address is determined by mac_addr array.
(4)Configure the chip only receive the data package that match to the local MAC address (also can be configured as receiving all packages or broadcast packages). Enable received interrupt. Enable CRC. (5) Start the chip for receiving/sending data.
●NicClose() Close 8019AS data receive/send functions.
●NicReset() Reset 8019AS chip.
●NicOutput() Data package output. Fill the data package with a header of Ethernet data package. Set the target MAC address according to the parameter. Write the content of Ethernet package to the send buffer. Start DMA send function. This chip will automatically finish the sending.
●EtherInput() Data package input. Check the data receive flag register. If there is data in the buffer, then receive the header of the package from the receive buffer. If the content of the header is correct, then according to the data length in the header, read the content of data from the package and transfer it to the higher layer interface. Make the pointer to the current receive buffer to the last page of the buffer.
2. IP Network Protocols
TCP/IP protocol is a group of protocols including TCP (Transmission Control Protocol) and IP (Internet Protocol), UDP (User Datagram Protocol), ICMP (Internet Control Message Protocol) etc.
TCP/IP was first time introduced in 1973 by two researchers at Stanford University. At that time the US ARPA (Advanced Research Project Agency) planed to implement interconnections between different networks. ARPA aided the research and development of inter-network connections. In 1977-1979, the TCP/IP architecture and standard was developed and is almost the same as the current TCP/IP architecture. Around 1980s, the US DARPA started to port all the machines to the TCP/IP network. From 1985, NSF (National Scientific
246