• Aucun résultat trouvé

NETWORK DATA FORMATS

Dans le document COMPLETE DIGITAL DESIGN (Page 131-135)

Serial Communications

5.8 NETWORK DATA FORMATS

Common data formats and protocols are necessary to regulate the flow of data across a network to ensure proper addressing, delivery, and access to that common resource. Several general terms for

Node

-Balch.book Page 110 Thursday, May 15, 2003 3:46 PM

Serial Communications 111

message elements on a network are frame, packet, and cell. Frames are sets of data that are framed at the beginning and end by special delimiters. Packets are sets of data that are not fully framed but that have some other means of determining their size, such as an embedded length field. Cells are fixed-length frames or packets. Frames and packets usually imply variable fixed-length data sets, but this is not a strict rule. As with many terms and classifications in digital systems, specific definitions are context specific and are often blurred: one system’s cells may be another’s frames. Frames, packets, and cells are composed of headers, payloads, and trailers, as shown in Fig. 5.13. The header is a collec-tion of data fields that handle network overhead funccollec-tions such as addressing and delineacollec-tion. The actual data to be transmitted is placed into the payload. If present, a trailer is commonly used to im-plement some form of error checking and/or delineation. Not all packet formats specify the inclusion of trailers. When present, a trailer is usually substantially smaller in length than the header.

Networking is an aspect of digital systems design that directly involves hardware–software inter-action at a basic level. One cannot really design networking hardware without keeping in mind the protocol, or software, support requirements. One key example is packet format. Hardware must have knowledge of the packet format so that it can properly detect a packet that is sent to it. At the same time, software must have this same knowledge so that it can properly parse received packets and generate new ones to be transmitted.

As soon as more than two nodes are connected to form a network, issues such as addressing and shared access arise. When there is only one transmitter and one receiver, it is obvious that data is in-tended for the only possible recipient. Likewise, the lone transmitter can begin sending data at any time it chooses, because there are no other transmitters competing for network access.

Network addressing is the mechanism by which a transmitting node indicates the destination for its packet. Each node on the network must therefore have a unique address to prevent confusion over where the packet should be delivered. In a bus topology, each node watches all the data traffic that is placed onto the network and picks out those packets that are tagged with its unique address. In a ring topology, each node passes packets on to the next node if the destination address is not matched with that node’s address. If the address is matched, the node absorbs the packet and does not forward it on to the next node in the ring. Logical star and mesh topologies function a bit differently. Nodes on

Logical Bus Node

Node Node

Node

hub

hub

Logical Ring Node

Node

Node

Node

FIGURE 5.12 Physical vs. logical network topologies.

Header Payload Trailer

FIGURE 5.13 Generic packet structure.

-Balch.book Page 111 Thursday, May 15, 2003 3:46 PM

112Digital Fundamentals

these types of networks do not observe all traffic that traverses the network; rather, the network itself contains some intelligence when it comes to delivering a packet. A node in a logically starred net-work sends a packet to a central hub that examines the destination address and then forwards the message to only the specified node. A mesh network routes traffic partly like a ring and partly like a star; however, multiple paths between nodes exist to complicate the delivery process. Based on the destination address, the originating node sends a packet to one of its neighbors, which in turn for-wards the message to one of its neighbors. This process continues until the path has been completed and the packet arrives at its intended destination. The presence of multiple valid paths between nodes requires the mesh network to use knowledge about the location of nodes to select an optimal path through the network.

Access sharing is necessary on networks to ensure that each node eventually has an opportunity to send a message. Numerous methods of access sharing have been implemented over the years. Gen-erally speaking, the length of messages is bounded to prevent a node from transmitting an infinitely long set of data and preventing anyone else from gaining access to the shared medium. Sharing algo-rithms differ according to the specific network topology involved. Networks that are a collection of point-to-point links (e.g., ring, star, mesh) do not have to worry about multiple nodes fighting for ac-cess to the same physical wire, but do have to ensure that one node does not steal all the bandwidth from others. Bus networks require sharing algorithms that address both simultaneous physical con-tention for the same shared wire in addition to logical concon-tention for the network’s bandwidth. Arbi-tration schemes can be centralized (whereby a single network master provides permission to each node to transmit) or distributed (whereby each node cooperates on a peer-to-peer level to resolve si-multaneous access attempts).

After deciding on a network topology, one of the first issues to resolve is the network packet for-mat. If the network type is already established (e.g., Ethernet), the associated formats and protocols are already defined by industry and government standards committees. If an application benefits from a simple, custom network, the packet format can be tailored to suit the application’s specific needs.

Delineation and addressing are the two most basic issues to resolve. Delineation can be accom-plished by sending fixed-size packets, embedding a length field in the packet header, or by reserving unique data values to act as start/stop markers. Framing with unique start/stop codes places a restric-tion on the type of data that a packet can contain: it cannot use these unique codes without causing false start or end indications. Referring back to Table 5.1, notice that start-of-header (SOH) and end-of-transmission (EOT) are represented by 0x01 and 0x04. These (or other pairs of codes) can be used as delimiters if the packet is guaranteed to contain only alphanumeric ASCII values that do not conflict with these codes.

