Home
CrossWorks TCP/IP Library
Contents
1. CTL NET ONC MULTICAST ACCEPT FN CIN INDE INTERFACE C eon unsigned CTL NET MAC MULTICAST OUERY FN t CTL NET INTERFACE t const IL NET MAC MIT WRITE FN t CTL NET INTERFACE t int int L NET MAC MII READ FN t CTL NET INTERFACE t int TL NET MAC MII DEFERRED READ FN t CTL NET INTERFACE t int TL NET MAC MIT DEFERRED READ RESULT FN t CTL NET INTERFACE E LENE MAG 5 BEG DUPHYN ENGEL Ca lim NE TINEEREAEEIE A CTL NET MAC DRIVER t holds the data and functions that handle the MAC layer mac addr The Ethernet MAC address that the network interface uses You must set this before calling init fn 158 CrossWorks TCP IP Library CrossWorks TCP IP Library init_fn This should return non zero if MAC hardware initialization was successful update_fn The network stack will call update_fn called periodically with a non zero isHousekeeping or when the network task is activated by ctl_mac_wake_net_task get_state_fn The network stack will will call get_state_fn to query the state of the MAC in various layers send_fn The IP layer will call send_fn to send a frame to the MAC for transmission send_fn must be thread safe multicast_accept_fn Enable or disable accepting packets given the layer 2 destination address Returns non zero if successful multicast_query_fn Returns non zero if the MAC layer is currently accepting mulitcast packets w
2. Description ct dns secondary server addrreturns the secondary DNS server as set in the CTL_IP_CONFIG_t passed to ct net init or or retrieved from a DHCP server If IP addresses are assigned by DHCP ct dns secondary server addr will returns an all zero IP address whilst IP negotiation is in progress See Also CTL_IP_CONFIG t ctl_net_init 79 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl dns set max ttl Synopsis void ct1 dns set max tt1 unsigned long ttl Description ctl dns set max tt sets the maximum timeout before an entry is deleted from the DNS cache to ttl seconds The default time to live is 24 hours The DNS cache entry for a DNS record is set to the earliest of the time to live set by ctl_dns_set_max_ttl and the time to live returned by the server Thread Safety ctl_dns_set_max_ttl is thread safe 80 CrossWorks TCP IP Library CrossWorks TCP IP Library ct dns set memory allocator Synopsis void ctl1 dns set memory allocator CTL MEMORY ALLOCATOR t allocator Description ct dns set memory allocator sets DNS memory allocator to allocator If allocator is zero the DNS cache uses the system memory allocator ct system memory allocator Note Setting the memory allocator automatically clears the DNS cache and cancels any outstanding DNS resolves We recommend that you set the DNS allocator before starting the DNS revolver Thread Safety ctl_dns_set_memory
3. Description CTL_TCP_GET_SOCKETS_FLAG _t defines a set of flags for enumerating sockets using ctl_tcp_get_sockets CTL_TCP_GET_SOCKETS_CONNECTING Enumerate sockets that have not completed the synchronization handshake CTL TCP GET SOCKETS CONNECTED Enumerate sockets with an established connection CTL TCP GET SOCKETS READABLE Sockets with an established connection that also have gueued bytes available CTL TCP GET SOCKETS TRIGGERED Sockets with an established connection that have a push packet in the receive gueue and all sent push packets have been acknowledged by the remote CTL TCP GET SOCKETS CLOSED Sockets that are to be reclaimed soon typically within 100 milliseconds See Also ctl_tcp_get_sockets 50 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL TCP PORT OPTIONS t Synopsis typedef struct unsigned max connections CEATEC PES EK IGK ONSE dd ES Ne LASEEEEORTAEPIKGNS SE CTL TCP PORT OPTIONS t contains settings for server sockets on a port by port basis max Connections Maximum number of sockets that can be owned by the server defaults Default options for a socket created by the server When a new TCP connect reguest is received for the port registered to the server a socket is created and its options are initialized with these values before the accept callback is invoked See Also CTL_TCP_SOCKET_OPTIONS _t ctl_tcp_get_port_options ctl_tcp_set_port_options
4. Synopsis void designware emac v2 first free CTL NET INTERFACE t self Description designware emac v2 first free returns a pointer to the first byte free for use by the application after the allocation of transmit and receive descriptors The client can use this to add all remaining memory to the network heap for example You can call this after initializing the network interface using designware_emac_v2_init See Also designware_emac_v2_init 209 CrossWorks TCP IP Library CrossWorks TCP IP Library designware emac v2 init mac driver Synopsis void designware emac v2 init mac driver CTL NET INTERFACE t self void emac void mem 1nt descrip ror racont int rx descriptor count unsigned clock int interruptSource Description designware emac v2 init mac driver initializes the network interface self but does not start it The DesignWare 10 100 EMAC register interface is specified in emac and the memory reguired to hold the transmit and receive descriptors is specified in mem The number of transmit and receive descriptors are passed in tx descriptor count and rx descriptor count At least two transmit descriptors are required and transmit performance of the TCP IP library will scale with the number of descriptors allocated At least one receive descriptor is required and receive performance of the TCP IP library will scale with the number of descriptors allocated The clock provided to the mod
5. To resume accepting connections call ctl_tcp_bind followed by ctl_tcp_accept See Also ctl_tcp_unbind ctl_tcp_accept CTL_NET_PORT_t ctl_tcp_init 142 CrossWorks TCP IP Library CrossWorks TCP IP Library ct tcp use callback Synopsis Cilims TAL Sep ctiltepluselcallback str NE PORTIE port CTL TCP SERVER FN t serverFn Description ctl tcp use callback sets serverFn to be the callback function for the the bound TCP port port You should call ct tcp use callback after ct tcp bind but before ct tcp accept port is specified in network byte order Callback and Event TCP server models are mutually exclusive invoking this function will nullify the behavior set in a previous call to ctl_tcp_use_event See Also ctl_tcp_use_event ctl_tcp_use_callback ctl_soc_use_event ctl_tcp_accept ctl_tcp_bind 143 CrossWorks TCP IP Library CrossWorks TCP IP Library ct tcp use event Synopsis CTE STATUS t cetl tep use event CTL NET PORT t port CTL EVENT SET t wake event CTL EVENT SET t wake value ctl tcp use event assigns the wake event pointer and value used for sockets used by a TCP server on port port Callback and event TCP server models are mutually exclusive invoking this function will nullify the behavior set in a previous call to ctl_tcp_use_callback See Also ctl_tcp_use_callback ctl_soc_use_callback ctl_soc_use_event 144 CrossWorks TCP IP Library C
6. ctl_tcp_get_socket_options ctl_tcp_set_socket_options 51 CrossWorks TCP IP Library CTL TCP SEND FLAG t Synopsis typedef enum em ePASENPAPYS Hy CTL TCP SEND URGENT n nErASENPANGSOP YS Em CES END SERIE CIEL TOP SEND FLAG Ut See ctl_tcp_send for a full description of the flags CTL TCP SEND PUSH Push buffered data to network CTL_TCP_SEND_URGENT Send out of band data This is not implemented CTL_TCP_SEND_NOCOPY Perform a zero copy send of static data CTL_TCP_SEND_FREE Perform a zero copy send of dynamic data 52 CrossWorks TCP IP Library CrossWorks TCP IP Library CrossWorks TCP IP Library CTL TCP SOCKET CLOSE TYPE Synopsis typedef enum n nerdEOSEOIMTINGER CTL TCP CLOSE DONTLINGER j ET TOP SOOKET GEGEE TEE IE Description CTL TCP SOCKET CLOSE TYPE t indicates how a socket should be closed linger timeout Type of close Wait for close CTL TCP CLOSE DONTLINCDon t care Graceful No CTL TCP CLOSE LINGER Zero Hard No CTL TCP CLOSE LINGER Nonzero Graceful Yes See Also ctl tcp close socket 53 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL TCP SOCKET CONNECTION STATE Synopsis typedef enum Enr sep Ss OCKHI SS TATE CHOSE D CTL_TCP_SOCKET_STATE_CONNECTING EmI EP SOCKET STATE CONNECTED CTL TCP SOCKET STATE CLOSING CEE _TCP_SOCKET CONNECTION STATE t Description CTL_TCP_SOCKET_CONNECTION_STATE_t is a condensed version of t
7. libplatform platform_network h amp addr 2000 30 CrossWorks TCP IP Library NE example terminate Could not resolve www rowley co uk n else Yes print the resolved IP address printf s resolved to s n ROSE ctl1 ip sprint addr str addr User needs to know Prince Connecting Ho ss ES au DOSE ctllip sprint addr str addr Open a socket to the host on port 80 s ctl_tcp_socket if s lt CTL_NO_ERROR example terminate No sockets available n example check status ctl tcp connect s addr HTONS 80 1000 Send the reguest printf Reguesting s n name Ctlstep sprint f s Eer hete ss HETE MONA ost name etl tep printf s Accept text plain r n cChlltcpeprint amp sym Osim cic NE ao os ctl tep printf is Ens ctl_tcp_push s Process response for Try to read a whole line from the web server stat ctl1 tcp read line s line buffer sizeof line buffer l CTL TIMEOUT DELAY 4000 Ensure the buffer is terminated line bufferl sizeof line buffer 1 0 Process return status if stat CTL NET ERR TIMEDOUT 1 Dhein e EISE EEEN lode tenet else if stat lt CTL_NO_ERROR Error reading the socket or the socket closed break else Dump response printf sNn line buffer Make sure socket is closed ctl_tcp_shutdown s 31 CrossWorks TCP IP Library CrossWorks TCP
8. unsigned short ethType CTL _ETH_HEADER_t Description The Ethernet header is 14 bytes long In order to make the subsequent IP and TCP UDP headers align on a 32 bit word an extra short is added to the start of the structure The 1536 byte frame buffer passed back and forth with the hardware actually begins at amp ethDstMac 0 Some MAC layers have a short word length field preceding the Ethernet header when the data is sent received to the hardware The ___ required_align short mentioned in the preceding paragraph is used for that purpose An example of this is the Ethernet FIFO on the TI LM3S Stellaris devices 151 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL ETH RX FRAME Synopsis typedef struct CTL_ETH HEADER t data unsigned byteCount unsigned ethAndIpByteCount CTL ETH RX FRAME G Description For frame based MACs LPC2xxx STR91x SAM7X there is a rotating ring of receive frame buffers that are passed to the network task during processing of received frames For FIFO based MACs Stellaris ENC28J60 there is a single static receive frame buffer that is filled and then passed to the network task as frames arrive In either case the stack or application code must not hold on to any data in the received frame outside the context of ctl_net_process_received_frame nor should it block in ctl_net_process_received_frame which includes any UDP callback handler The members are data Poi
9. CrossWorks TCP IP Library Version 3 2 Copyright 2013 Rowley Associates Limited CrossWorks TCP IP Library CrossWorks TCP IP Library Contents Contents ell dn ell dk se EE N RER En Preamble RE esnovczonnasgcatovuiossindesdat cdetovasssnasscatnsaseasageabantaatouasennaustetovaden aadeabab dotovisatassistpatcnteaadeabonsde Object Code Evaluation License sense soeke RR ee Roe Roe Oe Rae oe ek Ge R oek Ge Roe Roe Roe Roe Roe Roe gee Object Code Commercial License id ell EE N nassau REE E dief Mana RES EG A DS GR AE A 14 Before you egin EE EE EE Oe 14 Goton eie ie N untesessdeaniaass 15 Don t break it Ping by name Resolving OSE Ed OO N 25 Retrieving a WED EE 28 Sending eMail GE EO N ANENA AREER a 33 di vis N A E 35 eet iet api HE eed RE ED DS EG a Eee ee ve ee ee CTL_IP_CONFIG t is CTL NET ERROR ER an Ei EA E EERE EEE CIL NET IPVA ADDR I N OE NE 43 CTL_NET_IPv4_LOCAL_BROADCAST_ADDR nnnnnnesesseeeoeeoeoseeseeeeeeeeeeeeeeeseeeeeeeeeeeeeeeseeeeeeeeeeeeeeeseeseeeeeee 44 CTL NET_ AC po AA A N 45 En HET PORT ES ee ee ie ge DA ee eg ee Ge es ed 46 CTE SOCKET JU AE EE EE 47 CTL TOP ACCEPT FEN EE n S RENE EEEREN 48 CrossWorks TCP IP Library Contents sie ed do ER EE 49 GIL TEP GET SOCKETS FLAG Tonine es ese gs Eg ee esse see ieke geb beoog sek GE ee ge eg 50 CTE TER PORT OPTIONS ees GER RR Gee EER ee Rea GR r iA 51 CTL TCP SEND FLAG ER EE EN CTL_TCP_SOCKET_CLOSE_TYPE_t
10. This is implemented in the following device families e STM32F1 STM32F2 STM32F4 e LPC1800 LPC4000 LPC4300 e XMC4500 e TMC4129x The following MAC versions are currently known and some of the marketing material from the various devices transcribed Version 3 4 e IEEE 802 3 2002 standard for Ethernet MAC e IEEE 1588 2002 standard for precision networked clock synchronization Present on STM32F1 Version 3 5 e IEEE 802 3 2002 standard for Ethernet MAC e IEEE 1588 2002 standard for precision networked clock synchronization Present on STM32F4 Version 3 6 Present on LPC4300 Version 3 7 e IEEE 802 3 2008 standard for Ethernet MAC e IEEE 1588 2008 standard for precision networked clock synchronization Present on XMC4500 and TMC4129X API Summary Setup designware_emac_v3_init Initialize the network interface Control designware_emac_v3_isr Handle network interrupt 213 CrossWorks TCP IP Library designware emac v3 start Status designware emac v3 first free designware emac v3 version 214 CrossWorks TCP IP Library Start the network interface Return extent of memory consumed Return the Synopsis version of the EMAC CrossWorks TCP IP Library CrossWorks TCP IP Library designware emac v3 first free Synopsis void designware emac v3 first free CTL NET INTERFACE t self Description designware emac v3 first free returns a pointer to the first byte free for use by the application afte
11. ctl net mem free is a wrapper around the free fn member of the singleton instance of the network memory manager see CTL NET MEM DRIVER t ctl net mem free should only be used on buffers allocated with ct net mem alloc xmit or ct net mem alloc data ct net mem free is safe to call from an interrupt service routine or the zero priority main task See Also CTL NET MEM FREE FN t CTL NET MEM DRIVER t ct net mem alloc xmit ct net mem alloc data 106 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl net mem trim Synopsis void ctl1 net mem trim void p size t byteSize Description ct net mem trim is a wrapper around the trim member of the of the network memory manager see CTL NET MEM DRIVER tand ct net mem alloc fn t This is a request to reduce the memory allocated and pointed to by p to byteSize bytes It is guaranteed that byteSize is less than the currently allocated size for p The network memory allocator is not required to trim its memory allocation this call is an indication to the memory allocator that the extra memory will not be used by the network library and the allocator can recover it It is acceptable for the implementation of the underlying trim function to do nothing 107 CrossWorks TCP IP Library CrossWorks TCP IP Library ct net register error decoder Synopsis void ctl1 net register error decoder void Description ct net register error decoder registers an
12. ctl_dns_get_host_by_name 27 CrossWorks TCP IP Library CrossWorks TCP IP Library Retrieving a web page Start of a web browser We build upon the capabilities of previous examples by showing how to grab the contents of a web page from the Internet This example shows how to dump the HTML data of the Rowley Associates home page at www rowley co uk index htm Select and build the project In the examples for your board you ll find a Networking Projects solution and within that a Retrieve Web Page project Double click that project to make it active and press F7 to build Sockets Double click the file example retrieve web page cinthe Source Files folder and it will open in the code editor This example is longer than before but then it does much more than previous examples Once the domain name is resolved the example needs to communicate with the web server in order to download the web page It does this by creating a socket and connecting the socket to the server Open a socket to the host on port 80 s ctl_tcp_socket if s lt CIL_NO ERROR example terminate No sockets available n example check status ctl tcp connect s addr HTONS 80 1000 ctl_tcp_socket creates a new socket and ct tcp connect connects that socket to the server The parameters to ctl_tcp_connect are e The socket created by ctl_tcp_socket e The IP address of the server to connect to The IP address in this example
13. em process the rcvData em and then call ctl_udp_sendto ctl_udp_sendto sendData sendByteCount info 0 You can use the metaData member to store endpoint information for any application specific data set by the MAC layer driver Note The metaData member is intended to be used by IEEE 1588 Precision Time Protocol compliant MAC layers to provide a packet timestamp or at least a pointer to a packet timestamp but the field may be used for any information that needs to be transmitted from the MAC layer to the application layer as part of a UDP datagram See Also CTL_UDP_RECV_FN_t ctl_udp_sendto 58 CrossWorks TCP IP Library CrossWorks TCP IP Library ct arp cache entry Synopsis void ctl1 arp cache entry CTL NET 1Pv4 ADDR t ip addr const CTL NET MAC ADDR t mac_addr Description ct arp cache entry updates the ARP cache to associate the IP address ip addr with the MAC address mac_addr Broadcast MAC addresses are rejected and not entered into the cache You would not usually need to call ctl_arp_cache_entry as ARP management is handled transparently by the network library Thread Safety ctl_arp_cache_entry is thread safe See Also ctl_arp_clear_entry ctl_arp_purge_cache 59 CrossWorks TCP IP Library ct arp clear entry Synopsis void ctl1 arp clear entry CTL NET 1Pv4 ADDR t ip addr Description ct arp clear entry removes the entry for the IP address ip addr in the
14. s CTL TCP SOCKET CONNECTION STATE ocrocsosinscssanornounananeneanonnunsersn 54 CBE TCP SOCKET OPTIONS A occcsccisssccsserouss esersaseesesecszisisscenssevenicatavezsecasestsendnasesonssssvsevarnossav asevseussceetse 55 CTL WDP CONFIGURATION suscaissscciesesscosseisccssevectstssvsissceonssscadeechsevacccobyessesboaleiistessaseesnsbsescabstodsssetgiabes 57 CTL UDP NFO TESE SG EG ee EG RE ee EE ee 58 ad os te NNER AR EE EE 59 ct arp clear entry sd oe AS ie AE AE EE EE CEU ap get TH i e eie ER Se RE RE ee ee ee ee Ee GR ee ee ee eed ede Vo ene ed ve AER A EN 63 ctl arp Oie Med iscsi ccsssscscisiseccasecdessenssssencccatasscniasctibansaestactensiaecacnannesthosteavacteatanasssianceatastasanstionnadiaten 64 ct arp reguest entry ct arp set cache size ct arp set memory allocatoF uuussess sense see ee ee ee ek oek oek oek GEROER oe Roe Roe Renee Rg 67 ad ed dd AE OE EE 68 ad clie SA ol EE OE EE 69 ctl dhcp lease expire time sesse se ee SR ER ese Oe se ese ese ee ese ese ee eek ese ER ee ER ER ee ee ER 70 Ctl dhep lease rebind time ER ERG SR seke RAGE ARe Reede Be isas sees Rees ee ene Re 71 ct dhcp lease renew time ct dns get host by name etl ey Re AE GEE EE EE EEN 74 ad dl Oe ee ee 75 et dns primary servet add sesse see esse dese ies eke age ae geag ieke ee 76 adel Me de iet oc EE EE N ct dns purge cache ctl dns secondary server AGO oinccsscsscsssascissnssscscevesssnvssess
15. unsigned ctl1 tcp get sockets CTL NET PORT t port unsigned flags GAS oes oker unsigned max socket count Description ctl tcp get sockets enumerates the sockets for the port port that match the conditions specified in flags port is specified in network byte order When a TCP server thread is woken up before it can do anything useful it must first fetch a list of active sockets on a per port basis using ct tcp get sockets flags is the bitwise or of one or more of the flags in CTL TCP GET SOCKETS FLAG t The sockets matching the combination of flags are written into the array pointed to by sockets which must have at least max socket count elements Description ctl tcp get sockets returns the number of sockets that matched and were written into the sockets array See Also CTL TCP GET SOCKETS FLAG t 130 CrossWorks TCP IP Library CrossWorks TCP IP Library ct tcp init Synopsis CTL STATUS t ctl_tcp_init unsigned socket count unsigned listener count CTL TCP GEN 1SS FN t issGenCallback Description ctl_tcp_init will attempt to allocate a buffer for its state data from the general heap and then register itself with the IP layer The buffer allocation will be approximately 160 bytes socket_count 48 bytes listener_count Registration with the IP layer requires a small allocation as well ctl_tcp_init must be invoked during initialization prior to calling any other function in the TCP
16. CTL TCP TOO MANY SOCKETS Indicates that an API call could not allocate a socket using ctl_tcp_socket The number of sockets that the application can open is determined by the number of streams that the CTL library supports one socket requires one stream and other components such as the mass storage library will consume shared streams when you use them CTL TCP SOCKET CLOSED Indicates that the other TCP closed the socket whilst the client was waiting for data from the socket In some cases the network library will return CTL_TCP_BAD_SOCKET for the same conditions if on entry to the API call the socket is already closed For socket related errors see ctl_tcp_get_socket_error 42 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL NET IPv4 ADDR t Synopsis typedef unsigned long CTL NET IPv4 ADDR t Description CTL NET IPv4 ADDR t contains a 4 octet IPv4 address held in in network byte order 43 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL NET IPv4 LOCAL BROADCAST ADDR Synopsis define CTL NET IPv4 LOCAL BROADCAST ADDR OEEEEEE RE Description CTL NET IPv4 LOCAL BROADCAST ADDR is the IP broadcast address 255 255 255 255 It is the broadcast address of the zero network 0 0 0 0 0 which in IP standards stands for this network i e the local network Transmission to this address is limited by definition it is never forwarded by routers that connect the local network to the In
17. 0 0 44 bytes 32 time lt lms TTL 64 oO Ping statisties ron On oo 4a Packets Sent 4 Received 4 Lost 0 0 loss Approximate round trip times in milli seconds Minimum Oms Maximum Oms Average Oms Notice that the full name of the host is crossworks rowley co uk This is because the LAN that the board is connected to has a domain name suffix You might have noticed this in the output from ipconfig in the first example 22 CrossWorks TCP IP Library CrossWorks TCP IP Library gt ipconfig Windows IP Configuration Bthernet adapter Local Area Connection Connection specific DNS Suffix rowley co uk Min lood EEvo adress 5 3 8 iets soreAcleQOS 7 seiouil saya TEVA Address 5 6 6 6 6 4 0 6 o 6 LOOM 2e SuDGee Moe a so se ele ese Oo oa oO Derault Gateway a 6 6 6 6 5 6 5 a amp LMCOZW e The full host name is the name that we assigned to the node crossworks with the suffix assigned by the network rowley co uk Job done You now have a functioning Ethernet connection between your PC and your target board using a dynamically assigned IP address and with a friendly name to contact the board The code Set up network using a DHCP assigned IP address include libnet ctl_net_private h include libplatform platform h include libplatform platform_network h include example_support h Assign a fixed MAC address to the NIC Normally this will be blown into OTP or some ot
18. 157 CrossWorks TCP IP Library CrossWorks TCP IP Library CrossWorks TCP IP Library CTL NET MAC DRIVER t Synopsis typedef struct LTICAST_ACCEPT_FN_t multicast_accept_fn I_DEFERRED_READ_FN_t mii_deferred_read_fn I_DEFERRED_READ_RESULT_FN_t mii deferred read result fn SBEANET MAG INTE BNAG SONET ENEEREAGE Go CTL NET MAC UPDATE FN t CTL NET INTERFACE t unsigned ETL NET MAG GET STATE BENE CTE NET TINPERBAGB t CTL NET MAC ADDR t macl addr CELL NET MAC INTT N init _ fn CTL_NET_MAC_UPDATE_FN_t update fn CTL NET MAC GET STATE FN t get state fn CTL NET MAC SEND FN t send fn CTE NET MAC MU CTL NET MAC MULTICAST OUERY EN t multicast guery fn CTL NET MAC MIT WRITE FN t mii write fn CTL NET MAC MIT READ FN t mii read fn CTL NET MAC MI CTL NET MAC ME CTL NET MAC SELECT PHY FN t select phy Tn CTL NET MAC PRIVATE s device CTL NET MAC DRIVER t Associated types typedef CTL STATUS t typedef void typedef CTL MAC STATE t typedef void typedef unsigned CTL NET MAC ADDR t typedef unsigned ie ANERIMAE NS ENDAENA Ee EANE DA NOEREASEA CARI Islan EVAN _je 2 CTL NET MAC ADDR t typedef typedef typedef typedef typedef ET eT eT CT Cr TESTATUS L STATUS TESTATUS LL STATUS L STATUS Description ie EN ie EN Lae oc Lie eC Lie ET
19. ARP cache Thread Safety ct arp clear entry is thread safe See Also ctl_arp_purge_cache 60 CrossWorks TCP IP Library CrossWorks TCP IP Library CrossWorks TCP IP Library ct arp get entry Synopsis unsigned ct1 arp get entry CTL NET MAC ADDR t dst CTL NET IPv4 ADDR t ip addr Description ct arp get entry queries the ARP cache for the MAC address corresponding to the IP address ip addr If the IP address is found in the ARP cache the found MAC address is copied into the MAC address pointed to by mac_addr and a non zero result is returned If the IP address is not found in the ARP cache the MAC address pointed to by mac_addr is zeroed and ctl_arp_get_entry returns zero mac addr can be null to query the presence of an IP to MAC mapping without returning the MAC address of the entry Note ctl_arp_get_entry only queries the cache and does not send an ARP request top the network if the IP address is not found in the cache 61 CrossWorks TCP IP Library CrossWorks TCP IP Library ct arp get ttl Synopsis unsigned long ctl_arp_get_ttl1 void Description ctl_arp_get_ttl returns the currently set time to live for entries in the ARP cache The default time to live is 10 minutes Thread Safety ctl_arp_get_ttl is thread safe See Also ctl_arp_set_ttl 62 CrossWorks TCP IP Library CrossWorks TCP IP Library ct arp print cache Synopsis void ctl1 arp print cache CTL STREAM
20. BAD PORT Indicates that the port passed to ctl_udp_unbind is invalid or is not currently bound CTL TCP TOO MANY PORTS Indicates that you have requested to bind a TCP ports using ct tcp bind but there are no TCP ports left in the TCP port pool You will need to increase the number of ports when calling ctl_tcp_init to initialize the TCP subsystem CTL_TCP_PORT_ACTIVE Indicates that there are active open sockets associated with a port when the port is unbound with ctl_tcp_unbind CTL TCP BAD PORT Indicates that an invalid TCP port has been provided as a parameter Port numbers in API calls must be in network byte order and must specify a valid TCP port number usually between 1 and 65535 41 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL TCP PORT NOT BOUND Indicates that an unbound port parameter has been passed to an API call that requires a bound TCP port Many API calls require bound ports and you try to operate on a port that has not been bound using ctl_tcp_bind you will receive this error CTL_TCP_PORT_IN_USE Indicates that a call to ctl_tcp_bind failed because the port provided is already being listened to In order to specify a different listener for a port the port must be first be unbound using ctl_tcp_unbind CTL_TCP BAD SOCKET Indicates that the socket provided to a network API call is invalid because the socket has been closed either by the client or by the network library or has never been open
21. IP Library CrossWorks TCP IP Library int main void Initialize platform platform_initialize Start networking wait for an IP address example check status example bring up full networking example check status example await assigned ip address Send headers read web page example retrieve web page www rowley co uk in Done return example finish 32 CrossWorks TCP IP Library CrossWorks TCP IP Library Sending e mail Send a mail As a more complex example of interacting with a server here is an example of how to send e mail using an open relay You can send e mail Select and build the project In the examples for your board you ll find a Networking Projects solution and within that a Send E mail project Double click that project to make it active and press F7 to build SMTP server You need to configure the SMTP server for this example to work In the example you will need to configure SMTP_SERVER with the domain name or dotted decimal IP address of your SMTP server and also set Hd USER MAIL ADDRESS to the e mail address of the recipient The code There is nothing new in this example it s just a little longer than retrieving a web page in the previous example Copyright c 2004 2013 Rowley Associates Limited of include lt string h gt include example_support h include libnet ctl_net_api h include libnet extras ctl_s
22. Maximum size of a receive segment This cannot be greater than 1460 for Ethernet transports max owned receive bytes Used to calculate the receive window and slow down the remote TCP if reguired For maximum efficiency it should be a multiple of max receive segment size max send segment size Maximum size of a sense segment This cannot be greater than 1460 for Ethernet transports When sending a segment for this socket the network library will allocate the minimum of this value and what the remote advertises during the connect handshake max owned send bytes Used to slow down application code if reguired This value does not include big external buffers that are passed during blocking ct tcp send For maximum efficiency this should be a multiple of the max send segment size idle socket shutdown In whole seconds Set this to zero if an idle socket should be kept alive forever Otherwise when a socket is idle for longer than this value the network library will gracefully close the socket and recover its resources by initiating a FIN handshake with the remote TCP 55 CrossWorks TCP IP Library CrossWorks TCP IP Library Note This structure sh ould be set prior to a connection being established with a remote TCP For a client socket it means that the application layer may only set a socket s options between the calls to ctl_tcp_socket and ctl_tcp_connect For a server socket it means that the only place to modify the s
23. Overview PHY driver for a SMSC LAN8720A API Summary PHY LAN8720A_PHY_ID PHY ID lan8720a_phy_init_driver PHY driver setup 230 CrossWorks TCP IP Library CrossWorks TCP IP Library LANSZ20A PHY ID Synopsis define LANS720A PHY ID 0x0007COFO Description LAN8720A_PHY_ID is the ID returned by the LAN8720A PHY CrossWorks TCP IP Library CrossWorks TCP IP Library CrossWorks TCP IP Library lan8720a phy init driver Synopsis void lan8720a phy init driver CTL NET PHY DRIVER t self Description lan8720a phy init driver initializes self with functions that implement the PHY state machine for the SMSC LAN8720A 232 CrossWorks TCP IP Library lt Im3s_phy h gt Overview PHY driver for the integrated LM3S Stellaris PHY API Summary PHY LM3S_PHY_ID PHY ID Im3s_phy_init_driver PHY driver setup 233 CrossWorks TCP IP Library CrossWorks TCP IP Library LM3S PHY ID Synopsis define LM3S_PHY_ID 0x0161B410 Description LM3S_PHY_ID is the ID returned by the LM3S Stellaris PHY 234 CrossWorks TCP IP Library CrossWorks TCP IP Library CrossWorks TCP IP Library Im3s phy init driver Synopsis void lm3s phy init driver CTL NET PHY DRIVER t self Description Im3s phy init driver initializes self with functions that implement the PHY state machine for the LM3S integrated PHY 235
24. Overview PHY driver for a Texas Instruments DP83848 API Summary PHY DP83848_PHY_ID PHY ID dp83848_phy_init_driver PHY driver setup 224 CrossWorks TCP IP Library CrossWorks TCP IP Library CrossWorks TCP IP Library DP83848 PHY ID Synopsis define DP83848 PHY ID 0x20005C90 Description DP83848 PHY ID is the ID returned by the DP83848 PHY 225 CrossWorks TCP IP Library CrossWorks TCP IP Library dp83848 phy init driver Synopsis void dp83848 phy init driver CTL NET PHY DRIVER t self Description dp83848 phy init driver initializes self with functions that implement the PHY state machine for the Texas Instruments DP83848 226 CrossWorks TCP IP Library lt ksz8721bl h gt Overview PHY driver for a Micrel KSZ8721BL API Summary PHY KSZ8721BL_PHY_ID PHY ID ksz8721bl_phy_init_driver PHY driver setup 227 CrossWorks TCP IP Library CrossWorks TCP IP Library KSZ8721BL PHY ID Synopsis define KSAaA721B1 PHY ID 0002211610 Description KSZ8721BL_PHY_ID is the ID returned by the KSZ8721BL PHY 228 CrossWorks TCP IP Library CrossWorks TCP IP Library CrossWorks TCP IP Library ksz8721bl phy init driver Synopsis void ksz8721bl phy init driver CTL NET PHY DRIVER t self Description ksz8721bl phy init driver initializes self with functions that implement the PHY state machine for the Micrel KSZ8721BL 229 CrossWorks TCP IP Library lt lan8720a h gt
25. TCP IP Library ct dns init Synopsis Cmi STATYSIL etl1 dnsi init void Description bound UDP ports 75 CrossWorks TCP IP Library CrossWorks TCP IP Library CrossWorks TCP IP Library ct dns primary server addr Synopsis CTL NET 1Pv4 ADDR t ctl1 dns primary server addr void Description ct dns primary server addrreturns the primary DNS server as set in the CTL_IP_CONFIG_t passed to ct net init or or retrieved from a DHCP server If IP addresses are assigned by DHCP ct dns primary server addr will returns an all zero IP address whilst IP negotiation is in progress See Also CTL_IP_CONFIG t ctl_net_init 76 CrossWorks TCP IP Library ct dns print cache Synopsis void ctl1 dns print cache CTL STREAM t s Description ct dns print cache prints the contents of the DNS cache to the stream s Thread Safety ct dns print cache is thread safe if writing to stream s is thread safe 77 CrossWorks TCP IP Library CrossWorks TCP IP Library ct dns purge cache Synopsis void ctl_dns_purge_cache void Description CrossWorks TCP IP Library ctl_dns_purge_cache purges the DNS cache throwing away all cache entries and canceling all outstanding resolves Thread Safety ctl_dns_purge_cache is thread safe 78 CrossWorks TCP IP Library CrossWorks TCP IP Library ct dns secondary server addr Synopsis CTL NET 1Pv4 ADDR t ctl1 dns secondary server addr void
26. a way and that is to register a name using DHCP Select and build the project In the examples for your board you ll find a Networking Projects solution and within that a Ping by Name project Double click that project to make it active and press F7 to build Double click the file example ping by name cinthe Source Files folder and it will open in the code editor In main you ll find a call to ct net set host name before the network is brought up to set the host name of the evaluation board Set our host name ctl1 net set host name crossworks This registers the name of the host with the DHCP server and means that you can ping the board using a friendly name whatever the assigned IP address is See if it works Power up the board and run the code In the CrossWorks Debug Terminal you should see the same as before DHCP awaiting IP address assignment DHCP awaiting IP address assignment DHCP awaiting IP address assignment DEEP Pl address is Moo Ok aa and subnet mass is sk 225 255 0 DHCP IP address is 10 0 0 44 and subnet mask is 255 255 255 0 DEUCE re address is Moo OP da and subaets mass sos 2 5 2E 0 Now you can ping the device by its assigned name crossworks gt ping crossworks Pinging crossworks rowley co uk 10 0 0 44 with 32 bytes of data Reply from 10 0 0 44 bytes 32 time lt lms TTL 64 Reply from 10 0 0 44 bytes 32 time lt lms TTL 64 Reply from 10 0 0 44 bytes 32 time lt lms TTL 64 Reply from 10
27. address uur ese se SR GR ese ese ER GR ese ese ER SR ER ese ER ER ER ee ER EER 100 ct net is multicast ip address sssrinin inasra 101 ctl net is private ip addresS cssssssssssssssssssssosssssssoscsssssnsesssesncsssesnscsssesncssscsnecsseesnecsseesneesseesoes 102 ct net is subnet broadcast addresS sssssssssssscccsescsesssesssneesesnseesesseeessnsecsenssesssnessssneeesenseeesse 103 ad net mem aioe EL N 104 ct net mem alloe MIE ee ee ee E Ge Re ee Ede ee oe ER Re eed RS ee EE ee 105 ctl_net_mem_free 0 se 106 EU ROE memes ie EE ee Ee oe eo ee Pe ee ee de 107 ct net register error decoder ecesscsssesccssesscessseccesssseesssscesnsssessesscesseessenseesesssecesneesesnenecesseeseeneeees 108 ct net scan dot decimal ip addF uu ee Re RE ROER OR oe RR GE RR GE RR oe RE RE RE 109 cetl net scan mac add AA N EE assasin seras asisas Si oaa 6 iE ss 30e 110 a net sel host NaMe ss Ee ee ee Ge ed ee ee 111 ed ed Ee OR E OO OE EE N GUL MVE Tie ele OR ante EE ctl ntp set time RU ON SR AT E eal NR ie N E A A T A AA E E AT is ll SOC usa OE Ee EEA ETE ad ET BE es OE NE EET AEA EATA AEEA Ctl tep BINA EE EA EE A DE N ad solid e ed de ctl tcp connect sees ct tcp get local ip addr ct tcp get local port ctl top get port options OE EE ctl tep get remote ip add RE os Gee ER Ge RR a rarna AE Ani Re ARKAA 124 etl icp ei le Ao ee oe ee 125 ct tcp get socket con
28. an 8 bit value where the most significant four bits define the major version number and the least significant four bits define the minor version number 219 CrossWorks TCP IP Library CrossWorks TCP IP Library lt enc28j60 h gt Overview Driver for a Microchip ENC28J60 MAC and integrated PHY API Summary MAC enc28j60_mac_setup Configure ENC28J60 MAC PHY ENC28J60_PHY_ID PHY ID enc28j60_phy_init_driver Initialize ENC28J60 integrated PHY driver 220 CrossWorks TCP IP Library ENC28J60 PHY ID Synopsis define ENC28J60 PHY ID 0x00831400 Description ENC28J60 PHY ID is the ID returned by the ENC28J60 PHY 221 CrossWorks TCP IP Library CrossWorks TCP IP Library CrossWorks TCP IP Library enc28j60 mac setup Synopsis CTL STATUS t enc28j60 mac setup CTL NET INTERFACE t self GIL SP1 DEVIOE t dev Description enc28j60 mac setup initializes self with functions that implement the MAC interface for the ENC28J60 The ENC28J60 is addressed using the SPI device dev Return Value enc28j60_mac_setup returns a standard status code 222 CrossWorks TCP IP Library CrossWorks TCP IP Library enc28j60 phy init driver Synopsis void enc28j60 phy init driver CTL NET PHY DRIVER t self Description enc28j60 phy init driver initializes self with functions that implement the PHY state machine for the Microchip ENC28J60 integrated PHY 223 CrossWorks TCP IP Library lt dp83848 h gt
29. closed it closing it a second time makes no difference See if it works Power up the board and run the code In the CrossWorks Debug Terminal you will see something similar to this DHCP awaiting IP address assignment DHCP awaiting IP address assignment DHCP awaiting IP address assignment DHCP Using DNS server 1O0 0 0 8 www rowley co uk resolved to 178 236 4 60 Connecting to www rowley co uk 178 236 4 60 Requesting Taray i 200 Os Date Mon 0 Sep 2013 13 17 33 GMT Last Modified Thu Content Type text html Content length ad Connection keep alive Server Amazons3 lt DOCTYPEK HIML gt lt html gt Job done iP address is ooo da and subnet mask is 255 255 255 0 2S Moe ZOLS oe giles CMe You now have a way to communicate with an HTTP server You ll find that many servers will communicate in much the same way a command some headers a blank line and read the response so you have a starting point at least The code Retrieve a web page include libnet ctl_net_api h include libplatform platform h include include example_support h Static data static char line _ buffer 512 static void example retrieve web page const char host const char name CTL_NET_IPv4_ADDR_t addr CI SOEKAP ic SP CTE STATUS t stat char str 16 Try to resolve host stat ctl_dns_get_host_by name host Did this resolve if stat lt CLE NO ERROR
30. data This flag indicates that buf meets the target CPU s requirement for network DMA memory if any and that buf will remain in scope indefinitely Buffer pointer buf will be passed through the stack directly to the MAC layer instead of copying its data to network memory first CTL_TCP_SEND_FREE Perform a zero copy send of dynamic data This flag indicates that buf has been allocated by application code using ctl_net_mem_alloc_data and that the network library is to use ctl_net_mem_free to free it after the remote TCP acknowledges receipt Notes Using the network library the application layer has complete control over packet send coalescing If the CTL_TCP_SEND_PUSH flag is not set then an outgoing packet is only sent when a complete TCP segment has been built up The CTL_TCP_SEND_PUSH flag will cause the buf and any previous queued send data to be sent to the remote TCP If flags is CTL_TCP_SEND_PUSH buf may be null or len may be zero in that case all previous queued data is sent on its way to the remote TCP 136 CrossWorks TCP IP Library CrossWorks TCP IP Library Return Value ct tcp send returns the count of bytes actually sent for success or a negative value for fail A non blocking call timeout is zero that sent at least one byte but less than len bytes is considered successful ct tcp send should not be invoked from the network task with a non zero timeout value In other words do not use the blocking version
31. entire bufLen is received ctl_tcp_recv returns the count actually received for success or a standard CTL error code if the socket failed A non blocking call that received at least one byte but fewer than bufLen bytes is considered successful Note ctl_tcp_recv must not be called from the network task with a non zero timeout In other words do not use the blocking version of this function in a TCP server callback 135 CrossWorks TCP IP Library CrossWorks TCP IP Library ct tcp send Synopsis eds HAvSdik EtINtcpisendler iseer s const void buf size_t len CTL_TIMEOUT_t type CTL TIME t timeout unsigned flags Description ct tcp send sends len bytes from buf to socket s Socket s must first be in the connected state CTL TCP SOCKET STATE CONNECTED or ct tcp send fails Setting the timeout value ms to zero indicates a non blocking call In this case as much data as possible will be passed to the MAC before returning In a blocking call multiple passes across the task synchronization between the network task and the calling task may be required before the entire len is sent Parameter flags may be zero or a bitwise combination of the following CTL_TCP_SEND_PUSH Indicates the end of the current query or response to the remote TCP In other words this is the final call to ctl_tcp_send in a message CTL TCP SEND URGENT Send out of band data CTL_TCP_SEND_NOCOPY Perform a zero copy send of static
32. error decoder with the CrossWorks runtime to decode errors generated by the TCP IP Library 108 CrossWorks TCP IP Library CrossWorks TCP IP Library ct net scan dot decimal ip addr Synopsis CTL NET 1Pv4 ADDR t ctl1 net scan dot decimal ip addr const char str Description ct net scan dot decimal ip addr parses the string pointed to by str as a a dotted decimal IPv4 address and returns that address If the string does not contain a valid IPv4 address ctl_net_scan_dot_decimal_ip_addr returns an all zero IP address See Also ctl_ip_sprint_addr 109 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl net scan mac addr Synopsis CTL STATUS t ctl1 net scan mac addr CTL NET MAC ADDR t dst const char text Description ctl_net_scan_mac_addr converts the zero terminated string text into a MAC address in dst The textual string is in the form OA 1B 2C 4D F7 78 the spaces between the octets can be any character allowing use of both and as separators Return Value ctl_net_scan_mac_addr returns a standard status code See Also ctl_mac_sprint_addr 110 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl net set host name Synopsis void ctl1 net set host name const char name Description ctl net set host name sets the host name to the null terminated string pointed to by name ctl net set host name makes a local copy of the host name which is truncated
33. frame should be called by the network interface s MAC update function for each Ethernet frame the interface receives 177 CrossWorks TCP IP Library CrossWorks TCP IP Library ct net read phy operating mode Synopsis int ctl1 net read phy operating mode CTL NET INTERFACE t self Description ctl net read phy operating mode returns the PHY flags for the network interface net See Also CTL NET PHY DRIVER t 178 CrossWorks TCP IP Library CrossWorks TCP IP Library ct net read phy register Synopsis CTL STATUS t ctl1 net read phy register CTL NET INTERFACE t self int reg Description ctl net read phy register reads PHY register reg from the PHY associated with the network interface self You can call this from any task to read the PHY register as access to the MAC and PHY is protected by a mutex Return Value ctl net read phy register returns a standard status code 179 CrossWorks TCP IP Library CrossWorks TCP IP Library ct net read phy state Synopsis CTL PHY STATE t ctl1 net read phy state CTL NET INTERFACE t self Description ctl net read phy state is a wrapper for the get state fn member of the PHY layer driver See Also CTL NET PHY DRIVER t CTL PHY STATE t 180 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl_net_search_for_first_phy Synopsis CTL_STATUS_t ctl_net_search_for_first_phy CTL_NET_INTERFACE_t net Description ctl_net_search_for
34. is subnet broadcast address if you need to know whether an IP address is a local subnet broadcast address or a limited broadcast address use ct net is local broadcast address Thread Safety ct net is subnet broadcast address is thread safe See Also ct net is local broadcast address 103 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl net mem alloc data Synopsis void ctl1 net mem alloc data size_t byteSize OT TIME t tolicks gt Description ct net mem alloc data is a wrapper around the alloc data member of the of the network memory manager see CTL NET MEM DRIVER tand ct net mem alloc fn t The network memory manager will not use its entire heap for this request Instead a kilobyte or so is held in reserve for future ctl_net_mem_alloc_xmit requests and this routine will fail before dipping into that reserve Buffers allocated with this routine should be freed using ctl_net_mem_free The network memory manager driver will return a word aligned buffer of at least byteSize bytes if successful null for fail If toTicks is non zero and the allocation initially fails the routine will block in the hope that another task or ISR will call ctL_net_mem_free in the interim giving the network memory manager adequate resources to perform the allocation Thread Safety Even with toTicks set to zero ctl net mem alloc data routine is not safe to call from an ISR or a zero priority main CTL t
35. it is sent See Also CTL_UDP_INFO_t ctl_udp_init ctl_udp_bind ctl_net_mem_alloc_data ctl_net_mem_free 147 CrossWorks TCP IP Library CrossWorks TCP IP Library ct udp unbind Synopsis CTL STATUS t ct1 udp unbind CTL NET PORT t port Description ctl_udp_unbind unregisters any associated callback function associated with UDP port port ctl_udp_unbind returns CTL_NO_ERROR if the call was successful i e the port is current bound otherwise an error code See Also CTL_UDP_RECV_FN_t ctl_udp_init 148 CrossWorks TCP IP Library lt ctl_net_hw h gt Overview CrossWorks TCP IP Library This is the private set of functions and types that are required to implement a MAC or PHY driver when porting the Network Library to a new device API Summary Constants CTL_NET_ETHERNET_HEADER_SIZE CTL_NET_ETHERNET_PDU_SIZE Types CTL_ETH_RX_FRAME_t CTL_ETH_TX_FRAME_t CTL NET INTERFACE t MAC CTL MAC STATE t CTL NET MAC DRIVER t ct mac get state ct mac init ct mac send ct mac update ct mac wake net task ctl net process received frame PHY CTL NET PHY DRIVER t CTL PHY ERROR t CTL PHY STATE t ct net get phy name ct net read phy operating mode ct net read phy register ct net read phy state ct net search for first phy ct net update phy ct phy read id The number of bytes in an Ethernet header The size of the PDU of a Ethernet II frame Recei
36. netmask ctl1 net get subnet mask 17 CrossWorks TCP IP Library CrossWorks TCP IP Library Don t be too enthusiastic with messages ctl_delay 1000 Modify the definition of FIXED TIP ADDRESS to match your selected IP address and FTXED_NETMASK to match your subnet mask Power up and attach a network cable to your evaluation board and press F5 to run your code The application downloads and if CrossWorks is configured to stop at main press F5 again to continue running the code In the CrossWorks Debug Terminal you should see something similar to the following but with your selected IP address and subnet mask IP address is 10 0 0 44 and subnet mask is 255 255 255 0 IP address is 10 0 0 44 and subnet mask is 255 255 255 0 IP address is 10 0 0 44 and subnet mask is 255 255 255 0 This is inviting you to ping the board So do it gt ping 10 0 0 44 Pinging 10 0 0 44 with 32 bytes of data Reply from 10 0 0 44 bytes 32 time lt lms TTL 64 Reply from 10 0 0 44 bytes 32 time lt lms TTL 64 Reply from 10 0 0 44 bytes 32 time lt lms TTL 64 Reply from 10 0 0 44 bytes 32 time lt lms TTL 64 ee OD ES PANG statisties Hor Vo oo 44 Packets Sent 4 Received 4 Lost 0 0 loss Approximate round trip times in milli seconds Minimum Oms Maximum Oms Average Oms gt i That s it So you now have a functioning Ethernet connection between your PC and your target board 18 CrossW
37. of this function in a TCP server callback See Also ct net mem alloc data ct net mem free ct tcp get socket state ct tcp get socket error 137 CrossWorks TCP IP Library CrossWorks TCP IP Library ct tcp set port options Synopsis CTL STATUS t ctl1 tcp set port options CTL NET PORT t port Const elm epAEORAEOP ONS EE options Description ctl tcp set port options sets the server options for bound TCP port port The socDefault member of the port options only will be applied for newly created sockets ctl tcp set port options returns CIL NO ERROR if the call was successful otherwise an error code if port is nota bound port See Also CTL TCP PORT OPTIONS t ct tcp get port options 138 CrossWorks TCP IP Library CrossWorks TCP IP Library ct tcp set socket options Synopsis CTL STATUS t ctl1 tcp set socket options CTL SOCKET t s Const erdie ds oer ImOPlkON Smt opsies Description ctl tcp set socket options copy the data pointed to by options to the set of values used by socketsoc This call should be made prior to a connection being established with a remote TCP For a client socket it means that the application layer should only use this function between the calls to ctl_tcp_socket and ctl_tcp_connect For a server socket it means that the appropriate place to call ctl_tcp_set_socket_options is in the accept callback function See Also CTL TCP SOCKET OP
38. only manipulated for segments in the send queue 205 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL TCP SOCKET STATE t Synopsis typedef enum CTL_NCP_SOCKET_STATE_UNALLOCATED TL_NCP_SOCKET_STATE_CLOSED TEANCPESOCKE TESTATE MISEEN TT NEP SOEKET SYN SENT TL NCP SOCKET SYN RECEIVED TL NCP SOCKET ESTABLISHED TL_NCP_SOCKET_FIN_WAITI TL NCE SOCKET FIN WAITZ2 TL NCP SOCKET CLOSE WAIT TL NCP SOCKET CLOSING TL NCP SOCKET LAST ACK TL NCP SOCKET TIME WAIT NRG EP sOEKETAS FEEL Ee E eee ee Description CTL_TCP_SOCKET_STATE_t describes the state of the socket along the lines of RFC 793 CTL_NCP_SOCKET_STATE_UNALLOCATED NOT RFC 793 kind of like Super Duper Closed The RFC assumes that the system has dynamic socket allocation we don t CTL NCP SOCKET STATE CLOSED No connection state at all CTL NCP SOCKET STATE LISTEN Waiting for a connection reguest from any remote TCP and port CTL NCP SOCKET SYN SENT Waiting for a matching connection request after having sent a connection request CTL_NCP_SOCKET_SYN_RECEIVED Waiting for a confirming connection request acknowledgment after having both received and sent a connection request CTL NCP SOCKET ESTABLISHED An open connection data received can be delivered to the user The normal state for the data transfer phase of the connection CTL_NCP_SOCKET_FIN_WAIT1 Waiting for a con
39. sets this member before initializing the PHY using init_fn flags The PHY layer flags including link capability and operating mode state The logical state of the PHY This member must only be written by the update_fn method to reflect the current link state init_fn The MAC layer should call the wrapper version of this function ctl_phy_init during hardware initialization after the MII is initialized update_fn The network task will periodically call the wrapper version of this function ctl_net_update_phy to update the PHY state mutex When user level code wants access to PHY registers this holds off the periodic functions so we can access the PHY ourselves There is no need for direct access to this mutex as the wrapper functions ctl_net_read_phy_register and ctl_net_get_phy_state lock the mutex to prevent simultaneous access by the network task name The device name of the PHY 163 CrossWorks TCP IP Library CrossWorks TCP IP Library See Also ct net update phy ct net get phy state ct net read phy operating mode ctl net read phy register 164 CrossWorks TCP IP Library CTL PHY ERROR t Synopsis typedef enum CTL_PHY_MII_READ_FATLURE PHY_MII_WRITE_FAILURE PHY_RESET_FAILURE PHY_NOT_FOUND PHY_INCORRECT_ID p p p HY UNSUPPORTED ID HY AGAIN CTL PAY BEROBR a9999899 Description CTL_PHY_ERROR_t defines the potential errors from the MII RMII and
40. stat lt CTL_NO_ERROR return stat Initializing the DNS part of the TCP IP Library enables you to resolve human readable domain names such as www rowley co uk into an IP address you can communicate with About DNS In order to resolve a domain name to an IP address you must have already set the domain name server or servers that the TCP IP Library communicates with to resolve the domain name If you are using DHCP to configure the TCP IP Library which we assume from here on the domain name servers are automatically set as part of IP address assignment with DHCP If you are using a static IP address then you must configure the DNS servers the stack uses by passing in the IP addresses of the primary and optional secondary server when initializing the network see ct net init and CTL_IP_CONFIG _t Client code Double click the file example_resolve_domain_name c in the Source Files folder and it will open in the code editor The example is now much smaller 25 CrossWorks TCP IP Library CrossWorks TCP IP Library Resolve a domain name include libnet ctl_net_api h include libplatform platform h include libplatform platform_network h include example_support h int main void CTL_STATUS E staty CTL NET IPv4 ADDR t addr char dot_ipaddr 16 Hi Maglite alie Plat FORM platform initialize Start networking wait for an IP address example check status example bring up full networki
41. A SADPRIK addr Description ctl dns set server sets index entry index of the DNS server list to addr Index 0 is the primary DNS server 1 is the secondary server and so on 84 CrossWorks TCP IP Library CrossWorks TCP IP Library ct eth get mac addr Synopsis CTL NET MAC ADDR t ctl_eth_get_mac_addr void ctl eth get mac addr returns the MAC address set when registering the MAC driver using ct net set mac driver See Also ct net set mac driver 85 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl icmp init Synopsis els TAL Sa teti iecmp init vord Description network library all other type codes fail silently ctl_icmp_init returns CTL NO ERROR on success i e the ICMP subsystem is registered with the IP layer 86 CrossWorks TCP IP Library CrossWorks TCP IP Library ct ip sprint addr Synopsis char ctl1 ip sprint addr char dst CTL NET IPv4 ADDR t addr Description ct ip sprint addr converts the address addr to dotted decimal notation and writes the result to the object pointed to by dst dst must be 16 characters or more for three dotted decimal octets plus a terminating zero Return Value ctl_ip_sprint_addr returns dst 87 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl mac addr is broadcast Description ct mac addr is broadcast returns true if the address addr is a broadcast address A MAC address with every bit set to one is a
42. ATUS t ctl1 phy read id CTL NET INTERFACE t self unsigned long id Description ctl_phy_read_id reads the PHY device identification register The ID is returned with the least significant four bits which indicates the PHY revision set to zero Return Value ctl_phy_read_id returns a standard status code 185 CrossWorks TCP IP Library CrossWorks TCP IP Library ct phy reset Synopsis CTL STATUS t ctl_phy_reset CTL NET INTERFACE t self Description ctl_phy_reset resets the PHY using the standard BMCR register Return Value ctl_phy_reset returns a standard status code 186 CrossWorks TCP IP Library lt ctl_net_private h gt API Summary IP CTL_IPV4_HEADER amp CTL_IP_STATS_t Utility ctl_eth_tx_frame_total_count ctl_ipv4_rx_payload_start Transmission Frames ctl_eth_alloc_tx_frame ctl_eth_free_tx_frame ARP ctl_arp_init IP Function ctl_ipv4_rx_payload_byte_count Utility functions ctl_ipv4_make_multicast_mac_addr TCP ctl_net_calc_cksum ctl_net_normalize_cksum_and_comp ctl_net_sum_bytes ctl_tcp_register_stats UNASSIGNED GROUP ctl_dns_register_stats CrossWorks TCP IP Library IPv4 header IP statistics Compute total Ethernet frame size Get a pointer to receive frame s payload Allocate a transmission frame Free a transmission frame Initialize ARP Calculate IPv4 payload length Create a multicast MAC address Calculates the TCP checksum over 16
43. CP IP Library ctl_tcp_get_local_ip addr Synopsis CTL_NET_IPv4_ADDR_t ctl_tcp_get_local_ip_addr CTL_SOCKET_t s Description ctl_tcp_get_local_ip_addr returns the IP address of the TCP partner of socket soc or zero if there is an error The local IPv4 address is returned in network byte order 121 CrossWorks TCP IP Library CrossWorks TCP IP Library ct tcp get local port Synopsis EGTI NET PORT t et1 tcepi get local port CTE_SOCKET_t soc Description ct tcp get local port returns the local port number for socket soc or zero if there is an error The local remote port is returned in network byte order See Also ctl tcp get remote port ct tcp get remote ip addr 122 CrossWorks TCP IP Library CrossWorks TCP IP Library ct tcp get port options Synopsis CTL STATUS t ctl1 tcp get port options CTL NET PORT t port GREEP ERORTAEORT HON AG ope ONSI Description ctl tcp get port options copies the port options used by a server on TCP port port to the buffer pointed to by options port is specified in network byte order See Also CTL TCP PORT OPTIONS amp ct tcp set port options CIL TCP SOCKET OPTIONS t ctl tcp get socket options ctl tcp set socket options 123 CrossWorks TCP IP Library CrossWorks TCP IP Library ct tcp get remote ip addr Synopsis CTL NET IPv4 ADDR t ctl1 tcp get remote ip addr CTL SOCKET t soc Description ctl tcp get remote ip ad
44. CP_SOCKET_STATE_t TCP socket states 203 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL TCP APP LAYER CMD Synopsis typedef enum cule Nomey lcBlockedOnWrite 1cBlockedOnRead Ne Conmec ty 1cConnectAndBlock 1cShutdown leCloseHard lcCloseGraceful lcLingeringClose lcRecycle esel IU NPS Ibe CMI ic 9 oo 9 OD 9 9 DY D 204 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL TCP SEGMENT _t Synopsis typedef struct mr ners HEMEMNTAS me de size t allocatedByteSize size t byteCount unsigned long segStart CTL TIME t timeStamp unsigned long freeExternalBuf unsigned short sentCount unsigned char flags unsigned long data CIL_TCP_ SEGMENT E Description CTL_TCP_SEGMENT_t describes a single TCP segment in a transmit or receive queue next The next segment in the list null indicates no further segments allocatedByteSize The number of bytes allocated to segment payload data in the data member byteCount The number of valid payload bytes in the payload data This will be less than or equal to allocatedByteSize segStart The segment start sequence number timeStamp The last sent time for a transmit segment or received time for a receive segment freeExternalBuf Additional memory to free when the segment is itself freed Only transmit frames set this to a non null value sent Count A count of the number of times this frame has been sent this is
45. CTL NET NOT UP Indicates that a call to ct dns get host by name timed out without the network stack coming up 40 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL NET UNREACHABLE Indicates that a network packet needs to be delivered to an IP address that has no route This can happen for instance when the packet has a non local IP address which must be delivered to the gateway and no gateway has been configured either statically or by DHCP CTL DNS HOST NAME ERROR Indicates that a host name is invalid for instance it has a trailing period foo bar is invalid or the host name has more than 47 characters CTL_DNS_RESOLVE_IN_PROGRESS Indicates that the requested host name is already being resolved Typically this status is returned by ctl_dns_get_host_by_name when a non zero timeout is specified and the name did not resolve before the timeout CTL_DNS_OUT_OF_MEMORY Indicates that the DNS resolver could not allocate memory using the DNS memory allocator when queuing a DNS request CTL_DNS NAME UNKNOWN Indicates that the DNS resolver could not resolve the host name CTL DNS NO DNS SERVER Indicates that no DNS server has been defined in order to resolve reguests CTL UDP TOO MANY PORTS Indicates that all UDP ports are bound and no unused port exists when using ct udp bind CTL UDP PORT IN USE Indicates that the client tried to bind a port using ct udp bind but that port has already been bound CTL UDP
46. DDR t addr Description ct net is autoip address determines whether addr is a IPv4 link local Auto IP address on the local subnet ct net is autoip address returns non zero if addr is an Auto IP address on the local subnet and zero if not Auto IP addresses are defined by RFC 3927 to be the range 169 254 0 0 169 254 255 255 169 254 16 prefix with subnet mask 255 255 0 0 Thread Safety ctl_net_is_autoip_address is thread safe 98 CrossWorks TCP IP Library CrossWorks TCP IP Library ct net is local broadcast address Synopsis unsigned ctl1 net is local broadcast address CTL NET IPv4 ADDR t addr Description ct net is local broadcast address determines whether addr is an local subnet broadcast address that is the address addr is either the limited subnet broadcast address 255 255 255 255 or the subnet broadcast address Thread Safety ct net is local broadcast address is thread safe See Also ct net is subnet broadcast address 99 CrossWorks TCP IP Library CrossWorks TCP IP Library ct net is local ip address Synopsis unsigned ctl1 net is local ip address CTL NET IPv4 ADDR t addr Description ctl net is local ip address determines whether addr is an IP address on the local subnet ctl_net_is_local_ip_address returns non zero if addr is known to be on the local subnet and zero if not Thread Safety ctl_net_is_local_ip_address is thread safe 100 CrossWorks
47. ERNET HEADER SIZE 6612 Description CTL NET ETHERNET HEADER SIZE defines the number of bytes in an Ethernet ll header The Ethernet header comprises six bytes of source MAC address six bytes of destination MAC address and two bytes for the EtherType field Note that we do not support 802 10 VLAN tagging nor do we support non Ethernet LAN protocols that rely on IEEE 802 2 LLC encapsulation at present 155 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL NET ETHERNET PDU SIZE Synopsis define CTL NET ETHERNET PDU SIZE 1500 Description CTL NET ETHERNET PDU SIZE defines the number of bytes of payload data the network PDU in an Ethernet ll frame In general when dealing with Ethernet MAC drivers we have A 16 bit padding short 2 bytes Required to align TCP headers Destination MAC 6 bytes Source MAC 6 bytes Ethernet Type Frame Size 2 bytes 16 bits including padding Payload of 1 500 bytes FCS 4 bytes nO U BUY N Excluding the padding 1518 bytes Including the padding 1520 bytes which is divisible by four 156 CrossWorks TCP IP Library CTL NET INTERFACE Synopsis typedef struct CTL NET MAC DRIVER t mac CTL NET PHY DRIVER t phy CTL NET INTERFACE t Description CTL NET INTERFACE t describes a single network interface Structure mac The MAC driver that the network interface uses phy The PHY driver associated with the MAC interface
48. ETHERNET HEADER SIZE iis eiers esse etes KERR Gees seed eene ese Gegee Reede ee Ra ene 155 CTE NET ETHERNET PDU SIF sessies iese ee ese ee ses iiair kepe boe 156 CTL_NET_INTERFACE AA N E 157 CTL NET MAG DRIVER ESE Eg ie ee A ee Ge EG Ge ee ae 158 CTL NET MAC MI DEFERRED READ FN t uueeusseessenseenseen sees ees gees eee een ee nee e ee e gees oe seen een geoes ees 160 CTI NET MER DRIVER ee esse sesde ie gee dees sei si eek er esse ese ese oe ee 161 CTL NET PAY DRIVER t iste sscsascccscsssccnsvasencsavecuassechavavcseateccuassceonsadcteassecuavaceendascausvasrassaveteassertax 163 CTL PHY ERROR t CTL PHY STATE t eke nl AE EE EE T ctl mac ie AA AE ct mac mii deferred read 0 0 esssssssssssesccssssscessesccenseecesseecesnsessenseesssnsesesnsessesseesesneessenseesesneeseeneeesene 169 ct mac mii deferred read _result 0 esse esse ee PER ee ee Ge ee ee ee ee ee ee 170 ad sk ATU MOA EE eo ee ee ei EE 171 Gil UME sede ed es De ee AA RA ee ctl mae update scicca ccssscesccaseesdecssacutacssctusvissbcuiestuvessstostcvsasesced RR R E ctl_mac_wake_net_task ct net do mac dis conneEt ccisscasscscesssessssescissssccosscontetsoasssnscedaieesSsstdesectssadsbisciastenctansanseceveceaveandetbens 175 ctl net get phy name 1 cesssssscsssscssescssescsssccsssccsseccsseccssecssseccsseessncesssecsssccssseessscesssscsnscessseerseeesssses 176 ctl net process received frame sscsssssssesseessscsssesssesseessecsssesseesseessec
49. P address in this but there is an option to start up the DHCP client subsystem to manage acquisition of DHCP assigned IP addresses See if it works Power up and attach a network cable to your evaluation board and press F5 to run your code The application downloads and if CrossWorks is configured to stop at main press F5 again to continue running the code In the CrossWorks Debug Terminal you should see something similar to the following but with your DHCP assigned IP address and subnet mask DHCP awaiting IP address assignment DHCP awaiting IP address assignment DHCP awaiting IP address assignment DHCP EP address is Hok Oo oa and subuet mass is zoo Zo ZO orl DACP re address s mI ORONO 4a and subnet mass sos 225 2E 0 DHCP IP address is 10 0 0 44 and subnet mask is 255 255 255 0 You can ping the device to make sure that it does indeed work 20 CrossWorks TCP IP Library CrossWorks TCP IP Library Job done You now have a functioning Ethernet connection between your PC and your target board using a dynamically assigned IP address However it s a bit of a bore to type in IP addresses each time and as the IP address may change how do you know which IP address to use 21 CrossWorks TCP IP Library CrossWorks TCP IP Library Ping by name Your third TCP IP Library application What would be great is if your evaluation board had a name rather than an address so we can simply ping the name of the board Well there is
50. PHY 165 CrossWorks TCP IP Library CrossWorks TCP IP Library CrossWorks TCP IP Library CTL PHY STATE t Synopsis typedef enum Ent PAY STATES BARROR CTL PHY STATE NO LINK CTL PHY STATE NEGOTIATING CTL PHY STATE LINKED CTL PHY STATE INITIALIZE Ne tEPE YES FEE ic 2 Description CTL PHY STATE tisthe set of values that a PHY driver should report as its state to the outside world even if its actual state machine is more complicated than that represented here CTL PHY STATE INITIALIZE Indicates that the PHY requires initializing CTL_PHY_STATE_ERROR An error prevents the PHY from operating CTL_PHY_STATE_NO_LINK The Ethernet cable or other media is unplugged CTL_PHY_STATE_NEGOTIATING The PHY is negotiating duplex and transmission rate with its partner CTL_PHY_STATE_LINKED The PHY and its partner have completed negotiating the link is active See Also ctl_net_get_phy_state 166 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl_mac_get_state Synopsis CTL_MAC_STATE_t ctl_mac_get_state CTL_NET_INTERFACE_t self Description ctl_mac_get_state returns the MAC state for the network interface self 167 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl mac init Synopsis CTLES TATUS At etl mae init TT NEH TNHEREAGBI H self Description init fn member of the the CTL NET MAC DRIVER t driver You need to call ct mac init from your application code ct m
51. TCP IP Library ct udp sendto Synopsis void ctl_udp_sendto void data size_t byte_count eonst PTi UPP_INPO_t info unsigned flags Description ctl_udp_sendto sends a UDP datagram to a remote host The member other_port of info is the remote port and the member otherlpAddr of info is the remote IP address ctl_udp_sendto will return almost immediately after the outgoing datagram has been queued for transmission by the MAC layer or queued for ARP hold at the IP layer The UDP datagram will be dropped by the network library if The destination IP address is not on the local subnet as returned by ctl_net_is_local_ip_address and no gateway is configured or e The network library cannot allocate an Ethernet transmission frame for the datagram or e The network library cannot allocate network memory for the datagram payload flags may be zero or one of the following CTL_UDP_SENDTO_NOCOPY Perform a zero copy send of static data This flag indicates that data meets the target CPU s requirement for network DMA memory if any and that data will remain in scope indefinitely Buffer pointer data will be passed through the stack directly to the MAC layer instead of copying its data to network memory first CTL_UDP_SENDTO_FREE Perform a zero copy send of dynamic data This flag indicates that data was allocated by application code using ctl_net_mem_alloc_data and that the library is to use ctl_net_mem_free to free it after
52. TCP IP Library CrossWorks TCP IP Library ct net is multicast ip address Synopsis unsigned ctl1 net is multicast ip address CTL NET IPv4 ADDR t addr Description ct net is multicast ip address determines whether addr is an IP multicast address ct net is multicast ip address returns non zero if addr is known to be a multicast address zero if not Thread Safety ct net is multicast ip address is thread safe 101 CrossWorks TCP IP Library CrossWorks TCP IP Library ct net is private ip address Synopsis unsigned ctl1 net is private ip address CTL NET IPv4 ADDR t addr Description ctl net is private ip address determines whether addr is a private IPv4 address on the local subnet ctl_net_is_private_ip_address returns non zero if addr is a private address zero if not The private address ranges are 10 0 0 0 10 255 255 255 10 8 prefix 172 16 0 0 172 31 255 255 172 16 12 prefix and 192 168 0 0 192 168 255 255 192 168 16 prefix Thread Safety ctl_net_is_private_ip_address is thread safe 102 CrossWorks TCP IP Library CrossWorks TCP IP Library ct net is subnet broadcast address Synopsis unsigned ctl1 net is subnet broadcast address CTL NET IPv4 ADDR t addr Description ct net is subnet broadcast address determines whether addr is an IP subnet broadcast address the limited broadcast address 255 255 255 255 is not considered a subnet broadcast address by ctl net
53. TIONS t ctl_tcp_get_socket_options 139 CrossWorks TCP IP Library CrossWorks TCP IP Library ct tcp shutdown Synopsis void ctl1 tcp shutdown CTL SOCKET t s Description ct tcp shutdown begins the three way shutdown handshake on socket soc after all outgoing data has been sent Socket soc s remote TCP partner is sent a FIN packet indicating end of stream Half open connections are not supported the classic socket s how parameter is always SD_BOTH See Also ctl_tcp_socket ctl_tcp_connect ctl_tcp_send ctl_tcp_recv ctl_tcp_close_socket 140 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl_tcp_socket Synopsis CTE SOCKET t etl tcp socket void Description ctl_tcp_socket fetches a TCP socket from the pool of unused sockets ctl_tcp_socket returns a socket index if successful or zero for fail i e no sockets were available for use Once a socket is allocated application code must make a call to ctl_tcp_connect within 100 CTL TIME t units or the socket will be reclaimed by the network library See Also CTL_SOCKET t ctl_tcp_connect ctl_tcp_send ctl_tcp_recv ctl_tcp_shutdown ctl_tcp_close_socket 141 CrossWorks TCP IP Library CrossWorks TCP IP Library ct tcp unbind Synopsis CIES TATUS GE etlliteplunbind ET NE P BERIG port Description ctl_tcp_unbind tells the TCP layer to stop accepting connections on TCP port port port is specified in network byte order
54. _allocator is thread safe 81 CrossWorks TCP IP Library CrossWorks TCP IP Library ct dns set primary server addr Synopsis void ctl1 dns set primary server addr CTL NET IPv4 ADDR t addr Description ctl dns set primary server addr sets the primary DNS server IP address to addr Note Other parts of the network library may overwrite the address set by this function for instance when DHCP negotiation is complete ct dns set primary server addrand ctl dns set secondary server addrare decoupled from the rest of the DNS resolver so that you can use DHCP with assigned DNS server addresses set without automatically pulling in the resolver code 82 CrossWorks TCP IP Library CrossWorks TCP IP Library ct dns set secondary server addr Synopsis void ctl1 dns set secondary server addr CTL NET IPv4 ADDR t addr Description ct dns set secondary server addr sets the secondary DNS server IP address to addr Note Other parts of the network library may overwrite the address set by this function for instance when DHCP negotiation is complete ct dns set primary server addrand ctl dns set secondary server addrare decoupled from the rest of the DNS resolver so that you can use DHCP with assigned DNS server addresses set without automatically pulling in the resolver code 83 CrossWorks TCP IP Library CrossWorks TCP IP Library ct dns set server Synopsis void ctl1 dns set server int index ETA NES E
55. _connections value for that port If that check is passes a socket is allocated and the port s accept callback is invoked to make the final pass fail judgment For example unsigned tcpAcceptCallbackFn SOCKET s SOCKET s is not yet readable or writable but does have valid endpoint information You may choose to accept or reject the connection based upon the remote TCP s IP address for example If the connection is accepted ctl_tcp_use_callback or ctl_tcp_use_event should be called to set up processing of the TCP data Now is the time to adjust per socket memory limits using Cel_tep set socket _options before ne response is made to the remote TCP s synchroization packet if we accept connection return 1 else return 0 48 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL TCP GEN ISS FN t Synopsis typedef unsigned long CTL TCP GEN ISS FN t void Description CTL_TCP_GEN_ISS_FN_t describes a callback function to generate TCP initial send segment numbers The application must supply an instance of this which must generate unpredictable numbers 49 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL TCP GET SOCKETS FLAG t Synopsis typedef enum CTL_TCP_GET_SOCKETS_CONNECTING Emil CESCE N OCKE EONNEETEP CTE TCE GET SOCKETS READABLE CIMT CPeGETE SOCKET SL TRIGEERED Emil CPeGE TES SOCKET Sah SED Citi CEA Chimes CKE om EnAGmer
56. _first_phy tries to read the PHY identification registers from each PHY on the MAC interface net starting at address zero and progressing through address 31 If a PHY is found ctl_net_search_for_first_phy returns the address corresponding to that PHY and the PHY address is set in the network interface s PHY driver If no PHY is found ctl_net_search_for_first_phy returns CTL_PHY_NOT_FOUND Return Value ctl_net_search_for_first_phy returns a standard status code 181 CrossWorks TCP IP Library ctl net set mem driver Synopsis void ctl1 net set mem driver const CTL NET MEM DRIVER t mem Description ctl net set mem driver sets the memory driver to mem 182 CrossWorks TCP IP Library CrossWorks TCP IP Library CrossWorks TCP IP Library ct net update phy Synopsis void ctl1 net update phy CTL NET INTERFACE t self Description ctl net update phy is a wrapper around the update fn of the PHY layer driver It is called periodically by the CTL stack task when nothing else is happening 183 CrossWorks TCP IP Library CrossWorks TCP IP Library ct phy lm3s init driver Synopsis void ctl1 phy lm3s init driver CTL NET PHY DRIVER t self Description ct phy Im3s init driver initializes driver with functions that implement the PHY state machine for the Luminary Stellaris integrated PHY 184 CrossWorks TCP IP Library CrossWorks TCP IP Library ct phy read id Synopsis CTL ST
57. ac init returns a MAC layer or PHY layer error status See Also CTL NET MAC DRIVER amp ctl_phy_init 168 CrossWorks TCP IP Library CrossWorks TCP IP Library ct mac mii deferred read Synopsis CTL STATUS t ctl1 mac mii deferred read CTL NET INTERFACE t net ant reg Description ct mac mii deferred read is a wrapper around the mii deferred read fn member of the network MAC driver The valid range for devAddr is 0 through 31 and needs to match the PHY chip s physical address which is typically set on the PHY hardware using strapping pins See your PHY chip s datasheet for valid values of reg You can retrieve the result of the deferred read using ct mac mii deferred read result See Also ct mac mii deferred read fn t CTL NET MAC DRIVER t ct mac mii deferred read result 169 CrossWorks TCP IP Library CrossWorks TCP IP Library ct mac mii deferred read result Synopsis CTL STATUS t ctl1 mac mii deferred read result CTL NET INTERFACE t net Description ct mac mii deferred read result returns the result of the last read of the MII management interface without blocking or busy wait This is a wrapper around the mii_deferred_read_result_fn member of the network driver Return values are the same as ctl_mac_mii_read negactive for failure a number between 0 and OxFFFF inclusive for success See Also ctl_mac_mii_deferred_read_fn_t CTL_NET_MAC_DRIVER_t 170 CrossWorks TCP IP Li
58. asis Assign event group to socket Register an accept callback for a port Reserve TCP listener for TCP port Close a socket Connect a socket to port on a remote host Get socket s local IP address Get socket s local port Get options for a TCP port Get socket s local IP address Get socket s remote port 35 CrossWorks TCP IP Library ct tcp get socket connection state ct tcp get socket error ct tcp get socket options ct tcp get sockets ctl_tcp_init ctl_tcp_look_ahead ctl_tcp_push ctl_tcp_read_line ctl_tcp_recv ctl_tcp_send ctl_tcp_set_port_options ctl_tcp_set_socket_options ctl_tcp_shutdown ctl_tcp_socket ctl_tcp_unbind ctl_tcp_use_callback ctl_tcp_use_event UDP CTL_UDP_CONFIGURATION_t CTL_UDP_INFO_t ctl_udp_bind ctl_udp_init ctl_udp_sendto ctl_udp_unbind DHCP ctl_dhcp_init ctl_dhcp_lease_expire_time ctl_dhcp_lease_rebind_time ctl_dhcp_lease_renew_time ctl_net_domain_name_suffix DNS ctl_dns_get_host_by_name ctl_dns_get_server ctl_dns_init ctl_dns_primary_server_addr CrossWorks TCP IP Library Get socket state Get socket error Get socket options Enumerate sockets for port Initialize TCP layer Look ahead in socket data Push data on socket to network Read a line of text from a socket Receive from socket Send data to socket Set options for a TCP port Set socket options Shut down a socket Fetch a TCP socket from the pool of unused socket
59. ask See Also CTL NET MEM DRIVER t ct net mem alloc xmit ct net mem free 104 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl net mem alloc xmit Synopsis void ctl1 net mem alloc xmit size_t byteSize CTL TIME t tolicks Description ctl_net_mem_alloc_xmit is a wrapper around the alloc_xmit member of the singleton instance of the network memory manager see CTL_NET_MEM_DRIVER_t and ctl_net_mem_alloc_fn_t The network library memory manager attempts to use its entire heap to satisfy this request Buffers allocated with this routine should be freed using ctl_net_mem_free The network memory manager driver returns a word aligned buffer of at least byteSize bytes when successful null for fail If toTicks is non zero and the allocation initially fails ct net mem alloc xmit blocks in the hope that another task or ISR will call ctl net mem free in the interim giving the network memory manager adequate resources to perform the allocation Thread Safety Even with toTicks set to zero ct net mem alloc xmit is not safe to call from an interrupt service routine See Also ctl_net_mem_alloc_data ct net mem free CTL_NET_MEM_DRIVER_t 105 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl net mem free Synopsis void ctl1 net mem free void p Description ctl net mem free frees the object pointed to by p if p is a null pointer ct net mem free does nothing
60. bit data Normalize and complement a calculated TCP checksum Calculates the TCP checksum over 16 bit data Register TCP statistics Register statistics for the DNS module 187 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL IPV4 HEADER t Synopsis typedef struct unsigned short __required_align unsigned char ethDstMac unsigned char ethSrcMac unsigned short ethType unsigned char ipVerHl unsigned char ipDifServEcn unsigned short ipTotalLen unsigned short ipIdent unsigned short ipFlagsFragOffst unsigned char ipTtl unsigned char ipProtocol unsigned short ipHdrChecksum unsigned long ipSrcAddr unsigned long ipDstAddr unsigned short ipOptions CTL_IPV4_HEADER_t Description CTL_IPV4_HEADER_t describes the layout of the IPv4 header We include the Ethernet header because they are always adjacent But this is the last layer we can do this with Because of the variable length ipOptions field we can t fix where the start of the transport or user datagram layer is after the IP layer 188 CrossWorks TCP IP Library CTL_IP_STATS_t Synopsis typedef struct long long long long long long long long long long long long rxPackets badRxHdrSize checksumFail badRxSize promiscousPacket rxBroadcastPacket badRxProt sendFragMallocFail unsupportedProtocol txFramesDropped txFramesHeldForARP txFramesDirectToMAC EMIL Ie SIEAMUS ip Description CTL_IP_STATS_t
61. brary CrossWorks TCP IP Library ct mac mii read Synopsis CTL STATUS t ctl1 mac mii read CTL NET INTERFACE t net ant reg Description ct mac mii read busy waits until the result is available This is a wrapper around the mii read fn member of the network MAC driver The valid range for devAddr is 0 through 31 and needs to match the PHY chip s physical address which is typically set on the PHY hardware using strapping pins See your PHY chip s datasheet for valid values of reg Return values are negative for failure a number between 0 and OxFFFF inclusive for success See Also ctl_mac_mii_read_fn_t CTL NET MAC DRIVER t ctl_mac_mii_deferred_read 171 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl mac send Synopsis void ctl1 mac send CTL ETH TX FRAME t frame Description ct mac send sends the Ethernet frame frame to the MAC for transmission Note that this can be called from any thread not just the network thread dealing with TCP segments For instance UDP frames are sent in the context of the sending thread 172 CrossWorks TCP IP Library CrossWorks TCP IP Library ct mac update Synopsis void ct1 mac update unsigned isHousekeeping Description ctl_mac_update is a wrapper for the update method of the network interface 173 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl mac wake net task Synopsis void ctl1 mac wake net task void Description
62. broadcast address i e address FF FF FF FF FF FF Thread Safety ctl_mac_addr_is_broadcast is thread safe 88 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl_mac_addr_is_null_or_empty Description ct mac addr is null or empty returns true if the address addr is null or the address pointed to is an all zero address A MAC address with every bit set to zero is a null address i e address 00 00 00 00 00 00 Thread Safety ctl_mac_addr_is_null_or_empty is thread safe 89 CrossWorks TCP IP Library CrossWorks TCP IP Library ct mac sprint addr Synopsis char ctl1 mac sprint addr char dst const CTL NET MAC ADDR t addr char sep Description ct mac sprint addr converts the address addr to hexadecimal notation using sep to separate each octet and writes the result to the object pointed to by dst dst must be 18 characters or more for six hexadecimal octets separators and a terminating zero Return Value ctl_mac_sprint_addr returns dst 90 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl net domain name suffix Synopsis char ctl1 net domain name suffix void Description ct net domain name suffix returns domain name suffix provided by the DHCP server when an IP address is assigned If no domain name suffix is set by the DHCP server or no address has been assigned by the DHCP server ctl net domain name suffix returns zero Thread Safety ct net domain na
63. ce is personalized as Vf part of production define FIXED MAC ADDRESS bc 28 d6 ff ff ff i Thread PEER DE define NET TASK PRIORITY 200 Network interface static CTL NET INTERFACE t nic static void bring up network void CELETTE COMMPINE Ie ASE L Clear network IP configuration for population memset ip config 0 sizeof CTL_IP_CONFIG_t Assign fixed IP address and subnet mask ip_config ip_addr ctl_net_scan_dot_decimal_ip_addr FIXED_IP_ADDRESS ip_config subnet_mask ctl_net_scan_dot_decimal_ip_addr FIXED NETMASK Assign a fixed MAC address to the NIC example check status ctl_net_scan_mac_addr amp nic mac mac_addr FIXED MAC ADDRESS Bring up network example check status ctl mac init amp nic Bring up the IP network example check status ctl net init NET TASK PRIORITY amp ip_config Bring up only ICMP to respond to pings example check status ctl_icmp_init int main void char dot_ipaddr 16 dot_netmask 16 didi Bigiiieneuiliveaes joyll eye sie yiain platform_initialize Configure the NIC for this platform example check status platform configure network amp nic Start network bring up network Idle away the network task responds to pings for Dump message inviting a ping printf IP address is s and subnet mask is s n ct1 ip sprint addr dot ipaddr ctl_net_get_ip_address ct1 ip sprint addr dot
64. che Purge the DNS cache Get secondary DNS server address Set DNS time to live Set DNS request memory allocator Set primary DNS server IP address Set secondary DNS server IP address Set DNS server list entry Initialize NTP subsystem Return IPv4 address of NTP server Set IPv4 address of NTP server Initialize ICMP IP configuration structure IPv4 network address IP local network broadcast address Get gateway IP address Get system IP address Get system subnet mask Is an IP address a link local Auto IP address Is an IP address a local broadcast IP address Is an IP address on the local subnet Is an IP address a multicast IP address Is an IP address a private address Is an IP address a subnet broadcast IP address Scan a dotted decimal IPv4 address Replace ARP cache entry Clear ARP cache entry Get ARP cache entry Get the ARP time to live Display the ARP cache Purge ARP cache 37 CrossWorks TCP IP Library ct arp redguest entry ct arp set cache size ct arp set memory allocator ct arp set tt MAC CTL_NET_MAC_ADDR_t ctl_eth_get_mac_addr ctl_mac_addr_is_broadcast ctl_mac_addr_is_null_or_empty ctl_net_scan_mac_addr Memory ctl_net_mem_alloc_data ctl_net_mem_alloc_xmit ctl_net_mem_free ctl_net_mem_trim Utility ctl_ip_sprint_addr ctl_mac_sprint_addr ctl_net_register_error_decoder CrossWorks TCP IP Library Generate an ARP request for an IP address Set
65. csssccsssccsssccsssccsssccssecessscesscessssessnecssssecsseecenecesneests 223 MACUSER he EE N Ee ee ke Ee ee seed Ee DP83848 PHY ID dp83848 phy initAHVER siese see EIERS ERG Roe eene enii AE see oes dee koes dend 226 E ETAS TAPA ST AUN RA EO ieee 227 WS ZS 72 IN PHY DD RE EE ina Er a REEE 228 ksz8721bl phy init driver 0 eesssssssssscssscccssccssseccssccsssccesscssssccssscesssccsscesnecssseessnecssncccssecssneecsneessnees 229 slae DAM RE E E A T caress LAN8720A_PHY_ID lan8720a phy init driver 0 cssssssscsssscsssscsseccsssccsseccsssccsseccsnscsssccssscesssecssscesssccssccssscesssccssscesseeeses 232 des Ao a SA OE 233 HE od dd DE EE EE 234 Ede dd N 235 CrossWorks TCP IP Library CrossWorks TCP IP Library CrossWorks TCP IP Library The CrossWorks TCP IP Library is a collection of functions and device drivers that add TCP IP networking to your application We have primarily designed the TCP IP Library to work well on reduced memory real time embedded systems that require network connectivity but you can equally well use the library on faster processors with more memory The TCP IP Library is designed to run exclusively in the CrossWorks tasking environment if your application doesn t use tasking and you wish to use this product then you must convert your application to run in a tasking environment which is simple enough to do If you are using some other real time operating system then using the TCP IP Library is not viable and should see
66. ct arp set memory allocator sets ARP memory allocator to allocator If allocator is zero the ARP cache uses the system memory allocator ct system memory allocator Thread Safety ct arp set memory allocator is thread safe 67 CrossWorks TCP IP Library CrossWorks TCP IP Library ct arp set tt Synopsis void ctl1 arp set tt1 unsigned long ttl Description ctl_arp_set_ttl sets the timeout before an entry is deleted from the ARP cache to ttl seconds The default time to live is 10 minutes Thread Safety ctl_arp_set_ttl is thread safe See Also ctl_arp_get_ttl 68 CrossWorks TCP IP Library CrossWorks TCP IP Library ct dhcp init Synopsis eds TAL Sa ik Etlildhepliinit vord Description bound UDP ports See Also ct net init ctl_udp_init 69 CrossWorks TCP IP Library CrossWorks TCP IP Library ct dhcp lease expire time Synopsis CTL TIME t ctl1 dhcp lease expire time void Description ct dhcp lease expire time returns the time that the DHCP lease expires Note This is provided as a convenience so the application can print DHCP information the DHCP client code in the Network Library manages all aspects of the IP lease See Also ctl_dhcp_lease_renew_time ctl_dhcp_lease_rebind_time 70 CrossWorks TCP IP Library CrossWorks TCP IP Library ct dhcp lease rebind time Synopsis CTL TIME t ctl1 dhcp lease rebind time void Description c
67. ct mac wake net task must be called by the MAC layer driver s interrupt service routine when there is action to be taken in the network stack task ct mac wake net task will wake the network task which will call ct mac update in due course See Also ct mac update ct net process received frame 174 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl net do mac dis connect Synopsis void ctl1 net do mac dis connect void Description ct net do mac dis connect signals to the network stack that the media connected to an network interface has changed state such as unplugging or plugging the Ethernet cable It is intended that MAC layer or PHY layer drivers call ct net do mac dis connect when they detect that the media has changed as the PHY will renegotiate its operating parameters and the MAC may well need to be reconfigured for inter packet gaps and so on In addition the network stack must renegotiate its DHCP parameters 175 CrossWorks TCP IP Library CrossWorks TCP IP Library ct net get phy name Synopsis char ctl1 net get phy name CTL NET INTERFACE t self Description ctl net get phy name returns the name of the PHY driver attached to the network interface self 176 CrossWorks TCP IP Library CrossWorks TCP IP Library ct net process received frame Synopsis void ctl1 net process received frame CTL ETH RX FRAME t frame Description ctl net process received
68. data sent to the socket gets pushed to the network and sent out on the wire The TCP IP Library buffers data on a socket until a TCP segment is full when it is pushed to the network to flush a partially filled segment call ctl_tcp_flush This makes the TCP IP Library different from classic TCP stacks which will typically flush a partially filled segment to the network after a short timeout Reading the response Once the headers are sent the example reads the response from the server using repeated calls to tcp_read_line We specified HTTP 1 0 which requests the server to close the connection after sending all its data and take advantage of the fact that when a socket is closed we ll receive an error if we try to read more from it and we exit the loop Process response for ii Try to read a whole line from the web server stat ctl_tcp_read_line s line buffer sizeof line_buffer 1 Ensure the buffer is terminated line_buffer sizeof line_buffer 1 0 Process return status if stat CTL_NET_ERR_TIMEDOUT Didn t get anything loiter else if stat lt CTL_NO_ERROR Error reading the socket or the socket closed break else Dump response prance Zs n line busfer Make sure socket is closed ctl_tcp_shutdown s 29 CrossWorks TCP IP Library CrossWorks TCP IP Library Before exiting we close the socket If the socket is already closed because the server
69. drreturns the IP address for socket soc or zero if there is an error The IP address is returned in network byte order See Also ctl_tcp_get_local_port 124 CrossWorks TCP IP Library CrossWorks TCP IP Library ct tcp get remote port Synopsis CTL NET PORT t ctl1 tcp get remote port CTL SOCKET t soc Description ctl tcp get remote port returns the port number for the TCP partner of socket soc or zero if there is an error The remote port is returned in network byte order See Also ct tcp get local port ctl tcp get remote ip addr 125 CrossWorks TCP IP Library CrossWorks TCP IP Library ct tcp get socket connection state Synopsis CTL TCP SOCKET CONNECTION STATE t ctl1 tcp get socket connection state CTL SOCKET t soc Description ct tcp get socket connection state returns the connection state of socket soc If soc does not identify a socket ct tcp get socket connection state returns CTL TCP SOCKET STATE CLOSED See Also CTL TCP SOCKET CONNECTION STATE t 126 CrossWorks TCP IP Library CrossWorks TCP IP Library ct tcp get socket error Synopsis CTL STATUS t ctl1 tcp get socket error CTL SOCKET t soc Description ctl tcp get socket error returns the error state of the socket soc If there is no error on the socket ctl tcp get socket error returns CTL NO ERROR otherwise one of the following error codes CTL NET ERR WOULDBLOCK The operation cann
70. e cksum and COMP ccsssssscssssssecssecssecssesssecssscsnecssecssccssscsnecssessseessecsneesseesseessees 199 ed SUPT o CO OE E A AAEE 200 dl ip regkta SS GO N N 201 rt net dep peiVate ME ES RS A ER GR ee ee GR Ge ese RS ee ae 203 sies AF dd OR EE N 204 CTL TCP SEGMENT EO EE RE N EE 205 CTL TCP ed ESE VA AE EE OE N 206 Devices sssscsssssssssssessosssssssssssecaseasenseaees lt designware_emac_v2 h gt designware_emac_v2_first_free eesssssssssscsssscssescsssscssescsssscsssccssssessecessescssecssscessnecssneecsseesenecesseeses 209 designware emac v2 init mac driver sees sen seek ee ee ek ee oek oek GER oek oe en oek eks 210 designware emat V2 SE RO N N 211 designware emac v2 start seen seeek soek ooeR GEROER oe R oek ORR oo eR ee Roe R Roe Oe oe Ge R ee Gee Gee oek gee 212 eel eli ME ed V3 EE N EI N RE Ee OE Ie 213 designware emac v3 first free see seke R ek GEROER Gee Oe Oe R oek oek OER GER eek oe Rek ek ees 215 designware emac V3 MIE sissies ER Ke oek GER Re SEER E de E AE Geek ee EE Sesde ee ee 216 designware emac v3 isr designware_emac_v3_start N N N 218 designware emac Vv3 versiON csccssssssssscsssscssecssscscsseccsseccsseccsseccssecssseccsseesssecssseessscersseessscessneessseesans 219 si AE 220 CrossWorks TCP IP Library Contents ae EA do EE N EN 221 SNEZSIGO_ mad setub Ee sege ER EG RR cE ee ee gee Gee Re ee 222 enc28j60 phy init driver 0 escssscsssscssccsssscsssecssss
71. e source files and object code files in this package are not public domain and are not open source They represent a substantial investment undertaken by Rowley Associates to assist CrossWorks customers in developing solutions using well written tested code Object Code Commercial License If you hold a paid for Object Code Commercial License for this product you are free to incorporate the object code in your own products without royalties and without additional license fees This Library is licensed to you PER DEVELOPER and is associated with a CrossWorks Product Key which when combined forms the entitlement to use this library You must not provide the library to other developers to link against each developer that links with this Library requires their own individual license CrossWorks TCP IP Library CrossWorks TCP IP Library Prerequisites What s in the box As delivered the TCP IP Library provides the following core TCP IP protocols in object form ARP UDP TCP DHCP NTP and DNS The stack also provides examples of application level protocols in source form that you can customize e FTP HTTP SMTP You can extend the capabilities of the TCP IP Library by writing your own functions to implement other application level UDP and TCP protocols just as we have implemented the existing application level protocols using core protocols What we assume you know This user manual is a user manual for our network stack You don t
72. ero if DNS is not used or there is no secondary DNS server ttl Time to live for outgoing IP packets Generally a don t care for use on a LAN See Also ctl_net_init 39 CrossWorks TCP IP Library CTL NET ERROR t Synopsis typedef enum ET DE ET CT L NET CONFIGURATION ERROR L NET NOT UP L NET UNREACHABLE L DNS HOST NAME ERROR L DNS RESOLVE IN PROGRESS Li DNS OUT OF MEMORY L DNS NAME UNKNOWN L DNS NO DNS SERVER ii UDP TOO MANY PORTS L UDP PORT IN USE i TEP POET ACTIVE L UDP BAD PORT ii TOP TOO MANY PORTS ii TEP BAD PORT L TCP PORT NOT BOUND ii TEP POET IN USB i TOP BAD SOCKET L TCP TOO MANY OPEN SOCKETS ii TEP OOLKET CLOSED L NET ERR WOULD BLOCK L NET ERR ALREADY L NET ERR NOTSOCK L NET BERR OPNOTSUPP L NET ERR NETDOWN L NET ERR NETUNREACH L NET ERR CONNABORTED L NET ERR CONNRESET L NET ERR NOTCONN L NET ERR TIMEDOUT L NET ERR CONNREFUSED L NET ERR HOSTUNRBACH L NET ERR NOTEMPTY L NET ERR DISCON Li NET ERROR t Description CTL NET ERROR t enumerates the errors that the TCP IP Library generates CTL NET CONFIGURATION ERROR CrossWorks TCP IP Library Indicates that the network library is not configured correctly As delivered the CTL network library is correctly configured and tested so this error should not be seen by users If you do see this error please check your configuration
73. es fields within the frame A header is allocated and assigned to the header member of the allocated frame header_byte_count is the number of byes to allocate for the header must be a multiple of four and must include the alignment short If the header size is not a multiple of four the frame isn t allocated Once allocated the header_byte_count of the frame is initialized to the header_byte_count parameter adjusted to remove the alignment short size Return Value ctl_eth_alloc_tx_frame returns a pointer to the allocated frame or zero if the frame cannot be allocated 192 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl eth free tx frame Synopsis void ctl1 eth free tx frame CTL_ETH_TX_FRAME t frame Description ctl_eth_free_tx_frame frees the transmission frame frame along with any memory that needs to be freed from the frame s header and payload 193 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl eth tx frame total count Synopsis unsigned long ctl1 eth tx frame total count const CTL ETH TX FRAME t frame Description ct eth tx frame total count computes the total number of bytes in the Ethernet frame frame which is the sum of the header size and payload size The header size includes the 12 bytes of Ethernet header 194 CrossWorks TCP IP Library CrossWorks TCP IP Library ct ipv4 make multicast mac addr Synopsis void ctl1 ipv4 make multicast mac addr unsigned c
74. get_ip_address is thread safe 94 CrossWorks TCP IP Library CrossWorks TCP IP Library ct net get subnet mask Synopsis CTL NET 1Pv4 ADDR t ctl1 net get subnet mask void Description ctl net get subnet mask returns the system s subnet mask as set in the CTL_IP_CONFIG_t configuration passed to ct net init or retrieved from a DHCP server If IP addresses are assigned by DHCP ct net get subnet mask will returns an all zero IP address whilst IP negotiation is in progress Thread Safety ctl_net_get_subnet_mask is thread safe 95 CrossWorks TCP IP Library CrossWorks TCP IP Library ct net init Synopsis CTL STATUS t ctl1 net init unsigned taskPriority Const eur iPAdeoNH IERE MIE created using a task priority priority The initial IP configuration is pointed to by and this may be null if DHCP is used to configure the host settings See Also CTL IP CONFIG t 96 CrossWorks TCP IP Library CrossWorks TCP IP Library ct net interface Synopsis CTL NET INTERFACE t ctl net interface Description ctl net interface holds a pointer to the network interface initialized by ctl_mac_init If ct net interface is zero the MAC has not been initialized The TCP IP library supports a single MAC at this time See Also ct mac init 97 CrossWorks TCP IP Library CrossWorks TCP IP Library ct net is autoip address Synopsis unsigned ctl1 net is autoip address CTL NET IPv4 A
75. group A pseudo random number generating routine issGenCallback must be provided to make initial send segments CTL_TCP_GEN_ISS_FN_t In general the free running accumulator from the hardware timer that drives ct get current time is used for this purpose so the network library can provide a one size fits all solution See Also CTL_TCP_GEN_ISS_FN_t 131 CrossWorks TCP IP Library CrossWorks TCP IP Library ct tcp look ahead Synopsis size_t ctl1 tcp look ahead CTL SOCKET t soc char ch Description ctl_tcp_look_ahead looks ahead to find the character ch in the received but as yet unread data for the socket soc ctl_tcp_look_ahead returns the number of characters that can be read from the socket such that the data on the socket is exhausted or the character ch is the terminating character read You can use ctl_tcp_look_ahead for instance to search for specific characters in the stream See Also ctl_tcp_read_line 132 CrossWorks TCP IP Library CrossWorks TCP IP Library ct tcp push Synopsis CHES MY SA GE cElEEEpipushile mis Eers Description ct tcp push sends any data queued on socket s to the network layer for transmission Socket s must first be in the connected state CTL_TCP_SOCKET_STATE_CONNECTED or ctl_tcp_push fails ctl_tcp_push is equivalent to calling ctl_tcp_send with no data and the push flag set 133 CrossWorks TCP IP Library CrossWorks TCP IP Library c
76. har dst CTL NET IPv4 ADDR t ip addr Description ct ipv4 make multicast mac addr creates a multicast Ethernet MAC address in dst for the IPv4 address ip addr 195 CrossWorks TCP IP Library CrossWorks TCP IP Library ct ipv4 rx payload byte count Synopsis unsigned ct1 ipv4 rx payload byte count CTL ETH RX FRAME t frame 196 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl ipv4 rx payload start Synopsis void ctl1 ipv4 rx payload start CTL ETH RX FRAME t rxFrame 197 CrossWorks TCP IP Library CrossWorks TCP IP Library ct net calc cksum Synopsis unsigned short ctl1 net calc cksum unsigned long seed const unsigned short data size t byte count Description ct net calc cksum calculates the checksum over an array of shorts See RFC 1071 The returned value is 0 through 65535 with all end around carries accounted for Note Data in and out of checksum functions are in network byte order Actually it doesn t matter which byte order is used as long as the answer is the same byte order seed contains the value calculated from the TCP or UDP pseudo header 198 CrossWorks TCP IP Library CrossWorks TCP IP Library ct net normalize cksum and comp Synopsis unsigned short ctl1 net normalize cksum and comp unsigned long sum Description ct net normalize cksum and comp normalizes the checksum sum and complements it such that the output is a correct 16 bit TCP checks
77. he complete set of states defined by RFC793 Whilst this should be self explanatory we document the states anyway CTL_TCP SOCKET STATE CLOSED Socket has never been open is invalid or has been closed CTL_TCP_SOCKET_STATE_CONNECTING Socket is connecting CTL_TCP_SOCKET_STATE_CONNECTED Socket has completed three way handshake and is ready for business CTL_TCP_SOCKET_STATE_CLOSING Socket is closing 54 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL TCP SOCKET OPTIONS Synopsis typedef struct size_t max_receive_segment_size size_t max_owned_receive_bytes size_t max_send_segment_size size_t max owned send bytes unsigned long idle socket shutdown char autoPush j EETL TOP SOOKET OETTONS ty CTL_TCP_SOCKET_OPTIONS_t contains configuration information for a socket In lieu of the classic sockets getsockopt and setsockopt functions the TCP layer presents and receives its options in a single structure A client socket should set these options before calling ctl_tcp_connect A server socket s only chance at legally manipulating this its options would be during the CTL_TCP_ACCEPT_FN_t callback but all sockets for a given port are initialized with the CTL_TCP_SOCKET_OPTIONS_t contained in the CTL_TCP_PORT_OPTIONS_t for that port In general T calling ct 1 tcp set socket options for an individual server socket is not required The structure has the following members max receive segment size
78. he network is not yet up for instance the network library has not received an IP address from a static configuration or by DHCP ctl_dns_get_host_by_name returns CTL NET NOT UP If the host address is in the DNS cache maintained by the network library the address is written to ip_addr immediately and ctl_dns_get_host_by_name returns CTL_NO_ERROR If the host address is not in the DNS cache the network library queues a DNS lookup If this is a non blocking call i e ms is zero then ctl_dns_get_host_by_name immediately returns the non fatal status CTL_DNS_RESOLVE_IN_PROGRESS If this is a blocking call ctl_dns_get_host_by_name waits for a response If no response is received from a DNS server within timeout milliseconds or all DNS servers are queried and time out ctl_dns_get_host_by_name returns CTL_DNS_NAME_UNKNOWN Return Value ctl_dns_get_host_by_name returns a standard status code Thread Safety ctl_dns_get_host_by_name is thread safe 73 CrossWorks TCP IP Library CrossWorks TCP IP Library ct dns get server Synopsis CTL NET 1Pv4 ADDR t ctl1 dns get server unsigned index Description ctl dns get server returns the IP address of the DNS server with index index If index is invalid ctl dns get server returns an all zero IP address If IP addresses are assigned by DHCP ct dns get server returns all zero IP address whilst IP negotiation is in progress 74 CrossWorks
79. he network stack The difference is that ct net mem alloc xmit will attempt to take every last byte in the heap if that is what is required while ct net mem alloc data will attempt to leave a few bytes for future transmit allocations The reason for this duality is to prevent a potential fatal embrace whereby there is data available to be sent but a transmit frame cannot be allocated to send it Application code should always use ctl_net_mem_alloc_data when allocating memory from the network heap free fn Method to free previously allocated memory alloc xmit fn Method to allocate data for a transmit frame alloc data fn Method to allocate data for payload 161 CrossWorks TCP IP Library CrossWorks TCP IP Library See Also CTL NET MEM FREE FN t CTL NET MEM ALLOC FN t 162 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL NET PHY DRIVER t Synopsis typedef struct int addr unsigned short operating_mode unsigned short configuration_flags unsigned short mii_mode unsigned short auto_negotiation C NE e EN NEG eN is CE NET PHY UPDATE FN t update_fn Cihib JEN SVN AS etes C mr MM DEd mees const char name CYL NET _ PRY DRIVER Description CTL_NET_PHY_DRIVER_t contains data and hardware specific function overloads for the PHY layer The CTL_NET_PHY_DRIVER_t structure has the following members addr The address of the PHY in use 0 through 31 The network stack
80. her nonvolatile medium when the device is personalized as part of production define FIXED_MAC_ADDRESS Moe Zs de Ef EE EEN Network task thread priority define NET TASK PRIORITY 200 Network interface static CTL NET INTERFACE t nic static void bring up network void Assign a fixed MAC address to the NIC example check status ctl_net_scan_mac_addr amp nic mac mac_addr FIXED MAC ADDRESS Initialize MAC example check status ctl_mac_init amp nic Bring up network task and use DHCP to assign an IP address example check status ctl_net_init NET TASK PRIORITY 0 Bring up UDP and ICMP DHCP requires UDP and ICMP will respond to pings example check status ctl_udp_init 0 example check status ctl_icmp_init Start DHCP to assign us an IP address 23 CrossWorks TCP IP Library CrossWorks TCP IP Library example check status ctl1 dhcp init int main void char dot_ipaddr 16 dot_netmask 16 niie alie PlaE FOR platform initialize Initialize NIC for this platform example check status platform configure network amp nic Set our host name ct1 net set host name crossworks Start network bring up network Idle away when we re configured dump our network for See if we ve acquired an IP address yet if ctl1 net get ip address Dump message inviting a ping printf DHCP IP address is s and subnet mask
81. hly that you purchase one or more of these to start learning how the TCP IP Library works You ll feel so much better running networking examples straight away and then you can progress to other hardware and see how it works out for you Tested examples This manual is written using the TCP IP Library examples that come included with boards that are pre configured ready to run networking as part of a CrossWorks Board Support Package Not all Board Support Packages contain networking examples they may not have them because we haven t supported the embedded or external network controller or because they are too limited to run networking If you are familiar with TCP IP networking CrossWorks and are comfortable skipping the manual and diving straight into code with a reference manual that s great go right ahead and try out some of the examples What you need to know To try out the networking examples there s very little that you need to know about CrossWorks and the Platform Library All you need is a board that we ship examples for and a way to program it If you want to start delving a little deeper into the examples you will need to refer to the Platform Library user manual as the examples use Platform Library facilities to make the code portable over all the boards we support There are many examples that you can extract code from inheritance by text editor is a tried and tested method of program development Because all the s
82. holds the statistics related to IP txFramesHeldForARP The number of frames that required ARP lookup before being passed to the MAC driver txFramesDirect ToMAC The number of frames passed directly to the MAC driver as the Ethernet address of the frame is known without broadcasting an ARP request for it 189 CrossWorks TCP IP Library CrossWorks TCP IP Library CrossWorks TCP IP Library ct arp init Synopsis sus TAN Sdie Etlarpiinat vord Description ctl_arp_init initializes the ARP protocol and creates an ARP cache with a default eight entries You must call ctl_arp_init before initializing other protocols By default the ARP cache will use the system memory allocator ctl_system_memory_allocator to allocate its cache If you want to use a different memory allocator for instance to dedicate a fixed memory size to the ARP cache you can replace the default allocator using ctl_arp_set_memory_allocator Thread Safety ctl_arp_init is thread safe See Also ctl_arp_set_cache_size 190 CrossWorks TCP IP Library CrossWorks TCP IP Library ct dns register stats Synopsis void ctl1 dns register stats void 191 CrossWorks TCP IP Library CrossWorks TCP IP Library ct eth alloc tx frame Synopsis CTL ETH TX FRAME t ctl_eth_alloc_tx_frame size_t header byte count Ci TIMI je E mecut Description ctl_eth_alloc_tx_frame allocate a new transmission frame from network memory and initializ
83. ich should all be freed on transmit completion e With fragmented IP packets the entire buffer is freed after the final fragment is transmitted The members are header A pointer to the header data to transmit guaranteed to be correctly aligned for the MAC Data transmission starts with header ethDstMac header byte count The number of header bytes to transmit This byte count always excludes the reguired align member from the count Frames presented to the MAC driver for transmission are guaranteed that header_byte_count 2 is divisible by four payload A pointer to the payload data if any and guaranteed to be correctly aligned for the MAC If there is no payload this member must be set to zero payload_byte_count The number of bytes in the payload If there is no payload this member must be set to zero payload_free The data to free once the frame is sent If there is nothing to free this member must be zero 153 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL MAC STATE t Synopsis typedef enum CTL_MAC_STATE_FATAL_ERROR CTL_MAC_STATE_NO_LINK CTL_MAC_STATE_NEEDS_REINIT CTL_MAC_STATE_CONNECTED Em MAG ISTE ty Description CTL MAC STATE t defines the internal states that the MAC state machine may go though A MAC driver can use this to maintain its internal state 154 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL NET ETHERNET HEADER SIZE Synopsis define CTL NET ETH
84. ing your application for you no matter how nicely you ask If you ask us a question that can be answered by reading the manual don t be surprised if you receive a short to the point reply am writing this documentation for a reason if have taken the time to write it you really should take the time to read it or at least search it Impending product deadlines do not excuse you from using our support service as an on demand oracle And as a final request never end you e mails with Please advise because that really ticks me off With all that understood let s begin CrossWorks TCP IP Library CrossWorks TCP IP Library Before you begin Simplify your life Your intention is to deploy or evaluate the CrossWorks TCP IP Library for use in your product Before you begin there is something very important that must ask you to do run on known good hardware with tested software You don t want to make your life complicated to begin with You don t want to port the TCP IP Library to an untested piece of hardware as well as learn about the TCP IP Library and maybe even learn CrossWorks at the same time So do yourself a favor and spend a little money getting a piece of hardware that is fully tested and that we know runs the TCP IP Library well Purchase a SolderCore Suggestions Well the TCP IP Library is primarily developed using the SolderCore and as Rowley Associates manufactures the SolderCore we would recommend most hig
85. is s n ctl_ip_sprint_addr dot_ipaddr ctl_net_get_ip_address ct1 ip sprint addr dot netmask ctl_net_get_subnet_mask else Can t ping me yet printf DHCP awaiting IP address assignment n Don t be too enthusiastic with messages ctl_delay 1000 See Also ctl_net_set_host_name 24 CrossWorks TCP IP Library CrossWorks TCP IP Library Resolving host names Finding IP addresses You ve seen how to get your board registered with a name on the LAN Now it s time to step outside and get onto the Internet This example is how to resolve the IP address of the Rowley Associates web server www rowley co uk Select and build the project In the examples for your board you ll find a Networking Projects solution and within that a Resolve Domain Name project Double click that project to make it active and press F7 to build Hiding some details Rather than repeat all the boilerplate code that brings up the network and waits for an IP address that code is moved into example_network_support c This example and all following examples assume that example_network_support c is included in the project Double click the file example network support cinthe Source Files folder and it will open in the code editor Because this example needs to resolve a domain name it initializes the Domain Name System component of the TCP IP Library Start DNS for domain name lookup stat ctl_dns_init if
86. is can happen when packets arrive that do not conform to the TCP state machine bad_mss The number of socket connections attempted with an invalid MSS cnx_refused_unsupported The TCP connection request was refused because there are no listeners registered for the port cnx_refused_ports The TCP connection request was refused because the maximum number of connections are already open for the port cnx_refused_sockets The TCP connection request was refused because there are insufficient sockets in the socket pool to establish a connection tx_total_retrans The total number of retransmission requests because an ACK from the other TCP was lost tx 1 retrans A count of the number of segments that reguired a single retransmission as an ACK form the other TCP was lost 201 CrossWorks TCP IP Library CrossWorks TCP IP Library tx 2 retrans A count of the number of segments that reguired two retransmission as an ACK form the other TCP was lost tx unreach A count of the number of segments that exceeded two retransmissions and considered the other TCP unreachable rx fast retrans A count of the number of received segments that are lost and the network stack re reguested using the fast restransmission algorithm 202 CrossWorks TCP IP Library CrossWorks TCP IP Library lt ctl_net_tcp_private h gt API Summary Segments CTL_TCP_SEGMENT_t ATCP segment Types CTL_TCP_APP_LAYER_CMD_t Application layer command CTL_T
87. is resolved using DNS using ctl_dns_get_host_by_name e The TCP IP port to connect to HTTP connections use port 80 and HTONS converts the port number from host byte order to network byte order as required by the TCP IP Library The maximum time to wait for the connection to be made In this example we are prepared to wait one second for the connection to be established Sending the request Once the socket is established you start to communicate with the server using a GET request For reference the HTTP protocol is fully described in RFC2616 The GET request consists of the command the headers and a blank line to terminate the headers ctl_tcp_printf s GET http s s HTIP 1 0 r n host name ctl_tcp_printf s Accept text plain r n GET tepl prints ost os Ve ele Osi Er cti tcpliprintfis En 28 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl_tcp_push s The application sends e The GET command specifying the URL and the protocol to use In this case the URL is composed of the host name and the page we are interested in Following that is the protocol to use HTTP 1 0 which simplifies the following code somewhat e The headers This tells the server the MIME type of the response and the host we are addressing A blank line which indicates that the headers are complete An important difference One thing to notice is the call to ctl_tcp_push this ensures that the
88. ith the given MAC address mii_write_fn Writes to a PHY register This doesn t need to be thread safe as it is only called from the network task mii_read_fn Reads a PHY register This doesn t need to be thread safe as it is only called from the network task mii_deferred_read_fn Start a deferred read of an MII register The result will be read by calling mii_deferred_read_result_fn mii_deferred_read_result_fn Return the PHY register requested by mii_deferred_read_fn If the result is not ready return CTL_PHY_AGAIN or an error code if there is an error else the register contents select_phy_fn Select the appropriate PHY attached to the MAC device Additional MAC data if any 159 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL NET MAC MII DEFERRED READ FN Synopsis typedef CTL STATUS t CTL NET MAC MII DEFERRED READ FN t CTL NET INTERFACE t int Description CTL NET MAC MII DEFERRED READ FN t is the MAC layer MII management interface deferred read function signature This function in the network interface initializes a read of the MII RMII management interface and immediately returns 160 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL NET MEM DRIVER t Synopsis typedef struct CTL NET MEM FREE FN t free fn CTL NET MEM ALLOC FN t alloc mit fn CTL NET MEM ALLOC FN t alloe data fn T D CTL NET MEM TRIM FN t trim fn GTL NET MEM DRIVER t Descrip
89. k a product that integrates well with your existing RTOS or ditch that RTOS and use our excellent CTL tasking environment instead As you would expect the TCP IP Library integrates with other components in the CrossWorks Target Library For instance the TCP IP Library uses the CrossWorks Mass Storage Library to store and retrieve files using FTP or serve web pages from files in the file system The file system and the TCP IP Library both integrate with the CrossWorks Streams framework CrossWorks TCP IP Library CrossWorks TCP IP Library Object Code Evaluation License If you are evaluating the TCP IP Library for use in your product the following terms apply General terms The source files and object code files in this package are not public domain and are not open source They represent a substantial investment undertaken by Rowley Associates to assist CrossWorks customers in developing solutions using well written tested code Library Evaluation License Rowley Associates grants you a license to the Object Code provided in this package solely to evaluate the performance and suitability of this library for inclusion into your products You are prohibited from extracting disassembling and reverse engineering the Object Code in this package CrossWorks TCP IP Library CrossWorks TCP IP Library Object Code Commercial License If you have paid to use the TCP IP Library in your product the following terms apply General terms Th
90. kage f this is the case you ll need to figure out what you ve done or get in touch with us Find a spare network address As the example we are going to run uses a fixed IP address you need to find a free one to assign to the evaluation board On Windows you can use ipconfig to view your network parameters gt ipconfig Windows IP Configuration Ethernet adapter Local Area Connection Conneceton speciric DNS SuFf1ix rowley co uk Bin lovee INP Address 4 4 6 a 8 imebiOS soezd eoo ad eA reli EVANS SE EE bo OS 6 amp OO 0E se Some WEB 6 6 A 6 BA 8 6 6 6 B ASSSLEBLASD 0 taak GAT eWS Ye aie Ghee a oe ce EL OG DS Here we see that the subnet mask is 255 255 255 0 and the PC s IP address is 10 0 0 58 So let s try a random IP address by changing the last number to see if it s free gt ping 10 0 0 32 Pingng MO OOK a2 with JA bytes or data Reply from 10 0 0 32 bytes 32 time lt lms TTL 64 Reply from 10 0 0 32 bytes 32 time lt lms TTL 64 15 CrossWorks TCP IP Library Reply from 10 0 0 32 bytes 32 time lt lms TTL 64 Reply from 10 0 0 32 bytes 32 time lt lms TTL 64 Pein Gers tarist esir ror do OOR Packets Sent 4 Received 4 Lost 0 0 loss Approximate round trip times in milli seconds Minimum Oms Maximum Oms Average Oms Ahh that one s in use Let s try another gt ping 10 0 0 44 Pinging 10 0044 wath 32 bytes of data Request timed out Request timed out Request
91. know anything about our stack or how it works so this manual teaches you how to use it This user manual is not a Dummies Guide to TCP IP because you don t find that in the title we expect you to know what you want to do but not how to achieve it using our software You need a good understanding of how TCP IP and Ethernet work and the underlying concepts If you know nothing to very little about TCP IP don t know what a datagram is or the difference between a TCP segment and grapefruit segment you re not really ready to swim with sharks just yet then check out the following books to expand your horizons e TCP IP Illustrated Volume 1 The Protocols W Richard Stevens ISBN 978 0201633467 e TCP IP Illustrated Volume 3 TCP for Transactions HTTP NNTP and the UNIX Domain Protocols W Richard Stevens ISBN 978 0201634952 In fact the books above are a great reference for anybody that needs to use TCP IP on a daily basis so go and buy them If all you want to do is send an e mail from the network stack this manual alone is enough to construct a solution for that If you want to write your own TCP and datagram protocol handler this manual shows you the mechanisms to achieve that goal What this manual does not do is tell you how to make UDP protocols reliable or how to design your own protocols that s all up to you we just provide the necessary parts kit for you to assemble your application This manual tells you h
92. l tcp close socket should not be invoked from the network task with CTL TCP CLOSE LINGER and a non zero timeout value In other words do not use the blocking version of this function in a UDP or TCP callback See Also ctl_tcp_shutdown 119 CrossWorks TCP IP Library CrossWorks TCP IP Library ct tcp connect Synopsis Cllins LAT sd EEIEEpIESnneet ss e SERE II S CTL NET 1IPv4 ADDR t remotelpAddr CTE NET PORT t remotePort CTL TIME t timeout Description ctl tcp connect connects socket s to port remotePort of remote host remotelpAddr The socket should have been previously allocated with ctl_tcp_socket Returns CTL_NO_ERROR if successful or an error code for fail i e no sockets were available There is no non blocking version of this function If timeout is non zero ctl_tcp_connect will block until the connection is made or it times out If timeout is zero ctl_tcp_connect will block for a few microseconds until the network task signals that it has started the connect process If you call ctl_tcp_connect with timeout set to zero you can poll the connection state using ctl_tcp_get_socket_state to determine when the connect or fail timeout occurs Note ctl_tcp_connect must not be called in the zero priority main task nor should it be called from the network task in a UDP or TCP receive callback See Also ctl_tcp_socket ctl_tcp_get_socket_state 120 CrossWorks TCP IP Library CrossWorks T
93. maximum ARP cache size Set ARP cache memory allocator Set ARP time to live Ethernet MAC address Return interface s MAC address Is this MAC address a broadcast address Is this MAC address a null address Scan a textual MAC address Allocate network memory Allocate network memory Deallocate network memory Trim allocated network memory Convert IPv4 address to dotted decimal string Convert Ethernet MAC address to string Register network error decoder 38 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL IP CONFIG Synopsis typedef struct CTL NET IPv4 ADDR ip addr CTL NET IPv4 ADDR subnet mask CTL NET IPv4 ADDR gateway CTL NET IPv4 ADDR CTL NET IPv4 ADDR unsigned char ttl CY TE CONFIG tv dns_primary_server dns secondary server ar ior Pr ior far Description CTL_IP_CONFIG_t contains the values needed to configure the IPv4 layer of the network library If DHCP is not used the application code must supply one of these structures to ctl_net_init during startup ip_addr Our IP address in network byte order subnet_mask Our subnet mask in network byte order gateway Local router gateway address in network byte order This can be zero if packets never leave the LAN dns_primary_server Primary DNS server IP address in network byte order This can be zero if DNS is not used dns secondary server Secondary DNS server IP address in network byte order This can be z
94. me suffix is thread safe 91 CrossWorks TCP IP Library CrossWorks TCP IP Library ct net get gateway address Synopsis CTL NET 1Pv4 ADDR t ctl1 net get gateway address void Description ctl net get gateway address returns returns the gateway local router s IP address as set in the CTL IP CONFIG t configuration passed to ct net init or retrieved from a DHCP server If IP addresses are assigned by DHCP ct net get gateway address will returns an all zero IP address whilst IP negotiation is in progress Thread Safety ctl_net_get_gateway_address is thread safe 92 CrossWorks TCP IP Library CrossWorks TCP IP Library ct net get host name Synopsis char ctl1 net get host name void Description ctl net get host name returns a pointer to a null terminated read only string that contains the host name set by ctl_net_set_host_name If no host name has been set the host name is empty See Also ctl_net_get_host_name 93 CrossWorks TCP IP Library CrossWorks TCP IP Library ct net get ip address Synopsis CTL NET 1Pv4 ADDR t ctl1 net get ip address void Description ctl net get ip address returns the system s IP address as set in the CTL_IP_CONFIG_t configuration passed to ct net init or retrieved from a DHCP server If IP addresses are assigned by DHCP ctl_net_get_ip_address will return an all zero IP address whilst IP negotiation is in progress Thread Safety ctl_net_
95. mtp_client h include libplatform platform h include libplatform platform_network h WA Example SMTP server address Replace with yours either dotted decimal or DNS name define SMTP_SERVER your mailserver here Wee Example e mail delivery address Replace with yours define USER EMAIL ADDRESS N somebody home com Resolved SMTP server static CTL NET IPv4 ADDR t smtp server addr int main void CTL_STATUS E stat char dot_ipaddr 16 Initialize platform platform_initialize example initialize 33 CrossWorks TCP IP Library CrossWorks TCP IP Library Start networking wait for an IP address example check status example bring up full networking example check status example await assigned ip address Wait 5s to see if we can resolve our mail server If you use a dotted decimal IPv4 address there is no name lookup and this completes immediately printf DNS Resolving s SMTP SERVER maximum wait for DNS reply is 5 seconds n example check status ctl_dns_get_host_by_ name SMTP_SERVER amp smtp server addr 5000 printf DNS Resolved s to s n SMTP_SERVER ctl_ip_sprint_addr dot_ipaddr smtp_server_addr Attempt to send some mail stat ctl_smtp_client_send_mail smtp_server_addr Say whether it worked if stat lt CTL_NO_ERROR example _ terminate SMTP else USER_EMAIL_ADDRESS cro
96. nction should only be called in the accept callback see CTL TCP ACCEPT FN t Callback and Event TCP server models are mutually exclusive invoking this function will nullify the behavior set in a previous call to ctl_soc_use_event ctl_tcp_use_callback ctl_tcp_use_event See Also ctl_tcp_accept ctl_tcp_bind ctl_tcp_use_callback ctl_soc_use_event ctl_tcp_use_event 115 CrossWorks TCP IP Library CrossWorks TCP IP Library ct soc use event Synopsis CTL STATUS t ctl1 soc use event CTL SOCKET t s CTL EVENT SET t wakeEvent CTL EVENT SET t wakeValue Description ctl soc use event is a TCP server function to assign the wake event pointer and wake event value used for thread synchronization on a per socket basis ctl_soc_use_event This function should be called from the accept callback function see CTL_TCP_ACCEPT_FN_t Callback and Event TCP server models are mutually exclusive invoking ctl_soc_use_event will nullify the behavior set in a previous call to ctl_soc_use_callback ctl_tcp_use_callback or ctl_tcp_use_event See Also ctl_soc_use_callback ctl_tcp_use_event ctl_tcp_accept ctl_tcp_bind ctl_tcp_use_callback 116 CrossWorks TCP IP Library CrossWorks TCP IP Library ct tcp accept Synopsis CTL STATUS t ctl1 tcp accept CTL NET PORT t port SA CEA GC CHE ah Niece Ce pE EN Description ctl_tcp_accept registers the function acceptFn as the accept callback fo
97. nection state uuuuuu sere sees ee ee ee BEER ee ee ee ee ee Re ee 126 et tap get socket ROF iss Es es RE sees eke Re Re en a GR Gegee oe Ee ee se BE ee eg 127 ctl tcp get socket optiONS uuu sesse ek ek ERGER ERGER ek ek ek oek ee Roe Roe Roe Roe Roe ee Reen 129 ctl tep get os OE N EE 130 ad ves Al EER EE Oe RO OE Oe E OE N 131 ctl tep look ahead EE OE OE DE eN 132 CrossWorks TCP IP Library Contents ed Cel o ISOM SIN EE E 133 et tap read line iss RE GE EE EN be oe ER Rg Ede gee Re KA ee Roe Re EE Ee ee ge iA 134 dl ie die AR EE EO EE EE Ee 135 ede sed ie EE ER EG 136 ctl tcp set port optioNS ius eek ERGER eene R oe Roe Roe Gee oek GER eo eR OER oek Gene oe Roe ee ge 138 ctl tcp set socket Options ou ssccssscsssscsseecssssssseecssccesseccsseecsneccssecssseesssesssssessseessscessneecsseesaneesseeesss 139 SUL vee Udo io RE sates ddesusnusensavecavccevateosecis gered aveencesevsdacabnacatehedecesenceeaseats 140 GUL REP SOCK EE A A EE EE N EE ane 141 etl tep Unbind AE ER AE AE EE N 142 ad e o USS Cal DAG EE ETE AA EE 143 ed od ii AE E 144 ede odie ye ER EE N 145 ctl_udp_init z edik ie Jo g lee EE A A N 147 etl udp Po ie AE EE N OE N Ne 148 ir ed id de ie de AE EO N EN 149 CEN pet WDS N OE 149 CIL ETH HEADER T G N GN ES ER GR AE De GO EG DS EE IE GO ee Ee 151 ei MEd EA N OE 152 CTL ETH BP dd NA EE schaysucentvestnssscpucscecedssdesassesessstatuadevsuvavarcdsaveancurees 153 CTL MAC STATE t CTL NET
98. nection termination request from the remote TCP or an acknowledgment of the connection termination request previously sent CTL_NCP_SOCKET_FIN_WAIT2 Waiting for a connection termination request from the remote TCP 206 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL NCP SOCKET CLOSE WAIT Waiting for a connection termination reguest from the local user CTL NCP SOCKET CLOSING Waiting for a connection termination reguest acknowledgment from the remote TCP CTL NCP SOCKET LAST ACK Waiting for an acknowledgment of the connection termination request previously sent to the remote TCP which includes an acknowledgment of its connection termination request CTL_NCP_SOCKET_TIME WAIT Waiting for enough time to pass to be sure the remote TCP received the acknowledgment of its connection termination request 207 CrossWorks TCP IP Library CrossWorks TCP IP Library lt designware_emac_v2 h gt Overview Synopsis DesignWare 10 100 Ethernet MAC driver This is implemented in the following device families e LPC1700 e LPC2300 LPC2400 e LPC3000 LPC3100 LPC3200 API Summary Setup designware_emac_v2_init_mac_driver Initialize the network interface Control designware_emac_v2_isr Handle network interrupt designware_emac_v2_start Start the network interface Status designware_emac_v2_first_free Return extent of memory consumed 208 CrossWorks TCP IP Library CrossWorks TCP IP Library designware emac v2 first free
99. ng example check status example await assigned ip address Dump the primary domain name server for reference printf Using DNS server s n ctl1 ip sprint addr dot ipaddr ctl1 dns primary server addr Try to resolve www rowley co uk Wait a maximum of two seconds for an answer stat ctl1 dns get host by name www rowley co uk amp addr 2000 Did this resolve if stat lt CTL NO ERROR No printf Could not resolve www rowley co uk n else Yes print the resolved IP address printf www rowley co uk resolved to s n ct1 ip sprint addr dot ipaddr addr Done return example finish The part of interest is stat ctl1 dns get host by name www rowley co uk amp addr 2000 This sends a request to the DNS server to resolve the domain name www rowley c uk and deliver the result to addr The third parameter 2000 indicates the maximum duration we re prepare to wait for in this case two seconds See if it works Power up the board and run the code In the CrossWorks Debug Terminal you will see something similar to this DHCP awaiting IP address assignment 26 CrossWorks TCP IP Library CrossWorks TCP IP Library DHCP awaiting IP address assignment DHCP awaiting IP address assignment DEEP IP address is 1 0 0 44 and subnet mask 1s 255 255 255 0 Using DNS server 0 0 0 8 www rowley co uk resolved to 178 236 4 60 Finished See Also
100. nic static void bring up network void Assign a fixed MAC address to the NIC example check status ctl1 net scan mac addr amp nic mac mac addr FIXED MAC ADDRESS Initialize MAC example check status ctl mac init amp nic Bring up network task and use DHCP to assign an IP address example check status ctl_net_init NET TASK PRIORITY 0 Bring up UDP and ICMP DHCP requires UDP and ICMP will respond to pings example check status ctl_udp_init 0 example check status ctl_icmp_init Start DHCP to assign us an IP address example check status ctl1 dhcp init 19 CrossWorks TCP IP Library CrossWorks TCP IP Library int main void char dot_ipaddr 16 dot_netmask 16 Initialize platform platform_initialize Ene ele Ne For Ens plat Er example check status platform configure network amp nic Start network bring up network Idle away when we re configured dump our network for See if we ve acquired an IP address yet if ctl1 net get ip address Dump message inviting a ping printf DHCP IP address is s and subnet mask is s n ctl_ip_sprint_addr dot_ipaddr ctl_net_get_ip_address ctl1 ip sprint addr dot netmask ctl_net_get_subnet_mask else Can t ping me yet printf DHCP awaiting IP address assignment n Don t be too enthusiastic with messages ctl_delay 1000 There s no fixed I
101. nter to the complete Ethernet receive frame the Ethernet header and payload data are held in a single chunk unlike transmission frames which separate header and payload byteCount The total count of bytes in the received Ethernet frame which excludes the reaguired align member in the Ethernet header and excludes the FCS appended by the transmitting MAC ethAndIpByteCount Set in the IP layer The offset of the start of the TCP UDP or ICMP header after IP options have been parsed relative to the start of the Ethernet frame excluding the alignment short 152 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL ETH TX FRAME Synopsis typedef struct CTL BTH HEADER t header unsigned short header byte count unsigned short payload byte count void payload void payload_free CTL BTH TX FRAME t Description Transmit frames are allocated from the network stack s private heap by the highest level stack code TCP or UDP or ICMP and then passed down the stack to the MAC layer which ct net mem free s the memory allocated to the frame and its header data A separate pointer payload_free is provided for the MAC layer to free payload data This is decoupled from the actual payload pointer for a number of reasons e TCP payload data is not freed from the MAC layer a null pointer does double duty as a do not free flag e It can be desirable for the payload data to be a subset of a larger block of memory wh
102. ocket options is within the CTL TCP ACCI See Also EPT_FN_t callback function ctl_tcp_get_socket_options ctl_tcp_set_socket_options ctl_tcp_connect 56 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL UDP CONFIGURATION t Synopsis typedef struct CTL NET PORT t min ephemeral port CTL NET PORT t max ephemeral port int max bound ports CTL UDP CONFIGURATION t Description CTL_UDP_CONFIGURATION_t contains the initialization parameters for the UDP layer Please refer to ctl_udp_init for a description of these members See Also ctl_udp_init 57 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL UDP INFO t Synopsis typedef struct BEANE HEPORTIEG nisi or Es CTL NET PORT other port CTL NET IPv4 ADDR t other_ip_addr void metadata CW UDP NEO ies Description pointer to an instance of CTL_UDP_INFO_t is passed into user code during a UDP receive callback and out of user code when calling ctl_udp_sendto Note the use of this and other semantics rather than src and dst In a UDP server the same CTL_UDP_INFO_t pointer received in the CTL UDP RECV FN t may be passed unmodified to ctl_udp_sendto as in the following example The simple semantic change of using this and other avoids having to do a parameter swap in the callback void myUdpReceiveFn unsigned long rcvData unsigned rcvByteCount const Clim UDP NEK Ee
103. orks TCP IP Library CrossWorks TCP IP Library Don t break it Your second TCP IP Library application It s not that common to use a fixed IP address for a network attached device Modern networks use dynamically assigned IP addresses and a DHCP server to manage assignment when a device powers on it broadcasts a request to the network asking for a DHCP server to assign it an IP address Using a DHCP server is now a necessity with so many devices attached to a LAN there is no way that a human can possibly manage a large network without error Select and build the project In the examples for your board you ll find a Networking Projects solution and within that a Minimal Network with Ping DHCP IP address project Double click that project to make it active and press F7 to build Double click the file example_minimal_ping_fixed_ipaddr c in the Source Files folder and it will open in the code editor Set up network using a DHCP assigned IP address include libnet ctl_net_private h include libplatform platform h include libplatform platform_network h include example_support h Assign a fixed MAC address to the NIC Normally this will be blown into OTP or some other nonvolatile medium when the device is personalized as part of production define FIXED_MAC_ADDRESS Hoe de Ef EE ae ie Network task thread priority define NET TASK PRIORITY 200 Network interface static CTL NET INTERFACE t
104. ot be completed without blocking and the application layer software reguested non blocking operation CTL NET ERR ALREADY The reguested operation has already been performed CTL NET ERR NOTSOCK Invalid socket descriptor CTL NET ERR OPNOTSUPP Option not supported CTL NET ERR NETDOWN Network interface is not configured or has a problem at the MAC level CTL NET ERR NETUNREACH Network interface is not connected CTL NET ERR CONNABORTED TCP connection aborted CTL NET ERR CONNRESET TCP connection reset CTL NET ERR NOTCONN Not connected CTL NET ERR TIMEDOUT Timed out CTL NET ERR CONNREFUSED The remote TCP refused our connection attempt CTL NET ERR HOSTUNREACH The remote host does not respond 127 CrossWorks TCP IP Library CTL NET ERR NOTEMPTY A TCP connect call was made on a socket is already connected CTL NET ERR DISCON The socket was disconnected no further communication is possible 128 CrossWorks TCP IP Library CrossWorks TCP IP Library CrossWorks TCP IP Library ct tcp get socket options Synopsis CTL STATUS t ctl1 tcp get socket options CTL SOCKET t s CUATE EES CMM Or EKEN AE SEUSS Description ctl tcp get socket options copies the socket options used by socket soc into the buffer pointed to by options See Also CTL TCP SOCKET OPTIONS t ctl tcp set socket options 129 CrossWorks TCP IP Library CrossWorks TCP IP Library ct tcp get sockets Synopsis
105. ow you can use some of the TCP IP Library s built in features that help when you re debugging your code It doesn t tell you how to go about debugging your application or how to use a network analyzer to track down rogue packets how to figure out which rabbit hole a particular packet disappeared down or how to tune out noise and dig deep into packets scuttling across the network you need to acquire CrossWorks TCP IP Library CrossWorks TCP IP Library those skills yourself it s called being an software developer When you re a true network warrior buy yourself a celebration beer and T shirt Nobody said this profession was easy What s not in the box must also take the opportunity to tell you what is not included in your purchase No we do not include your favorite bizarre protocol for controlling a network coffee pot There are so many protocols built upon TCP and UDP that it is impossible to offer implementations for them all so we offer the useful few It just means you need to implement the Coffee Pot Control Protocol yourself for that must have network attached Espresso machine or find somebody who has the necessary experience and has done so already Start your search by Googling RFC 2324 Product support and questions If you ask us for support about things that you should really know yourself don t be surprised or offended when we tell you that product support doesn t include hand holding nursemaid duties or writ
106. r port port port is specified in network byte order acceptFn may be null in which case all incoming connection requests are accepted provided that the number of open sockets is less than the allowed limit See Also CTL_TCP_ACCEPT_FN_t ctl_tcp_bind 117 CrossWorks TCP IP Library CrossWorks TCP IP Library ct tcp bind Synopsis CTPS YALE et Iitepibaind NP PIBORRIG pere Description ct tcp bind reserves a listener for the TCP port port port is specified in network byte order In the case of this library Bind means set aside one of the allocated server port slots for this port Unbind means to free up the resource See Also ctl_tcp_unbind ctl_tcp_accept ctl_tcp_init 118 CrossWorks TCP IP Library CrossWorks TCP IP Library ct tcp close socket Synopsis void ctl tep close socket CTL SOCKET t soc CIL_TCP_SOCKET_CLOSE_TYPE_t linger CTL TIME t timeout Description ctl tcp close socket closes the socket soc Closing can be either graceful or hard A graceful shutdown involves invoking the three way FIN handshake with the remote TCP after all outgoing data has been sent A hard shutdown merely closes socket soc at the local end any further packets from the socket s remote partner are NAKed with a reset response linger timeout Type of close Wait for close CTL TCP CLOSE DONTLINCDon t care Graceful No CTL TCP CLOSE LINGER Zero Hard No CTL TCP CLOSE LINGER Nonzero Graceful Yes ct
107. r the allocation of transmit and receive descriptors The client can use this to add all remaining memory to the network heap for example You can call this after initializing the network interface using designware_emac_v3_init See Also designware_emac_v3_init 215 CrossWorks TCP IP Library CrossWorks TCP IP Library designware emac v3 init Synopsis void designware emac v3 init CTL NET INTERFACE t self void emac void mem ant ti deseriptor seun int ry deseriptor edount ine clock Description designware_emac_v3_init initializes the network interface self but does not start it The DesignWare 10 100 EMAC register interface is specified in emac and the memory required to hold the transmit and receive descriptors is specified in mem The number of transmit and receive descriptors are passed in tx_descriptor_count and rx_descriptor_count At least two transmit descriptors are required and transmit performance of the TCP IP library will scale with the number of descriptors allocated At least one receive descriptor is required and receive performance of the TCP IP library will scale with the number of descriptors allocated The clock provided to the module is passed in clock in Hertz The driver automatically configures the MAC to divide the module clock in order to clock the management interface at a maximum of 2 5 MHz Note mem must be accessible by the DMA engine of the Ethernet MAC Please ensure that yo
108. rossWorks TCP IP Library ct udp bind Synopsis CIES TATUS GE etliudplibind Clie NA PORT It port Cit UDI INE TIN ie saiikaelk Description ctl_udp_bind registers the callback function callback for received datagrams on UDP port port To unbind a port to enable reuse of the port s resources use ctl_udp_unbind ctl_udp_bind returns CTL_NO_ERROR if the call was successful i e the number of bound ports was less than the value passed to ctl_udp_init See Also CTL_UDP_RECV_FN_t ct udp unbind 145 CrossWorks TCP IP Library CrossWorks TCP IP Library ct udp init Synopsis CTL STATUS t ctl_udp_init const CTL UDP CONFIGURATION t init data Description The configuration parameter max bound ports sets the maximum number of bound UDP ports The UDP layer will attempt to allocate a buffer for its state data of approximately eight bytes times max bound ports and then register the UDP layer with the IP layer The configuration parameters min_ephemeral_port and max_ephemeral_port define the UDP ephemeral port range You can elect to use a default configuration by passing a null pointer for init_data In this case the UDP layer is initialized with a maximum of 20 bound UDP ports with the ephemeral UDP port range being between 1024 and 65535 Note ctl_udp_init must be called prior to calling ctl_udp_bind See Also CTL_UDP_RECV_FN_t ctl_udp_bind 146 CrossWorks TCP IP Library CrossWorks
109. s Releases TCP listener resources for a TCP port Assign a server callback function to a bound TCP port Assign a server event UDP layer configuration parameters UDP packet information Register a UDP port callback Initialize UDP layer Send a UDP datagram Release a UDP port callback Initialize DHCP client subsystem Get lease renewal time Get lease rebind time Get lease renewal time Return assigned domain name suffix Look up a host name Get DNS server address Initialize DNS Client subsystem Get primary DNS server address 36 CrossWorks TCP IP Library ct dns print cache ct dns purge cache ct dns secondary server addr ct dns set max ttl ct dns set memory allocator ct dns set primary server addr ct dns set secondary server addr ct dns set server NTP ctl_ntp_init ctl_ntp_server_addr ctl_ntp_set_time_server ICMP ctl_icmp_init IP CTL_IP_CONFIG_t CTL_NET_IPv4_ADDR_t CTL_NET_IPv4_LOCAL_BROADCAST_ADDR ctl_net_get_gateway_address ctl_net_get_ip_address ctl_net_get_subnet_mask ctl_net_is_autoip_address ctl_net_is_local_broadcast_address ctl_net_is_local_ip_address ctl_net_is_multicast_ip_address ctl_net_is_private_ip_address ctl_net_is_subnet_broadcast_address ctl_net_scan_dot_decimal_ip_addr ARP ctl_arp_cache_entry ctl_arp_clear_entry ctl_arp_get_entry ctl_arp_get_ttl ctl_arp_print_cache ctl_arp_purge_cache CrossWorks TCP IP Library Display the DNS ca
110. sscsssusedsnavescenssessnsvascotoecseansevsonvescevseasnaneaseanoeds 79 n set EE AE EE 80 ct dns set memory allocatOF on eessssessssescssescsseessssccsseessseccsseesssccsssessssccnssscsnccessccesecessecessecesssesses 81 ct dns set primary server addF uuusseee seen seek ee REAGEER EER ee Bee Re ee eek ee ee 82 ct dns set secondary server addr uuseessee seek ee ROER Gee Oe Oe oek GER GER oek ek ek eke 83 ct dns set server ct eth get mac addr CE eed LE N Ed 86 ctl ip sprint addr RA EE N N EE N 87 ct mac addr is broadcast ccsscssscsssssssssssessscssecsssesseessessnecsssssnsessessasesseesnsessscsasesnsesasessssssesasesssesass 88 ct mac addr is null or empty CLIMATES dad ls OR Ee E A SLEE Ea 90 CrossWorks TCP IP Library Contents ct net domain name suffix ct net get Gateway address ere Ee RE N eg Reed RR enge eko eke Reese Geek Ee 92 ctl net get host name ou ecccssscsssecsssecsssecsssccsssecsssscsssccssscesssccsneccsseccsseccssscesseessscessscessnsessseessneceaseesssees 93 cil net get Ip address AA N ninnan E 94 ctl net get_subnet Mask SE EE EE snnasnaan aaaea S 95 EEN nat Hit ncn AA A S 96 cil mot Mre OE ann E E 97 ctl net is autoip AGALESS sccsssss cccsesssvsssasccsosecassecssnesccecssnssasbeasensscesstesssvarseserdesasvivecsersonssebestssnsssccancnssstbeas 98 ct net is local broadcast addresS users ee ee EER ee oe eke ee Ge eek ee ER ek ee gegee ge 99 ctl net is local ip
111. sseesaeesseessecsseesseesaeesseesseessees 177 CrossWorks TCP IP Library Contents ctl net read phy operating mode seen sssen sek ek GER GER OER Ge RARR Roe Roe Roe Ge Roe Re Re 178 et net read phy register esse es RE ee seeks GE a ed Een RE RE ee 179 ctl net read phy state on sesse oek OER GR GER OER ek GER Oak GER eek oo Roe Roe oe Gee Gee ek Gee ee ees 180 ctil net search fer first DRY sissies seels RS datovaientssccavsuasencasialas canouaiecrsesccrosasetdsucsbas datovciessaedenh 181 ctl net set mem driver sense oen oek ee REKE Roe we 182 ctl net update PAY AO OR cavanucasccasccctiacedcaenn a A N E RARE RR aS 183 et phy Mos init ei AE irarri ariin are ENRE ET aroancertoiseereed 184 ctl phy read id AE ON 185 EA AA AE EE EE 186 BET e VE OI RE EE EE 187 ACAI AR MEADER N AA AE AG 188 CILP TATS by EE Ee ee GE ee ees ee EG ee Ee ee Ee 189 ct arp init ed oi Mel EE E 1 OR EET 191 CELL se ol di n EA 192 etl AA NE EE eusenavaesh 193 Ctl eth te frame total COU TE assess dss ss ssstsscicosssscatov acest anucated cesnovdvesnacscannsaseseaaissbanteatoadveanasseatovadesbaaveas 194 ct ipv4 make multicast mac addr ou ceesssssscsssscsssscsscessscccsscssssscssescsssccssecesssccsneccssseseneceeseeesnecess 195 ct ipv4 rx payload byte cCOUN ou cecsssssssscssescsscccsseccsssccsseccssecsssecsssccsssccssssessscessecersseessseerseeesees 196 tl Do dd de is N ye ses sccccassscssctsssess E 197 ct net calc cksum ct net normaliz
112. ssworks rowley co uk fake Hello from the CrossWorks TCP IP Library 0 Hello n nThis is the CrossWorks TCP IP Library sending an e mail to you n n Regards n n The CrossWorks Team Didnt send that e mail comrectily Sorry i printf SMTP E mail sent OK n Done return example_finish 34 CrossWorks TCP IP Library lt ctl_net_api h gt Overview TCP IP Library public interface API Summary Network CTL_NET_ERROR_t CTL_NET_PORT_t ctl_net_get_host_name ctl_net_init ctl_net_interface ctl_net_set_host_name Sockets CTL_SOCKET_t CTL_TCP_ACCEPT_FN_t CTL_TCP_GEN_ISS_FN_t CTL TCP GET SOCKETS FLAG t CTL TCP PORT OPTIONS t CTL TCP SEND FLAG t CTL TCP SOCKET CLOSE TYPE t CTL TCP SOCKET CONNECTION STATE t CTL TCP SOCKET OPTIONS t ct soc use callback ct soc use event ctl tcp accept ct tcp bind ct tcp close socket ct tcp connect ct tcp get local ip addr ct tcp get local port ct tcp get port options ct tcp get remote ip addr ct tcp get remote port CrossWorks TCP IP Library Network Library errors A network port Get host name Initialize network library Network interface Set host name A TCP socket Accept callback Initial send segment generation Flags for enumerating sockets TCP port options Socket send options Socket close options Logical socket state Socket options Assign a server callback function on a per socket b
113. t dhcp lease rebind time returns the time that the DHCP client will attempt a rebind as the lease has not been renewed by a DHCP server Note This is provided as a convenience so the application can print DHCP information the DHCP client code in the Network Library manages all aspects of the IP lease See Also ctl_dhcp_lease_renew_time ctl_dhcp_lease_expire_time 71 CrossWorks TCP IP Library CrossWorks TCP IP Library ct dhcp lease renew time Synopsis CTL TIME t ctl1 dhcp lease renew time void Description ct dhcp lease renew time returns the time that the DHCP client initiates renewal to extend the lease of the assigned IP address Note This is provided as a convenience so the application can print DHCP information the DHCP client code in the Network Library manages all aspects of the IP lease See Also ctl_dhcp_lease_rebind_time ctl_dhcp_lease_expire_time 72 CrossWorks TCP IP Library CrossWorks TCP IP Library ct dns get host by name Synopsis CTL STATUS t ctl1 dns get host by name const char hostname CT1 NET TPv4 ADDR t addr CTL TEME CIMSCUE p Description ctl_dns_get_host_by_name writes the IP address of the host hostname into the address pointed to by ip_addr If ms is zero this is a non blocking lookup otherwise it is a blocking lookup The host name is validated and if invalid ctl_dns_get_host_by_name returns CTL_DNS_HOST_NAME_ERROR If t
114. t tcp read line Synopsis CTE STATUS t ctl tep read Line CTL SOCKET E S char str size t size CTL TIMEOUT t type CTL TIME t timeout Description ct tcp read line reads a whole line up to and including the CR and optional LF from the socket s size is the size of the string that the line is returned in If the whole string cannot be placed into str characters beyond the end of the string up to the end of the line are discarded ctl_tcp_read_line returns the number of characters that have been consumed from the socket s which may be greater than the length of the returned string or size See Also ctl_tcp_look_ahead 134 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl tcp recv Synopsis sus TAN Cait EbeCpmre cu Clim s sr S void buf size_t bufLen CM IMINO sper CTL_TIME t timeout Description ctl_tcp_recv receives up to bufLen bytes into buf from socket soc Socket soc must first be in the connected state CTL_TCP_SOCKET_STATE_CONNECTED or ctl_tcp_recv will fail buf may be null in which case up to bufLen bytes are discarded from the input stream The timeout value timeout can be zero to indicate a non blocking call If that is the case this routine will retrieve as much data as it can up to bufLen from the socket and immediately return In a blocking call multiple passes across the task synchronization between the network task and the calling task may be required before the
115. t s Description ct arp print cache displays the contents of the ARP cache to the stream s 63 CrossWorks TCP IP Library ct arp purge cache Synopsis void ctl_arp_purge_cache void Description ctl_arp_purge_cache clears the entire ARP cache Thread Safety ctl_arp_purge_cache is thread safe See Also ctl_arp_clear_entry 64 CrossWorks TCP IP Library CrossWorks TCP IP Library CrossWorks TCP IP Library ct arp reduest entry Synopsis void ctl1 arp reguest entry CTL NET IPv4 ADDR t ip addr Description ct arp reguest entry generates an ARP request for the MAC address corresponding to the IP address ip addr 65 CrossWorks TCP IP Library CrossWorks TCP IP Library ct arp set cache size Synopsis void ctl1 arp set cache size unsigned size Description ct arp set cache size sets the maximum number of entries held in the ARP cache to size ct arp set cache size restricts the range of size to be between 4 and 256 entries ctl arp set cache size does not clear the ARP cache when it is resized but if the cache is contracted entries in the cache cache are discarded in reverse age order from oldest to youngest Thread Safety ctl_arp_set_cache_size is thread safe 66 CrossWorks TCP IP Library CrossWorks TCP IP Library ct arp set memory allocator Synopsis void ctl1 arp set memory allocator CTL MEMORY ALLOCATOR t allocator Description
116. ternet aa CrossWorks TCP IP Library CrossWorks TCP IP Library CTL NET MAC ADDR t Synopsis typedef struct unsigned char octet CD hwN EMAC iA DRIE Description CTL NET MAC ADDR t points to an object that contains the Ethernet MAC address in network byte order 45 CrossWorks TCP IP Library CTL NET PORT t Synopsis typedef unsigned short CTL NET PORT t Description CTL NET PORT tisa network port Note Ports are always specified in network byte order 46 CrossWorks TCP IP Library CrossWorks TCP IP Library CrossWorks TCP IP Library CTL SOCKET t Synopsis typedef CTL STREAM t CTL SOCKET t Description CTL_SOCKET_t is the type for TCP sockets You can treat the TCP socket as a simple stream of bytes and read from and write to the socket using standard CTL stream functions 47 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL TCP ACCEPT FN t Synopsis typedef unsigned CTL TCP ACCEPT FN t CTL SOCKET t Description The Accept callback performs two functions Decide whether or not the network library will accept an incoming connection request e Setup the process socket callback or CTL task trigger event i e call ct tcp use callback or ctl tcp use event When a SYN synchronize or connect packet arrives for a bound port a check is first made to determine if there is a free socket and that the number of open sockets for the port is less than the max
117. timed out Request timed out Pani stasisties or Mol oo AA Packets Sent 4 Received 0 Lost 4 100 loss OK that one seems free as the host is not reachable on the network You might see a variation on the above gt ping 10 0 0 44 Pinging 1070044 wath 32 bytes of data Reply from 10 0 0 58 Destination host unreachable Reply from 10 0 0 58 Destination host unreachable Reply from 10 0 0 58 Destination host unreachable Reply from 10 0 9 58 Destination host unreachable Pine stakiseies or Mo OON AA Packets Sent 4 Received 4 Lost 0 0 loss CrossWorks TCP IP Library This indicates that the ping request was answered in this case by 10 0 0 58 with a response that says that the IP address 10 0 0 44 cannot be reached Configure the board s network Double click the file example_minimal_ping_fixed_ipaddr c in the Source Files folder and it will open in the code editor Set up network using a fixed IP address include libnet ctl_net_private h include libplatform platform h include libplatform platform_network h include example_support h include lt string h gt 16 CrossWorks TCP IP Library CrossWorks TCP IP Library 2 YOU must al Ger nese to March Hour Hetwor l define FIXED_IP_ADDRESS 10 0 0 44 define FIXED_NETMASK TAS G2 Do coe oO Assign a fixed MAC address to the NIC Normally this will be blown into OTP or some other nonvolatile medium when the devi
118. tion In order to get the most flexibility out of a limited resource the network library dynamically allocates RAM where and when it needs it Systems that have dedicated Ethernet memory may use the network stack s built in net memory manager to manage the pool of Ethernet memory that is used for outgoing frames and TCP and UDP buffers Targets that don t have dedicated Ethernet memory may still benefit from using the net memory manager Because the stack memory allocations are extremely transitory more often than not there is no net memory allocated and the net memory heap is thus not fragmented Using a private sub heap is much more efficient than using the general heap in this particular case If you must squeeze every last bit of flexibility from dynamic RAM then there is a stack version of the net memory manager that uses the general heap You gain access to all of the heap but you will be sharing it with the rest of the application and you will take a performance hit because of fragmentation issues The MAC layer is responsible for freeing net memory After transmit it should call ctl_net_mem_free on transmit frames and their data that it gets from the higher stack layers The hdrData pointer of the CTL_ETH_TX_FRAME_t should always be ctl_net_mem_free d as well as the payload free pointer if it is non null and the CTL ETH TX FRAME t itself ct net mem alloc xmit and ct net mem alloc data both allocate memory for t
119. to 15 characters See Also ctl net get host name 111 CrossWorks TCP IP Library CrossWorks TCP IP Library ct ntp init Synopsis eds TAL sd ke EEIAntpiinat vord Description ctl_ntp_init returns CTL NO ERROR if the call was successful i e the NTP callbacks were successfully registered with the UDP layer Note You must call call this after initializing the UDP subsystem with ctl_udp_init NTP counts as one of your bound UDP ports See Also ctl_udp_init 112 CrossWorks TCP IP Library CrossWorks TCP IP Library ct ntp server addr Synopsis CTL NET 1Pv4 ADDR t ctl1 ntp server addr void Description ctl_ntp_server_addr returns the IPv4 address of the NTP server If no NTP server is has been configured using ctl_ntp_init ctl_ntp_server_addr returns an all zero IP address 113 CrossWorks TCP IP Library CrossWorks TCP IP Library ctl_ntp_set_time_server Synopsis CTL STATUS t ctl_ntp_set_time_server CTL_NET_IPv4_ADDR_t addr Description ctl_ntp_set_time_server sets the address to use for the NTP time server to addr Return Value ctl_ntp_set_time_server returns a standard status code 114 CrossWorks TCP IP Library CrossWorks TCP IP Library ct soc use callback Synopsis CTL STATUS t ctl soc use callback CTL SOCKET t s CTL TCP SERVER FN t serverFn Description ct soc use callback assign the server callback function serverFn to the socket s This fu
120. u pass an appropriate address for the descriptors by consulting the user manual of your device 216 CrossWorks TCP IP Library CrossWorks TCP IP Library designware emac v3 isr Synopsis void designware emac v3 isr CTL NET INTERFACE t self Description designware emac v3 isr must be called to handle the interrupt generated by the network interface self designware_emac_v3_isr will iterate the transmit descriptors preparing for transmission and wake the network task to process received packets 217 CrossWorks TCP IP Library CrossWorks TCP IP Library designware_emac_v3_start Synopsis CTL STATUS t designware emac v3 start CTL_NET_INTERFACE_t self Description designware emac v3 start starts the network interface self The start sequence calls the method to select and initialize the PHY initialize the receive and transmit descriptors and enable interrupts Return Value designware emac v3 start returns a standard status code 218 CrossWorks TCP IP Library CrossWorks TCP IP Library designware emac v3 version Synopsis CTL STATUS t designware emac v3 version CTL NET INTERFACE t self char version Description designware emac v3 version returns the Synopsis version number of the DesignWare 10 100 EMAC self If version is non zero it must point to an array of at least six characters where the decoded version number is written as a null terminated string Return Value The version number as
121. ule is passed in clock in Hertz The driver automatically configures the MAC to divide the module clock in order to clock the management interface at a maximum of 2 5 MHz The interrupt source associated with the MAC is passed in interruptSource Note mem must be accessible by the DMA engine of the Ethernet MAC Please ensure that you pass an appropriate address for the descriptors by consulting the user manual of your device 210 CrossWorks TCP IP Library CrossWorks TCP IP Library designware emac v2 isr Synopsis void designware emac v2 isr CTL NET INTERFACE t self Description designware_emac_v2_isr must be called to handle the interrupt generated by the network interface self designware_emac_v2_isr will iterate the transmit descriptors preparing for transmission and wake the network task to process received packets 211 CrossWorks TCP IP Library CrossWorks TCP IP Library designware_emac_v2_start Synopsis CTL STATUS t designware emac v2 start CTL_NET_INTERFACE_t self Description designware emac v2 start starts the network interface self The start sequence calls the method to select and initialize the PHY initialize the receive and transmit descriptors and enable interrupts Return Value designware emac v2 start returns a standard status code 212 CrossWorks TCP IP Library CrossWorks TCP IP Library lt designware_emac_v3 h gt Overview Synopsis DesignWare 10 100 Ethernet MAC driver
122. um in network byte order See RFC 1071 199 CrossWorks TCP IP Library CrossWorks TCP IP Library ct net sum bytes Synopsis unsigned long ctl1 net sum bytes unsigned long sum const unsigned char data size_t byte_count Description ctl_net_sum_bytes calculates the checksum over an array of shorts See RFC 1071 The returned value is 0 through 65535 with all end around carries accounted for Note Data in and out of checksum functions are in network byte order Actually it doesn t matter which byte order is used as long as the answer is the same byte order 200 CrossWorks TCP IP Library CrossWorks TCP IP Library ct tcp register stats Synopsis void ctl1 tcp register stats void Description ct tcp register stats registers the statistics associated with TCP Note that statistics regarding TCP are always collected but they are exposed to the user only by registering with the statistics manager The statistics are failed_checksum The number of TCP segments received with a failed checksum bad_length The number of TCP segments received which had a bad length tx_malloc fail When a TCP segment is ready for transmission the network stack attempts to allocate a transmission frame If the stack fails allocate a transmission frame because there is insufficient memory it is recorded in this statistic state_error This records the number of times that the TCP state machine is detected to be in error Th
123. upport code is provided in source form you can copy that into your application to get it working CrossWorks TCP IP Library CrossWorks TCP IP Library Get on the network Your first TCP IP Library application So you have a board you have a network and you re ready to attach your device to the network The first thing to do is establish that basic Ethernet communication works between your PC and your evaluation board Install board support Install the board support package for the evaluation board that you have purchased From now on we will assume this is the SolderCore but you can substitute your own board as required So install the SolderCore Board Support Package into CrossWorks using the package manager Tools gt Package Manager Load the board examples The easiest way to load the examples for the board is to open up the Contents window navigate to Board Support expand the SolderCore Board Support Package item and click the SolderCore Samples Solution Select and build the project In the examples for your board you ll find a Networking Projects solution and within that a Minimal Network with Ping Fixed IP address project Double click that project to make it active and press F7 to build This will compile cleanly we ve tested this before release If it doesn t build cleanly that usually means that you re missing one of the packages that the board support package requires or you ve edited something within a support pac
124. ve frame buffer descriptor Transmit frame descriptor A network interface MAC states MAC driver Return MAC state MAC layer driver initialization function Send Ethernet frame to MAC Wapper for MAC update Wake network task for MAC event Process received frame PHY driver RMII MII and PHY layer errors PHY state Get PHY name Returns PHY operating mode Read a PHY register Read state of the PHY driver Search for attached PHY PHY layer update function Read the PHY ID 149 CrossWorks TCP IP Library ct phy reset MII CTL_NET_MAC_MII_DEFERRED_READ_FN_t ctl_mac_mii_deferred_read ctl_mac_mii_deferred_read_result ctl_mac_mii_read Memory management CTL_NET_MEM_DRIVER_t ctl_net_set_mem_driver Utility ctl_net_do_mac_dis_connect Stock PHY drivers ctl_phy_Im3s_init_driver Frames CTL ETH HEADER t CrossWorks TCP IP Library Reset the PHY Initiates a read of the MII management interface Initiate an asynchronous read of the MIl management interface Get result of last asynchronous MII read Read the MIl management interface Network stack memory manager Set the network memory allocator Signal change of media connection state Luminary Stellaris integrated PHY driver setup 802 3 Ethernet Header 150 CrossWorks TCP IP Library CrossWorks TCP IP Library CTL ETH HEADER t Synopsis typedef struct unsigned short __required_align unsigned char ethDstMac unsigned char ethSrcMac
Download Pdf Manuals
Related Search
Related Contents
1004 - Janome fiat ducato 3.0 mjt - Giordano Benicchi home page Samsung 913N User Manual MSDS Rechargeable Bee-Bot Samsung 960BG User Manual Rapoo H1030 MicroTest™ M5 - Thermo Scientific Digital-Analog Converter Module User`s Manual Tauchmotorrührwerk - Meyer AG, Schweizer AG Copyright © All rights reserved.
Failed to retrieve file