Software and Hardware Design and Implementation of DSP-based Internet Access Solution

Source: Internet
Author: User
Software and Hardware Design and Implementation of DSP-based Internet Access Solution
[Date:] Source: Electronic Technology Application by fan Qing Han Chong Zhao Wei Hua [Font:Large Medium Small]

 

With the development of modern network technology, embedded systems, such as single-chip microcomputer and DSP, require more and more access networks, for example, an electric meter system with the remote meter reading function and an information appliance system that can be remotely controlled. In this paper, the hardware interface circuit of the RTL8019 Nic of Realtek company is designed using the DSP chip of TI Company and the hardware interface circuit of the RTL8019 Nic. the TCP/IP protocol is implemented using software in DSP to enable the DSP chip to access the Internet, in this way, a computer can exchange a large amount of data with the DSP circuit board through the NIC and control it.

1. Hardware Design 

Circuit Diagram 1 of the hardware interface between DSP and Nic is shown.

 

 

The DSP data bus is 16-bit connected to the 16-bit data line of the ISA Nic, And the IOCS16 of the ISA Nic is connected to the high level. The 16-bit Nic mode is set.

There are a total of 20 IP addresses. Change A7 ~ A8, A10 ~ A19 grounding, A0 ~ A6 and A9 are connected to the A0 ~ of the DSP respectively ~ A7, the network adapter address used is 0240H ~ 025FH, mapped to the Page3 space of the DSP, and the address ing is C000C0H ~ C000DFH.

The DSP Reset signal is used to Reset the NIC. Because the DSP's Reset signal is low and the NIC's Reset signal is high, it must be connected to another non-gate.

The Page3 and R/W signals of DSP are used to select the read/write signals IOR and IOW of the network card. The logical relationship between implementation 2 is shown.

IRQ9 is the network card interrupt 9. It is connected to the INT1 pin of the DSP through non-door rear.

RTL8019 NICs can work in three ways:

The first is the jumper method. The I/O and interruption of the NIC are determined by the jumper;

The second is plug-and-play mode. The software automatically configures plug and play;

The third method is jumper-free. The I/O and interruption of the NIC are determined by the content in 93C46.

The plug-and-play mode is generally implemented on the computer. To reduce the complexity of software programming, set the NIC as the jumper mode.

All the above decoding logics are implemented in EPM7128.

74alvc162135 is a bus driver chip that enables level conversion from 3 V to 5 V. Because TMS320VC33 and EPM7128 are 3.3V devices and the ISA bus is 5 V, the signal lines cannot be directly connected. The 74alvc162135 must be used for level conversion and isolation.

2 Software Design

2.1 Design of NIC hardware driver 

The NIC Driver consists of the following parts:

(1) NIC Initialization

NIC is a network interface control chip that receives and sends data on the network. To enable the NIC to start and be in the state of preparing to receive or prepare to send data, the related registers must be initialized. These registers include CR, DCR, RBCR, PSTART, PSTOP, ISR, IMR, PAR0 ~ PAR5, MAR0 ~ MAR7, CURR, CRS, RCR, etc.

(2) Service Interruption

Interrupt service programs generally complete two tasks: one is to set the interrupt mark so that the relevant program can detect the interruption, and the other is to obtain the value of the interrupt Status Register, and submit the specific cause of the interruption to the corresponding program. This process is also completed by setting the cause mark of the interruption. It should be noted that the interrupted service process should be protected at the beginning, and the interrupted site should be restored after the process is completed; the interrupted service process should be as short as possible, so that the execution can be completed in as short as possible, so unnecessary work needs to be handed over to other programs for completion.

(3) frame sending program

In the network, the frame transmission process is: the sender encapsulates the data to be sent into frames according to the frame format requirements, and then sends the frames to the transmission line of the network through the network adapter; the receiver determines whether to submit the frame to the upper-layer application based on the destination address of the received frame. Frame transmission refers to sending the data to be sent to the network transmission line in the form of frames. Therefore, the transmission process of frames should include the following steps:

① Frame loading;

② Send frames to the NIC sending buffer;

③ Initialize the sending control register;

④ Start NIC to send the frame to the network transmission line.

(4) frame receiving program

Frame receiving refers to receiving and caching data frames on the network in the receiving buffer ring of the network adapter, the Host Program then reads the frames cached in the receiving buffer ring and stores them in the memory for use by the program. We can see that the frame receiving process is divided into two steps:

