Home
R-IN32M3 Series User`s Manual TCP/IP stack
Contents
1. 2 2 1 Block diagram of network system Application program s 8 13 R IN32M3 TCP IP stack wn ln ln Oo O Oo 9 o o Application interface a O SOCKETO SOCKET1 SOCKETN Ci Device_num0 Device_num1 Device_numN a E O lt 3 TCP IP protocol stack eNET O gNET Device_numN 1 gNET_DEV 0 gNET_DEV Device_numN 1 gNET_ADR O gNET_ADR Device_numN 1 gNET_CFG 0 gNET_CFG Device_numN 1 d S O D gt a v D D A gt Network device control API e la 2 z la amp a ln ZS Network buffer Z ln 5 5 o Q 5 5 o lt lt o Network device driver Network device driver Device number 1 Device number N a Ne 2 Network device ex Ethernet Network device ex PPP Fig 2 2 Block diagram of network system e Application program The application program is used for network communication It includes application protocols such as DHCP FTP Telnet HTTP etc R18UZ0019EJ0300 RENESAS Page 9 of 168 Feb 28 2015 R IN32M3 Series 2 Basic concepts of R IN32M3 TCP IP stack e 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 e TCP IP protocol stack This program handles the network protocols such as TCP UDP ICMP IGMP IP and ARP e Network devic
2. 8 5 Resource list lt R gt 8 5 1 Kernel objects 1 Kernel object used by Ethernet device driver Convert 32 bit value to host byte order Object Object ID Description Task ID_TASK_ETH_SND Ether driver send task stack size 1024Byte Task ID_TASK_ETH_RCV Ether driver receive task stack size 1024Byte Task ID_TASK_PHYO_LINK PHY driver control task stack size 512Byte Task ID_TASK_PHY1_LINK PHY driver control task stack size 512Byte Event flag ID_FLG_ETH_RX_MAC Ether driver event flag Event flag ID_FLG_ETH_TX_MAC Ether driver event flag Event flag ID_FLG_PHY_STS Ether driver event flag Event flag ID_FLG_SYSTEM Ether driver event flag Mail box ID_ MBX_ETH_SND Ether driver mail box Mail box ID_ MBX_ETH_MEMPOL Ether driver mail box 2 Kernel object used by TCP IP protocol stack u Net3 compatible Object Task Object ID ID_TASK_TCP_TIM TCP IP stack time management task for R IN32M3 Description Semaphore ID_SEM_TCP Semaphore to control protocol stack resource 3 Kernel object used by TCP IP protocol stack BSD compatible Object ID Description ID TSK_BSD_API BSD Wrapper task Mail box ID_LO_IF_TSK ID MBX_BSD_REQ Loop back device task BSD Wrapper communication between task Mail box ID_LO_IF_MBX Communication between device task Note Kernel objects used by TCP IP protocol stack uNet3 compatible a
3. R18UZ0019EJ0300 Feb 28 2015 RENESAS 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 dev_num UH opt VP val Return value ER E_OK E_PAR Explanation This function calls Ethernet driver and PHY driver functions Available option is below Option type Device number Option type Option contents Success Invalid value Option contents Available value ETH_OPT_PHY_MODE R18UZ0019EJ0300 Feb 28 2015 Get PHY ability RENESAS same as get_phy_mode 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 _ADRO_EC LAN1 PHY address for R IN32M3 EC define PHY_ADR1_EC LAN PHY address for R IN32M3 EC define PHY_ADRO_CL LAN1 PHY address for R IN32M3 CL define PHY_ADR1_CL LAN 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 tra
4. 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 R18UZ0019EJ0300 tENESAS Page 1 of 168 Feb 28 2015 R IN32M3 Series 1 Overview 1 3 Development environment The development environment of TCP IP protocol stack is described here 1 3 1 Development tools Development tools is showed in Table 1 2 Table 1 2 Development tools Tool Chain IDE Compiler Debugger ICE ARM RealView Developer Suite microVIEW PLUS adviceLUNA 2 03 00 V4 1 Ver 5 11PL3 Yokogawa Digital ARM Yokogawa Digital Computer Corporation Computer Corporation GNU Sourcery G Lite microVIEW PLUS adviceLUNA 2 03 00 2012 09 63 Ver 5 11PL3 Yokogawa Digital Mentor Graphics Yokogawa Digital Computer Corporation Computer Corporation IAR Embedded Embedded Workbench for Embedded Workbench for i Jet Workbench for ARM ARM V6 60 1 ARM V6 60 1 JTAGjet Trace CM V6 60 1 IAR Systems IAR Systems IAR Systems 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 RENESAS Page 2 of 168 R IN32M3 Series 1 Overview 1 3 3
5. R18UZ0019EJ0300 RENESAS Page 136 of 168 Feb 28 2015 R IN32M3 Series 6 Network application 6 3 2 HTTP server sample Definition of content const char index_html lt html gt lt title gt uNet3 HTTP Server lt title gt lt body gt lt h1 gt Hello World lt h1 gt lt body gt lt html gt Initialization of content list T_HTTP_FILE const content_list text html index_html sizeof index_html NULL NULL NULL 0 NULL terminal E Starting HTTP session static T_HTTP_SERVER http_serverl void httpd_tsk1 VP_INT exinf Tnitialize the content list global pointer gHTTP_FILE T_HTTP_FILE content_list memset char amp http_server1 0 sizeof http_server1 http_serverl SocketID ID_SOC_HTTPI1 http_server amp http_server1 R18UZ0019EJ0300 RENESAS Page 137 of 168 Feb 28 2015 R IN32M3 Series 6 Network application 6 4 DNS client In DNS client use UDP socket UDP socket will be created by the below parameter ID protocol timeout receive ID_SOC_DNS 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 socid UDP socket ID UW dns_server IP address of DNS server char name Host name UW ipaddr IP address to acquire Return value ER ercd Successful completion E_OK or error code Erro
6. 8 T_HTTP_SERVER HTTP Server control information typedef struct t_http_server UW sbufsz UW rbufsz UW txlen UW rxlen UW rdlen UW len UB rbuf UB sbuf UB req UH Port UH SocketlD T_HTTP_HEADER _ hdr UB NetChannel UB ver TLHTTP_SERVER URL Content type Content Content size HTTP callback function or CGI handler 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 RENESAS Page 160 of 168 Feb 28 2015 R IN32M3 Series 9 T RCV_PKT_INF Reception packet information typedef struct t_rcv_pkt_inf UW UW UH UH UB UB UB UB src_ipa dst_ipa src_port dst_port ttl tos ver num T_LRCV_PKT_INF 10 T_DHCP_CLIENT DHCP Client information Source IP address of packet Destination IP address of packet Source port number of packet p p p p 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 typedef struct t_dhcp_client T_DHCP_CTL 11 T_PING_CLIENT Ping Client Information UW UW UW UW UW
7. R IN32M3 Series 3 Overview functions of R IN32M3 TCP IP stack 5 Retransmission timeout Timer sequence of resending is described in the diagram as below Host 1 Host 2 Host 1 Host 2 RIT calculation RTO 3s RTO 6s RTO 0 5 s RTO 12s RTO Is RTO 2s RTO 60s A SYN retransmission B DATA retransmission 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 a 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 5 of Time that packet makes round trip to the that s 500 milliseconds RTO scope is set from DEF_TCP_RTO_MIN 500 ms to DEF_TCP_RTO_MAX 60 s R18UZ0019EJ0300 RENESAS Page 21 of 168 Feb 28 2015 R IN32M3 Series 3 Overview functions of R IN32M3 TCP IP stack 6 Connection timeout Connection timer sequence is described in the below diagram Host 1 Host 2 Host 1 Host 2 SYN Timer ON consocO Timer ON 75 s 2
8. 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 pNet3 TCP IP hierarchical model R IN32M3 TCP IP stack hierarchical model FTP DHCP DNS Application layer API Transport layer TCP UDP e 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 RENESAS Page 4 of 168 Feb 28 2015 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
9. Get PHY ability Parameter UW mode Speed and duplex UB nego Auto negotiation enabled disabled UB link Link up down Return value ER E_OK Finished Explanation This function is called from Ethernet driver when get_phy_mode function is executed Speed and duplex has the value referred from Table 3 2 This value is different from Ethernet driver API set_phy_mode parameter speed and duplex R18UZ0019EJ0300 RENESAS Page 58 of 168 Feb 28 2015 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 argument in set_flg id ptn has specified event flag ID when PHY driver starts The event bit pattern oF 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 RENESAS Page 59 of 168 Feb 28 2015 R IN32M3 Series 4 Network configuration It s explained to configure TCP IP protocol stack in this chapter 4 1 Configuration of TCP IP stack for R IN32M3 4 Network configuration 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 The following is configurable parameter list The app
10. PLO3B cno gt Fig 7 1 Physical port connection for sample application R18UZ0019EJ0300 RENESAS Page 153 of 168 Feb 28 2015 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 JERITAN ENAIRE RES RARRESRERERERARRARR ERLE Define Local IP Address MEALERERAREEAR AERA ERERAEAREREA ERE E ANE RENEE RS T_NET_ADR gNET_ADRI 0x0 Reserved 0x0 Reserved 0xC0A80164 IP address 192 168 1 100 0xC0A80101 Gateway 192 168 1 1 OxFFFFFFOO 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 RENESAS Page 154 of 168 Feb 28 2015 R IN32M3 Series 7 Tutorial by sample application
11. 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 RENESAS Page 85 of 168 Feb 28 2015 R IN32M3 Series 5 Description of application programming interface rcv_soc Data reception Format ER ercd rcv_soc UH sid VP data UH len Parameter UH sid ID is used to identify socket VP data Pointer to receipt data UH len Receipt data size Return value ER ercd Actual received data size gt 0 or error code Error code E_ID Wrong ID number E_NOEXS Socket does not exist socket has not been created yet E_PAR Wrong receipt data or receipt data size is not specified E_OBJ Socket status is wrong E_TMOUT Receipt process timed out E_WBLK Processed by non blocking mode E_CLS Forced termination of the connection from remote host E_RLWAI Reception process is interrupted E_QOVR rcv_soc is executing already 0 The connection is disconnected Explanation This API receive data which is sent from remote host In case of TCP the maximum receiv
12. dhcp_bind T_DHCP_CLIENT dhcp Parameter T_DHCP_CLIENT dhcp DHCP Client Information Return Value ER ercd Success E_OK or Error Code Error Code E_PAR DHCP is NULL E OBJ Incorrect Socket status No create the socket E_ SYS Address conflict another host when the IP address is assigned E_TMOUT 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 ENESAS Page 141 of 168 Feb 28 2015 R IN32M3 Series 6 Network application dhcp_renew Renewal DHCP Lease API ER ercd dhcp_renew T_DHCP_CLIENT dhcp Parameter T_DHCP_CLIENT dhcp DHCP Client Information Return Value ER ercd Success E_OK or Error Code Error Code E_PAR DHCP is NULL E OBJ Incorrect DHCP client or request denied by DHCP server E SYS Address conflict another host when the IP address is assigned E_TMOUT 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 cli
13. include sys socket h int socket int domain int type int protocol Parameter int domain Domain int type Communication type int protocol Protocol Return value int Generated socket FD On error 1 errno ENOMEM Over the generation possible number of sockets Message buffer is depleted EINVAL Parameter is incorrect Explanation e The domain can be specified only AF_INET or AF_INET6 e The communication type can be specified only SOCK_STREAM or SOCK_DGRAM e Protocol parameter is not used so any value is possible e 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 e The number of TCP sockets that can be generated at the same time is the value defined by define CFG_NET_ TCP _MAX e 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 RENESAS Page 90 of 168 Feb 28 2015 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 Socket FD const struct sockaddr addr Local address unsigned int addrlen Local address length Return value int Result of process If success O or on error 1 e
14. 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 ofuNe3 the task calling the rev_soc function in Blocking mode is placed in the waiting st
15. 6 5 1 DHCP Client Extended API ooo ida OE a a ana IE AEn Er aa Ee SE EEE Iria 141 6 5 2 DHCP Client information Extended s ssseeeseeessseeessseeesesrsresreseesrssrerrsertsserrrnertretrstenteseerrssenrrsrerreerestt 145 6 6 Ping CHEN isc occ ate saci aici shision in ok Se a as 146 6 6 1 Pine Chent ARV ss ish Ao decis 146 6 7 SN TP Elli Rees nates nana ee ee oe selon ahaa amends 148 6 7 1 SNTP Chent API 42035 lorie Sista Shiga ict Bhs ae Reels Shi Si r 148 6 8 String EADEARY soe so eee eo eraan nes tela Ghee obi EEEE EE Ee E EE E E OEE E ugh ub EEA E E EA sees 150 7 Tutorial by sample appheatiOns iirinn niie eNEAN a ia EENE AN EEA EAN EEN 153 7 1 Descriptions of sample softwafe oooooocnocncononononononnnonnnnnnnnnnnnnnc EA E nono conoce nn nono IT OEE IS eRT E EEEE IST SE 153 7 2 Hardware COMMECON vomita ide ode oes diia dica 153 7 3 Board IP address setuni zr sre aa n EE a TRE Ea E EEEa SE IREE En e anae 154 7 3 1 Setting for u e a fixed IP address cis ccccscscsesssessehssepesyass sevvstsscecopesecesbetsnep eero ninio sra stpusedvabevsbepcueesuatebees 154 7 3 2 Setting for use DHCP function db 156 Contents 3 7 4 Demonstration 157 7 4 1 MC 157 8 Appa nra ti tei ein ie ie a et eine Set 158 8 1 Packet format uti ia lots 158 8 2 Constant and Mactopia rasa 163 8 3 Error Code Distinciones 165 8 4 APICES E E EEE EE E EEE EEE E EE E EE EEEE E OEE EEEE 166 8 5 Resource list lt R gt seei eri e e arri TE E a E EEEE ror EE EE E EE rE
16. E_OK or error code Error code lt 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 RENESAS Page 71 of 168 Feb 28 2015 R IN32M3 Series 5 Description of application programming interface net_dev_sts Acquire the status of network device Format ER ercd net_dev_sts UH dev_num UH opt VP val Parameter UH dev_num Device number UH opt Status code VP val Getting value Return value ER ercd Successful completion E_OK or error code Error code lt 0 Failure 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 RENESAS Page 72 of 168 Feb 28 2015 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 d
17. Feb 28 2015 RENESAS Page 79 of 168 R IN32M3 Series 5 Description of application programming interface Parameter code Data type Meaning SOC_TMO_CON TMO Calling timeout of con_soc SOC_TMO_CLS TMO Calling timeout of cls_soc SOC_TMO_SND TMO Calling timeout of snd_soc SOC_TMO_RCV TMO Calling timeout of rev_soc SOC_IP_TTL UB Set TTL of IP header Time to Live SOC_IP_TOS UB Set TOS of IP header Type of Server SOC_CBK_HND Pointer for function Register callback function SOC_CBK_FLG UH Set bit pattern of callback event flag Value to set is as below SOC_PRT_LOCAL UH Change Local Port Number Callback event flag bit Meaning EV_SOC_CON Set con_soc in non blocking mode only TCP socket EV_SOC_CLS Set cls_soc in non blocking mode only TCP socket EV_SOC_SND Set snd_soc in non blocking mode EV_SOC_RCV Set rcv_soc in non blocking mode 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_CONIEV_SOC_SNDIEV_SOC_RCVIEV_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 RENESAS Page 80 of 168 Feb 28 2015 R IN32M3 Series 5 Descrip
18. Operation Exit PHY driver Parameter void Return value ER E_OK Others Explanation 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 RENESAS 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 mode Speed duplex UB nego Auto negotiation enabled TRUE disabled FALSE Return value ER E_OK Finished Explanation This function is called from Ethernet driver when set_phy_mode function is executed Speed and duplex has the value referred from Table 3 2 This value is different from Ethernet driver API set_phy_mode parameter speed and duplex Default value is PHY_AUTO_ABILITY when PHY driver has been initialized Table 3 2 PHY ability setting PHY_10T_HD 10M Half duplex PHY_10T_FD 10M Full duplex PHY_100TX_HD 100M Half duplex PHY_100TX_FD 100M Full duplex PHY_1000T_HD 1G Half duplex PHY_1000T_FD 1G Full duplex PHY_AUTO_ABILITY Auto selected R18UZ0019EJ0300 RENESAS Page 57 of 168 Feb 28 2015 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
19. eee ceeceesseceseeeesseeeececsaceeeaeecaeceeneecsaeeeeaeecsaeeeenees 32 3 3 Memory Management siii ar da iio 33 3 3 1 NetWork DU ici 34 3 3 2 API network bullet nse melt levee eetides eee tie E aeons 36 3 4 Memory processing IV Oraison e acia e Toi EE aoda EAER E e addons 37 3 4 1 Memory processing Il Oreiro baii e 37 3 5 Ethernet device driver ER gt ini dais 39 3 5 1 Ethernet device driver Structure esccesececsseceereecssecesceecaeceeeeecsaeceneecsaecesneecsaeceneecaaeceeneecsaeceeeeesnaeeesnees 39 3 5 2 Ethernet device driver AP ita 40 3 5 3 Contigua 52 3 5 4 Cautions regarding Ethernet device Ariver e ee seecceescecsseceeececsseceencecsacceeacecsaeeeeneecsaeceeaeecsaeeeeneecsaeeesnees 53 3 6 PHY drivers A NN 54 3 6 1 PHY driver APh esensina A A a ie 55 3 6 2 Like vent NOUMCALION tii 59 Network ConfiguratiON tota ida 60 4 1 Configuration of TCP IP stack for R IN32M3 oooococnccncccocnconnconoconocnocnnocononnocnnccnnonnnonnncnnn ron cnn nnnnnnnn canon necnnecnnos 60 4 1 1 Configuration stiutinai R N 60 4 1 2 TO 62 4 1 3 DAA NN 62 4 1 4 Information table of protocol Stack eee eee cee csecseeeeeeeeeseeeescesecesecsecsaecsaecsaecaeecseseaeseeeeeeeseeeseenseenaes 62 Description of application programming interface 00 ee eeeeeee eset ee eeeeeeeeeeeeeeeteaeeeeesaeeeeeseeeeeeseneeeeeseeaaeees 63 5 1 Initialization Of protocol stack ooooococoncnoncnocononononcnnnnnnnnannnnnonnnc nooo nono nc cn nono non neon recono nn non
20. ftp_server amp ftpd ext_tsk 6 2 2 Restriction terms O Supported command includes login put get quit Do not support file system Therefore impossible to create directory structure and handle multiple files R18UZ0019EJ0300 RENESAS Page 129 of 168 Feb 28 2015 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 URL const char ctype Content type const char file Content Int len Content size HTTP callback function void cbk T_HTTP_SERVER http or CGI handler T_HTTP_FILE Register content to be used in HTTP server in this structure e 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 e Content type Specify Content Type of text html etc In case of dynamic content specify NULL e Content Specify actual content In case of dynamic content specify NULL e Content size Specify size of content In case of dynamic content specify 0 e 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 RENESAS Page 130 of 1
21. struct in_addr inp Parameter const char cp The dot notation IP address struct in_addr inp Buffer to store IP address binary value after conversion network byte order Return value int Result of process If success O or on error 1 errno Not set Explanation e If the fail to convert happen the return value is set to 1 R18UZ0019EJ0300 RENESAS Page 108 of 168 Feb 28 2015 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 IP address binary value network byte order Return value Int The dot notation IP address after conversion errno Not set Explanation e Ifthe fail to convert happen the return value is set to 0 e fuser 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 RENESAS Page 109 of 168 Feb 28 2015 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 Interface inde
22. typedef struct t_node UH port Port number of socket IP version UB ver Necessarily specify IP_VER4 UB num Device number UW ipa IP address T_NODE 2 T_NET_ADR Information of network address typedef struct t_net_adr IP Version UB ver Necessarily specify IP_VER4 UB mode Reserve UW ipaddr IP Address UW gateway Gateway UW mask Subnet mask T_NET_ADR 3 T_NET_DEV The information of the network device typedef struct t_net_dev UB name 8 Device name UH num Device number UH type Device type UH sts Reserve UH flg Reserve FP ini Pointer to dev_ini function FP cls Pointer to dev_cls function FP ctl Pointer to dev_ctl function FP ref Pointer to dev_ref function FP out Pointer to dev_snd function FP cbk Pointer to dev_cbk function UW tag Reserve union MAC address struct UB mac 6 R18UZ0019EJ0300 RENESAS Page 158 of 168 Feb 28 2015 R IN32M3 Series seth cfg UH UH hhdrsz hhdrofs T_NET_DEV 4 T NET BU F Information of network buffer lt R gt typedef struct t_net_buf T_NET_BUF UW ID T_NET next mpfid net T_NET_DEV dev T_NET_SOC soc ER UH UH UH UH UB UB UB 5 T_HOST_ADDR ercd flg seq dat_len hdr_len dat hdr buff Information of host address typedef str
23. Connect to the socket Format include sys socket h int connect int sockfd const struct sockaddr addr unsigned int addrlen Parameter int sockfd Socket FD const struct sockaddr addr Remote address unsigned int addrlen Remote address length Return value int Result of process If success O or on error 1 errno EINVAL Parameter is incorrect ENOMEM Message buffer is depleted EBADF Socked FD cannot be connected ECONNREFUSED The connection was refused EAFNOSUPPORT Unsupported address family EISCONN Already connected Socket is under listen EALREADY Already connected EAGAIN The socket is under connection During asynchronous execution ETIMEDOUT Timeout if the timeout is set Explanation e The behavior or operation for connect is different by the socket FD protocol or send receive operation e In the case of the connection of TCP socket SYN is sent to the remote address and try to do communication e 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 e Ifyou a remote address family sa_family are specified to AF_UNSPEC these settings will be cleared e Unlike the POSIX specification there is no filtering function by remote address for the receiving operation of the UDP socket e Unlike the POSIX specification in the connect for TCP
24. 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 amp link after application program is created The relationship among files is showed at Fig 1 1 HITRON header file TCP IP stack header file Files created or modified by user Files modified by user if it is needed Samples are ready OS configuration file TCP IP stack configuration file Application program file 5 Compile i i Object files a i z HW RTOS driver TCP IP stack library o library file file Link information file Makefile or IDE Link 1 J l ama PPP NE Ea Files created by user A eS Files produced by Renesas Electronics Fig 1 1 The figure of relationship among files R18UZ0019EJ0300 RENESAS Page 3 of 168 Feb 28 2015 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
25. FTP server application Socket used for command ID Protocol Timeout receive connect interrupt receive ID_SOC_FTP_CTL TCP 1s 5s 1024 Socket used for data Protocol Timeout Buffer size receive connect interrupt receive e 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 RENESAS Page 128 of 168 Feb 28 2015 R IN32M3 Series 6 Network application 6 2 1 FTP Server API ftp_server Start up FTP Server Format ER ercd ftp_server T_FTP_SERVER ftp Parameter T_FTP_SERVER ftp FTP server control information Return value ER ercd Successful completion E_OK or error code Error code E_PAR 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 fipd UB ftp_buf 1024 FTP server task void FtpServerTask VP_INT exinf memset char amp ftpd 0 sizeof ftpd ftpd ctl_socid ID_SOC_FTP_CTL ftpd data_socid ID_SOC_FTP_DATA ftod fs_file ftp_buf ftpd fs_maxsz 1024
26. 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 2 Basic concepts of R IN32M3 TCP IP stack DHCP client extended version macro prototype definition etc DHCP extended version client source code RENESAS Page 12 of 168 R IN32M3 Series 2 Basic concepts of R IN32M3 TCP IP stack 5 Sample source file Source Project uNet3_sample cgi_sample c CGI application sample html h HTML data kernel_cfg c OS resources configuration file kernel_id h OS resources ID definition file main c Main function net_cfg c TCP IP stack configuration file net_sample c Network application sample R18UZ0019EJ0300 RENESAS Page 13 of 168 Feb 28 2015 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
27. MSS TCP IPv4 MTU IP header TCP header CFG_TCP_MSS 1460 MSS TCP IPv6 MTU IP header TCP header CFG_TCP_MSS_IPV6 1440 TCP RTO retry timeout initial value ms CFG_TCP_RTO_INI 3000 2000 3000 TCP RTO retry timeout minimum value ms CFG_TCP_RTO_MIN 500 200 500 TCP RTO retry timeout maximum value ms CFG_TCP_RTO_MAX 60000 30000 60000 TCP transmission buffer size Byte CFG_TCP_SND_WND 1024 1024 8192 TCP reception buffer size Byte CFG_TCP_RCV_WND 1024 1024 8192 Duplicate ACK number of retry beginning reception CFG_TCP_DUP_CNT 4 1 10 count TCP SYN transmission timeout ms CFG_TCP_CON_TMO 75000 10000 75000 R18UZ0019EJ0300 Feb 28 2015 RENESAS Page 60 of 168 R IN32M3 Series 4 Network configuration TCP data transmission timeout ms CFG_TCP_SND_TMO 64000 10000 64000 TCP FIN transmission timeout ms CFG_TCP_CLS_TMO 75000 10000 75000 TCP 2MSL timeout ms CFG_TCP_CLW_TMO 20000 0 20000 TCP delay ACK transmission period ms CFG_TCP_ACK_TMO 200 100 1000 TCP Keep Alive notification count in case of 0 Keep Alive is disabled CFG_TCP_KPA_CNT 100 TCP Keep Alive notification period ms CFG_TCP_KPA_INT 1000 60000 Non communication time until TCP Keep Alive starts ms CFG_TCP_KPA_TMO 7200000 14400000 The queuing number of reception packet CFG_PKT_RCV_QUE 10 Waiting time ARP PROBE packet transmission ms CFG_ARP_PRB_WA
28. Size of buffer to store the value got Return value int Result of process If success 0 or on error 1 errno EINVAL Parameter is incorrect ENOMEM Message buffer is depleted EBADF Socked FD cannot be done getsockopt EPROTONOSUPPOR Unsupported option T Explanation e 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 RENESAS Page 104 of 168 Feb 28 2015 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 sockfd Socket FD int level Option level int optname Option name const void optval Buffer for the value to set unsigned int optlen Size of buffer for the value to set Return value int Result of process If success 0 or on error 1 errno EINVAL Parameter is incorrect ENOMEM Message buffer is depleted EBADF Socked FD cannot be done setsockopt EPROTONOSUPPOR Unsupported option T Explanation e The option level can be specified only SOL_SOCKET IPPROTO_IP or IPPROTO_TCP e The option name that user can get for each option level please refer to 5 5 5Socket option R18UZ0019EJ0300 RENESAS Page 105 of 168 Feb 28 2015 R IN32M3 Series 5 Description of applicatio
29. T_NODE remote ref soc ID SOC_IP_REMOTE VP amp remote Parameter code Data type Meaning SOC_TMO_CON TMO Calling timeout of con_soc SOC_TMO_CLS TMO Calling timeout of cls_soc SOC_TMO_SND TMO Calling timeout of snd_soc SOC_TMO_RCV TMO Calling timeout of rev_soc SOC_IP_LOCAL T_NODE Getting Port number and IP address of local host SOC_IP_REMOTE T_NODE Getting port number and IP address of remote host SOC_IP_TTL UB Getting TTL Time to Live SOC_IP_TOS UB Getting TOS Type Of Service SOC_RCV_PKT_INF T_RCV_PKT_INF Getting newest information of packet received by socket in case of TCP it s unable to get SOC_PRT_LOCAL UH 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 amp rcev_pkt_inf if rcv_pkt_inf dst_ipa MULTICASTADDRESS received by multicast address R18UZ0019EJ0300 Feb 28 2015 RENESAS Page 83 of 168 R IN32M3 Series 5 Description of application programming interface abt_soc Abort the socket process Format ER ercd abt_soc UH sid UB code Parameter UH sid ID is used to identify socket UB code Control code Return value ER ercd Successful completion E_OK or error code Error code E_ID Wron
30. UW UW UW UB UB UB UH UB T_LDHCP_CLIENT ctl ipaddr subnet gateway dhcp dns 2 lease t1 t2 mac 6 dev_num state socid arpchk typedef struct t_ping_client ID UW TMO UH UH sid ipa tmo devnum len T_PING_CLIENT R18UZ0019EJ0300 Feb 28 2015 3 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 RENESAS 8 Appendix Page 161 of 168 R IN32M3 Series 8 Appendix 12 T_SNTP_CLIENT SNTP Client Information typedef struct t_sntp_client ID sid UDP Socket ID UW ipa NTP server IP address TMO tmo Response Time out UH devnum Device numbr UH port NTP server port number UB ipv IP vrsion T_SNTP_CLIENT R18UZ0019EJ0300 RENESAS Page 162 of 168 Feb 28 2015 R IN32M3 Series 8 Appendix 8 2 Constant and Macro 1 IP Address ADDR_ANY IP address 0 IP_VER4 IP version 4 2 Port Number PORT_ANY Port number 0 3 IP protocol IP_PROTO_TCP TCP protocol IP_PROTO_UDP UDP protocol IP_PROTO_ICMP ICMP protocol 4 N
31. Y 75 s Timer OFF y E_TMOUT Timeout A TCP connection success B TCP connection timeout Fig 3 6 An example of connection timeout When call con_soc if this timer completes from starting up to three way handshake timed out it will return E_OK 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 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 X 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 RENESAS Page 22 of 168 Feb 28 2015 R IN32M3 Series 3 Overview functions of R IN32M3 TCP IP stack 10 TCP cong
32. 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 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 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
33. 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 RENESAS Page 18 of 168 R IN32M3 Series 3 Overview functions of R IN32M3 TCP IP stack Create Socket Unused a Connection error con_soc SOC_CLI con_soc SOC_SER Waiting for passive open Waiting for active open con_soc completion Connection is established Possible to transceive data by Establish connection con_soc snd_soc rcv_soc SOC_TCP_SHT Di ti E con_soc Interrupt connection or isconnect transmission SOC TCP CLS nished c nnectisn al con_soc y SOC_TCP_CLS While disconnectin a 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
34. 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 RENESAS Page 68 of 168 Feb 28 2015 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 1Use 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_ ni ID_ DEVNUM_ETHER if ercd E_OK return ercd Detect IP Address Conflict ercd net_acd ID_DEVNUM_ETHER amp 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 RENESAS Page 69 of 168 Feb 28 2015 R IN32M3 Series 5 Description of application prog
35. 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 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 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 et
36. procedure tira 3 Basic concepts of R IN32M3 TCP IP Sta k a iee eaaa inea anaana aaaeeeaa carr cra 4 2 1 Glossaries A eee ease 4 2 1 1 Protocol araoa A Ta ous ce E E E E E aid 4 2 1 2 Protocol stacki ara a E E E ee ET DE edn E E aaa E EA 4 2 1 3 A UN 5 2 1 4 MAC Media Access Control address cccccssseceessececsecececenscecessaeeecsesececseeeecessaececseaaececseaeeeessaesecsenaeess 5 2 1 5 POrt MUM Den 5 ess A di diia 5 2 1 6 Big endian and little endian eee ee ceeecesecese esse ceecseeeseseaeseeeeseeeeeeesecsecsaecsaecsaecaaecsaeeaeseaeseeeseeeeereeatens 5 2 1 7 Pack e A tada 5 2 1 8 HGStad NOME dit dls 3 2 1 9 Address Resolution Protocol ARP sesira nere a E E O E E E 6 2 1 10 Internet Protocol IP ia E E E R ee Mei ee eka aloe dk oh lc a ie ee 6 2 1 11 Internet Control Message Protocol ICMP cesscssscecsseceeececeseeeseeeceaeeeeeeecsaeeesaeeceaeeeeeeeceaeeeeaeecaeeeeaeeees 6 2 1 12 Internet Group Management Protocol IGMP oooconncccocccocononcnnnconcnonononcnnnonnnconoco nono nono nono conocio nn ncnn crac crnnnnnnons 6 2 1 13 User Datasram Protocol UDP kiireen eii ea eee ii a eovousleusteaipas guvecndheedinnesdevetss 6 2 1 14 Transmission Control Protocol TCP cccccecssssecesssececseseececessceceeaececseseeecsnceecsssaeeecseaaececeussecesaeeeesenaeees 6 2 1 15 Dynamic Host Configuration Protocol DHCP 0 00 eecceeceseceseceeesecesecesecaecsaecsaecaeecaeseaeseaeeeeeeeens 6 2 1 16 Hyper Text
37. process is interrupted E_QOVR cls_soc is executing already cls_flg 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 RENESAS Page 78 of 168 Feb 28 2015 R IN32M3 Series 5 Description of application programming interface cfg_soc Set parameter of socket Format ER ercd cfg_soc UH sid UB code VP val Parameter UH sid ID is used to identify socket UB code Parameter code VP val Value to set Return value ER ercd Successful completion E_OK or error code Error code EID Wrong ID number E_NOEXS Socket does not exist Socket has not been created yet E_NOSPT Wrong parameter code E_PAR Wrong parameter value E_OBJ 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
38. set DHCP_ENA to 1 the sample project might not be able to compile because of size limitation R18UZ0019EJ0300 RENESAS Page 156 of 168 Feb 28 2015 R IN32M3 Series 7 Tutorial by sample application 7 4 Demonstration 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 MAR 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 Tf the board is running the project above you should see a webpage from the R IN32M3 like Fig 7 3 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 3 192 168 1100 77 S EA nc E Most Visited o Getting Started LED Blinker in 100 msec 10 Interval Ping Request Remote Address IPv4 192 168 1 1 Network Time SNTP Server IPv4 133 243 238 243 Resolver gt DNS Server IPv4 8 8 4 4 Fig 7 3 The result of sample application HTTP server R18UZ0019EJ0300 RENESAS Page 157 of 168 Feb 28 2015 R IN32M3 Series 8 Appendix 8 Appendix 8 1 Packet format 1 T_NODE Information of communication endpoint
39. 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 lt 0 rcv_soc process completes normally Regarding error content of this time please refer to error code of rcv_soc X 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 RENESAS Page 81 of 168 Feb 28 2015 R IN32M3 Series 5 Description of application programming interface ref_soc Refer parameter of socket Format ER ercd ref_soc UH sid UB code VP val Parameter UH sid ID is used to identify socket UB code Parameter code VP val Pointer for buffer of the value to get Return value ER ercd Successful completion E_OK or error code Error code EID Wrong ID number E_NOEXS Socket does not exist socket has not been created yet E_NOSPT Wrong parameter code E_PAR Wrong parameter value in case that val is NULL E_OBJ Socket status is wrong Cannot refer to socket R18UZ0019EJ0300 RENESAS Page 82 of 168 Feb 28 2015 R IN32M3 Series Explanation 5 Description of application programming interface Refer the parameters as below Please cast and then hand the setting value to VP type Example of getting remote host information
40. 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 RENESAS Page 94 of 168 Feb 28 2015 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 socktd Socket FD const void buf Address for sending data unsigned int len Length for sending data int flags Flag Return value int Byte number which is sent On error 1 errno EINVAL Parameter is incorrect ENOMEM Message buffer is depleted Cannot get the network buffer corresponding to len EBADF Socked FD cannot be sent EDESTADDRREQ Unsetting the address UDP socket ENOTCONN Not be connected TCP socket EAGAIN The socket is under sending During asynchronous execution ETIMEDOUT Timeout if the timeout is set Explanation e The length for sending data can be specified the value from 1 to 65535 e The flag is not used so any value is possible e The sending 0 byte UDP data cannot be sent unlike the POSIX specification R18UZ0019EJ0300 RENESAS Page 95 of 168 Feb 28 2015 R IN32M3 Series 5 Description of a
41. str1 const char str2 Parameter const char stri String to be compared const char str2 String to be compared Return Value W 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 gt str2 and is negative if strl lt str2 Reach the end of the string until one of them to be compared R18UZ0019EJ0300 RENESAS Page 150 of 168 Feb 28 2015 R IN32M3 Series 6 Network application net_strcpy String Copy API char net_strcpy char str1 const char str2 Parameter char stri Address of copy destination string const char str2 Address of copy source string Return Value char stri Address of copy destination string DESCRIPTION This API is to copy of the srt2 to the end of str NULL net_strlen Get String Length API UW net_strlen const char str Parameter char str String Return Value UW String length DESCRIPTION Gets the number of characters up to NULL end of str NULL is not included _netstrcat _______ Stringconcatenation API char net_strcat char str1 const char str2 Parameter char str1 Address of destination string const char str2 Address of source string Return Value char stri Address of destination string DESCRIPTION Copy to the end of the str2 starting at NULL coupling the end of the destination string str1 R18UZ0019EJ0300 RENES
42. 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 RENESAS Page 8 of 168 Feb 28 2015 R IN32M3 Series 2 Basic concepts of R IN32M3 TCP IP stack 2 2 Architecture of Network system
43. transmission data is set 1472 bytes DEF_PATH_MTU 1500 bytes size IP header 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 RENESAS Page 17 of 168 R IN32M3 Series 2 Data reception 3 Overview functions of R IN32M3 TCP IP stack Data reception is executed by using rcv_soc The flow of rcv_soc processing is described in the diagram as below rev_soc Is UDP packet is enable Receive UDP packet application buffer L Return Copy UDP packet into Wait UDP packet Timeout 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 Ifreceived 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
44. unsigned int len int flags Parameter int sockfd Socket FD void buf Address for receiving buffer unsigned int len Length for receiving buffer int flags Flag Return value int Byte number which is received included 0 On error 1 errno EINVAL Parameter is incorrect ENOMEM Message buffer is depleted Cannot get the network buffer corresponding to len EBADF Socked FD cannot be received ENOTCONN Not be connected TCP socket EAGAIN The packet had not received yet During asynchronous execution ETIMEDOUT 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 RENESAS Page 97 of 168 Feb 28 2015 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_adadr unsigned int addrlen Parameter int socktd Socket FD void buf Address for receiving buffer unsigned int len Length for receiving buffer int flags Flag struct sockaddr sr
45. 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 IGMPvl message it will be back to IGMPv2 mode Timeout for returning from IGMPv 1 to IGMPy 2 is set by DEF_IGMP_V1_TMO 400 seconds 9 ICMP R IN32M3 TCP IP sta
46. 32 of 168 Feb 28 2015 R IN32M3 Series 6 Network application CgiGetParam CGI argument analysis Format void CgiGetParam char msg int clen char cgi_var char cgi_val int cgi_cnt Parameter char msg CGI argument int clen CGI argument size char cgi_var Analysed CGI argument char cgi_vall Value of analysed CGI argument int cgi_cnt 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 givenas namel valuel amp name2 value2 as below cgi_cnt 2 cgi_var 0 namel cgi_var 1 name2 cgi_val 0 valuel cgi_val 1 value2 R18UZ0019EJ0300 RENESAS Page 133 of 168 Feb 28 2015 R IN32M3 Series 6 Network application HttpSendText Transmission of text content Format ER ercd HttpSendText T_HTTP_SERVER http char str int len Parameter char http HTTP server control information int str String to transmit int len length of string to transmit Return value ER ercd Successful completion only E_OK Error code None Explanation This API transmits dynamic content Please call this API only from HTTP callback function Example char page1 lt html gt lt body gt Welcome to this web server lt body gt lt html gt void Http_Callback T_H
47. 68 Feb 28 2015 R IN32M3 Series 6 Network application 2 HTTP server control information typedef struct t_http_server UB UH UH UW UW UB UB UB UW UW UW UW T_HTTP_HEADER TLHTTP_SERVER NetChannel Port SocketID sbufsz rbufsz rbuf sbuf req txlen rxlen rdlen len har Device number Listening port number 1D 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 e 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 e 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 protocol port timeout Buffer size send receive connect interrupt send receive ID_SOC_HTTP TCP 80 25s 25s 25s 25s 1024 1024 e 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 b
48. AS Page 151 of 168 Feb 28 2015 R IN32M3 Series 6 Network application net_strchr Search Character API char net_strchr const char str int ch Parameter const char str Search target character Int ch Search character Return Value char str In the subject string address search string appears If the search string does not appear NULL R18UZ0019EJ0300 RENESAS Page 152 of 168 Feb 28 2015 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 e Web server LED flashing period can be changed by 100 msec unit from the Web browser Please refer to 2 3 Directory and file organization for a list of files included in sample software And please note that 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 O please use the R IN32 EC board s RJ45 PORT1 See following figure General USB USB port mini B cable Special USB cable enclosed in l jet package IAR ARM l jet In Circuit Emulator ICE AC DC adapter put AC 100 240V x Output DC 5V 3A R IN32M3EC Board DC jack form
49. C 0 A 0 lt v ENESAS 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 R18UZ0019EJO300 Issue date Feb 28 2015 R RM Renesas Electronics www renesas com Notice 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 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 Renesas Electronics does not assume any liability for infringement of patents copyrights or other intellectual property rights of third parties by
50. EJ R IN32M3 CL User s Manual R18UZ0005EJ R IN32M3 Series User s Manual Peripheral function R18UZ0007EJ R IN32M3 Series Programming Manual Driver edition R18UZ0009EJ R IN32M3 Series Programming Manual OS edition R18UZ0011EJ R IN32M3 Series User s Manual TCP IP stack 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 1024 M mega 2 1024 G giga 2 1024 Data Type Word 32 bits Halfword 16 bits Byte 8 bits il OVA Wia dd 1 1 1 ESA sve A E AE E EAE e e a O E EA AE E E cute gucbuwesusanceys cecoubegnen suse akcet tubers 1 1 2 Key FUNCION A AE 1 1 3 Development environment 0 05 0 sssr resson etsea aei Ease aa SEE ic E ORe EREE e Eos SOS ESEE EAr ETRE ERSTE esas E ESERSE 2 1 3 1 Development tools rin pp 2 1 3 2 Evaltiatiom boards esis ne rad id A da EO NEETA 2 1 3 3 Development
51. Er EEEo ES 167 8 5 1 Kernel Objects anid ee hese e r is E 167 8 5 2 Hardware SR o ee etl 168 Contents 4 ENESAS R IN32M3 Series R18UZ0019EJ0300 User s Manual TCP IP stack 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 e IPv4 ARP ICMP IGMPv2 UDP TCP protocol e DHCP client DNS client FTP server HTTP server e TCP IP configuration e TCP fast retransmit and fast recovery e IPreconstructure and fragmentation e 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 lt R gt Function Package Commercial Edition Evaluation Edition Max socket number TCP Depends on memory size 4 4 Max socket number UDP Depends on memory size IP reassemble Multicast
52. FD cannot be shutdowned EPIPE Not be connected TCP socket Explanation e The Direction for disconnection can be specified only SHUT_WR or SHUT_RDWR R18UZ0019EJ0300 RENESAS Page 99 of 168 Feb 28 2015 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 socktd Socket FD Return value int Result of process If success 0 or on error 1 errno EINVAL Parameter is incorrect ENOMEM Message buffer is depleted EBADF Socked FD cannot be closed Explanation e If TCP socket had not disconnected yet socket will close after disconnect TCP session e The closed socket FD cannot use until generate again R18UZ0019EJ0300 RENESAS Page 100 of 168 Feb 28 2015 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 readfds Socket FD set to monitor whether readable fd_set writefds Socket FD set to monitor whether writable fd_set exceptfds Socket FD set to monitor the exception not supported struct timeval timeout Monitor timeout Return value i
53. I 3000 The number of ARP PROBE packet transmission CFG_ARP_PRB_NUM 6 ARP PROBE packet transmission period minimum ms CFG_ARP_PRB_MIN 1000 ARP PROBE packet transmission period maximum ms CFG_ARP_PRB_MAX 2000 Waiting time ARP ANNOUNCE packet ms CFG_ARP_ANC_WAI The number of ARP ANNOUNCE packet transmission CFG_ARP_ANC_NUM 2 1 4 ARP ANNOUNCE packet transmission period ms CFG_ARP_ANC_INT 2000 200 2000 Packet control flag bit pattern CFG_PKT_CTL_FLG 0 Transmit ICMP Port Unreachable bitO Ignore reception IP header checksum bit1 Ignore reception TCP header checksum bit2 Ignore reception UDP header checksum bit3 R18UZ0019EJ0300 Feb 28 2015 RENESAS 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 forDevice1 0x0 Must be 0 0x0 Must be 0 OxCOA8000A Setting IP address 192 168 1 10 0xC0A80001 Gateway 192 168 1 1 OxFFFFFFOO 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_DEVgNET_DEV Please ref
54. INT n Parameter VP d Pointer to the destination of memory VP s Pointer to the source of data UINT n Number of bytes to copy Return value VP d 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 RENESAS Page 37 of 168 Feb 28 2015 R IN32M3 Series 3 Overview functions of R IN32M3 TCP IP stack net_memcmp Compare two blocks of memory Format int net_memcmp VP d VP s UINT n Parameter VP d pointer to blocks of memory1 VP s pointer to blocks of memory2 UINT n Number of bytes to compare Return value int Comparison result Explanation Please return 0 if the same value in the specified number of bytes Otherwise please return the non zero R18UZ0019EJ0300 RENESAS Page 38 of 168 Feb 28 2015 R IN32M3 Series 3 Overview functions of R IN32M3 TCP IP stack 3 5 Ethernet device driver lt R gt 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 dri
55. NOMEM Message buffer is depleted EBADF Socked FD cannot be listened EPROTONOSUPPOR Unsupported protocol not TCP T Explanation e TCP socket becomes to the state for waiting connection e The socket FD can be specified only the socket FD of TCP e The maximum number for back log is define CFG_NET_TCP_MAX 1 R18UZ0019EJ0300 RENESAS Page 92 of 168 Feb 28 2015 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 socktd Socket FD struct sockadar addr Remote address output unsigned int addrlen Remote address length output Return value int The connected socket FD On error 1 errno EINVAL Parameter is incorrect ENOMEM Message buffer is depleted EBADF Socked FD cannot be bound EAGAIN The socket is not connected During asynchronous execution ETIMEDOUT Timeout if the timeout is set Explanation e The socket FD can be specified only the socket FD of TCP that listen function had been successful e The remote address is set as struct sockaddr_in type e If there are not any the connected socket the accept function blocks the processes until it is connected from remote R18UZ0019EJ0300 RENESAS Page 93 of 168 Feb 28 2015 R IN32M3 Series 5 Description of application programming interface 5 5 4 7 connect
56. OTO_IP level int Get socket type For Get only IP_ADD_ MEMBERSHIP IP_DROP_MEMBERSHIP IP_MTU ip_mreqn ip_mreqn 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 IP_MULTICAST_TTL TTL setting for multicast sending packet For Get or Set IP_TOS TOS setting for IP sending packet For Get or Set IP_TTL TTL setting for IP sending packet For Get or Set IPPROTO_TCP level TCP_KEEPCNT Set the number of times of TCP Keep Alive probe For Set only TCP_KEEPIDLE Set the non communication interval of TCP Keep Alive started For Set only TCP_KEEPINTVL Set the sending interval for TCP Keep Alive probe For Set only TCP_MAXSEG R18UZ0019EJ0300 Feb 28 2015 Set the MSS value of TCP socket For Get or Set RENESAS Page 115 of 168 R IN32M3 Series 5 5 6 5 5 6 1 Support function Non blocking setting 5 Description of application programming interface 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 tim
57. PI 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 R18UZ0019EJ0300 RENESAS Page 143 of 168 Feb 28 2015 R IN32M3 Series 6 Network application dhcp_release Release DHCP Lease Information API ER ercd dhcp_release T_DHCP_CLIENT dhcp Parameter T_DHCP_CLIENT dhcp DHCP CLIENT INFORMATION Return Value ER ercd Success E_OK or Error Code Error Code E PAR DHCP is NULL E OBJ Illegal DHCP client information E_TMOUT 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 o
58. P_STS_INIT dhcp_addr socid ID_SOC_DHCP dhcp_addr dev_num ID_DEVNUM_ETHER for 33 ercd dhcp _client amp 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 RENESAS Page 127 of 168 Feb 28 2015 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 Device Number UH ctl_socid 1D Socket used for Command UH data_socid 1D Socket used for data UB fs file Store buffer UW _ fs_maxsz Store buffer size y T_FTP_SERVER Set necessary information in this structure and then transfer as argument of FTP Server API e 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 e 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
59. TRUE off FALSE UB mode gt ch Target PHY channel Return value ER E_OK Success E_PAR Invalid parameter others PHY driver configuration error Explanation Application can configure PHY ability anytime The configuration of speed and duplex is selected from Table 3 1 Target PHY is configured to ETH_INT_MI_PHYO or ETH_INT_MII_PHY1 struct PHY_MODE pmod pmod mode LAN_AUTO_ABILITY pmod nego TRUE pmod ch ETH_INT_MII_PHYO set_phy_mode amp pmod Table 3 1 PHY ability setting Description LAN_10T_HD 10M Half duplex LAN_10T_ FD 10M Full duplex LAN_100TX_HD 100M Half duplex LAN_100TX_FD 100M Full duplex LAN_1000T_HD 1G Half duplex LAN_1000T_FD 1G Full duplex LAN _AUTO_ABILITY Auto select R18UZ0019EJ0300 RENESAS Page 45 of 168 Feb 28 2015 R IN32M3 Series 3 5 2 7 Get PHY ability get_ph Prototype ER get_phy_mode PHY_MODE mode Operation Get PHY ability Parameter PHY_MODE mode Return value ER E_OK E_PAR EO Ht Explanation 3 Overview functions of R IN32M3 TCP IP stack y_mode PHY ability 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_PHYO or ETH_INT_MII_PHY1 pmod ch ETH_INT
60. TTP_SERVER http HtipSendText http page1 sizeof page1 R18UZ0019EJ0300 RENESAS Page 134 of 168 Feb 28 2015 R IN32M3 Series 6 Network application HttpSendFile Send Attached File API ER HtipSendFile T_HTTP_SERVER http char str int len char name char type Parameter T_HTTP_SERVER http HTTP server information char str File to be send int len Length to be send char name Filename char type Content Type value or strings of HTTP header Return Value ER ercd Success E_OK Error Code None 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 R18UZ0019EJ0300 RENESAS Page 135 of 168 Feb 28 2015 R IN32M3 Series 6 Network application HtipSendImage Send Image Content API ER ercd HtipSendlmage T_HTTP_SERVER http char str int len Parameter T_HTTP_SERVER http HTTP server information char str Image data to be send int len Length to be send Return Value ER ercd Success E_OK Error Code None DESCRIPTION This API sends the dynamic content Please only be called from this API function callback HTTP
61. Transfer Protocol HTTP coccni onnoninnenncsnononbasolusone es nerne seren EErEE EErEE Eeen EEES EE cade 7 2 1 17 File Transter Protocol EVR 2 sscsc2d5 sca ccestncs fo cicecesousencesv aid iaa 7 2 1 18 Domain Name System DNS J eo aa steaks dacs soxtsiee dile E Oa OARE AEE nec esbesbeesnenenene 7 2 1 19 Soc NS 7 2 1 20 Blocking and non blocking sesoses setececs seeesack cube ioro ube seb cds casbicnsck VAE ROEE eo e tnbecoceadiesecbiudesecosseevscss 7 2 1 21 Callback TUCU sorore Serei dd di 7 2 1 22 Task comedias 8 2 1 23 NO 8 2 1 24 MTU e liada 8 2 1 25 IMIS Sii A 8 Contents Contents 1 4 5 2 1 26 IP reassembly gt fragments iria 8 2 2 Architecture of NetWork SyStem scsi c scees sc a aA cbduesveshi bape sii EA AAA aa a ATENa 9 2 2 1 Block diagram of network SYSteM 0 eeececessceececeseceeneeceseeesneecsuceecaeecsuceecaeecsseeseaeeceseeseneecaeeseneeceereeeneeens 9 2 3 Directory and fle OF Sani Z ata OM violencia caste conse dede did direis 11 Overview functions of R IN32M3 TCP IP Stack cee ceeeee eeeeetereeeeeeeneeeaeesaeecaesaesnaeeeaeseaeseeeeseeeseeeseeeesgs 14 3 1 Protocol stack iaa A o dle 14 3 1 1 A O ON NN 14 3 1 2 ARP Module ta ida 16 3 1 3 UDP Mol ee hea eee Hea ees ae A ae es bean sem a eb waa 16 3 1 4 PE PaO dle las 18 3 2 Network device dai 24 3 2 1 BATA ANa ER E A A iaa A T 24 3 2 2 ON 26 3 2 3 packet routine ii dd 31 3 2 4 T_NET_DEV information registration example lt R gt
62. _MII_PHYO get_phy_mode amp 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 RENESAS 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 UINT mode Filter mode Return value ER E_OK Success E_PAR Invalid parameter Explanation Filter mode has three modes showed below Value Mode MCRX_MODE_ALLOW All multicast address receive mode MCRX_MODE_DENY Denied to receive multicast address mode MCRX_MODE_FILTER 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 RENESAS Page 47 of 168 Feb 28 2015 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 adr Multicast address to receive UB adr gt mac 6 Mul
63. able 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 RENESAS Page 86 of 168 Feb 28 2015 R IN32M3 Series 5 Description of application programming interface 5 5 Socket API BSD compatible lt R gt 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 in uNet3 socket e Multiple call of socket API e select function e Loop back address e Multicast group with socket unit e Listen queue of TCP socket e 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 rep
64. ace Format include sys types h int getifaddrs struct ifaddrs ifap Parameter struct ifaddrs ifap The start address of the interface information list Return value int Result of process If success 0 or on error 1 errno ENOMEM Error as getting the stored area of intereface information Explanation e 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 e If successfully completed the following values are stored in ifap ifap gt ifa_next The pointer of the next structure of interface information is stored If the last element this field 1s NULL ifap gt name The pointer to the interface name is stored ifap gt ifa_flags The device number is stored ifap gt ifa_addr The IP address of the device is stored as the sockaddr type pointer ifap gt ifa_netmask The subnet mask of the device is stored as the sockaddr type pointer ifap gt ifa_ifu ifap gt ifa_data No use e 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 RENESAS Page 113 of 168 Feb 28 2015 R IN32M3 Series 5 Description of application programming interface 5 5 4 27 freeifaddrs Release the interface information Format include sys unistd h void freeifad
65. am 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 Touse 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 RENESAS Page 6 of 168 Feb 28 2015 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
66. andling 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 corre
67. anghai 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 Jin 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 l ENESAS Renesas Electronics Corporation
68. ates on the network And the connection points in a network such as server client hub router access point etc are called node R18UZ0019EJ0300 ENESAS Page 5 of 168 Feb 28 2015 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 The protocol which executes the communication between nodes or node and gateway is called IP IP 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 Datagr
69. ation ENXIO EBADF Interface is not existed Socket FD is invalid ENOMEM EFAULT ENODEV Out of memory Parameter error A fatal abnormality or unknown in the system EINVAL Parameter error EPIPE Socket object is invalid EAGAIN Run the blocking processing EALREADY Processing of already running EDESTADDRREQ Need a destination set EPROTONOSUPPORT EAFNOSUPPORT Function is not supported Address family is not supported EADDRINUSE Address is already in use EADDRNOTAVAIL Address is not available EISCONN Socket is already connected ENOTCONN Socket is not connected ETIMEDOUT Time out ECONNREFUSED Connection is denied R18UZ0019EJ0300 Feb 28 2015 RENESAS Page 117 of 168 R IN32M3 Series 5 Description of application programming interface 5 5 7 Implementation of BSD application 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 ibune3bsd a Library for BSD socket 5 5 7 2 Include path Application which
70. atus until that action completes until data can be received Calling the rev_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 RENESAS Page 7 of 168 Feb 28 2015 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
71. box ID_MBX_ETH_MEMPOL Ether driver mail box R18UZ0019EJ0300 RENESAS Page 10 of 168 Feb 28 2015 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 Operation Use information PHYO_IRQn set_flg PHY driver PHY1_IRQn set_flg PHY driver ETHTXDMA_IRQn set_flg Ethernet driver in transmit operation ETHTXDERR_IRQn set_flg Ethernet driver in transmit operation ETHTX_IRQn set_flg Ethernet driver in transmit operation ETHTXFIFO_IRQn set_flg Ethernet driver in transmit operation ETHTXFIFOERR_IRQn set_flg Ethernet driver in transmit operation ETHRXDMA_IRQn ETHRXFIFO_IRQn Ethernet driver in receive operation Ethernet driver in receive operation ETHRXDERR_IRQn ETHRXERR_IRQn 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 lt R gt 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 lt TOOL gt li
72. btained dhcp_bind in dhcp_ inform Get DHCP Options API ER ercd dhcp_inform T_DHCP_CLIENT dhcp Parameter T_DHCP_CLIENT dhcp DHCP CLIENT INFORMATION Return Value ER ercd Success E_OK or Error Code Error Code E_PAR DHCP is NULL Or there isn t available of the address E OBJ No specified the IP address b Host E_TMOUT 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 RENESAS Page 144 of 168 Feb 28 2015 R IN32M3 Series 6 Network application 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 amp dhcp_client while ercd E_OK Set Time event setup t wai_flg ID_DHCP_FLG OxFFFF TWF_ORW amp ptn ti timeout if ptn 8 T1_EVENT ercd dhcp_renew 8dhcp_client re boot else if ptn amp REBOOT_EVENT ercd dhcp_reboot amp dhcp_client dly_tsk 1000 dh
73. bunet3 a TCP IP protocol stack library Libunet3bsd a TCP IP protocol stack library BSD interface lt TOOL gt depends on development tool chain ARM GCC IAR R18UZ0019EJ0300 RENESAS Page 11 of 168 Feb 28 2015 R IN32M3 Series 3 Ethernet device driver file lt R gt Source Driver ether_uNet3 DDR_ETH c DDR_PHY0 c DDR_PHY1 c Source Driver ethsw ethsw c Include ether_uNet3 Include ethsw DDR_ETH h DDR_PHY h DDR_ETH_CFG h COMMONDEF h ethsw h Ethernet driver PHY driver for LAN1 PHY driver for LAN2 Ethernet Switch driver Ethernet driver header PHY driver common header Ethernet driver configuration header Ethernet driver common definition header Ethernet Switch driver header 4 Application protocol source file lt R gt 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 R18UZ0019EJ0300 Feb 28 2015 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
74. c 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 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 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
75. c_addr Source address unsigned int addrlen Length of source address Return value int Byte number which is received included 0 On error 1 errno EINVAL Parameter is incorrect ENOMEM Message buffer is depleted Cannot get the network buffer corresponding to len EBADF Socked FD cannot be received ENOTCONN Not be connected TCP socket EAGAIN The packet had not received yet During asynchronous execution ETIMEDOUT 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 RENESAS Page 98 of 168 Feb 28 2015 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 sockfd Socket FD int how Direction for disconnection Return value int Result of process If success 0 or on error 1 errno EINVAL Parameter is incorrect ENOMEM Message buffer is depleted EBADF Socked
76. ce 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 The R IN32M3 TCP IP stack uses T_NET_BUF to transceive packet between protocol and device driver or the protocols In TCP IP the actual packet data are stored in buf dat hdr hdr_len dat_len are used to access to that R18UZ0019EJ0300 Feb 28 2015 RENESAS 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 lt R gt Member Send protocol stack gt driver Receive driver gt protocol stack This is set for gNET_DEV dev_num 1 dev_num is specified by application This is set for amp gNET_DEV eth_dev_num 1 eth_dev_num is set at initialization This shows the reason why driver fails to send If driver succeed to send this remains the size specified by protocol stack Not used hdr hdr_len 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 is set the head address and size of frame data which protocol stack sends Driver sends data addressed between hdr and
77. cf How to set the PC IP address not using DHCP Open the network connections list In Windows7 Control panel gt Network and Sharing Center gt Change adapter settings a CMA E lt Net Network C gt S Search Network Connections 2 gt File Edit View Tools Advanced Help Organize v Disable this network device Local Area Connection A Local Area Connection 2 Unidentified network SS Disabled AS TwinCAT Intel PCI Ethernet Adap 4 Cisco Systems VPN Adapter for 6 Wireless Network Connection renesasam com il Intel R Centrino R Advanced N if 1 item selected Double click or right click on the Local Area Connection then select Properties General Connection IPv4 Connectivity No Internet access IPv6 Connectivity No network access Media State Enabled Duration 02 21 20 Speed 100 0 Mbps Activity Sent Received as Bytes 101 355 88 138 E Properties J A Disable J Diagnose ase Select TCP IPv4 and push the Properties button Networking Sharing Connect using Cg TwinCAT Intel PCI Ethernet Adapter Gigabit This connection uses the following items A Client for Microsoft Networks 2 Deterministic Network Enhancer a QoS Packet Scheduler 8 File and Printer Sharing for Microsoft Networks 2 TwinCAT Ethernet Protocol Internet Protocol Version 6 TCP IP v6 PS Interne
78. cify network device used by DHCP client If specify 0 default network device is used R18UZ0019EJ0300 RENESAS Page 125 of 168 Feb 28 2015 R IN32M3 Series 6 Network application 6 1 1 DHCP client API dhcp_client Starting DHCP Client Format ER ercd dhcp_client T_HOST_ADDR addr Parameter T_HOST_ADDR addr host address information Return value ER ercd Successful completion E_OK or error code Error code E_PAR addr is NULL or socid is specified E_OBJ Socket status is wrong socket has not been created yet E_TMOUT 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 1t 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 RENESAS Page 126 of 168 Feb 28 2015 R IN32M3 Series 6 Network application DHCP client example Exclusive task void dhcp_tsk VP_INT exinf ER ercd T_HOST_ADDR dhcp_adar 0 UB status DHC
79. ck supports messages of echo response echo request time excess R18UZ0019EJ0300 RENESAS Page 15 of 168 Feb 28 2015 R IN32M3 Series 3 Overview functions of R IN32M3 TCP IP stack 3 1 2 ARP module 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 t
80. coming recvfrom number becomes EAGAIN 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 RENESAS Page 116 of 168 R IN32M3 Series 5 5 6 3 Error handling 5 Description of application programming interface 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 Explanation The last of errno that occurred within a task called from this API e 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 Explan
81. cp_release amp dhcp_client R18UZ0019EJ0300 RENESAS Page 145 of 168 Feb 28 2015 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 ping_client Ping transmit information Return Value ER ercd Success E_OK or Error Code Error Code E_PAR Specified the incorrect Parameter E_TMOUT No response from remote or failed address resolver E_NOMEM Memory Error E_OBJ 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 RENESAS Page 146 of 168 Feb 28 2015 R IN32M3 Series 6 Network application Use Case ER ping_send void T_PING_CLIENT ping 0 ER e
82. ct 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 P
83. disconnect the transmit direction only R18UZ0019EJ0300 RENESAS Page 19 of 168 Feb 28 2015 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 Transmission buffer empty waiting Waiting timeout or Transmission Copy application data into process interrubtion transmission buffer Return Return size of copied data 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 e 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 e 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 RENESAS Page 20 of 168 Feb 28 2015
84. drs struct ifaddrs ifa Parameter struct ifaddrs ifap The start address of the interface information list Return value void errno Not set Explanation e This function relase the interface information list which was got by getifaddrs function R18UZ0019EJ0300 ENESAS Page 114 of 168 Feb 28 2015 R IN32M3 Series 5 55 Socket option 5 Description of application programming interface The following figure shows the list of option which can be set or got by setsockopt or getsockoptO API If anything other than the specified options The function setsockopt and getsockopt will return 1 Table 5 2 Socket option Option name Type Function SOL_SOCKET level SO_ACCEPTCONN int Get the LISTEN state of TCP socket For Get only SO_BROADCAST int Affect only to UDP broadcast reception operation For Get or Set SO_DOMAIN int Get the socket domain For Get only SO_ERROR int Get the socket error For Get only SO_KEEPALIVE int Enable the Keep Alive function of TCP socket For Set only SO_RCVBUF 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 SO_RCVBUFFORCE int Same as for SO_RCVBUF SO_RCVTIMEO timeval Set the received timeout of socket For Get or Set SO_SNDTIMEO timeval Set the sending timeout of socket For Get or Set SO_TYPE IPPR
85. dware ISR which are used in TCP IP stack for R IN32M3 New created 23 3 2Network device driver Sentences fixes 96 7 3Behavior confirmation Add procedure 2 01 Apr 18 2014 94 98 Add some detail descriptions in 7 Tutorial by sample application 3 00 Feb 28 2015 Modify Table 1 1The difference between evaluation edition and commercial edition 1 Modify 2 3Directory and file organization 1 izati 32 2 i i i 167 Add 8 5Resource list Modify 3 2 4T_NET_DEV information registration example Memo 7tENESAS SALES OFFICES Renesas Electronics Corporation http Awww renesas com 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 21 1 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 Sh
86. e 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 e 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 e Network device The hardware that execute the transmission and reception of actual network data This refers to Ethernet PPP RS 232 and WLAN etc e 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 Object ID Usage Task ID_NET_MAIN_TSK R IN32M3 TCP IP stack startup task Task ID_TASK_TCP_TIM R IN32M3 TCP IP stack time management task Task ID_TASK_ETH_SND Ether driver send task Task ID TASK_ETH_RCV Ether driver receive task Task ID_TASK_PHY_LINK Ether driver control task Semaphore ID_SEM_TCP R IN32M3 TCP IP stack resource control semaphore Event flag ID_FLG_ETH_RX_MAC Ether driver event flag Event flag ID_FLG_ETH_TX_MAC Ether driver event flag Event flag ID_FLG_PHY_STS Ether driver event flag Event flag ID_FLG_SYSTEM Ether driver event flag Mailbox ID_ MBX_ETH_SND Ether driver mail box Mail
87. e information in T_NET_DEV dev_cls Device release Format ER ercd dev_cls UH dev_num Parameter UH dev_num Device number Return value ER ercd Successful completion E_OK or error code Error code E_ID Device number is wrong E OBJ Already released Explanation Release device R18UZ0019EJ0300 RENESAS Page 26 of 168 Feb 28 2015 R IN32M3 Series 3 Overview functions of R IN32M3 TCP IP stack dev_ctl Device control Format ER ercd dev_ctl UH dev_num UH opt VP val Parameter UH UH VP Return value ER Error code E ID E_PAR E_OBJ Explanation dev_num opt val ercd Device number Control code Value to be set Successful completion E_OK or error code Device number is wrong Illegal parameter Already released 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 dev_num Device number UH opt Status code VP val Acquire value Return value ER ercd Successful completion E_OK or error code Error code EID Device number is wrong E PAR Illegal parameter E OBJ Already released Explanation The operation of this function is implementation dependent R18UZ0019EJ0300 Feb 28 2015 RENESAS Page 27 of 168 R IN32M3 Series 3 Overview functions of R IN32M3 TCP IP stack dev_snd Packet transmission Format ER ercd d
88. e the function get INFORM 1 DHCP Client Information typedef struct t_dhcp_client T_DHCP_CTL ctl Control Informatio UW ipaddr Paddress UW subnet Subnet Mask UW gateway Gateway Address UW dhcp DHCPserver address UW dns 2 DNSAddress UW lease Release time for DHCP Addless UW t1 Renewal DHCP address UW t2 Rebind time of DHCP address UB mac 6 MAC addresss UB dev_num Device number UB state Status of DHCP Clients UH socid UDP with socket ID UB arpchk Duplicate IP check T_DHCP_CLIENT 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 RENESAS Page 140 of 168 Feb 28 2015 R IN32M3 Series 6 Network application 6 5 1 DHCP Client Extended API dhcp_bind Get DHCP Lease Information API ER ercd
89. ed from appropriate protocol stack Prototype Description Requirement ER dev_ini UH dev_num Device initialization Require ER dev_cls UH dev_num Device release No require ER dev_snd UH dev_num T_NET_BUF pkt Send packet to network Require ER dev_ctl UH dev_num UH opt VP val Device control No require ER dev_ref UH dev_num UH opt VP val Device status acquisition No require void dev_cbk UH dev_num UH opt VP val Notify event from device callback function No require 5 MAC address Set unique value to specify hardware union struct UB mac 6 MAC address seth cfg 6 Device header size lt R gt Header size of network device header size is set 7 Position writing network buffer lt R gt Network buffer data offset is set This parameter must be 42 R18UZ0019EJ0300 RENESAS Page 25 of 168 Feb 28 2015 R IN32M3 Series 3 Overview functions of R IN32M3 TCP IP stack 3 2 2 Interface dev_ini Device initialization Format ER ercd dev_ini UH dev_num Parameter UH dev_num Device number Return value ER ercd Successful completion E_OK or error code Error code E_ ID Device number is wrong E OBJ Already initialized E PAR Illegal value set in T NET DEV lt 0 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 devic
90. ent information obtained by dhcp_bind This API should be called t1 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 R18UZ0019EJ0300 RENESAS Page 142 of 168 Feb 28 2015 R IN32M3 Series 6 Network application dhcp_ reboot DHCP Client Reboot API ER ercd dhcp_reboot T_DHCP_CLIENT dhcp Parameter T_DHCP_CLIENT dhcp DHCP Client Information Return Value ER ercd Success E_OK or Error Code Error Code E_PAR DHCP is NULL or there is no address available E_OBJ Illegal DHCP client information or DHCP server has refused the request E SYS The assigned IP address conflict with another host E_TMOUT Delayed response from the DHCP server Or DHCP server does not exist DESCRIPTION This APT is reusing the IP resource to which the client was previously used A
91. eout 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 Condition Application behavior connect In the case of TCP socket the return TCP socket continues to wait SYN ACK from remote and value is 1 and error number is resend SYN during the stipulated time after returned 1 The EAGAIN always 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 accept If there is no socket has been The TCP socket is monitored by readfds because of connected to the listen socket the becoming readable by select at the time of receiving the SYN return value becomes 1 and error from remote User should run accept again after becoming number becomes EAGAIN readable send In the case that it is TCP socket and EAGAIN means that the packet couldn t be sent by the sendto the sending buffer is full error number condition of socket Then also packet is not sent becomes EAGAIN In the case that it is UDP socket and the socket is under sending error number becomes EAGAIN recv If packet has not received yet error The socket is monitored by readfds because of be
92. er 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 RENESAS Page 62 of 168 Feb 28 2015 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 RENESAS Page 63 of 168 Feb 28 2015 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 ercd Successful complet
93. estion 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 _ E A e a t Eoo in to ty t ty ty i to MOR Close ee Start of non communication Start of non communication Keep on sending Keep Alive c times to The time of activation Keep Alive t The interval of transmission Keep Alive c The number of transmission Keep Alive Fig 3 7 Operation TCP Keep Alive If Keep Alive feature is enabled c gt 0 after to 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 t1 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 RENESAS Page 23 of 168 Feb 28 2015 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 functio
94. et in asip_array In case of error ip_array turns into NULL R18UZ0019EJ0300 RENESAS Page 124 of 168 Feb 28 2015 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 IP address UW subnet Subnet Mask UW gateway Gateway UW dhcp DHCP Server address UW dns 2 DNS Address UW lease Lease period of the DHCP address UW t1 Renewal period of DHCP address UW t2 Rebind period of DHCP address UB mac 6 MAC address UB dev_num Device address UB state DHCP Cliente status UH socid 1D of UDP socket T_HOST_ADDR 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 e 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 ID Port Transmission timeout Reception timeout UDP ID SOC_DHCP 68 3 seconds 3 seconds e Device number In device number spe
95. etwork interface control NET_IP4_CFG Configure and verify IP Address Subnet mask NET_IP4_TTL Configure and vefiry TTL NET_BCAST_RCV Configure and verify reception of broadcast NET_MCAST_JOIN Join in multicast group NET_MCAST_DROP Drop from multicast Group NET_MCAST_TTL Configure TTL used in multicast transmission 5 Parameter of socket SOC_IP_TTL Configure and verify TTL of Socket SOC_IP_TOS Configure and verify TOS of Socket SOC_TMO_SND Configure and verify blocking time out of snd_soc SOC_TMO_RCV Configure and verify blocking time out of rev_soc SOC_TMO_CON Configure and verify blocking time out of con_soc SOC_TMO_CLS Configure and verify blocking time out of cls_soc SOC_IP_LOCAL Get port number and IP address of local host SOC_IP_REMOTE Get port number and IP address of remote host SOC_CBK_HND Register callback function SOC_CBK_FLG Specify callback event SOC_RCV_PKT_INF Get information of reception packet 6 Connection mode of socket SOC_CLI Connect to remote host active connection SOC_SER Wait for connection passive connection R18UZ0019EJ0300 ENESAS Page 163 of 168 Feb 28 2015 R IN32M3 Series 8 Appendix 7 Termination mode of socket SOC_TCP_CLS Disconnect socket Terminate connection SOC_TCP_SHT Disable only the transmission process Reception is possible 8 Interruption mode of socket SOC_ABT_CON Abort con_soc SOC_ABT_CLS Abort cls_soc SOC_ABT_SND Abort snd_soc SOC_ABT_RCV Abort rcv_
96. ev_snd UH dev_num T_NET_BUF pkt Parameter UH dev_num Device number T_NET_BUF pkt Pointer to network buffer Return value ER ercd Successful completion E_OK or error code Error code E_WBLK Packet is registered in queue not error E_ID Device number is wrong E PAR Illegal parameter E_TMOUT Packet transmission timed out E_OBJ Device status was wrong already Explanation This function transmits packet to Ethernet R18UZ0019EJ0300 RENESAS Page 28 of 168 Feb 28 2015 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 gt hdr pkt gt 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 gt hdr pkt gt hdr_len xmit_frame txframe Transmit to network if transmission timeout pkt gt ercd E_TMOUT Set time out net_buf_ret pkt In dev_snd transmission process i
97. f application programming interface ip_aton Convert an IPv4 address string in dot notation to 32 bit value Format UW ip_aton const char str Parameter char str Pointer to IPv4 address string in dot notation Return value UW gt 0 Successful completion 32 bit value after converting Error code 0 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 str Pointer that accepted IP address string after converting UW ipaddr 32 bit value IP address Return value None Explanation If the process completes successfully the character string will be set in str but str will be NULL if the error occurs R18UZ0019EJ0300 RENESAS Page 123 of 168 Feb 28 2015 R IN32M3 Series 5 Description of application programming interface ip_byte2n Convert IPv4 address array to 32 bit value Format UW ip_byte2n char ip_array Parameter char ip_array Pointer to byte value array of IP address Return value UW gt 0 Successful completion 32 bit value after converting Error code 0 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 ip_array Pointer to byte value array of IP address UW ip 32 bit value IP address Return value None Explanation After completing successfullyl value is s
98. g ID number E NOEXS Socket does not exist socket has not been created yet E_NOSPT Wrong control code E_OBJ Socket status is wrong Explanation This API can cancel waiting status of con_soc cls_soc snd_soc rev_soc Cancelled API returns E_RLWAI Control code Meaning SOC_ABT_CON Discontinuation of con_soc process SOC_ABT_CLS SOC_ABT_SND Discontinuation of cls_soc process Discontinuation of snd_soc process SOC_ABT_RCV Discontinuation of rcv_soc process SOC_ABT_ALL Process discontinuation of all sockets R18UZ0019EJ0300 Feb 28 2015 ENESAS Page 84 of 168 R IN32M3 Series 5 Description of application programming interface snd_soc Data transmission Format ER ercd snd_soc UH sid VP data UH len Parameter UH sid ID is used to identify socket VP data Pointer to the transmit data UH len Size of the transmit data Return value ER ercd Actual transmitted data size gt 0 or error code Error code E_ID Wrong ID number E_NOEXS Socket does not exist socket has not been created yet E_PAR Wrong transmitted data or data size for transmission is not specified E_OBJ Socket status is wrong E_TMOUT Transmission process is out of time E_WBLK Processed by non blocking mode E_CLS Forced termination of the connection from remote host E_RLWAI Transmission process is interrupted E_NOMEM Memory is not enough E_QOVR snd_soc is executing already Explanation
99. ge 102 of 168 Feb 28 2015 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 socktd Socket FD struct sockadar addr Buffer to store the remote address unsigned int addrlen Size of buffer to store the remote address Return value int Result of process If success O or on error 1 errno EINVAL Parameter is incorrect ENOMEM Message buffer is depleted EBADF Socked FD cannot be done getpeername ENOTCONN The address is not set Explanation e For the addrlen user needs to set the size of the sockaddr_in 16 bytes or more e Inthe case of TCP user can get the remote address only for connected socket e Inthe 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 RENESAS Page 103 of 168 Feb 28 2015 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 sockfd Socket FD int level Option level int optname Option name void optval Buffer to store the value got unsigned int optlen
100. hdr_len offset 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 driver received data In the case of Ethernet frame header size is 14 Bytes dat dat_len Not used 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 R18UZ0019EJ0300 Feb 28 2015 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 RENESAS 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 buf Address of buffer that allocate memory UH len Number of allocating bytes UH tmo Timeout specification Return value ER ercd Successful completion E_OK or error code Error code E_PAR Set wrong parameter value E_NOMEM Unable to al
101. hen 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 RENESAS Page 16 of 168 Feb 28 2015 R IN32M3 Series 3 Overview functions of R IN32M3 TCP IP stack snd_soc Copy data into Network buffer uo packet construction ARP entry existence ARP response waiting ARP solution IP fragmentation Data length gt 1472 ARP timeout E_TMOUT A A Be pe eo eis ss EEE 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 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
102. 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 H
103. ion E_OK or error code Error code lt 0 Initialization failure 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 1t needs to issue this API prior to any other API R18UZ0019EJ0300 RENESAS Page 64 of 168 Feb 28 2015 R IN32M3 Series 5 Description of application programming interface net_cfg Parameter setting of network interface Format ER ercd net_cfg UH num UH opt VP val Parameter UH num Device number UH opt Parameter code VP val Value to set Return value ER ercd Successful completion E_OK or error code Error code E_NOSPT Wrong parameter code E ID Wrong parameter code E NOMEM 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 Parameter code Data type enable broadcast reception Meaning NET_IP4_CFG NET_IP4 TTL NET_BCAST_RCV T_NET_ADR 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 NET _MCAST_JOIN Register IP address of multicast gr
104. laced 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 RENESAS Page 87 of 168 Feb 28 2015 R IN32M3 Series 5 Description of application programming interface 5 5 2 Module structures Markers BSD Socket management data 1 1 1 1 Y BSD Wrapper Task uNet3 extended TCP IP Timer task API uNet3 Socket management data Fig 5 1 Module structure for BSD socket R18UZ0019EJ0300 RENESAS Page 88 of 168 Feb 28 2015 R IN32M3 Series 5 5 3 API list Table 5 1 API list 5 Description of application programming interface API Function Include header unet3_bsd_init Initialize the TCP IP and BSD stack for R IN32M3 sys socket h get_errno Get the errno of each task sys errno h socket Create an end point for communication sys socket h bind Put a name for socket sys socket h listen Wait the connection on the socket sys socket h accept Accept connection to the socket sys socket h connect Connect to the socket sys socket h send Send message to the socket sys socket h sendto Send message to the socket sys socket h recv Receive message from the socket sys socket h recvfrom Receive me
105. lication can modify macro values defined as define CFG_XXX XXX is any and cannot modify other macros or variables directly Almost initial values are defined by DEF_XXX macro Configuration content Unit Definition Initial Minimum Maximum value value value The number of data link devices CFG_NET_DEV_MAX 1 1 2 The maximum number of all protocol sockets CFG_NET_SOC_ MAX 10 1 1000 The maximum number of TCP sockets CFG_NET_TCP_MAX 5 0 1000 The number of ARP entries CFG_NET_ARP_MAX 8 1 32 The number of multicast entries CFG_NET_MGR_MAX 8 1 100 The number of IP reassembly queues CFG_NET_IPR_MAX 2 1 16 Network buffer size Byte CFG_NET_BUF_SZ 2048 768 2048 The number of network buffers CFG_NET_BUF_CNT 16 100 Network buffer data offset not allowed to change CFG_NET_BUF_OFFSET 42 MTU size CFG_PATH_MTU 1500 1500 The number of ARP retry CFG_ARP_RET_CNT 3 10 Timeout value for ARP retry ms CFG_ARP_RET_TMO 1000 10000 Clear timeout of ARP cache ms CFG_ARP_CLR_TMO 1200000 3600000 TTL value of IP header TOS value of IP header CFG_IP4_TTL CFG_IP4_TOS 64 255 255 Waiting time IP fragment packet ms CFG_IP4_IPR_TMO 60000 TTL value of multicast IP header CFG_IP4_MCAST_TTL 255 Timeout value of IGMPv1 ms CFG_IGMP_V1_TMO 120000 Timeout value of IGMP report ms CFG_IGMP_REP_TMO 30000
106. locate memory E_TMOUT Timeout 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 Address of buffer that free memory Return value None Error code None 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 RENESAS Page 36 of 168 Feb 28 2015 R IN32M3 Series 3 Overview functions of R IN32M3 TCP IP stack 3 4 Memory processing 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 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 d Pointer to the block of memory to fill int c Value to be set UINT n Number of bytes to be set Return value VP d 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 U
107. n programming interface 5 5 4 19 ioctl Control the device socket Format include sys ioctl h int ioctl int d int request Parameter int d Socket FD int request Request Request parameter Return value int Result of process If success O or on error 1 errno EINVAL Parameter is incorrect ENOMEM Message buffer is depleted EFAULT Cannot expand the request parameters Explanation e The Request can be specified only FIONBIO non blocking connection setting e The request parameter for non blocking communication setting is 1 seting or O release e Regarding the non blocking communication seeting please refer to 5 5 6 1 Non blocking setting R18UZ0019EJ0300 RENESAS Page 106 of 168 Feb 28 2015 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 The dot notation IP address Return value int IP address binary value after conversion network byte order errno Not set Explanation e If the fail to convert happen the return value is set to 0 R18UZ0019EJ0300 RENESAS Page 107 of 168 Feb 28 2015 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
108. n value ER ercd ID of generated socket gt 0 or error code Error code E ID Unable to generate socket exceed maximum number of socket E_ PAR host is wrong E_NOSPT proto is wrong T_NODE Specify local port number and device interface to use UH 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 stack UH ver IP version Specify O use IP_VER4 UB num Device number Specify device number of the device it want to use UW ipa IP address Specify 0 use local IP address proto 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 amp host R18UZ0019EJ0300 RENESAS Page 74 of 168 Feb 28 2015 R IN32M3 Series 5 Description of application programming interface del_soc Delete socket Format ER ercd del_soc UH sid Parameter UH sid ID is used to identify socket Return value ER ercd Successful completion E_OK or error code Error code E_ID Wrong ID number E_NOEXS Socket does not exist Socket has not been created yet E_OBJ Status of socket is wrong Explanation This API deletes the specified ID socket When delete TCP socket
109. ns 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 structt_net_dev UB name 8 Device name UH num Device number UH type Device type UH sts Reserve UH flg Reserve FP ini Pointer to dev_ini function FP cls Pointer to dev_cls function FP ctl Pointer to dev_ctl function FP ref Pointer to dev_ref function FP out Pointer to dev_snd function FP cbk Pointer to dev_cbk function UW tag Reserve union cfg MAC address UH hhdrsz Device header size UH hhdrofs Position writing network buffer T_NET_DEV 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 RENESAS Page 24 of 168 Feb 28 2015 R IN32M3 Series 3 Overview functions of R IN32M3 TCP IP stack 3 Device type Set type of network device There are some as below Device type NET_DEV_TYPE_ETH Ethernet device NET_DEV_TYPE_PPP PPP device 4 Function of driver device Device driver needs to support the below functions These functions are call
110. nsmit 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 RENESAS Page 52 of 168 Feb 28 2015 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 gt flg HW_CS_RX_IPH4 HW_CS_RX_DATA Enables transmit hardware checksum T_NET net net amp gNET eth_devnum 1 set hardware checksum flag net gt flag HW_CS_TX_IPH4 HW_CS_TX_ DATA R18UZ0019EJ0300 RENESAS Page 53 of 168 Feb 28 2015 R IN32M3 Series 3 Overview functions of R IN32M3 TCP IP stack 3 6 PHY driver lt R gt 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
111. nt 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 Memory pool Memory block 0 net_pkt_rev Memory block 1 Send packet to upper layer net buf gat Memory allocation Device driver p set necessary information in t_net_buf lt Data reception Memory block N Hardware Fig 3 8 Memory allocation diagram R18UZ0019EJ0300 RENESAS Page 33 of 168 Feb 28 2015 R IN32M3 Series 3 3 1 Network buffer 3 Overview functions of R IN32M3 TCP IP stack 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 ID T_NET T_NET_DEV T_NET_SOC ER UH UH UH UH UB UB UB T_NET_BUF next mpfid net dev soc ercd flg seq dat_len hdr_len dat hdr buff Reserve ID memory pool Network interfa
112. nt The number of the socket FD which is writable or readable On timeout 0 On error 1 errno EINVAL Parameter is incorrect ENOMEM Message buffer is depleted EBADF Socked FD cannot be selected Explanation e The exceptfds is not used e 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 RENESAS Page 101 of 168 Feb 28 2015 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 sockfd Socket FD struct sockaddr addr Buffer to store the socket address unsigned int addrlen Size of buffer to store the socket address Return value int Result of process If success O or on error 1 errno EINVAL Parameter is incorrect ENOMEM Message buffer is depleted EBADF Socked FD cannot be done getsokname Explanation e For the addrlen user needs to set the size of the sockaddr_in 16 bytes or more e The socket address determined by the time that issued the following API bindQ connect accept send sendto recv recvfrom The socket address becomes the undefined value if these API failed R18UZ0019EJ0300 RENESAS Pa
113. ntrol 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 Event contents Factor EV_CBK_DEV_INIT Always 0 When Ethernet driver is initialized EV_CBK_DEV_LINK Link down 0 Link up 1 Caution Currently link event cannot be detected R18UZ0019EJ0300 Feb 28 2015 RENESAS When link status is changed 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 Description Available value ETH_OPT_PHY MODE PHY ability same as set_phy_mode ETH_OPT_MCRX_MODE Multicast address filter mode setting same as set_mcast_filter_mode ETH_OPT_MCRX_ADR Add multicast address filter same as add_mcast_filter ETH_OPT_RAW_RXFNC ETH_OPT_RAW_SNDDONE Ethernet frame receive report same as eth_raw_rcv Frame tranmit completaion report same as eth_raw_snddone
114. o nono nrnnn ran nan nacen n non necnnecnnos 63 Contents 2 5 2 Network Interface AP dot nl lirios 64 5 3 Network Device Control APD ccococccosoooislsoncosoco thes dekssesdeessveasietave sosbeashssdedscesstescceseay snvestebesshacdetssnsdevasenseseeenvese 70 5 4 Socket API UNet3 compatible vsvs scccsceccecgiveccessleiidecavaaaeeatescacanusegecativecevepueasedevsen cevepueetacsstcnent eg vageuentevsnsesvend 73 5 9 socket API BSD Compatible Riu Ar E esas 87 9 521 Module OVERVIEW oes ers it tapados 87 5 5 2 Module strictures sisese O NO 88 5 5 3 API list EE E AEAEE 89 5 5 4 Detail foreach APPin e E ele o Sa RE ieee E 90 5 5 5 Steele DINTO I A ia an aro 115 5 5 6 S pport functi A sets code raa ara Erea dave Ea R OE EE E EEA O RE e e SEE REEE A E A EREE ETE REESS ERS 116 5 5 7 Implementation of BSD application sseessesessseeseessesreereseeerssteresestesresresrssertsertrsresrenteseertsserrrsrestreerestt 118 5 6 OtherAP less neeese coria as oe 122 6 Network application ccc raini nne aea A i e 125 6 1 DHCP clienta 125 6 1 1 DHEP client A Gals echechesinn a haste eave etisalat th Be decree els 126 6 2 FTE Simon pipi 128 6 2 1 ETP Server APs inchs oi st 129 6 2 2 Restriction O eo de dee ds 129 6 3 HTTP Serveis tad ist 130 6 3 1 HTTP server API ista diia 132 6 3 2 HTTP server Sample ninio ol a aiii reir 137 6 4 DNS elent hai a A a SS ee A ASS 138 6 4 1 DNS client APD ainiin nea teint ea E E nce Ai ee iti 138 6 5 DHCP Clients iia 140
115. ocket Standard version only con_soc Socket connection cls_soc Socket interruption snd_soc Send data rcV_SOC Receive data cfg_soc Configure parameter of socket ref_soc Refer parameter of socket abt_soc Abort process of socket D Network Application dhcp_client Start DHCP Client ftp_server Start FTP Server http_server Start HTTP server CgiGetParam Analyze CGI argument HttpSendText Send text content HttpSendFile Send Attached File HtipSendImage Send Image Content dns_get_ipaddr Get IP address from host name dns_get_name Get host name from IP address dhcp_bind dhcp_renew Get DHCP Lease Information Renewal DHCP lease information dhcp_reboot Reboot DHCP client dhcp_release Release DHCP lease information dhcp_inform Get DHCP option ping_client ICMP Echo request and response sntp_client Get NTP time E Others ip_aton Convert IPv4 address string in dot notation to 32 bit value ip_ntoa Convert 32 bit value IPv4 address to IPv4 address string in dot notation ip_byte2n Convert IPv4 address array to 32 bit value ip_n2byte Convert 32 bit value IPv4 addresse to array htons R18UZ0019EJ0300 Feb 28 2015 Convert 16 bit value to network byte order RENESAS Page 166 of 168 R IN32M3 Series 8 Appendix Convert 16 bit value to host byte order Convert 32 bit value to network byte order
116. on 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 Device number when Device number when Device in use creating X1 connecting X2 Socket transmission action 0 0 Device number 1 top con_soc of snd_soc and TCP 0 N Device number N client N ANY Device number N SYN transmission Socket reception action 0 0 Notified device X3 con_soc of rev_soc and TCP 0 N Device number N server N ANY Device number N SYN reception X1 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 gt num argument of con_soc API X2 Specify by host gt num argument of con_soc API In case of receiving through UDP socket do not need to call con_soc API X3 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 RENESAS Page 73 of 168 Feb 28 2015 R IN32M3 Series 5 Description of application programming interface cre_soc Socket generation Format ER ercd cre_soc UB proto T_NODE host Parameter UH proto Protocol type T_NODE host Information of local host Retur
117. oup to join NET_MCAST_DROP Set IP address of multicast group to drop NET _MCAST_TTL NET_ACD_CBK Callback function pointer 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 RENESAS Page 65 of 168 R IN32M3 Series 5 Description of application programming interface net_ref Reference parameter for network interface Format ER ercd net_ref UH num UH opt VP val Parameter UH num Device number UH opt Parameter code VP val Pointer to buffer of the value to get Return value ER ercd Successful completion E_OK or error code Error code E_NOSPT Wrong parameter code E_ID 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 amp bcast reception status of broadcast Parameter code Data type Meaning NET_IP4_CFG T_NET_ADR Get IP address subnet mask gate way Please hand pointer of T_NET_ADR to val NET_IP4_TTL UB Get TTL Time to Live NET_BCAST_RCV UB Get the receive status of broadcast NET_MCAST_TTL UB Get TTL broadcast transmission R18UZ0019EJ0300 RENESAS Page 66 of 168 Feb 28 2015 R IN32M3 Series 5 Description of applica
118. 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 communic
119. please call cls_soc in advance and close the socket R18UZ0019EJ0300 RENESAS Page 75 of 168 Feb 28 2015 R IN32M3 Series 5 Description of application programming interface con_soc Socket connection Format ER ercd con_soc UH sid T_NODE host UB con_flg Parameter UH sid ID is used to identify socket T_NODE host Information of remote host UB con_fig Connection mode Return value ER ercd Successful completion E_OK or error code Error code E ID Wrong ID number E_NOEXS Socket does not exist Socket has not been created yet E_PAR Host or con_flg is wrong E_OBJ Socket status is wrong for example calling this API for the socket which has already connected E_TMOUT Connection process is out of time E_WBLK Processed by non blocking mode E_CLS Refuse the connection from remote host E_RLWAI Connection process is interrupted E_QOVR con_soc is already executing T_NODE Specify remote host and device interface to use UH port Port number Port number of remote host from 1 to 65535 UH ver IP version Specify 0 UB num Device number Device number of the device that wants to use UW ipa IP address IP address of remote host con_fig Specify the waiting for connection server or the active connection client Usually specify O for UDP socket SOC_CLI Connect to remote host active connection SOC_SER Wait for connection passive connection R18UZ0019EJ0300 RENESAS Page 76 of 168 Feb 28 2015 R IN32M3 Se
120. pplication 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 sockfd Socket FD const void buf Address for sending data unsigned int len Length for sending data int flags Flag const struct sockaddr dest_addr The destination address unsigned int addrlen Length of the destination address Return value int Byte number which is sent On error 1 errno EINVAL Parameter is incorrect ENOMEM Message buffer is depleted Cannot get the network buffer corresponding to len EBADF Socked FD cannot be sent to EDESTADDRREQ Unsetting the address UDP socket ENOTCONN Not be connected TCP socket EAGAIN The socket is under sending During asynchronous execution ETIMEDOUT Timeout if the timeout is set Explanation e The length for sending data can be specified the value from 1 to 65535 e The flag is not used so any value is possible e Inthe case of TCP socket the destination address and length of it is not used e The sending 0 byte UDP data cannot be sent unlike the POSIX specification R18UZ0019EJ0300 RENESAS Page 96 of 168 Feb 28 2015 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
121. r code E_PAR Wrong parameter is specified E_TMOUT No response from DNS server E_NOMEM Memory error E_OBJ 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 amp ip R18UZ0019EJ0300 RENESAS Page 138 of 168 Feb 28 2015 R IN32M3 Series 6 Network application dns_get_name Acquire host name from IP address Format ER ercd dns_get_name ID socid UW dns_server char name UW ipadar Parameter ID socid UDP socket ID UW dns_server IP address of DNS char name host name to acquire UW ipaddr IP address Return value ER ercd Successful completion E_OK or error code Error code E_PAR Wrong parameter is specified E_TMOUT No response from DNS server E_NOMEM Memory error E_OBJ Unable to acquire host name from P 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 amp ip R18UZ0019EJ0300 RENESAS Page 139 of 168 Feb 28 2015 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 provid
122. ramming 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 dev_num Device number Return value ER ercd Successful completion E_OK or error code Error code lt 0 Initialization failure 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 RENESAS Page 70 of 168 Feb 28 2015 R IN32M3 Series 5 Description of application programming interface net_dev_cls Release network device Format ER ercd net_dev_cls UH dev_num Parameter UH dev_num Device number Return value ER ercd Successful completion E_OK or error code Error code lt 0 Failure 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 dev_num Device number UH opt Control code VP val Value to set Return value ER ercd Successful completion
123. rcd ping sid ID_ICMP ping devnum ID_DEVNUM_ETHER ping tmo 1000 Timeout 1 second ercd ping_client amp ping if ercd E_OK ping success return ercd R18UZ0019EJ0300 RENESAS Page 147 of 168 Feb 28 2015 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 API sntp_client Get NTP time API ER sntp_client T_SNTP_CLIENT sntp_client UW sec UW msec Parameter T_SNTP_CLIENT sntp_client Information of SNTP client UW sec MTP Time second UW msec NTP Time 32 bit fixed point representation below the decimal Return Value ER ercd Success E_OK or Error Code Error Code E_PAR Specified the illegal parameter E_TMOUT No response from remote or failed address resplver E_NOMEM Memory Error E_OBJ 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 calc
124. rce 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 Error number management table defines a global variable as T_UNET3_BSD_SOC type array that the number of elements is NUM_OF_TASK_ ERRNO R18UZ0019EJ0300 RENESAS Page 119 of 168 Feb 28 2015 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 Use ID Task BSD Wrapper task ID TSK_BSD_API Loopback device task ID_LO_IF_TSK Mailbox Communication between the BSD Wrapper task ID MBX_BSD_REQ Communication between the loopback device task ID_LO_IF_MBX R18UZ0019EJ0300 RENESAS Page 120 of 168 Feb 28 2015 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 socke
125. re also used added to above 4 Kernel object used by memory management Object ID Object Mail box ID_MBX_ETH_MEMPOL Description Memory management R18UZ0019EJ0300 Feb 28 2015 RENESAS Page 167 of 168 R IN32M3 Series 8 Appendix 8 5 2 Hardware ISR Table 8 1 Hardware ISR used by TCP IP stack for R IN32M3 Hardware ISR reason Operation Description PHYO_IRQn set_flg PHY driver PHY1_IRQn ETHTXDMA_IRQn PHY driver Ethernet driver send operation ETHTXDERR_IRQn set_flg Ethernet driver send operation ETHTX_IRQn set_flg Ethernet driver send operation ETHTXFIFO_IRQn set_flg Ethernet driver send operation ETHTXFIFOERR_IRQn ETHRXDMA_IRQn Ethernet driver send operation Ethernet driver receive operation ETHRXFIFO_IRQn ETHRXDERR_IRQn ETHRXERR_IRQn Ethernet driver receive operation Ethernet driver receive operation Ethernet driver receive operation R18UZ0019EJ0300 RENESAS Page 168 of 168 Feb 28 2015 REVISION HISTORY R IN32M3 Series User s Manual TCP IP stack Rev Date Description Page Summary 1 00 Jul 26 2013 First edition issued 2 00 Oct 4 2013 Typos are fixed all over this document 2 Table 1 2Development tools EWARM version is fixed Fig 2 2Block diagram of network system Typos in figure fixes 10 Table 2 10S Kernel objects which are used in TCP IP stack for R IN32M3 Delete ID_ NET_MAIN_TSK as not used 11 Table 2 2Har
126. ries 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 amp 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 amp remote SOC_CLI R18UZ0019EJ0300 RENESAS Page 77 of 168 Feb 28 2015 R IN32M3 Series 5 Description of application programming interface cls_soc Socket disconnetion Format ER ercd cls_soc UH sid UB cls_flg Parameter UH sid ID is used to identify socket UB cls_fig Disconnetion mode Return value ER ercd Successful completion E_OK or error code Error code E ID Wrong ID number E_NOEXS Socket does not exist Socket has not been created yet E_PAR cls_flg is wrong E_OBJ Socket status is wrong Such as when calling this API in the status of disconnection E_TMOUT Disconnection process is out of time E_WBLK Processed by non blocking mode E_CLS Forced termination of the connection from remote host E_RLWAI Disconnection
127. rrno EINVAL Parameter is incorrect ENOMEM Message buffer is depleted EBADF Socked FD cannot be bound EAFNOSUPPORT Unsupported address family EADDRINUSE Address is already in use EADDRNOTAVAIL Address is not available Explanation e Local address should be set as struct sockaddr_in type e IP address IPv4 for the local address can be specified only the address which is set to device or INADDR_ANY unspecified e Ifuser sets the PORT_ANY 0 to the port number of the local address a port number is assigned in the protocol stack e The local address length can be specified only sizeof struct sockaddr_in 16 e The member sin_len with struct sockaddr_in type is not used so any value is possible e 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 e User can bind to wellknown port 1 1023 also R18UZ0019EJ0300 RENESAS Page 91 of 168 Feb 28 2015 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 sockfd Socket FD int backlog Back log Return value int Result of process If success 0 or on error 1 errno EINVAL Parameter is incorrect E
128. s 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 RENESAS Page 29 of 168 Feb 28 2015 R IN32M3 Series 3 Overview functions of R IN32M3 TCP IP stack dev_cbk Device event notification Format void dev_cbk UH dev_num UH opt VP val Parameter UH dev_num Device number UH opt Event code UH val 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 RENESAS Page 30 of 168 Feb 28 2015 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 pkt Pointer to network buffer Return value None Error code None 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 amp pkt len TMO Set received Ethernet header to network buffer pk
129. soc SOC_ABT_ALL Abort all the processes of socket 9 Callback Event EV_SOC_CON Enable con_soc to be non blocking mode EV_SOC_CLS Enable cls_soc to be non blocking mode EV_SOC_SND Enable snd_soc to be non blocking mode EV_SOC_RCV Enable rcv_soc to be non blocking mode R18UZ0019EJ0300 RENESAS Page 164 of 168 Feb 28 2015 R IN32M3 Series 8 Appendix 8 3 Error Code List E_NOSPT Unsupported function E_PAR Parameter error E_ID Illegal ID number E NOMEM Insufficient memory E OBJ 41 Object status error E NOEXS 42 Uncreated object E QOVR 43 Queuing overflow E RLWAI Forced cancellation of wait state E_TMOUT Polling failure or time out E_CLS Change status of waiting object E_WBLK Non blocking acceptance Buffer overflow R18UZ0019EJ0300 RENESAS Page 165 of 168 Feb 28 2015 R IN32M3 Series 8 4 API List API Name A Network Interface 8 Appendix net_ini Initialize TCP IP protocol stack net_cfg Configure parameters of network interface net_ref Refer parameters of network interface net_acd Detection IP Address Confliction B Network Device Control net_dev_ini Initialize network device net_dev_cls Release Network Device net_dev_ctl Control network device net_dev_sts Get status of network device C Socket cre_soc Create socket Standard version only del_soc Delete a s
130. ssage from the socket sys socket h shutdown Close the part of the full duplex connection sys socket h close Close the descriptor socket sys unistd h select Multiplexing of synchronous I O sys select h getsockname Get the name of the socket sys socket h getpeername Get the name of the peer socket sys socket h getsockopt Get the socket options sys socket h setsockopt Set the socket options sys socket h ioctl Control the device socket sys ioctl h inet_addr Internet address manipulation routines arpa inet h inet_aton Internet address manipulation routines arpa inet h inet_ntoa Internet address manipulation routines arpa inet h if_nametoindex Mapping name and index of the network interface net if h if_indextoname Mapping name and index of the network interface net if h rresvport Get the socket which is bound to port sys unistd h getifaddrs Get the address of the interface sys types h freeifaddrs R18UZ0019EJ0300 Feb 28 2015 Release the interface information RENESAS sys types h Page 89 of 168 R IN32M3 Series 5 Description of application programming interface 5 5 4 Detail for each API 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
131. t gt hdr pkt gt buf 2 pkt gt hdr_len ETH_HDR_SZ memcpy pkt gt hdr rx_frame pkt gt hdr_len Set received IP payload to network buffer pkt gt dat pkt gt hdr pkt gt hdr_len pkt gt dat_len rx_frame_len pkt gt hdr_len memcpy pkt gt dat rx_frame pkt gt hdr_len pkt gt dat_len Device information setting pkt gt dev dev Transfer network buffer to protocol stack net_pkt_rcv pkt Release of network buffer is executed by net_pkt_rev net_pkt_rcv must be called from task context R18UZ0019EJ0300 RENESAS Page 31 of 168 Feb 28 2015 R IN32M3 Series 3 Overview functions of R IN32M3 TCP IP stack 3 2 4 T_NET_DEV information registration example lt R gt T_NET_DEV information registration example is showed as bellows T_NET_DEV information registration example T_NET_DEV gNET_DEV ano Device Name 1 Device Number NET _DEV_TYPE_ETH Device Type O Status 0 Flags si eth_ini Device Init eth_cls Device Close eth_cil Device Configure eth_sts Device Status eth_snd Device Transmit eth_cbk Device Callback 0 0x12 0x34 0x56 0x78 0x9A OxBC MAC Address ETH_HDR_SZ Link Header Size CFG_NET_BUF_OFFSET Network buffer data Offset R18UZ0019EJ0300 RENESAS Page 32 of 168 Feb 28 2015 R IN32M3 Series 3 Overview functions of R IN32M3 TCP IP stack 3 3 Memory manageme
132. t Protoco j K RRK RKK KRK Install Uninstall Properties Description Transmission Control Protocol Intemet Protocol The default wide area network protocol that provides communication across diverse interconnected networks R18UZ0019EJ0300 RENESAS Page 155 of 168 Feb 28 2015 R IN32M3 Series 7 Tutorial by sample application Set IP address to 192 168 1 101 and sub net mask to 255 255 255 0 Internet Protocol Version 4 TCP IPv4 Properties General You can get IP settings assigned automatically if your network supports this capability Otherwise you need to ask your network administrator for the appropriate IP settings Obtain an IP address automatically IP address Subnet mask Default gateway Obtain DNS server address automatically Use the following DNS server addresses Preferred DNS server Alternate DNS server Validate settings upon exit 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
133. t h ER unet3_bsd_init void Parameter void Return value ER Result of process If success E_OK or if error error code 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 RENESAS Page 121 of 168 Feb 28 2015 R IN32M3 Series 5 Description of application programming interface 5 6 Other API htons Convert 16 bit value to network byte order Format UH htons UH val Parameter UH val 16 bit value host byte order Return value UH 16 bit value to network byte order htonl Convert 32 bit value to network byte order Format UW htonl UW val Parameter UW val 32 bit value host byte order Return value UW 32 bit value network byte order ntohs Convert 16 bit value to host byte order Format UH ntohs UH val Parameter UH val 16 bit value network byte order Return value UH 16 bit value host byte order ntohl Convert 32 bit value to host byte order Format UW ntohl UW val Parameter UW val 32 bit value network byte order Return value UW 32 bit value host byte order R18UZ0019EJO300 RENESAS Page 122 of 168 Feb 28 2015 R IN32M3 Series 5 Description o
134. th_snd Prototype ER eth_snd UH dev_num T_NET_BUF pkt Operation Ethernet frame transmit Parameter UH dev_num Device number 1 UH pkt gt hdr Address for transmit data UB pkt gt hdr_len Transmit data length Return value ER E_OK Success for transmit E_TMOUT Link down E_WBLK Non blocking reception Only when non blocking transit E_NOMEM No enough memory E_SYS MAC controller error Explanation 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 RENESAS Page 42 of 168 Feb 28 2015 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 pkt pkt specified to eth_snd ER pkt gt ercd Transmit result Return value void Explanation 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 f
135. 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 ENESAS Page 14 of 168 Feb 28 2015 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
136. this variable is called from Ethernet driver Last element of gPHY_IO arrays must be set O 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 Description phy_id PHY ID ID number of LAN1 LAN4 If target is LAN1 this member is 1 phy_adr PHY address phy_ini Initialize function phy_ext Exit function phy_set_mode PHY ability setting function phy_get_mode PHY ability getting function R18UZ0019EJ0300 RENESAS Page 54 of 168 Feb 28 2015 R IN32M3 Series 3 Overview functions of R IN32M3 TCP IP stack 3 6 1 PHY driver API 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 flg Event flag ID UW id PHY ID UW adr PHY address Return value ER E_OK Success Others Error when task start Explanation 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 RENESAS Page 55 of 168 Feb 28 2015 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
137. ticast address to add UB adr gt bitnum Valid bit number 0 40 48 Return value ER E_OK Success E _ PAR Invalid parameter Explanation 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 octets is OxE0 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 Ox5e 0x00 0x01 0x00 memcpy amp adr mac 0 macadr 6 adr bitnum 40 add_mcast_filter amp 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 RENESAS Page 48 of 168 Feb 28 2015 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 Device number Event type Event description This function is defined by network application It is possible to co
138. tion of application programming interface soc_cbt Callback function Format UW soc_cbt UH sid UH event ER erca Parameter UH sid ID is used to identify socket UH event Callback event flag bit ER ercd 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 Error code Meaning event ercd EV_SOC_CON E OK con_soc process completes normally lt 0 con_soc process completes with error Regarding error content of this time please refer to error code of con_soc EV_SOC_CLS E OK cls_soc process completes normally lt 0 cls_soc process complete with error Regarding error content of this time please refer to error code of cls_soc EV_SOC_SND gt 0 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 lt 0 snd_soc process completes normally Regarding error content of this time please refer to error code of snd_soc EV_SOC_RCV gt 0 UDP socket There is receipt data in UDP socket Shows receipt data
139. tion programming interface net_acd Detection IP Address Confliction API ER ercd net_acd UH dev_num T_NET_ACD aca Parameter UH num Deviec Number T_NET_ACD acd Address Conflict Information Return Value ER ercd Success E_OK or Error Code Error Code E ID Illegal Device Number E PAR Illegal Parameter E OBJ Call Duplicate or Call host IP undefined E_TMOU Time out ARP transmit E SYS Detect IP address conflict E OK 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 RENESAS Page 67 of 168 Feb 28 2015 R IN32M3 Series 5 Description of application programming interface _net_cbk __ Callback IP address conflict detected API ER acd_cbk T_NET_ACD aca Parameter T_NET_ACD acd Address Conflict Information Return Value ER ercd 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
140. uct t_host_addr UW UW UW UW UW UW UW UW UB UB UH ipaddr subnet gateway dhcp dns 2 lease t1 t2 mac 6 dev_num socid TLHOST_ADDR R18UZ0019EJ0300 Feb 28 2015 Device header size Position of writing network buffer 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 RENESAS 8 Appendix Page 159 of 168 R IN32M3 Series 8 Appendix 6 T_FTP_SERVER FTP server control information typedef struct t_ftp_server UB dev_num Device number UH ctl_socid SocketID for command UH data_socid SocketID for data UB fs_file Store buffer UW fs_maxsz Store buffer size T_FTP_SERVER 7 T_HTTP FILE HTTP Content Information typedef struct t_http_file const char path 12 const char ctype 12 const char file int len void cbk T_HTTP_SERVER http T_HTTP FILE
141. uffers 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 RENESAS Page 131 of 168 R IN32M3 Series 6 Network application 6 3 1 HTTP server API http_server Start up HTTP server Format ER ercd http_server T_HTTP_SERVER http Parameter T_FTP_SERVER http HTTP server control information Return value ER ercd Successful completion E_OK or error code Error code E_PAR 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 RENESAS Page 1
142. ulated by the caller R18UZ0019EJ0300 RENESAS Page 148 of 168 Feb 28 2015 R IN32M3 Series 6 Network application Use Case ER sntp_time void T_SNTP_CLIENT snip 0 UW sec msec ER ercd sntp sid ID_UDP sntp devnum ID_DEVNUM_ETHER ercd sntp_client amp sntp amp sec amp msec if ercd E_OK Convert to Unix Time sec 2208988800 Accuracy for ms msec gt gt 16 msec 1000 msec gt gt 16 return ercd R18UZ0019EJ0300 RENESAS Page 149 of 168 Feb 28 2015 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 stri String to be compared const char str2 String to be compared W len Length of compare Return Value WwW Result DESCRIPTION The results were compared with the character code it will return 0 if str1 str2 The return value is positive if str1 gt str2 and is negative if strl lt 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_stremp String Compare API W net_stremp const char
143. unction 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 RENESAS Page 43 of 168 Feb 28 2015 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 fram Reception data address UH len Reception data length Return value void Explanation 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_RXENC 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 RENESAS Page 44 of 168 Feb 28 2015 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 mode PHY ability UW mode gt mode Speed Duplex UB mode gt nego Auto negotiation on
144. urpose 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 lt R gt means the updated point in this revision The mark lt R gt 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 R IN32M3 Series Datasheet R18DS0008EJ R IN32M3 EC User s Manual R18UZ0003
145. 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 Include base folder of uNet3 socket R18UZ0019EJ0300 RENESAS Page 118 of 168 Feb 28 2015 R IN32M3 Series 5 Description of application programming interface 5 5 7 9 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 defin 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 uNet3 socket maximum number CFG_NET_SOC_MAX Number of application tasks defin 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 Resou
146. ver operates with PHY driver which controls MDIO interface This driver structure is showed below Network Application Ethernet Driver RX Task R IN32M3 MAC Controller Fig 3 9 Ethernet device driver structure R18UZ0019EJ0300 RENESAS Page 39 of 168 Feb 28 2015 R IN32M3 Series 3 Overview functions of R IN32M3 TCP IP stack 3 5 2 Ethernet device driver API 3 5 2 1 Ethernet driver initialization eth_ini Prototype ER eth_ini UH dev_num Operation Initialize Ethernet driver Parameter UH dev_num Device number 1 Return value ER E_OK Success initialization E ID Undefined device number E _ PAR Invalid device number Others Task wake up error PHY driver initialization error Explanation 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 RENESAS Page 40 of 168 Feb 28 2015 R IN32M3 Series 3 Overview functions of R IN32M3 TCP IP stack 3 5 2 2 Ethernet driver closed eth_cls Prototype ER eth_cls UH dev_num Operation Ethernet driver is closed Parameter UH dev_num Device number 1 Return value ER E_OK Exit without error Explanation PHY MAC controller stops R18UZ0019EJ0300 RENESAS Page 41 of 168 Feb 28 2015 R IN32M3 Series 3 Overview functions of R IN32M3 TCP IP stack 3 5 2 3 Ethernet frame transmit e
147. x On error 0 errno ENXIO Nonexistent interface name Explanation e 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 RENESAS Page 110 of 168 Feb 28 2015 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 ifindex Interface index char ifname Buffer for storing the interface name Return value int Result of process If success ifname value or on error NULL errno ENXIO Nonexistent interface index Explanation e 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 ENESAS Page 111 of 168 Feb 28 2015 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 Buffer to store port number Return value int The socket FD which is bound to port If socket is not existing return 1 errno Not set R18UZ0019EJ0300 RENESAS Page 112 of 168 Feb 28 2015 R IN32M3 Series 5 Description of application programming interface 5 5 4 26 getifaddrs Get the address of the interf
Download Pdf Manuals
Related Search
Related Contents
"service manual" User Manual - Jackson Systems CLUB3D HD4670 1GB CPC REGIONALES [TOURS] Panasonic SL-PR300 4 Bauanleitung / Instruction Manual / manuale d`istruzione - RC-Toy PROPHÉTIE: Comprendre la puissance qui contrôle votre avenir Asante Technologies 10NIC-PCITM Network Card User Manual Garmin 17X GPS Receiver User Manual Copyright © All rights reserved.
Failed to retrieve file