Renesas R-IN32M3 EC, CL networking User’s Manual
R-IN32M3 EC and R-IN32M3 CL are network devices that are designed for industrial applications. These devices utilize the TCP/IP protocol stack and feature a compact design optimized for the R-IN32M3 series. They offer a variety of network capabilities, including IPv4, ARP, ICMP, IGMPv2, UDP, and TCP protocols. The devices are also equipped with features such as DHCP client, DNS client, FTP server, and HTTP server. These features enable users to design and implement applications that require network communication in various industrial settings.
Advertisement
Advertisement
R-IN32M3 Series
User’s Manual: TCP/IP stack
・R-IN32M3-EC
・R-IN32M3-CL
All information of mention is things at the time of this document publication, and Renesas
Electronics may change the product or specifications that are listed in this document without a notice. Please confirm the latest information such as shown by website of Renesas
Document number : R18UZ0019EJ0300
Issue date : Feb 28, 2015
Renesas Electronics
www.renesas.com
Notice
1. Descriptions of circuits, software and other related information in this document are provided only to illustrate the operation of semiconductor products and application examples. You are fully responsible for the incorporation of these circuits, software, and information in the design of your equipment. Renesas Electronics assumes no responsibility for any losses incurred by you or third parties arising from the use of these circuits, software, or information.
2. Renesas Electronics has used reasonable care in preparing the information included in this document, but Renesas
Electronics does not warrant that such information is error free. Renesas Electronics assumes no liability whatsoever for any damages incurred by you resulting from errors in or omissions from the information included herein.
3. Renesas Electronics does not assume any liability for infringement of patents, copyrights, or other intellectual property rights of third parties by or arising from the use of Renesas Electronics products or technical information described in this document. No license, express, implied or otherwise, is granted hereby under any patents, copyrights or other intellectual property rights of Renesas Electronics or others.
4. You should not alter, modify, copy, or otherwise misappropriate any Renesas Electronics product, whether in whole or in part. Renesas Electronics assumes no responsibility for any losses incurred by you or third parties arising from such alteration, modification, copy or otherwise misappropriation of Renesas Electronics product.
5. Renesas Electronics products are classified according to the following two quality grades: "Standard" and "High
Quality". The recommended applications for each Renesas Electronics product depends on the product's quality grade, as indicated below.
"Standard": Computers; office equipment; communications equipment; test and measurement equipment; audio and visual equipment; home electronic appliances; machine tools; personal electronic equipment; and industrial robots etc.
"High Quality": Transportation equipment (automobiles, trains, ships, etc.); traffic control systems; anti-disaster systems; anti-crime systems; and safety equipment etc.
Renesas Electronics products are neither intended nor authorized for use in products or systems that may pose a direct threat to human life or bodily injury (artificial life support devices or systems, surgical implantations etc.), or may cause serious property damages (nuclear reactor control systems, military equipment etc.). You must check the quality grade of each Renesas Electronics product before using it in a particular application. You may not use any Renesas
Electronics product for any application for which it is not intended. Renesas Electronics shall not be in any way liable for any damages or losses incurred by you or third parties arising from the use of any Renesas Electronics product for which the product is not intended by Renesas Electronics.
6. You should use the Renesas Electronics products described in this document within the range specified by Renesas
Electronics, especially with respect to the maximum rating, operating supply voltage range, movement power voltage range, heat radiation characteristics, installation and other product characteristics. Renesas Electronics shall have no liability for malfunctions or damages arising out of the use of Renesas Electronics products beyond such specified ranges.
7. Although Renesas Electronics endeavors to improve the quality and reliability of its products, semiconductor products have specific characteristics such as the occurrence of failure at a certain rate and malfunctions under certain use conditions. Further, Renesas Electronics products are not subject to radiation resistance design. Please be sure to implement safety measures to guard them against the possibility of physical injury, and injury or damage caused by fire in the event of the failure of a Renesas Electronics product, such as safety design for hardware and software including but not limited to redundancy, fire control and malfunction prevention, appropriate treatment for aging degradation or any other appropriate measures. Because the evaluation of microcomputer software alone is very difficult, please evaluate the safety of the final products or systems manufactured by you.
8. Please contact a Renesas Electronics sales office for details as to environmental matters such as the environmental compatibility of each Renesas Electronics product. Please use Renesas Electronics products in compliance with all applicable laws and regulations that regulate the inclusion or use of controlled substances, including without limitation, the EU RoHS Directive. Renesas Electronics assumes no liability for damages or losses occurring as a result of your noncompliance with applicable laws and regulations.
9. Renesas Electronics products and technology may not be used for or incorporated into any products or systems whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. You should not use Renesas Electronics products or technology described in this document for any purpose relating to military applications or use by the military, including but not limited to the development of weapons of mass destruction. When exporting the Renesas Electronics products or technology described in this document, you should comply with the applicable export control laws and regulations and follow the procedures required by such laws and regulations.
10. It is the responsibility of the buyer or distributor of Renesas Electronics products, who distributes, disposes of, or otherwise places the product with a third party, to notify such third party in advance of the contents and conditions set forth in this document, Renesas Electronics assumes no responsibility for any losses incurred by you or third parties as a result of unauthorized use of Renesas Electronics products.
11. This document may not be reproduced or duplicated in any form, in whole or in part, without prior written consent of
Renesas Electronics.
12. Please contact a Renesas Electronics sales office if you have any questions regarding the information contained in this document or Renesas Electronics products, or if you have any other inquiries.
(Note 1) "Renesas Electronics" as used in this document means Renesas Electronics Corporation and also includes its majority-owned subsidiaries.
(Note 2) "Renesas Electronics product(s)" means any product developed or manufactured by or for Renesas Electronics.
Instructions for the use of product
In this section, the precautions are described for over whole of CMOS device.
Please refer to this manual about individual precaution.
When there is a mention unlike the text of this manual, a mention of the text takes first priority
1.Handling of Unused Pins
Handle unused pins in accord with the directions given under Handling of Unused Pins in the manual.
-The input pins of CMOS products are generally in the high-impedance state. In operation with an unused pin in the open-circuit state, extra electromagnetic noise is induced in the vicinity of LSI, associated shoot-through current flows internally, and malfunctions occur due to the false recognition of the pin state as an input signal become possible. Unused pins should be handled as described under Handling of Unused Pins in the manual.
2.Processing at Power-on
The state of the product is undefined at the moment when power is supplied.
-The states of internal circuits in the LSI are indeterminate and the states of register settings and pins are undefined at the moment when power is supplied.
In a finished product where the reset signal is applied to the external reset pin, the states of pins are not guaranteed from the moment when power is supplied until the reset process is completed.
In a similar way, the states of pins in a product that is reset by an on-chip power-on reset function are not guaranteed from the moment when power is supplied until the power reaches the level at which resetting has been specified.
3.Prohibition of Access to Reserved Addresses
Access to reserved addresses is prohibited.
-The reserved addresses are provided for the possible future expansion of functions. Do not access these addresses; the correct operation of LSI is not guaranteed if they are accessed.
4.Clock Signals
After applying a reset, only release the reset line after the operating clock signal has become stable. When switching the clock signal during program execution, wait until the target clock signal has stabilized.
-When the clock signal is generated with an external resonator (or from an external oscillator) during a reset, ensure that the reset line is only released after full stabilization of the clock signal. Moreover, when switching to a clock signal produced with an external resonator (or by an external oscillator) while program execution is in progress, wait until the target clock signal is stable.
・ARM, AMBA, ARM Cortex, Thumb and ARM Cortex-M3 are a trademark or a registered trademark of ARM Limited in EU and other countries.
・Ethernet is a registered trademark of Fuji Zerox Limited.
・IEEE is a registered trademark of the Institute of Electrical and Electronics Engineers, Inc.
・EtherCAT is a registered trademark of Beckhoff Automation GmbH, Germany.
・CC-Link and CC-Link IE Field are registered trademarks of CC-Link Partner Association (CLPA).
・Additionally all product names and service names in this document are a trademark or a registered trademark which belongs to the respective owners.
・Real-Time OS Accelerator and Hardware Real-Time OS is based on Hardware Real-Time OS of “ARTESSO” made in KERNELON SILICON Inc.
How to use this manual
1. Purpose and target readers
This manual is intended for users who wish to understand the functions of Industrial Ethernet network LSI
“R-IN32M3-EC/CL” for designing application of it.
It is assumed that the reader of this manual has general knowledge in the fields of electrical engineering, logic circuits, and microcontrollers.
Particular attention should be paid to the precautionary notes when using the manual. These notes occur within the body of the text, at the end of each section, and in the Usage Notes section.
The revision history summarizes the locations of revisions and additions. It does not list all revisions. Refer to the text of the manual for details.
The mark “<R>” means the updated point in this revision. The mark “<R>” let users search for the updated point in this document.
Related The related documents indicated in this publication may include preliminary versions. However,
Documents preliminary versions are not marked as such. Please be understanding of this beforehand. In addition, because we make document at development, planning of each core, the related document may be the document for individual customers. Last four digits of document number(described as ****) indicate version information of each document. Please download the latest document from our web site and refer to it.
The document related to R-IN32M3 Series
Document name
R-IN32M3 Series Datasheet
R-IN32M3-EC User’s Manual
R-IN32M3-CL User’s Manual
R-IN32M3 Series User’s Manual Peripheral function
R-IN32M3 Series Programming Manual (Driver edition)
R-IN32M3 Series Programming Manual (OS edition)
R-IN32M3 Series User's Manual TCP/IP stack
Document number
R18DS0008EJ****
R18UZ0003EJ****
R18UZ0005EJ****
R18UZ0007EJ****
R18UZ0009EJ****
R18UZ0011EJ****
This Manual
2. Notation of Numbers and Symbols
Weight in data notation: Left is high-order column, right is low-order column
Active low notation:
xxxZ (capital letter Z after pin name or signal name)
or xxx_N (capital letter _N after pin name or signal name)
or xxnx (pin name or signal name contains small letter n)
Note:
explanation of (Note) in the text
Caution:
Item deserving extra attention
Remark:
Supplementary explanation to the text
Numeric notation:
Binary … xxxx , xxxxB or n’bxxxx (n bits)
Decimal … xxxx
Hexadecimal … xxxxH or n’hxxxx (n bits)
Prefixes representing powers of 2 (address space, memory capacity):
K (kilo)… 2 10
= 1024
M (mega)… 2 20
= 1024
2
G (giga)… 2 30
= 1024
3
Data Type:
Word … 32 bits
Halfword … 16 bits
Byte … 8 bits
Contents
Contents -1
Contents -2
Contents -3
Contents -4
R-IN32M3 Series
User’s Manual: TCP/IP stack
R18UZ0019EJ0300
Feb 28, 2015
1. Overview
This document explains TCP/IP and UDP/IP protocol stacks for R-IN32M3 series.
Function summary and Application Programming Interface (API) and application samples of TCP/IP protocol stack provided by Renesas are described in this document.
There are 2 versions of TCP/IP stack; one is “Evaluation Edition” downloaded from Renesas WEB, the other one is
“Commercial Edition” released to only user who have purchased R-IN32M3 device.
1.1 Features
TCP/IP stack is a compact stack optimized for R-IN32M3. This stack uses “uNet3” customized and produced by eForce Co., Ltd.
1.2 Key Functions
TCP/IP stack for R-IN32M3 has key functions as follows:
• IPv4, ARP, ICMP, IGMPv2, UDP, TCP protocol
• DHCP client, DNS client, FTP server, HTTP server
• TCP/IP configuration
• TCP fast retransmit and fast recovery
• IP reconstructure and fragmentation
• Multiple network interface
The difference between evaluation edition and commercial edition shows at table1.1:
Table 1.1 The difference between evaluation edition and commercial edition <R>
Function / Package
Max socket number(TCP)
Max socket number(UDP)
IP reassemble
Multicast
TCP Keep-Alive
Protocol stack configurations
(e.g. TCP tuning)
Provides source code of network application
Provides source code of network device driver
Provides source code of protocol stack
Commercial Edition
Depends on memory size
Depends on memory size
Yes
Yes
Yes
Yes
Yes
Yes
No
Evaluation Edition
4
4
No
No
No
No
No
No
No
R18UZ0019EJ0300
Feb 28, 2015
Page 1 of 168
R-IN32M3 Series
1.3 Development environment
The development environment of TCP/IP protocol stack is described here.
1. Overview
1.3.1 Development tools
Development tools is showed in Table 1.2.
Table 1.2 Development tools
Tool Chain
ARM -
IDE Compiler
RealView Developer Suite
V4.1
(ARM)
GNU
IAR
- Sourcery G++ Lite
2012.09-63
(Mentor Graphics)
Embedded
Workbench for ARM
V6.60.1
(IAR Systems)
Embedded Workbench for
ARM V6.60.1
(IAR Systems)
Debugger microVIEW-PLUS
Ver.5.11PL3
(Yokogawa Digital
Computer Corporation)
ICE adviceLUNA 2.03-00
(Yokogawa Digital
Computer Corporation) microVIEW-PLUS
Ver.5.11PL3
(Yokogawa Digital
Computer Corporation)
Embedded Workbench for
ARM V6.60.1
(IAR Systems) adviceLUNA 2.03-00
(Yokogawa Digital
Computer Corporation) i-Jet
JTAGjet-Trace-CM
(IAR Systems)
1.3.2 Evaluation board
TCP/IP stack sample application behavior can be confirmed on “TS-R-IN32M3 evaluation board” made by TESSERA
TECHNOLOGY INC.
Please get more detail from Renesas or TESSERA TECHNOLOGY INC. WEB site.
R18UZ0019EJ0300
Feb 28, 2015
Page 2 of 168
R-IN32M3 Series 1. Overview
1.3.3 Development procedure
Standard development procedure is as follows:
1. Merge TCP/IP stack program and R-IN32M3 samplesoft which has driver/middleware.
2. Modify net_cfg.c to configure network parameter (IP address, socket definition) and how to call initialize routine.
3. Make the execution file by build (compile & link), after application program is created.
The relationship among files is showed at Fig. 1.1.
Files created or modified by user
Application program file
.c
.c
.c
Object files
.o
.o
.o
μITRON header file itron.h
kernel.h
OS configuration file kernel_cfg.c
kernel_id.h
TCP/IP stack header file net_hdr.h
Files modified by user if it is needed
(Samples are ready)
TCP/IP stack configuration file net_cfg.c
Start up routine file startup_RIN32M3.c
system_RIN32M3.c
Compile
HW-RTOS driver library file libos.a
TCP/IP stack library file libunet3.a
Link information file Makefile or IDE scat.ld
Makefile
Link
Files created by user
Files produced by Renesas Electronics
Execution file
.elf
Fig. 1.1 The figure of relationship among files
R18UZ0019EJ0300
Feb 28, 2015
Page 3 of 168
R-IN32M3 Series 2. Basic concepts of R-IN32M3 TCP/IP stack
2. Basic concepts of R-IN32M3 TCP/IP stack
2.1 Glossary
2.1.1 Protocol
Protocol is a set of rules that determines the method and the procedure of transmitting data between networks.
R-IN32M3 TCP/IP stack adopts this protocol (=communication rule). These rules are called Request For Comments
(abbreviation: RFC)”, its specification is published.
2.1.2 Protocol stack
Choose a necessary protocol in order to implement functions on network, and a protocol stack is a prescribed hierarchy of software layers. The following figure shows the hierarchy in µNet3.
TCP/IP hierarchical model
Application layer
HTTP
R-IN32M3 TCP/IP stack hierarchical model
FTP DHCP
API
DNS
Transport layer TCP UDP
IGMP ICMP
Nerwork layer IP
ARP
Data link layer
Ethernet Driver
Hardware
Fig. 2.1 Figure of TCP/IP hierarchical model and R-IN32M3 TCP/IP stack hierarchical model
R18UZ0019EJ0300
Feb 28, 2015
Page 4 of 168
R-IN32M3 Series 2. Basic concepts of R-IN32M3 TCP/IP stack
2.1.3 IP address
Each node on the network has a specific logical number, it is called “IP address”. IP address has 32 bit address space, be represent as 192.168.1.32.
(1) Broadcast address
Broadcast means that the same data is simultaneously sent (broadcast communication) to all of the nodes in one network. The address is allocated particularly to broadcast called “Broadcast address”. Ordinarily in “Broadcast address”, all bits use 1 IP address “255.255.255.255”.
(2) Multicast address
Contrary to the broadcast that send data to all nodes, a special address is used to send data to a specific group only, is called “Multicast address”.
2.1.4 MAC (Media Access Control) address
Contrary to a logical address “IP address”, a physical address specify to an installed hardware in order to identify network devices such as LAN card is called “MAC address”. “MAC address” has 48-bit address space and to be notated
12-34-56-78-9A-BC or 12:34:56:78:9A:BC.
2.1.5 Port number
In network communication, a number identifies a program of communication partners is called “Port number”. The node that communicate through TCP/IP has IP address that corresponds to the address inside the network, but in order to communicate with more than one node at the same time, we use port number in the range from 1 to 65535 as auxiliary address. If port number is set 0 (PORT_ANY) then automatically ephemeral port number is allocated.
2.1.6 Big endian and little endian
The way multibyte numerical data is stored in memory is called “Endian”. “Big endian” refers to the way that store the most significant byte in the sequence. “Little endian” refers to the way that store the least significant byte in the sequence
It is determined that the header information is transmitted by “big endian” through TCP/IP.
2.1.7 Packet
The Unit of data transceiver is called “packet”. The packet includes 2 kinds of information. One contains actual stored data (data area) and the other contains the information used to manage as the information of source or destination of that data, error checking information (header area).
2.1.8 Host and node
Host refers to the computer that communicates on the network. And the connection points in a network such as server, client, hub, router, access point etc. are called “node”.
R18UZ0019EJ0300
Feb 28, 2015
Page 5 of 168
R-IN32M3 Series 2. Basic concepts of R-IN32M3 TCP/IP stack
2.1.9 Address Resolution Protocol (ARP)
A protocol used to translate the physical address (MAC address) from logical address (In case of TCP/IP, that is IP address) is called “ARP”.
2.1.10 Internet Protocol (IP)
(IP protocol)” is an very important protocol of the upper layer. The role of “IP” is to transfer data to the destination through the router based on the IP address without however ensuring their delivery, thus, ensuring the reliability of data is upper layer’s responsibility
“IP address” mentioned above is placed in the header of this “IP protocol”.
2.1.11 Internet Control Message Protocol (ICMP)
A protocol provides the function that is to notify errors occurred in IP network communication and verify the state of network status is called “ICMP”. There are echo request and echo reply messages are called Ping which most well-known.
2.1.12 Internet Group Management Protocol (IGMP)
The protocol executes IP Multicast is called “IGMP”. We can usually send the same data to many different hosts efficiently.
2.1.13 User Datagram Protocol (UDP)
A protocol provides the connectionless mode datagram communication service is called “UDP”. IP does not have interface with application. “UDP” is the protocol which helps to use that function from application. As a result, there is no way to notify that packets have arrived to the partner and the order of arrived packets may be changed so UDP does not sure the reliability of data.
2.1.14 Transmission Control Protocol (TCP)
A protocol which provides connection mode stream communication service is called “TCP”. “TCP” is known as upper layer of IP protocol, which provides a reliable communication as flow control, retransmission, error correction and sequence control.
2.1.15 Dynamic Host Configuration Protocol (DHCP)
When connecting to a network, a protocol which assigns automatically the necessary information such as IP address is called “DHCP”. To use “DHCP”, we have to prepare DHCP server and on server side, it’s necessary to prepare some
IP addresses for DHCP client in advance (Address pool).
R18UZ0019EJ0300
Feb 28, 2015
Page 6 of 168
R-IN32M3 Series 2. Basic concepts of R-IN32M3 TCP/IP stack
2.1.16 Hyper Text Transfer Protocol (HTTP)
A protocol used to transfer the contents such as HTML file of homepage or website is called “HTTP”. “HTTP” not only can transfer HTML file but also can send binary data which are displayed on WEB browser such as JPEG, GIF,
PNG, ZIP file.
2.1.17 File Transfer Protocol (FTP)
We call the protocol which transfer files between hosts is “FTP”.
2.1.18 Domain Name System (DNS)
A name resolution mechanism which can exchange host name into IP address or IP address into host name (domain) is called DNS. In case of using “DNS”, it is possible to look up the host name based on IP address or look up IP address from the host name.
2.1.19 Socket
An endpoint for communication which applications use for communicating TCP/IP is called “socket”. “Socket” is constructed by IP address and port number. The applications, through specifying the socket to establish a connection, can transceive data without caring about any details of communication procedure. There are varieties of sockets depending on the protocol used in communication side. TCP socket uses TCP protocol to communicate data and UDP socket uses UDP protocol to communicate data. In R-IN32M3 TCP/IP stack, we use ID number to identify the socket which becomes an operational objective. The application utilizes ID number to invoke socket API.
2.1.20 Blocking and non-blocking
When calling some function, if it does not return until the action has completed, that is called “Blocking mode” and if it returns immediately without waiting for its completion, that is called “Non-blocking mode”.
For instance, in the socket API ofμNe3, the task calling the rcv_soc function in “Blocking mode” is placed in the waiting status until that action completes (until data can be received). Calling the rcv_soc function in “Non-blocking mode” will return immediately with an E_WBLK error code and the completion of that action (EV_RCV_SOC) is notified to callback function.
By default, the R-IN32M3 TCP/IP stack sockets are in “Blocking mode”, and in order to switch to “Non-blocking mode”, we have to use cfg_soc function and set up registration of callback function and callback event flag.
2.1.21 Callback function
The function used for notifying the status of protocol stack to the applications asynchronously is called “Callback function”.
R18UZ0019EJ0300
Feb 28, 2015
Page 7 of 168
R-IN32M3 Series 2. Basic concepts of R-IN32M3 TCP/IP stack
2.1.22 Task context
All API functions of R-IN32M3 TCP/IP stack must be called from Task context.
Do not call the system call which is in status of waiting for tasks such as slp_tsk from network callback function.
Besides, do not call all API functions of R-IN32M3 TCP/IP stack from network callback function.
2.1.23 Resource
The resource used in a program is called “Resource”. There include tasks, semaphores are called “Kernel objects” and memory.
※Please make reference to OS User Guide on details of “Kernel object” such as tasks, semaphores.
2.1.24 MTU
In communication network, MTU (Maximum Transfer Unit) is a value indicating the maximum amount of data that can be transferred by one-time transfer. Moreover, MTU also shows the maximum data size of the frame in data link layer. In addition, the minimum value indicated by MTU is 68 bytes.
Specifying the maximum data size depends on the protocol used in data link layer and in Ethernet interface generally uses 1500 bytes.
2.1.25 MSS
MSS (Maximum Segment Size) indicates the maximum data size of TCP packet. Therefore, MSS value can be calculated by the following formula.
MSS = MTU– (IP Header size+ TCP Header size (normally 40 bytes))
In case of Ethernet interface, the value of MSS is generally 1460 bytes.
2.1.26 IP reassembly - fragment
The maximum size of an IP packet is 64K bytes. However, in order that MTU of communication interface becomes a smaller value than the original, it’s necessary that IP module must divide IP packet into smaller pieces to send. This processing is called “IP fragmentation” and divided IP packet is called “IP fragment”.
Moreover, IP module of receiver side needs to combine the divided “IP fragment” and we call this process is “IP reassembly”.
R18UZ0019EJ0300
Feb 28, 2015
Page 8 of 168
R-IN32M3 Series
2.2 Architecture of Network system
2.2.1 Block diagram of network system
SOCKET0
Device_num0
2. Basic concepts of R-IN32M3 TCP/IP stack
Application program
R-IN32M3 TCP/IP stack
Application interface
SOCKET1
Device_num1
SOCKETN
Device_numN gNET[0] gNET_DEV[0] gNET_ADR[0] gNET_CFG[0]
TCP/IP protocol stack gNET[Device_numN-1] gNET_DEV[Device_numN-1] gNET_ADR[Device_numN-1] gNET_CFG[Device_numN-1]
Network device control API
Network buffer
Network device driver
(Device number = 1)
Network device driver
(Device number = N)
Network device (ex: Ethernet) Network device (ex: PPP)
Fig. 2.2 Block diagram of network system
• Application program
The application program is used for network communication. It includes application protocols such as DHCP, FTP,
Telnet, HTTP etc.
R18UZ0019EJ0300
Feb 28, 2015
Page 9 of 168
R-IN32M3 Series 2. Basic concepts of R-IN32M3 TCP/IP stack
• Application Interface
Providing the interface (API) to utilize various network services such as transmission / reception of data or establishing connection to remote host.
In case of normal application, we have to specify socket ID and device number before using Application Interface.
• TCP/IP protocol stack
This program handles the network protocols such as TCP, UDP, ICMP, IGMP, IP and ARP.
• Network device control API
In network system, maybe there exist various network devices. Every device needs a device driver. And the network device control API absorbs the difference between these devices, provides interface in order to access unifiedly. Using device number from application program before accessing to the devices.
• Network device driver
A program that control network device. The content integration is different depending on the device.
In R-IN32M3 TCP/IP stack, it is provided standard Ethernet driver device.
• Network device
The hardware that execute the transmission and reception of actual network data. This refers to Ethernet, PPP (RS-
232), and WLAN etc.
• Others
R-IN32M3 TCP/IP stack using the below OS Kernel objects:
Table 2.1 OS Kernel objects which are used in TCP/IP stack for R-IN32M3
Object
Task
Task
Task
Task
Task
Semaphore
Event flag
Event flag
Event flag
Event flag
Mailbox
Mailbox
Object ID
ID_NET_MAIN_TSK
ID_TASK_TCP_TIM
ID_TASK_ETH_SND
ID_TASK_ETH_RCV
ID_TASK_PHY_LINK
ID_SEM_TCP
ID_FLG_ETH_RX_MAC
ID_FLG_ETH_TX_MAC
ID_FLG_PHY_STS
ID_FLG_SYSTEM
ID_MBX_ETH_SND
ID_MBX_ETH_MEMPOL
Usage
R-IN32M3 TCP/IP stack startup task
R-IN32M3 TCP/IP stack time management task
Ether driver send task
Ether driver receive task
Ether driver control task
R-IN32M3 TCP/IP stack resource control semaphore
Ether driver event flag
Ether driver event flag
Ether driver event flag
Ether driver event flag
Ether driver mail box
Ether driver mail box
R18UZ0019EJ0300
Feb 28, 2015
Page 10 of 168
R-IN32M3 Series 2. Basic concepts of R-IN32M3 TCP/IP stack
Table 2.2 Hardware ISR which are used in TCP/IP stack for R-IN32M3
The factor of Hardware ISR
PHY0_IRQn
PHY1_IRQn
ETHTXDMA_IRQn
ETHTXDERR_IRQn
ETHTX_IRQn
ETHTXFIFO_IRQn
ETHTXFIFOERR_IRQn
ETHRXDMA_IRQn
ETHRXFIFO_IRQn,
ETHRXDERR_IRQn
ETHRXERR_IRQn
Operation set_flg() set_flg() set_flg() set_flg() set_flg() set_flg() set_flg() set_flg() set_flg() set_flg() set_flg()
Use information
PHY driver
PHY driver
Ethernet driver in transmit operation
Ethernet driver in transmit operation
Ethernet driver in transmit operation
Ethernet driver in transmit operation
Ethernet driver in transmit operation
Ethernet driver in receive operation
Ethernet driver in receive operation
Ethernet driver in receive operation
Ethernet driver in receive operation
2.3 Directory and file organization
These files as below are included in R-IN32M3 TCP/IP stack.
(1) Header File
/Source/Middleware/uNet3/Inc/ net_cfg.h Default configuration macro of TCP/IP protocol stack net_hdr.h Definition of the necessary information to use TCP/IP protocol stack
Please include this header file in source file of applications.
(2) Library files
<R>
This folder stores the library that has already built the TCP/IP protocol stack in various processor mode, and the project files are used to build.
/Library/<TOOL>/ libunet3.a
Libunet3bsd.a
TCP/IP protocol stack library
TCP/IP protocol stack library (BSD interface)
<TOOL> depends on development tool chain. (ARM/GCC/IAR)
R18UZ0019EJ0300
Feb 28, 2015
Page 11 of 168
R-IN32M3 Series 2. Basic concepts of R-IN32M3 TCP/IP stack
(3) Ethernet device driver file
<R>
/Source/Driver/ether_uNet3/
DDR_ETH.c
DDR_PHY0.c
DDR_PHY1.c
/Source/Driver/ethsw/
Ethernet driver
PHY driver for LAN1
PHY driver for LAN2 ethsw.c Ethernet Switch driver
/Include/ ether_uNet3/
DDR_ETH.h
DDR_PHY.h
COMMONDEF.h
Ethernet driver header
PHY driver common header
DDR_ETH_CFG.h Ethernet driver configuration header
Ethernet driver common definition header
/Include/ ethsw/ ethsw.h Ethernet Switch driver header
(4) Application protocol source file
<R>
/Source/Middleware/uNet3/NetApp/ dhcp_client.h dhcp_client.c ftp_server.h ftp_server.c http_server.h http_server.c dns_client.h dns_client.c ping_client.h ping_client.c sntp_client.h sntp_client.c net_strlib.h net_strlib.c
/Source/Middleware/uNet3/NetApp/ext/ dhcp_client.h dhcp_client.c
DHCP client macro, prototype, definition etc.
DHCP client source code
FTP server macro, prototype, definition etc.
FTP server source code
HTTP server macro, prototype, definition etc.
HTTP server source code
DNS client macro, prototype, definition etc.
DNS client source code
ICMP echo request macro, prototype, definition etc.
ICMP echo request (ping) source code.
SNTP client macro, prototype, definition etc.
SNTP client macro source code.
String library function definition.
String library function source code.
DHCP client extended version macro, prototype, definition etc.
DHCP extended version client source code
R18UZ0019EJ0300
Feb 28, 2015
Page 12 of 168
R-IN32M3 Series
(5) Sample source file
/Source/Project/uNet3_sample/ cgi_sample.c html.h kernel_cfg.c kernel_id.h main.c net_cfg.c net_sample.c
2. Basic concepts of R-IN32M3 TCP/IP stack
CGI application sample
HTML data
OS resources configuration file
OS resources ID definition file
Main function
TCP/IP stack configuration file
Network application sample
R18UZ0019EJ0300
Feb 28, 2015
Page 13 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3. Overview functions of R-IN32M3 TCP/IP stack
3.1 Protocol stack
3.1.1 IP module
The IP module only receives and handles the arrived packets which has destination IP address matches with the IP address of local host. Other packets are not handled.
(1) IP Option
R-IN32M3 TCP/IP stack supports router warning option of internal IGMP in IP option only. IP options which do not support will be ignored. .
(2) TTL (Time to Live)
Default value of TTL in R-IN32M3 TCP/IP stack is set DEF_IP4_TTL(64). This value may be changed by using net_cfg(). In case of using net_cfg() to change the value of TTL, TTL value of all sockets are changed. In case that we want to change TTL value of each socket, please use cfg_soc().
(3) TOS (Type Of Service)
In R-IN32M3 TCP/IP stack, TOS is set DEF_IP4_TOS (0).
(4) Broadcast
Maybe receive broadcast or not depending on using net_cfg(). The initial value is set that ready to receive. Always can transmit broadcast. The broadcast setting is effective for all sockets but we cannot set up whether receive broadcast by socket unit.
Regarding to transceive broadcast, please use UDP socket.
(5) Multicast
In order to allow multicast reception, we use net_cfg() and register at the address of the multicast group which join to.
Multicast group address may be registered by DEF_NET_MGR_MAX (8).
Always can send multicast. The multicast setting is effective for all sockets but we cannot set up whether receive multicast by socket unit.
TL used for transferring multicast is set DEF_IP4_MCAST_TTL (1). This value can also be changed by using net_cfg().
Do not support multicast loopback.
Regarding to transceive of multicast, please use UDP socket.
(6) MTU
In R-IN32M3 TCP/IP stack, DEF_PATH_MTU (1500 byte) is set as default value of MTU. This value can be configured by the configurator.
R18UZ0019EJ0300
Feb 28, 2015
Page 14 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
(7) IP reassembly / fragment
In R-IN32M3 TCP/IP stack, maximum size of IP packet is 1500 byte as default (This value is related to the value of network buffer). In order to increase the size of IP packet to maximum, we need to enlarge the network buffer. For example, in case that transceive 2048byte of UDP data, we need to increase the value of network buffer larger than the value is calculated from this formula (control header size (100 bytes) + IP header size (20bytes) + UDP header size
(8bytes) + 2048).
The default value of IP reassembly process timeout is DEF_IP4_IPR_TMO(10 seconds). If the reassembly process cannot complete within this timeout, the reassembly process is cancelled, the ICMP error message (type 11: packet discarded by time excess) is sent to remote host.
The default number of times of the IP reassembly process is set DEF_NET_IPR_MAX(2). DEF_NET_IPR_MAX value expresses a value which host can execute IP reassembly process at the same time.
(8) IGMP
In R-IN32M3 TCP/IP stack, the timeout until the “report (reply)” message is sent to “query (group inquiry)” (from router) is set by DEF_IGMP_REP_TMO (10 seconds)
R-IN32M3 TCP/IP stack supports IGMPv2 and also supports IGMPv1 compatible function.
In case of getting query of IGMPv1, it will be changed into IGMPv1 mode and then processed. After that, within a certain time period, if there is no IGMPv1 message, it will be back to IGMPv2 mode. Timeout for returning from IGMPv
1 to IGMPv 2 is set by DEF_IGMP_V1_TMO (400 seconds).
(9) ICMP
R-IN32M3 TCP/IP stack supports messages of “echo response”, “echo request”, “time excess”.
R18UZ0019EJ0300
Feb 28, 2015
Page 15 of 168
R-IN32M3 Series
3.1.2 ARP module
3. Overview functions of R-IN32M3 TCP/IP stack
(1) Resolve ip address
R-IN32M3 TCP/IP stack will manage the mapping of IP address of host and physical address (MAC address). The administration table (conversion table) of this mapping is called ARP cache. ARP cache size is set by
DEF_NET_ARP_MAX (8).
When sending IP packet to network, in case that there exists a compatible IP address which refers to ARP cache, it will send a packet to the destination that is the physical address has been recorded there. In case that there is no existing IP address, IP packet will be stored temporarily in queue, then, send broadcast ARP request packets. After receiving ARP response packets from remote host, record a received physical address in ARP cache newly. Then, remove IP packet from queue, send the packet to the newly acquired physical address.
Besides, ARP entry information is held in the cache table for a maximum of ARP_CLR_TMO (20 minutes).
(2) Address conflict detection
According RFC5227, R-IN32M3 TCP/IP stack will check whether Ipv4 address is non-duplicative in the same link.
This feature is performed by API is called from application, when LAN interface boot up or link status changes.
After setting the IP address of the interface, the other host had set the same IP address, then the detected the conflict,
R-IN32M3 TCP/IP stack will notify the application.
"ARP Probe" can detect whether the IP address that you will use is not already in use.
Other host did not respond to "ARP Probe"(IP address conflict is not), R-IN32M3 TCP/IP stack notify the other hosts that to use this IP address from now by sending the "ARP Announce".
3.1.3 UDP module
UDP executes the transceiver of data without connecting to remote host.
(1) Sending data
Before sending data, we should use con_soc and associate a socket with a source address (IP address, port number).
After that, we use snd_soc() to send data. The flow snd_soc() processing is described in the diagram as below.
R18UZ0019EJ0300
Feb 28, 2015
Page 16 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack snd_soc()
Copy data into
Network buffer
UDP packet construction
ARP entry existence
Yes
No
ARP response waiting
ARP solution
IP fragmentation
Yes
Data length>1472
No dev_snd()
ARP timeout
E_TMOUT
Return
Fig. 3.1 The flow of snd_soc processing of UDP socket
4. The application data is copied into network buffer, adding UDP header such as port number,IP address of remote host,then construct UDP packet.
5. In case that cannot resolve MAC address of remote host by ARP protocol, it will return E_TMOUT error.
6. In default, the maximum size of transmission data is set 1472 bytes (DEF_PATH_MTU (1500 bytes) – IP header size– UDP header size). In case of sending data with larger size than this, we need to set network buffer size.
Regarding the details, please refer to the item of IP reassembly/fragment
R18UZ0019EJ0300
Feb 28, 2015
Page 17 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
(2) Data reception
Data reception is executed by using rcv_soc(). The flow of rcv_soc() processing is described in the diagram as below. rcv_soc()
Is UDP packet is enable?
Yes
No
Receive UDP packet
Wait UDP packet
Copy UDP packet into application buffer
Timeout
E_TMOUT
Return
Fig. 3.2 The flow of rcv_soc processing of UDP socket
7. If UDP packet has not been received yet, enter a state of waiting for UPD packet reception. At that time, if it exceeds timeout of receiving socket, it will return E_TMOUT.
8. If received packet size is smaller than requested data size, copy into application buffer. In case that received packet with bigger size, just copy the request size into application buffer. Remaining part will be ignored.
9. In default, maximum size of reception data is set 1472 bytes (DEF_PATH_MTU (1500 bytes) – IP header size–
UDP header size). In case of receiving data with larger size than this, we need to set network buffer size. Regarding the details, please refer to the item of IP reassembly/fragment.
3.1.4 TCP module
TCP is different from UDP. TCP is connection mode, so it can allocate sending party and channels before transceiving data. TCP sequence is described in the diagram as below.
R18UZ0019EJ0300
Feb 28, 2015
Page 18 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
Create Socket con_soc()
SOC_SER
Waiting for passive open con_soc()
SOC_TCP_SHT
Disconnect transmission
Unused
Connection error con_soc()
SOC_CLI
Waiting for active open con_soc() completion
Establish connection
Connection is established
Possible to transceive data by snd_soc / rcv_soc con_soc()
SOC_TCP_CLS
Interrupt connection or finished connection con_soc()
SOC_TCP_CLS
While disconnecting cls_soc() completion
Fig. 3.3 TCP sequence
(1) Establishing connection
There are two modes of TCP connection, active and passive connection. Active connection that requires connect to remote host by itself. On the contrary, passive connection that wait for the connection from remote host.
Use con_soc() to connect, and need to specify active connection by SOC_CLI and passive connection by SOC_SER.
(2) Connection completion
In order to disconnect the connection, we use cls_soc(). Specify SOC_TCP_CLS in order to disconnect all the connection completely, and SOC_TCP_SHT to disconnect the transmit direction only.
R18UZ0019EJ0300
Feb 28, 2015
Page 19 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
(3) Data transmission
Use snd_soc() to send data. The flow of snd_soc() processing is described as below. snd_soc()
Transmission buffer is empty?
Yes
Copy application data into transmission buffer
No Transmission buffer empty waiting
Waiting timeout or
Transmission process interrubtion
Return
(size of copied data)
Return
(error)
Fig. 3.4 TCP socket–Flow of snd_soc processing
10. Copy data of application into TCP transmission buffer. If copy is successful, TCP protocol will send data. If remote host received data, all data in TCP transmission buffer will be clear.
•
TCP transmission buffer
It is necessary to specify transmission buffer size when create TCP socket. Buffer size has a range from 4 bytes to 32 kilobytes and aligns to 2 power 2.
(4) Data reception
Use rcv_soc() to send data. Received TCP packet firstly will be registered at TCP reception buffer. When rcv_soc() is called, it will be copied from TCP reception buffer into application buffer.
•
TCP reception buffer (Window buffer)
It is necessary to specify reception buffer size when create TCP socket. Buffer size has a range from 4 bytes to 32 kilobytes and aligns to 2 power 2.
R18UZ0019EJ0300
Feb 28, 2015
Page 20 of 168
R-IN32M3 Series
(5) Retransmission timeout
Timer sequence of resending is described in the diagram as below.
3. Overview functions of R-IN32M3 TCP/IP stack
Host 1
SYN
SYN
Host 2
RTO = 3s.
RTT calculation
{
Host 1
DATA
DATA
Host 2
SYN
RTO = 6s.
DATA
RTO = 0.5 s.
・
・
RTO = 12s.
DATA
RTO = 1s.
A) SYN retransmission
・
・
B) DATA retransmission
RTO = 2s.
・
・
RTO = 60s.
Fig. 3.5 An example of retransmission timer
In TCP, if there are not response of ACK packet within a certain time for any reason, segment without response will be sent again. The waiting time until retransmission action is executed is called “RTO” (Retransmission Time Out). Initial value of RTO is called “RTT” (Round Trip Time), is “4 times+α” of “Time that packet makes round trip to the other). RTO value is increased twice every time resending action is done.
When retransmit SYN like the above A diagram, it uses DEF_TCP_RTO_INI (3 seconds) due to RTT value is not set. In the above B diagram of data retransmission, it calculates RTT value based on the previous successful transmission, that’s 500 milliseconds.
RTO scope is set from DEF_TCP_RTO_MIN (500 ms) to DEF_TCP_RTO_MAX (60 s).
R18UZ0019EJ0300
Feb 28, 2015
Page 21 of 168
R-IN32M3 Series
(6) Connection timeout
Connection timer sequence is described in the below diagram.
3. Overview functions of R-IN32M3 TCP/IP stack
Host 1
SYN
SYN/ACK
Host 2
Timer ON
75 s.
ACK
Timer OFF
Host 1 con_soc() SYN
SYN
SYN
Host 2
Timer ON
75 s.
A) TCP connection success
E_TMOUT
B) TCP connection timeout
Timeout
Fig. 3.6 An example of connection timeout
(A). If finish timeout, it will return E_TMOUT (B).
Timeout value of connection process (3-way handshake) is set DEF_TCP_CON_TMO (75 seconds).
※When create TCP socket, it can specify blocking timeout used in connection. If this value runs out of time, connection process will be interrupted immediately and con_soc() will return E_TMOUT.
When call con_soc(), if this timer completes from starting up to three-way handshake timed out, it will return E_OK
(7) Transmission timeout
Transmission timeout is set DEF_TCP_SND_TMO (64 seconds). While communicating data, if there is no response from the partner even though passes DEF_TCP_SND_TMO, the connection will be disconnected.
(8) Disconnection timeout
Timeout of disconnection process is set DEF_TCP_CLS_TMO (64 seconds). If cls_soc() does not complete at
DEF_TCP_CLS_TMO, connection will be forcibly disconnected and cls_soc() will return E_TMOUT.
※When create TCP socket, it can specify blocking timeout used in connection. If this value runs out of time, connection process will be interrupted immediately and cls_soc() will return E_TMOUT.
(9) Delay ACK timeout
Delay ACK timeout is set DEF_TCP_ACK_TMO (200 milliseconds).
R18UZ0019EJ0300
Feb 28, 2015
Page 22 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
(10) TCP congestion control
R-IN32M3 TCP/IP stack supports fast retransmit and fast recovery. Number of duplicate ACK is set
DEF_TCP_DUP_CNT (4).
(11) Maximum Segment Size (MSS)
MSS is set DEF_TCP_MSS (1460 bytes).
(12) Keep Alive
R-IN32M3 TCP/IP stack supports TCP Keep Ailve.
Get ACK t t
0 t
1 t
1 t
1 t
1 t
0
Start of non communication
Close
Keep on sending Keep Alive c times t
0
= The time of activation Keep-Alive t
1
= The interval of transmission Keep-Alive c = The number of transmission Keep-Alive
Start of non communication
Fig. 3.7 Operation TCP Keep Alive
If Keep Alive feature is enabled (c > 0), after t
0
seconds in non-communication state, start the transmission of Keep
Alive packet to the destination host.
Until it is transmitted c times, or get ACK from destination, R-IN32M3 TCP/IP stack will continue to send the Keep
Alive packets at intervals of t
1
seconds.
If no response is obtained in c times Keep Alive packet, then R-IN32M3 TCP/IP stack close TCP connection.
It does not disconnect TCP connection automatically if Keep Alive feature is disable (c = 0)
R18UZ0019EJ0300
Feb 28, 2015
Page 23 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.2 Network device driver
Because protocol stack will access to device driver through T_NET_DEV structure, so the information as device name, device number, the functions of device driver must be registered in T_NET_DEV structure in advance. Protocol stack specify and access to the device which is registered in T_NET_DEV by device number.
3.2.1 Device structure
typedef struct t_net_dev {
UB name[8];
FP
FP
FP
FP
UH
UH
UH
UH
FP
FP
UW union
UH
UH
} T_NET_DEV; num; type; sts; flg; ini; cls; ctl; ref; out; cbk;
*tag; cfg; hhdrsz; hhdrofs;
/* Device name*/
/* Device number */
/* Device type */
/*Reserve*/
/*Reserve */
/*Pointer to dev_ini function*/
/* Pointer to dev_cls function*/
/* Pointer to dev_ctl function*/
/* Pointer to dev_ref function*/
/* Pointer to dev_snd function*/
/* Pointer to dev_cbk function*/
/* Reserve*/
/* MAC address */
/* Device header size */
/* Position writing network buffer */
(1) Device number
Set unique number to specify device. Protocol stack will use this number to access to the device. Device number should be numbered consecutively from 1.
(2) Device name
Set the name in order to specify the device. The length of device name should be under 8 bytes long.
For example: eth0, eth1 etc.
R18UZ0019EJ0300
Feb 28, 2015
Page 24 of 168
R-IN32M3 Series
(3) Device type
Set type of network device. There are some as below.
Device type
NET_DEV_TYPE_ETH
NET_DEV_TYPE_PPP
Ethernet device
PPP device
3. Overview functions of R-IN32M3 TCP/IP stack
Meaning
(4) Function of driver device
Prototype Description
ER dev_ini(UH dev_num)
ER dev_cls(UH dev_num)
Device initialization
Device release
ER dev_snd(UH dev_num, T_NET_BUF *pkt) Send packet to network
ER dev_ctl(UH dev_num, UH opt, VP val)
Device control
ER dev_ref(UH dev_num, UH opt, VP val) void dev_cbk(UH dev_num, UH opt, VP val)
Device status acquisition
Notify event from device (callback function)
Device driver needs to support the below functions. These functions are called from appropriate protocol stack.
Requirement
Require
No require
Require
No require
No require
No require
(5) MAC address
Set unique value to specify hardware. union { struct {
UB mac[6]; /* MAC address */
}eth;
} cfg;
(6) Device header size
<R>
Header size of network device header size is set.
(7) Position writing network buffer
<R>
Network buffer data offset is set. This parameter must be “42”.
R18UZ0019EJ0300
Feb 28, 2015
Page 25 of 168
R-IN32M3 Series
3.2.2 Interface
3. Overview functions of R-IN32M3 TCP/IP stack dev_ini Device initialization
【Format】
ER ercd = dev_ini(UH dev_num);
【Parameter】
UH
【Return value】 dev_num
ER ercd
【Error code】
E_ID
E_OBJ
E_PAR
<0
Device number
Successful completion (E_OK) or error code
Device number is wrong
Already initialized
Illegal value set in T_NET_DEV
Other errors (implementation dependent)
【Explanation】
Initialize device. This function is called to initialize device from protocol stack. Before calling this function, it is necessary to register device information in T_NET_DEV. dev_cls Device release
【Format】
ER ercd = dev_cls(UH dev_num);
【Parameter】
UH
【Return value】
ER
【Error code】
E_ID
E_OBJ dev_num ercd
Device number
Successful completion (E_OK) or error code
Device number is wrong
Already released
【Explanation】
Release device.
R18UZ0019EJ0300
Feb 28, 2015
Page 26 of 168
R-IN32M3 Series dev_ctl
3. Overview functions of R-IN32M3 TCP/IP stack
Device control
【Format】
ER ercd = dev_ctl(UH dev_num, UH opt, VP val);
【Parameter】
UH
UH
VP dev_num opt val
Device number
Control code
Value to be set
【Return value】
ER
【Error code】
E_ID
E_PAR
E_OBJ ercd
Device number is wrong
Illegal parameter
Already released
Successful completion (E_OK) or error code
【Explanation】
The operation of this function is implementation dependent. dev_ref Device status acquisition
【Format】
ER ercd = dev_ref(UH dev_num, UH opt, VP val);
【Parameter】
UH
UH
VP dev_num opt val
Device number
Status code
Acquire value
【Return value】
ER
【Error code】
E_ID
E_PAR
E_OBJ ercd
Device number is wrong
Illegal parameter
Already released
Successful completion (E_OK) or error code
【Explanation】
The operation of this function is implementation dependent.
R18UZ0019EJ0300
Feb 28, 2015
Page 27 of 168
R-IN32M3 Series dev_snd
3. Overview functions of R-IN32M3 TCP/IP stack
Packet transmission
【Format】
ER ercd = dev_snd (UH dev_num, T_NET_BUF *pkt);
【Parameter】
UH
T_NET_BUF dev_num
*pkt
Device number
Pointer to network buffer
【Return value】
ER
【Error code】
E_WBLK
E_ID
E_PAR
E_TMOUT
E_OBJ ercd Successful completion (E_OK) or error code
Packet is registered in queue (not error)
Device number is wrong
Illegal parameter
Packet transmission timed out
Device status was wrong already
【Explanation】
This function transmits packet to Ethernet.
R18UZ0019EJ0300
Feb 28, 2015
Page 28 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
An example of integration
ER dev_snd(UH dev_num, T_NET_BUF *pkt)
{
/* Copy to Ethernet frame (IP/TCP/UDP/Payload) */ memcpy(txframe, pkt->hdr, pkt->hdr_len);
/* Transmit to network */ xmit_frame(txframe); return E_OK;
}
In the above example, the process of protocol stack is blocked by device driver. The next example shows the example that using queue and no blocking.
Non-blocking example
ER dev_snd(UH dev_num, T_NET_BUF *pkt)
{ queue_tx(pkt); /* register packet in queue */ return E_WBLK; /* Non-blocking */
} void queue_tx_task(void)
{ dequeue_tx(pkt); /* Removing packet from queue */
/* Copy to Ethernet frame (IP/TCP/UDP/Payload) */ memcpy(txframe, pkt->hdr, pkt->hdr_len); xmit_frame(txframe); /* Transmit to network */ if (transmission timeout) { pkt->ercd = E_TMOUT; /* Set time out */
} net_buf_ret(pkt);
}
In dev_snd transmission process is not executed, packet will register in queue and return E_WBLK. Actual packet transmission process is executed by another task and release of network buffer is also executed there too.
R18UZ0019EJ0300
Feb 28, 2015
Page 29 of 168
R-IN32M3 Series dev_cbk
3. Overview functions of R-IN32M3 TCP/IP stack
Device event notification
【Format】 void dev_cbk(UH dev_num, UH opt, VP val);
【Parameter】
UH
UH
UH dev_num opt val
Device number
Event code
Event value
【Return value】
None
【Error code】
None
【Explanation】
This function is to notify an event to the application from device driver. This function is implementation dependent.
R18UZ0019EJ0300
Feb 28, 2015
Page 30 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.2.3 packet routing
To send a packet to the upper protocol stack from device driver, it uses the following API.
※This API cannot be used from Applications. net_pkt_rcv Sending packet to protocol stack
【Format】 void net_pkt_rcv(T_NET_BUF *pkt);
【Parameter】
T_NET_BUF
【Return value】
*pkt
None
【Error code】
None
Pointer to network buffer
【Explanation】
This function is to send packet to the upper protocol. The below example shows the example for sending packet to upper protocol stack from device driver.
Example
/* Network buffer allocation */
T_NET_BUF *pkt; net_buf_get(&pkt, len, TMO);
/* Set received Ethernet header to network buffer */ pkt->hdr = pkt->buf + 2; pkt->hdr_len = ETH_HDR_SZ; memcpy(pkt->hdr, rx_frame, pkt->hdr_len);
/* Set received IP payload to network buffer */ pkt->dat= pkt->hdr + pkt->hdr_len; pkt->dat_len = rx_frame_len – pkt->hdr_len; memcpy(pkt->dat, rx_frame + pkt->hdr_len, pkt->dat_len);
/* Device information setting*/ pkt->dev = dev;
/* Transfer network buffer to protocol stack */ net_pkt_rcv(pkt);
Release of network buffer is executed by net_pkt_rcv(). net_pkt_rcv() must be called from task context.
R18UZ0019EJ0300
Feb 28, 2015
Page 31 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.2.4 T_NET_DEV information registration example
<R>
T_NET_DEV information registration example is showed as bellows.
T_NET_DEV information registration example
T_NET_DEV gNET_DEV[] = {
{
"lan0", /* Device Name */
1, /* Device Number */
NET_DEV_TYPE_ETH, /* Device Type */
0, /* Status */
0, /* Flags */
eth_ini, /* Device Init */
eth_cls, /* Device Close */
eth_ctl, /* Device Configure */
eth_sts, /* Device Status */
eth_snd, /* Device Transmit */
eth_cbk, /* Device Callback */
0,
{{{ 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC }}}, /* MAC Address */
ETH_HDR_SZ, /* Link Header Size */
CFG_NET_BUF_OFFSET /* Network buffer data Offset */
}
};
R18UZ0019EJ0300
Feb 28, 2015
Page 32 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.3 Memory management
In protocol stack, it uses network buffer in memory management. By using network buffer, it can allocate the empty block of memory actively. The following diagram shows an example of memory allocation. First, device driver which receives data from hardware will use API network buffer, then allocate memory (net_buf_get). Next, it will set necessary information in allocated memory and then send packet to the upper layer protocol stack (net_pkt_rcv).
Protocol stack
④ net_pkt_rcv()
Send packet to upper layer
Device driver
③ set necessary information in t_net_buf
① Data reception
Hardware
Memory pool
Memory block 0
Memory block 1
② net_buf_get()
Memory allocation
・ ・ ・ ・
Memory block N
Fig. 3.8 Memory allocation diagram
R18UZ0019EJ0300
Feb 28, 2015
Page 33 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.3.1 Network buffer
In R-IN32M3 TCP/IP stack, block size uses maximum 8 memory pool with 1472byte fixed length. Network buffer provides the mechanism that allocate or free memory from this memory pool.
Network buffer organization (T_NET_BUF) typedef struct t_net_buf {
UW *next;
ID
T_NET mpfid;
*net;
T_NET_DEV *dev;
T_NET_SOC *soc;
ER
UH ercd; flg;
UH
UH
UH
UB
UB
UB
} T_NET_BUF ; seq; dat_len; hdr_len;
*dat;
*hdr; buf[];
/*Reserve */
/* ID memory pool */
/* Network interface */
/* Network device */
/* Socket */
/* Error code */
/* Flag used to control protocol stack */
/* Fragment sequence*/
/* Data size of packet */
/* Header size of packet */
/* Showing data position in packet (buf) */
/* Showing header position in packet (buf) */
/* Actual packet*/ protocols.
In TCP/IP, the actual packet data are stored in ‘buf’,‘*dat’,‘*hdr’, ‘hdr_len’,‘dat_len’ are used to access to that.
The R-IN32M3 TCP/IP stack uses T_NET_BUF to transceive packet between protocol and device driver or the
R18UZ0019EJ0300
Feb 28, 2015
Page 34 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
(1) The access between protocol stack and device driver by network buffer
<R> dev ercd flg buf[]
Member hdr/hdr_len dat/dat_len
Send (protocol stack->driver)
This is set for &gNET_DEV[dev_num-1]. dev_num is specified by application.
This shows the reason why driver fails to send. If driver succeed to send, this remains the size specified by protocol stack.
Receive (driver->protocol stack)
This is set for &gNET_DEV[eth_dev_num-1] eth_dev_num is set at initialization.
Not used.
This controls whether hardware checksum is enabled or disabled;
-HW_CS_TX_IPH4(0x0040)
(IP header checksum)
-HW_CS_TX_DATA(0x0080)
(payload data checksum)
This controls whether hardware checksum is enabled or disabled;
-HW_CS_TX_IPH4(0x0040)
(IP header checksum)
-HW_CS_RX_DATA(0x0020)
(payload data checksum)
If above checksum result has an error, please set below bits:
-HW_CS_IPH4_ERR(0x0100)
(IP header checksum error)
-HW_CS_DATA_ERR(0x0200)
(payload data checksum error)
This is set the head address and size of frame data which protocol stack sends.
Driver sends data addressed between hdr and hdr_len offset.
Not used.
This Is set the head address and size of frame data which driver received data.
(In the case of Ethernet frame, header size is 14
Bytes)
This is set head address of data and data size following the frame header received by driver.
(In the case of Ethernet, dat shows the position shifted from hdr to hdr_len offset.)
Packet
This stores actual packet data. buf[0] and buf[1] are 4Byte alignments control buffer.
The data to send or receive can be written upper buf[2].
R18UZ0019EJ0300
Feb 28, 2015
Page 35 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.3.2 API network buffer
※This API network buffer cannot be used from application. net_buf_get Network buffer allocation
【Format】
ER ercd = net_buf_get(T_NET_BUF **buf, UH len, TMO tmo);
【Parameter】
T_NET_BUF
UH
UH
**buf len tmo
Address of buffer that allocate memory
Number of allocating bytes
Timeout specification
【Return value】
ER
【Error code】
E_PAR
E_NOMEM
E_TMOUT ercd
Set wrong parameter value
Unable to allocate memory
Timeout
Successful completion (E_OK) or error code
【Explanation】
Allocate memory from memory pool. Allocated buffer address returns to buf. net_buf_ret Network buffer release
【Format】 void net_buf_ret(T_NET_BUF *buf);
【Parameter】
T_NET_BUF **buf
【Return value】
None
【Error code】
None
Address of buffer that free memory
【Explanation】
Give back memory to the memory pool. If the socket is associated with network buffer, notify the free memory event to the socket.
R18UZ0019EJ0300
Feb 28, 2015
Page 36 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.4 Memory processing I / O
Comparison and writing process of contiguous memory occurred in the protocol are able to defined by user, so that it does not depend on device or compilation environment.
For devices with features DMA, Processing memory copy can use the DMA transfer instead of the memcpy() of standard library.
3.4.1 Memory processing I / O
※memory I/O API must be defined in application always. net_memset Fill block of memory
【Format】
VP net_memset(VP d, int c, UINT n);
【Parameter】
VP int
UINT
【Return value】
VP d c n d
Pointer to the block of memory to fill
Value to be set
Number of bytes to be set
Pointer to the block of memory to fill
【Explanation】
If the memory settings are successful, please return the destination pointer that is specified in the argument. net_memcpy Copy bytes in memory
【Format】
VP net_memcpy(VP d, VP s, UINT n);
【Parameter】
VP
VP d s n UINT
【Return value】
VP d
Pointer to the destination of memory
Pointer to the source of data
Number of bytes to copy
Pointer to the destination of memory
【Explanation】
If the memory copies are successful, please return the destination pointer that is specified in the argument.
R18UZ0019EJ0300
Feb 28, 2015
Page 37 of 168
R-IN32M3 Series net_memcmp
3. Overview functions of R-IN32M3 TCP/IP stack
Compare two blocks of memory
【Format】 int net_memcmp(VP d, VP s, UINT n);
【Parameter】
VP
VP
UINT d s n
【Return value】 int pointer to blocks of memory1 pointer to blocks of memory2
Number of bytes to compare
Comparison result
【Explanation】
Please return 0 if the same value in the specified number of bytes. Otherwise, please return the non-zero.
R18UZ0019EJ0300
Feb 28, 2015
Page 38 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.5 Ethernet device driver
<R>
This device driver is for Ethernet MAC or Ethernet Switch included in R-IN32M3. Ethernet device driver is used by calling from network device driver.
This device driver functions are showed below.
- PHY mode set/get
- PHY speed set/get
- Receive frame filtering
- Dynamic configuration for multicast address filter
- Raw data send/receive API
- Direct MAC mode / Ether Switch mode
- Blocking transmit / non-blocking transmit
- VLAN
3.5.1 Ethernet device driver structure
Ethernet device driver operates with PHY driver which controls MDIO interface. This driver structure is showed below.
Network Application
Ethernet Driver
TX Task
PHY0 Driver
Link Task
RX Task
PHY1 Driver
Link Task
R-IN32M3 MAC Controller
Fig.3.9 Ethernet device driver structure
R18UZ0019EJ0300
Feb 28, 2015
Page 39 of 168
R-IN32M3 Series
3.5.2 Ethernet device driver API
3. Overview functions of R-IN32M3 TCP/IP stack
3.5.2.1 Ethernet driver initialization - eth_ini()
【Prototype】
ER eth_ini(UH dev_num)
【Operation】
Initialize Ethernet driver
【Parameter】 dev_num UH
【Return value】
ER
【Explanation】
E_OK
E_ID
E_PAR
Others
Device number (1)
Success initialization
Undefined device number
Invalid device number
Task wake up error, PHY driver initialization error
This API initialize PHY and MAC controller, and wake up the task which controls Ethernet driver. This function must be called before Ethernet driver is used.
R18UZ0019EJ0300
Feb 28, 2015
Page 40 of 168
R-IN32M3 Series
3.5.2.2 Ethernet driver closed - eth_cls()
【Prototype】
ER eth_cls(UH dev_num)
【Operation】
Ethernet driver is closed
【Parameter】 dev_num UH
【Return value】
ER
【Explanation】
E_OK
PHY, MAC controller stops.
Device number (1)
Exit without error
3. Overview functions of R-IN32M3 TCP/IP stack
R18UZ0019EJ0300
Feb 28, 2015
Page 41 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.5.2.3 Ethernet frame transmit - eth_snd()
【Prototype】
ER eth_snd(UH dev_num, T_NET_BUF *pkt)
【Operation】
Ethernet frame transmit
【Parameter】
UH
UH
UB*
【Return value】
ER dev_num pkt->hdr pkt->hdr_len
E_OK
E_TMOUT
E_WBLK
Device number(1)
Address for transmit data
Transmit data length
Success for transmit
Link down
Non-blocking reception
(Only when non-blocking transit)
No enough memory
MAC controller error
【Explanation】
E_NOMEM
E_SYS
When blocking transmit, this function returns after waits the interrupt for transmit complete. When non-blocking transmit, this function returns with E_WBLK after transmit success. If E_WBLK is returned, Ethernet driver calls back
“eth_raw_snddone()” function when Ethernet frame transmit completed.
R18UZ0019EJ0300
Feb 28, 2015
Page 42 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.5.2.4 Ethernet frame transmit end report - eth_raw_snddone()
【Prototype】 void eth_raw_snddone(T_NET_BUF *pkt)
【Operation】
Ethernet frame transmit complete call-back function
【Parameter】
T_NET_BUF*
ER
【Return value】 void
【Explanation】 pkt pkt->ercd pkt specified to eth_snd()
Transmit result
Ethernet driver is called when non-blocking transmit is completed. This function needs to be registered by application before it’s used. How to registration is showed below.
/* Function body of transmit complete note */
} void eth_raw_snddone(T_NET_BUF *pkt)
{
/* Registration to transmit completion report function */ eth_ctl(1, ETH_OPT_RAW_SNDDONE, (VP)eth_raw_snddone);
The TX task must not be stopped, because this function operates under TX task.
R18UZ0019EJ0300
Feb 28, 2015
Page 43 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.5.2.5 Ethernet frame reception report - eth_raw_rcv()
【Prototype】 void eth_raw_rcv(VP fram, UH len)
【Operation】
Ethernet frame reception report function
【Parameter】
VP
UH
【Return value】 void
【Explanation】 fram len
Reception data address
Reception data length
When Ethernet driver receive a frame, this function is called. This function needs to be registered to application before it is used. Registration example shows below.
/* Receive report function */ void eth_raw_rcv(VP p, UH len)
{
}
/* Receive report function registration */ eth_ctl(1, ETH_OPT_RAW_RXFNC, (VP)eth_raw_rcv);
Rx task must not be stopped because this function operates Rx task. If Ethernet driver is shared with TCP/IP stack, this function is called in driver earlier than in TCP/IP stack. Therefore, received frame data cannot be modified.
R18UZ0019EJ0300
Feb 28, 2015
Page 44 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.5.2.6 PHY ability setting - set_phy_mode()
【Prototype】
ER set_phy_mode(PHY_MODE *mode)
【Operation】
PHY ability setting
【Parameter】
PHY_MODE*
UW
UB
UB
【Return value】
ER
【Explanation】 mode mode->mode mode->nego mode->ch
E_OK
E_PAR others
PHY ability
Speed / Duplex
Auto-negotiation on(TRUE)/off(FALSE)
Target PHY channel
Success
Invalid parameter
PHY driver configuration error
Target PHY is configured to ETH_INT_MII_PHY0 or ETH_INT_MII_PHY1. struct PHY_MODE pmod; pmod.mode = LAN_AUTO_ABILITY; pmod.nego = TRUE; pmod.ch = ETH_INT_MII_PHY0; set_phy_mode(&pmod);
Table. 3.1 PHY ability setting
Value
LAN_10T_HD
LAN_10T_FD
LAN_100TX_HD
LAN_100TX_FD
LAN_1000T_HD
LAN_1000T_FD
LAN_AUTO_ABILITY
10M/Half-duplex
10M/Full-duplex
100M/Half-duplex
100M/Full-duplex
1G/Half-duplex
1G /Full-duplex
Auto select
Description
R18UZ0019EJ0300
Feb 28, 2015
Page 45 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.5.2.7 Get PHY ability - get_phy_mode()
【Prototype】
ER get_phy_mode(PHY_MODE *mode)
【Operation】
Get PHY ability
【Parameter】 mode PHY ability PHY_MODE*
【Return value】
ER
【Explanation】
E_OK
E_PAR
その他
Success
Invalid parameter
PHY driver ability get error
This function is used to get PHY ability (speed, duplex, auto-negotiation on/off), and link status. Application can get
PHY ability anytime. Example is showed below. struct PHY_MODE pmod = {0};
/* Target PHY is set by ETH_INT_MII_PHY0 or ETH_INT_MII_PHY1 */ pmod.ch = ETH_INT_MII_PHY0; get_phy_mode(&pmod);
pmod.mode shows PHY ability (reference Table. 3.1).
pmod.nego shows auto-negotiation enabled(TRUE) or disabled(FALSE). pmod.link shows link-up(TRUE) or link-down(FALSE).
If a PHY is link-down, please notice that PHY ability shows invalid value.
R18UZ0019EJ0300
Feb 28, 2015
Page 46 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.5.2.8 Multicast address filter mode setting - set_mcast_filter_mode()
【Prototype】
ER set_mcast_filter_mode(UINT mode)
【Operation】
Set multicast address filter mode
【Parameter】 mode UINT
【Return value】
ER
【Explanation】
E_OK
E_PAR
Filter mode
Success
Invalid parameter
Filter mode has three modes showed below.
Value
MCRX_MODE_ALLOW
MCRX_MODE_DENY
MCRX_MODE_FILTER
Mode
All multicast address receive mode
Denied to receive multicast address mode
Specified multicast address receive mode
Caution 1 When independent address is set, choose MCRX_MODE_FILTER.
Caution 2 After MCRX_MODE_DENY is set, already registered multicast address is deleted all.
R18UZ0019EJ0300
Feb 28, 2015
Page 47 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.5.2.9 Add multicast address filter - add_mcast_filter()
【Prototype】
ER add_mcast_filter(MAC_FILTER *adr)
【Operation】
Add multicast address to receive
【Parameter】
MAC_FILTER*
UB
UB
【Return value】
ER
【Explanation】 adr adr->mac[6] adr->bitnum
E_OK
E_PAR
Multicast address to receive
Multicast address to add
Valid bit number (0, 40-48)
Success
Invalid parameter
Filter mode must be set to MCRX_MODE_FILTER to add multicast address for receive.
Multicast address is shown as combination with lower 23 bits of class D IP address (1 st
octets is
0xE0~0xEF(224~239)) and upper 25 bits (0x01.0x00.0x5e.0x00/25). Application has to calculate receive MAC address from entering multicast IP address. Valid bits are specified 40 bits (5 octets) to 48 bits bit-by-bit. If 0 is set, it seems to be no valid bits (equal 48).
In case that all MAC address 01:00:5e:00:01:* (* is any value) can be received, the example is showed below.
MAC_FILTER adr;
UB macadr[] = {0x01, 0x00, 0x5e, 0x00, 0x01, 0x00}; memcpy(&adr.mac[0], macadr, 6); adr.bitnum = 40; add_mcast_filter(&adr);
Note: Please add the multicast address (224.0.0.1) which targeget all nodes. If this address is not added, receive operation can’t work.
R18UZ0019EJ0300
Feb 28, 2015
Page 48 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.5.2.10 Call back event from Ethernet driver
【Prototype】 void eth_cbk(UH dev_num, UH opt, VP val)
【Operation】
Call back event from Ethernet driver
【Parameter】
UH
UH
VP
【Return value】 void
【Explanation】 dev_num opt val
Device number
Event type
Event description
This function is defined by network application. It is possible to control operation for asynchronous event or specific application operation by registering call back function to device configuration (T_NET_DEV gNET_DEV[]).
Event type and contents are showed below.
Event type
EV_CBK_DEV_INIT
EV_CBK_DEV_LINK
Event contents
Always 0
Link down:0, Link up:1
Factor
When Ethernet driver is initialized
When link status is changed
Caution Currently, link event cannot be detected.
R18UZ0019EJ0300
Feb 28, 2015
Page 49 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.5.2.11 Ethernet driver option setting - eth_ctl()
【Prototype】
ER eth_ctl(UH dev_num, UH opt, VP val)
【Operation】
Ethernet driver option setting
【Parameter】
UH
UH
VP
【Return value】
ER
【Explanation】 dev_num opt val
E_OK
E_PAR
Device number
Option type
Setting value
Success
Invalid parameter
This function calls Ethernet driver or PHY driver setting function. Available options are showed below.
Option type
ETH_OPT_PHY_MODE
ETH_OPT_MCRX_MODE
ETH_OPT_MCRX_ADR
ETH_OPT_RAW_RXFNC
ETH_OPT_RAW_SNDDONE
Description
PHY ability
Multicast address filter mode setting
Add multicast address filter
Ethernet frame receive report
Frame tranmit completaion report
Available value same as set_phy_mode() same as set_mcast_filter_mode() same as add_mcast_filter() same as eth_raw_rcv() same as eth_raw_snddone()
R18UZ0019EJ0300
Feb 28, 2015
Page 50 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.5.2.12 Get Ethernet driver option - eth_sts()
【Prototype】
ER eth_sts(UH dev_num, UH opt, VP val)
【Operation】
Get Ethernet driver option
【Parameter】
UH
UH
VP
【Return value】
ER
【Explanation】 dev_num opt val
E_OK
E_PAR
Device number
Option type
Option contents
Success
Invalid value
This function calls Ethernet driver and PHY driver functions. Available option is below.
Option type
ETH_OPT_PHY_MODE
Option contents
Get PHY ability
Available value same as get_phy_mode()
R18UZ0019EJ0300
Feb 28, 2015
Page 51 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.5.3 Configuration
Following configuration is written to DDR_ETH_CFG.h depends on purpose.
#define PHY_ADR0_EC
LAN1 PHY address for R-IN32M3-EC
#define PHY_ADR1_EC
LAN2 PHY address for R-IN32M3-EC
#define PHY_ADR0_CL
LAN1 PHY address for R-IN32M3-CL
#define PHY_ADR1_CL
LAN2 PHY address for R-IN32M3-CL
#define PROMISCUOUS_FILTER_MODE
Promiscuous filter mode. (0: receive all frames, 1: receive only self-station frame)
#define ETH_EARLY_TX_ENA
Early transmit mode. (0: disabled, 1: enabled)
If early transmit mode is enabled, it seems finish transmitting as soon as data was transmitted to FIFO in MAC controller.
#define ETH_TX_ASYNC
Non-blocking transmit mode. (0: disabled, 1: enabled)
If non-blocking mode is enabled, transmission is operated by send task of Ethernet drive.
#define USE_ETHSW
Ethernet switch is used or not. (0: not used, 1: used)
#define USE_ETHSW_MGTAG
Ethernet switch management tag is used or not. (0: not used, 1: used)
R18UZ0019EJ0300
Feb 28, 2015
Page 52 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.5.4 Cautions regarding Ethernet device driver
3.5.4.1 TCP/UDP hardware checksum function
Ethernet device driver uses hardware checksum function of R-IN32M3. Therefore, checksum calculation is not operated inside protocol stack.
T_NET_BUF structure member “flg” and global variable gNet[device number-1].flag can control whether checksum operation is used or not.
Following ensamples show how hardware checksum function is enabled.
Enables receive hardware checksum
T_NET_BUF *pkt;
pkt->flg |= (HW_CS_RX_IPH4 | HW_CS_RX_DATA);
Enables transmit hardware checksum
T_NET *net;
net = &gNET[eth_devnum-1];
/* set hardware checksum flag */
net->flag |= (HW_CS_TX_IPH4 | HW_CS_TX_DATA);
R18UZ0019EJ0300
Feb 28, 2015
Page 53 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.6 PHY driver
<R>
Ethernet driver and PHY driver I/F are defined to global variable PHY_IO gPHY_IO[]. gPHY_IO[] is arrays to define some PHYs.
PHY driver API registered to this variable is called from Ethernet driver. Last element of gPHY_IO[] arrays must be set 0 to all of PHY_IO member and terminated. PHY_IO member is described below. typedef struct phy_io {
UW phy_id;
UW phy_adr;
ER (*phy_ini)(ID flg, UW id, UW adr);
ER (*phy_ext)(void);
ER (*phy_set_mode)(UW mode, UB nego);
ER (*phy_get_mode)(UW *mode, UB *nego, UB *link);
}PHY_IO;
Member phy_id phy_adr phy_ini phy_ext phy_set_mode phy_get_mode
Description
PHY ID (ID number of LAN1~LAN4. If target is LAN1, this member is 1)
PHY address
Initialize function
Exit function
PHY ability setting function
PHY ability getting function
R18UZ0019EJ0300
Feb 28, 2015
Page 54 of 168
R-IN32M3 Series
3.6.1 PHY driver API
3. Overview functions of R-IN32M3 TCP/IP stack
3.6.1.1 Initialize PHY driver - phy_ini()
【Prototype】
ER phy_ini(ID flg, UW id, UW adr)
【Operation】
Initialize PHY driver
【Parameter】
ID
UW
UW
【Return value】
ER
【Explanation】 flg id adr
E_OK
Others
Event flag ID
PHY ID
PHY address
Success
Error when task start
This function is called from Ethernet driver when eth_ini() function is executed. Event flag ID gives Ethernet driver link event. PHY ID gives event pattern when link event is noticed.
R18UZ0019EJ0300
Feb 28, 2015
Page 55 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.6.1.2 Exit PHY driver - phy_ext()
【Prototype】
ER phy_ext(void)
【Operation】
Exit PHY driver
【Parameter】 void
【Return value】
ER
【Explanation】
E_OK
Others
Success
Error when task finish
This function is called from Ethernet driver when eth_cls() function is executed. This driver terminates link task.
R18UZ0019EJ0300
Feb 28, 2015
Page 56 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.6.1.3 PHY ability setting - phy_set_mode()
【Prototype】
ER phy_set_mode(UW mode, UB nego)
【Operation】
PHY ability setting
【Parameter】
UW
UB
【Return value】
ER
【Explanation】 mode nego
E_OK
Speed, duplex
Auto negotiation enabled(TRUE) / disabled(FALSE)
Finished
This function is called from Ethernet driver when set_phy_mode() function is executed. Speed and duplex has the
duplex. Default value is PHY_AUTO_ABILITY when PHY driver has been initialized.
Table. 3.2 PHY ability setting
Description
PHY_10T_HD
PHY_10T_FD
PHY_100TX_HD
PHY_100TX_FD
PHY_1000T_HD
PHY_1000T_FD
PHY_AUTO_ABILITY
Settings
10M/Half-duplex
10M/Full-duplex
100M/Half-duplex
100M/Full-duplex
1G/Half-duplex
1G /Full-duplex
Auto selected
R18UZ0019EJ0300
Feb 28, 2015
Page 57 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.6.1.4 Get PHY ability - phy_get_mode()
【Prototype】
ER phy_get_mode(UW *mode, UB *nego, UB *link)
【Operation】
Get PHY ability
【Parameter】
UW*
UB*
UB*
【Return value】
ER
【Explanation】 mode nego link
E_OK
Speed and duplex
Auto negotiation enabled / disabled
Link up / down
Finished
This function is called from Ethernet driver when get_phy_mode() function is executed. Speed and duplex has the
duplex.
R18UZ0019EJ0300
Feb 28, 2015
Page 58 of 168
R-IN32M3 Series 3. Overview functions of R-IN32M3 TCP/IP stack
3.6.2 Link event notification
Rx task in Ethernet driver waits for receiving frame or changing link event state. The event shows link state change is set (set_flg()) by link task in PHY driver or interrupt handler.
The event flag ID (1 st
argument) in set_flg(id, ptn) has specified event flag ID when PHY driver starts. The event bit pattern (2 nd
argument) has logical OR “PHY_LINK_EVT” and PHY ID. PHY_LINK_EVT means link event, PHY ID is specified when PHY driver starts.
R18UZ0019EJ0300
Feb 28, 2015
Page 59 of 168
R-IN32M3 Series
4. Network configuration
It’s explained to configure TCP/IP protocol stack in this chapter.
4. Network configuration
4.1 Configuration of TCP/IP stack for R-IN32M3
TCP/IP stack parameters such as IP address and transmission buffer size can be configured by editing net_cfg.c.
4.1.1 Configuration list
macros or variables directly. Almost initial values are defined by “DEF_XXX” macro.
The following is configurable parameter list.
The application can modify macro values defined as “#define CFG_XXX” (XXX is any), and cannot modify other
Configuration content [Unit]
The number of data link devices
The maximum number of all protocol sockets
The maximum number of TCP sockets
The number of ARP entries
The number of multicast entries
The number of IP reassembly queues
Network buffer size [Byte]
The number of network buffers
Network buffer data offset (not allowed to change)
MTU size
The number of ARP retry
Timeout value for ARP retry [ms]
Clear timeout of ARP cache [ms]
TTL value of IP header
TOS value of IP header
Waiting time IP fragment packet [ms]
TTL value of multicast IP header
Timeout value of IGMPv1 [ms]
Timeout value of IGMP report [ms]
MSS(TCP/IPv4) (MTU-IP header-TCP header)
MSS(TCP/IPv6) (MTU-IP header-TCP header)
TCP/RTO (retry timeout) initial value [ms]
TCP/RTO (retry timeout) minimum value [ms]
TCP/RTO (retry timeout) maximum value [ms]
TCP transmission buffer size [Byte]
TCP reception buffer size [Byte]
Duplicate ACK number of retry beginning [reception count]
TCP/SYN transmission timeout [ms]
Definition
1
10
5
8
8
2
Initial value
CFG_NET_DEV_MAX
CFG_NET_SOC_MAX
CFG_NET_TCP_MAX
CFG_NET_ARP_MAX
CFG_NET_MGR_MAX
CFG_NET_IPR_MAX
CFG_NET_BUF_SZ
CFG_NET_BUF_CNT
2048
16
CFG_NET_BUF_OFFSET 42
CFG_PATH_MTU
CFG_ARP_RET_CNT
CFG_ARP_RET_TMO
1500
3
1000
CFG_ARP_CLR_TMO
CFG_IP4_TTL
CFG_IP4_TOS
CFG_IP4_IPR_TMO
CFG_IP4_MCAST_TTL
CFG_IGMP_V1_TMO
768
2
42
576
0
1
1200000 1000
64 1
0
10000
1
40000
0
1
1
40000
0
1
1
1
1
1
Minimum value
CFG_IGMP_REP_TMO 10000
CFG_TCP_MSS 1460
CFG_TCP_MSS_IPV6
CFG_TCP_RTO_INI
CFG_TCP_RTO_MIN
CFG_TCP_RTO_MAX
1440
3000
500
60000
CFG_TCP_SND_WND
CFG_TCP_RCV_WND
CFG_TCP_DUP_CNT
1024
1024
4
10000
536
516
2000
200
30000
1024
1024
1
CFG_TCP_CON_TMO 75000 10000
30000
1460
1440
3000
500
60000
8192
8192
10
Maximum value
2
1000
1000
32
100
16
2048
100
42
1500
10
10000
3600000
255
255
60000
255
120000
75000
R18UZ0019EJ0300
Feb 28, 2015
Page 60 of 168
R-IN32M3 Series
TCP/data transmission timeout [ms]
TCP/FIN transmission timeout [ms]
TCP/2MSL timeout [ms]
TCP/delay ACK transmission period [ms]
TCP/Keep-Alive notification count (in case of 0
Keep-Alive is disabled)
TCP/Keep-Alive notification period [ms]
Non-communication time until TCP/Keep-Alive starts
[ms]
The queuing number of reception packet
Waiting time ARP PROBE packet transmission [ms]
The number of ARP PROBE packet transmission
ARP PROBE packet transmission period (minimum)
[ms]
CFG_TCP_SND_TMO
CFG_TCP_CLS_TMO
CFG_TCP_CLW_TMO
CFG_TCP_ACK_TMO
CFG_TCP_KPA_CNT
CFG_TCP_KPA_INT
CFG_TCP_KPA_TMO
CFG_PKT_RCV_QUE
CFG_ARP_PRB_WAI
CFG_ARP_PRB_NUM
CFG_ARP_PRB_MIN
ARP PROBE packet transmission period (maximum)
[ms]
Waiting time ARP ANNOUNCE packet [ms]
CFG_ARP_PRB_MAX
CFG_ARP_ANC_WAI
The number of ARP ANNOUNCE packet transmission CFG_ARP_ANC_NUM
CFG_ARP_ANC_INT
CFG_PKT_CTL_FLG
ARP ANNOUNCE packet transmission period [ms]
Packet control flag (bit pattern)
‐Transmit ICMP Port Unreachable (bit0)
‐Ignore reception IP header checksum (bit1)
‐Ignore reception TCP header checksum (bit2)
‐Ignore reception UDP header checksum (bit3)
64000
75000
20000
200
0
1
1000
3
1000
2000
2000
2
2000
0
4. Network configuration
10000
10000
0
100
0
1000 1000
7200000 10000
1
1000
1
100
200
200
1
200
-
64000
75000
20000
1000
100
60000
14400000
10
3000
6
1000
2000
2000
4
2000
-
R18UZ0019EJ0300
Feb 28, 2015
Page 61 of 168
R-IN32M3 Series 4. Network configuration
4.1.2 IP address
Set up IP address. Because every network device needs an IP address, please register CFG_NET_DEV_MAX part for
IP address.
The following is the example for set up of IP address:192.168.1.10, gateway:192.168.1.1, subnet mask:
255.255.255.0.
T_NET_ADR gNET_ADR[] = {
{ /* for Device 1 */
0x0, /* Must be 0 */
0x0, /* Must be 0 */
0xC0A8000A, /* Setting IP address 192.168.1.10 */
0xC0A80001, /* Gateway 192.168.1.1 */
0xFFFFFF00, /* Subnet mask 255.255.255.0 */
}
};
4.1.3 Device Driver
Set device driver. Please register CFG_NET_DEV_MAX part for device driver.
T_NET_DEV gNET_DEV[] = {
{ ..}
}
Please refer to 3.2 Network device driver for more details.
4.1.4 Information table of protocol stack
Set global variable of protocol stack as below. const VP net_inftbl[] = {
0, /* Necessarily specify 0*/
(VP)gNET_SOC, /* Set NULL in case of not using socket */
(VP)gNET_TCP, /* Set NULL in case of not using socket*/
(VP)gNET_IPR, /* Set NULL in case of not using IP reassembly function */
(VP)gNET_MGR, /* Set NULL in case of not using IGMP*/
(VP)gTCP_SND_BUF, /* Set NULLin case of not using TCP socket*/
};
R18UZ0019EJ0300
Feb 28, 2015
Page 62 of 168
R-IN32M3 Series 5. Description of application programming interface
5. Description of application programming interface
5.1 Initialization of protocol stack
To use TCP/IP protocol stack, the initialization of protocol stack and initialization of network device are needed.
Basically initialization is as follows:
Example of initialization code
/* Initialization of protocol stack */ ercd = net_ini(); if (ercd != E_OK) {
return ercd;
}
/* Network device initialization (device number N) */ ercd = net_dev_ini(N);
If (ercd != E_OK) { return ercd;
}
R18UZ0019EJ0300
Feb 28, 2015
Page 63 of 168
R-IN32M3 Series 5. Description of application programming interface
5.2 Network Interface API
net_ini Initialization of TCP/IP protocol stack
【Format】
ER ercd = net_ini(void);
【Parameter】
None
【Return value】
ER
【Error code】
<0 ercd
Initialization failure
Successful completion (E_OK) or error code
【Explanation】
Initialize the resource to be used by protocol stack. Kernel objects (tasks, memory pools, semaphores) to be used by protocol stack are also created and initialized simultaneously. Besides, the initial value is set in global variable used in protocol stack.
In case of using protocol stack, it needs to issue this API prior to any other API.
R18UZ0019EJ0300
Feb 28, 2015
Page 64 of 168
R-IN32M3 Series net_cfg
5. Description of application programming interface
Parameter setting of network interface
【Format】
ER ercd = net_cfg(UH num, UH opt, VP val);
【Parameter】
UH
UH
VP num opt val
Device number
Parameter code
Value to set
【Return value】
ER
【Error code】
E_NOSPT
E_ID
E_NOMEM ercd Successful completion (E_OK) or error code
Wrong parameter code
Wrong parameter code
Too many multicast table
【Explanation】
Set up forIP address and subnet mask, broadcast address, multicast and others.
Setting sample net_cfg(1, NET_BCAST_RCV, (VP)1); /* enable broadcast reception */
Parameter code
NET_IP4_CFG
NET_IP4_TTL
NET_BCAST_RCV
NET_MCAST_JOIN
NET_MCAST_DROP
NET_MCAST_TTL
NET_ACD_CBK
Data type
T_NET_ADR
UB
UB
UW
UW
UB
Callback function pointer
Meaning
Set IP address, subnet mask, gateway. Please hand pointer of T_NET_ADR to val.
Set TTL (Time to Live)
Default is set 64.
Set whether to receive broadcast or not. Set 1 to receive and 0 to not receive.
Register IP address of multicast group to join
Set IP address of multicast group to drop
Set TTL to be used in multicast transmission
In this field, set the callback function to notify that it has detected an IP address conflict during operation.
Notification feature is enabled by this setting of conflict detection.
R18UZ0019EJ0300
Feb 28, 2015
Page 65 of 168
R-IN32M3 Series net_ref
5. Description of application programming interface
Reference parameter for network interface
【Format】
ER ercd = net_ref(UH num, UH opt, VP val);
【Parameter】
UH
UH
VP num opt val
Device number
Parameter code
Pointer to buffer of the value to get
【Return value】
ER
【Error code】
E_NOSPT
E_ID ercd Successful completion (E_OK) or error code
Wrong parameter code
Wrong device number
【Explanation】
Verify the basic setting of IP address and subnet mask, broadcast address and others.
Setting sample
UB bcast; net_ref(1, NET_BCAST_RCV, (VP)&bcast); /* reception status of broadcast */
Parameter code
NET_IP4_CFG
NET_IP4_TTL
NET_BCAST_RCV
NET_MCAST_TTL
Data type
T_NET_ADR
UB
UB
UB
Meaning
Get IP address, subnet mask, gate-way. Please hand pointer of T_NET_ADR to val
Get TTL (Time to Live).
Get the receive status of broadcast
Get TTL broadcast transmission
R18UZ0019EJ0300
Feb 28, 2015
Page 66 of 168
R-IN32M3 Series net_acd
5. Description of application programming interface
Detection IP Address Confliction
【API】
ER ercd = net_acd(UH dev_num, T_NET_ACD *acd);
【Parameter】
UH
T_NET_ACD num
*acd
Deviec Number
Address Conflict Information
【Return Value】
ER
【Error Code】
E_ID
E_PAR
E_OBJ
E_TMOU
E_SYS
E_OK ercd Success (E_OK) or Error Code
Illegal Device Number
Illegal Parameter
Call Duplicate or Call host IP undefined
Time out ARP transmit
Detect IP address conflict
No Detect IP address conflict
【DESCRIPTION】
This API is done in the device specified by dev_num, IP address conflict detection.
If it detects a conflict for the IP address, MAC address of the other party is stored in the conflict information of the argument.
If you want to detect conflicts in asynchronous IP address separately, you will need to register a callback function ()
API net_cfg with this API.
Note : Function is recommended that a maximum of about 10 seconds, call a dedicated task to attempt the detection of address conflicts.
R18UZ0019EJ0300
Feb 28, 2015
Page 67 of 168
R-IN32M3 Series net_cbk
5. Description of application programming interface
Callback IP address conflict detected.
【API】
ER acd_cbk(T_NET_ACD* acd);
【Parameter】
T_NET_ACD
【Return Value】
*acd
ER ercd
Address Conflict Information
Success (E_OK) or Error Code
【DESCRIPTION】
This function is called when it detects an IP address conflict during operation. The conflict is stored what conflict information of the argument MAC address of the host that.
If the IP address for the conflict, continue to use the IP address in the host itself, please return the E_OK. Otherwise, please return the E_SYS.
R18UZ0019EJ0300
Feb 28, 2015
Page 68 of 168
R-IN32M3 Series 5. Description of application programming interface
Called on the task that received the ARP packet (task received Ethernet driver) callback function. The callback function should therefore be terminated immediately. There is no callback function that is called (running () net_acd) detection in
IP address.
Use Casee
/* Callback function at the time of detecting address conflicts */
ER acd_detect(T_NET_ACD * acd)
{
return E_OK;
}
/* Network Initialize Function */
ER net_setup(void)
{
ER ercd;
T_NET_ACD acd;
ercd = net_ini();
if (ercd != E_OK) {
return ercd;
}
ercd = net_dev_ini(ID_DEVNUM_ETHER);
if (ercd != E_OK) {
return ercd;
}
/* Detect IP Address Conflict */
ercd = net_acd(ID_DEVNUM_ETHER, &acd);
if (ercd == E_OK) {
/* No Information IP Address conflict */
/* Callback function at the time of detecting IP address conflicts */
net_cfg(ID_DEVNUM_ETHER, NET_ACD_CBK, (VP)acd_detect);
}
else if (ercd == E_SYS) {
/* MAC address is conflict a host of acd.mac IP address */
} else {
/* Failed to detect IP address conflict */
}
return ercd;
}
R18UZ0019EJ0300
Feb 28, 2015
Page 69 of 168
R-IN32M3 Series 5. Description of application programming interface
5.3 Network Device Control API
The Network Device Control API provides interface to access unifiedly from application to device driver. For each device, it specifies a device number to access this API. Device number is the specific number to identify the device. net_dev_ini Network device initialization
【Format】
ER ercd = net_dev_ini(UH dev_num);
【Parameter】
UH
【Return value】
ER
【Error code】
<0 dev_num ercd
Initialization failure
Device number
Successful completion (E_OK) or error code
【Explanation】
Use dev_num to initialize a specific device. In fact, net_dev_ini uses dev_ini of driver device to initialize the device.
If it completes normally, it can handle the packet through that network device.
R18UZ0019EJ0300
Feb 28, 2015
Page 70 of 168
R-IN32M3 Series net_dev_cls
5. Description of application programming interface
Release network device
【Format】
ER ercd = net_dev_cls(UH dev_num);
【Parameter】
UH
【Return value】 dev_num
ER ercd
【Error code】
<0 Failure
Device number
Successful completion (E_OK) or error code
【Explanation】
Release specific device by using dev_num. In fact, net_dev_cls will release device by using dev_cls of device driver. net_dev_ctl Network device control
【Format】
ER ercd = net_dev_ctl(UH dev_num, UH opt, VP val);
【Parameter】
UH
UH
VP
【Return value】
ER dev_num opt val ercd
Device number
Control code
Value to set
Successful completion (E_OK) or error code
【Error code】
<0 Failure
【Explanation】
Control the specific device by using dev_num. Because net_dev_ctl only calls dev_ctl of device driver, the actual actions depend much on integration of driver device.
R18UZ0019EJ0300
Feb 28, 2015
Page 71 of 168
R-IN32M3 Series net_dev_sts
5. Description of application programming interface
Acquire the status of network device
【Format】
ER ercd = net_dev_sts(UH dev_num, UH opt, VP val);
【Parameter】
UH
UH
VP dev_num opt val
Device number
Status code
Getting value
【Return value】
ER
【Error code】
<0 ercd
Failure
Successful completion (E_OK) or error code
【Explanation】
Acquire the status of specific device by using dev_num. Because net_dev_sts only calls dev_ref of device driver, the detailed action depends on integration of device driver.
R18UZ0019EJ0300
Feb 28, 2015
Page 72 of 168
R-IN32M3 Series 5. Description of application programming interface
5.4 Socket API (uNet3 compatible)
Application uses socket API to exchange TCP/UDP data with remote host.
When creating socket or connecting, it’s necessary to use device number to specify network device to connect. In case specify device number 0, it means that “Don’t specify device”, the interface selection action between socket and network device is different depending on transmission or reception. Besides, when creating socket, if it specify device number beside 0, it don’t need to specify device number when connecting.
For example, in the system is constructed by N network devices (N is more than 2) with the using socket APIs, show in the below it.
Socket transmission action con_soc() of snd_soc() and TCP client
(SYN transmission)
Socket reception action con_soc() of rcv_soc() and TCP server
(SYN reception)
0
0
N
Device number when Device number when
creating (※1) connecting (※2)
0
0
N
0
N
ANY
Device in use
Device number 1(top)
Device number N
Device number N
0
N
ANY
Notified device (※3)
Device number N
Device number N
※1 In case of R-IN32M3 TCP/IP stack, when adding socket by the configurator, we specify network device. In case of Standard,
it specify by host->num argument of con_soc() API.
※2 Specify by host->num argument of con_soc() API. In case of receiving through UDP socket, do not need to call
con_soc() API.
※3 The socket which does not specify device number even when creating or connecting socket, if port number and
protocol are matched, it can receive packet from any device. The socket in this case uses the device notified packet
in subsequent operation.
R18UZ0019EJ0300
Feb 28, 2015
Page 73 of 168
R-IN32M3 Series cre_soc
5. Description of application programming interface
Socket generation
【Format】
ER ercd = cre_soc(UB proto, T_NODE *host);
【Parameter】
UH
T_NODE proto
*host
Protocol type
Information of local host
【Return value】
ER
【Error code】
E_ID ercd ID of generated socket (>0) or error code
UH
E_PAR
E_NOSPT
Unable to generate socket (exceed maximum number of socket)
‘host’ is wrong
‘proto’ is wrong
【T_NODE】
Specify local port number and device interface to use. port Port number Port number of local host. Specify the value from 1 to 65535 or PORT_ANY.
In case that PORT_ANY is specified, it will determine port number by protocol
UH
UB
UW ver num ipa
【proto】
IP version
Device number
IP address stack.
Specify 0 (use IP_VER4)
Specify device number of the device it want to use
Specify 0 (use local IP address)
Protocol type of socket to create
IP_PROTO_TCP TCP socket
IP_PROTO_UDP UDP socket
【Explanation】
This API creates the socket of specified protocol.
Example of creating TCP socket
T_NODE host; host.num = 1; host.port = 7; host.ver = IP_VER4; host.ipa = INADDR_ANY; cre_soc(IP_PROTO_TCP, &host);
R18UZ0019EJ0300
Feb 28, 2015
Page 74 of 168
R-IN32M3 Series del_soc
5. Description of application programming interface
Delete socket
【Format】
ER ercd = del_soc(UH sid);
【Parameter】
UH
【Return value】 sid
ER ercd
【Error code】
E_ID
E_NOEXS
E_OBJ
Wrong ID number
ID is used to identify socket
Successful completion (E_OK) or error code
Socket does not exist (Socket has not been created yet)
Status of socket is wrong
【Explanation】
This API deletes the specified ID socket. When delete TCP socket, please call cls_soc() in advance and close the socket.
R18UZ0019EJ0300
Feb 28, 2015
Page 75 of 168
R-IN32M3 Series con_soc
5. Description of application programming interface
Socket connection
【Format】
ER ercd = con_soc(UH sid, T_NODE *host, UB con_flg) ;
【Parameter】
UH
T_NODE
UB sid
*host con_fig
ID is used to identify socket
Information of remote host
Connection mode
【Return value】
ER ercd Successful completion (E_OK) or error code
【Error code】
E_ID
E_NOEXS
E_PAR
E_OBJ
Wrong ID number
Socket does not exist (Socket has not been created yet)
Host or con_flg is wrong
Socket status is wrong (for example, calling this API for the socket which has already
E_TMOUT
E_WBLK
E_CLS
E_RLWAI connected)
Connection process is out of time
Processed by non-blocking mode
Refuse the connection from remote host
E_QOVR
【T_NODE】
Connection process is interrupted con_soc() is already executing
Specify remote host and device interface to use.
UH port Port number Port number of remote host
UH
UB ver num
UW ipa
【con_fig】
IP version
Device number
IP address
(from 1 to 65535)
Specify 0
Device number of the device that wants to use
IP address of remote host
Specify the waiting for connection (server) or the active connection (client).
Usually specify 0 for UDP socket.
SOC_CLI
SOC_SER
Connect to remote host (active connection)
Wait for connection (passive connection)
R18UZ0019EJ0300
Feb 28, 2015
Page 76 of 168
R-IN32M3 Series 5. Description of application programming interface
【Explanation】
This API has different behavior depending on using protocol.
In the course of TCP, establish the connection to remote host, in case of UDP, associate the socket with the destination of data transmission.
An example for the connection of TCP server socket
T_NODE remote = {0}; /* clear by 0 */ con_soc(ID, &remote, SOC_SER);
An example for the connection of TCP client socket
T_NODE remote; remote.port = 100; /* Port number of remote host */ remote.ver = IP_VER4; remote.num = 1; /*Specify device number to use */ remote.ipa = ip_aton(“192.168.11.1”); /*IP address of remote host */ con_soc(ID, &remote, SOC_CLI);
R18UZ0019EJ0300
Feb 28, 2015
Page 77 of 168
R-IN32M3 Series cls_soc
5. Description of application programming interface
Socket disconnetion
【Format】
ER ercd = cls_soc(UH sid, UB cls_flg);
【Parameter】
UH
UB
【Return value】
ER
【Error code】
E_ID
E_NOEXS
E_PAR
E_OBJ
E_TMOUT
E_WBLK
E_CLS
E_RLWAI
E_QOVR
【cls_flg】 sid cls_fig ercd
Wrong ID number
ID is used to identify socket
Disconnetion mode
Successful completion (E_OK) or error code
Socket does not exist (Socket has not been created yet)
‘cls_flg is wrong
Socket status is wrong (Such as when calling this API in the status of disconnection)
Disconnection process is out of time
Processed by non-blocking mode
Forced termination of the connection from remote host
Disconnection process is interrupted cls_soc() is executing already
This parameter is only valid for TCP socket
SOC_TCP_CLS Disconnect socket (End the connection)
SOC_TCP_SHT Disable transmission process only. Reception is possible. (In case that want to stop the connection completely after using SOC_TCP_SHT to discontinue the transmission process only, it need to use SOC_TCP_CLS to disconnect completely.)
【Explanation】
This API has different behavior depending on using protocol.
In case of TCP, stop the connection to remote host, in case of UDP, clear the information of the destination or the source of data associated with socket. (After that, it cannot send UDP data).
R18UZ0019EJ0300
Feb 28, 2015
Page 78 of 168
R-IN32M3 Series cfg_soc
5. Description of application programming interface
Set parameter of socket
【Format】
ER ercd = cfg_soc(UH sid, UB code, VP val) ;
【Parameter】
UH
UB
VP sid code val
ID is used to identify socket
Parameter code
Value to set
【Return value】
ER ercd Successful completion (E_OK) or error code
【Error code】
E_ID
E_NOEXS
E_NOSPT
E_PAR
E_OBJ
Wrong ID number
Socket does not exist (Socket has not been created yet)
Wrong parameter code
Wrong parameter value
Status of socket is wrong
【Explanation】
This API can set parameter as below. Please cast and then hand the setting value to VP type.
Example of setting
UB ttl = 32; cfg_soc(ID, SOC_IP_TTL, (VP)ttl);
R18UZ0019EJ0300
Feb 28, 2015
Page 79 of 168
R-IN32M3 Series
Parameter code
SOC_TMO_CON
SOC_TMO_CLS
SOC_TMO_SND
SOC_TMO_RCV
SOC_IP_TTL
SOC_IP_TOS
SOC_CBK_HND
SOC_CBK_FLG
Data type
TMO
TMO
TMO
TMO
UB
UB
Pointer for function
UH
5. Description of application programming interface
Meaning
Calling timeout of con_soc
Calling timeout of cls_soc
Calling timeout of snd_soc
Calling timeout of rcv_soc
Set TTL of IP header (Time to Live)
Set TOS of IP header (Type of Server)
Register callback function
Set bit pattern of callback event flag (Value to set is as below)
Change Local Port Number SOC_PRT_LOCAL UH
Callback event flag bit
EV_SOC_CON
EV_SOC_CLS
Meaning
Set con_soc() in non-blocking mode
(only TCP socket)
Set cls_soc() in non-blocking mode
(only TCP socket)
Set snd_soc() in non-blocking mode
Set rcv_soc() in non-blocking mode
EV_SOC_SND
EV_SOC_RCV
Regarding callback event flag bit, it can set a multiple bit. In case of setting it multiple, set by OR. An example of setting is as below.
Ex: ercd = cfg_soc(ID socket, SOC_CBK_FLG, (VP)(EV_SOC_CON|EV_SOC_SND|EV_SOC_RCV|EV_SOC_CLS));
Socket event set in non-blocking disables socket timeout of that event.
When enable callback event flag bit, it is necessary to register callback function in SOC_CBK_HND. Regarding callback function, please refer to the following.
R18UZ0019EJ0300
Feb 28, 2015
Page 80 of 168
R-IN32M3 Series soc_cbt
5. Description of application programming interface
Callback function
【Format】
UW soc_cbt(UH sid, UH event, ER ercd);
【Parameter】
UH
UH
ER sid event ercd
ID is used to identify socket
Callback event flag bit
Error code
This callback function is called out from TCP/IP stack. However, in case of execution API socket of non-blocking mode, if API process is necessary to enter the waiting sate, it will return E_WBLK value without enter. This time, it will be notified from TCP/IP stack that the process of callback function has completed.
Call back event flag bit
(event)
EV_SOC_CON
Error code
(ercd)
E_OK
Meaning con_soc() process completes normally
< 0
EV_SOC_CLS E_OK
< 0 con_soc() process completes with error. Regarding error content of this time, please refer to error code of con_soc(). cls_soc() process completes normally
EV_SOC_SND > 0 cls_soc() process complete with error. Regarding error content of this time, please refer to error code of cls_soc().
UDP socket: snd_soc()process completes normally
TCP socket:
In case of TCP transmission buffer is available, it will show the available size by ‘ercd’ value. Again, snd_soc() is called and then it can copy transmission data into TCP transmission buffer.
<= 0
EV_SOC_RCV > 0
<= 0 snd_soc() process completes normally. Regarding error content of this time, please refer to error code of snd_soc().
UDP socket:
There is receipt data in UDP socket. Shows receipt data size by ‘ercd’ value. Again, it can call rcv_soc() to receive data.
TCP socket:
There exists receipt data in TCP socket. Shows receipt data size by
‘ercd’ value. Again, it can call rcv_soc() to receive data. rcv_soc() process completes normally. Regarding error content of this time, please refer to error code of rcv_soc().
※Prohibit to call all API functions of R-IN32M3 TCP/IP stack from callback function. (Please think callback unction the same as interrupting handler and use it).
R18UZ0019EJ0300
Feb 28, 2015
Page 81 of 168
R-IN32M3 Series ref_soc
5. Description of application programming interface
Refer parameter of socket
【Format】
ER ercd = ref_soc(UH sid, UB code, VP val) ;
【Parameter】
UH
UB
VP sid code val
ID is used to identify socket
Parameter code
Pointer for buffer of the value to get
【Return value】
ER ercd Successful completion (E_OK) or error code
【Error code】
E_ID
E_NOEXS
E_NOSPT
E_PAR
E_OBJ
Wrong ID number
Socket does not exist (socket has not been created yet)
Wrong parameter code
Wrong parameter value (in case that val is NULL)
Socket status is wrong (Cannot refer to socket)
R18UZ0019EJ0300
Feb 28, 2015
Page 82 of 168
R-IN32M3 Series 5. Description of application programming interface
【Explanation】
Refer the parameters as below. Please cast and then hand the setting value to VP type.
Example of getting remote host information
T_NODE remote; ref_soc(ID, SOC_IP_REMOTE, (VP)&remote);
Parameter code
SOC_TMO_CON
SOC_TMO_CLS
SOC_TMO_SND
SOC_TMO_RCV
SOC_IP_LOCAL
SOC_IP_REMOTE
SOC_IP_TTL
SOC_IP_TOS
SOC_RCV_PKT_INF
SOC_PRT_LOCAL
Data type
TMO
TMO
TMO
TMO
T_NODE
T_NODE
UB
UB
T_RCV_PKT_INF
UH
Meaning
Calling timeout of con_soc
Calling timeout of cls_soc
Calling timeout of snd_soc
Calling timeout of rcv_soc
Getting Port number and IP address of local host
Getting port number and IP address of remote host
Getting TTL (Time to Live)
Getting TOS (Type Of Service)
Getting newest information of packet received by socket
(in case of TCP, it’s unable to get)
Reference Local Port Number
For the socket having both multicast address and unicast address, to know IP address of the last received packet, please refer to the below.
Example of getting received IP address
T_RCV_PKT_INF rcv_pkt_inf; ref_soc(ID, SOC_RCV_PKT_INF, (VP)&rcv_pkt_inf); if(rcv_pkt_inf.dst_ipa == MULTICASTADDRESS) {
/* received by multicast address */
}
R18UZ0019EJ0300
Feb 28, 2015
Page 83 of 168
R-IN32M3 Series abt_soc
5. Description of application programming interface
Abort the socket process
【Format】
ER ercd = abt_soc(UH sid, UB code);
【Parameter】
UH
UB sid code
【Return value】
ER
【Error code】
E_ID
E_NOEXS
E_NOSPT
E_OBJ ercd
Wrong ID number
ID is used to identify socket
Control code
Successful completion (E_OK) or error code
Socket does not exist (socket has not been created yet)
Wrong control code
Socket status is wrong
【Explanation】
This API can cancel waiting status of con_soc, cls_soc, snd_soc, rcv_soc. Cancelled API returns E_RLWAI .
Meaning Control code
SOC_ABT_CON
SOC_ABT_CLS
SOC_ABT_SND
SOC_ABT_RCV
SOC_ABT_ALL
Discontinuation of con_soc() process
Discontinuation of cls_soc() process
Discontinuation of snd_soc() process
Discontinuation of rcv_soc() process
Process discontinuation of all sockets
R18UZ0019EJ0300
Feb 28, 2015
Page 84 of 168
R-IN32M3 Series snd_soc
5. Description of application programming interface
Data transmission
【Format】
ER ercd = snd_soc(UH sid, VP data, UH len);
【Parameter】
UH
VP
UH sid data len
ID is used to identify socket
Pointer to the transmit data
Size of the transmit data
【Return value】
ER ercd Actual transmitted data size (>0) or error code
【Error code】
E_ID
E_NOEXS
E_PAR
E_OBJ
E_TMOUT
E_WBLK
E_CLS
E_RLWAI
E_NOMEM
E_QOVR
Wrong ID number
Socket does not exist (socket has not been created yet)
Wrong transmitted data or data size for transmission is not specified.
Socket status is wrong
Transmission process is out of time
Processed by non-blocking mode
Forced termination of the connection from remote host
Transmission process is interrupted
Memory is not enough snd_soc() is executing already
【Explanation】
This API transmits data to remote host. When the process succeeds, it will return the actual transmitted data size.
Besides that case, it will return error code.
In case of TCP socket, this API will copy data into protocol stack inside, and return that copied size. (Returned data size is less than len specified by argument) . Please refer to“3.1.4 TCP module” for details.
In case of UDP socket, data will be transmitted to network and return that transmitted size. Please refer to “3.1.3 UDP module” for details.
R18UZ0019EJ0300
Feb 28, 2015
Page 85 of 168
R-IN32M3 Series rcv_soc
5. Description of application programming interface
Data reception
【Format】
ER ercd = rcv_soc(UH sid, VP data, UH len);
【Parameter】
UH
VP
UH sid data len
ID is used to identify socket
Pointer to receipt data
Receipt data size
【Return value】
ER ercd Actual received data size (>0) or error code
【Error code】
E_ID
E_NOEXS
E_PAR
E_OBJ
E_TMOUT
E_WBLK
E_CLS
E_RLWAI
E_QOVR
0
Wrong ID number
Socket does not exist (socket has not been created yet)
Wrong receipt data or receipt data size is not specified.
Socket status is wrong
Receipt process timed out
Processed by non-blocking mode
Forced termination of the connection from remote host
Reception process is interrupted rcv_soc() is executing already
The connection is disconnected
【Explanation】
This API receive data which is sent from remote host.
In case of TCP, the maximum receivable size to receive is “Reception buffer size” specified by the configurator. Please refer to “3.1.4 TCP module” for details.
In case of UDP, the maximum receivable size to receive is 1472 bytes (MTU default – IP header size – UDP header size). Please refer to “3.1.3 UDP module” for details.
R18UZ0019EJ0300
Feb 28, 2015
Page 86 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5 Socket API (BSD compatible)
<R>
TCP/IP stack for R-IN32M3 has the socket API for the BSD interface too. Thus, it is possible to easily divert the existing network applications using BSD sockets API.
5.5.1 Module overview
5.5.1.1 Position of the POSIX specification
TCP/IP stack for R-IN32M3 is supported the socket API which is equivalent to the 4.4BSD-Lite. For supported API
list, please refer the section 5.5.3 API list.
5.5.1.2 The difference to uNet3 socket API
In addition to the POSIX-compliant sockets API, also provides the features that did not combine i n μNet3 socket.
• Multiple call of socket API
• select() function
• Loop back address
• Multicast group with socket unit
• Listen queue of TCP socket
• Socket error
5.5.1.3 Compatibility of symbol name
The APIs, structures, and macros are added the unique prefix "unet3_" in order to avoid a symbol collision by the compiler environment.
By including sys/socket.h, the symbol name of the POSIX standard, which is used in application, be replaced with to these symbols with unique prefix. So application source codes based on BSD socket can be run as is.
The notation in this document has been using the POSIX standard symbol, because of considering the readability.
R18UZ0019EJ0300
Feb 28, 2015
Page 87 of 168
R-IN32M3 Series
5.5.2 Module structures
BSD Socket Application
5. Description of application programming interface
Markers
Task
Function
Data
BSD Wrapper Task
BSD Socket API
BSD Socket management data
Callback function uNet3 extended
API uNet3 API uNet3 Socket management data
Fig. 5.1 Module structure for BSD socket
TCP/IP Timer task
R18UZ0019EJ0300
Feb 28, 2015
Page 88 of 168
R-IN32M3 Series
5.5.3 API list
Table 5.1 API list
API unet3_bsd_init get_errno socket bind listen accept connect send sendto recv recvfrom shutdown close select getsockname getpeername getsockopt setsockopt ioctl inet_addr inet_aton inet_ntoa if_nametoindex if_indextoname rresvport getifaddrs freeifaddrs
5. Description of application programming interface
Function
Initialize the TCP/IP and BSD stack for R-IN32M3
Get the errno of each task
Create an end point for communication
Put a name for socket
Wait the connection on the socket
Accept connection to the socket
Connect to the socket
Send message to the socket
Send message to the socket
Receive message from the socket
Receive message from the socket
Close the part of the full-duplex connection
Close the descriptor (socket)
Multiplexing of synchronous I / O
Get the name of the socket
Get the name of the peer socket
Get the socket options
Set the socket options
Control the device (socket)
Internet address manipulation routines
Internet address manipulation routines
Internet address manipulation routines
Mapping name and index of the network interface
Mapping name and index of the network interface
Get the socket which is bound to port
Get the address of the interface
Release the interface information
Include header
“sys/socket.h”
“sys/errno.h”
“sys/socket.h”
“sys/socket.h”
“sys/socket.h”
“sys/socket.h”
“sys/socket.h”
“sys/socket.h”
“sys/socket.h”
“sys/socket.h”
“sys/socket.h”
“sys/socket.h”
“sys/ unistd.h”
“sys/ select.h”
“sys/socket.h”
“sys/socket.h”
“sys/socket.h”
“sys/socket.h”
“sys/ioctl.h”
“arpa/inet.h”
“arpa/inet.h”
“arpa/inet.h”
“net/if.h”
“net/if.h”
“sys/unistd.h”
“sys/types.h”
“sys/types.h”
R18UZ0019EJ0300
Feb 28, 2015
Page 89 of 168
R-IN32M3 Series
5.5.4 Detail for each API
5. Description of application programming interface
5.5.4.1 unet3_bsd_init
Please refer the section 5.5.7.6 Initialization
5.5.4.2 get_errno
Please refer the section 5.5.6.3 Error handling
5.5.4.3 socket (Create an end point for communication)
【Format】
#include “sys/socket.h” int socket(int domain, int type, int protocol);
【Parameter】 int int int domain type protocol
Domain
Communication type
Protocol
【Return value】 int
【errno】
ENOMEM
EINVAL
Generated socket FD. On error, -1.
Over the generation possible number of sockets
Message buffer is depleted
Parameter is incorrect
【Explanation】
• The domain can be specified only AF_INET or AF_INET6.
• The communication type can be specified only SOCK_STREAM or SOCK_DGRAM.
• Protocol parameter is not used, so any value is possible.
• The number of sockets (sum of for TCP and UDP) that can be generated at the same time is the value defined by
“#define CFG_NET_SOC_MAX”.
• The number of TCP sockets that can be generated at the same time is the value defined by “#define CFG_NET_
TCP _MAX”.
• The local port of socket cannot be set to 0, unlike the POSIX specification. Therefore the socket immediately after generation is assigned the temporary local port number.
R18UZ0019EJ0300
Feb 28, 2015
Page 90 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.4 bind (Put a name for the socket)
【Format】
#include “sys/socket.h” int bind(int sockfd, const struct sockaddr *addr, unsigned int addrlen);
【Parameter】 int sockfd const struct sockaddr * addr unsigned int addrlen
Socket FD
Local address
Local address length
【Return value】 int
【errno】
EINVAL
ENOMEM
EBADF
EAFNOSUPPORT
EADDRINUSE
EADDRNOTAVAIL
Result of process. If success, 0 or on error, -1.
Parameter is incorrect
Message buffer is depleted
Socked FD cannot be bound
Unsupported address family
Address is already in use
Address is not available
【Explanation】
• Local address should be set as struct sockaddr_in type.
• IP address (IPv4) for the local address can be specified only the address which is set to device or INADDR_ANY
(unspecified).
• If user sets the PORT_ANY (0) to the port number of the local address, a port number is assigned in the protocol stack.
• The local address length can be specified only sizeof(struct sockaddr_in) (=16).
• The member “sin_len” with struct sockaddr_in type is not used, so any value is possible.
• To start the receive operation, user needs to run the bind() function in advance with specifying the socket of the target. In here, the receive operation means a standby connection of TCP (listen()) and the reception of UDP packet
(recv (), recvfrom ()).
• User can bind() to wellknown port (1-1023) also.
R18UZ0019EJ0300
Feb 28, 2015
Page 91 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.5 listen (Wait the connection on the socket)
【Format】
#include “sys/socket.h” int listen(int sockfd, int backlog);
【Parameter】 int int
【Return value】 sockfd backlog int
Socket FD
Back log
Result of process. If success, 0 or on error, -1.
【errno】
EINVAL
ENOMEM
EBADF
EPROTONOSUPPOR
T
Parameter is incorrect
Message buffer is depleted
Socked FD cannot be listened
Unsupported protocol (not TCP)
【Explanation】
• TCP socket becomes to the state for waiting connection.
• The socket FD can be specified only the socket FD of TCP.
• The maximum number for back log is #define CFG_NET_TCP_MAX - 1.
R18UZ0019EJ0300
Feb 28, 2015
Page 92 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.6 accept (Accept connection to the socket)
【Format】
#include “sys/socket.h” int accept(int sockfd, struct sockaddr *addr, unsigned int *addrlen);
【Parameter】 int struct sockaddr * unsigned int * sockfd addr addrlen
Socket FD
Remote address (output)
Remote address length (output)
【Return value】 int
【errno】
EINVAL
ENOMEM
EBADF
EAGAIN
ETIMEDOUT
The connected socket FD. On error, -1.
Parameter is incorrect
Message buffer is depleted
Socked FD cannot be bound
The socket is not connected. (During asynchronous execution)
Timeout (if the timeout is set)
【Explanation】
• The socket FD can be specified only the socket FD of TCP that listen() function had been successful.
• The remote address is set as struct sockaddr_in* type.
• If there are not any the connected socket, the accept() function blocks the processes until it is connected from remote.
R18UZ0019EJ0300
Feb 28, 2015
Page 93 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.7 connect (Connect to the socket)
【Format】
#include “sys/socket.h” int connect(int sockfd, const struct sockaddr *addr, unsigned int addrlen);
【Parameter】 int sockfd const struct sockaddr * addr unsigned int addrlen
Socket FD
Remote address
Remote address length
【Return value】 int
【errno】
EINVAL
ENOMEM
EBADF
ECONNREFUSED
EAFNOSUPPORT
EISCONN
EALREADY
EAGAIN
ETIMEDOUT
Result of process. If success, 0 or on error, -1.
Parameter is incorrect
Message buffer is depleted
Socked FD cannot be connected
The connection was refused
Unsupported address family
Already connected.
Socket is under listen.
Already connected.
The socket is under connection. (During asynchronous execution)
Timeout (if the timeout is set)
【Explanation】
• The behavior or operation for connect() is different by the socket FD protocol or send/receive operation.
• In the case of the connection of TCP socket, SYN is sent to the remote address and try to do communication..
• In the case of the sending of UDP socket, the remote address is set as the destination address. However if the different destination address with sendto() is specified, the destination address for sendto() is used.
• If you a remote address family (sa_family) are specified to AF_UNSPEC, these settings will be cleared.
• Unlike the POSIX specification, there is no filtering function by remote address for the receiving operation of the
UDP socket.
• Unlike the POSIX specification, in the connect() for TCP socket with the asynchronous setting, user cannot issue the connect() again after the connection is completed. For example after confirmed EAGAIN for connect() and be guaranteed the writable status by select(), sending/receiving data becomes possible, because TCP session has been established at that point in time.
R18UZ0019EJ0300
Feb 28, 2015
Page 94 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.8 send (Send message to the socket)
【Format】
#include “sys/socket.h” int send(int sockfd, const void *buf, unsigned int len, int flags);
【Parameter】 int const void * unsigned int int sockfd buf len flags
Socket FD
Address for sending data
Length for sending data
Flag
【Return value】 int
【errno】
EINVAL
ENOMEM
EBADF
EDESTADDRREQ
ENOTCONN
EAGAIN
ETIMEDOUT
Byte number which is sent. On error, -1.
Parameter is incorrect
Message buffer is depleted
Cannot get the network buffer corresponding to “len”
Socked FD cannot be sent
Unsetting the address (UDP socket)
Not be connected (TCP socket)
The socket is under sending. (During asynchronous execution)
Timeout (if the timeout is set)
【Explanation】
• The length for sending data can be specified the value from 1 to 65535.
• The flag is not used, so any value is possible.
• The sending 0 byte UDP data cannot be sent, unlike the POSIX specification.
R18UZ0019EJ0300
Feb 28, 2015
Page 95 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.9 sendto (Send message to the socket)
【Format】
#include “sys/socket.h” int sendto(int sockfd, const void *buf, unsigned int len, int flags, const struct sockaddr *dest_addr, unsigned int addrlen);
【Parameter】 int const void * unsigned int int unsigned int sockfd buf len flags const struct sockaddr * dest_addr addrlen
Socket FD
Address for sending data
Length for sending data
Flag
The destination address
Length of the destination address
【Return value】 int
【errno】
EINVAL
ENOMEM
EBADF
EDESTADDRREQ
ENOTCONN
EAGAIN
ETIMEDOUT
Byte number which is sent. On error, -1.
Parameter is incorrect
Message buffer is depleted
Cannot get the network buffer corresponding to “len”
Socked FD cannot be sent to
Unsetting the address (UDP socket)
Not be connected (TCP socket)
The socket is under sending. (During asynchronous execution)
Timeout (if the timeout is set)
【Explanation】
• The length for sending data can be specified the value from 1 to 65535.
• The flag is not used, so any value is possible.
• In the case of TCP socket, the destination address and length of it is not used
• The sending 0 byte UDP data cannot be sent, unlike the POSIX specification.
R18UZ0019EJ0300
Feb 28, 2015
Page 96 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.10 recv (Receive message from the socket)
【Format】
#include “sys/socket.h” int recv(int sockfd, void *buf, unsigned int len, int flags);
【Parameter】 int void * unsigned int int sockfd buf len flags
Socket FD
Address for receiving buffer
Length for receiving buffer
Flag
【Return value】 int
【errno】
EINVAL
ENOMEM
EBADF
ENOTCONN
EAGAIN
ETIMEDOUT
Byte number which is received (included 0). On error, -1.
Parameter is incorrect
Message buffer is depleted
Cannot get the network buffer corresponding to “len”
Socked FD cannot be received
Not be connected (TCP socket)
The packet had not received yet. (During asynchronous execution)
Timeout (if the timeout is set)
【Explanation】
• The length for received buffer can be specified the value from 1 to 65535.
• The flag is not used, so any value is possible.
• If there are not any received packets, the recv() function blocks the processes until reception of packet.
• If not yet connected to the remote as TCP socket, recv () will result in an error.
• If in disconnected condition from remote with TCP socket, recv() returns 0.
R18UZ0019EJ0300
Feb 28, 2015
Page 97 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.11 recvfrom (Receive message from the socket)
【Format】
#include “sys/socket.h” int recvfrom(int sockfd, void *buf, unsigned int len, int flags, struct sockaddr *src_addr, unsigned int *addrlen);
【Parameter】 int void * unsigned int int struct sockaddr * unsigned int * sockfd buf len flags src_addr addrlen
Socket FD
Address for receiving buffer
Length for receiving buffer
Flag
Source address
Length of source address
【Return value】 int
【errno】
EINVAL
ENOMEM
EBADF
ENOTCONN
EAGAIN
ETIMEDOUT
Byte number which is received (included 0). On error, -1.
Parameter is incorrect
Message buffer is depleted
Cannot get the network buffer corresponding to “len”
Socked FD cannot be received
Not be connected (TCP socket)
The packet had not received yet. (During asynchronous execution)
Timeout (if the timeout is set)
【Explanation】
• The length for received buffer can be specified the value from 1 to 65535.
• The flag is not used, so any value is possible.
• If there are not any received packets, the recvfrom() function blocks the processes until reception of packet.
• If not yet connected to the remote as TCP socket, recvfrom () will result in an error.
• If in disconnected condition from remote with TCP socket, recvfrom () returns 0.
• For the TCP socket, Source address and Length of source address is not used.
R18UZ0019EJ0300
Feb 28, 2015
Page 98 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.12 shutdown (Close the part of the full-duplex connection)
【Format】
#include “sys/socket.h” int shutdown(int sockfd, int how);
【Parameter】 int int
【Return value】 sockfd how int
Socket FD
Direction for disconnection
Result of process. If success, 0 or on error, -1.
【errno】
EINVAL
ENOMEM
EBADF
EPIPE
Parameter is incorrect
Message buffer is depleted
Socked FD cannot be shutdowned
Not be connected (TCP socket)
【Explanation】
• The Direction for disconnection can be specified only SHUT_WR or SHUT_RDWR.
R18UZ0019EJ0300
Feb 28, 2015
Page 99 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.13 close (Close the descriptor (socket))
【Format】
#include “sys/unistd.h” int close(int fd);
【Parameter】 int sockfd
【Return value】 int
【errno】
EINVAL
ENOMEM
EBADF
Socket FD
Result of process. If success, 0 or on error, -1.
Parameter is incorrect
Message buffer is depleted
Socked FD cannot be closed.
【Explanation】
• If TCP socket had not disconnected yet, socket will close after disconnect TCP session.
• The closed socket FD cannot use until generate again.
R18UZ0019EJ0300
Feb 28, 2015
Page 100 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.14 select (Multiplexing of synchronous I/O)
【Format】
#include “sys/select.h” int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
【Parameter】 int nfds The value that maximum value in the socket FD included in the readfds and writefds, plus 1 fd_set * fd_set * fd_set * struct timeval * readfds writefds exceptfds timeout
Socket FD set to monitor whether readable
Socket FD set to monitor whether writable
Socket FD set to monitor the exception (not supported)
Monitor timeout
【Return value】 int
【errno】
EINVAL
ENOMEM
EBADF
The number of the socket FD which is writable or readable. On timeout, 0. On error, -1.
Parameter is incorrect
Message buffer is depleted
Socked FD cannot be selected.
【Explanation】
• The “exceptfds” is not used.
• Unlike the POSIX specification, in the execution of select() for the socket FD immediately after generation, it is writable for UDP socket (unreadable if not received the packet), or readable for TCP socket (unwritable).
R18UZ0019EJ0300
Feb 28, 2015
Page 101 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.15 getsockname (Get the name of the socket)
【Format】
#include “sys/socket.h” int getsockname(int sockfd, struct sockaddr *addr, unsigned int *addrlen);
【Parameter】 int struct sockaddr * unsigned int * sockfd addr addrlen
Socket FD
Buffer to store the socket address
Size of buffer to store the socket address
【Return value】 int
【errno】
EINVAL
ENOMEM
EBADF
Result of process. If success, 0 or on error, -1.
Parameter is incorrect
Message buffer is depleted
Socked FD cannot be done getsokname.
【Explanation】
• For the *addrlen, user needs to set the size of the “sockaddr_in” (16 bytes or more).
• The socket address determined by the time that issued the following API. bind()
connect()
accept()
send/sendto()
recv/recvfrom()
The socket address becomes the undefined value if these API failed.
R18UZ0019EJ0300
Feb 28, 2015
Page 102 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.16 getpeername (Get the name of the peer socket)
【Format】
#include “sys/socket.h” int getpeername(int sockfd, struct sockaddr *addr, unsigned int *addrlen);
【Parameter】 int struct sockaddr * unsigned int * sockfd addr addrlen
Socket FD
Buffer to store the remote address
Size of buffer to store the remote address
【Return value】 int
【errno】
EINVAL
ENOMEM
EBADF
ENOTCONN
Result of process. If success, 0 or on error, -1.
Parameter is incorrect
Message buffer is depleted
Socked FD cannot be done getpeername.
The address is not set.
【Explanation】
• For the *addrlen, user needs to set the size of the “sockaddr_in” (16 bytes or more).
• In the case of TCP, user can get the remote address only for connected socket.
• In the case of UDP, user can get the remote address only for the socket which had set the address by “connect” or
“sendto”, or the socket had already got a packet.
R18UZ0019EJ0300
Feb 28, 2015
Page 103 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.17 getsockopt (Get the socket options)
【Format】
#include “sys/socket.h” int getsockopt(int sockfd, int level, int optname, void *optval, unsigned int *optlen);
【Parameter】 int int int void * unsigned int * sockfd level optname optval optlen
Socket FD
Option level
Option name
Buffer to store the value got
Size of buffer to store the value got
【Return value】 int Result of process. If success, 0 or on error, -1.
【errno】
EINVAL
ENOMEM
EBADF
EPROTONOSUPPOR
T
Parameter is incorrect
Message buffer is depleted
Socked FD cannot be done getsockopt.
Unsupported option
【Explanation】
• The option level can be specified only SOL_SOCKET, IPPROTO_IP or IPPROTO_TCP.
The option name that user can get for each option level, please refer to 5.5.5Socket option.
R18UZ0019EJ0300
Feb 28, 2015
Page 104 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.18 setsockopt (Set the socket options)
【Format】
#include “sys/socket.h” int setsockopt(int sockfd, int level, int optname, const void *optval, unsigned int optlen);
【Parameter】 int int int const void * unsigned int sockfd level optname optval optlen
Socket FD
Option level
Option name
Buffer for the value to set
Size of buffer for the value to set
【Return value】 int Result of process. If success, 0 or on error, -1.
【errno】
EINVAL
ENOMEM
EBADF
EPROTONOSUPPOR
T
Parameter is incorrect
Message buffer is depleted
Socked FD cannot be done setsockopt.
Unsupported option
【Explanation】
• The option level can be specified only SOL_SOCKET, IPPROTO_IP or IPPROTO_TCP.
• The option name that user can get for each option level, please refer to 5.5.5Socket option
R18UZ0019EJ0300
Feb 28, 2015
Page 105 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.19 ioctl (Control the device (socket))
【Format】
#include “sys/ioctl.h” int ioctl(int d, int request, ...);
【Parameter】 int int
... d request
【Return value】 int
【errno】
EINVAL
ENOMEM
EFAULT
Socket FD
Request
Request parameter
Result of process. If success, 0 or on error, -1.
Parameter is incorrect
Message buffer is depleted
Cannot expand the request parameters
【Explanation】
• The Request can be specified only FIONBIO (non-blocking connection setting).
• The request parameter for non-blocking communication setting is 1 (seting) or 0 (release).
• Regarding the non-blocking communication seeting, please refer to 5.5.6.1Non-blocking setting
R18UZ0019EJ0300
Feb 28, 2015
Page 106 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.20 inet_addr (Internet address manipulation routines)
【Format】
#include “arpa/inet.h” unsigned int inet_addr(const char *cp);
【Parameter】 const char * cp
【Return value】 int
【errno】
Not set
The dot notation IP address
IP address binary value after conversion (network byte order)
【Explanation】
• If the fail to convert happen, the return value is set to 0.
R18UZ0019EJ0300
Feb 28, 2015
Page 107 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.21 inet_aton (Internet address manipulation routines)
【Format】
#include “arpa/inet.h” int inet_aton(const char *cp, struct in_addr *inp);
【Parameter】 const char * struct in_addr * cp inp
The dot notation IP address
Buffer to store IP address binary value after conversion (network byte order)
【Return value】 int
【errno】
Not set
Result of process. If success, 0 or on error, -1.
【Explanation】
• If the fail to convert happen, the return value is set to -1.
R18UZ0019EJ0300
Feb 28, 2015
Page 108 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.22 inet_ntoa (Internet address manipulation routines)
【Format】
#include “arpa/inet.h” char *inet_ntoa(struct in_addr in);
【Parameter】 struct in_addr in
【Return value】
Int
【errno】
Not set
IP address binary value (network byte order)
The dot notation IP address after conversion
【Explanation】
• If the fail to convert happen, the return value is set to 0.
• If user call this function again after execution, the string will be overwritten, because the area stored the converted dot notation IP address is returned the string data stored the buffer which is assigned statically.
R18UZ0019EJ0300
Feb 28, 2015
Page 109 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.23 if_nametoindex (Mapping name and index of the network interface)
【Format】
#include “net/if.h” unsigned int if_nametoindex(const char *ifname)
【Parameter】 const char * ifname Interface name
【Return value】 unsigned int
【errno】
ENXIO
Interface index. On error, 0.
Nonexistent interface name
【Explanation】
• The interface name is set by the device name (gNET_DEV[index-1].name [8]) to be used in the TCP/IP protocol stack.
R18UZ0019EJ0300
Feb 28, 2015
Page 110 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.24 if_indextoname (Mapping name and index of the network interface)
【Format】
#include “net/if.h” char *if_indextoname(unsigned int ifindex, char *ifname)
【Parameter】 unsigned int char *
【Return value】 ifindex ifname
Interface index
Buffer for storing the interface name int Result of process. If success, ifname value, or on error, NULL.
【errno】
ENXIO Nonexistent interface index
【Explanation】
• The interface name is set by the device name (gNET_DEV[index-1].name [8]) to be used in the TCP/IP protocol stack.
R18UZ0019EJ0300
Feb 28, 2015
Page 111 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.25 rresvport (Get the socket which is bound to port)
【Format】
#include “sys/unistd.h” int rresvport(int *port)
【Parameter】 int * port
【Return value】 int
【errno】
Not set
Buffer to store port number
The socket FD which is bound to port. If socket is not existing, return -1.
R18UZ0019EJ0300
Feb 28, 2015
Page 112 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.26 getifaddrs (Get the address of the interface)
【Format】
#include “sys/types.h” int getifaddrs(struct ifaddrs **ifap)
【Parameter】 struct ifaddrs** ifap
【Return value】 int
【errno】
ENOMEM
The start address of the interface information list
Result of process. If success, 0 or on error, -1.
Error as getting the stored area of intereface information
【Explanation】
• This function gets the interface information for the part of the number of devices (CFG_DEV_MAX) that are set in the application as chain.
• If successfully completed, the following values are stored in “ifap”.
(*ifap)->ifa_next : The pointer of the next structure of interface information is stored. If the last element, this field
is NULL.
(*ifap)->name : The pointer to the interface name is stored.
(*ifap)->ifa_flags : The device number is stored.
(*ifap)->ifa_addr : The IP address of the device is stored as the sockaddr type pointer.
(*ifap)->ifa_netmask : The subnet mask of the device is stored as the sockaddr type pointer.
(*ifap)->ifa_ifu, (*ifap)->ifa_data : No use.
• After successful completion, user will need to release the interface information list in the freeifaddrs() function, because the interface information list is dynamically allocated.
R18UZ0019EJ0300
Feb 28, 2015
Page 113 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.4.27 freeifaddrs (Release the interface information)
【Format】
#include “sys/unistd.h” void freeifaddrs(struct ifaddrs *ifa)
【Parameter】 struct ifaddrs* ifap
【Return value】 void
【errno】
Not set
The start address of the interface information list
【Explanation】
• This function relase the interface information list which was got by getifaddrs() function.
R18UZ0019EJ0300
Feb 28, 2015
Page 114 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.5 Socket option
The following figure shows the list of option which can be set or got by setsockopt() or getsockopt()API. If anything other than the specified options, The function setsockopt() and getsockopt() will return -1.
Table 5.2 Socket option
Option name
SOL_SOCKET level
SO_ACCEPTCONN
SO_BROADCAST
SO_DOMAIN
SO_ERROR
SO_KEEPALIVE
SO_RCVBUF int int int int int int
Type int timeval timeval int
Function
Get the LISTEN state of TCP socket. For Get only.
Affect only to UDP broadcast reception operation. For Get or Set.
Get the socket domain. For Get only.
Get the socket error. For Get only.
Enable the Keep-Alive function of TCP socket. For Set only.
Set the receive buffer. For TCP, it is a byte number of received window. For UDP, it is treated as a number of received packets
(queue size). For Get or Set.
Same as for SO_RCVBUF.
Set the received timeout of socket. For Get or Set.
Set the sending timeout of socket. For Get or Set.
Get socket type. For Get only.
SO_RCVBUFFORCE
SO_RCVTIMEO
SO_SNDTIMEO
SO_TYPE
IPPROTO_IP level
IP_ADD_MEMBERSHIP
IP_DROP_MEMBERSHIP
IP_MTU
IP_MULTICAST_TTL
IP_TOS
IP_TTL
IPPROTO_TCP level
TCP_KEEPCNT
TCP_KEEPIDLE
TCP_KEEPINTVL
TCP_MAXSEG ip_mreqn ip_mreqn int int int int int int int int
Join the multicast group. For UDP socket only. For Set only.
Drop from the multicast group. For Set only.
Get path MTU. For Get only.
TTL setting for multicast sending packet. For Get or Set.
TOS setting for IP sending packet. For Get or Set.
TTL setting for IP sending packet. For Get or Set.
Set the number of times of TCP Keep-Alive probe. For Set only.
Set the non-communication interval of TCP Keep-Alive started. For
Set only.
Set the sending interval for TCP Keep-Alive probe. For Set only.
Set the MSS value of TCP socket. For Get or Set.
R18UZ0019EJ0300
Feb 28, 2015
Page 115 of 168
R-IN32M3 Series
5.5.6 Support function
5. Description of application programming interface
5.5.6.1 Non-blocking setting
By using ioclt() function, user can set the call for socket API to non-blocking (or blocking). At the initial state, all of
APIs are set as blocking. In the case of non-blocking setting, API may return -1, and set EAGAIN to error number. The following table shows API lists that non-blocking setting is available, the condition that error number becomes to
EAGAIN, and the operation that application should behave.
The timeout setting by socket option doesn’t affect to the API with non-blocking. And for the API of TCP/IP stack with BSD socket for R-IN32M3, the calling task may become the sleep state even under non-blocking setting, because of the spec through the inter-task communication.
Table 5.3 non-blocking API
API connect
Condition
In the case of TCP socket, the return value is “-1”, and error number is
EAGAIN, always. accept send sendto recv recvfrom
If there is no socket has been connected to the listen socket, the return value becomes “-1”, and error number becomes EAGAIN.
In the case that it is TCP socket and the sending buffer is full, error number becomes EAGAIN.
In the case that it is UDP socket and the socket is under sending, error number becomes EAGAIN.
If packet has not received yet, error number becomes EAGAIN.
Application behavior
TCP socket continues to wait SYN/ACK from remote and resend SYN during the stipulated time, after returned -1. The
TCP socket is monitored by writefds, because of becoming writable by select at the time of receiving the SYN / ACK.
User does not need to run connect again after becoming writable.
The TCP socket is monitored by readfds, because of becoming readable by select at the time of receiving the SYN from remote. User should run accept again after becoming readable.
EAGAIN means that the packet couldn’t be sent by the condition of socket. (Then also packet is not sent.).
The socket is monitored by readfds, because of becoming readable by select at the time of receiving packet from remote. User should run recv again after becoming readable.
5.5.6.2 Loopback
If a local loopback address (127.0.0.1 ~ 127.255.255.254) is specified as the destination address, the packet is sent is notified to the network interface.
In the TCP/IP stack with BSD for R-IN32M3, loopback address does not have a specific device interface, it is treated as a send-only address. So, it is not possible to run the bind() function for loopback address.
R18UZ0019EJ0300
Feb 28, 2015
Page 116 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.6.3 Error handling
Symbol errno is the only global variables. This value is updated in accordance with the error that occurred during the
API execution. If user wants to run the API from multiple tasks, it is recommended that user gets the last of errno that occurred within a task with using get_errno() function, in order to guarantee the integrity of errno.
【Format】
#include “sys/errno.h” int get_errno(void)
【Parameter】 void
【Return value】 int
【errno】
Not set
The last of errno that occurred within a task called from this API.
【Explanation】
• errno of each task is stored in the global variable UW tsk_errno[] which is the application prepared. User needs to pre-set the maximum number of tasks in this array element.
Table 5.4 errorno list errno
ENXIO
EBADF
ENOMEM
EFAULT
ENODEV
EINVAL
EPIPE
EAGAIN
EALREADY
EDESTADDRREQ
EPROTONOSUPPORT
EAFNOSUPPORT
EADDRINUSE
EADDRNOTAVAIL
EISCONN
ENOTCONN
ETIMEDOUT
ECONNREFUSED
14
19
22
32
35
Value
6
9
12
37
39
43
47
48
49
56
57
60
61
Explanation
Interface is not existed.
Socket FD is invalid.
Out of memory
Parameter error
A fatal abnormality(or unknown) in the system
Parameter error
Socket object is invalid
Run the blocking processing
Processing of already running
Need a destination set
Function is not supported
Address family is not supported
Address is already in use
Address is not available
Socket is already connected
Socket is not connected
Time out
Connection is denied
R18UZ0019EJ0300
Feb 28, 2015
Page 117 of 168
R-IN32M3 Series
5.5.7 Implementation of BSD application
5. Description of application programming interface
5.5.7.1 Source code
Application which uses the BSD sockets needs to bind 4 files (unet3_iodev.c, unet3_option.c, unet3_socket.c, unet3_wrap.c) in the folder “Middleware/uNet3/bsd/” to the application project.
Middleware
|
+--uNet3
+--bsd
+--unet3_lodev.c
+--unet3_option.c
+--unet3_socket.c
+--unet3_wrap.c
In addition, user will need to link library for BSD called “libunet3bsd.a”.
Library
│
└──ARM or GCC or IAR
+--libune3bsd.a /* Library for BSD socket */
5.5.7.2 Include path
Application which uses the BSD sockets needs to add the directry “unet3_posix” and “inc” in the folder
“Middleware/uNet3/bsd/” as a include path in the setting.
Middleware
|
+--uNet3
+--bsd
|
+--unet3_posix /* Include base folder for BSD socket */
| | :
|
+--inc /* Include base folder of uNet3 socket */
R18UZ0019EJ0300
Feb 28, 2015
Page 118 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.7.3 Configuration
In the TCP/IP stack with BSD for R-IN32M3, the maximum number of sockets and the number of the task of application is needed to macro defined in unet3_cfg.h, in advance.
The maximum number of sockets
#define BSD_SOCKET_MAX
The maximum number of sockets, regardless of the protocol, shows the number of sockets that application generates at the same time (including also listen backlog). This macro definition is used for definition of the management table number of
BSD socket and fd_set type, which will be described later. This value must be the same value as the μNet3 socket maximum number (CFG_NET_SOC_MAX).
Number of application tasks
#define NUM_OF_TASK_ERRNO
The number of application tasks is the task number that can be generated in the kernel. This macro definition is used to the management table number of error number, which will be described later. This value, regardless of the use or non-use of BSD, should be set the number of generatable task.
5.5.7.4 Resource definition
Application which uses the BSD sockets needs to prepare a table for managing information.
BSD socket management table
T_UNET3_BSD_SOC gNET_BSD_SOC[BSD_SOCKET_MAX];
BSD socket management table defines a global variable as T_UNET3_BSD_SOC-type array that the number of elements is BSD_SOCKET_MAX.
Error number management table
UW tsk_errno[NUM_OF_TASK_ERRNO]; elements is NUM_OF_TASK_ERRNO.
Error number management table defines a global variable as T_UNET3_BSD_SOC-type array that the number of
R18UZ0019EJ0300
Feb 28, 2015
Page 119 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.7.5 Kernel objects
Kernel objects that TCP/IP stack with BSD for R-IN32M3 uses, is as follows.
Resource name
Task
Mailbox
Use
BSD Wrapper task
Loopback device task
ID TSK_BSD_API
ID_LO_IF_TSK
Communication between the BSD Wrapper task ID MBX_BSD_REQ
Communication between the loopback device task ID_LO_IF_MBX
ID
R18UZ0019EJ0300
Feb 28, 2015
Page 120 of 168
R-IN32M3 Series 5. Description of application programming interface
5.5.7.6 Initialization
Application needs to initialize the BSD module by calling the unet3_bsd_init() function, before using the BSD sockets API. In addition, before this BSD module initialization, the initialization of the uNet3 and device driver are needed to be completed successfully.
【Format】
#include “sys/socket.h”
ER unet3_bsd_init(void)
【Parameter】 void
【Return value】
Result of process. If success, E_OK. or if error, error code. ER
【errno】
E_SYS Failed to initialize the process of kernel objects
Example of use
ER net_sample(void)
{
/* Initialize TCP/IP Stack */
ER ercd;
ercd = net_ini();
if (ercd != E_OK) {
return ercd;
}
/* Initialize Ethernet Driver */
ercd = net_dev_ini(1);
if (ercd != E_OK) {
return ercd;
}
/* BSD wrapper */
ercd = unet3_bsd_init();
return ercd;
}
R18UZ0019EJ0300
Feb 28, 2015
Page 121 of 168
R-IN32M3 Series
5.6 Other API
htons
【Format】
UH htons(UH val);
【Parameter】
UH
【Return value】
UH htonl
【Format】
UW htonl(UW val);
【Parameter】
UW
【Return value】
UW ntohs
【Format】
UH ntohs(UH val);
【Parameter】
UH
【Return value】
UH ntohl
【Format】
UW ntohl(UW val);
【Parameter】
UW
【Return value】
UW
5. Description of application programming interface
Convert 16 bit value to network byte order val
Convert 32 bit value to network byte order val
Convert 16 bit value to host byte order val
Convert 32 bit value to host byte order val
16 bit value host byte order
16 bit value to network byte order
32 bit value host byte order
32 bit value network byte order
16-bit value network byte order
16-bit value host byte order
32 bit value network byte order
32 bit value host byte order
R18UZ0019EJ0300
Feb 28, 2015
Page 122 of 168
R-IN32M3 Series ip_aton
5. Description of application programming interface
Convert an IPv4 address string in dot-notation to 32 bit value
【Format】
UW ip_aton(const char *str);
【Parameter】 char
【Return value】 str
UW >0
【Error code】
0
Pointer to IPv4 address string in dot-notation
Successful completion (32 bit value after converting)
Wrong IP address is specified ip_ntoa Convert 32-bit value IPv4 address to IPv4 address string in dot-notation
【Format】 void ip_ntoa(const char *str, UW ipaddr);
【Parameter】 char
UW
【Return value】
None str ipaddr
Pointer that accepted IP address string after converting
32-bit value IP address
【Explanation】
If the process completes successfully, the character string will be set in str, but str will be NULL if the error occurs.
R18UZ0019EJ0300
Feb 28, 2015
Page 123 of 168
R-IN32M3 Series ip_byte2n
5. Description of application programming interface
Convert IPv4 address array to 32 bit value
【Format】
UW ip_byte2n(char *ip_array);
【Parameter】 char
【Return value】 ip_array
UW >0
【Error code】
0
Pointer to byte value array of IP address
Successful completion (32-bit value after converting)
Wrong IP address is specified ip_n2byte Convert 32 bit value IPv4 address to array
【Format】 void ip_n2byte(char *ip_arry, UW ip);
【Parameter】 char
UW
【Return value】
None ip_array ip
Pointer to byte value array of IP address
32-bit value IP address
【Explanation】
After completing successfullyl, value is set in asip_array. In case of error, ip_array turns into NULL.
R18UZ0019EJ0300
Feb 28, 2015
Page 124 of 168
R-IN32M3 Series
6. Network application
6. Network application
6.1 DHCP client
DHCP client obtains IP address information which is used in network from DHCP server. Acquired IP address is assigned to the host.
SE THIS FUNCTION OF RENEW, RELEASE, DECLINE, FEATURES INFORM. FOR DHCP EXTENDED
VERSION, SEE THE EXTENDED VERSION 6.5 DHCP CLIENT.
(1) Host address information typedef struct t_host_addr {
UW ipaddr;
UW
UW
UW subnet; gateway; dhcp;
UW
UW
UW
UW
UB
UB dns[2]; lease; t1; t2; mac[6]; dev_num;
UB
UH state; socid;
} T_HOST_ADDR ;
/* IP address */
/* Subnet Mask */
/* Gateway*/
/* DHCP Server address */
/* DNS Address */
/* Lease period of the DHCP address*/
/* Renewal period of DHCP address*/
/* Rebind period of DHCP address */
/* MAC address */
/* Device address */
/* DHCP Cliente status*/
/* ID of UDP socket*/
This structure is used as an argument of DHCP client API. Device number and ID of UDP socket have to be set by user application. The remaining parameters are set by the response from a DHCP server.
•
ID of UDP socket
In DHCP client, use UDP socket. UDP socket must be created by the following parameter. (It is created in DHCP client applications)
Protocol
UDP
ID
ID_SOC_DHCP 68
Port Transmission timeout
3 seconds
Reception timeout
3 seconds
•
Device number
In device number, specify network device used by DHCP client. If specify '0 ', default network device is used
R18UZ0019EJ0300
Feb 28, 2015
Page 125 of 168
R-IN32M3 Series 6. Network application
6.1.1
dhcp_client
DHCP client API
Starting DHCP Client
【Format】
ER ercd = dhcp_client(T_HOST_ADDR *addr);
【Parameter】
T_HOST_ADDR
【Return value】
ER
【Error code】
E_PAR
E_OBJ
E_TMOUT
*addr ercd host address information
Successful completion (E_OK) or error code
*addr is NULL or socid is specified
Socket status is wrong (socket has not been created yet)
Response from DHCP server delays. Or DHCP server does not exist
【Explanation】
This API acquires an IP address, a subnet mask, a gateway address from a DHCP server and assigns them to host.
Maybe E_TMOUT error occurs due to the construction of using network. At that time, we recommend that you try to retry until it succeeds.
This API will also initiate a new DHCP session. When you call the API, you will start to send operation DISCOVER always expect receive OFFER, send REQUEST, the reception of the ACK that is.
The expiration of an IP address which is acquired from a DHCP server is specified 'lease (lease period).
As follows: DHCP client to do lease before the lease period expires.
R18UZ0019EJ0300
Feb 28, 2015
Page 126 of 168
R-IN32M3 Series 6. Network application
DHCP client example (Exclusive task) void dhcp_tsk(VP_INT exinf)
{
ER ercd;
T_HOST_ADDR dhcp_addr = {0};
UB status = DHCP_STS_INIT;
dhcp_addr.socid = ID_SOC_DHCP;
dhcp_addr.dev_num = ID_DEVNUM_ETHER;
for (;;) {
ercd = dhcp_client(&dhcp_addr);
if (ercd == E_OK) {
/* BOUND period */
dly_tsk(dhcp_addr.t1*1000);
/* RENEWING period */
status = DHCP_STS_RENEWING;
continue;
}
if (status == DHCP_STS_RENEWING) {
/* REBINDING period */
dly_tsk((dhcp_addr.t2-dhcp_addr.t1)*1000);
status = DHCP_STS_INIT;
continue;
}
/* INIT period */
dly_tsk(1000);
}
}
If it is need to update the lease on the DHCPREQUEST message, please use the extended version of DHCP CLient.
R18UZ0019EJ0300
Feb 28, 2015
Page 127 of 168
R-IN32M3 Series 6. Network application
6.2 FTP Server
FTP server enables to download and upload files to the remote host.
FTP Server Control Information typedef struct t_ftp_server {
UB dev_num;
UH
UH
UB ctl_socid; data_socid;
*fs_file;
UW fs_maxsz;
} T_FTP_SERVER ;
/* Device Number*/
/* ID Socket used for Command */
/* ID Socket used for data*/
/* Store buffer */
/* Store buffer size */
Set necessary information in this structure and then transfer as argument of FTP Server API.
•
Device Number
In device number, specify network device used in FTP server. In case of specifying “0”, default network device will be used (Please set 0 normally)
•
TCP socket
FTP server requires two TCP sockets for commands and data. TCP socket should be created in the following parameters. (It will be created in the FTP server application)
Socket used for command:
ID
ID_SOC_FTP_CTL
Protocol Port
TCP send
21 5s receive
Timeout connect
15s -1s 5s interrupt
Buffer size send receive
1024 1024
Socket used for data:
ID Protocol Port
ID_SOC_FTP_DATA TCP send
20 5s receive
15s
Timeout
5s connect
5s interrupt
Buffer size send receive
1024 1024
•
FTP file saving
In this FTP server, because it does not support file system, received files are stored in memory. Please set memory address of storing location in store buffer. In addition, please set size of memory of storing location in Store buffer size.
R18UZ0019EJ0300
Feb 28, 2015
Page 128 of 168
R-IN32M3 Series 6. Network application
6.2.1
ftp_server
FTP Server API
Start up FTP Server
【Format】
ER ercd = ftp_server(T_FTP_SERVER *ftp);
【Parameter】
T_FTP_SERVER
【Return value】
ER
【Error code】
E_PAR
*ftp ercd
FTP server control information
Successful completion (E_OK) or error code
Wrong parameter is specified
(*fpt is NULL. ctl_socid or data_socid is not specified
*fs_file is NULL fs_maxsz is zero)
【Explanation】
This API initializes FTP server, accepts and processes requests from FTP clients. Because this API becomes blocking calling, please use specific task to call it.
FTP server example
T_FTP_SERVER ftpd;
UB ftp_buf[1024];
/* FTP server task */ void FtpServerTask(VP_INT exinf)
{
memset((char*)&ftpd, 0, sizeof(ftpd));
ftpd.ctl_socid = ID_SOC_FTP_CTL;
ftpd.data_socid = ID_SOC_FTP_DATA;
ftpd.fs_file = ftp_buf;
ftpd.fs_maxsz = 1024;
ftp_server(&ftpd);
ext_tsk();
}
6.2.2 Restriction terms
● Supported command includes login, put, get, quit.
● Do not support file system. Therefore, impossible to create directory structure and handle multiple files.
R18UZ0019EJ0300
Feb 28, 2015
Page 129 of 168
R-IN32M3 Series 6. Network application
6.3 HTTP server
HTTP server transmits content to HTTP client (internet browser) statically and dynamically.
(1) HTTP content information typedef struct t_http_file { const char *path; const char const char
Int
*ctype;
*file; len; void(*cbk)(T_HTTP_SERVER *http);
} T_HTTP_FILE ;
Register content to be used in HTTP server in this structure.
/* URL */
/* Content type */
/* Content */
/* Content size*/
/* HTTP callback function or
CGI handler */
•
URL
Show URL of content. For example, if there is request from client to that URL, corresponding content will be sent to client.
Impossible to specify NULL in URL. Besides, URL starts by `/ as usual.
•
Content type
Specify Content-Type of text/html etc. In case of dynamic content, specify NULL.
•
Content
Specify actual content. In case of dynamic content, specify NULL.
•
Content size
Specify size of content. In case of dynamic content, specify 0.
•
Callback function or CGI handler
When it’s dynamic content, specify pointer of the function called from HTTP server. In case of static content, specify
NULL.
R18UZ0019EJ0300
Feb 28, 2015
Page 130 of 168
R-IN32M3 Series
(2) HTTP server control information
6. Network application typedef struct t_http_server {
UB NetChannel;
UH
UH
Port;
SocketID;
UW
UW
UB
UB sbufsz; rbufsz;
*rbuf;
*sbuf;
UB
UW
UW
UW
*req; txlen; rxlen; rdlen;
UW len;
T_HTTP_HEADER hdr;
} T_HTTP_SERVER;
/* Device number*/
/* Listening port number*/
/* ID socket */
/* transmission buffer size */
/* reception buffer size*/
/* transmission buffer*/
/* reception buffer*/
/* internal data*/
/*internal data */
/* internal data*/
/* internal data*/
/* internal data*/
/* HTTP client request */
This structure is used as argument of HTTP server API. ID socket needs to be set by user application.
•
Device number
For device number, specify network device to use in HTTP server. In case of specifying “0”, default network device is used. (Please set “0” normally).
•
ID socket
In HTTP server, use TCP socket. TCP socket needs to be created by the following parameter. (It will be created in
HTTP server application).
ID
ID_SOC_HTTP protocol port
TCP 80 send
25s receive
25s timeout connect
25s interrupt
25s
Buffer size send
1024 receive
1024
•
Transmit buffer Receive buffer
In the HTTP server uses the network protocol stack buffers for each send and receive packets.
And receive buffers (transmit), if you (for example, you want to send content to a larger network buffers, for example) for reasons such as content size, you want to use your own buffer application in which the value of the buffer own buffer size (send) and receive set. You will not get the network buffer on the HTTP server in that case.
Own area set cannot be shared with other processes HTTP server also.
R18UZ0019EJ0300
Feb 28, 2015
Page 131 of 168
R-IN32M3 Series 6. Network application
6.3.1
http_server
HTTP server API
Start up HTTP server
【Format】
ER ercd = http_server(T_HTTP_SERVER *http);
【Parameter】
T_FTP_SERVER
【Return value】
ER
【Error code】
E_PAR
*http ercd
HTTP server control information
Successful completion (E_OK) or error code
Wrong parameter is specified
(*http is NULL. SocketID is not specified. )
【Explanation】
This API initializes HTTP session, then accepts and processes request from HTTP client. In case the URL which is requested from client exists in content table (T_HTTP_FILE), send that content to client, if not, send HTTP error message”404 File not found”. In case content is dynamic (cbk is not NULL), call that callback function.
Because this API becomes blocking call, please use a specific task to call it.
If NULL, the receive buffer of the control information of the argument is HTTP server uses the network buffer.
If NULL, the transmit buffer of the control information of the argument is HTTP server uses the network buffer.
R18UZ0019EJ0300
Feb 28, 2015
Page 132 of 168
R-IN32M3 Series
CgiGetParam CGI argument analysis
【Format】 void CgiGetParam(char *msg, int clen, char *cgi_var[], char *cgi_val[], int *cgi_cnt);
【Parameter】 char int char char int
*msg clen
*cgi_var[]
*cgi_val[]
*cgi_cnt
CGI argument
CGI argument size
Analysed CGI argument
Value of analysed CGI argument
Number of articles of the analysed CGI argument
【Return value】
None
【Error code】
None
【Explanation】
This API analyses query string to be constructed in “field value” group. For example, analysis result in case of query string is given as “name1=value1&name2=value2” as below. cgi_cnt = 2; cgi_var[0] = “name1”; cgi_var[1] = “name2”; cgi_val[0] = “value1”; cgi_val[1] = “value2”;
6. Network application
R18UZ0019EJ0300
Feb 28, 2015
Page 133 of 168
R-IN32M3 Series
HttpSendText Transmission of text content
【Format】
ER ercd = HttpSendText(T_HTTP_SERVER *http, char *str, int len);
【Parameter】 char int int
*http
*str len
HTTP server control information
String to transmit length of string to transmit
【Return value】
ER
【Error code】
None ercd Successful completion only (E_OK)
【Explanation】
This API transmits dynamic content. Please call this API only from HTTP callback function.
Example char page1[] = “<html><body>Welcome to this web server </body></html>”; void Http_Callback(T_HTTP_SERVER *http)
{
HttpSendText(http, page1, sizeof(page1));
}
6. Network application
R18UZ0019EJ0300
Feb 28, 2015
Page 134 of 168
R-IN32M3 Series
HttpSendFile Send Attached File
【API】
ER HttpSendFile(T_HTTP_SERVER*http, char*str, int len, char*name, char *type);
【Parameter】
T_HTTP_SERVER *http char int char char
*str len
*name
*type
HTTP server information
File to be send
Length to be send
Filename
Content-Type value or strings of HTTP header
【Return Value】
ER
【Error Code】
None ercd Success (E_OK)
【DESCRIPTION】
This API sends the dynamic content. Please only be called from this API function callback HTTP.
Send file attachments in API: This is sent in (Content-Disposition attachment).
Use Case char file[1024]; void Http_Callback(T_HTTP_SERVER *http)
{ int len;
:
/* Specify the “file” of contents, the size set to “len” */
:
HttpSendFile(http, file , len, “FILE NAME”, “text/plain”);
}
6. Network application
R18UZ0019EJ0300
Feb 28, 2015
Page 135 of 168
R-IN32M3 Series
HttpSendImage Send Image Content
【API】
ER ercd = HttpSendImage(T_HTTP_SERVER *http, char *str, int len);
【Parameter】
T_HTTP_SERVER char int
*http
*str len
HTTP server information
Image data to be send
Length to be send
【Return Value】
ER
【Error Code】
None ercd Success (E_OK)
【DESCRIPTION】
This API sends the dynamic content. Please only be called from this API function callback HTTP.
6. Network application
R18UZ0019EJ0300
Feb 28, 2015
Page 136 of 168
R-IN32M3 Series
6.3.2 HTTP server sample
/* Definition of content */ const char index_html[] =
"<html>\
<title> uNet3 HTTP Server </title>\
<body>\
<h1>Hello World!</h1>\
</body>\
</html>";
/* Initialization of content list */
T_HTTP_FILE const content_list[] =
{
{"/", "text/html", index_html, sizeof(index_html), NULL},
{"", NULL, NULL, 0, NULL} /* terminal */
};
/* Starting HTTP session */ static T_HTTP_SERVER http_server1; void httpd_tsk1(VP_INT exinf)
{
/* Initialize the content list global pointer */ gHTTP_FILE = (T_HTTP_FILE*)content_list; memset((char* )&http_server1, 0, sizeof(http_server1));
http_server1.SocketID = ID_SOC_HTTP1;
http_server(&http_server1);
}
6. Network application
R18UZ0019EJ0300
Feb 28, 2015
Page 137 of 168
R-IN32M3 Series
6.4 DNS client
In DNS client, use UDP socket. UDP socket will be created by the below parameter.
ID protocol port timeout send
ID_SOC_DNS UDP 0 5s 5s
6. Network application receive
6.4.1 DNS client API
dns_get_ipaddr Acquire IP address from host name
【Format】
ER ercd = dns_get_ipaddr(ID socid, UW dns_server, char *name, UW *ipaddr);
【Parameter】
ID
UW char
UW
【Return value】
ER
【Error code】
E_PAR
E_TMOUT
E_NOMEM
E_OBJ socid dns_server
*name
*ipaddr ercd
UDP socket ID
IP address of DNS server
Host name
IP address to acquire
Successful completion (E_OK) or error code
Wrong parameter is specified
No response from DNS server
Memory error
Unable to resolve IP address from host name
Example of use
UW ip;
ER ercd;
UW dns_server = ip_aton(“192.168.11.1”); dns_get_ipaddr(ID_SOC_DNS, dns_server, “www.eforce.co.jp”, &ip);
R18UZ0019EJ0300
Feb 28, 2015
Page 138 of 168
R-IN32M3 Series dns_get_name Acquire host name from IP address
【Format】
ER ercd = dns_get_name(ID socid, UW dns_server, char *name, UW *ipaddr);
【Parameter】
ID
UW char
UW
【Return value】
ER socid dns_server
*name
*ipaddr ercd
UDP socket ID
IP address of DNS host name to acquire
IP address
Successful completion (E_OK) or error code
【Error code】
E_PAR
E_TMOUT
E_NOMEM
E_OBJ
Wrong parameter is specified
No response from DNS server
Memory error
Unable to acquire host name from IP address
Example of use
UW ip = ip_aton(“192.168.11.30”);
ER ercd; char host_name[256];
UW dns_server = ip_aton(“192.168.11.1”); dns_get_name(ID_SOC_DNS, dns_server, host_name, &ip);
6. Network application
R18UZ0019EJ0300
Feb 28, 2015
Page 139 of 168
R-IN32M3 Series 6. Network application
6.5 DHCP Client
For the existing DHCP client, holds the lease on the resources of the state, such as IP, DHCP client extended version information (RENEW), release (RELEASE), denial (DECLINE), a restart (REBOOT), an extension of these has been enhanced to provide the function get (INFORM).
(1) DHCP Client Information typedef struct t_dhcp_client {
T_DHCP_CTL ctl
UW
UW
UW ipaddr; subnet; gateway;
UW
UW
UW
UW
UW
UB dhcp; dns[2]; lease; t1; t2; mac[6];
UB
UB
UH
UB
} T_DHCP_CLIENT ; dev_num; state socid; arpchk;
/* Control Informatio */
/* IPaddress*/
/* Subnet Mask */
/* Gateway Address */
/* DHCPserver address */
/* DNSAddress */
/* Release time for DHCP Addless */
/* Renewal DHCP address */
/* Rebind time of DHCP address.*/
/* MAC addresss */
/* Device number */
/* Status of DHCP Clients */
/* UDP with socket ID */
/* Duplicate IP check */
This structure is intended to be used as an argument to the DHCP client API, is an extension of the host address information structure. The same manner as described above, UDP socket ID number and device must be set by the user application. Please refer to the DHCP client is the value to be set.
If you set the "ARP_CHECK_ON" to check whether or not duplicate IP, you do the duplicate check using the ACD feature for the IP, which is leased from the DHCP server.
This structure is used, even when I update the IP address that you set IP address at the time of acquisition. We cannot change the DHCP client state and control information in the application for that.
R18UZ0019EJ0300
Feb 28, 2015
Page 140 of 168
R-IN32M3 Series
6.5.1 DHCP Client Extended API
6. Network application dhcp_bind Get DHCP Lease Information
【API】
ER ercd = dhcp_bind(T_DHCP_CLIENT *dhcp);
【Parameter】
T_DHCP_CLIENT
【Return Value】
*dhcp DHCP Client Information
ER ercd Success (E_OK) or Error Code
【Error Code】
E_PAR
E_OBJ
E_SYS
E_TMOUT
DHCP is NULL
Incorrect Socket status (No create the socket)
Address conflict another host when the IP address is assigned.
Response is delay from DHCP server or the DHCP server doesn't exist.
【DESCRIPTION】
This API provides the same functionality as the () API dhcp_client traditional.
To verify the IP address that you get that you do not have overlap with other hosts, we set up a check for duplicate IP
ARP_CHECK_ON the presence of DHCP client information of the argument. If a duplicate IP address is detected at this time, to send a message to the DHCP server DHCP_DECLINE, API will return the E_SYS.
R18UZ0019EJ0300
Feb 28, 2015
Page 141 of 168
R-IN32M3 Series dhcp_renew Renewal DHCP Lease
【API】
ER ercd = dhcp_renew(T_DHCP_CLIENT *dhcp);
【Parameter】
T_DHCP_CLIENT
【Return Value】
*dhcp DHCP Client Information
ER ercd Success(E_OK) or Error Code
【Error Code】
E_PAR
E_OBJ
E_SYS
E_TMOUT
DHCP is NULL
Incorrect DHCP client, or request denied by DHCP server.
Address conflict another host when the IP address is assigned.
Response is delay from DHCP server or the DHCP server doesn't exist.
【DESCRIPTION】
This API to extend the validity period of IP address obtained from the DHCP server. The argument specifies the
DHCP client information obtained by dhcp_bind ().
This API should be called (t
1
) within the validity period. Lifetime is measured by the application using the timer or control task.
This feature also includes the ability RENEW REBIND. The difference between the two is only to send broadcast messages to send unicast REQUEST. If you cannot receive the ACK after sending a REQUEST message to the DHCP server at the beginning, we perform a broadcast transmission immediately.
To verify the IP address that the extension does not have an overlap with other hosts, we set up a check for duplicate IP
ARP_CHECK_ON the presence of DHCP client information of the argument. If a duplicate IP address is detected at this time, to send a message to the DHCP server DHCP_DECLINE, API will return the E_SYS.
6. Network application
R18UZ0019EJ0300
Feb 28, 2015
Page 142 of 168
R-IN32M3 Series dhcp_reboot DHCP Client Reboot
【API】
ER ercd = dhcp_reboot(T_DHCP_CLIENT *dhcp);
【Parameter】
T_DHCP_CLIENT
【Return Value】
*dhcp DHCP Client Information
ER ercd Success(E_OK) or, Error Code
【Error Code】
E_PAR
E_OBJ
E_SYS
E_TMOUT
DHCP is NULL or there is no address available.
Illegal DHCP client information or DHCP server has refused the request.
The assigned IP address conflict with another host.
Delayed response from the DHCP server. Or DHCP server does not exist.
【DESCRIPTION】
This API is reusing the IP resource to which the client was previously used, API is used to verify its legitimacy in
DHCP server. If you do not, such as when you remove and insert the LAN cable or if the LAN interfaces in the pause is activated again, and security that are part of the same network before and after, the DHCP server for the IP resource that has been previously used, for example notice.
The argument specifies the DHCP CLIENT INFORMATION dhcp_bind acquired by ().
If an ACK is not received after sending REQUEST message, API This is an error, or if it receives a DHCPNAK.
To verify the IP address that you notice that you do not have overlap with other hosts, we set the duplicate IP
ARP_CHECK_ON to check whether or not the argument of the DHCP CLIENT INFORMATION. If a duplicate IP address is detected at this time, to send a message to the DHCP server DHCP_DECLINE, API will return the E_SYS.
6. Network application
R18UZ0019EJ0300
Feb 28, 2015
Page 143 of 168
R-IN32M3 Series dhcp_release Release DHCP Lease Information
【API】
ER ercd = dhcp_release(T_DHCP_CLIENT *dhcp);
【Parameter】
T_DHCP_CLIENT
【Return Value】
*dhcp DHCP CLIENT INFORMATION
ER ercd Success (E_OK) or Error Code
【Error Code】
E_PAR
E_OBJ
E_TMOUT
DHCP is NULL
Illegal DHCP client information
Timeout send DHCPRELEASE message
【DESCRIPTION】
This API will notify the DHCP server to release the resources when it no longer want to use the IP address obtained from the DHCP server.
The argument specifies the DHCP information obtained dhcp_bind in (). dhcp_inform Get DHCP Options
6. Network application
【API】
ER ercd = dhcp_inform(T_DHCP_CLIENT *dhcp);
【Parameter】
T_DHCP_CLIENT
【Return Value】
*dhcp DHCP CLIENT INFORMATION
ER ercd Success (E_OK) or Error Code
【Error Code】
E_PAR
E_OBJ
E_TMOUT
DHCP is NULL.
Or, there isn’t available of the address.
No specified the IP address b Host.
Delay DHCP server response. Or no existence DHCP server.
【DESCRIPTION】
This API to get the information other than the IP address from the DHCP server. Set the static IP address, for example, the address of the DNS server is used, for example, if you want to get from the DHCP server.
To the argument set DHCP CLIENT INFORMATION (for R-IN32M3 TCP/IP stack) only socket ID and device number of the interface.
R18UZ0019EJ0300
Feb 28, 2015
Page 144 of 168
R-IN32M3 Series
6.5.2 DHCP Client information Extended
DHCP Client Extended Information void dhcp_client_tsk(VP_INT exinf)
{
ER ercd;
FLGPTN ptn;
T_DHCP_CLIENT dhcp_client = {0};
dhcp_client.dev_num = ID_DEVNUM_ETHER;
dhcp_client.socid = ID_SOC_DHCP;
while (1) {
ercd = dhcp_bind(&dhcp_client);
while (ercd == E_OK) {
/* Set Time event setup t
1
*/
wai_flg(ID_DHCP_FLG, 0xFFFF, TWF_ORW, &ptn);
/* t
1
timeout */
if (ptn & T1_EVENT) {
ercd = dhcp_renew(&dhcp_client);
}
/* re-boot */
else if (ptn & REBOOT_EVENT) {
ercd = dhcp_reboot(&dhcp_client);
}
}
dly_tsk(1000);
}
dhcp_release(&dhcp_client);
}
6. Network application
R18UZ0019EJ0300
Feb 28, 2015
Page 145 of 168
R-IN32M3 Series 6. Network application
6.6 Ping Client
For any destination, Ping client sends the ICMP echo request. We found that in the IP address of the communication is possible if there is an echo response from the other party.
In addition, Ping client sends and receives using the ICMP socket. If R-IN32M3 TCP/IP stack use the socket ID
"ID_ICMP" that is reserved by check instead of defining the ICMP socket, to "use the request ICMP Echo" from the net
Configurator application.
6.6.1 Ping Client API
ping_client ICMP Echo (Transmite Request and Receive Response)
【API】
ER ping_client(T_PING_CLIENT *ping_client);
【Parameter】
T_PING_CLIENT
【Return Value】
*ping_client Ping transmit information
ER ercd Success (E_OK) or Error Code
【Error Code】
E_PAR
E_TMOUT
E_NOMEM
E_OBJ
Specified the incorrect Parameter
No response from remote or failed address resolver
Memory Error
Incorrect ping transmit information
【DESCRIPTION】
This API sends a ping to the IP address that you set in the argument. I continue to wait for a response from the other party and then I get a timeout that is specified in the argument to expire. If you get a response I will return E_OK.
This API is limited to IPv4.
R18UZ0019EJ0300
Feb 28, 2015
Page 146 of 168
R-IN32M3 Series
Use Case
ER ping_send(void)
{
T_PING_CLIENT ping = {0};
ER ercd;
ping.sid = ID_ICMP;
ping.devnum = ID_DEVNUM_ETHER;
ping.tmo = 1000; /* Timeout 1 second*/
ercd = ping_client(&ping);
if (ercd == E_OK) {
/* ping success */
}
return ercd;
}
6. Network application
R18UZ0019EJ0300
Feb 28, 2015
Page 147 of 168
R-IN32M3 Series 6. Network application
6.7 SNTP Client
SNTP client get the (number of seconds starting from 1/1/1900) time from NTP (NTP) server time on the network using the NTP packet.
6.7.1
sntp_client
SNTP Client API
Get NTP time
【API】
ER sntp_client(T_SNTP_CLIENT *sntp_client, UW *sec, UW *msec);
【Parameter】
T_SNTP_CLIENT
UW
UW
【Return Value】
ER
【Error Code】
E_PAR
E_TMOUT
E_NOMEM
E_OBJ
*sntp_client
*sec
*msec ercd
Information of SNTP client
MTP Time (second)
NTP Time(32-bit fixed-point representation below the decimal)
Success (E_OK) or Error Code
Specified the illegal parameter
No response from remote or failed address resplver
Memory Error
Incorrect Information of SNTP client
【DESCRIPTION】
This API gets the time from NTP NTP server you set up in the argument. To set the NTP server, specify the IPv4 address and port number.
In the SNTP client uses the UDP socket. If R-IN32M3 TCP/IP stack argument should be set to the socket ID available.
This API returns the E_OK if you can successfully get the time NTP.
NTP time is shown in the sec and msec arguments at this time. Because you are starting from 1/1/1900, NTP time and the conversion to Unix time (JST) UTC must be calculated by the caller.
R18UZ0019EJ0300
Feb 28, 2015
Page 148 of 168
R-IN32M3 Series
Use Case
ER sntp_time(void)
{
T_SNTP_CLIENT sntp = {0};
UW sec, msec;
ER ercd;
sntp.sid = ID_UDP;
sntp.devnum = ID_DEVNUM_ETHER;
ercd = sntp_client(&sntp, &sec, &msec);
if (ercd == E_OK) {
/* Convert to Unix Time */
sec -= 2208988800;
/* Accuracy for ms */
msec >>= 16;
msec *= 1000;
msec >>= 16;
}
return ercd;
}
6. Network application
R18UZ0019EJ0300
Feb 28, 2015
Page 149 of 168
R-IN32M3 Series 6. Network application
6.8 String Library
R-IN32M3 TCP/IP stack system provides a standard library of String so that it is not dependent on the compiler.
Network applications you can use to provide these functions. net_strncasecmp Compare String (case-insensitive letter)
【API】
W net_strncasecmp(const char *str1, const char *str2, W len);
【Parameter】 const char * const char *
W str1 str2 len
String to be compared
String to be compared
Length of compare
【Return Value】
W Result
【DESCRIPTION】
The results were compared with the character code, it will return 0 if str1 = str2. The return value is positive if str1> str2, and is negative if str1 <str2.
I arrived at the end of either string number of characters until it reaches the comparison is to be compared. By this function equate the case of the letters. net_strcmp String Compare
【API】
W net_strcmp(const char *str1, const char *str2);
【Parameter】 const char * const char *
【Return Value】
W str1 str2
String to be compared
String to be compared
Result of Compare
【DESCRIPTION】
The results were compared with the character code, it will return 0 if str1 = str2. The return value is positive if str1> str2, and is negative if str1 <str2.
Reach the end of the string until one of them to be compared
R18UZ0019EJ0300
Feb 28, 2015
Page 150 of 168
R-IN32M3 Series net_strcpy String Copy
【API】 char* net_strcpy(char *str1, const char *str2);
【Parameter】 char * const char * str1 str2
Address of copy destination string
Address of copy source string
【Return Value】 char* str1 Address of copy destination string
【DESCRIPTION】
This API is to copy of the srt2 to the end of str1 (NULL). net_strlen Get String Length
【API】
UW net_strlen(const char *str);
【Parameter】 char *
【Return Value】 str
UW
String
String length
【DESCRIPTION】
Gets the number of characters up to (NULL) end of str. (NULL is not included) net_strcat String concatenation
【API】 char* net_strcat(char *str1, const char *str2);
【Parameter】 char * const char *
【Return Value】 char str1 str2 str1
Address of destination string
Address of source string
Address of destination string
【DESCRIPTION】
Copy to the end of the str2 starting at (NULL) coupling the end of the destination string str1.
6. Network application
R18UZ0019EJ0300
Feb 28, 2015
Page 151 of 168
R-IN32M3 Series net_strchr Search Character
【API】 char* net_strchr(const char *str, int ch);
【Parameter】 const char *
Int str ch
【Return Value】 char str
Search target character
Search character
In the subject string, address search string appears.
If the search string does not appear NULL
6. Network application
R18UZ0019EJ0300
Feb 28, 2015
Page 152 of 168
R-IN32M3 Series 7. Tutorial by sample application
7. Tutorial by sample application
In this chapter, the way to run the TCP/IP stack sample application is showed, and the behavior of it is confirmed.
7.1 Descriptions of sample software
“uNet3_sample” under the directory “Project” is used. This sample software lets us confirm HTTP server.
• Web server
LED flashing period can be changed by 100 msec unit from the Web browser.
R-IN32M3 TCP/IP stack is need to merge to driver and middleware sample program.
7.2 Hardware connection
Please check file DDR_ETH_CFG.h.
If macro USE_ETHSW is set to 0, please use the R-IN32-EC board’s RJ45 PORT1. See following figure.
Fig. 7.1 Physical port connection for sample application
R18UZ0019EJ0300
Feb 28, 2015
Page 153 of 168
R-IN32M3 Series 7. Tutorial by sample application
7.3 Board IP address setting
There are two options for setting the IP address. Either use a fixed IP address, or let the LAN network DHCP controller set it.
7.3.1 Setting for use a fixed IP address
Please set according to following procedure.
(1) Set DHCP_ENA to 0 in net_sample.c.
(2) Set desired server network address setting in net_cfg.c. Example is shown in Fig. 7.2.
/*******************************************
Define Local IP Address
********************************************/
T_NET_ADR gNET_ADR[] = {
{
0x0, /* Reserved */
0x0, /* Reserved */
0xC0A80164, /* IP address (192.168. 1.100) */
0xC0A80101, /* Gateway (192.168. 1. 1) */
0xFFFFFF00, /* Subnet mask (255.255.255. 0) */
}
};
Fig. 7.2 The example setting of IP address (in case IP address is 192.168.1.100)
(3) Your PC’s IP-address need to be in the same domain as the R-IN32M3 board. (Please also refer next page as detail procedure.)
In this example we will use:
Subnet mask: 255.255.255.0.
PC IP-address: 192.168.1.101.
This is so that server and client are in the same domain.
(4) Skip next section “7.3.2 Setting for use DHCP ”.
R18UZ0019EJ0300
Feb 28, 2015
Page 154 of 168
R-IN32M3 Series 7. Tutorial by sample application
cf. How to set the PC IP-address (not using DHCP)
・ Open the network connections list.
In Windows7: Control panel->Network and Sharing Center->Change adapter settings.
・ Double-click (or right-click) on the Local Area Connection, then select "Properties".
・ Select TCP/IPv4, and push the Properties button.
R18UZ0019EJ0300
Feb 28, 2015
Page 155 of 168
R-IN32M3 Series
・ Set IP-address to 192.168.1.101, and sub net mask to 255.255.255.0
7. Tutorial by sample application
Done.
7.3.2 Setting for use DHCP function
When DHCP client is enabled, IP address is defined automatically by DHCP server. In this case, UDP socket for
DHCP is also added automatically.
Please set according to following procedure.
(1) Set DHCP_ENA to 1 in net_sample.c.
(2) Connect the LAN server IP cable to port 1
(3) Connect the LAN server IP cable to the PC.
Note If user uses EWARM evaluation version which is size limited 32KB and set DHCP_ENA to 1, the sample project might not be able to compile because of size limitation.
R18UZ0019EJ0300
Feb 28, 2015
Page 156 of 168
R-IN32M3 Series
7.4 Demonstration
7. Tutorial by sample application
7.4.1 Webserver
In this example we will use the IAR project “uNet3_sample”. The workbench file is in
..\r-in32m3_samplesoft\r-in32m3_samplesoft\Device\Renesas\RIN32M3\Source\Project\uNet3_sample
\IAR \main.eww
Please execute the following procedure.
1. Compile, download, and run application.
2. Open a web browser in PC (client),
3. Enter into the URL field http://192.168.1.100
(or http://192.168.1.100:80 , but socket is default 80 for http).
If you have problems getting or seeing anything in the browser, you may need to restart the code in IAR, and/or get rid of breakpoints that cause timeouts.
Fig. 7.3 The result of sample application (HTTP server)
R18UZ0019EJ0300
Feb 28, 2015
Page 157 of 168
R-IN32M3 Series
8. Appendix
8.1 Packet format
(1) T_NODE
Information of communication endpoint typedef struct t_node {
UH port;
UB
UB
UW
} T_NODE; ver; num; ipa;
/* Port number of socket */
/* IP version*/
/* Necessarily specify IP_VER4 */
/* Device number*/
/* IP address */
(2) T_NET_ADR
Information of network address typedef struct t_net_adr {
UB ver;
UB
UW
UW
UW
} T_NET_ADR; mode; ipaddr; gateway; mask;
(3) T_NET_DEV
The information of the network device typedef struct t_net_dev {
UB name[8];
FP
FP
FP
FP
UH
UH
UH
UH
FP
FP
UW union {
struct {
UB num; type; sts; flg; ini; cls; ctl; ref; out; cbk;
*tag; mac[6];
/* IP- Version*/
/* Necessarily specify IP_VER4*/
/* Reserve*/
/* IP Address*/
/* Gateway*/
/* Subnet mask*/
/* Device name */
/* Device number */
/* Device type */
/*Reserve */
/* Reserve */
/* Pointer to dev_ini function*/
/*Pointer to dev_cls function*/
/* Pointer to dev_ctl function*/
/*Pointer to dev_ref function*/
/*Pointer to dev_snd function*/
/*Pointer to dev_cbk function*/
/*Reserve */
/* MAC address */
R18UZ0019EJ0300
Feb 28, 2015
8. Appendix
Page 158 of 168
R-IN32M3 Series
}eth;
} cfg;
UH
UH
} T_NET_DEV; hhdrsz; hhdrofs;
/* Device header size */
/* Position of writing network buffer*/
(4) T_NET_BUF
Information of network buffer <R> typedef struct t_net_buf {
UW *next;
ID
T_NET mpfid;
*net;
T_NET_DEV *dev;
T_NET_SOC *soc;
ER
UH ercd; flg;
UH
UH
UH
UB
UB
UB
} T_NET_BUF ; seq; dat_len; hdr_len;
*dat;
*hdr; buf[];
(5) T_HOST_ADDR
Information of host address typedef struct t_host_addr {
UW ipaddr;
UW
UW subnet; gateway;
UW
UW
UW
UW dhcp; dns[2]; lease; t1;
UW
UB
UB
UH t2; mac[6]; dev_num; socid;
} T_HOST_ADDR ;
/* Reserve */
/* Memory pool ID */
/* Network interface */
/* Network device */
/* Socket*/
/* Error code */
/* Protocol stack control flag*/
/* Fragment sequence */
/* Data size of packet */
/* Header size of packet*/
/* Indicate data position of packet (buf) */
/* Indicate header position of packet (buf) */
/* Actual packet */
/* IP address*/
/* Subnet mask */
/* Gateway */
/* DHCPserver address */
/* DNS address */
/* Lease period of DHCP address */
/* Renewal period of DHCP address*/
/* Rebind period of DHCP address */
/* MAC address */
/* Device number */
/* UDP socket ID */
8. Appendix
R18UZ0019EJ0300
Feb 28, 2015
Page 159 of 168
R-IN32M3 Series
(6) T_FTP_SERVER
FTP server control information typedef struct t_ftp_server {
UB dev_num;
UH
UH
UB ctl_socid; data_socid;
*fs_file;
UW fs_maxsz;
} T_FTP_SERVER ;
(7) T_HTTP_FILE
HTTP Content Information typedef struct t_http_file { const char const char const char int path[12]; ctype[12];
*file; len;
/* Device number */
/* SocketID for command */
/* SocketID for data */
/* Store buffer */
/* Store buffer size */ void(*cbk)(T_HTTP_SERVER *http);
/* URL */
/* Content type*/
/* Content */
/* Content size*/
/* HTTP callback function or
CGI handler */
} T_HTTP_FILE ;
(8) T_HTTP_SERVER
HTTP Server control information typedef struct t_http_server {
UW
UW
UW
UW
UW
UW sbufsz; rbufsz; txlen; rxlen; rdlen; len;
UB
UB
UB
*rbuf;
*sbuf;
*req;
UH
UH
Port;
SocketID;
T_HTTP_HEADER hdr;
UB
UB
} T_HTTP_SERVER;
NetChannel; ver
/* Transmission buffer size */
/* Reception buffer size */
/* Internal data*/
/* Internal data*/
/* Internal data*/
/* Internal data*/
/* Transmission buffer*/
/* Reception buffer */
/* Internal data*/
/* Listerning port number*/
/* Socket ID */
/* HTTP client request */
/* Device number */
/* IP version */
R18UZ0019EJ0300
Feb 28, 2015
8. Appendix
Page 160 of 168
R-IN32M3 Series
(9) T_RCV_PKT_INF
Reception packet information typedef struct t_rcv_pkt_inf{
UW src_ipa;
UW
UH
UH
UB
UB
UB dst_ipa; src_port; dst_port; ttl; tos; ver;
UB num;
} T_RCV_PKT_INF;
/* Source IP address of packet*/
/* Destination IP address of packet*/
/* Source port number of packet*/
/* Destination port number of packet*/
/* IP header TTL of packet*/
/* IP header TOS of packet*/
/* IP header version of packet*/
/* Reception device number of packet/
(10) T_DHCP_CLIENT
DHCP Client information typedef struct t_dhcp_client {
T_DHCP_CTL
UW
UW
UW
UW
UW
UW
UW
UW
UB
UB
UB
UH
UB
} T_DHCP_CLIENT; ctl ipaddr; subnet; gateway; dhcp; dns[2]; lease; t1; t2; mac[6]; dev_num; state; socid; arpchk
(11) T_PING_CLIENT
Ping Client Information typedef struct t_ping_client {
ID sid;
UW ipa;
TMO
UH
UH tmo; devnum; len;
} T_PING_CLIENT;
/* Internal data*/
/* IP address*/
/* Subnet mask */
/* Gateway */
/* DHCPserver address */
/* DNS address */
/* Lease period of DHCP address */
/* Renewal period of DHCP address*/
/* Rebind period of DHCP address */
/* MAC address */
/* Device number */
/* DHCP client status */
/* UDP socket ID */
/* APR check */
/* ICMP Socket ID */
/* Destination IP Address */
/* Response Time out */
/* Device number */
/* Packet Size */
R18UZ0019EJ0300
Feb 28, 2015
8. Appendix
Page 161 of 168
R-IN32M3 Series
(12) T_SNTP_CLIENT
SNTP Client Information typedef struct t_sntp_client {
ID sid;
UW ipa;
TMO tmo;
UH devnum;
UH
UB port; ipv;
} T_SNTP_CLIENT;
/* UDP Socket ID */
/* NTP server IP address */
/* Response Time out */
/* Device numbr */
/* NTP server port number */
/* IP vrsion */
8. Appendix
R18UZ0019EJ0300
Feb 28, 2015
Page 162 of 168
R-IN32M3 Series
8.2 Constant and Macro
(1) IP Address
ADDR_ANY
IP_VER4
IP address 0
IP version 4
(2) Port Number
PORT_ANY Port number 0
(3) IP protocol
IP_PROTO_TCP
IP_PROTO_UDP
IP_PROTO_ICMP
TCP protocol
UDP protocol
ICMP protocol
(4) Network interface control
NET_IP4_CFG
NET_IP4_TTL
NET_BCAST_RCV
NET_MCAST_JOIN
NET_MCAST_DROP
NET_MCAST_TTL
Configure and verify IP Address, Subnet mask
Configure and vefiry TTL
Configure and verify reception of broadcast
Join in multicast group
Drop from multicast Group
Configure TTL used in multicast transmission
(5) Parameter of socket
SOC_IP_TTL
SOC_IP_TOS
SOC_TMO_SND
SOC_TMO_RCV
SOC_TMO_CON
SOC_TMO_CLS
SOC_IP_LOCAL
SOC_IP_REMOTE
SOC_CBK_HND
SOC_CBK_FLG
SOC_RCV_PKT_INF
Configure and verify TTL of Socket
Configure and verify TOS of Socket
Configure and verify blocking time-out of snd_soc
Configure and verify blocking time-out of rcv_soc
Configure and verify blocking time-out of con_soc
Configure and verify blocking time-out of cls_soc
Get port number and IP address of local host
Get port number and IP address of remote host
Register callback function
Specify callback event
Get information of reception packet
(6) Connection mode of socket
SOC_CLI
SOC_SER
Connect to remote host (active connection)
Wait for connection (passive connection)
R18UZ0019EJ0300
Feb 28, 2015
8. Appendix
Page 163 of 168
R-IN32M3 Series
(7) Termination mode of socket
SOC_TCP_CLS
SOC_TCP_SHT
Disconnect socket. (Terminate connection)
Disable only the transmission process. Reception is possible
(8) Interruption mode of socket
SOC_ABT_CON
SOC_ABT_CLS
SOC_ABT_SND
SOC_ABT_RCV
SOC_ABT_ALL
Abort con_soc()
Abort cls_soc()
Abort snd_soc()
Abort rcv_soc()
Abort all the processes of socket
(9) Callback Event
EV_SOC_CON
EV_SOC_CLS
EV_SOC_SND
EV_SOC_RCV
Enable con_soc() to be non-blocking mode
Enable cls_soc() to be non-blocking mode
Enable snd_soc() to be non-blocking mode
Enable rcv_soc() to be non-blocking mode
8. Appendix
R18UZ0019EJ0300
Feb 28, 2015
Page 164 of 168
R-IN32M3 Series
8.3 Error Code List
E_NOSPT
E_PAR
E_ID
E_NOMEM
E_OBJ
E_NOEXS
E_QOVR
E_RLWAI
E_TMOUT
E_CLS
E_WBLK
E_BOVR
-42
-43
-49
-50
-52
-57
-58
-9
-17
-18
-33
-41
Unsupported function
Parameter error
Illegal ID number
Insufficient memory
Object status error
Uncreated object
Queuing overflow
Forced cancellation of wait state
Polling failure or time-out
Change status of waiting object
Non-blocking acceptance
Buffer overflow
8. Appendix
R18UZ0019EJ0300
Feb 28, 2015
Page 165 of 168
R-IN32M3 Series
8.4 API List
API Name
ftp_server http_server
CgiGetParam
HttpSendText
HttpSendFile
HttpSendImage dns_get_ipaddr dns_get_name dhcp_bind dhcp_renew dhcp_reboot dhcp_release dhcp_inform ping_client sntp_client
E) Others
ip_aton ip_ntoa ip_byte2n ip_n2byte htons
A) Network Interface
net_ini net_cfg net_ref net_acd
B) Network Device Control
net_dev_ini net_dev_cls net_dev_ctl net_dev_sts
C) Socket
cre_soc del_soc con_soc cls_soc snd_soc rcv_soc cfg_soc ref_soc abt_soc
D) Network Application
dhcp_client
Initialize TCP / IP protocol stack
Configure parameters of network interface
Refer parameters of network interface
Detection IP Address Confliction
Initialize network device
Release Network Device
Control network device
Get status of network device
Create socket (Standard version only)
Delete a socket (Standard version only)
Socket connection
Socket interruption
Send data
Receive data
Configure parameter of socket
Refer parameter of socket
Abort process of socket
Start DHCP Client
Start FTP Server
Start HTTP server
Analyze CGI argument
Send text content
Send Attached File
Send Image Content
Get IP address from host name
Get host name from IP address
Get DHCP Lease Information
Renewal DHCP lease information
Reboot DHCP client
Release DHCP lease information
Get DHCP option
ICMP Echo request and response
Get NTP time
Convert IPv4 address string in dot notation to 32-bit value
Convert 32-bit value IPv4 address to IPv4 address string in dot notation
Convert IPv4 address array to 32 bit value
Convert 32-bit value IPv4 addresse to array
Convert 16-bit value to network byte order
8. Appendix
R18UZ0019EJ0300
Feb 28, 2015
Page 166 of 168
R-IN32M3 Series ntohs htonl ntohl
8.5 Resource list
<R>
Convert 16-bit value to host byte order
Convert 32-bit value to network byte order
Convert 32- bit value to host byte order
8. Appendix
8.5.1 Kernel objects
(1) Kernel object used by Ethernet device driver
Object
Task
Task
Task
Task
Event flag
Event flag
Event flag
Event flag
Mail box
Mail box
Object ID
ID_TASK_ETH_SND
ID_TASK_ETH_RCV
ID_TASK_PHY0_LINK
ID_TASK_PHY1_LINK
ID_FLG_ETH_RX_MAC
ID_FLG_ETH_TX_MAC
ID_FLG_PHY_STS
ID_FLG_SYSTEM
ID_MBX_ETH_SND
ID_MBX_ETH_MEMPOL
Description
Ether driver send task (stack size: 1024Byte)
Ether driver receive task (stack size: 1024Byte)
PHY driver control task (stack size: 512Byte)
PHY driver control task (stack size: 512Byte)
Ether driver event flag
Ether driver event flag
Ether driver event flag
Ether driver event flag
Ether driver mail box
Ether driver mail box
(2) Kernel object used by TCP/IP protocol stack (μNet3 compatible)
Object
Task
Semaphore
Object ID
ID_TASK_TCP_TIM
ID_SEM_TCP
Description
TCP/IP stack time management task for R-IN32M3
Semaphore to control protocol stack resource.
(3) Kernel object used by TCP/IP protocol stack (BSD compatible)
Object
Task
Task
Mail box
Mail box
Object ID
ID TSK_BSD_API
ID_LO_IF_TSK
ID MBX_BSD_REQ
ID_LO_IF_MBX
BSD Wrapper task
Loop back device task
Description
BSD Wrapper communication between task
Communication between device task
Kernel objects used by TCP/IP protocol stack (uNet3 compatible) are also used added to above. Note
(4) Kernel object used by memory management
Object
Mail box
Object ID
ID_MBX_ETH_MEMPOL Memory management
Description
R18UZ0019EJ0300
Feb 28, 2015
Page 167 of 168
R-IN32M3 Series
8.5.2 Hardware ISR
Table.8.1 Hardware ISR used by TCP/IP stack for R-IN32M3
Hardware ISR reason
PHY0_IRQn
PHY1_IRQn
ETHTXDMA_IRQn
ETHTXDERR_IRQn
ETHTX_IRQn
ETHTXFIFO_IRQn
ETHTXFIFOERR_IRQn
ETHRXDMA_IRQn
ETHRXFIFO_IRQn,
ETHRXDERR_IRQn
ETHRXERR_IRQn
Operation set_flg() set_flg() set_flg() set_flg() set_flg() set_flg() set_flg() set_flg() set_flg() set_flg() set_flg()
Description
PHY driver
PHY driver
Ethernet driver send operation
Ethernet driver send operation
Ethernet driver send operation
Ethernet driver send operation
Ethernet driver send operation
Ethernet driver receive operation
Ethernet driver receive operation
Ethernet driver receive operation
Ethernet driver receive operation
8. Appendix
R18UZ0019EJ0300
Feb 28, 2015
Page 168 of 168
2.01
3.00
REVISION HISTORY
Rev.
1.00
2.00
R-IN32M3 Series User’s Manual: TCP/IP stack
Date
Page
Description
Summary
Jul 26, 2013
Oct 4, 2013
-
-
First edition issued
Typos are fixed all over this document.
2 Table 1.2Development tools EWARM version is fixed.
9 Fig. 2.2 Block diagram of network system Typos in figure fixes.
10 Table 2.1OS Kernel objects which are used in TCP/IP stack for R-IN32M3
Delete”ID_ NET_MAIN_TSK” as not used.
11 Table 2.2Hardware ISR which are used in TCP/IP stack for R-IN32M3 New created
23 3.2 Network device driver Sentences fixes.
96 7.3 Behavior confirmation Add procedure.
Apr 18, 2014 94-98 Add some detail descriptions in 7. Tutorial by sample application
Feb 28, 2015 1
11
32
35
39
54
87
159
167
Modify Table 1.1 The difference between evaluation edition and commercial edition
Modify 2.3Directory and file organization
Modify 3.2.4T_NET_DEV information registration example
Modify 3.3.1Network buffer
Add 3.5Ethernet device driver
Add 3.6PHY driver
Add 5.5Socket API (BSD compatible)
Modify (4)T_NET_BUF of 8.1Packet format
Add 8.5Resource list
C - 1
[Memo]
Renesas Electronics America Inc.
2880 Scott Boulevard Santa Clara, CA 95050-2554, U.S.A.
Tel: +1-408-588-6000, Fax: +1-408-588-6130
Renesas Electronics Canada Limited
1101 Nicholson Road, Newmarket, Ontario L3Y 9C3, Canada
Tel: +1-905-898-5441, Fax: +1-905-898-3220
Renesas Electronics Europe Limited
Dukes Meadow, Millboard Road, Bourne End, Buckinghamshire, SL8 5FH, U.K
Tel: +44-1628-651-700, Fax: +44-1628-651-804
Renesas Electronics Europe GmbH
Arcadiastrasse 10, 40472 Düsseldorf, Germany
Tel: +49-211-65030, Fax: +49-211-6503-1327
Renesas Electronics (China) Co., Ltd.
7th Floor, Quantum Plaza, No.27 ZhiChunLu Haidian District, Beijing 100083, P.R.China
Tel: +86-10-8235-1155, Fax: +86-10-8235-7679
Renesas Electronics (Shanghai) Co., Ltd.
Unit 204, 205, AZIA Center, No.1233 Lujiazui Ring Rd., Pudong District, Shanghai 200120, China
Tel: +86-21-5877-1818, Fax: +86-21-6887-7858 / -7898
Renesas Electronics Hong Kong Limited
Unit 1601-1613, 16/F., Tower 2, Grand Century Place, 193 Prince Edward Road West, Mongkok, Kowloon, Hong Kong
Tel: +852-2886-9318, Fax: +852 2886-9022/9044
Renesas Electronics Taiwan Co., Ltd.
13F, No. 363, Fu Shing North Road, Taipei, Taiwan
Tel: +886-2-8175-9600, Fax: +886 2-8175-9670
Renesas Electronics Singapore Pte. Ltd.
80 Bendemeer Road, Unit #06-02 Hyflux Innovation Centre Singapore 339949
Tel: +65-6213-0200, Fax: +65-6213-0300
Renesas Electronics Malaysia Sdn.Bhd.
Unit 906, Block B, Menara Amcorp, Amcorp Trade Centre, No. 18, Jln Persiaran Barat, 46050 Petaling Jaya, Selangor Darul Ehsan, Malaysia
Tel: +60-3-7955-9390, Fax: +60-3-7955-9510
Renesas Electronics Korea Co., Ltd.
11F., Samik Lavied' or Bldg., 720-2 Yeoksam-Dong, Kangnam-Ku, Seoul 135-080, Korea
Tel: +82-2-558-3737, Fax: +82-2-558-5141
© 2013-2014 Renesas Electronics Corporation. All rights reserved
R-IN32M3 Series
User’s Manual: TCP/IP stack

Public link updated
The public link to your chat has been updated.
Advertisement
Key features
- IPv4, ARP, ICMP, IGMPv2, UDP, TCP
- DHCP client, DNS client, FTP server, HTTP server
- Compact design optimized for R-IN32M3
- Multiple network interface
- TCP fast retransmit and fast recovery
- IP reconstructure and fragmentation
- Protocol stack configurations
- Provides source code of network application
- Provides source code of network device driver