① The NIC saves the frame to the receiving buffer ring through local DMA;

② The second step is to read the frames in the buffer ring into the memory through remote DMA and with the cooperation of the host.

2.2 Implementation of TCP/IP protocol

2.2.1 differences between the TCP/IP protocol in DSP and PC 

TCP/IP is first implemented in UNIX systems, and later TCP/IP is also implemented in LINUX, DOS, and WINDOWS systems. However, the source code of the TCP/IP protocol implemented on UNIX cannot be directly transplanted to the DSP, because there is a huge difference between the PC and DSP.

PC computing speed is very fast. Generally, there is a multi-task operating system that can be executed in parallel with multiple tasks, communication between TCP/IP protocol layers and the entire network is realized through hard interrupt and Soft Interrupt, message queue and various plug-ins. However, the DSP runs slowly and lacks a multi-task operating system platform. It can only be implemented through sequential execution and hardware interruption. In addition, it also needs to execute data collection, serial port interruption, and other tasks at the same time, therefore, the interrupt program should be as short as possible. Only the flag spaces of various states should be configured, and the processing of relatively slow network data packets should be executed in the main program to reduce conflicts between various tasks.

The memory size of the PC is very large. Generally, it can reach 32 ~ The storage capacity of MB can be dynamically allocated and released. It is easy to implement chain-like structures such as memory cache mbuf and network control block ncb, and can be added or deleted at will; at the same time, multiple network connections can be maintained. Due to the fast processing speed of the computer, there is almost no need to consider the problem of buffer overflow. The DSP's internal RAM is generally only a dozen K, and the external extended RAM can only reach dozens of K capacity. A maximum Ethernet packet has about K, if the mbuf chain is used according to the memory management mode and data structure of the PC, RAM is definitely not enough, therefore, you can only allocate a fixed 1514-byte segment in RAM to store the received Ethernet packet and receive a packet for processing.

In PC, TCP/IP protocols are implemented in different layers, and each other is connected through parameter transmission, which is conducive to improving program modularization and independence. In the DSP, parameter transmission consumes too much space and reduces the speed of DSP execution. Therefore, parameter transmission should be minimized, in turn, global variables and external variables are used to pass values. Therefore, the dependencies between various programs are large, and some variables and data are often shared.

A complete TCP/IP protocol is implemented on the PC. In the DSP, due to the speed and memory constraints, it is impossible to support all the Protocols. Generally, only the required parts are implemented, and none of the unnecessary protocols are supported; in addition, even the required protocols do not need to be as complex as those implemented on PCs. You can simplify the protocols according to the specific hardware conditions and implementation requirements.

2.2.2 specific implementation of TCP/IP protocol

TCP/IP is a protocol cluster that includes many protocols. As shown in figure 3 of all Protocols implemented on DSP, it can be divided into four layers (excluding the physical layer ).

 

 

According to the structure characteristics and functions of DSP, ARP, IP, and ICMP are implemented in DSP), UDP (User Datagram Protocol) and TCP (Transmission Control Protocol), and simplify them.

ARP is implemented at the link layer. Each network has its own addressing mechanism. Ethernet addresses are addressed through an ethernet address, that is, the MAC address of the hardware address of the Network Adapter. Each network adapter has a unique MAC address at the factory. An IP address is only a virtual address that is meaningful to the TCP/IP protocol cluster. To transmit an IP packet to an IP address over Ethernet, you must convert the IP address to an ethernet address for correct transmission. ARP dynamically maps 32-bit IP addresses to 48-bit Ethernet addresses to ensure correct network transmission. The ARP protocol is implemented by two files, arpin. c and arpout. c. Arpin. c is responsible for receiving arp packets broadcast on the network, determining whether the type of the arp packet is the request packet of another machine on the network or the response packet returned from the local machine, determining its legitimacy and processing it accordingly; arpout. c. The host sends arp REQUEST packets and arpin packets when sending data reports to the network. c calls the arp request packet received in response.

