SERIAL NETWORK PROTOCOL (SERNETP) 1. INTRODUCTION 1.1 Layering Protocol Layering +---------------------+ | higher-level | +---------------------+ | internet protocol | +---------------------+ | SERNETP | +---------------------+ Figure 1 1.2 Introduction The protocol is aimed for simple appliances, that wish to implement a protocol that can act as a physical transport for TCP/IP or SMP/IP higher level protocols. It's supposed to combine the strengths of Ethernet and token-ring networks. Ethernet's primary problem lies with it's collision detection and the problems in high-load situations. Also, Ethernet only operates at 10Mbps and 100Mbps and many simple embedded systems doesn't need these high speeds. The protocol should also operate over long distances. Token ring sends a token around all the time, so the network would be in constant use. This is a problem in many systems, since minimizing electrostatic and magnetic fields is an important goal. Power consumption is also reduced by sending as little data as possible. 1.3 Basic operation The protocol uses implicit tokens. The token implicitly goes to the next node. The time it takes before the token is passed to the next node is determined by the master. The token passing is initialized with a initialize message beeing sent by the master. The arrival of the first character of the initialize message is assumed to be the start of the master's time frame. The master should periodically send an initialize command. During initialization, all nodes wanting to participate on the network must answer and identify themselves. When all nodes had a chance to answer the initialize command, the master will reply with the time-frame each node gets. One reply per time frame is sent by the master. During this time only the master is allowed to send, so no collisions are possible. Time-frames can be 1 to 64, and thus a maximum of 64 nodes can be on the network. During the initialize command, the nodes time frames equals their node numbers. The master must send the initialize command in it's own timeframe if the network is in use. 1.4 Master selection The protocol doesn't use an explicit master, rather any node can become the master. The master selection is carried out then the line is idle. Every node waits max initialize period + node id / 64 seconds before it sends out an initial initialization command. Only if at least one node answers this command, is the current node selected as a master. When a node powers-up, it must wait at least this time before it tries to send an initialize command. The master should send an initialization command at least every max initialize period. 2. FUNCTIONAL SPECIFICATION 2.1. Header Format SERNETP data are sent over a serial network. The type of network is irrelavant as long as all senders share a single physical pair of wires. The protocol should be able to handle its own echos. The header is designed so each of fields have different valid value ranges. This ensures misaligned frames can easily be detected. 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Start (9B) | Message type | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Source | Destination | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | Message Data | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Checksum | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Basic SERNETP Header Format Note that one tick mark represents one bit position. Figure 3. Start: 8 bits The start sequence is used to indicate the start of a new message. This number is defined as 9B. Message type: 8 bits Currently defined message types include (kind indicated in hex): Kind Meaning ---- ------- 7C Initialize request 7D Node registration request 7E Node registration reply 7F Data Source: 8 bits Source node of the message. The node number is biased with 2C. The valid range for this field is thus 2D-6C. Destination: 8 bits Destination node of the message. The broadcast address is AB and should be responded to by all nodes. Non broadcast nodes are biased with AC. The valid range for this field is thus AB and AD-EC. CRC sum: 16 bits The CRC sum of the header and the data part of the message. The polynomial used for this sum is 1021 hex. 2.2. Initialization message To initiate the network, the master must send an initialization message. The message is broadcast to all nodes, and nodes wanting to participate on the network must respond to it. The message also contains the implicit time it takes before the token moves to the next node. Message data format: 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Time frame length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Time frame length: 16 bits Number of microseconds before the token moves to the next node. Tokens are not sent on the line, so this time is implicit. All nodes must observe this and only send data in it's own time frame. This will ensure collisions could never occur, and performance will not drop as load increases. 2.3. Node registration request message When a node wants to participate on the network, it must answer the initialization message with a node registration message. The node must only answer when the node has the implicit token. The message doesn't have a data part. The message should be sent to the master, and should not be broadcasted. 2.4. Node registration reply message After all nodes had a chance to register themselves, the master will answer all nodes that sent a node registration request. The message will give the node it's time-frame number. After the node receives this message, it may send data messages over the network. The message should be sent in the time frame the node should use. This ensures collisions can not occur, since a node is not allowed to send until it receives this message. Message data format: 0 0 1 2 3 4 5 6 7 +-+-+-+-+-+-+-+-+ | Frame number | +-+-+-+-+-+-+-+-+ | Frame count | +-+-+-+-+-+-+-+-+ Frame number: 8 bits Gives the time-frame number the node should use. Frame number zero is the master's frame, and should never be handed out. Frame count: 8 bits Number of used time frames on the network. This equals the number of active nodes. The number is used by the nodes to wrap the current time frame number to zero when this count is reached. 2.5. Data message Data messages are used to transfer data from on node to another. Message data format: 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Size | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Packet type | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | Data | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Size: 16 bits The size of the data part of the message. Packet type: 16 bits The type of packet. The packet types used is the same as Ethernet's packet types. 806 is ARP and 800 is IP. Data: variable The message sent 3. IMPLEMENTATION 3.1 Max initialize time The max initialize time is baudrate dependent. It should never exceed 5 seconds, and more than 1000 time frames should never be used. This ensures a node doesn't have to wait too long to participate on the network. It also ensures the time-keeping in the system only needs a 500ppm crystal oscillator, which most systems has. 3.2 Calculating optimal time frame lengths The time frame length is an important parameter for performance and stability. It must not be larger than 65535us (65ms). A larger selection doesn't fit in the 16-bit field used. A good selection is 9 (max non-data message length + 1) * 10 (1 data bit, 1 stop bit, 8 data bits) * 1000000 / baudrate microseconds. This will give the following values for common baudrates: Baudrate Time frame length Max initialize time Usable bandwidth ---------------------------------------------------------------------- 2400 37500us 5.000s 51% 122 bytes/s 4800 18750us 5.000s 76% 365 bytes/s 9600 9375us 5.000s 88% 845 bytes/s 19200 4688us 4.688s 94% 1805 bytes/s 38400 2344us 2.344s 94% 3610 bytes/s 57600 1562us 1.562s 94% 5414 bytes/s 115200 781us 0.781s 94% 10828 bytes/s Of course, the highest baudrate will require a lot from both the OS and CPU. The OS must support timers with an accuracy below 0.5ms, with full load from the serial port. If the OS cannot meet the requirements, collisions or overrun errors will result in dramatic decrease of through-put. Also, note that baudrates below 2400 cannot be used, since that would violate the maximum time frame limit. For 2400, half of the bandwidth would be used for sending initialize commands. Reasonable baudrates are 9600 or higher. Although the master may use any value for the time frame length, it's highly recommended to use the above values. References [1] Postel, J., "Internet Protocol," RFC 760, USC/Information Science Institute, January 1980