Addressing is normally achieved by inserting both the destination and source addresses into the header. However, some networking schemes may send only a single address. Sending both addresses enables recognition of the destination as well as a determination of which node sent the packet. Since most data exchanges are bidirectional to a certain degree, a destination node will probably need to send some form of reply to the source node of a particular packet. Many networks include a provision known as broadcast addressing whereby a packet is sent to all nodes on the network rather than just one. This broadcast is often indicated using a reserved broadcast address. In contrast to a unicast address that is matched by only one node, a broadcast address is matched by all nodes on the network. Some networks also have multicast addresses that associate multiple nodes with a single destination address.

5.9 RS-485

Whereas RS-232 and RS-422 enable point-to-point serial links, the RS-485 standard enables multi-ple-node networks. Like RS-422, RS-485 provides differential signaling to enable communications -Balch.book Page 112 Thursday, May 15, 2003 3:46 PM

Serial Communications 113

across spans of twisted-pair wire exceeding 1.2 km. Unlike RS-422, the RS-485 standard allows up to 32 transmit/receive nodes on a single twisted pair that is terminated at each end as shown in Fig.

5.14. Modern low-load receivers that draw very little current from the RS-485 bus can be used to in-crease the number of nodes on an RS-485 network well beyond the original 32-node limit to 256 nodes or more. A single pair of wires is used for both transmit and receive, meaning that the system is capable of half-duplex (one-way) operation rather than full-duplex operation (both directions at the same time). Half-duplex operation restricts the network to one-way exchange of information at any given time. When node A is sending a packet to node B, node B cannot simultaneously send a packet to node A.

RS-485 directly supports the implementation of bus networks. Bus topologies are easy to work with, because nodes can directly communicate with each other without having to pass through other nodes or semi-intelligent hubs. However, a bus network requires provisions for sharing access to be built into the network protocol. In a centralized arbitration scheme, a master node gives permission for any other node to transmit data. This permission can be a request-reply scheme whereby slave nodes do not respond unless a request for data is issued. Alternatively, slave nodes can be periodi-cally queried by the master for transmit requests, and the master can grant permissions on an indi-vidual-node basis. There are many centralized arbitration schemes that have been worked out over the years.

A common distributed arbitration scheme on a bus network is collision detection with random back-off. When a node wants to transmit data, it first waits until the bus becomes idle. Once idle, the node begins transmitting data. However, when the node begins transmitting, there is a chance that one or more nodes have been waiting for an opportunity to begin transmitting and that they will be-gin transmitting at the same time. Collision detection circuits at each node determine that more than one node is transmitting, and this causes all active transmitters to stop. Figure 5.15 shows the

imple-ZO=110 Ω

RT=110 Ω RT=110 Ω

FIGURE 5.14 RS-485 bus topology.

Tx

Rx

+ –

Twisted Pair Transmit Enable

Receive Enable (always on) Transmit Data

Receive Data UART Logic

Collision Detect '1'

FIGURE 5.15 RS-485 collision detection transceiver.

-Balch.book Page 113 Thursday, May 15, 2003 3:46 PM

114 Digital Fundamentals

mentation of an RS-485 transceiver with external collision detection logic. A transmit enable signal exists to turn off the transmitter when the UART is not actively sending data. Unlike an RS-422 transmitter that does not have to share access with others, the RS-485 transmitter must turn itself off when not sending data to enable others to transmit.

When transmitting, the receiver returns the logical state of the twisted-pair bus. If the bus is not at the same state as the transmitted data, a collision is most likely being caused by another transmitter trying to drive the opposite logic state. An XOR gate implements this collection detect, and the XOR output must be sampled only after allowing adequate time for the bus to settle to a stable state fol-lowing the assertion of each bit from the transmitter.

Once a collision has been detected by each node and the transmitters are disabled, each node waits a different length of time before retransmitting. If all delays were equal, multiple nodes would get caught in a deadlock situation wherein each node keeps trying to transmit after the same delay interval. Random back-off delays are pseudo-random so as to not unfairly burden some nodes with consistently longer delays than other nodes. At the end of the delay, one of the nodes begins trans-mitting first and gains control of the bus by default. The other waiting nodes eventually exit from their delays and observe that the bus is already busy, indicating that they must wait their turn until the current packet has been completed. If, by coincidence, another node begins transmitting at the same time that the first node begins, the back-off process begins again. It is statistically possible for this process to occur several times in a row, although the probability of this being a frequent event is small in a properly designed network. A bus network constructed with too many nodes trying to send too much data at the same time can exhibit very poor performance, because it would be quite prone to collisions. In such a case, the solution may be to either reduce the network traffic or increase the network’s bandwidth.

Dans le document COMPLETE DIGITAL DESIGN (Page 131-135)