IP and ICMP are implemented at the network layer. The IP protocol is the most core protocol in the TCP/IP protocol cluster. It provides connectionless data transmission services. All upper-layer protocols must be transmitted in the IP data packet format. The ipprotocol is implemented by ipin. c and ipout. c. Ipin. c is responsible for receiving IP packets. After receiving an IP packet, c first checks the version number, Data Length, destination address, and check whether the packet is correct, then, it is handed over to the corresponding upper-layer protocol for processing based on the value of the protocol type field in the IP header; ipout. c is responsible for sending IP data packets, receiving data transmitted by the upper-layer protocol, adding a 20-byte IP header, Correctly Setting the source IP address and destination IP address, protocol type, calculation test, send it to the link layer below. IP packet on a PC can be segmented when its length exceeds the MTU of the network. In DSP, IP packet segmentation and IP Option fields are not supported. The ICMP protocol is responsible for transmitting error messages and other information that requires attention. the type of the information is determined by the first eight-bit type field and eight-bit code field of ICMP. In DSP, only echo request (type code: 80) packets are processed. After receiving the ICMP packet from the IP layer, determine whether the type code segment is 80. If yes, set these two fields to 00 (echo response), calculate the test, and send the result to the IP layer. If not, discard the result. Thus, ping is supported.

UDP and TCP are implemented at the transport layer.

UDP is a non-connection-oriented and unreliable protocol, which is implemented using two files udpin. c and udpout. c. Udpin. c. process the udp packet input and determine the port number, check, and check whether it is correct. If it is correct, the data is handed over to the application on the corresponding port. If it is incorrect, the data is discarded. udpout. c. Process udp packet output, receive data from the application, set the source port number and destination port number, and send the data to the IP layer. It is worth noting that the test of the UDP packet for computing is different from the test of the IP packet for computing. The test of the IP packet only covers the header of the IP packet, the UDP packet inspection overwrites the UDP packet header and all data. A 12-byte pseudo header is introduced in the test of UDP packet calculation, including 4-byte source IP address, 4-byte destination IP address, 1-byte zero segment, 1-byte protocol segment, and two-byte test, the goal is to let UDP check whether the data has arrived at the destination correctly twice.

Although the TCP and UDP protocols are the same transport layer protocols, they provide a reliable connection-oriented byte stream service. TCP is the most complex and difficult to implement in all protocols, mainly by tcpin. c. tcpout. c. tcptimer. c and tcpstatem. the c files are implemented in blocks and simplified according to the needs of specific applications. The TCP Control Block tcb is implemented by struct. Each tcb contains all the control and status information of a TCP connection. All tcb forms a two-way linked list, it is helpful for searching in all TCP connections. Tcptimer. c is responsible for managing various status information in the TCP protocol. It contains forward and backward pointers to form a timer timeout. The TCP protocol on the PC contains two Timers: Speed and speed, only a Ms slow timer is implemented here. Because there is no fast timer, ACK message delay is not supported, and ACK is sent immediately upon receiving a frame; tcpstatem. c is a state machine function of TCP. It determines the status change of the TCP Connection Based on the status and events of the TCP connection. c is responsible for sending tcp packets. A typical sending process is to first send SYN frames when receiving data from upper-layer applications, establish a connection with the target node through three handshakes, and then add the TCP header, send the message to the lower-layer IP module, and use the retransmission timer to implement time-out re-transmission, continuous timer sending window probe frame, and send the FIN frame after all data is sent and confirmed, close the connection through four handshakes, tcpout. c can also be called by other programs in different states and events to send other TCP packets such as ACK frames and RST frames; tcpin. c is responsible for receiving T from the lower-layer IP Module CP data packets, branch Processing Based on the status information of the TCP connection and the flag bit of the TCP Header, and send the data to the upper-layer application on the corresponding port, call other functions to respond to TCP packets and change their status. Multiple TCP connections can be maintained at the same time on a PC. However, only one TCP connection is supported due to DSP speed and RAM capacity constraints. This greatly simplifies the complexity of the program, it also meets the actual needs and can be expanded if needed in the future.

To sum up, the specific process of TCP/IP protocol 4 is shown.

 

 

Through the design and programming of DSP and nic hardware interfaces, this paper enables DSP to implement Ethernet-Based TCP/IP communication, so that DSP can be networked through the network cable, it can also communicate with computers in real time to exchange a large amount of data and control information. The technology introduced in this article has been applied in the hardware design of the "973" project "acquisition and integration of spatial and temporal quantitative information in complex natural environments, and runs well.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.