W5300 - SOCKET APIs: What is W5300 and How to use W5300 ?

  • Main Page
  • Related Pages
  • Modules
  • Files

What is W5300 and How to use W5300 ?

1.2.1

What is W5300?

W5300 is a 0.18um CMOS technology single chip into which 10/100 Ethernet controller, MAC, and TCP/IP are integrated. W5300 is designed for Internet embedded applications where easy implementation, stability, high performance, and effective cost are required. W5300's target application is the embedded internet solution requiring high performance such as multi-media streaming service. Comparing to existing WIZnet chip solution, W5300 has been improved in memory and data process. W5300 is the most appropriate to the products of IPTV, IP-STB and DTV transferring multi-media data with high-capacity. The Internet connectivity can be implemented easily and quickly only with single chip having TCP/IP protocol and 10/100 Ethernet MAC & PHY.

  • High-Performance Hardware TCP/IP single chip solutions
    WIZnet retains the technology of full hardware logic of communication protocols such as TCP, UDP, IPv4, ICMP, IGMP, ARP and PPPoE. In order to provide high-performing data communication, the data communication memory is extended to 128Kbyte and 16bit bus interface is supported in W5300. Users can utilize independent 8 hardware SOCKETs for high-speed data communication.

  • More flexible memory allocation for various applications
    The memory for data communication can be allocated to each SOCKET in the range of 0~64Kbytes. It is more flexible for users to utilize the memory according to their application. Users can develop more efficient system by concentrating on the application of high performance.

  • Easy to implements for beginners
    W5300 supports BUS interface as the host interface. By using direct and indirect access methods, W5300 can easily interfaced to the host as like SRAM memory. The data communication memory of W5300 can be accessed through TX/RX FIFO registers that exist in each SOCKET. With these features, even beginners can implement Internet connectivity by using W5300.

How to use W5300?

W5300 can provide Internet connectivity simply by setting some register.
WIZnet provides basic I/O funtions, WIZnet SOCKET APIs and this document for your Internet connectivity application. You can learn how to initialize W5300 and communicate according to the protocol types (TCP, UDP) by reviewing example code.
For example, Wiznet provide "TCP SERVER/CLIENT loopback" and "UDP loopback" program. Refer to Main().

  • "TCP SERVER loopback" program
    This program works as "TCP SERVER" mode, and AX1 program of the testing PC works as "TCP CLIENT" mode. AX1 tries to connect to W5300 and if the connection is successful, AX1 transmits the data stream through the connection SOCKET. This program returns back the data stream from AX1 without processing through the connection SOCKET.
    Refer to loopback_tcps().

  • "TCP CLIENT loopback" program
    This program works in "TCP CLIENT" mode and AX1 works in "TCP SERVER" mode. This program tries to connect to AX1 which is waiting as "TCP SERVR", if the connection is successful and W5300 receives data stream through the connection SOCKET, and then this program sends back the received data stream to AX1.
    Refer to loopback_tcpc().

  • "UDP loopback" program
    This program uses unicast datagram communication of UDP protocol. This program operates same as "TCP SERVER/CLIENT loopback" program does. UDP communication includes unicast datagram communication and broadcast datagram communication, and basically supports 1-to-many communication that is used for many destinations with one SOCKET.
    Refer to loopback_udp().
Generated on Fri Jan 2 12:19:59 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Todo List

  • Files

Todo List

Global __DEF_IINCHIP_BUF_OP__
__DEF_MCU_DEP_XXX__
If you define __DEF_MCU_DEP_XXX, You should do implement the code to access internal TX/RX memory of W5300.
Because the code is dependant on your MCU & compiler.

Global __DEF_IINCHIP_MAP_BASE__
__DEF_IINCHIP_MAP_BASE__ should be defined as your specified physical address value instead of '0x0800000'.

Global IINCHIP_CRITICAL_SECTION_ENTER
You should do implement that is suitable in your MCU & compiler.

Global IINCHIP_CRITICAL_SECTION_EXIT
You should do implement that is suitable in your MCU & compiler.

Global iinchip_irq
You should do implement your interrupt request routine instead of this function. If you want to use ISR, this function should be mapped in your ISR handler.

Global wait_10ms
These delay functions depend on the MCU. Therefore, These function should be replaced with yours.
Generated on Fri Jan 2 12:20:00 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Waring List

Waring List

Global recv

Global recvfrom

Global sendto

Global getSn_RX_RSR

Global getSn_SSR

Global getSn_TX_FSR

Global Sn_MSSR
Generated on Fri Jan 2 12:20:00 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Bug List

Bug List

Global Sn_SSR
At TCP communication, it happens that Sn_SSR value does't change the undefined status to the defined. This case is occurred because the previous TCP communication is abnormlay terminated when W5300 couldn't be receive the ACK packet of transmitted DATA from the peer. That is, SOCKET is closed when the transmit DATA are still remained in the SOCKET.
To solve this problem, you must be close the SOCKET after all DATA are transmitted completly. Refer to close().

Generated on Fri Jan 2 12:20:00 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Module Index

Modules

Here is a list of all modules:
  • WIZnet_SOCKET_APIs
  • IINCHIP_REG
    • MODE_REG
    • IDM_REG
    • COMMON_REG
    • SOCKET_REG
  • IINCHIP_IO_FUNC
Generated on Fri Jan 2 12:20:01 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: WIZnet_SOCKET_APIs

WIZnet_SOCKET_APIs

WIZnet SOCKET API is based on Berkeley SOCKET API, thus it has much similar name and interface.
But, there's a little bit difference like followings.

Comparison between WIZnet and Berkeley SOCKET APIs
API | WIZnet | Berkeley
socket() | O | O
bind() | X | O
listen() | O | O
connect() | O | O
accept() | X | O
recv() | O | O
send() | O | O
recvfrom() | O | O
sendto() | O | O
closesocket() | O close() & disconnect() | O

There are bind() and accept() functions in Berkeley SOCKET API but, not in WIZnet SOCKET API. Because socket() of WIZnet is not only creating a SOCKET but also binding a local port number, and listen() of WIZnet is not only listening to connection request from client but also accepting the connection request. When you program "TCP SERVER" with Berkeley SOCKET API, you can use only one listen port. When the listen SOCKET accepts a connection request from a client, it keeps listening. After accepting the connection request, a new SOCKET is created and the new SOCKET is used in communication with the client. Following figure shows network flow diagram by Berkeley SOCKET API.

<Berkeley SOCKET API>

But, When you program "TCP SERVER" with WIZnet SOCKET API, you can use as many as MAX_SOCK_NUM listen SOCKET with same port number. Because there's no accept() in WIZnet SOCKET APIs, when the listen SOCKET accepts a connection request from a client, it is changed in order to communicate with the client. And the changed SOCKET is not listening any more and is dedicated for communicating with the client. If there're many listen SOCKET with same listen port number and a client requests a connection, the SOCKET who has the smallest SOCKET number accepts the request and is changed as communication SOCKET. Following figure shows network flow diagram by WIZnet SOCKET API.

<WIZnet SOCKET API>

Note:
In using WIZnet SOCKET APIs, if byte odring of data is incorrect then set MR_FS bit using the below code.
 setMR(getMR()|MR_FS);

Generated on Fri Jan 2 12:20:00 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: IINCHIP_REG

IINCHIP_REG

Detailed Description

IINCHIP_REG defines register group of W5300. IINCHIP_REG includes 4 sub-group.

  • MODE_REG : Mode register
  • IDM_REG : Indirect mode register group
  • COMMON_REG : Common register group
  • SOCKET_REG : SOCKET register group

Note:
IDM_REG can be only used in indirect address mode.

Modules

MODE_REG
IDM_REG
COMMON_REG
SOCKET_REG

Generated on Fri Jan 2 12:20:00 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: MODE_REG

MODE_REG
[IINCHIP_REG]

Detailed Description

Mode register.
It sets the configuration which relates with host.

See also:
MR

Defines

#define MR (__DEF_IINCHIP_MAP_BASE__)
Mode register.

Define Documentation

#define MR (__DEF_IINCHIP_MAP_BASE__)

Mode register.

RESET value : 0x3800 or 0xB800
MR sets host I/F, MSB/LSB swap of Sn_TX_FIOR & Sn_RX_FIFOR, S/W reset, internal TX/RX memory test, MSB/LSB swap of data bus and address mode.

Each bit of MR defined as the following.

  • MR_DBW : 15 bit
  • MR_MPF : 14 bit
  • MR_WDF(X) : 13~11 bit
  • MR_RDH : 10 bit
  • MR_FS : 8 bit
  • MR_RST : 7 bit
  • MR_MT : 5 bit
  • MR_PB : 4 bit
  • MR_PPPoE : 3 bit
  • MR_DBS : 2 bit
  • MR_IND : 0 bit

Definition at line 128 of file w5300.h.

Referenced by getMR(), iinchip_init(), recv(), recvfrom(), send(), and setMR().

Generated on Fri Jan 2 12:20:00 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: IDM_REG

IDM_REG
[IINCHIP_REG]

Detailed Description

Indirect mode register group
These register can be accessed only in indirect address mode. In indirect address mode, You can access COMMEON_REG and SOCKET_REG indirectly using IDM_AR and IDM_DR regsiter.

See also:
__DEF_IINCHIP_ADDRESS_MODE__
Note:
If you use the W5300 in direct address mode, you can not access these register.

Defines

#define | IDM_AR (__DEF_IINCHIP_MAP_BASE__ + 0x02)
Indirect mode address register.
#define | IDM_DR (__DEF_IINCHIP_MAP_BASE__ + 0x04)
Indirect mode data register.

Define Documentation

#define IDM_AR (__DEF_IINCHIP_MAP_BASE__ + 0x02)

Indirect mode address register.

RESET value : 0x0000
It is used when indirect address mode(MR (MR_IND) = '1'). It sets address offset of COMMON_REG or SOCKET_REG that are indirectly accessible.

See also:
__DEF_IINCHIP_ADDRESS_MODE__

Definition at line 141 of file w5300.h.

Referenced by IINCHIP_READ(), IINCHIP_WRITE(), wiz_read_buf(), and wiz_write_buf().

#define IDM_DR (__DEF_IINCHIP_MAP_BASE__ + 0x04)

Indirect mode data register.

RESET value : 0x0000
It is used when indirect address mode(MR (MR_IND) = '1'). It accesses real data value of COMMON_REG or SOCKET_REG that are indirectly accessible.

See also:
__DEF_IINCHIP_ADDRESS_MODE__

Definition at line 154 of file w5300.h.

Referenced by IINCHIP_READ(), IINCHIP_WRITE(), wiz_read_buf(), and wiz_write_buf().

Generated on Fri Jan 2 12:20:00 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: COMMON_REG

COMMON_REG
[IINCHIP_REG]

Detailed Description

COMMON register group
It set the basic for the networking.
It sets a configuration such as interrupt, network information, memory allocation, etc.
And it includes registers from IR to IDR.

See also:
IR, IMR : Interrupt

SHAR, GAR, SUBR, SIPR : Network information

RTR, RCR : Data retransmittion

TMS01R, TMS23R, TMS45R, TMS67R, RMS01R, RMS23R, RMS45R, RMS67R, MTYPER : Memory allocation

PATR, PTIMER, PSIDR, PDHAR : PPPoE

UIPR, UPORTR, FMTUR : ICMP message

Pn_BRDYR, Pn_BDPTHR : PIN 'BRDYn' Configuration

IDR : W5300 ID

Defines

#define | IR (COMMON_REG_BASE + 0x02)
Interrupt register.
#define | IMR (COMMON_REG_BASE + 0x04)
Interrupt mask register.
#define | SHAR (COMMON_REG_BASE + 0x08)
Source hardware address register.
#define | GAR (COMMON_REG_BASE + 0x10)
Gateway IP address register.
#define | SUBR (COMMON_REG_BASE + 0x14)
Subnet mask register.
#define | SIPR (COMMON_REG_BASE + 0x18)
Source IP address register.
#define | RTR (COMMON_REG_BASE + 0x1C)
Retransmittion timeout-period register.
#define | RCR (COMMON_REG_BASE + 0x1E)
Retransmittion retry count reigster.
#define | TMS01R (COMMON_REG_BASE + 0x20)
Transmit memory size of each SOCKET reigster.
#define | RMS01R (COMMON_REG_BASE + 0x28)
Transmit memory size of each SOCKET reigster.
#define | MTYPER (COMMON_REG_BASE + 0x30)
Memory type register.
#define | PATR (COMMON_REG_BASE + 0x32)
Authentication type register.
#define | PTIMER (COMMON_REG_BASE + 0x36)
PPP link control protocol request timer register.
#define | PMAGICR (COMMON_REG_BASE + 0x38)
PPP LCP magic number register.
#define | PSIDR (COMMON_REG_BASE + 0x3C)
PPPoE session ID register.
#define | PDHAR (COMMON_REG_BASE + 0x40)
PPPoE destination hardware address register.
#define | UIPR (COMMON_REG_BASE + 0x48)
Unreachable IP address register.
#define | UPORTR (COMMON_REG_BASE + 0x4C)
Unreachable port number register.
#define | FMTUR (COMMON_REG_BASE + 0x4E)
Fragment MTU register.
#define | Pn_BRDYR(n) (COMMON_REG_BASE + 0x60 + n*4)
PIN 'BRDYn' configure register.
#define | Pn_BDPTHR(n) (COMMON_REG_BASE + 0x60 + n*4 + 2)
PIN 'BRDYn' buffer depth Register.
#define | IDR (COMMON_REG_BASE + 0xFE)
W5300 identification register

Define Documentation

#define FMTUR (COMMON_REG_BASE + 0x4E)

Fragment MTU register.

RESET : 0x0000
When communicating with a peer having a different MTU, iichip can receive an ICMP(Fragment MTU) packet.
At this case, IR(IR_FMTU) becomes '1' and destination IP address and fragment MTU of the received ICMP packet can be acquired through UIPR and FMTUR.
In order to communicate with the peer continously, set the FMTUR to Sn_MSSR of the SOCKET, and then try to communicate again.

Definition at line 475 of file w5300.h.

Referenced by getFMTUR().

#define GAR (COMMON_REG_BASE + 0x10)

Gateway IP address register.

RESET : 0.0.0.0
It configures gateway IP address.

Definition at line 224 of file w5300.h.

Referenced by getGAR(), and setGAR().

#define IDR (COMMON_REG_BASE + 0xFE)

W5300 identification register

RESET : 0x5300

Definition at line 528 of file w5300.h.

Referenced by getIDR().

#define IMR (COMMON_REG_BASE + 0x04)

Interrupt mask register.

RESET : 0x0000
It configures the interrupt of W5300 to notify the host.
Each interrupt mask bit of IMR corresponds to each interrupt bit of IR.
When any bit of IR is set as '1' and its corresponding bit of IMR is also set as '1', interrupt is issued to the host.

Definition at line 192 of file w5300.h.

Referenced by getIMR(), and setIMR().

#define IR (COMMON_REG_BASE + 0x02)

Interrupt register.

RESET : 0x0000
It is the register to notify W5300 interrupt type to the Host.
If any interrupt occurs, its related bit is set as '1'.
When its related mask bit is '1', b\ '/INT' signal is asserted low. '/INT' keeps low until all bits of IR becomes '0'. If all bits of IR become '0', it becomes high de-assert.
In order to clear its higher bits(15-8) which is set as '1', the host should write the bit as '1'.
In case of its lower bits(7~0) which is set as '1', it is automatically cleared when clearing the related bit of Sn_IR.

Each bit of IR defines as the following.

  • IR_IPCF : 7 bit of IR's MSB
  • IR_DPUR : 6 bit of IR's MSB
  • IR_PPPT : 5 bit of IR's MSB
  • IR_FMTU : 4 bit of IR's MSB
  • IR_SnINT(n) : n bit of IR's LSB

Definition at line 178 of file w5300.h.

Referenced by getIR(), iinchip_irq(), and setIR().

#define MTYPER (COMMON_REG_BASE + 0x30)

Memory type register.

'1' - TX memory
'0' - RX memory

RESET : 0x00FF
W5300's 128KBytes data communication memory (Internal TX/RX memory) is composed of 16 memory blocks of 8KBytes.
MTYPER configures type of each 8KB memory block - RX or TX. The type of 8KB memory block corresponds to each bit of MTYPER.
When the bit is '1', it is used as TX memory, and the bit is '0', it is used as RX memory. MTYPER is configured as TX memory type from the lower bit.
The rest of the bits not configured as TX memory, should be set as '0'.

See also:
TMS01R, RMS01R

Definition at line 353 of file w5300.h.

Referenced by sysinit().

#define PATR (COMMON_REG_BASE + 0x32)

Authentication type register.

RESET : 0x0000
It notifies authentication method negotiated with PPPoE server. W5300 supports 2 types of authentication methods.

  • PAP : 0xC023
  • CHAP : 0xC223

For the detail, refer to 'How to use PPPoE in W5300.pdf'

Definition at line 369 of file w5300.h.

Referenced by getPATR().

#define PDHAR (COMMON_REG_BASE + 0x40)

PPPoE destination hardware address register.

RESET : 0x0000
It notifies hardware address of PPPoE server (acquired by PPPoE-process of W5300).
For the detail, refer to 'How to use PPPoE in W5300.pdf'

Definition at line 425 of file w5300.h.

Referenced by getPDHAR().

#define PMAGICR (COMMON_REG_BASE + 0x38)

PPP LCP magic number register.

RESET : 0x--00
It configures byte value to be used for 4Bytes 'Magic number' during LCP negotiation with PPPoE server.
For the detail, refer to 'How to use PPPoE in W5300.pdf'

Definition at line 397 of file w5300.h.

Referenced by getPMAGICR(), and setPMAGICR().

#define Pn_BDPTHR ( n ) (COMMON_REG_BASE + 0x60 + n*4 + 2)

PIN 'BRDYn' buffer depth Register.

RESET : 0xUUUU
( 0 <= n <= 3 )

It configures buffer depth of PIN 'BRDYn'.
When monitoring TX memory and Sn_TX_FSR is same or bigger than Pn_BDPTHR, the PIN 'BRDYn' is signaled.
When monitoring RX memory and Sn_RX_RSR is same or bigger than Pn_BDPTHR, PIN 'BRDYn' is signaled.
The value for Pn_BDPTHR can't exceed TX/RX Memory size allocated by TMSxyR or RMSxyR .

Definition at line 518 of file w5300.h.

Referenced by getPn_BDPTHR(), and setPn_BDPTHR().

#define Pn_BRDYR ( n ) (COMMON_REG_BASE + 0x60 + n*4)

PIN 'BRDYn' configure register.

RESET : 0x--00
( 0 <= n <= 3 )

It sets the PIN 'BRDYn' which is monitoring TX/RX memory status of the SOCKET.
If the free buffer size of TX memory is same or bigger than the buffer depth of Pn_BDPTHR, or received buffer size of RX memory is same or bigger than the Pn_BDPTHR, PIN 'BRDYn' is signaled.

Each bit of Pn_BRDYR defines as the following.

  • Pn_PEN : 7 bit
  • Pn_MT : 6 bit
  • Pn_PPL : 5 bit
  • Pn_SN(n) : 2~0 bit

Definition at line 500 of file w5300.h.

Referenced by getPn_BRDYR(), and setPn_BRDYR().

#define PSIDR (COMMON_REG_BASE + 0x3C)

PPPoE session ID register.

RESET : 0x0000
It notifies PPP session ID to be used for communication with PPPoE server (acquired by PPPoE-process of W5300).
For the detail, refer to 'How to use PPPoE in W5300'

Definition at line 413 of file w5300.h.

Referenced by getPSIDR().

#define PTIMER (COMMON_REG_BASE + 0x36)

PPP link control protocol request timer register.

RESET : 0x--28
It configures transmitting timer of Link Control Protocol (LCP) Echo Request. Value 1 is about 25ms.

Definition at line 385 of file w5300.h.

Referenced by getPTIMER(), and setPTIMER().

#define RCR (COMMON_REG_BASE + 0x1E)

Retransmittion retry count reigster.

RESET : 0x--08
It configures the number of retransmission count.
When retransmission occurs as many as 'RCR+1' counts, Timeout interrupt is issued to the host.

See also:
RTR, IR, Sn_IR

Definition at line 280 of file w5300.h.

Referenced by getRCR(), and setRCR().

#define RMS01R (COMMON_REG_BASE + 0x28)

Transmit memory size of each SOCKET reigster.

RESET : 0x0808
RMSxyR configures each internal RX memory size of SOCKETx and SOCKETy
RX memory size of each SOCKET is configurable in the range of 0~64KBytes. 8Kbytes is assigned when reset.
Total size of each socket's RX memory should be the multiple of 8.

See also:
TMS01R, MTYPER

Definition at line 321 of file w5300.h.

Referenced by sysinit().

#define RTR (COMMON_REG_BASE + 0x1C)

Retransmittion timeout-period register.

RESET : 0x07D0
It configures Retransmission Timeout-Period.
Value 1 is 100us.
RTR is initialized with 2000(0x07D0) and has 200ms timeout-period.

See also:
RCR

Definition at line 266 of file w5300.h.

Referenced by getRTR(), and setRTR().

#define SHAR (COMMON_REG_BASE + 0x08)

Source hardware address register.

RESET : 00.00.00.00.00.00
It configures source hardware address (MAC address).

Definition at line 208 of file w5300.h.

Referenced by getSHAR(), and setSHAR().

#define SIPR (COMMON_REG_BASE + 0x18)

Source IP address register.

RESET : 0.0.0.0
It configures source IP address or notifies source IP address acquired by PPPoE-Process of W5300.

Definition at line 250 of file w5300.h.

Referenced by getSIPR(), and setSIPR().

#define SUBR (COMMON_REG_BASE + 0x14)

Subnet mask register.

RESET : 0.0.0.0
It configures subnet mask.

Definition at line 237 of file w5300.h.

Referenced by getSUBR(), and setSUBR().

#define TMS01R (COMMON_REG_BASE + 0x20)

Transmit memory size of each SOCKET reigster.

RESET : 0x0808
TMSxyR configures each internal TX memory size of SOCKETx and SOCKETy
TX memory size of each SOCKET is configurable in the range of 0~64Kbytes. 8Kbytes is assigned when reset.
Total size of each SOCKET's TX memory should be the multiple of 8.

See also:
RMS01R, MTYPER

Definition at line 295 of file w5300.h.

Referenced by sysinit().

#define UIPR (COMMON_REG_BASE + 0x48)

Unreachable IP address register.

RESET : 0.0.0.0
When trying to transmit UDP data to destination port number which is not open, W5300 can receive ICMP (Destination port unreachable) packet.
In this case, IR(IR_DPUR) becomes '1'. And destination IP address and unreachable port number of ICMP packet can be acquired through UIPR and UPORTR.

Definition at line 444 of file w5300.h.

Referenced by getUIPR(), and iinchip_irq().

#define UPORTR (COMMON_REG_BASE + 0x4C)

Unreachable port number register.

* RESET : 0x0000
Refer to UIPR.

Definition at line 457 of file w5300.h.

Referenced by getUPORTR(), and iinchip_irq().

Generated on Fri Jan 2 12:20:00 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: SOCKET_REG

SOCKET_REG
[IINCHIP_REG]

Detailed Description

SOCKET register group
SOCKET_REG configures and control SOCKETn which is necessary to a data communication.
It includes registers from Sn_MR to Sn_RX_FIFOR.

See also:
Sn_MR, Sn_CR, Sn_IMR, Sn_IR : SOCKETn Control

Sn_SSR, Sn_PORTR, Sn_DHAR, Sn_DPORTR, Sn_DIPR : SOCKETn Information

Sn_MSSR, Sn_KPALVTR, Sn_PROTOR, Sn_TOSR, Sn_TTLR, Sn_FRAGR : Internet protocol.

Sn_TX_WRSR, Sn_TX_FSR, Sn_RX_RSR, Sn_TX_FIFOR, Sn_RX_FIFOR : Data communication

Defines

#define | Sn_MR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x00)
SOCKETn mode register
#define | Sn_CR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x02)
SOCKETn command register
#define | Sn_IMR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x04)
SOCKETn interrupt mask register
#define | Sn_IR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x06)
SOCKETn interrupt register
#define | Sn_SSR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x08)
SOCKETn status register
#define | Sn_PORTR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x0A)
SOCKETn source port register
#define | Sn_DHAR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x0C)
SOCKETn destination hardware address register
#define | Sn_DPORTR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x12)
SOCKETn destination port register
#define | Sn_DIPR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x14)
SOCKETn destination IP address register
#define | Sn_MSSR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x18)
SOCKETn maximum segment size register
#define | Sn_PROTOR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x1A)
SOCKETn protocol of IP header field register
#define | Sn_KPALVTR(n) Sn_PROTOR(n)
SOCKETn keep alive timer register
#define | Sn_TOSR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x1C)
SOCKETn IP type of service(TOS) register
#define | Sn_TTLR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x1E)
SOCKETn IP time to live(TTL) register
#define | Sn_TX_WRSR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x20)
SOCKETn TX write size register
#define | Sn_TX_FSR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x0024)
SOCKETn TX free size register
#define | Sn_RX_RSR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x0028)
SOCKETn RX received size register
#define | Sn_FRAGR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x002C)
SOCKETn fragment register
#define | Sn_TX_FIFOR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x2E)
SOCKETn TX FIFO register
#define | Sn_RX_FIFOR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x30)
SOCKET n RX FIFO register

Define Documentation

#define Sn_CR ( n ) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x02)

SOCKETn command register

RESET : 0x--00
It sets command type such as open, close, connect, listen, send, recv for SOCKETn. Command type defines as the following

  • Sn_CR_OPEN : Uses in all protocol(TCP,UDP,IP raw, MAC raw, PPPoE).
  • Sn_CR_LISTEN : Uses in TCP (only 'TCP-SERVER' mode)
  • Sn_CR_CONNECT : Uses in TCP (only 'TCP-CLIENT' mode)
  • Sn_CR_DISCON : Uses in TCP (both 'TCP-SERVER' and 'TCP-CLIENT' mode)
  • Sn_CR_CLOSE : Uses in all protocol.
  • Sn_CR_SEND : Uses in all protocol.
  • Sn_CR_SEND_MAC : Uses in UDP and IP raw.
  • Sn_CR_SEND_KEEP : Uses in TCP (both 'TCP-SERVER' and 'TCP-CLIENT' mode).
  • Sn_CR_RECV : Uses in all.
  • Sn_CR_PCON : Uses in PPPoE.
  • Sn_CR_PDISCON : Uses in PPPoE.
  • Sn_CR_PCR : Uses in PPPoE.
  • Sn_CR_PCN : Uses in PPPoE.
  • Sn_CR_PCJ : Uses in PPPoE.

Definition at line 577 of file w5300.h.

Referenced by getSn_CR(), and setSn_CR().

#define Sn_DHAR ( n ) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x0C)

SOCKETn destination hardware address register

It sets or is set as destination hardware address of SOCKETn. Also, if SOCKET0 is used for PPPoE mode, S0_DHAR sets as PPPoE server hardware address that is already known.

  • When using Sn_CR_SEND_MAC at the UDP or IPRAW mode,
    it sets destination hardware address of SOCKETn.
  • At the TCP, UDP and IPRAW mode,
    Sn_DHAR is set as destination hardware address that is acquired by ARP-process of Sn_CR_CONNECT or Sn_CR_SEND. The host can acquire the destination hardware address through Sn_DHAR after successfully performing Sn_CR_CONNECT or Sn_CR_SEND.
  • When using PPPoE-process of W5300,
    PPPoE server hardware address is not required to be set. However, even if PPPoE-process of W5300 is not used but implemented by yourself with MACRAW mode, in order to transmit or receive the PPPoE packet, PPPoE server hardware address (acquired by your PPPoE-process), PPPoE server IP address, and PPP session ID should be set, and MR(PPPoE) also should be set as '1'. S0_DHAR sets PPPoE server hardware address before Sn_CR_OPEN. PPPoE server hardware address which is set by S0_DHAR is applied to PDHAR after Sn_CR_OPEN. The configured PPPoE information is internally valid even after Sn_CR_CLOSE.

Definition at line 709 of file w5300.h.

Referenced by getSn_DHAR(), and setSn_DHAR().

#define Sn_DIPR ( n ) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x14)

SOCKETn destination IP address register

It sets or is set as destination IP address of SOCKETn.
If SOCKET0 is used as PPPoE mode, S0_DIPR sets PPPoE server IP address that is already known. It is valid only in TCP, UDP, IPRAW or PPPoE mode, but ignored in MACRAW mode.

  • At the TCP mode,
    when operating as "TCP CLIENT" it sets as IP address of "TCP SERVER" before Sn_CR_CONNECT, And when operating as "TCP SERVER", it is internally set as IP address of "TCP CLIENT" after successfully establishing connection.
  • At the UDP or IPRAW mode,
    Sn_DIPR sets as destination IP address to be used for transmitting UDP or IPRAW DATA packet before Sn_CR_SEND or Sn_CR_SEND_MAC.
  • At the PPPoE mode,
    S0_DIPR sets as PPPoE server IP address that is already known. Refer to the description of Sn_DHAR in PPPoE mode.

Definition at line 758 of file w5300.h.

Referenced by connect(), getSn_DIPR(), sendto(), and setSn_DIPR().

#define Sn_DPORTR ( n ) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x12)

SOCKETn destination port register

It sets as destination port number of SOCKETn. If SOCKET0 is used as PPPoE mode, S0_DPORTR sets PPP session ID that is already known. It is valid only in TCP, UDP or PPPoE mode, and ignored in other modes.

  • At the TCP mode,
    when operating as "TCP CLIENT" it sets as the listen port number of "TCP SERVER" before Sn_CR_CONNECT.
  • At the UDP mode,
    Sn_DPORTR sets as the destination port number to be used for transmitting UDP DATA packet before Sn_CR_SEND or Sn_CR_SEND_MAC.
  • At the PPPoE mode, S0_DPORTR sets as PPP session ID that is already known. PPP session ID (set by S0_DPORTR) is applied to PSIDR after Sn_CR_OPEN. Refer to the description of Sn_DHAR in PPPoE mode.

Definition at line 735 of file w5300.h.

Referenced by connect(), sendto(), and setSn_DPORTR().

#define Sn_FRAGR ( n ) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x002C)

SOCKETn fragment register

It sets the fragment field of the IP header at the IP layer. W5300 does not support the packet fragment at the IP layer. Even though Sn_FRAGR is configured, IP data is not fragmented. And its configuration is not recommended. It should be configured before Sn_CR_OPEN.

Definition at line 934 of file w5300.h.

Referenced by getSn_FRAGR(), and setSn_FRAGR().

#define Sn_IMR ( n ) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x04)

SOCKETn interrupt mask register

RESET : 0x--FF
It configures the interrupt of SOCKETn so as to notify to the host.
Interrupt mask bit of Sn_IMR corresponds to interrupt bit of Sn_IR. If interrupt occurs in any SOCKET and the bit is set as '1', its corresponding bit of Sn_IR is set as '1'.
When the bits of Sn_IMR and Sn_IR are '1', IR(n) becomes '1'. At this time, if IMR(n) is '1', the interrupt is issued to the host.

Definition at line 593 of file w5300.h.

Referenced by getSn_IMR(), and setSn_IMR().

#define Sn_IR ( n ) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x06)

SOCKETn interrupt register

RESET : 0x--00
It is the register to notify interrupt type (establishment, termination, receiving data, timeout) of SOCKENTn to the host.
When any interrupt occurs and the mask bit of Sn_IMR is '1', the interrupt bit of Sn_IR becomes '1'. In order to clear the bit of Sn_IR which is set as '1', the host should write the bit as '1'.
When all the bits of Sn_IR is cleared as '0', IR(n) is automatically cleared.

The interrupt type defines as the following

  • Sn_IR_PRECV : 7 bit, PPP Receive Interrupt
  • Sn_IR_PFAIL : 6 bit, PPP Fail Interrupt
  • Sn_IR_PNEXT : 5 bit, PPP Next Phase Interrupt
  • Sn_IR_SENDOK : 4 bit, SEND OK Interrupt
  • Sn_IR_TIMEOUT : 3 bit, TIMEOUT Interrupt
  • Sn_IR_RECV : 2 bit, Receive Interrupt
  • Sn_IR_DISCON : 1 bit, Disconnect Interrupt
  • Sn_IR_CON : 0 bit, Connect Interrupt

Definition at line 621 of file w5300.h.

Referenced by getSn_IR(), iinchip_irq(), and setSn_IR().

#define Sn_KPALVTR ( n ) Sn_PROTOR(n)

SOCKETn keep alive timer register

It is 1 byte register that sets transmitting timer of KEEP ALIVE(KA) packet of SOCKETn. It is valid only in TCP mode, and ignored in other modes. The unit is 5 seconds.
KA packet can be transmitted after Sn_SSR is changed to SOCK_ESTABLISHED and more than one time DATA packet transmitting or receiving.

  • In case of 'Sn_KPALVTR > 0',
    W5300 automatically transmits KA packet after time-period, and checks TCP connection(Auto-keep-alive-process).
  • In case of 'Sn_KPALVTR = 0', Auto-keep-alive-process does not operate, and KA packet can be transmitted by Sn_CR_SEND_KEEP(Manual-keep-alive-process). Manual-keep-alive-process is ignored in case of 'Sn_KPALVTR > 0'

Note:
Be careful of writting a value to it when using 16bit data bus width(MR_DBW = '1').

Definition at line 846 of file w5300.h.

Referenced by getSn_KPALVTR(), and setSn_KPALVTR().

#define Sn_MR ( n ) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x00)

SOCKETn mode register

RESET : 0x0000
It configures the protocol type or option of SOCKETn. Each bit of Sn_MR defines as the following

  • Sn_MR_ALIGN : 8 bit
  • Sn_MR_MULTI : 7 bit
  • Sn_MR_MF : 6 bit
  • Sn_MR_IGMPv, Sn_MR_ND : 5 bit
  • Sn_MR(P3:P0) : 3~0 bit. This bits are defined as the following.
    1. Sn_MR_CLOSE
    2. Sn_MR_TCP
    3. Sn_MR_UDP
    4. Sn_MR_IPRAW
    5. Sn_MR_MACRAW
    6. Sn_MR_PPPoE

Definition at line 551 of file w5300.h.

Referenced by getSn_MR(), recv(), recvfrom(), setSn_MR(), and socket().

#define Sn_MSSR ( n ) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x18)

SOCKETn maximum segment size register

It sets MTU(Maximum Transfer Unit) of SOCKETn or notifies MTU that is already set. If the host does not set the Sn_MSSR, it is set as default MTU. It just supports TCP or UDP mode.

  • When using PPPoE (MR(MR_PPPoE)='1'),
    the MTU of TCP or UDP mode is assigned in the range of MTU of PPPoE.
  • At the IPRAW or MACRAW,
    MTU is not processed internally, but default MTU is used. Therefore, when transmitting the data bigger than default MTU, the host should manually divide the data into the unit of default MTU.
  • At the TCP or UDP mode,
    if transmitting data is bigger than MTU, W5300 automatically divides the data into the unit of MTU. MTU is called as MSS at the TCP mode. By selecting from Host-Written-Value and peer's MSS, MSS is set as smaller value through TCP connection process.

Below is the default MTU according to Sn_MR(P3:P0).

<The default MTU>

Note:
At the UDP mode,
there is no connection-process of TCP mode, and Host-Written-Value is just used. When communicating with the peer having different MTU, W5300 is able to receive ICMP(Fragment MTU) packet. In this case, IR(IR_FMTU) becomes '1', and the host can acquire the fragment MTU and destination IP address through FMTUR and UIPR respectively. In case of IR(IR_FMTU)='1', the UDP communication with the peer, is not possible. So, you should close the SOCKET, set FMTUR as Sn_MSSR and retry the communication with Sn_CR_OPEN.
Warning:
Warning:
If HOST set a value to Sn_MSSR, the value keeps on the MTU of SOCKETn regardless of Sn_MR and Sn_SSR. For example, If Sn_MSSR set a smaller value than the default MTU by HOST or peer, even though the SOCKETn is closed and then reopened with a different protocol, Sn_MSSR keeps on the previous written value and does't not recovery the default value. If you want to recovery the default MTU value according to the protocol(Sn_MR(P3:P0)), Write Sn_MSSR to '0xFFFF' before SOCKETn is opened.
           set_Sn_MSSR(s,0xFFFF);
           socket(s,Sn_MR_TCP,3000,0);  // The MTU will be the default value of TCP(1460);

Definition at line 806 of file w5300.h.

Referenced by getSn_MSSR(), and setSn_MSSR().

#define Sn_PORTR ( n ) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x0A)

SOCKETn source port register

It sets source port number. It is valid when SOCKETn is used as TCP or UDP mode, and ignored when used as other.

Note:
It should be set before Sn_CR_OPEN.

Definition at line 680 of file w5300.h.

Referenced by socket().

#define Sn_PROTOR ( n ) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x1A)

SOCKETn protocol of IP header field register

It is 1 byte register that sets protocol number field of IP header at the IP layer. It is valid only in IPRAW mode, and ignored in other modes. Sn_PROTOR is set before Sn_CR_OPEN. SOCKETn opened as IPRAW mode, transmits and receives the data of protocol number set in Sn_PROTOR. Sn_PROTOR can be assigned in the range of 0x00 ~ 0xFF, but W5300 does not support TCP(0x06) and UDP(0x11) protocol number.
Protocol number is defined in IANA (Internet assigned numbers authority).

See also:
IPPROTO_IP, IPPROTO_ICMP, IPPROTO_IGMP, IPPROTO_GGP, IPPROTO_TCP, IPPROTO_PUP, IPPROTO_UDP, IPPROTO_IDP, IPPROTO_ND, IPPROTO_RAW, etc.
Note:
Be careful of writting a value to it when using 16bit data bus width(MR_DBW = '1').

Definition at line 827 of file w5300.h.

Referenced by getSn_PROTOR(), and setSn_PROTOR().

#define Sn_RX_FIFOR ( n ) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x30)

SOCKET n RX FIFO register

It indirectly accesses to internal RX memory of SOCKETn.
The internal RX memory can't be directly accessed by the host, but can be accessed through Sn_RX_FIFOR. If MR(MR_MT) = '0', only the Host-Read of internal RX memory is allowed through Sn_RX_FIFOR. But MR(MR_MT) = '1', both of Host-Read and Host-Write are allowed. It should be set as '0' after verifying the interface between W5300 and the host system. (Refer to "How to Test Internal TX/RX memory").

When the host reads the received DATA packet in internal RX memory through Sn_RX_FIFOR by 2 bytes, the low and high data in internal RX memory can be read through Sn_RX_FIFOR0 and Sn_RX_FIFOR1 respectively. The host performs Sn_CR_RECV after processing the received DATA packet in internal RX memory.

Note:
It is not allowed to access Sn_RX_FIFOR0 and Sn_RX_FIFOR1 right after accessing Sn_TX_FIFOR0 and Sn_TX_FIFOR1 when using 8bit data bus width(MR(MR_DBW='0'). These are cause for the incorrect read. In order to prevent this, after reading Sn_TX_FIFOR, the host reads any register such as Sn_MR and then access Sn_RX_FIFOR.

Definition at line 979 of file w5300.h.

Referenced by getSn_RX_FIFOR(), and wiz_read_buf().

#define Sn_RX_RSR ( n ) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x0028)

SOCKETn RX received size register

It informs the byte size of received data in internal RX memory of SOCKETn. The host can't read data through Sn_RX_FIFOR as the size bigger than Sn_RX_RSR. So, after checking Sn_RX_RSR, the host read the received data though Sn_RX_FIFOR smaller than or as same size as Sn_RX_RSR, and copies the data into the host system memory.
After memory copy, the host should inform the copy completion of data to W5300 by Sn_CR_RECV. Sn_RX_RSR automatically decreases by 2bytes whenever the host reads Sn_RX_FIFOR.
In case of 'Sn_RX_RSR > 0', there is one or more DATA packet in internal RX memory. And the received data should be processed in DATA packet unit. Refer to Sn_RX_FIFOR.

Definition at line 920 of file w5300.h.

Referenced by getSn_RX_RSR().

#define Sn_SSR ( n ) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x08)

SOCKETn status register

RESET : 0x--00
It notifies SOCKETn status.
SOCKETn status can be changed by Sn_CR or packet transmission/receipt. Sn_SSR values define as the following.

  • Use in all mode
    1. SOCK_CLOSED
  • Use in TCP mode(Sn_MR(P3:P0) = Sn_MR_TCP)
    1. SOCK_INIT
    2. SOCK_LISTEN
    3. SOCK_SYNSENT
    4. SOCK_SYNRECV
    5. SOCK_ESTABLISHED
    6. SOCK_FIN_WAIT
    7. SOCK_CLOSING
    8. SOCK_TIME_WAIT
    9. SOCK_CLOSE_WAIT
    10. SOCK_LAST_ACK
  • Use in UDP mode(Sn_MR(P3:P0) = Sn_MR_UDP)
    1. SOCK_UDP
  • Use in IPRAW mode(Sn_MR(P3:P0) = Sn_MR_IPRAW)
    1. SOCK_IPRAW
  • Use in MACRAW mode(Sn_MR(P3:P0) = Sn_MR_MACRAW)
    1. SOCK_MACRAW
  • Use in PPPoE mode(Sn_MR(P3:P0) = Sn_MR_PPPoE)
    1. SOCK_PPPoE
  • Use in TCP, UDP and IPRAW mode
    1. SOCK_ARP

Below show the transition of Sn_SSR.

<Sn_SSR Transition Diagram>

Bug:
At TCP communication, it happens that Sn_SSR value does't change the undefined status to the defined. This case is occurred because the previous TCP communication is abnormlay terminated when W5300 couldn't be receive the ACK packet of transmitted DATA from the peer. That is, SOCKET is closed when the transmit DATA are still remained in the SOCKET.
To solve this problem, you must be close the SOCKET after all DATA are transmitted completly. Refer to close().

Definition at line 668 of file w5300.h.

Referenced by getSn_SSR().

#define Sn_TOSR ( n ) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x1C)

SOCKETn IP type of service(TOS) register

It sets TOS(Type of Service) field of IP header at the IP layer. It should be set before Sn_CR_OPEN.
Refer to IANA .

Definition at line 856 of file w5300.h.

Referenced by getSn_TOSR(), and setSn_TOSR().

#define Sn_TTLR ( n ) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x1E)

SOCKETn IP time to live(TTL) register

It sets TTL(Time To Live) field of IP header at the IP layer. It should be set before OPEN command.
Refer to IANA .

Definition at line 867 of file w5300.h.

Referenced by getSn_TTLR(), and setSn_TTLR().

#define Sn_TX_FIFOR ( n ) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x2E)

SOCKETn TX FIFO register

It indirectly accesses internal TX memory of SOCKETn.
The internal TX memory can't be accessed directly by the host, but can be accessed through Sn_TX_FIFOR. If MR(MR_MT) = '0', the Host-Write of internal TX memory is allowed through Sn_TX_FIFOR. But if MR(MR_MT) = '1', both of Host-Read and Host-Write are allowed. Be sure to set it as '0' after verifying interface between W5300 and the host system. (for the detail, refer to "How to Test Internal TX/RX memory").

When any data is written by the host through Sn_TX_FIFOR, the data is sequentially copied into internal TX memory. The data of Sn_TX_FIFOR0 and Sn_TX_FIFOR1 are respectively saved in low and high addresses of internal TX memory. The data in internal TX memory is transmitted in order of low address by Sn_CR_SEND or Sn_CR_SEND_MAC.

Definition at line 954 of file w5300.h.

Referenced by recv(), setSn_TX_FIFOR(), and wiz_write_buf().

#define Sn_TX_FSR ( n ) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x0024)

SOCKETn TX free size register

It notifies the free size of internal TX memory(the byte size of transmittable data) of SOCKETn.
The host can't write data through Sn_TX_FIFOR as the size bigger than Sn_TX_FSR. Therefore, be sure to check Sn_TX_FSR before transmitting data, and if data size is smaller than or same as Sn_TX_FSR, transmit the data with Sn_CR_SEND or Sn_CR_SEND_MAC after copying the data.

At the TCP mode, if the peer checks the transmitted DATA packet(if DATA/ACK packet is received from the peer), Sn_TX_FSR is automatically increased by the size of transmitted DATA packet. At the other modes, when Sn_IR(Sn_IR_SENDOK) is '1', Sn_TX_FSR is automatically increased by the size of transmitted data.

Definition at line 901 of file w5300.h.

Referenced by getSn_TX_FSR().

#define Sn_TX_WRSR ( n ) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x20)

SOCKETn TX write size register

It sets the byte size of the data written in internal TX memory through Sn_TX_FIFOR.
It is set before Sn_CR_SEND or Sn_CR_SEND_MAC, and can't be bigger than internal TX memory size set by TMSRn.

W5300 automatically divides the data in the unit of Sn_MSSR in case of 'Sn_TX_WRSR > Sn_MSSR' at the TCP or UDP mode. In other modes, Sn_TX_WRSR should not be set bigger than Sn_MSSR.

Definition at line 882 of file w5300.h.

Referenced by getSn_TX_WRSR(), and setSn_TX_WRSR().

Generated on Fri Jan 2 12:20:01 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: IINCHIP_IO_FUNC

IINCHIP_IO_FUNC

This supports the basic I/O functions for IINCHIP_REG.

  • Basic I/O function
    IINCHIP_READ(), IINCHIP_WRITE(), getMR(), setMR()

  • COMMON_REG function
    1. Interrupt
      getIR(), setIR(), getIMR(), setIMR()
    2. Network Information
      getSHAR(), setSHAR(), getGAR(), setGAR(), getSUBR(), setSUBR(), getSIPR(), setSIPR()
    3. Retransmittion
      getRCR(), setRCR(), getRTR(), setRTR()
    4. PPPoE
      getPATR(), getPTIMER(), setPTIMER(), getPMAGICR(), setPMAGICR(), getPSIDR(), getPDHAR()
    5. ICMP packet
      getUIPR(), getUPORTR(), getFMTUR()
    6. PIN "BRDYn"
      getPn_BRDYR(), setPn_BRDYR(), getPn_BDPTHR(), setPn_BDPTHR()
    7. ID
      getIDR(void);

  • SOCKET_REG function
    1. SOCKET control
      getSn_MR(), setSn_MR(), getSn_CR(), setSn_CR(), getSn_IMR(), setSn_IMR(), getSn_IR(), setSn_IR()
    2. SOCKET information
      getSn_SSR(), getSn_DHAR(), setSn_DHAR(), setSn_DPORTR(), getSn_DIPR(), setSn_DIPR(), getSn_MSSR(), setSn_MSSR()
    3. SOCKET communition
      getSn_KPALVTR(), setSn_KPALVTR(), getSn_TX_WRSR(), setSn_TX_WRSR(),
      getSn_TX_FSR(), getSn_RX_RSR(), setSn_TX_FIFOR(), getSn_RX_FIFOR()
    4. IP header field
      getSn_FRAGR(), setSn_FRAGR(), getSn_PROTOR(), setSn_PROTOR(), getSn_TOSR(), setSn_TOSR(),
      getSn_TTLR(), setSn_TTLR()

  • ETC
    1. Initialization & Interrupt request routine W5300
      iinchip_init(), iinchip_irq()
    2. Interanl memory operation
      sysinit(), getIINCHIP_TxMAX(), getIINCHIP_RxMAX(), wiz_write_buf(), wiz_read_buf()
    3. PPPoE
      pppinit(), pppterm()

Generated on Fri Jan 2 12:20:01 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: File Index

  • File List
  • Globals

File List

Here is a list of all documented files with brief descriptions:
main.c [code] | W5300 example applications
socket.c [code] | Implemetation of WIZnet SOCKET API fucntions
w5300.c [code] | Implementation of W5300 I/O fucntions
include/iinchip_conf.h [code] | W5300 Configuration & Defintions
include/socket.h [code] | WIZnet SOCKET API function definition
include/types.h [code] | Type Definition of Variables.
include/w5300.h [code] | Definition register of W5300 and basic I/O functions.
Generated on Fri Jan 2 12:20:01 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: main.c File Reference

main.c File Reference

Detailed Description

W5300 example applications

This file shows how to use WIZnet SOCKET APIs and how to implement your internet application with W5300.

Author:
MidnightCow
Date:
11/25/2008
Version:
1.2.1
Revision History :
Date | Version | Author | Description
24/03/2008 | 1.0.0 | MidnightCow | Release with W5300 launching
01/05/2008 | 1.0.1 | MidnightCow | Modify 'w5300.c'
15/05/2008 | 1.1.0 | MidnightCow | Modify 'w5300.c', 'w5300.h', and 'socket.c'.
04/07/2008 | 1.1.1 | MidnightCow | Modify 'socket.c'
08/08/2008 1.2.0 MidnightCow - Solve unmatched-link between the descripion and the source code.
  • Modify 'w5300.c' & 'socket.c'
11/25/2008 1.2.1 Bongjun - Fixed the bug in close()
  • Modify 'socket.c'

The Main() includes the example program of W5300 such as

  • loopback_tcps()
  • loopback_tcpc()
  • loopback_udp()

Definition in file main.c.

#include "main.h"
#include "xscale.h"
#include "socket.h"

Go to the source code of this file.

Functions

void | loopback_tcps (SOCKET s, uint16 port, uint8 *buf, uint16 mode)
"TCP SERVER" loopback program.
void | loopback_tcpc (SOCKET s, uint8 *addr, uint16 port, uint8 *buf, uint16 mode)
"TCP CLIENT" loopback program.
void | loopback_udp (SOCKET s, uint16 port, uint8 *buf, uint16 mode)
UDP loopback program.
void | Main ()
It executes example program such as loopback_tcps(), loopback_tcpc(), and loopback_udp().

Function Documentation

void loopback_tcpc | ( | SOCKET | s,
 |  | uint8 * | addr,
 |  | uint16 | port,
 |  | uint8 * | buf,
 |  | uint16 | mode
 | ) |  |

"TCP CLIENT" loopback program.

It initilizes SOCKET as TCP mode and try to connect to AX1. If a connection is accepted by AX1, it receives data from AX1 and sends the data to AX1.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | addr | IP address of the PC that runs AX1 ("TCP SERVER" IP address)
[in] | port | listen port number of AX1 ("TCP SERVER" listen port number)
[in,out] | buf | A buffer to be used for loopback data
[in] | mode | SOCKET options
The below image shows the flow diagram of "TCP CLIENT".

<The flow of TCP CLIENT>

Definition at line 218 of file main.c.

References close(), connect(), disconnect(), getSn_IR(), getSn_RX_RSR(), getSn_SSR(), recv(), send(), setSn_IR(), Sn_IR_CON, Sn_MR_TCP, SOCK_CLOSE_WAIT, SOCK_CLOSED, SOCK_ESTABLISHED, SOCK_INIT, and socket().

Referenced by Main().

void loopback_tcps | ( | SOCKET | s,
 |  | uint16 | port,
 |  | uint8 * | buf,
 |  | uint16 | mode
 | ) |  |

"TCP SERVER" loopback program.

It initilizes SOCKET as TCP mode and listens to a connection request of AX1. If a connection is accepted, it receives data from AX1 and sends the data to AX1.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | port | listen port number
[in,out] | buf | A buffer to be used for loopback data
[in] | mode | SOCKET options
The below image shows the flow diagram of "TCP SERVER".

<The flow of TCP SERVER>

Definition at line 162 of file main.c.

References close(), disconnect(), getSn_IR(), getSn_RX_RSR(), getSn_SSR(), listen(), recv(), send(), setSn_IR(), Sn_IR_CON, Sn_MR_TCP, SOCK_CLOSE_WAIT, SOCK_CLOSED, SOCK_ESTABLISHED, SOCK_INIT, and socket().

Referenced by Main().

void loopback_udp | ( | SOCKET | s,
 |  | uint16 | port,
 |  | uint8 * | buf,
 |  | uint16 | mode
 | ) |  |

UDP loopback program.

It initilizes SOCKET as UDP mode. If it receives data from any AX1, it sends the data to the AX1.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | port | listen port number
[in,out] | buf | A buffer to be used for loopback data
[in] | mode | SOCKET options
The below image shows the flow diagram of UDP or IPRAW.

<The flow of UDP or IPRAW>

Definition at line 274 of file main.c.

References close(), getSn_RX_RSR(), getSn_SSR(), recvfrom(), sendto(), Sn_MR_UDP, SOCK_CLOSED, SOCK_UDP, and socket().

Referenced by Main().

void Main ( )

It executes example program such as loopback_tcps(), loopback_tcpc(), and loopback_udp().

It initilizes MCU, serial port and W5300 and executes 6 loopback_tcps() which have same listen port number, 1 loopback_tcpc(), and 1 loopback_udp().

Definition at line 55 of file main.c.

References close(), getGAR(), getPDHAR(), getPSIDR(), getSHAR(), getSIPR(), getSUBR(), iinchip_init(), loopback_tcpc(), loopback_tcps(), loopback_udp(), pppinit(), pppterm(), setGAR(), setSHAR(), setSIPR(), setSUBR(), and sysinit().

Generated on Fri Jan 2 12:20:00 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: socket.c File Reference

socket.c File Reference

Detailed Description

Implemetation of WIZnet SOCKET API fucntions

This file implements the WIZnet SOCKET API functions that is used in your internat application program.

Revision History :
Date | Version | Author | Description
24/03/2008 | 1.0.0 | MidnightCow | Release with W5300 launching
15/05/2008 | 1.1.0 | MidnightCow | Refer to M_15052008. Modify the warning code block in recv().
04/07/2008 | 1.1.1 | MidnightCow | Refer to M_04072008. Modify the warning code block in recv().
08/08/2008 | 1.2.0 | MidnightCow | Refer to M_08072008. Modify close().
11/25/2008 | 1.2.1 | Bongjun | Refer to M_11252008. Modify close().

Definition in file socket.c.

#include "socket.h"
#include "lstring.h"
#include "string.h"

Go to the source code of this file.

Functions

uint8 | socket (SOCKET s, uint8 protocol, uint16 port, uint16 flag)
Open a SOCKET.
void | close (SOCKET s)
Close a SOCKET.
uint8 | connect (SOCKET s, uint8 *addr, uint16 port)
It tries to connect a client.
void | disconnect (SOCKET s)
It tries to disconnect a connection SOCKET with a peer.
uint8 | listen (SOCKET s)
It is listening to a connect-request from a client.
uint32 | send (SOCKET s, uint8 *buf, uint32 len)
It sends TCP data on a connection SOCKET.
uint32 | recv (SOCKET s, uint8 *buf, uint32 len)
It receives TCP data on a connection SOCKET.
uint32 | sendto (SOCKET s, uint8 *buf, uint32 len, uint8 *addr, uint16 port)
It sends UDP, IPRAW, or MACRAW data.
uint32 | recvfrom (SOCKET s, uint8 *buf, uint32 len, uint8 *addr, uint16 *port)
It receives UDP, IPRAW, or MACRAW data.

Variables

uint16 iinchip_source_port
Variable for temporary source port number.
uint8 | check_sendok_flag [MAX_SOCK_NUM]
The flag to check if first send or not.

Function Documentation

void close ( SOCKET s )

Close a SOCKET.

It closes a SOCKET and releases its all used resouces.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Note:
In TCP mode, if you disconnect a SOCKET using close(), a FIN packet won't be sent to the peer.
Warning:
In TCP mode, You'd better to call close() after disconect() for the safe terminating. Refer to Sn_SSR bug phase.

Definition at line 57 of file socket.c.

References getIINCHIP_TxMAX(), getSn_MR(), getSn_TX_FSR(), sendto(), setSn_CR(), setSn_IR(), Sn_CR_CLOSE, Sn_MR_TCP, Sn_MR_UDP, socket(), and wait_10ms().

Referenced by loopback_tcpc(), loopback_tcps(), loopback_udp(), and Main().

uint8 connect | ( | SOCKET | s,
 |  | uint8 * | addr,
 |  | uint16 | port
 | ) |  |

It tries to connect a client.

It operates a SOCKET as "TCP CLIENT" and sends a connect-request(SYN packet) to "TCP SERVER".
It is valid only in TCP mode.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | addr | IP address of "TCP SERVER"
[in] | port | Listen port number of "TCP SERVER".
Returns:
success - 1
fail - 0

Definition at line 86 of file socket.c.

References IINCHIP_WRITE(), setSn_CR(), Sn_CR_CONNECT, Sn_DIPR, and Sn_DPORTR.

Referenced by loopback_tcpc().

void disconnect ( SOCKET s )

It tries to disconnect a connection SOCKET with a peer.

It sends a disconnect-request(FIN packet) to "TCP SERVER" or "TCP CLIENT".
It is valid only in TCP mode.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.

Definition at line 113 of file socket.c.

References setSn_CR(), and Sn_CR_DISCON.

Referenced by loopback_tcpc(), and loopback_tcps().

uint8 listen ( SOCKET s )

It is listening to a connect-request from a client.

It operates a SOCKET as "TCP SERVER" and waits a connect-request(SYN packet) from a "TCP CLIENT".
It is valid only in TCP mode.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
success - 1
fail - 0

Definition at line 118 of file socket.c.

References getSn_SSR(), setSn_CR(), Sn_CR_LISTEN, and SOCK_INIT.

Referenced by loopback_tcps().

uint32 recv | ( | SOCKET | s,
 |  | uint8 * | buf,
 |  | uint32 | len
 | ) |  |

It receives TCP data on a connection SOCKET.

It is used to read incoming data on a connection SOCKET.
It is valid only in TCP mode.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[out] buf A buffer for the imcoming data
The length of buf should be equal or greater than len + 1, in order to prevent the memory violation.
[in] | len | The byte length of the data in buf
Returns:
It returns the number of bytes received.
Note:
When receiving TCP data from a peer,

  • In case of Sn_MR_ALIGN = '1'
    W5300 adds PACKET-INFO(2bytes lenght) in front of all received DATA(max Sn_MSSR lenght) packet in internal RX memory. The added PACKET-INFO contains the size of DATA packet. If the size of received DATA packet is odd number, 1 byte dummy data is added. The host should read this dummy data first and ignore it.

  • In case of Sn_MR_ALIGN = '0'
    iichip receives only DATA packet without PACKET-INFO. Therefore, All size of the received data should be a even number.

    Below shows the format of received TCP data.

<The format of received TCP data>

Warning:
Warning:
When SOCKETn is used only to receive data without transmitting data, the slow data receiving process by the host can cause internal RX memory full. In this case, even though W5300 window size (the maximum size of receivable data) is not '0', by misunderstanding the window size as '0', the peer does not transmit the data, and waits until window size is increased. It is the cause of decreasing data receiving performance of W5300. In order to solve the problem, the host processes the data received in internal RX memory first and notify the peer that the window size of W5300 is increased by received data size.
After Sn_CR_RECV command, add to the below code.
 if(getSn_RX_RSR(s) == 0)
 {
    setSn_TX_WRSR(s,1);
    IINCHIP_WRITE(Sn_TX_FIFOR(s),0x0000);
    setSn_CR(s,Sn_CR_SEND);
    while(!(getSn_IR(s) & Sn_IR_SENDOK));
    setSn_IR(s,Sn_IR_SENDOK);
 }
There is no need when SOCKETn is used to both receive and transmit data.

Definition at line 217 of file socket.c.

References getSn_IR(), getSn_RX_RSR(), IINCHIP_READ(), IINCHIP_WRITE(), MR, MR_FS, setSn_CR(), setSn_IR(), setSn_TX_WRSR(), Sn_CR_RECV, Sn_CR_SEND, Sn_IR_SENDOK, Sn_MR, Sn_MR_ALIGN, Sn_TX_FIFOR, and wiz_read_buf().

Referenced by loopback_tcpc(), and loopback_tcps().

uint32 recvfrom | ( | SOCKET | s,
 |  | uint8 * | buf,
 |  | uint32 | len,
 |  | uint8 * | addr,
 |  | uint16 * | port
 | ) |  |

It receives UDP, IPRAW, or MACRAW data.

It is used to read incoming data and to store a destination information.
On the IPRAW SOCKET, the port parameter are ignored.
On the MACRAW SOCKET, the addr and port parameters are ignored, making recvfrom() equivalent to recv(). But, The destination and source information is included in front of buf.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[out] buf A buffer for the imcoming data
The length of buf should be equal or greater than len + 1, in order to prevent the memory violation.
[in] | len | The byte length of the data in buf
[out] | addr | An optional pointer to the address of destination.
[out] | port | An optional the port number of destination.
Returns:
It returns the number of bytes received.
Note:
When receiving data from a peer, W5300 adds the different PACKET-INFO in front of all received DATA(max Sn_MSSR lenght) packet in internal RX memory. The added PACKET-INFO contains basically the DATA packet size which length is 2bytes and contains extra information such as destination IP address according to SOCKETn mode.
If the size of received DATA packet is odd number, 1 byte dummy data is added. The host should read this dummy data first and ignore it.

  • In case of UDP mode

    <The format of received UDP data>

    Destination IP address and port number are stored respectively in the parameters addr and port. And DATA packet is stored in the parameter buf.

  • In case of IPRAW mode

    <The format of received IPRAW data>

    Destination IP address is stored in the parameter addr. And DATA packet is stored in the parameter buf.

  • In case of MACRAW mode

    <The format of received MACRAW data>

    Destination and source MAC, and type are stored in the parameter buf. But, CRC is ignored.

Warning:
Warning:
In case that free buffer size of internal RX memory is smaller than the size of receiving MAC RAW data,
some parts of un-acceptable PACKET-INFO and DATA packet of the MACRAW data can be saved in internal RX memory. This can cause the error in analyzing PACKET-INFO, and receiving correct MACRAW data. This problem is more likely to happen when internal RX memory gets close full.
This can be solved by ignoring some loss of MACRAW data.

  • By performing internal RX memory process as quick as possible, prevent the memory to be full

  • By receiving only its own MACRAW data, reduce the receiving burden.
    Set the Sn_MR_MF bit of S0_MR by calling socket() with Sn_MR_MF flag
       socket(0,Sn_MR_MACRAW,0x1000,Sn_MR_MF);

  • In case that the free size of internal RX memory is smaller than 1528 -Default MTU(1514)+ PACKET-INFO(2)+DATA packet(8)+CRC(4)- close SOCKET 0. After closing the SOCKET0, Process all received MACRAW data and the reopen the SOCKET0.
    For example,
       // Assume that you can process the MACRAW data by this function.
   void process_macraw_data(uint8* mac_data, uint32 len);

   // main example
   void main(void)
   {
      int32 remained_rsr = 0;
      int32 rsr = 0;
      int32 recv_len = 0;
      uint8 data_buf[2048];

      while(1)
      {
         switch(getSn_SSR(0))
         {
            case SOCK_MACRAW:
               rsr = getSn_RX_RSR(0);
               if(rsr > 0)
               {
                  // check the received size.
                  if(getIINCHIP_MaxRX(0) - rsr < 1528) // Abnormal
                  {
                     remained_rsr = rsr;
                     close(s);
                     while(remained_rsr > 0)           // Process all received data.
                     {
                        recv_len = recvfrom(0,data_buf,remained_rsr,0,0);
                        remained_rsr -= (recv_len+2+4); // length of DATA packet size - 2bytes, length of CRC - 4 bytes
                        if(remained_rsr < 0)
                        {
                           // Error. It maybe receive an un-acceptable MACRAW data and should be ignored that.
                           break;
                        }
                        process_macraw_data(data_buf,recv_len);
                     }
                  }
                  else                                 // Normal
                  {
                     recv_len = recvfrom(0,data_buf,remained_rsr,0,0);
                     process_macraw_data(data_buf,recv_len);
                  }
               }
               break;
            case SOCK_CLOSED:
               socket(0,Sn_MR_MACRAW,0x1000,Sn_MR_MF); // open or re-open the MACRAW SOCKET with MAC filter flag.
               break;
         } // end switch
      } // end while
   } // end main

Definition at line 342 of file socket.c.

References IINCHIP_READ(), MR, MR_FS, setSn_CR(), Sn_CR_RECV, Sn_MR, Sn_MR_IPRAW, Sn_MR_MACRAW, Sn_MR_UDP, and wiz_read_buf().

Referenced by loopback_udp().

uint32 send | ( | SOCKET | s,
 |  | uint8 * | buf,
 |  | uint32 | len
 | ) |  |

It sends TCP data on a connection SOCKET.

It is used to write outgoing data on a connection SOCKET.
It is valid only in TCP mode.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | buf | A buffer containing the data to be transmitted
[in] | len | The byte length of the data in buf
Returns:
If no error occurs, it returns the total number of bytes sent, which can be less than the number indicated by len when len is greater than the allocated size of internal TX memory.
If error such as timeout and abnormally disconnect occurs, it returns 0.
Remarks:
It is a blocking function which doesn't return until len lenght data is transmitted completely.
Note:
if you want to use non blocking function, "do{...}while(freesize < ret)" code block can be replaced with the below code.
 while((freesize = getSn_TX_FSR(s))==0); It can tranmit data as many as free size
       ret = freesize;

Definition at line 133 of file socket.c.

References check_sendok_flag, getIINCHIP_TxMAX(), getSn_IR(), getSn_SSR(), getSn_TX_FSR(), MR, setSn_CR(), setSn_IR(), setSn_TX_WRSR(), Sn_CR_SEND, Sn_IR_SENDOK, SOCK_CLOSE_WAIT, SOCK_CLOSED, SOCK_ESTABLISHED, and wiz_write_buf().

Referenced by loopback_tcpc(), and loopback_tcps().

uint32 sendto | ( | SOCKET | s,
 |  | uint8 * | buf,
 |  | uint32 | len,
 |  | uint8 * | addr,
 |  | uint16 | port
 | ) |  |

It sends UDP, IPRAW, or MACRAW data.

It is normally used on a connectionless SOCKET to send a datagram to a specific peer identified by the to parameter(addr, port). Even if the connectionless SOCKET has been previously connected to a specific address, the addr and port parameters override the destination address for that particular datagram only.

On the IPRAW SOCKET, the port parameter are ignored.
On the MACRAW SOCKET, the addr and port parameters are ignored, making sendto() equivalent to send(). But, The destination and source information must be included in front of buf.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | buf | A buffer containing the data to be transmitted
[in] | len | The byte length of the data in buf
[in] | addr | An optional pointer to the address of destination.
[in] | port | An optional the port number of destination.
Returns:
If no error occurs, it returns the total number of bytes sent, which can be less than the number indicated by len when len is greater than the allocated size of internal TX memory.
If error such as ARP timeout and abnormally close occurs, it returns 0.
Remarks:
It is a blocking function which doesn't return until Sn_IR_SENDOK becomes '1'. It should wait in order to prevent from overriding the destination information.
Warning:
Warning:
If sendto() is failed by ARP timeout, Sn_TX_FSR is decreased as size of the transmitted data. If ARP timeout occurs continuously, Sn_RX_FSR maybe become 0 and any data can't be transmitted. But, don't worry about that. If sendto() successes only once, Sn_RX_FSR is perfectly recovered.

Definition at line 284 of file socket.c.

References getIINCHIP_TxMAX(), getSn_IR(), getSn_SSR(), IINCHIP_WRITE(), setSn_CR(), setSn_IR(), setSn_TX_WRSR(), Sn_CR_SEND, Sn_DIPR, Sn_DPORTR, Sn_IR_SENDOK, Sn_IR_TIMEOUT, SOCK_CLOSED, and wiz_write_buf().

Referenced by close(), and loopback_udp().

uint8 socket | ( | SOCKET | s,
 |  | uint8 | protocol,
 |  | uint16 | port,
 |  | uint16 | flag
 | ) |  |

Open a SOCKET.

It opens a SOCKET according protocol and bind the SOCKET with port number.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] protocol SOCKET protocol such as TCP, UDP and IP.
Refer to Sn_MR_TCP, Sn_MR_UDP, Sn_MR_IPRAW, Sn_MR_MACRAW and Sn_MR_PPPoE.
[in] | port | port number to be binded
[in] flag SOCKET option such as alignment, no-delayed ack, and etc.
Refer to Sn_MR_ALIGN, Sn_MR_MULTI, Sn_MR_MF and Sn_MR_ND/Sn_MR_IGMPv.
Returns:
Always, It returns 1.

Definition at line 38 of file socket.c.

References check_sendok_flag, getSn_SSR(), IINCHIP_READ(), iinchip_source_port, IINCHIP_WRITE(), setSn_CR(), Sn_CR_OPEN, Sn_MR, and Sn_PORTR.

Referenced by close(), loopback_tcpc(), loopback_tcps(), and loopback_udp().

Variable Documentation

uint8 check_sendok_flag[MAX_SOCK_NUM]

The flag to check if first send or not.

It is used in when you calls send().

Definition at line 35 of file socket.c.

Referenced by send(), and socket().

uint16 iinchip_source_port

Variable for temporary source port number.

It is used when you calls socket() with port number 0. It increases one whenever socket() is called with port number 0.

Definition at line 28 of file socket.c.

Referenced by socket().

Generated on Fri Jan 2 12:20:00 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: w5300.c File Reference

w5300.c File Reference

Detailed Description

Implementation of W5300 I/O fucntions

This file implements the basic I/O fucntions that access a register of W5300(IINCHIP_REG).

Revision History :
Date | Version | Author | Description
24/03/2008 | 1.0.0 | MidnightCow | Release with W5300 launching
01/05/2008 1.0.1 MidnightCow Refer to M_01052008.
Modify a logical error in iinchip_irq().
15/05/2008 1.1.0 MidnightCow Refer to M_15052008.
Delete getSn_DPORTR() because Sn_DPORTR is write-only.
Replace 'Sn_DHAR2' with 'Sn_DIPR2' in getSn_DIPR().
08/08/2008 1.2.0 MidnightCow & Gorulko Dmitry Refer to M_08082008.
Add IINCHIP_CRITICAL_SECTION_ENTER() & IINCHIP_CRITICAL_SECTION_EXIT() to wiz_read_buf() and wiz_write_buf().

Definition in file w5300.c.

#include "w5300.h"
#include "lstring.h"
#include "md5.h"

Go to the source code of this file.

Defines

#define | PPP_OPTION_BUF_LEN 64

Functions

uint16 | IINCHIP_READ (uint32 addr)
Basic I/O function.
void | IINCHIP_WRITE (uint32 addr, uint16 data)
Basic I/O function.
uint16 | getMR (void)
It gets MR value.
void | setMR (uint16 val)
It sets MR value.
uint16 | getIR (void)
It gets IR value.
void | setIR (uint16 val)
It sets IR value.
uint16 | getIMR (void)
It gets IMR value.
void | setIMR (uint16 mask)
It sets IMR value.
void | getSHAR (uint8 *addr)
It gets the source hardware address.
void | setSHAR (uint8 *addr)
It sets the source hardware address.
void | getGAR (uint8 *addr)
It gets the gateway IP address.
void | setGAR (uint8 *addr)
It sets the gateway IP address.
void | getSUBR (uint8 *addr)
It gets the subnet mask address.
void | setSUBR (uint8 *addr)
It sets the subnet mask address.
void | getSIPR (uint8 *addr)
It gets the source IP address.
void | setSIPR (uint8 *addr)
It sets the source IP address.
uint16 | getRTR (void)
It gets RTR value.
void | setRTR (uint16 timeout)
It sets RTR value.
uint8 | getRCR (void)
It gets RCR value.
void | setRCR (uint8 retry)
It sets RCR value.
uint16 | getPATR (void)
It gets PATR value.
uint8 | getPTIMER (void)
It gets PTIMER value.
void | setPTIMER (uint8 time)
It sets PTIMER value.
uint8 | getPMAGICR (void)
It gets PMAGICR value.
void | setPMAGICR (uint8 magic)
It sets PTIMER value.
uint16 | getPSIDR (void)
It gets PSIDR value.
void | getPDHAR (uint8 *addr)
It gets the PPPoE server hardware address.
void | getUIPR (uint8 *addr)
It gets the unreachable destination IP address of ICMP message.
uint16 | getUPORTR (void)
It gets the unreachable destination port number of ICMP message.
uint16 | getFMTUR (void)
It gets the fragmented MTU value of ICMP message.
uint8 | getPn_BRDYR (uint8 p)
It gets Pn_BRDYR value.
void | setPn_BRDYR (uint8 p, uint8 cfg)
It sets Pn_BRDYR value.
uint16 | getPn_BDPTHR (uint8 p)
It gets the buffer depth of PIN "BRDYn".
void | setPn_BDPTHR (uint8 p, uint16 depth)
It sets the buffer depth of PIN "BRDYn".
uint16 | getIDR (void)
It gets the ID of W5300.
uint16 | getSn_MR (SOCKET s)
It gets Sn_MR value.
void | setSn_MR (SOCKET s, uint16 mode)
It sets Sn_MR value.
uint8 | getSn_CR (SOCKET s)
It gets Sn_CR value.
void | setSn_CR (SOCKET s, uint16 com)
It sets Sn_CR value.
uint8 | getSn_IMR (SOCKET s)
It gets Sn_IMR value.
void | setSn_IMR (SOCKET s, uint8 mask)
It sets Sn_IMR value.
uint8 | getSn_IR (SOCKET s)
It gets Sn_IR value.
void | setSn_IR (SOCKET s, uint8 ir)
It sets Sn_IR value.
uint8 | getSn_SSR (SOCKET s)
It gets Sn_SSR value.
void | getSn_DHAR (SOCKET s, uint8 *addr)
It gets Sn_DHAR value.
void | setSn_DHAR (SOCKET s, uint8 *addr)
It sets Sn_DHAR value.
void | setSn_DPORTR (SOCKET s, uint16 port)
It sets Sn_DPORTR value.
void | getSn_DIPR (SOCKET s, uint8 *addr)
It gets Sn_DIPR value.
void | setSn_DIPR (SOCKET s, uint8 *addr)
It sets Sn_DIPR value.
uint16 | getSn_MSSR (SOCKET s)
It gets Sn_MSSR value.
void | setSn_MSSR (SOCKET s, uint16 mss)
It sets Sn_MSSR value.
uint8 | getSn_KPALVTR (SOCKET s)
It gets Sn_KPALVTR value.
void | setSn_KPALVTR (SOCKET s, uint8 time)
It sets Sn_KPALVTR value.
uint32 | getSn_TX_WRSR (SOCKET s)
It gets Sn_TX_WRSR value.
void | setSn_TX_WRSR (SOCKET s, uint32 size)
It gets Sn_KPALVTR value.
uint32 | getSn_TX_FSR (SOCKET s)
It gets Sn_TX_FSR value.
uint32 | getSn_RX_RSR (SOCKET s)
It gets Sn_RX_RSR value.
void | setSn_TX_FIFOR (SOCKET s, uint16 data)
It sets Sn_TX_FIFOR value.
uint16 | getSn_RX_FIFOR (SOCKET s)
It gets Sn_RX_FIFOR value.
uint8 | getSn_PROTOR (SOCKET s)
It gets Sn_PROTOR value.
void | setSn_PROTOR (SOCKET s, uint8 pronum)
It sets Sn_PROTOR value.
uint8 | getSn_TOSR (SOCKET s)
It gets Sn_TOSR value.
void | setSn_TOSR (SOCKET s, uint8 tos)
It sets Sn_TOSR value.
uint8 | getSn_TTLR (SOCKET s)
It gets Sn_TTLR value.
void | setSn_TTLR (SOCKET s, uint8 ttl)
It sets Sn_TTLR value.
uint8 | getSn_FRAGR (SOCKET s)
It gets Sn_FRAGR value.
void | setSn_FRAGR (SOCKET s, uint8 frag)
It sets Sn_FRAGR value.
void | iinchip_init (void)
It initializes W5300.
void | iinchip_irq (void)
It handles the interrupt of W5300.
uint8 | sysinit (uint8 *tx_size, uint8 *rx_size)
It allocate internal TX/RX memory of each SOCKET.
uint32 | wiz_write_buf (SOCKET s, uint8 *buf, uint32 len)
It copies data to interna1 TX memory.
uint32 | wiz_read_buf (SOCKET s, uint8 *buf, uint32 len)
It copies data to your buffer from internal RX memory.
uint32 | getIINCHIP_TxMAX (SOCKET s)
It gets the max size of internal TX memory of each SOCKET.
uint32 | getIINCHIP_RxMAX (SOCKET s)
It gets the max size of internal RX memory of each SOCKET.
uint8 | pppinit_in (uint8 *id, uint8 idlen, uint8 *passwd, uint8 passwdlen)
Internal function.
uint8 | pppinit (uint8 *id, uint8 idlen, uint8 *passwd, uint8 passwdlen)
It initializes to PPPoE of W5300.
void | pppterm (uint8 *mac, uint16 sessionid)
It terminates PPPoE connection.
void | wait_1us (uint32 us)
Delay function Refer to wait_10ms().
void | wait_1ms (uint32 ms)
Delay function Refer to wait_10ms().
void | wait_10ms (uint32 ms)
Delay function.

Variables

uint32 | TXMEM_SIZE [MAX_SOCK_NUM]
TX memory size variables.
uint32 | RXMEM_SIZE [MAX_SOCK_NUM]
RX memory size variables.
uint8 | SOCK_INT [MAX_SOCK_NUM]
The variables for SOCKETn interrupt.

Define Documentation

#define PPP_OPTION_BUF_LEN 64

Max lenght of PPPoE message

Definition at line 800 of file w5300.c.

Referenced by pppinit_in().

Function Documentation

uint16 getFMTUR ( void )

It gets the fragmented MTU value of ICMP message.

Returns:
The fragmented MTU value
See also:
IR_FMTU, Sn_MSSR, setSn_MSSR()

Definition at line 245 of file w5300.c.

References FMTUR, and IINCHIP_READ().

void getGAR ( uint8 * addr )

It gets the gateway IP address.

Parameters:
[out] addr Storage location for input the gateway IP address. It should be allocated 4bytes size.
See also:
setGAR()

Definition at line 130 of file w5300.c.

References GAR, and IINCHIP_READ().

Referenced by Main().

uint16 getIDR ( void )

It gets the ID of W5300.

Returns:
0x5300

Definition at line 274 of file w5300.c.

References IDR, and IINCHIP_READ().

uint32 getIINCHIP_RxMAX ( SOCKET s )

It gets the max size of internal RX memory of each SOCKET.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
It returns RXMEM_SIZE value of s-th SOCKET

Definition at line 788 of file w5300.c.

References RXMEM_SIZE.

uint32 getIINCHIP_TxMAX ( SOCKET s )

It gets the max size of internal TX memory of each SOCKET.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
It returns TXMEM_SIZE value of s-th SOCKET

Definition at line 783 of file w5300.c.

References TXMEM_SIZE.

Referenced by close(), send(), and sendto().

uint16 getIMR ( void )

It gets IMR value.

Returns:
The IMR value
See also:
setIMR()

Definition at line 102 of file w5300.c.

References IINCHIP_READ(), and IMR.

uint16 getIR ( void )

It gets IR value.

Returns:
The IR value
See also:
setIR()

Definition at line 93 of file w5300.c.

References IINCHIP_READ(), and IR.

uint16 getMR ( void )

It gets MR value.

Returns:
The value of MR
See also:
setMR()

Definition at line 77 of file w5300.c.

References MR.

Referenced by pppinit(), and pppterm().

uint16 getPATR ( void )

It gets PATR value.

Returns:
The value of PATR.
If PAP it returns 0xC023.
If CHAP it returns 0xC223.

Definition at line 191 of file w5300.c.

References IINCHIP_READ(), and PATR.

Referenced by pppinit_in().

void getPDHAR ( uint8 * addr )

It gets the PPPoE server hardware address.

Parameters:
[out] addr Storage location for input the source IP address. It should be allocated 6bytes size.

Definition at line 219 of file w5300.c.

References IINCHIP_READ(), and PDHAR.

Referenced by Main().

uint8 getPMAGICR ( void )

It gets PMAGICR value.

Returns:
The value of PMAGICR.
See also:
setPMAGICR()

Definition at line 205 of file w5300.c.

References IINCHIP_READ(), and PMAGICR.

uint16 getPn_BDPTHR ( uint8 p )

It gets the buffer depth of PIN "BRDYn".

Parameters:
[in] p The number of PIN "BRDYn". It is valid when 0 <= p <= 3.
Returns:
The buffer depth of PIN "BRDYn".
See also:
setPn_BDPTHR(), Pn_BRDYR

Definition at line 263 of file w5300.c.

References IINCHIP_READ(), and Pn_BDPTHR.

uint8 getPn_BRDYR ( uint8 p )

It gets Pn_BRDYR value.

Parameters:
[in] p The number of PIN "BRDYn". It is valid when 0 <= p <= 3.
Returns:
The configuration value of Pn_BRDYR.
See also:
setPn_BRDYR(), Pn_BDPTHR

Definition at line 253 of file w5300.c.

References IINCHIP_READ(), and Pn_BRDYR.

uint16 getPSIDR ( void )

It gets PSIDR value.

Returns:
The value of PSIDR.
Note:
PSIDR is read-only register.
However, in order to set PPP session ID(PSIDR), You can do it by writing S0_DPORTR to PPP session ID.

Definition at line 214 of file w5300.c.

References IINCHIP_READ(), and PSIDR.

Referenced by Main().

uint8 getPTIMER ( void )

It gets PTIMER value.

Returns:
The value of PTIMER. The unit is 25ms.
See also:
setPTIMER()

Definition at line 196 of file w5300.c.

References IINCHIP_READ(), and PTIMER.

uint8 getRCR ( void )

It gets RCR value.

Returns:
The value of RCR
See also:
setRCR()

Definition at line 181 of file w5300.c.

References IINCHIP_READ(), and RCR.

uint16 getRTR ( void )

It gets RTR value.

Returns:
The value of RTR. The unit is 100us.
See also:
setRTR()

Definition at line 172 of file w5300.c.

References IINCHIP_READ(), and RTR.

void getSHAR ( uint8 * addr )

It gets the source hardware address.

Parameters:
[out] addr Storage location for input the source hardware address. It should be allocated 6bytes size.
See also:
setSHAR()

Definition at line 114 of file w5300.c.

References IINCHIP_READ(), and SHAR.

Referenced by Main().

void getSIPR ( uint8 * addr )

It gets the source IP address.

Parameters:
[out] addr Storage location for input the source IP address. It should be allocated 4bytes size.
See also:
setSIPR()

Definition at line 156 of file w5300.c.

References IINCHIP_READ(), and SIPR.

Referenced by Main().

uint8 getSn_CR ( SOCKET s )

It gets Sn_CR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The command value of s-th SOCKET.
See also:
setSn_CR()

Definition at line 295 of file w5300.c.

References IINCHIP_READ(), and Sn_CR.

void getSn_DHAR | ( | SOCKET | s,
 |  | uint8 * | addr
 | ) |  |

It gets Sn_DHAR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[out] | addr | Storage location for input the destination hardware address of s-th SOCKET. It should be allocated 6bytes size.
Note:
It is also used when you get the PPPoE server hardware address.
Refer to getPDHAR(), PDHAR
See also:
setSn_DHAR()

Definition at line 348 of file w5300.c.

References IINCHIP_READ(), and Sn_DHAR.

void getSn_DIPR | ( | SOCKET | s,
 |  | uint8 * | addr
 | ) |  |

It gets Sn_DIPR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[out] | addr | Storage location for input the destination IP address of s-th SOCKET. It should be allocated 4bytes size.
See also:
setSn_DIPR()

Definition at line 377 of file w5300.c.

References IINCHIP_READ(), and Sn_DIPR.

uint8 getSn_FRAGR ( SOCKET s )

It gets Sn_FRAGR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The Sn_FRAGR value of s-th SOCKET.
See also:
setSn_FRAGR()

Definition at line 501 of file w5300.c.

References IINCHIP_READ(), and Sn_FRAGR.

uint8 getSn_IMR ( SOCKET s )

It gets Sn_IMR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The interrupt mask value of s-th SOCKET.
See also:
setSn_IMR(), Sn_IR, IR_SnINT

Definition at line 305 of file w5300.c.

References IINCHIP_READ(), and Sn_IMR.

uint8 getSn_IR ( SOCKET s )

It gets Sn_IR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The interrupt status of s-th SOCKET.
See also:
setSn_IR(), Sn_IMR, IR_SnINT

Definition at line 314 of file w5300.c.

References IINCHIP_READ(), Sn_IR, and SOCK_INT.

Referenced by loopback_tcpc(), loopback_tcps(), pppinit(), pppinit_in(), pppterm(), recv(), send(), and sendto().

uint8 getSn_KPALVTR ( SOCKET s )

It gets Sn_KPALVTR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The Sn_KPALVTR value of s-th SOCKET to be set.
See also:
setSn_KPALVTR()

Definition at line 405 of file w5300.c.

References IINCHIP_READ(), and Sn_KPALVTR.

uint16 getSn_MR ( SOCKET s )

It gets Sn_MR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The mode value of s-th SOCKET.
See also:
setSn_MR()

Definition at line 286 of file w5300.c.

References IINCHIP_READ(), and Sn_MR.

Referenced by close().

uint16 getSn_MSSR ( SOCKET s )

It gets Sn_MSSR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The value of Sn_MSSR
See also:
setSn_MSSR()

Definition at line 392 of file w5300.c.

References IINCHIP_READ(), and Sn_MSSR.

uint8 getSn_PROTOR ( SOCKET s )

It gets Sn_PROTOR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The protocol number of s-th SOCKET.
See also:
setSn_PROTOR()

Definition at line 472 of file w5300.c.

References IINCHIP_READ(), and Sn_PROTOR.

uint16 getSn_RX_FIFOR ( SOCKET s )

It gets Sn_RX_FIFOR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The data value to be read from internal RX memory of of s-th SOCKET, through Sn_RX_FIFOR.

Definition at line 464 of file w5300.c.

References IINCHIP_READ(), and Sn_RX_FIFOR.

uint32 getSn_RX_RSR ( SOCKET s )

It gets Sn_RX_RSR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
It returns the byte size of received data in internal RX memory of s-th SOCKET.
Warning:
Warning:
The host can read the wrong value of Sn_RX_RSR.
Because Sn_TX_RSR is not changed by 'system bus signal' but changed by synchronous 'NIC_CLK' clock.
To prevented this problem, the host should read it until the previous value is equal to the curruent.

Definition at line 444 of file w5300.c.

References IINCHIP_READ(), and Sn_RX_RSR.

Referenced by loopback_tcpc(), loopback_tcps(), loopback_udp(), pppinit_in(), and recv().

uint8 getSn_SSR ( SOCKET s )

It gets Sn_SSR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The status value of s-th SOCKET.
Warning:
Warning:
The host can read the wrong value of Sn_SSR.
Because Sn_SSR is not changed by 'system bus signal' but changed by synchronous 'NIC_CLK' clock.
To prevented this problem, the host should read it until the previous value is equal to the curruent.

Definition at line 334 of file w5300.c.

References IINCHIP_READ(), and Sn_SSR.

Referenced by listen(), loopback_tcpc(), loopback_tcps(), loopback_udp(), pppterm(), send(), sendto(), and socket().

uint8 getSn_TOSR ( SOCKET s )

It gets Sn_TOSR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The TOS value of s-th SOCKET.
See also:
setSn_TOSR()

Definition at line 483 of file w5300.c.

References IINCHIP_READ(), and Sn_TOSR.

uint8 getSn_TTLR ( SOCKET s )

It gets Sn_TTLR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The TTL value of s-th SOCKET.
See also:
setSn_TTLR()

Definition at line 492 of file w5300.c.

References IINCHIP_READ(), and Sn_TTLR.

uint32 getSn_TX_FSR ( SOCKET s )

It gets Sn_TX_FSR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
It returns the free size of internal TX memory(the byte size of transmittable data) of s-th SOCKET.
Warning:
Warning:
The host can read the wrong value of Sn_TX_FSR.
Because Sn_TX_FSR is not changed by 'system bus signal' but changed by synchronous 'NIC_CLK' clock.
To prevented this problem, the host should read it until the previous value is equal to the curruent.

Definition at line 430 of file w5300.c.

References IINCHIP_READ(), and Sn_TX_FSR.

Referenced by close(), and send().

uint32 getSn_TX_WRSR ( SOCKET s )

It gets Sn_TX_WRSR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The byte size of data written in internal TX memory of s-th SOCKET.
See also:
setSn_TX_WRSR()

Definition at line 417 of file w5300.c.

References IINCHIP_READ(), and Sn_TX_WRSR.

void getSUBR ( uint8 * addr )

It gets the subnet mask address.

Parameters:
[out] addr Storage location for input the subnet mask address. It should be allocated 4bytes size.
See also:
getSUBR()

Definition at line 143 of file w5300.c.

References IINCHIP_READ(), and SUBR.

Referenced by Main().

void getUIPR ( uint8 * addr )

It gets the unreachable destination IP address of ICMP message.

Parameters:
[out] addr Storage location for input the unreachable destination IP address. It should be allocated 4bytes size.
Note:
PDHAR is read-only register.
However, in order to set PPPoE server hardware address(PDHAR), You can do it by writing S0_DHAR to PPPoe server hardware address.
See also:
getUPORTR(), IR_DPUR

Definition at line 232 of file w5300.c.

References IINCHIP_READ(), and UIPR.

uint16 getUPORTR ( void )

It gets the unreachable destination port number of ICMP message.

Returns:
The unreachable destination port number
See also:
getUIPR(), IR_DPUR

Definition at line 240 of file w5300.c.

References IINCHIP_READ(), and UPORTR.

void iinchip_init ( void )

It initializes W5300.

It initializes W5300 by soft reset and decides the host interface mode by configuration MR.

Note:
You can modify this function to configure MR_WDF, MR_RDH, MR_FS, MR_DBS, MR_PB, MR_PPPoE.

Definition at line 518 of file w5300.c.

References MR, MR_IND, MR_RST, and wait_10ms().

Referenced by Main().

void iinchip_irq ( void )

It handles the interrupt of W5300.

Todo:
You should do implement your interrupt request routine instead of this function. If you want to use ISR, this function should be mapped in your ISR handler.

Definition at line 536 of file w5300.c.

References IINCHIP_CRITICAL_SECTION_ENTER, IINCHIP_CRITICAL_SECTION_EXIT, IINCHIP_READ(), IINCHIP_WRITE(), IR, IR_DPUR, IR_IPCF, IR_SnINT, MAX_SOCK_NUM, Sn_IR, SOCK_INT, UIPR, and UPORTR.

uint16 IINCHIP_READ ( uint32 addr )

Basic I/O function.

It reads a value from a register

Parameters:
[in] addr register address
Returns:
the value of register
Note:
If you define __DEF_IINCHIP_DIRECT_MODE__, you can use the below code instead of this function for the better performance.
 #define IINCHIP_READ(uint32 addr) (*(vint16*)addr)

Definition at line 52 of file w5300.c.

References IDM_AR, IDM_DR, IINCHIP_CRITICAL_SECTION_ENTER, and IINCHIP_CRITICAL_SECTION_EXIT.

Referenced by getFMTUR(), getGAR(), getIDR(), getIMR(), getIR(), getPATR(), getPDHAR(), getPMAGICR(), getPn_BDPTHR(), getPn_BRDYR(), getPSIDR(), getPTIMER(), getRCR(), getRTR(), getSHAR(), getSIPR(), getSn_CR(), getSn_DHAR(), getSn_DIPR(), getSn_FRAGR(), getSn_IMR(), getSn_IR(), getSn_KPALVTR(), getSn_MR(), getSn_MSSR(), getSn_PROTOR(), getSn_RX_FIFOR(), getSn_RX_RSR(), getSn_SSR(), getSn_TOSR(), getSn_TTLR(), getSn_TX_FSR(), getSn_TX_WRSR(), getSUBR(), getUIPR(), getUPORTR(), iinchip_irq(), recv(), recvfrom(), setSn_CR(), setSn_KPALVTR(), setSn_PROTOR(), socket(), sysinit(), and wiz_read_buf().

void IINCHIP_WRITE | ( | uint32 | addr,
 |  | uint16 | data
 | ) |  |

Basic I/O function.

It writes a value to a register

Parameters:
[in] | addr | register address
[in] | data | write data
Returns:
void
Note:
If you define __DEF_IINCHIP_DIRECT_MODE__, you can use the below code instead of this function for the better performance.
 #define IINCHIP_WRITE(uint32 addr,uint16 data)  ((*(vint16*)addr) = data)

Definition at line 65 of file w5300.c.

References IDM_AR, IDM_DR, IINCHIP_CRITICAL_SECTION_ENTER, and IINCHIP_CRITICAL_SECTION_EXIT.

Referenced by connect(), iinchip_irq(), recv(), sendto(), setGAR(), setIMR(), setIR(), setPMAGICR(), setPn_BDPTHR(), setPn_BRDYR(), setPTIMER(), setRCR(), setRTR(), setSHAR(), setSIPR(), setSn_CR(), setSn_DHAR(), setSn_DIPR(), setSn_DPORTR(), setSn_FRAGR(), setSn_IMR(), setSn_IR(), setSn_KPALVTR(), setSn_MR(), setSn_MSSR(), setSn_PROTOR(), setSn_TOSR(), setSn_TTLR(), setSn_TX_FIFOR(), setSn_TX_WRSR(), setSUBR(), socket(), sysinit(), and wiz_write_buf().

uint8 pppinit | ( | uint8 * | id,
 |  | uint8 | idlen,
 |  | uint8 * | passwd,
 |  | uint8 | passwdlen
 | ) |  |

It initializes to PPPoE of W5300.

It initiazes W5300 for PPPoE and calls pppinit_in() for PPPoE processing phase.
For the detail, refer to "How to use PPPoE in W5300".

Parameters:
[in] | id | User ID for connecting to a PPPoE server
[in] | idlen | Length of id
[in] | passwd | User password for connecting to a PPPoE server
[in] | passwdlen | Length of passwd
Returns:
It returns the result of pppinit_in()

Definition at line 1116 of file w5300.c.

References getMR(), getSn_IR(), MR_FS, MR_PPPoE, pppinit_in(), setMR(), setPMAGICR(), setPTIMER(), setSn_CR(), setSn_IR(), setSn_MR(), Sn_CR_CLOSE, Sn_CR_OPEN, and Sn_MR_PPPoE.

Referenced by Main().

uint8 pppinit_in | ( | uint8 * | id,
 |  | uint8 | idlen,
 |  | uint8 * | passwd,
 |  | uint8 | passwdlen
 | ) |  |

Internal function.

It is called in pppinit().
It processes 4 phases as following.

  • PPPoE Discovery
  • LCP process
  • PPPoE authentication
  • IPCP process

Parameters:
id | User ID for connecting to a PPPoE server
idlen | Length of id
passwd | User password for connecting to a PPPoE server
passwdlen | Length of passwd
Returns:
1 - success
2 - ID or password error
3 - Timeout occurs while processing PPPoE
4 - Not support authentication type.

Definition at line 821 of file w5300.c.

References getPATR(), getSn_IR(), getSn_RX_RSR(), PPP_OPTION_BUF_LEN, setSn_CR(), setSn_IR(), setSn_TX_WRSR(), Sn_CR_PCJ, Sn_CR_PCON, Sn_CR_PCR, Sn_CR_RECV, Sn_IR_PFAIL, Sn_IR_PNEXT, Sn_IR_PRECV, wait_10ms(), wiz_read_buf(), and wiz_write_buf().

Referenced by pppinit().

void pppterm | ( | uint8 * | mac,
 |  | uint16 | sessionid
 | ) |  |

It terminates PPPoE connection.

For the detail, refer to "How to use PPPoE in W5300".

Parameters:
[in] | mac | PPPoE server hardware address occupied by pppinit() or your PPPoE-process code.
[in] | sessionid | session ID occupied by pppinit() or your PPPoE-process code.

Definition at line 1143 of file w5300.c.

References getMR(), getSn_IR(), getSn_SSR(), MR_PPPoE, setMR(), setSn_CR(), setSn_DHAR(), setSn_DPORTR(), setSn_IR(), setSn_MR(), Sn_CR_CLOSE, Sn_CR_OPEN, Sn_CR_PDISCON, Sn_MR_PPPoE, SOCK_PPPoE, and wait_10ms().

Referenced by Main().

void setGAR ( uint8 * addr )

It sets the gateway IP address.

Parameters:
[in] addr Pointer to the gateway IP address to be set
See also:
getGAR()

Definition at line 137 of file w5300.c.

References GAR, and IINCHIP_WRITE().

Referenced by Main().

void setIMR ( uint16 mask )

It sets IMR value.

Parameters:
[in] mask The mask value to be set
See also:
getIMR()

Definition at line 106 of file w5300.c.

References IINCHIP_WRITE(), and IMR.

void setIR ( uint16 val )

It sets IR value.

Parameters:
[in] val The value to be set
See also:
getIR()

Definition at line 97 of file w5300.c.

References IINCHIP_WRITE(), and IR.

void setMR ( uint16 val )

It sets MR value.

Parameters:
[in] val The value to be set
See also:
getMR()

Definition at line 81 of file w5300.c.

References MR.

Referenced by pppinit(), and pppterm().

void setPMAGICR ( uint8 magic )

It sets PTIMER value.

Parameters:
[in] magic The byte of 4byts MAGIC number for PPPoE
See also:
getPMAGICR()

Definition at line 209 of file w5300.c.

References IINCHIP_WRITE(), and PMAGICR.

Referenced by pppinit().

void setPn_BDPTHR | ( | uint8 | p,
 |  | uint16 | depth
 | ) |  |

It sets the buffer depth of PIN "BRDYn".

Parameters:
[in] | p | The number of PIN "BRDYn". It is valid when 0 <= p <= 3.
[in] | depth | The buffer depth of PIN "BRDYn" to be set.
See also:
getPn_BDPTHR(), Pn_BRDYR

Definition at line 267 of file w5300.c.

References IINCHIP_WRITE(), and Pn_BDPTHR.

void setPn_BRDYR | ( | uint8 | p,
 |  | uint8 | cfg
 | ) |  |

It sets Pn_BRDYR value.

Parameters:
[in] | p | The number of PIN "BRDYn". It is valid when 0 <= p <= 3.
[in] | cfg | The configuration values of Pn_BRDYR to be set.
See also:
getPn_BRDYR(), Pn_BDPTHR

Definition at line 257 of file w5300.c.

References IINCHIP_WRITE(), and Pn_BRDYR.

void setPTIMER ( uint8 time )

It sets PTIMER value.

Parameters:
[in] time LCP echo-request transmittion timer value to be set. The unit is 25ms.
See also:
getPTIMER()

Definition at line 200 of file w5300.c.

References IINCHIP_WRITE(), and PTIMER.

Referenced by pppinit().

void setRCR ( uint8 retry )

It sets RCR value.

Parameters:
[in] retry The retry count of retransmittion to be set.
See also:
getRCR()

Definition at line 185 of file w5300.c.

References IINCHIP_WRITE(), and RCR.

void setRTR ( uint16 timeout )

It sets RTR value.

Parameters:
[in] timeout The timeout value to be set. The unit is 100us.
See also:
getRTR()

Definition at line 176 of file w5300.c.

References IINCHIP_WRITE(), and RTR.

void setSHAR ( uint8 * addr )

It sets the source hardware address.

Parameters:
[in] addr Pointer to the source hardware address to be set.
See also:
getSHAR()

Definition at line 123 of file w5300.c.

References IINCHIP_WRITE(), and SHAR.

Referenced by Main().

void setSIPR ( uint8 * addr )

It sets the source IP address.

Parameters:
[in] addr Pointer to the source IP address to be set
See also:
getSIR()

Definition at line 163 of file w5300.c.

References IINCHIP_WRITE(), and SIPR.

Referenced by Main().

void setSn_CR | ( | SOCKET | s,
 |  | uint16 | com
 | ) |  |

It sets Sn_CR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | com | The command value of s-th SOCKET.
Note:
It is blocked until Sn_CR is cleared.
See also:
getSn_CR()

Definition at line 299 of file w5300.c.

References IINCHIP_READ(), IINCHIP_WRITE(), and Sn_CR.

Referenced by close(), connect(), disconnect(), listen(), pppinit(), pppinit_in(), pppterm(), recv(), recvfrom(), send(), sendto(), and socket().

void setSn_DHAR | ( | SOCKET | s,
 |  | uint8 * | addr
 | ) |  |

It sets Sn_DHAR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | addr | Pointer to the destination hardware address of s-th SOCKET to be set.
Note:
It is also used when you set PPPoE server hardware address.
Refer to PDHAR
See also:
getSn_DHAR()

Definition at line 358 of file w5300.c.

References IINCHIP_WRITE(), and Sn_DHAR.

Referenced by pppterm().

void setSn_DIPR | ( | SOCKET | s,
 |  | uint8 * | addr
 | ) |  |

It sets Sn_DIPR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | addr | Pointer to the destination IP address of s-th SOCKET to be set.
See also:
getSn_DIPR()

Definition at line 386 of file w5300.c.

References IINCHIP_WRITE(), and Sn_DIPR.

void setSn_DPORTR | ( | SOCKET | s,
 |  | uint16 | port
 | ) |  |

It sets Sn_DPORTR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | port | The desintinaton port number of s-th SOCKET
Note:
It is also used when you set the PPP session ID.
Refer to PSIDR

Definition at line 372 of file w5300.c.

References IINCHIP_WRITE(), and Sn_DPORTR.

Referenced by pppterm().

void setSn_FRAGR | ( | SOCKET | s,
 |  | uint8 | frag
 | ) |  |

It sets Sn_FRAGR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | frag | The Sn_FRAGR value of s-th SOCKET to be set.
Note:
W5300 doesn't support the packet fragment at the IP layer.
Even though Sn_FRAGR is configured, IP data is not fragmented.
See also:
getSn_FRAGR()

Definition at line 506 of file w5300.c.

References IINCHIP_WRITE(), and Sn_FRAGR.

void setSn_IMR | ( | SOCKET | s,
 |  | uint8 | mask
 | ) |  |

It sets Sn_IMR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | mask | The interrupt mask value of s-th SOCKET.
See also:
getSn_IMR(), Sn_IR, IR_SnINT

Definition at line 309 of file w5300.c.

References IINCHIP_WRITE(), and Sn_IMR.

void setSn_IR | ( | SOCKET | s,
 |  | uint8 | ir
 | ) |  |

It sets Sn_IR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | ir | The interrupt status of s-th SOCKET to be cleared.
See also:
getSn_IR(), Sn_IMR, IR_SnINT

Definition at line 322 of file w5300.c.

References IINCHIP_WRITE(), Sn_IR, and SOCK_INT.

Referenced by close(), loopback_tcpc(), loopback_tcps(), pppinit(), pppinit_in(), pppterm(), recv(), send(), and sendto().

void setSn_KPALVTR | ( | SOCKET | s,
 |  | uint8 | time
 | ) |  |

It sets Sn_KPALVTR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | time | The keep alive timer value of s-th SOCKET to be set. The unit is 5 seconds.
Note:
When Sn_KPALVTR > 0, KEEP ALIVE(KA) packet is automatically transmitted and Sn_CR_SEND_KEEP is ignored.
When Sn_KPALVTR = 0, KA packet is manually transmitted by Sn_CR_SEND_KEEP.
See also:
getSn_KPALVTR()

Definition at line 410 of file w5300.c.

References IINCHIP_READ(), IINCHIP_WRITE(), and Sn_KPALVTR.

void setSn_MR | ( | SOCKET | s,
 |  | uint16 | mode
 | ) |  |

It sets Sn_MR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | mode | The mode value of s-th SOCKETn.
See also:
getSn_MR()

Definition at line 290 of file w5300.c.

References IINCHIP_WRITE(), and Sn_MR.

Referenced by pppinit(), and pppterm().

void setSn_MSSR | ( | SOCKET | s,
 |  | uint16 | mss
 | ) |  |

It sets Sn_MSSR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | mss | The MSS value of s-th SOCKET to be set.
Note:
When receiving the fragment MTU of ICMP message at UDP mode, You should be set Sn_MSSR to FMTUR by using this function.
Refer to FMTUR, IR_FMTU.
See also:
getSn_MSSR()

Definition at line 397 of file w5300.c.

References IINCHIP_WRITE(), and Sn_MSSR.

void setSn_PROTOR | ( | SOCKET | s,
 |  | uint8 | pronum
 | ) |  |

It sets Sn_PROTOR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | pronum | The protocol number of s-th SOCKET to be set. pronum does't support both 0x06(TCP) and 0x11(UDP) number.
See also:
getSn_PROTOR()

Definition at line 476 of file w5300.c.

References IINCHIP_READ(), IINCHIP_WRITE(), and Sn_PROTOR.

void setSn_TOSR | ( | SOCKET | s,
 |  | uint8 | tos
 | ) |  |

It sets Sn_TOSR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | tos | The TOS value of s-th SOCKET to be set.
See also:
getSn_TOSR()

Definition at line 487 of file w5300.c.

References IINCHIP_WRITE(), and Sn_TOSR.

void setSn_TTLR | ( | SOCKET | s,
 |  | uint8 | ttl
 | ) |  |

It sets Sn_TTLR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | ttl | The TTL value of s-th SOCKET to be set.
See also:
getSn_TTLR()

Definition at line 496 of file w5300.c.

References IINCHIP_WRITE(), and Sn_TTLR.

void setSn_TX_FIFOR | ( | SOCKET | s,
 |  | uint16 | data
 | ) |  |

It sets Sn_TX_FIFOR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
data | The data value to be written into internal TX memory of of s-th SOCKET, through Sn_TX_FIFOR.

Definition at line 459 of file w5300.c.

References IINCHIP_WRITE(), and Sn_TX_FIFOR.

void setSn_TX_WRSR | ( | SOCKET | s,
 |  | uint32 | size
 | ) |  |

It gets Sn_KPALVTR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | size | The byte size of data written in interanl TX memory of s-th SOCKET.
See also:
getSn_TX_WRSR()

Definition at line 424 of file w5300.c.

References IINCHIP_WRITE(), and Sn_TX_WRSR.

Referenced by pppinit_in(), recv(), send(), and sendto().

void setSUBR ( uint8 * addr )

It sets the subnet mask address.

Parameters:
[in] addr Pointer to the subnet mask address to be set
See also:
setSUBR()

Definition at line 150 of file w5300.c.

References IINCHIP_WRITE(), and SUBR.

Referenced by Main().

uint8 sysinit | ( | uint8 * | tx_size,
 |  | uint8 * | rx_size
 | ) |  |

It allocate internal TX/RX memory of each SOCKET.

Parameters:
[in] tx_size The pointer to allocate tx_size[n] to the internal TX memory of each SOCKET.
( 0 <= n <= MAX_SOCK_NUM-1).
TX memory size of each SOCKET is configurable in the range of 0~64Kbytes. Total memory size of each SOCKET's TX memory should be the multiple of 8.
[in] rx_size The pointer to allocate rx_size[n] to the internal RX memory of each SOCKET.
( 0 <= n <= MAX_SOCK_NUM-1).
RX memory size of each SOCKET is configurable in the range of 0~64Kbytes. Total memory size of each SOCKET's TX memory and RX memory should be 128Kbytes.
Returns:
If success, it returns 1. Otherwize 0.

Definition at line 577 of file w5300.c.

References IINCHIP_READ(), IINCHIP_WRITE(), MAX_SOCK_NUM, MTYPER, RMS01R, RMS23R, RMS45R, RMS67R, RXMEM_SIZE, TMS01R, TMS23R, TMS45R, TMS67R, and TXMEM_SIZE.

Referenced by Main().

void wait_10ms ( uint32 ms )

Delay function.

Parameters:
[in] ms - wait time It waits for the ms time.
Todo:
These delay functions depend on the MCU. Therefore, These function should be replaced with yours.

Definition at line 1200 of file w5300.c.

References wait_1ms().

Referenced by close(), iinchip_init(), pppinit_in(), and pppterm().

uint32 wiz_read_buf | ( | SOCKET | s,
 |  | uint8 * | buf,
 |  | uint32 | len
 | ) |  |

It copies data to your buffer from internal RX memory.

It copies the len bytes of internal RX memory of s-th SOCKET to buf through Sn_RX_FIFOR.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[out] buf Destination buffer to copy
The length of buf should be equal or greater than len + 1, in order to prevent the memory violation.
[in] | len | bytes of internal RX memory of s-th SOCKET to copy.
Returns:
The copied byte number
Note:
In case using interrupt or multi-task, it is protected with IINCHIP_CRITICAL_SECTION_ENTER() & IINCHIP_CRITICAL_SECTION_EXIT() while Sn_RX_FIFOR read.
If no use, it can be occured some problem such as invalid PACKET_INFO or DATA.

Definition at line 714 of file w5300.c.

References IDM_AR, IDM_DR, IINCHIP_CRITICAL_SECTION_ENTER, IINCHIP_CRITICAL_SECTION_EXIT, IINCHIP_READ(), and Sn_RX_FIFOR.

Referenced by pppinit_in(), recv(), and recvfrom().

uint32 wiz_write_buf | ( | SOCKET | s,
 |  | uint8 * | buf,
 |  | uint32 | len
 | ) |  |

It copies data to interna1 TX memory.

It copies the len bytes of buf to internal TX memory of s-th SOCKET through Sn_TX_FIFOR.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | buf | Source buffer to copy from
[in] | len | bytes of data to copy.
Returns:
The copied byte number
Note:
In case using interrupt or multi-task, it is protected with IINCHIP_CRITICAL_SECTION_ENTER() & IINCHIP_CRITICAL_SECTION_EXIT() while Sn_TX_FIFOR write.
If no use, it can be occured some problem such that invalid DATA are transmitted.

Definition at line 648 of file w5300.c.

References IDM_AR, IDM_DR, IINCHIP_CRITICAL_SECTION_ENTER, IINCHIP_CRITICAL_SECTION_EXIT, IINCHIP_WRITE(), and Sn_TX_FIFOR.

Referenced by pppinit_in(), send(), and sendto().

Variable Documentation

uint32 RXMEM_SIZE[MAX_SOCK_NUM]

RX memory size variables.

It stores the real allocated RX memory size of each SOCKET. Refer to RMSxyR.

Definition at line 38 of file w5300.c.

Referenced by getIINCHIP_RxMAX(), and sysinit().

uint8 SOCK_INT[MAX_SOCK_NUM]

The variables for SOCKETn interrupt.

It stores Sn_IR value when IR_SnINT(n) = '1'. ( 0 <= n <= MAX_SOCK_NUM-1).

Definition at line 45 of file w5300.c.

Referenced by getSn_IR(), iinchip_irq(), and setSn_IR().

uint32 TXMEM_SIZE[MAX_SOCK_NUM]

TX memory size variables.

It stores the real allocated TX memory size of each SOCKET. Refer to TMSxyR.

Definition at line 30 of file w5300.c.

Referenced by getIINCHIP_TxMAX(), and sysinit().

Generated on Fri Jan 2 12:20:00 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: include/iinchip_conf.h File Reference

include/iinchip_conf.h File Reference

Detailed Description

W5300 Configuration & Defintions

This file defines some compile options of the W5300 program and code dependency of a target host system.

Compile option of the \b W5300 program

  • __DEF_IINCHIP_DBG__
    If it is defined, Some debug code is involved in the W5300 program.
  • __DEF_IINCHIP_INT__
    If it is defined, ISR routine is involved in the W5300 program.
  • __DEF_IINCHIP_PPP__
    If it is defined, PPP service routines is involved in the W5300 program. Also two files("md5.h" and "md5.c") are included in it.
  • MAX_SOCK_NUM
    It determines the SOCKET count of W5300.

Code dependency of a target host system

  • __DEF_IINCHIP_ADDRESS_MODE__
    It is used to decide to W5300 host interface mode. It must be defined with one in the following definitions.
    1. __DEF_IINCHIP_DIRECT_MODE__ : when direct mode
    2. __DEF_IINCHIP_INDIRECT_MODE__ : when indirect mode
  • __DEF_IINCHIP_MAP_BASE__
    It is determined the base address of W5300.
    You must define it as the physical address of your target host system.
    1. COMMON_REG_BASE : It is the base address of COMMON registers.
    2. SOCKET_REG_BASE : It is the base address of SOCKET registers.
  • __DEF_IINCHIP_BUF_OP__
    It define how to access to the intenal TX/RX memory of W5300.
    1. __DEF_C__ : Using C code
    2. __DEF_MCU_DEP_INLINE_ASM__ : Using inline ASM code
    3. __DEF_MCU_DEP_DMA__ : Using DMA controller
  • IINCHIP_CRITICAL_SECTION_ENTER() : Enter a critical section
  • IINCHIP_CRITICAL_SECTION_EXIT() : Exit a crtical section

Definition in file iinchip_conf.h.

Go to the source code of this file.

Defines

#define | __DEF_IINCHIP_DBG__
#define | __DEF_IINCHIP_INT__
#define | __DEF_IINCHIP_PPP__
#define | MAX_SOCK_NUM 8
#define | __DEF_IINCHIP_DIRECT_MODE__ 1
#define | __DEF_IINCHIP_INDIRECT_MODE__ 2
#define | __DEF_IINCHIP_ADDRESS_MODE__ __DEF_IINCHIP_DIRECT_MODE__
#define | __DEF_IINCHIP_MAP_BASE__ 0x08000000
Define the base address of W5300 on your target host system.
#define | COMMON_REG_BASE __DEF_IINCHIP_MAP_BASE__
#define | SOCKET_REG_BASE __DEF_IINCHIP_MAP_BASE__ + 0x0200
#define | __DEF_C__ 0
#define | __DEF_MCU_DEP_INLINE_ASM__ 1
#define | __DEF_MCU_DEP_DMA__ 2
#define | __DEF_IINCHIP_BUF_OP__ __DEF_C__
#define | IINCHIP_CRITICAL_SECTION_ENTER() {}
Enter a critical section.
#define | IINCHIP_CRITICAL_SECTION_EXIT() {}
Exit a critical section.

Define Documentation

#define __DEF_C__ 0

Using C code

Definition at line 100 of file iinchip_conf.h.

#define __DEF_IINCHIP_ADDRESS_MODE__ __DEF_IINCHIP_DIRECT_MODE__

It is used to decide to W5300 host interface mode.

Note:
If you use W5300 with indirect mode, you define as the following.
 #define  __DEF_IINCHIP_ADDRESS_MODE__    __DEF_IINCHIP_INDIRECT_MODE__

Definition at line 64 of file iinchip_conf.h.

#define __DEF_IINCHIP_BUF_OP__ __DEF_C__

It define how to access to the intenal TX/RX memory of W5300.

  • __DEF_C__
    Generally, Implements to use C code.
  • __DEF_MCU_DEP_INLINE_ASM__
    Implements to use inline ASM code
  • __DEF_MCU_DEP_DMA__
    Implements to use DMA controller

See also:
iinchip_write_buf(), iinchip_read_buf();
Todo:
__DEF_MCU_DEP_XXX__
If you define __DEF_MCU_DEP_XXX, You should do implement the code to access internal TX/RX memory of W5300.
Because the code is dependant on your MCU & compiler.

Definition at line 120 of file iinchip_conf.h.

#define __DEF_IINCHIP_DBG__

Involves debug code

Definition at line 41 of file iinchip_conf.h.

#define __DEF_IINCHIP_DIRECT_MODE__ 1

Direct address mode

Definition at line 51 of file iinchip_conf.h.

#define __DEF_IINCHIP_INDIRECT_MODE__ 2

Indirect address mode

Definition at line 52 of file iinchip_conf.h.

#define __DEF_IINCHIP_INT__

Involves ISR routine

Definition at line 42 of file iinchip_conf.h.

#define __DEF_IINCHIP_MAP_BASE__ 0x08000000

Define the base address of W5300 on your target host system.

It is used to define to base address of W5300 registers .

  • In direct mode,
       #define COMMON_REG_BASE   __DEF_IINCHIP_MAP_BASE__
   #define SOCKET_REG_BASE   __DEF_IINCHIP_MAP_BASE__ + 0x0200
  • In indirect mode,
       #define COMMON_REG_BASE     0
   #define SOCKET_REG_BASE     0x0200

Todo:
__DEF_IINCHIP_MAP_BASE__ should be defined as your specified physical address value instead of '0x0800000'.

Definition at line 85 of file iinchip_conf.h.

#define __DEF_IINCHIP_PPP__

Involves PPP service routines and md5.h & md5.c

Definition at line 43 of file iinchip_conf.h.

#define __DEF_MCU_DEP_DMA__ 2

Using DMA controller

Definition at line 102 of file iinchip_conf.h.

#define __DEF_MCU_DEP_INLINE_ASM__ 1

Using inline ASM code

Definition at line 101 of file iinchip_conf.h.

#define COMMON_REG_BASE __DEF_IINCHIP_MAP_BASE__

The base address of COMMON_REG

Definition at line 88 of file iinchip_conf.h.

#define IINCHIP_CRITICAL_SECTION_ENTER ( ) {}

Enter a critical section.

It is provided to protect your shared code which are executed without distribution.

In non-OS environment, It can be just implemented by disabling whole interrupt.
In OS environment, You can replace it to critical section api supported by OS.

See also:
IINCHIP_READ(), IINCHIP_WRITE(), getSn_TX_FSR(), getSn_RX_RSR()

IINCHIP_CRITICAL_SECTION_EXIT()

Todo:
You should do implement that is suitable in your MCU & compiler.

Definition at line 138 of file iinchip_conf.h.

Referenced by iinchip_irq(), IINCHIP_READ(), IINCHIP_WRITE(), wiz_read_buf(), and wiz_write_buf().

#define IINCHIP_CRITICAL_SECTION_EXIT ( ) {}

Exit a critical section.

It is provided to protect your shared code which are executed without distribution.

In non-OS environment, It can be just implemented by disabling whole interrupt.
In OS environment, You can replace it to critical section api supported by OS.

See also:
IINCHIP_READ(), IINCHIP_WRITE(), getSn_TX_FSR(), getSn_RX_RSR()

IINCHIP_CRITICAL_SECTION_ENTER()

Todo:
You should do implement that is suitable in your MCU & compiler.

Definition at line 155 of file iinchip_conf.h.

Referenced by iinchip_irq(), IINCHIP_READ(), IINCHIP_WRITE(), wiz_read_buf(), and wiz_write_buf().

#define MAX_SOCK_NUM 8

SOCKET count of W5300

Definition at line 48 of file iinchip_conf.h.

Referenced by iinchip_irq(), and sysinit().

#define SOCKET_REG_BASE __DEF_IINCHIP_MAP_BASE__ + 0x0200

The base address of SOCKET_REG

Definition at line 89 of file iinchip_conf.h.

Generated on Fri Jan 2 12:19:59 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: include/socket.h File Reference

include/socket.h File Reference

Detailed Description

WIZnet SOCKET API function definition

For user application, WIZnet provides SOCKET API functions which are similar to Berkeley SOCKET API.

Author:
MidnightCow
Date:
11/25/2008
Version:
1.2.1
Revision History :
Date | Version | Author | Description
24/03/2008 | 1.0.0 | MidnightCow | Release with W5300 launching
15/05/2008 | 1.1.0 | MidnightCow | Refer to M_15052008. Modify the warning code block in recv().
04/07/2008 | 1.1.1 | MidnightCow | Refer to M_04072008. Modify the warning code block in recv().
08/08/2008 | 1.2.0 | MidnightCow | Refer to M_08082008. Modify close().
11/25/2008 | 1.2.1 | Bongjun | Refer to M_11252008. Modify close().

Definition in file socket.h.

#include "types.h"
#include "w5300.h"

Go to the source code of this file.

Functions

uint8 | socket (SOCKET s, uint8 protocol, uint16 port, uint16 flag)
Open a SOCKET.
void | close (SOCKET s)
Close a SOCKET.
uint8 | connect (SOCKET s, uint8 *addr, uint16 port)
It tries to connect a client.
void | disconnect (SOCKET s)
It tries to disconnect a connection SOCKET with a peer.
uint8 | listen (SOCKET s)
It is listening to a connect-request from a client.
uint32 | send (SOCKET s, uint8 *buf, uint32 len)
It sends TCP data on a connection SOCKET.
uint32 | recv (SOCKET s, uint8 *buf, uint32 len)
It receives TCP data on a connection SOCKET.
uint32 | sendto (SOCKET s, uint8 *buf, uint32 len, uint8 *addr, uint16 port)
It sends UDP, IPRAW, or MACRAW data.
uint32 | recvfrom (SOCKET s, uint8 *buf, uint32 len, uint8 *addr, uint16 *port)
It receives UDP, IPRAW, or MACRAW data.

Function Documentation

void close ( SOCKET s )

Close a SOCKET.

It closes a SOCKET and releases its all used resouces.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Note:
In TCP mode, if you disconnect a SOCKET using close(), a FIN packet won't be sent to the peer.
Warning:
In TCP mode, You'd better to call close() after disconect() for the safe terminating. Refer to Sn_SSR bug phase.

Definition at line 57 of file socket.c.

References getIINCHIP_TxMAX(), getSn_MR(), getSn_TX_FSR(), sendto(), setSn_CR(), setSn_IR(), Sn_CR_CLOSE, Sn_MR_TCP, Sn_MR_UDP, socket(), and wait_10ms().

Referenced by loopback_tcpc(), loopback_tcps(), loopback_udp(), and Main().

uint8 connect | ( | SOCKET | s,
 |  | uint8 * | addr,
 |  | uint16 | port
 | ) |  |

It tries to connect a client.

It operates a SOCKET as "TCP CLIENT" and sends a connect-request(SYN packet) to "TCP SERVER".
It is valid only in TCP mode.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | addr | IP address of "TCP SERVER"
[in] | port | Listen port number of "TCP SERVER".
Returns:
success - 1
fail - 0

Definition at line 86 of file socket.c.

References IINCHIP_WRITE(), setSn_CR(), Sn_CR_CONNECT, Sn_DIPR, and Sn_DPORTR.

Referenced by loopback_tcpc().

void disconnect ( SOCKET s )

It tries to disconnect a connection SOCKET with a peer.

It sends a disconnect-request(FIN packet) to "TCP SERVER" or "TCP CLIENT".
It is valid only in TCP mode.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.

Definition at line 113 of file socket.c.

References setSn_CR(), and Sn_CR_DISCON.

Referenced by loopback_tcpc(), and loopback_tcps().

uint8 listen ( SOCKET s )

It is listening to a connect-request from a client.

It operates a SOCKET as "TCP SERVER" and waits a connect-request(SYN packet) from a "TCP CLIENT".
It is valid only in TCP mode.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
success - 1
fail - 0

Definition at line 118 of file socket.c.

References getSn_SSR(), setSn_CR(), Sn_CR_LISTEN, and SOCK_INIT.

Referenced by loopback_tcps().

uint32 recv | ( | SOCKET | s,
 |  | uint8 * | buf,
 |  | uint32 | len
 | ) |  |

It receives TCP data on a connection SOCKET.

It is used to read incoming data on a connection SOCKET.
It is valid only in TCP mode.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[out] buf A buffer for the imcoming data
The length of buf should be equal or greater than len + 1, in order to prevent the memory violation.
[in] | len | The byte length of the data in buf
Returns:
It returns the number of bytes received.
Note:
When receiving TCP data from a peer,

  • In case of Sn_MR_ALIGN = '1'
    W5300 adds PACKET-INFO(2bytes lenght) in front of all received DATA(max Sn_MSSR lenght) packet in internal RX memory. The added PACKET-INFO contains the size of DATA packet. If the size of received DATA packet is odd number, 1 byte dummy data is added. The host should read this dummy data first and ignore it.

  • In case of Sn_MR_ALIGN = '0'
    iichip receives only DATA packet without PACKET-INFO. Therefore, All size of the received data should be a even number.

    Below shows the format of received TCP data.

<The format of received TCP data>

Warning:
Warning:
When SOCKETn is used only to receive data without transmitting data, the slow data receiving process by the host can cause internal RX memory full. In this case, even though W5300 window size (the maximum size of receivable data) is not '0', by misunderstanding the window size as '0', the peer does not transmit the data, and waits until window size is increased. It is the cause of decreasing data receiving performance of W5300. In order to solve the problem, the host processes the data received in internal RX memory first and notify the peer that the window size of W5300 is increased by received data size.
After Sn_CR_RECV command, add to the below code.
 if(getSn_RX_RSR(s) == 0)
 {
    setSn_TX_WRSR(s,1);
    IINCHIP_WRITE(Sn_TX_FIFOR(s),0x0000);
    setSn_CR(s,Sn_CR_SEND);
    while(!(getSn_IR(s) & Sn_IR_SENDOK));
    setSn_IR(s,Sn_IR_SENDOK);
 }
There is no need when SOCKETn is used to both receive and transmit data.

Definition at line 217 of file socket.c.

References getSn_IR(), getSn_RX_RSR(), IINCHIP_READ(), IINCHIP_WRITE(), MR, MR_FS, setSn_CR(), setSn_IR(), setSn_TX_WRSR(), Sn_CR_RECV, Sn_CR_SEND, Sn_IR_SENDOK, Sn_MR, Sn_MR_ALIGN, Sn_TX_FIFOR, and wiz_read_buf().

Referenced by loopback_tcpc(), and loopback_tcps().

uint32 recvfrom | ( | SOCKET | s,
 |  | uint8 * | buf,
 |  | uint32 | len,
 |  | uint8 * | addr,
 |  | uint16 * | port
 | ) |  |

It receives UDP, IPRAW, or MACRAW data.

It is used to read incoming data and to store a destination information.
On the IPRAW SOCKET, the port parameter are ignored.
On the MACRAW SOCKET, the addr and port parameters are ignored, making recvfrom() equivalent to recv(). But, The destination and source information is included in front of buf.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[out] buf A buffer for the imcoming data
The length of buf should be equal or greater than len + 1, in order to prevent the memory violation.
[in] | len | The byte length of the data in buf
[out] | addr | An optional pointer to the address of destination.
[out] | port | An optional the port number of destination.
Returns:
It returns the number of bytes received.
Note:
When receiving data from a peer, W5300 adds the different PACKET-INFO in front of all received DATA(max Sn_MSSR lenght) packet in internal RX memory. The added PACKET-INFO contains basically the DATA packet size which length is 2bytes and contains extra information such as destination IP address according to SOCKETn mode.
If the size of received DATA packet is odd number, 1 byte dummy data is added. The host should read this dummy data first and ignore it.

  • In case of UDP mode

    <The format of received UDP data>

    Destination IP address and port number are stored respectively in the parameters addr and port. And DATA packet is stored in the parameter buf.

  • In case of IPRAW mode

    <The format of received IPRAW data>

    Destination IP address is stored in the parameter addr. And DATA packet is stored in the parameter buf.

  • In case of MACRAW mode

    <The format of received MACRAW data>

    Destination and source MAC, and type are stored in the parameter buf. But, CRC is ignored.

Warning:
Warning:
In case that free buffer size of internal RX memory is smaller than the size of receiving MAC RAW data,
some parts of un-acceptable PACKET-INFO and DATA packet of the MACRAW data can be saved in internal RX memory. This can cause the error in analyzing PACKET-INFO, and receiving correct MACRAW data. This problem is more likely to happen when internal RX memory gets close full.
This can be solved by ignoring some loss of MACRAW data.

  • By performing internal RX memory process as quick as possible, prevent the memory to be full

  • By receiving only its own MACRAW data, reduce the receiving burden.
    Set the Sn_MR_MF bit of S0_MR by calling socket() with Sn_MR_MF flag
       socket(0,Sn_MR_MACRAW,0x1000,Sn_MR_MF);

  • In case that the free size of internal RX memory is smaller than 1528 -Default MTU(1514)+ PACKET-INFO(2)+DATA packet(8)+CRC(4)- close SOCKET 0. After closing the SOCKET0, Process all received MACRAW data and the reopen the SOCKET0.
    For example,
       // Assume that you can process the MACRAW data by this function.
   void process_macraw_data(uint8* mac_data, uint32 len);

   // main example
   void main(void)
   {
      int32 remained_rsr = 0;
      int32 rsr = 0;
      int32 recv_len = 0;
      uint8 data_buf[2048];

      while(1)
      {
         switch(getSn_SSR(0))
         {
            case SOCK_MACRAW:
               rsr = getSn_RX_RSR(0);
               if(rsr > 0)
               {
                  // check the received size.
                  if(getIINCHIP_MaxRX(0) - rsr < 1528) // Abnormal
                  {
                     remained_rsr = rsr;
                     close(s);
                     while(remained_rsr > 0)           // Process all received data.
                     {
                        recv_len = recvfrom(0,data_buf,remained_rsr,0,0);
                        remained_rsr -= (recv_len+2+4); // length of DATA packet size - 2bytes, length of CRC - 4 bytes
                        if(remained_rsr < 0)
                        {
                           // Error. It maybe receive an un-acceptable MACRAW data and should be ignored that.
                           break;
                        }
                        process_macraw_data(data_buf,recv_len);
                     }
                  }
                  else                                 // Normal
                  {
                     recv_len = recvfrom(0,data_buf,remained_rsr,0,0);
                     process_macraw_data(data_buf,recv_len);
                  }
               }
               break;
            case SOCK_CLOSED:
               socket(0,Sn_MR_MACRAW,0x1000,Sn_MR_MF); // open or re-open the MACRAW SOCKET with MAC filter flag.
               break;
         } // end switch
      } // end while
   } // end main

Definition at line 342 of file socket.c.

References IINCHIP_READ(), MR, MR_FS, setSn_CR(), Sn_CR_RECV, Sn_MR, Sn_MR_IPRAW, Sn_MR_MACRAW, Sn_MR_UDP, and wiz_read_buf().

Referenced by loopback_udp().

uint32 send | ( | SOCKET | s,
 |  | uint8 * | buf,
 |  | uint32 | len
 | ) |  |

It sends TCP data on a connection SOCKET.

It is used to write outgoing data on a connection SOCKET.
It is valid only in TCP mode.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | buf | A buffer containing the data to be transmitted
[in] | len | The byte length of the data in buf
Returns:
If no error occurs, it returns the total number of bytes sent, which can be less than the number indicated by len when len is greater than the allocated size of internal TX memory.
If error such as timeout and abnormally disconnect occurs, it returns 0.
Remarks:
It is a blocking function which doesn't return until len lenght data is transmitted completely.
Note:
if you want to use non blocking function, "do{...}while(freesize < ret)" code block can be replaced with the below code.
 while((freesize = getSn_TX_FSR(s))==0); It can tranmit data as many as free size
       ret = freesize;

Definition at line 133 of file socket.c.

References check_sendok_flag, getIINCHIP_TxMAX(), getSn_IR(), getSn_SSR(), getSn_TX_FSR(), MR, setSn_CR(), setSn_IR(), setSn_TX_WRSR(), Sn_CR_SEND, Sn_IR_SENDOK, SOCK_CLOSE_WAIT, SOCK_CLOSED, SOCK_ESTABLISHED, and wiz_write_buf().

Referenced by loopback_tcpc(), and loopback_tcps().

uint32 sendto | ( | SOCKET | s,
 |  | uint8 * | buf,
 |  | uint32 | len,
 |  | uint8 * | addr,
 |  | uint16 | port
 | ) |  |

It sends UDP, IPRAW, or MACRAW data.

It is normally used on a connectionless SOCKET to send a datagram to a specific peer identified by the to parameter(addr, port). Even if the connectionless SOCKET has been previously connected to a specific address, the addr and port parameters override the destination address for that particular datagram only.

On the IPRAW SOCKET, the port parameter are ignored.
On the MACRAW SOCKET, the addr and port parameters are ignored, making sendto() equivalent to send(). But, The destination and source information must be included in front of buf.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | buf | A buffer containing the data to be transmitted
[in] | len | The byte length of the data in buf
[in] | addr | An optional pointer to the address of destination.
[in] | port | An optional the port number of destination.
Returns:
If no error occurs, it returns the total number of bytes sent, which can be less than the number indicated by len when len is greater than the allocated size of internal TX memory.
If error such as ARP timeout and abnormally close occurs, it returns 0.
Remarks:
It is a blocking function which doesn't return until Sn_IR_SENDOK becomes '1'. It should wait in order to prevent from overriding the destination information.
Warning:
Warning:
If sendto() is failed by ARP timeout, Sn_TX_FSR is decreased as size of the transmitted data. If ARP timeout occurs continuously, Sn_RX_FSR maybe become 0 and any data can't be transmitted. But, don't worry about that. If sendto() successes only once, Sn_RX_FSR is perfectly recovered.

Definition at line 284 of file socket.c.

References getIINCHIP_TxMAX(), getSn_IR(), getSn_SSR(), IINCHIP_WRITE(), setSn_CR(), setSn_IR(), setSn_TX_WRSR(), Sn_CR_SEND, Sn_DIPR, Sn_DPORTR, Sn_IR_SENDOK, Sn_IR_TIMEOUT, SOCK_CLOSED, and wiz_write_buf().

Referenced by close(), and loopback_udp().

uint8 socket | ( | SOCKET | s,
 |  | uint8 | protocol,
 |  | uint16 | port,
 |  | uint16 | flag
 | ) |  |

Open a SOCKET.

It opens a SOCKET according protocol and bind the SOCKET with port number.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] protocol SOCKET protocol such as TCP, UDP and IP.
Refer to Sn_MR_TCP, Sn_MR_UDP, Sn_MR_IPRAW, Sn_MR_MACRAW and Sn_MR_PPPoE.
[in] | port | port number to be binded
[in] flag SOCKET option such as alignment, no-delayed ack, and etc.
Refer to Sn_MR_ALIGN, Sn_MR_MULTI, Sn_MR_MF and Sn_MR_ND/Sn_MR_IGMPv.
Returns:
Always, It returns 1.

Definition at line 38 of file socket.c.

References check_sendok_flag, getSn_SSR(), IINCHIP_READ(), iinchip_source_port, IINCHIP_WRITE(), setSn_CR(), Sn_CR_OPEN, Sn_MR, and Sn_PORTR.

Referenced by close(), loopback_tcpc(), loopback_tcps(), and loopback_udp().

Generated on Fri Jan 2 12:20:00 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: include/types.h File Reference

include/types.h File Reference

Detailed Description

Type Definition of Variables.

The simple data types supported by the W5300 programs are used to define function return values,
function and message parameters, and structure members.
They define the size and meaning of these elements.

Definition in file types.h.

Go to the source code of this file.

Typedefs

typedef char | int8
typedef volatile char | vint8
typedef unsigned char | uint8
typedef volatile unsigned char | vuint8
typedef short | int16
typedef volatile short | vint16
typedef unsigned short | uint16
typedef volatile unsigned short | vuint16
typedef long | int32
typedef volatile long | vint32
typedef unsigned long | uint32
typedef volatile unsigned long | vuint32
typedef uint8 | SOCKET
The SOCKET data type.

Typedef Documentation

typedef short int16

The 16-bit signed data type.

Definition at line 22 of file types.h.

typedef long int32

The 32-bit signed data type.

Definition at line 30 of file types.h.

typedef char int8

The 8-bit signed data type.

Definition at line 14 of file types.h.

typedef uint8 SOCKET

The SOCKET data type.

The 8-bit unsigned data.
This is used as SOCKET number in W5300. SOCKET number range is from 0 to MAX_SOCK_NUM-1

See also:
MAX_SOCK_NUM

Definition at line 47 of file types.h.

typedef unsigned short uint16

The 16-bit unsigned data type.

Definition at line 26 of file types.h.

typedef unsigned long uint32

The 32-bit unsigned data type.

Definition at line 34 of file types.h.

typedef unsigned char uint8

The 8-bit unsigned data type.

Definition at line 18 of file types.h.

typedef volatile short vint16

The volatile 16-bit signed data type.

Definition at line 24 of file types.h.

typedef volatile long vint32

The volatile 32-bit signed data type.

Definition at line 32 of file types.h.

typedef volatile char vint8

The volatile 8-bit signed data type.

Definition at line 16 of file types.h.

typedef volatile unsigned short vuint16

The volatile 16-bit unsigned data type.

Definition at line 28 of file types.h.

typedef volatile unsigned long vuint32

The volatile 32-bit unsigned data type.

Definition at line 36 of file types.h.

typedef volatile unsigned char vuint8

The volatile 8-bit unsigned data type.

Definition at line 20 of file types.h.

Generated on Fri Jan 2 12:20:00 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: include/w5300.h File Reference

include/w5300.h File Reference

Detailed Description

Definition register of W5300 and basic I/O functions.

This file defines the memory map and values of W5300 register.
Also, it defines the basic I/O function to access register of W5300.

Author:
MidnightCow
Date:
08/08/2008
Version:
1.2.0
Revision History :
Date | Version | Author | Description
24/03/2008 | 1.0.0 | MidnightCow | Release with W5300 launching
01/05/2008 1.0.1 MidnightCow Refer to M_01052008.
Modify a logical error in iinchip_irq().
15/05/2008 1.1.0 MidnightCow Refer to M_15052008.
Delete 'getSn_DPORTR()' because Sn_DPORTR is write-only register.
Replace Sn_DHAR2 with Sn_DIPR2 in getSn_DIPR().
08/08/2008 1.2.0 MidnightCow - Refer to M_08082008.
Add IINCHIP_CRITICAL_SECTION_ENTER() & IINCHIP_CRITICAL_SECTION_EXIT() to wiz_read_buf() and wiz_write_buf().
- Add the description to Sn_PROTOR with IPPROTO_XXX definition.
- Modify the description of Sn_SSR and close().

Definition in file w5300.h.

#include "iinchip_conf.h"
#include "types.h"

Go to the source code of this file.

Defines

#define | MR (__DEF_IINCHIP_MAP_BASE__)
Mode register.
#define | IDM_AR (__DEF_IINCHIP_MAP_BASE__ + 0x02)
Indirect mode address register.
#define | IDM_DR (__DEF_IINCHIP_MAP_BASE__ + 0x04)
Indirect mode data register.
#define | IR (COMMON_REG_BASE + 0x02)
Interrupt register.
#define | IMR (COMMON_REG_BASE + 0x04)
Interrupt mask register.
#define | SHAR (COMMON_REG_BASE + 0x08)
Source hardware address register.
#define | GAR (COMMON_REG_BASE + 0x10)
Gateway IP address register.
#define | SUBR (COMMON_REG_BASE + 0x14)
Subnet mask register.
#define | SIPR (COMMON_REG_BASE + 0x18)
Source IP address register.
#define | RTR (COMMON_REG_BASE + 0x1C)
Retransmittion timeout-period register.
#define | RCR (COMMON_REG_BASE + 0x1E)
Retransmittion retry count reigster.
#define | TMS01R (COMMON_REG_BASE + 0x20)
Transmit memory size of each SOCKET reigster.
#define | TMS23R (TMS01R + 2)
#define | TMS45R (TMS01R + 4)
#define | TMS67R (TMS01R + 6)
#define | RMS01R (COMMON_REG_BASE + 0x28)
Transmit memory size of each SOCKET reigster.
#define | RMS23R (RMS01R + 2)
#define | RMS45R (RMS01R + 4)
#define | RMS67R (RMS01R + 6)
#define | MTYPER (COMMON_REG_BASE + 0x30)
Memory type register.
#define | PATR (COMMON_REG_BASE + 0x32)
Authentication type register.
#define | PTIMER (COMMON_REG_BASE + 0x36)
PPP link control protocol request timer register.
#define | PMAGICR (COMMON_REG_BASE + 0x38)
PPP LCP magic number register.
#define | PSIDR (COMMON_REG_BASE + 0x3C)
PPPoE session ID register.
#define | PDHAR (COMMON_REG_BASE + 0x40)
PPPoE destination hardware address register.
#define | UIPR (COMMON_REG_BASE + 0x48)
Unreachable IP address register.
#define | UPORTR (COMMON_REG_BASE + 0x4C)
Unreachable port number register.
#define | FMTUR (COMMON_REG_BASE + 0x4E)
Fragment MTU register.
#define | Pn_BRDYR(n) (COMMON_REG_BASE + 0x60 + n*4)
PIN 'BRDYn' configure register.
#define | Pn_BDPTHR(n) (COMMON_REG_BASE + 0x60 + n*4 + 2)
PIN 'BRDYn' buffer depth Register.
#define | IDR (COMMON_REG_BASE + 0xFE)
W5300 identification register
#define | Sn_MR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x00)
SOCKETn mode register
#define | Sn_CR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x02)
SOCKETn command register
#define | Sn_IMR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x04)
SOCKETn interrupt mask register
#define | Sn_IR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x06)
SOCKETn interrupt register
#define | Sn_SSR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x08)
SOCKETn status register
#define | Sn_PORTR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x0A)
SOCKETn source port register
#define | Sn_DHAR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x0C)
SOCKETn destination hardware address register
#define | Sn_DPORTR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x12)
SOCKETn destination port register
#define | Sn_DIPR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x14)
SOCKETn destination IP address register
#define | Sn_MSSR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x18)
SOCKETn maximum segment size register
#define | Sn_PROTOR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x1A)
SOCKETn protocol of IP header field register
#define | Sn_KPALVTR(n) Sn_PROTOR(n)
SOCKETn keep alive timer register
#define | Sn_TOSR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x1C)
SOCKETn IP type of service(TOS) register
#define | Sn_TTLR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x1E)
SOCKETn IP time to live(TTL) register
#define | Sn_TX_WRSR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x20)
SOCKETn TX write size register
#define | Sn_TX_FSR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x0024)
SOCKETn TX free size register
#define | Sn_RX_RSR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x0028)
SOCKETn RX received size register
#define | Sn_FRAGR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x002C)
SOCKETn fragment register
#define | Sn_TX_FIFOR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x2E)
SOCKETn TX FIFO register
#define | Sn_RX_FIFOR(n) (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x30)
SOCKET n RX FIFO register
#define | MR_DBW (1 << 15)
Data bus width bit of MR.
#define | MR_MPF (1 << 14)
Mac layer pause frame bit of MR.
#define | MR_WDF(X) ((X & 0x07) << 11)
Write data fetch time bit of MR.
#define | MR_RDH (1 << 10)
Read data hold time bit of MR.
#define | MR_FS (1 << 8)
FIFO swap bit of MR.
#define | MR_RST (1 << 7)
S/W reset bit of MR.
#define | MR_MT (1 << 5)
Memory test bit of MR.
#define | MR_PB (1 << 4)
Ping block bit of MR.
#define | MR_PPPoE (1 << 3)
PPPoE bit of MR.
#define | MR_DBS (1 << 2)
Data bus swap of MR.
#define | MR_IND (1 << 0)
Indirect mode bit of MR.
#define | IR_IPCF (1 << 7)
IP conflict bit of IR.
#define | IR_DPUR (1 << 6)
Destination port unreachable bit of IR.
#define | IR_PPPT (1 << 5)
PPPoE terminate bit of IR.
#define | IR_FMTU (1 << 4)
Fragment MTU bit of IR.
#define | IR_SnINT(n) (0x01 << n)
SOCKETn interrupt occurrence bit of IR.
#define | Pn_PEN (1 << 7)
PIN 'BRDYn' enable bit of Pn_BRDYR.
#define | Pn_MT (1 << 6)
PIN memory type bit of Pn_BRDYR.
#define | Pn_PPL (1 << 5)
PIN Polarity bit of Pn_BRDYR.
#define | Pn_SN(n) ((n & 0x07) << 0)
PIN Polarity bit of Pn_BRDYR.
#define | Sn_MR_ALIGN (1 << 8)
Alignment bit of Sn_MR.
#define | Sn_MR_MULTI (1 << 7)
Multicasting bit of Sn_MR.
#define | Sn_MR_MF (1 << 6)
MAC filter bit of Sn_MR.
#define | Sn_MR_IGMPv (1 << 5)
IGMP version bit of Sn_MR.
#define | Sn_MR_ND (1 << 5)
No delayed ack bit of Sn_MR.
#define | Sn_MR_CLOSE 0x00
Protocol bits of Sn_MR.
#define | Sn_MR_TCP 0x01
Protocol bits of Sn_MR.
#define | Sn_MR_UDP 0x02
Protocol bits of Sn_MR.
#define | Sn_MR_IPRAW 0x03
Protocol bits of Sn_MR.
#define | Sn_MR_MACRAW 0x04
Protocol bits of Sn_MR.
#define | Sn_MR_PPPoE 0x05
Protocol bits of Sn_MR.
#define | Sn_CR_OPEN 0x01
OPEN command value of Sn_CR.
#define | Sn_CR_LISTEN 0x02
LISTEN command value of Sn_CR.
#define | Sn_CR_CONNECT 0x04
CONNECT command value of Sn_CR.
#define | Sn_CR_DISCON 0x08
DISCONNECT command value of Sn_CR.
#define | Sn_CR_CLOSE 0x10
CLOSE command value of Sn_CR.
#define | Sn_CR_SEND 0x20
SEND command value of Sn_CR.
#define | Sn_CR_SEND_MAC 0x21
SEND_MAC command value of Sn_CR.
#define | Sn_CR_SEND_KEEP 0x22
SEND_KEEP command value of Sn_CR.
#define | Sn_CR_RECV 0x40
RECV command value of Sn_CR.
#define | Sn_CR_PCON 0x23
PCON command value of Sn_CR.
#define | Sn_CR_PDISCON 0x24
PDISCON command value of Sn_CR.
#define | Sn_CR_PCR 0x25
PCR command value of Sn_CR.
#define | Sn_CR_PCN 0x26
PCN command value of Sn_CR.
#define | Sn_CR_PCJ 0x27
PCJ command value of Sn_CR.
#define | Sn_IR_PRECV 0x80
PPP receive bit of Sn_IR.
#define | Sn_IR_PFAIL 0x40
PPP fail bit of Sn_IR.
#define | Sn_IR_PNEXT 0x20
PPP next phase bit of Sn_IR.
#define | Sn_IR_SENDOK 0x10
Send OK bit of Sn_IR.
#define | Sn_IR_TIMEOUT 0x08
Timout bit of Sn_IR.
#define | Sn_IR_RECV 0x04
Receive bit of Sn_IR.
#define | Sn_IR_DISCON 0x02
Disconnect bit of Sn_IR.
#define | Sn_IR_CON 0x01
Connect bit of Sn_IR.
#define | SOCK_CLOSED 0x00
It is the status that resource of SOCKETn is released.
#define | SOCK_ARP 0x01
It is the status that ARP-request is transmitted in order to acquire destination hardware address.
#define | SOCK_INIT 0x13
It is the status that SOCKETn is open as TCP mode.
#define | SOCK_LISTEN 0x14
It is the status that SOCKETn operates as "TCP SERVER" and waits for connection-request (SYN packet) from "TCP CLIENT".
#define | SOCK_SYNSENT 0x15
It is the status that connect-request(SYN packet) is transmitted to "TCP SERVER".
#define | SOCK_SYNRECV 0x16
It is the status that connect-request(SYN packet) is received from "TCP CLIENT".
#define | SOCK_ESTABLISHED 0x17
It is the status that TCP connection is established.
#define | SOCK_FIN_WAIT 0x18
It is the status that SOCKETn is closed.
#define | SOCK_CLOSING 0x1A
It is the status that SOCKETn is closed.
#define | SOCK_TIME_WAIT 0x1B
It is the status that SOCKETn is closed.
#define | SOCK_CLOSE_WAIT 0x1C
It is the status that disconnect-request(FIN packet) is received from the peer.
#define | SOCK_LAST_ACK 0x1D
It is the status that SOCKETn is closed.
#define | SOCK_UDP 0x22
It is the status that SOCKETn is open as UDP mode.
#define | SOCK_IPRAW 0x32
It is the status that SOCKETn is open as IPRAW mode.
#define | SOCK_MACRAW 0x42
It is the status that SOCKET0 is open as MACRAW mode.
#define | SOCK_PPPoE 0x5F
It is the status that SOCKET0 is open as PPPoE mode.
#define | IPPROTO_IP 0
#define | IPPROTO_ICMP 1
#define | IPPROTO_IGMP 2
#define | IPPROTO_GGP 3
#define | IPPROTO_TCP 6
#define | IPPROTO_PUP 12
#define | IPPROTO_UDP 17
#define | IPPROTO_IDP 22
#define | IPPROTO_ND 77
#define | IPPROTO_RAW 255

Functions

uint16 | IINCHIP_READ (uint32 addr)
Basic I/O function.
void | IINCHIP_WRITE (uint32 addr, uint16 data)
Basic I/O function.
uint16 | getMR (void)
It gets MR value.
void | setMR (uint16 val)
It sets MR value.
uint16 | getIR (void)
It gets IR value.
void | setIR (uint16 val)
It sets IR value.
uint16 | getIMR (void)
It gets IMR value.
void | setIMR (uint16 mask)
It sets IMR value.
void | getSHAR (uint8 *addr)
It gets the source hardware address.
void | setSHAR (uint8 *addr)
It sets the source hardware address.
void | getGAR (uint8 *addr)
It gets the gateway IP address.
void | setGAR (uint8 *addr)
It sets the gateway IP address.
void | getSUBR (uint8 *addr)
It gets the subnet mask address.
void | setSUBR (uint8 *addr)
It sets the subnet mask address.
void | getSIPR (uint8 *addr)
It gets the source IP address.
void | setSIPR (uint8 *addr)
It sets the source IP address.
uint16 | getRTR (void)
It gets RTR value.
void | setRTR (uint16 timeout)
It sets RTR value.
uint8 | getRCR (void)
It gets RCR value.
void | setRCR (uint8 retry)
It sets RCR value.
uint16 | getPATR (void)
It gets PATR value.
uint8 | getPTIMER (void)
It gets PTIMER value.
void | setPTIMER (uint8 time)
It sets PTIMER value.
uint8 | getPMAGICR (void)
It gets PMAGICR value.
void | setPMAGICR (uint8 magic)
It sets PTIMER value.
uint16 | getPSIDR (void)
It gets PSIDR value.
void | getPDHAR (uint8 *addr)
It gets the PPPoE server hardware address.
void | getUIPR (uint8 *addr)
It gets the unreachable destination IP address of ICMP message.
uint16 | getUPORTR (void)
It gets the unreachable destination port number of ICMP message.
uint16 | getFMTUR (void)
It gets the fragmented MTU value of ICMP message.
uint8 | getPn_BRDYR (uint8 p)
It gets Pn_BRDYR value.
void | setPn_BRDYR (uint8 p, uint8 cfg)
It sets Pn_BRDYR value.
uint16 | getPn_BDPTHR (uint8 p)
It gets the buffer depth of PIN "BRDYn".
void | setPn_BDPTHR (uint8 p, uint16 depth)
It sets the buffer depth of PIN "BRDYn".
uint16 | getIDR (void)
It gets the ID of W5300.
uint16 | getSn_MR (SOCKET s)
It gets Sn_MR value.
void | setSn_MR (SOCKET s, uint16 mode)
It sets Sn_MR value.
uint8 | getSn_CR (SOCKET s)
It gets Sn_CR value.
void | setSn_CR (SOCKET s, uint16 com)
It sets Sn_CR value.
uint8 | getSn_IMR (SOCKET s)
It gets Sn_IMR value.
void | setSn_IMR (SOCKET s, uint8 mask)
It sets Sn_IMR value.
uint8 | getSn_IR (SOCKET s)
It gets Sn_IR value.
void | setSn_IR (SOCKET s, uint8 ir)
It sets Sn_IR value.
uint8 | getSn_SSR (SOCKET s)
It gets Sn_SSR value.
void | getSn_DHAR (SOCKET s, uint8 *addr)
It gets Sn_DHAR value.
void | setSn_DHAR (SOCKET s, uint8 *addr)
It sets Sn_DHAR value.
void | setSn_DPORTR (SOCKET s, uint16 port)
It sets Sn_DPORTR value.
void | getSn_DIPR (SOCKET s, uint8 *addr)
It gets Sn_DIPR value.
void | setSn_DIPR (SOCKET s, uint8 *addr)
It sets Sn_DIPR value.
uint16 | getSn_MSSR (SOCKET s)
It gets Sn_MSSR value.
void | setSn_MSSR (SOCKET s, uint16 mss)
It sets Sn_MSSR value.
uint8 | getSn_KPALVTR (SOCKET s)
It gets Sn_KPALVTR value.
void | setSn_KPALVTR (SOCKET s, uint8 time)
It sets Sn_KPALVTR value.
uint32 | getSn_TX_WRSR (SOCKET s)
It gets Sn_TX_WRSR value.
void | setSn_TX_WRSR (SOCKET s, uint32 size)
It gets Sn_KPALVTR value.
uint32 | getSn_TX_FSR (SOCKET s)
It gets Sn_TX_FSR value.
uint32 | getSn_RX_RSR (SOCKET s)
It gets Sn_RX_RSR value.
void | setSn_TX_FIFOR (SOCKET s, uint16 data)
It sets Sn_TX_FIFOR value.
uint16 | getSn_RX_FIFOR (SOCKET s)
It gets Sn_RX_FIFOR value.
uint8 | getSn_PROTOR (SOCKET s)
It gets Sn_PROTOR value.
void | setSn_PROTOR (SOCKET s, uint8 pronum)
It sets Sn_PROTOR value.
uint8 | getSn_TOSR (SOCKET s)
It gets Sn_TOSR value.
void | setSn_TOSR (SOCKET s, uint8 tos)
It sets Sn_TOSR value.
uint8 | getSn_TTLR (SOCKET s)
It gets Sn_TTLR value.
void | setSn_TTLR (SOCKET s, uint8 ttl)
It sets Sn_TTLR value.
uint8 | getSn_FRAGR (SOCKET s)
It gets Sn_FRAGR value.
void | setSn_FRAGR (SOCKET s, uint8 frag)
It sets Sn_FRAGR value.
void | iinchip_init (void)
It initializes W5300.
void | iinchip_irq (void)
It handles the interrupt of W5300.
uint8 | sysinit (uint8 *tx_size, uint8 *rx_size)
It allocate internal TX/RX memory of each SOCKET.
uint32 | wiz_write_buf (SOCKET s, uint8 *buf, uint32 len)
It copies data to interna1 TX memory.
uint32 | wiz_read_buf (SOCKET s, uint8 *buf, uint32 len)
It copies data to your buffer from internal RX memory.
uint32 | getIINCHIP_TxMAX (SOCKET s)
It gets the max size of internal TX memory of each SOCKET.
uint32 | getIINCHIP_RxMAX (SOCKET s)
It gets the max size of internal RX memory of each SOCKET.
uint8 | pppinit (uint8 *id, uint8 idlen, uint8 *passwd, uint8 passwdlen)
It initializes to PPPoE of W5300.
void | pppterm (uint8 *mac, uint16 sessionid)
It terminates PPPoE connection.
void | wait_1us (uint32 us)
Delay function Refer to wait_10ms().
void | wait_1ms (uint32 ms)
Delay function Refer to wait_10ms().
void | wait_10ms (uint32 ms)
Delay function.

Define Documentation

#define IPPROTO_GGP 3

Gateway-to-Gateway (deprecated)

Definition at line 1756 of file w5300.h.

#define IPPROTO_ICMP 1

Control message protocol

Definition at line 1754 of file w5300.h.

#define IPPROTO_IDP 22

XNS idp

Definition at line 1760 of file w5300.h.

#define IPPROTO_IGMP 2

Internet group management protocol

Definition at line 1755 of file w5300.h.

#define IPPROTO_IP 0

Dummy for IP

Definition at line 1753 of file w5300.h.

#define IPPROTO_ND 77

UNOFFICIAL net disk protocol

Definition at line 1761 of file w5300.h.

#define IPPROTO_PUP 12

PUP

Definition at line 1758 of file w5300.h.

#define IPPROTO_RAW 255

Raw IP packet

Definition at line 1762 of file w5300.h.

#define IPPROTO_TCP 6

TCP

Definition at line 1757 of file w5300.h.

#define IPPROTO_UDP 17

UDP

Definition at line 1759 of file w5300.h.

#define IR_DPUR (1 << 6)

Destination port unreachable bit of IR.

It's set as '1' when receiving ICMP(destination port unreachable) packet.

See also:
UIPR, UPORTR

Definition at line 1134 of file w5300.h.

Referenced by iinchip_irq().

#define IR_FMTU (1 << 4)

Fragment MTU bit of IR.

When receiving ICMP (Fragment MTU) packet, it's set as '1'.

See also:
FMTUR

Definition at line 1147 of file w5300.h.

#define IR_IPCF (1 << 7)

IP conflict bit of IR.

It's set as '1' when receiving ARP-request packet having same IP address as SIPR of W5300.

Definition at line 1127 of file w5300.h.

Referenced by iinchip_irq().

#define IR_PPPT (1 << 5)

PPPoE terminate bit of IR.

When the connection with server is closed at the PPPoE mode, it is set as '1'.

Definition at line 1140 of file w5300.h.

#define IR_SnINT ( n ) (0x01 << n)

SOCKETn interrupt occurrence bit of IR.

When an interrupt occurs at the SOCKETn, it becomes '1'. This interrupt information is applied to Sn_IR's LSB.
This Bit is automatically cleared when Sn_IR's LSB is cleared to 0x00 by Host.

See also:
Sn_IR

Definition at line 1155 of file w5300.h.

Referenced by iinchip_irq().

#define MR_DBS (1 << 2)

Data bus swap of MR.

0 : Diable swap
1 : Enable swap

This bit swaps MSB and LSB of all registers including Sn_TX_FIFOR/ Sn_RX_FIFOR.

Note:
This bit can be applied when MR_DBW is '1' .

Definition at line 1106 of file w5300.h.

#define MR_DBW (1 << 15)

Data bus width bit of MR.

0 : 8 bit
1 : 16 bit

Read only. When reset of W5300, it is fixed according to logic level of PIN 'BIT16EN'.

Definition at line 1024 of file w5300.h.

#define MR_FS (1 << 8)

FIFO swap bit of MR.

0 : Diable swap
1 : Enable swap

It swaps the most significant byte (MSB) and least significant byte (LSB) of Sn_TX_FIFOR & Sn_RX_FIFOR.
Basically, the byte ordering of W5300 is big-endian.

Definition at line 1061 of file w5300.h.

Referenced by pppinit(), recv(), and recvfrom().

#define MR_IND (1 << 0)

Indirect mode bit of MR.

0 : Direct Address Mode
1 : Indirect Address Mode

It sets host interface mode of W5300.

See also:
__DEF_IINCHIP_ADDRESS_MODE__

Definition at line 1116 of file w5300.h.

Referenced by iinchip_init().

#define MR_MPF (1 << 14)

Mac layer pause frame bit of MR.

Read only. It is set as '1', when pause frame is received from router or switch.
When set as '1', all data is paused until changing to '0'.

Definition at line 1032 of file w5300.h.

#define MR_MT (1 << 5)

Memory test bit of MR.

0 : Disable Internal TX/RX Memory Test
1 : Enable Internal TX/RX Memory Test

For the detail, refer to "How to test internal TX/RX memory.pdf".

Definition at line 1078 of file w5300.h.

#define MR_PB (1 << 4)

Ping block bit of MR.

0 : Disable ping block
1 : Enable ping block

Definition at line 1086 of file w5300.h.

#define MR_PPPoE (1 << 3)

PPPoE bit of MR.

0 : Disable PPPoE mode
1 : Enable PPPoE mode

This bit should be set as '1', when connecting to ADSL server with router or others.
For the detail, refer to "How to use PPPoE in W5300.pdf"

Definition at line 1096 of file w5300.h.

Referenced by pppinit(), and pppterm().

#define MR_RDH (1 << 10)

Read data hold time bit of MR.

0 : No use
1 : Use

When the Host reads, W5300 holds the Read Data during '2' X 'PLL_CLK' after the read operation is finished ('/CS' is de-asserted as High).

Definition at line 1050 of file w5300.h.

#define MR_RST (1 << 7)

S/W reset bit of MR.

If it's set as '1', W5300 is reset. This Bit is automatically cleared after reset.

Definition at line 1069 of file w5300.h.

Referenced by iinchip_init().

#define MR_WDF ( X ) ((X & 0x07) << 11)

Write data fetch time bit of MR.

When the host writes, since '/CS' is asserted low, W5300 fetches Write Data after 'X' X 'PLL_CLK'.

Definition at line 1040 of file w5300.h.

#define Pn_MT (1 << 6)

PIN memory type bit of Pn_BRDYR.

'0' - RX memory
'1' - TX memory

It sets the type of socket memory to monitor.

Definition at line 1177 of file w5300.h.

#define Pn_PEN (1 << 7)

PIN 'BRDYn' enable bit of Pn_BRDYR.

'0' - Disable PIN 'BRDYn'
'1' - Enable PIN 'BRDYn'

When using PIN "BRDYn", set it as "1".

Definition at line 1168 of file w5300.h.

#define Pn_PPL (1 << 5)

PIN Polarity bit of Pn_BRDYR.

'0' - Low sensitive
'1' - High sensitive

When Free/Received buffer size of the specified SOCKET's TX/RX memory is same or bigger than Pn_DPTHR, set the logic level of PIN 'BRDYn' to be signaled to the Host.

See also:
Pn_BDPTHR

Definition at line 1187 of file w5300.h.

#define Pn_SN ( n ) ((n & 0x07) << 0)

PIN Polarity bit of Pn_BRDYR.

Set the SOCKET number to monitor through PIN 'BRDYn'.
0 <= n <= MAX_SOCK_NUM.

Definition at line 1195 of file w5300.h.

#define RMS23R (RMS01R + 2)

Refer to RMS01R.

Definition at line 322 of file w5300.h.

Referenced by sysinit().

#define RMS45R (RMS01R + 4)

Refer to RMS01R.

Definition at line 323 of file w5300.h.

Referenced by sysinit().

#define RMS67R (RMS01R + 6)

Refer to RMS01R.

Definition at line 324 of file w5300.h.

Referenced by sysinit().

#define Sn_CR_CLOSE 0x10

CLOSE command value of Sn_CR.

It closes SOCKETn regardless of Sn_SSR 's value. Sn_SSR is changed to SOCK_CLOSED.

Definition at line 1392 of file w5300.h.

Referenced by close(), pppinit(), and pppterm().

#define Sn_CR_CONNECT 0x04

CONNECT command value of Sn_CR.

It is valid only when Sn_MR(P3:P0) = Sn_MR_TCP and operates SOCKETn as 'TCP-CLIENT'.
It transmits connect-request(SYN packet) to the TCP server designated with Sn_DIPR and Sn_DPORTR.
When connect-request is successfully processed (when receiving SYN/ACK packet), Sn_IR(Sn_IR_CON) becomes '1', and Sn_SSR is changed to SOCK_ESTABLISHED.
There are 3 cases if connect-request is failed.

  • when ARP timeout occurs (Sn_IR(Sn_IR_TIMEOUT)='1') because destination hardware address is not acquired through ARP process
  • when SYN/ACK packet is not received and TCP timout occurrs (Sn_IR(Sn_IR_TIMEOUT)='1').
  • When RST packet is received instead of SYN/ACK packet.

    In above 3 cases, Sn_SSR is changed to SOCK_CLOSED.

Definition at line 1351 of file w5300.h.

Referenced by connect().

#define Sn_CR_DISCON 0x08

DISCONNECT command value of Sn_CR.

It is valid only when Sn_MR(P3:P0) = Sn_MR_TCP and operates SOCKETn as both 'TCP-SERVER' and 'TCP-CLIENT'.
It performs Disconnect-process.

  • Active close : It transmits disconnect-request(FIN packet) to the connected peer.
  • Passive close : When receiving disconnect-request (FIN packet) from the peer, it transmits FIN packet.

    If Disconnect-request is successful (when receiving FIN/ACK packet), Sn_SSR is changed to SOCK_CLOSED. If Disconnect-request is failed, TCP timeout occurs(Sn_IR(Sn_IR_TIMEOUT)='1') and Sn_SSR is changed to SOCK_CLOSED.

Note:
If Sn_CR_CLOSE is used instead of Sn_CR_DISCON, only Sn_SSR is changed to SOCK_CLOSED without disconnect-process (disconnect-request).
If RST packet is received from the peer during communication, Sn_SSR is unconditionally changed to SOCK_CLOSED.

Definition at line 1371 of file w5300.h.

Referenced by disconnect().

#define Sn_CR_LISTEN 0x02

LISTEN command value of Sn_CR.

It is valid only when Sn_MR(P3:P0) = Sn_MR_TCP and operates SOCKETn as 'TCP-SERVER'.
It changes Sn_SSR to SOCK_LISTEN at the SOCK_INIT in order to wait for connect-request (SYN packet) from any 'TCP Clinet'.

When Sn_SSR is SOCK_LISTEN and connect-request from a TCP Client is successfully processed, Sn_IR(Sn_IR_CON) becomes '1' and Sn_SSR is changed to SOCK_ESTABLISHED.
In case that the connect-request is not processed (SYN/ACK transmission is failed), TCP timeout occurs (Sn_IR(Sn_IR_TIMEOUT)='1') and Sn_SSR is changed to SOCK_CLOSED.

Note:
If TCP connect-request port number of TCP Client does not exist, W5300 transmits RST packet and Sn_SSR is not changed.

Definition at line 1332 of file w5300.h.

Referenced by listen().

#define Sn_CR_OPEN 0x01

OPEN command value of Sn_CR.

It initializes SOCKETn and opens according to protocol type set in Sn_MR(P3:P0).
Below is the value change of Sn_SSR according to Sn_MR(P3:P0).

  • Sn_MR_CLOSE : Not available
  • Sn_MR_TCP : SOCK_INIT
  • Sn_MR_UDP : SOCK_UDP
  • Sn_MR_IPRAW : SOCK_IPRAW
  • Sn_MR_MAC : SOCK_MACRAW
  • Sn_MR_PPPoE : SOCK_PPPoE

Definition at line 1318 of file w5300.h.

Referenced by pppinit(), pppterm(), and socket().

#define Sn_CR_PCJ 0x27

PCJ command value of Sn_CR.

It is valid only in Sn_MR(P3:P0) = Sn_MR_PPPoE.
In each phase, it transmits REJECT message. Refer to "How to use PPPoE in W5300.pdf"

Definition at line 1504 of file w5300.h.

Referenced by pppinit_in().

#define Sn_CR_PCN 0x26

PCN command value of Sn_CR.

It is valid only in Sn_MR(P3:P0) = Sn_MR_PPPoE.
In each phase, it transmits NAK message. Refer to "How to use PPPoE in W5300.pdf"

Definition at line 1495 of file w5300.h.

#define Sn_CR_PCON 0x23

PCON command value of Sn_CR.

It is valid only in Sn_MR(P3:P0) = Sn_MR_PPPoE.
PPPoE connection begins by transmitting PPPoE discovery packet.
Refer to "How to use PPPoE in W5300.pdf"

Definition at line 1468 of file w5300.h.

Referenced by pppinit_in().

#define Sn_CR_PCR 0x25

PCR command value of Sn_CR.

It is valid only in Sn_MR(P3:P0) = Sn_MR_PPPoE.
In each phase, it transmits REQ message. Refer to "How to use PPPoE in W5300.pdf"

Definition at line 1486 of file w5300.h.

Referenced by pppinit_in().

#define Sn_CR_PDISCON 0x24

PDISCON command value of Sn_CR.

It is valid only in Sn_MR(P3:P0) = Sn_MR_PPPoE.
Closes PPPoE connection. Refer to "How to use PPPoE in W5300.pdf"

Definition at line 1477 of file w5300.h.

Referenced by pppterm().

#define Sn_CR_RECV 0x40

RECV command value of Sn_CR.

It notifies that the host received the data packet of SOCKETn.

Note:
Before RECV command, the host should copy receiving data packet from internal RX memory into the host memory through Sn_RX_FIFOR.

Definition at line 1458 of file w5300.h.

Referenced by pppinit_in(), recv(), and recvfrom().

#define Sn_CR_SEND 0x20

SEND command value of Sn_CR.

It transmits data (DATA packets) as big as the size of Sn_TX_WRSR. In case that Sn_MR(P3:P0) is Sn_MR_TCP or Sn_MR_UDP, if Sn_TX_WRSR of data is bigger than maximum segment size(MSS), W5300 automatically divides data in MSS unit, and transmits the divided data.
In case that Sn_MR(P3:P0) is Sn_MR_IPRAW or Sn_MR_MACRAW, this function is not supported. Host should divide data in MSS unit and transmit the divided data to a peer.

When completing the Sn_CR_SEND process, Sn_IR(Sn_IR_SENDOK) becomes '1'. After checking Sn_IR(Sn_IR_SENDOK) = '1', Host can perform Sn_CR_SEND for the next data transmittion.

If data is successfully transmitted to the peer by Sn_CR_SEND (when DATA/ACK packet is received from the peer), Sn_TX_FSR is increased by the size of transmitted data. If not (when DATA/ACK packet is not received), TCP timeout occurs (Sn_IR(Sn_IR_TIMEOUT)='1') and Sn_SSR is changed to SOCK_CLOSED.

Note:
Host copies TX data into internal TX memory of SOCKETn through Sn_TX_FIFOR before performing Sn_CR_SEND, and configures data size in Sn_TX_WRSR.

Definition at line 1400 of file w5300.h.

Referenced by recv(), send(), and sendto().

#define Sn_CR_SEND_KEEP 0x22

SEND_KEEP command value of Sn_CR.

It is valid only when Sn_MR(P3:P0) = Sn_MR_TCP.
In order to check TCP connection status with the peer, KEEP ALIVE(KA) packet can be transmitted. Sn_CR_SEND_KEEP is available only in case of Sn_KPALVTR = 0, but ignored in case of Sn_KPALVTR > 0.
In case of Sn_KPALVTR > 0, KA packet is automatically transmitted if there is no data communication during the time of Sn_KPALVTR.

If KA packet is successfully transmitted (when KA/ACK packet is received from the peer), Sn_SSR maintains SOCK_ESTABLISHED status. If it is failed to transmit the KA packet (when the peer already closed the connection, or KA/ACK is not transmitted), TCP timeout will occurs(Sn_IR(Sn_IR_TIMEOUT)='1') and Sn_SSR is changed to SOCK_CLOSED.

Note:
KA packet can be transmitted after one or more data communication is processed.

Definition at line 1438 of file w5300.h.

#define Sn_CR_SEND_MAC 0x21

SEND_MAC command value of Sn_CR.

It is valid only in Sn_MR(P3:P0) = Sn_MR_UDP or Sn_MR_IPRAW
The basic operation is same as Sn_CR_SEND.
Sn_CR_SEND needs ARP process that acquires destination hardware address, but Sn_CR_SEND_MAC is no need ARP process and just use the user-specified destination hardware address in Sn_DHAR. Sn_CR_SEND_MAC can reduce network traffic by removing ARP process when sending UDP/IP data to the destination.

Definition at line 1425 of file w5300.h.

#define Sn_IR_CON 0x01

Connect bit of Sn_IR.

Setting for the case that the connection with the peer is successfully established.

Definition at line 1569 of file w5300.h.

Referenced by loopback_tcpc(), and loopback_tcps().

#define Sn_IR_DISCON 0x02

Disconnect bit of Sn_IR.

Setting for the case that FIN or FIN/ACK packet is received from the peer

Definition at line 1562 of file w5300.h.

#define Sn_IR_PFAIL 0x40

PPP fail bit of Sn_IR.

It is valid only in Sn_MR(P3:P0) = Sn_MR_PPPoE.
Setting for the case that PAP authentication is failed.

Definition at line 1525 of file w5300.h.

Referenced by pppinit_in().

#define Sn_IR_PNEXT 0x20

PPP next phase bit of Sn_IR.

It is valid only in Sn_MR(P3:P0) = Sn_MR_PPPoE.
Setting for the case that the phase is changed during PPPoE connection process.

Definition at line 1533 of file w5300.h.

Referenced by pppinit_in().

#define Sn_IR_PRECV 0x80

PPP receive bit of Sn_IR.

It is valid only in Sn_MR(P3:P0) = Sn_MR_PPPoE.
Setting for the case that option data which is not supported is received.

Definition at line 1517 of file w5300.h.

Referenced by pppinit_in().

#define Sn_IR_RECV 0x04

Receive bit of Sn_IR.

Setting for the case whenever data packet is received from the peer.

Definition at line 1555 of file w5300.h.

#define Sn_IR_SENDOK 0x10

Send OK bit of Sn_IR.

Setting for the case that the Sn_CR_SEND command is completed

Definition at line 1541 of file w5300.h.

Referenced by recv(), send(), and sendto().

#define Sn_IR_TIMEOUT 0x08

Timout bit of Sn_IR.

Setting for the case that ARP timeout or TCP timeout occurs(Sn_IR(Sn_IR_TIMEOUT) = '1')).

Definition at line 1548 of file w5300.h.

Referenced by sendto().

#define Sn_MR_ALIGN (1 << 8)

Alignment bit of Sn_MR.

'0' - No use alignment
'1' - Use alignment

It is only valid on Sn_MR_TCP.
When received data size is of even number and set as '1', data receiving performance can be improved by removing PACKET-INFO(Data Size) that is attached to every receipt data.

Definition at line 1211 of file w5300.h.

Referenced by recv().

#define Sn_MR_CLOSE 0x00

Protocol bits of Sn_MR.

No used.
It configures communication protocol (TCP, UDP, IP RAW, MAC RAW) in each socket
or PPPoE socket to operate with PPPoE server.

  • Sn_MR_CLOSE : No used
  • Sn_MR_TCP : TCP
  • Sn_MR_UDP : UDP
  • Sn_MR_IPRAW : IP RAW
  • Sn_MR_MACRAW : MAC RAW
  • Sn_MR_PPPoE : PPPoE

Definition at line 1273 of file w5300.h.

#define Sn_MR_IGMPv (1 << 5)

IGMP version bit of Sn_MR.

'0' - Using IGMP version 2 (IGMPv2)
'1' - Enable IGMP version 1 (IGMPv1)

It is only valid on Sn_MR_UDP and Sn_MR_MULTI.
It configures IGMP version to send IGMP message such as Join/Leave/Report to multicast-group.

Definition at line 1244 of file w5300.h.

#define Sn_MR_IPRAW 0x03

Protocol bits of Sn_MR.

IP raw.
Refer to Sn_MR_CLOSE.

Definition at line 1294 of file w5300.h.

Referenced by recvfrom().

#define Sn_MR_MACRAW 0x04

Protocol bits of Sn_MR.

MAC raw.
Refer to Sn_MR_CLOSE.

Note:
This mode can be used only in SOCKET0.

Definition at line 1302 of file w5300.h.

Referenced by recvfrom().

#define Sn_MR_MF (1 << 6)

MAC filter bit of Sn_MR.

'0' - Disable MAC filter
'1' - Enable MAC filter

It is only valid on Sn_MR_MACRAW.
When this bit is set as '1', W5300 can receive packet that is belong in itself or broadcasting.
When this bit is set as '0', W5300 can receive all packets on ethernet.

Definition at line 1233 of file w5300.h.

#define Sn_MR_MULTI (1 << 7)

Multicasting bit of Sn_MR.

'0' - Disable multicasting
'1' - Enable multicasting

It is only valid on Sn_MR_UDP.
In order to use multicasting, set its bit, the IP address and port number in Sn_DIPR and Sn_DPORTR respectively before 'Sn_CR = Sn_CR_OPEN'.

Definition at line 1222 of file w5300.h.

#define Sn_MR_ND (1 << 5)

No delayed ack bit of Sn_MR.

'0' - Disable no delayed ack
'1' - Enable no delayed ack

It is only valid on Sn_MR_TCP.
In case that this Bit is set as '1', ACK packet is transmitted right after receiving data packet from the peer.
This Bit is recommended to be set as '1' for TCP performance improvement. In case that this Bit is set as '0', ACK packet is transmitted after the time set in RTR regardless of Data packet receipt.

Definition at line 1258 of file w5300.h.

#define Sn_MR_PPPoE 0x05

Protocol bits of Sn_MR.

PPPoE.
Refer to Sn_MR_CLOSE.

Note:
This mode can be used only in SOCKET0.
S0_MR_PPPoE is temporarily used for PPPoE server connection/termination. After PPPoE session is established, it can be used as another protocol.

Definition at line 1312 of file w5300.h.

Referenced by pppinit(), and pppterm().

#define Sn_MR_TCP 0x01

Protocol bits of Sn_MR.

TCP.
Refer to Sn_MR_CLOSE.

Definition at line 1280 of file w5300.h.

Referenced by close(), loopback_tcpc(), and loopback_tcps().

#define Sn_MR_UDP 0x02

Protocol bits of Sn_MR.

UDP.
Refer to Sn_MR_CLOSE.

Definition at line 1287 of file w5300.h.

Referenced by close(), loopback_udp(), and recvfrom().

#define SOCK_ARP 0x01

It is the status that ARP-request is transmitted in order to acquire destination hardware address.

This status is observed when Sn_CR_SEND is performed at the SOCK_UDP or SOCK_IPRAW, or Sn_CR_CONNECT is performed at the SOCK_INIT.
If hardware address is successfully acquired from destination (when ARP-response is received), it is changed to SOCK_UDP, SOCK_IPRAW or SOCK_SYNSENT.
If it's failed and ARP timeout(Sn_IR(Sn_IR_TIMEOUT)='1') occurs, in case of UDP or IPRAW mode it goes back to the previous status(SOCK_UDP or SOCK_IPRAW), in case of TCP mode it goes to the SOCK_CLOSED.

See also:
Sn_SSR
Note:
ARP-process operates at the SOCK_UDP or SOCK_IPRAW if the current Sn_DIPR is different from the previous Sn_DIPR. If previous and current values of Sn_DIPR are same, ARP-process doesn't operate becase the destination hardware address is already acquired.

Definition at line 1589 of file w5300.h.

#define SOCK_CLOSE_WAIT 0x1C

It is the status that disconnect-request(FIN packet) is received from the peer.

As TCP connection is half-closed, it is possible to transfer data packet. In order to complete the TCP disconnection, Sn_CR_DISCON should be performed.
For SOCKETn close without disconnection-process, Sn_CR_CLOSE can be just performed.

See also:
Sn_SSR

Definition at line 1692 of file w5300.h.

Referenced by loopback_tcpc(), loopback_tcps(), and send().

#define SOCK_CLOSED 0x00

It is the status that resource of SOCKETn is released.

When Sn_CR_DISCON or Sn_CR_CLOSE is performed, or ARP/TCP timout occurs, it is changed to SOCK_CLOSED regardless of the previous Sn_SSR value.

See also:
Sn_SSR

Definition at line 1579 of file w5300.h.

Referenced by loopback_tcpc(), loopback_tcps(), loopback_udp(), send(), and sendto().

#define SOCK_CLOSING 0x1A

It is the status that SOCKETn is closed.

Refer to SOCK_FIN_WAIT.

Definition at line 1678 of file w5300.h.

#define SOCK_ESTABLISHED 0x17

It is the status that TCP connection is established.

It is changed to SOCK_ESTABLISHED when SYN packet from "TCP CLIENT" is successfully processed at the SOCK_LISTEN, or Sn_CR_CONNECT is successfully performed. At this status, DATA packet can be transferred, that is, Sn_CR_SEND or Sn_CR_RECV command can be performed.

See also:
Sn_SSR

Definition at line 1655 of file w5300.h.

Referenced by loopback_tcpc(), loopback_tcps(), and send().

#define SOCK_FIN_WAIT 0x18

It is the status that SOCKETn is closed.

It is observed in the disconnect-process of active close or passive close.
It is changed to SOCK_CLOSED when disconnect-process is successfully finished or TCP timeout occurs(Sn_IR(Sn_IR_TIMEOUT)='1').

See also:
Sn_SSR

Definition at line 1666 of file w5300.h.

#define SOCK_INIT 0x13

It is the status that SOCKETn is open as TCP mode.

It is changed to SOCK_INIT when Sn_MR(P3:P0) is Sn_MR_TCP and Sn_CR_OPEN is performed. It is the initial step of TCP connection establishment.
It is possible to perform Sn_CR_LISTEN at the "TCP SERVER" mode and Sn_CR_CONNECT command at the "TCP CLIENT".

See also:
Sn_SSR

Definition at line 1607 of file w5300.h.

Referenced by listen(), loopback_tcpc(), and loopback_tcps().

#define SOCK_IPRAW 0x32

It is the status that SOCKETn is open as IPRAW mode.

It is changed to SOCK_IPRAW when Sn_MR(P3:P0) is Sn_MR_IPRAW and Sn_CR_OPEN is performed.IP packet can be transferred without connection such like SOCK_UDP.

See also:
Sn_SSR

Definition at line 1720 of file w5300.h.

#define SOCK_LAST_ACK 0x1D

It is the status that SOCKETn is closed.

Refer to SOCK_FIN_WAIT.

Definition at line 1703 of file w5300.h.

#define SOCK_LISTEN 0x14

It is the status that SOCKETn operates as "TCP SERVER" and waits for connection-request (SYN packet) from "TCP CLIENT".

When Sn_CR_LISTEN is performed, it is changed to SOCK_LISTEN. When connect-request(SYN packet) from "TCP CLIENT" is successfully processed, SOCK_LISTEN is changed to SOCK_ESTABLISHED.
If it is failed, TCP timout occurs(Sn_IR(Sn_IR_TIMEOUT)='1') and changed to SOCK_CLOSED.

See also:
Sn_SSR

Definition at line 1618 of file w5300.h.

#define SOCK_MACRAW 0x42

It is the status that SOCKET0 is open as MACRAW mode.

It is changed to SOCK_MACRAW in case of S0_MR(P3:P0) = S0_MR_MACRAW and Sn_CR_OPEN is performed.
MAC packet(Ethernet frame) can be transferred such like SOCK_UDP.

See also:
Sn_SSR

Definition at line 1730 of file w5300.h.

#define SOCK_PPPoE 0x5F

It is the status that SOCKET0 is open as PPPoE mode.

It is changed to SOCK_PPPoE in case of S0_MR(P3:P0) = S0_MR_PPPoE and Sn_CR_OPEN is performed.
It is temporarily used at the PPPoE connection. For the detail, refer to "How to use PPPoE in W5300".

See also:
Sn_SSR

Definition at line 1740 of file w5300.h.

Referenced by pppterm().

#define SOCK_SYNRECV 0x16

It is the status that connect-request(SYN packet) is received from "TCP CLIENT".

It is automatically changed to SOCK_ESTABLISHED when W5300 successfully transmits connect-accept(SYN/ACK packet) to the "TCP CLIENT".
If it is failed, TCP timeout occurs(Sn_IR(Sn_IR_TIMEOUT)='1'), and it is changed to SOCK_CLOSED.

See also:
Sn_SSR

Definition at line 1644 of file w5300.h.

#define SOCK_SYNSENT 0x15

It is the status that connect-request(SYN packet) is transmitted to "TCP SERVER".

This status shows changing process from SOCK_INIT to SOCK_ESTABLISHED by Sn_CR_CONNECT.
At this status, if connect-accept(SYN/ACK packet) is received from "TCP SERVER", it is automatically changed to SOCK_ESTABLISHED. If SYN/ACK packet is not received from the "TCP SERVER" before TCP Timeout occurs (Sn_IR(Sn_IR_TIMEOUT)='1'), it is changed to SOCK_CLOSED.

See also:
Sn_SSR

Definition at line 1631 of file w5300.h.

#define SOCK_TIME_WAIT 0x1B

It is the status that SOCKETn is closed.

Refer to SOCK_FIN_WAIT.

Definition at line 1685 of file w5300.h.

#define SOCK_UDP 0x22

It is the status that SOCKETn is open as UDP mode.

It is changed to SOCK_UDP when Sn_MR(P3:P0) is Sn_MR_UDP and Sn_CR_OPEN is performed. DATA packet can be transferred without connection that is necessary to TCP mode SOCKET.

See also:
Sn_SSR

Definition at line 1710 of file w5300.h.

Referenced by loopback_udp().

#define TMS23R (TMS01R + 2)

Refer to TMS01R.

Definition at line 296 of file w5300.h.

Referenced by sysinit().

#define TMS45R (TMS01R + 4)

Refer to TMS01R.

Definition at line 297 of file w5300.h.

Referenced by sysinit().

#define TMS67R (TMS01R + 6)

Refer to TMS01R.

Definition at line 298 of file w5300.h.

Referenced by sysinit().

Function Documentation

uint16 getFMTUR ( void )

It gets the fragmented MTU value of ICMP message.

Returns:
The fragmented MTU value
See also:
IR_FMTU, Sn_MSSR, setSn_MSSR()

Definition at line 245 of file w5300.c.

References FMTUR, and IINCHIP_READ().

void getGAR ( uint8 * addr )

It gets the gateway IP address.

Parameters:
[out] addr Storage location for input the gateway IP address. It should be allocated 4bytes size.
See also:
setGAR()

Definition at line 130 of file w5300.c.

References GAR, and IINCHIP_READ().

Referenced by Main().

void uint16 getIDR ( void )

It gets the ID of W5300.

Returns:
0x5300

Definition at line 274 of file w5300.c.

References IDR, and IINCHIP_READ().

uint32 getIINCHIP_RxMAX ( SOCKET s )

It gets the max size of internal RX memory of each SOCKET.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
It returns RXMEM_SIZE value of s-th SOCKET

Definition at line 788 of file w5300.c.

References RXMEM_SIZE.

uint32 getIINCHIP_TxMAX ( SOCKET s )

It gets the max size of internal TX memory of each SOCKET.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
It returns TXMEM_SIZE value of s-th SOCKET

Definition at line 783 of file w5300.c.

References TXMEM_SIZE.

Referenced by close(), send(), and sendto().

uint16 getIMR ( void )

It gets IMR value.

Returns:
The IMR value
See also:
setIMR()

Definition at line 102 of file w5300.c.

References IINCHIP_READ(), and IMR.

uint16 getIR ( void )

It gets IR value.

Returns:
The IR value
See also:
setIR()

Definition at line 93 of file w5300.c.

References IINCHIP_READ(), and IR.

uint16 getMR ( void )

It gets MR value.

Returns:
The value of MR
See also:
setMR()

Definition at line 77 of file w5300.c.

References MR.

Referenced by pppinit(), and pppterm().

uint16 getPATR ( void )

It gets PATR value.

Returns:
The value of PATR.
If PAP it returns 0xC023.
If CHAP it returns 0xC223.

Definition at line 191 of file w5300.c.

References IINCHIP_READ(), and PATR.

Referenced by pppinit_in().

void getPDHAR ( uint8 * addr )

It gets the PPPoE server hardware address.

Parameters:
[out] addr Storage location for input the source IP address. It should be allocated 6bytes size.

Definition at line 219 of file w5300.c.

References IINCHIP_READ(), and PDHAR.

Referenced by Main().

uint8 getPMAGICR ( void )

It gets PMAGICR value.

Returns:
The value of PMAGICR.
See also:
setPMAGICR()

Definition at line 205 of file w5300.c.

References IINCHIP_READ(), and PMAGICR.

uint16 getPn_BDPTHR ( uint8 p )

It gets the buffer depth of PIN "BRDYn".

Parameters:
[in] p The number of PIN "BRDYn". It is valid when 0 <= p <= 3.
Returns:
The buffer depth of PIN "BRDYn".
See also:
setPn_BDPTHR(), Pn_BRDYR

Definition at line 263 of file w5300.c.

References IINCHIP_READ(), and Pn_BDPTHR.

uint8 getPn_BRDYR ( uint8 p )

It gets Pn_BRDYR value.

Parameters:
[in] p The number of PIN "BRDYn". It is valid when 0 <= p <= 3.
Returns:
The configuration value of Pn_BRDYR.
See also:
setPn_BRDYR(), Pn_BDPTHR

Definition at line 253 of file w5300.c.

References IINCHIP_READ(), and Pn_BRDYR.

uint16 getPSIDR ( void )

It gets PSIDR value.

Returns:
The value of PSIDR.
Note:
PSIDR is read-only register.
However, in order to set PPP session ID(PSIDR), You can do it by writing S0_DPORTR to PPP session ID.

Definition at line 214 of file w5300.c.

References IINCHIP_READ(), and PSIDR.

Referenced by Main().

uint8 getPTIMER ( void )

It gets PTIMER value.

Returns:
The value of PTIMER. The unit is 25ms.
See also:
setPTIMER()

Definition at line 196 of file w5300.c.

References IINCHIP_READ(), and PTIMER.

uint8 getRCR ( void )

It gets RCR value.

Returns:
The value of RCR
See also:
setRCR()

Definition at line 181 of file w5300.c.

References IINCHIP_READ(), and RCR.

uint16 getRTR ( void )

It gets RTR value.

Returns:
The value of RTR. The unit is 100us.
See also:
setRTR()

Definition at line 172 of file w5300.c.

References IINCHIP_READ(), and RTR.

void getSHAR ( uint8 * addr )

It gets the source hardware address.

Parameters:
[out] addr Storage location for input the source hardware address. It should be allocated 6bytes size.
See also:
setSHAR()

Definition at line 114 of file w5300.c.

References IINCHIP_READ(), and SHAR.

Referenced by Main().

void getSIPR ( uint8 * addr )

It gets the source IP address.

Parameters:
[out] addr Storage location for input the source IP address. It should be allocated 4bytes size.
See also:
setSIPR()

Definition at line 156 of file w5300.c.

References IINCHIP_READ(), and SIPR.

Referenced by Main().

uint8 getSn_CR ( SOCKET s )

It gets Sn_CR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The command value of s-th SOCKET.
See also:
setSn_CR()

Definition at line 295 of file w5300.c.

References IINCHIP_READ(), and Sn_CR.

void getSn_DHAR | ( | SOCKET | s,
 |  | uint8 * | addr
 | ) |  |

It gets Sn_DHAR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[out] | addr | Storage location for input the destination hardware address of s-th SOCKET. It should be allocated 6bytes size.
Note:
It is also used when you get the PPPoE server hardware address.
Refer to getPDHAR(), PDHAR
See also:
setSn_DHAR()

Definition at line 348 of file w5300.c.

References IINCHIP_READ(), and Sn_DHAR.

void getSn_DIPR | ( | SOCKET | s,
 |  | uint8 * | addr
 | ) |  |

It gets Sn_DIPR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[out] | addr | Storage location for input the destination IP address of s-th SOCKET. It should be allocated 4bytes size.
See also:
setSn_DIPR()

Definition at line 377 of file w5300.c.

References IINCHIP_READ(), and Sn_DIPR.

uint8 getSn_FRAGR ( SOCKET s )

It gets Sn_FRAGR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The Sn_FRAGR value of s-th SOCKET.
See also:
setSn_FRAGR()

Definition at line 501 of file w5300.c.

References IINCHIP_READ(), and Sn_FRAGR.

uint8 getSn_IMR ( SOCKET s )

It gets Sn_IMR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The interrupt mask value of s-th SOCKET.
See also:
setSn_IMR(), Sn_IR, IR_SnINT

Definition at line 305 of file w5300.c.

References IINCHIP_READ(), and Sn_IMR.

uint8 getSn_IR ( SOCKET s )

It gets Sn_IR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The interrupt status of s-th SOCKET.
See also:
setSn_IR(), Sn_IMR, IR_SnINT

Definition at line 314 of file w5300.c.

References IINCHIP_READ(), Sn_IR, and SOCK_INT.

Referenced by loopback_tcpc(), loopback_tcps(), pppinit(), pppinit_in(), pppterm(), recv(), send(), and sendto().

uint8 getSn_KPALVTR ( SOCKET s )

It gets Sn_KPALVTR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The Sn_KPALVTR value of s-th SOCKET to be set.
See also:
setSn_KPALVTR()

Definition at line 405 of file w5300.c.

References IINCHIP_READ(), and Sn_KPALVTR.

uint16 getSn_MR ( SOCKET s )

It gets Sn_MR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The mode value of s-th SOCKET.
See also:
setSn_MR()

Definition at line 286 of file w5300.c.

References IINCHIP_READ(), and Sn_MR.

Referenced by close().

uint16 getSn_MSSR ( SOCKET s )

It gets Sn_MSSR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The value of Sn_MSSR
See also:
setSn_MSSR()

Definition at line 392 of file w5300.c.

References IINCHIP_READ(), and Sn_MSSR.

uint8 getSn_PROTOR ( SOCKET s )

It gets Sn_PROTOR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The protocol number of s-th SOCKET.
See also:
setSn_PROTOR()

Definition at line 472 of file w5300.c.

References IINCHIP_READ(), and Sn_PROTOR.

uint16 getSn_RX_FIFOR ( SOCKET s )

It gets Sn_RX_FIFOR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The data value to be read from internal RX memory of of s-th SOCKET, through Sn_RX_FIFOR.

Definition at line 464 of file w5300.c.

References IINCHIP_READ(), and Sn_RX_FIFOR.

uint32 getSn_RX_RSR ( SOCKET s )

It gets Sn_RX_RSR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
It returns the byte size of received data in internal RX memory of s-th SOCKET.
Warning:
Warning:
The host can read the wrong value of Sn_RX_RSR.
Because Sn_TX_RSR is not changed by 'system bus signal' but changed by synchronous 'NIC_CLK' clock.
To prevented this problem, the host should read it until the previous value is equal to the curruent.

Definition at line 444 of file w5300.c.

References IINCHIP_READ(), and Sn_RX_RSR.

Referenced by loopback_tcpc(), loopback_tcps(), loopback_udp(), pppinit_in(), and recv().

uint8 getSn_SSR ( SOCKET s )

It gets Sn_SSR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The status value of s-th SOCKET.
Warning:
Warning:
The host can read the wrong value of Sn_SSR.
Because Sn_SSR is not changed by 'system bus signal' but changed by synchronous 'NIC_CLK' clock.
To prevented this problem, the host should read it until the previous value is equal to the curruent.

Definition at line 334 of file w5300.c.

References IINCHIP_READ(), and Sn_SSR.

Referenced by listen(), loopback_tcpc(), loopback_tcps(), loopback_udp(), pppterm(), send(), sendto(), and socket().

uint8 getSn_TOSR ( SOCKET s )

It gets Sn_TOSR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The TOS value of s-th SOCKET.
See also:
setSn_TOSR()

Definition at line 483 of file w5300.c.

References IINCHIP_READ(), and Sn_TOSR.

uint8 getSn_TTLR ( SOCKET s )

It gets Sn_TTLR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The TTL value of s-th SOCKET.
See also:
setSn_TTLR()

Definition at line 492 of file w5300.c.

References IINCHIP_READ(), and Sn_TTLR.

uint32 getSn_TX_FSR ( SOCKET s )

It gets Sn_TX_FSR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
It returns the free size of internal TX memory(the byte size of transmittable data) of s-th SOCKET.
Warning:
Warning:
The host can read the wrong value of Sn_TX_FSR.
Because Sn_TX_FSR is not changed by 'system bus signal' but changed by synchronous 'NIC_CLK' clock.
To prevented this problem, the host should read it until the previous value is equal to the curruent.

Definition at line 430 of file w5300.c.

References IINCHIP_READ(), and Sn_TX_FSR.

Referenced by close(), and send().

uint32 getSn_TX_WRSR ( SOCKET s )

It gets Sn_TX_WRSR value.

Parameters:
[in] s SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
Returns:
The byte size of data written in internal TX memory of s-th SOCKET.
See also:
setSn_TX_WRSR()

Definition at line 417 of file w5300.c.

References IINCHIP_READ(), and Sn_TX_WRSR.

void getSUBR ( uint8 * addr )

It gets the subnet mask address.

Parameters:
[out] addr Storage location for input the subnet mask address. It should be allocated 4bytes size.
See also:
getSUBR()

Definition at line 143 of file w5300.c.

References IINCHIP_READ(), and SUBR.

Referenced by Main().

void getUIPR ( uint8 * addr )

It gets the unreachable destination IP address of ICMP message.

Parameters:
[out] addr Storage location for input the unreachable destination IP address. It should be allocated 4bytes size.
Note:
PDHAR is read-only register.
However, in order to set PPPoE server hardware address(PDHAR), You can do it by writing S0_DHAR to PPPoe server hardware address.
See also:
getUPORTR(), IR_DPUR

Definition at line 232 of file w5300.c.

References IINCHIP_READ(), and UIPR.

uint16 getUPORTR ( void )

It gets the unreachable destination port number of ICMP message.

Returns:
The unreachable destination port number
See also:
getUIPR(), IR_DPUR

Definition at line 240 of file w5300.c.

References IINCHIP_READ(), and UPORTR.

void iinchip_init ( void )

It initializes W5300.

It initializes W5300 by soft reset and decides the host interface mode by configuration MR.

Note:
You can modify this function to configure MR_WDF, MR_RDH, MR_FS, MR_DBS, MR_PB, MR_PPPoE.

Definition at line 518 of file w5300.c.

References MR, MR_IND, MR_RST, and wait_10ms().

Referenced by Main().

void iinchip_irq ( void )

It handles the interrupt of W5300.

Todo:
You should do implement your interrupt request routine instead of this function. If you want to use ISR, this function should be mapped in your ISR handler.

Definition at line 536 of file w5300.c.

References IINCHIP_CRITICAL_SECTION_ENTER, IINCHIP_CRITICAL_SECTION_EXIT, IINCHIP_READ(), IINCHIP_WRITE(), IR, IR_DPUR, IR_IPCF, IR_SnINT, MAX_SOCK_NUM, Sn_IR, SOCK_INT, UIPR, and UPORTR.

uint16 IINCHIP_READ ( uint32 addr )

Basic I/O function.

It reads a value from a register

Parameters:
[in] addr register address
Returns:
the value of register
Note:
If you define __DEF_IINCHIP_DIRECT_MODE__, you can use the below code instead of this function for the better performance.
 #define IINCHIP_READ(uint32 addr) (*(vint16*)addr)

Definition at line 52 of file w5300.c.

References IDM_AR, IDM_DR, IINCHIP_CRITICAL_SECTION_ENTER, and IINCHIP_CRITICAL_SECTION_EXIT.

Referenced by getFMTUR(), getGAR(), getIDR(), getIMR(), getIR(), getPATR(), getPDHAR(), getPMAGICR(), getPn_BDPTHR(), getPn_BRDYR(), getPSIDR(), getPTIMER(), getRCR(), getRTR(), getSHAR(), getSIPR(), getSn_CR(), getSn_DHAR(), getSn_DIPR(), getSn_FRAGR(), getSn_IMR(), getSn_IR(), getSn_KPALVTR(), getSn_MR(), getSn_MSSR(), getSn_PROTOR(), getSn_RX_FIFOR(), getSn_RX_RSR(), getSn_SSR(), getSn_TOSR(), getSn_TTLR(), getSn_TX_FSR(), getSn_TX_WRSR(), getSUBR(), getUIPR(), getUPORTR(), iinchip_irq(), recv(), recvfrom(), setSn_CR(), setSn_KPALVTR(), setSn_PROTOR(), socket(), sysinit(), and wiz_read_buf().

void IINCHIP_WRITE | ( | uint32 | addr,
 |  | uint16 | data
 | ) |  |

Basic I/O function.

It writes a value to a register

Parameters:
[in] | addr | register address
[in] | data | write data
Returns:
void
Note:
If you define __DEF_IINCHIP_DIRECT_MODE__, you can use the below code instead of this function for the better performance.
 #define IINCHIP_WRITE(uint32 addr,uint16 data)  ((*(vint16*)addr) = data)

Definition at line 65 of file w5300.c.

References IDM_AR, IDM_DR, IINCHIP_CRITICAL_SECTION_ENTER, and IINCHIP_CRITICAL_SECTION_EXIT.

Referenced by connect(), iinchip_irq(), recv(), sendto(), setGAR(), setIMR(), setIR(), setPMAGICR(), setPn_BDPTHR(), setPn_BRDYR(), setPTIMER(), setRCR(), setRTR(), setSHAR(), setSIPR(), setSn_CR(), setSn_DHAR(), setSn_DIPR(), setSn_DPORTR(), setSn_FRAGR(), setSn_IMR(), setSn_IR(), setSn_KPALVTR(), setSn_MR(), setSn_MSSR(), setSn_PROTOR(), setSn_TOSR(), setSn_TTLR(), setSn_TX_FIFOR(), setSn_TX_WRSR(), setSUBR(), socket(), sysinit(), and wiz_write_buf().

uint8 pppinit | ( | uint8 * | id,
 |  | uint8 | idlen,
 |  | uint8 * | passwd,
 |  | uint8 | passwdlen
 | ) |  |

It initializes to PPPoE of W5300.

It initiazes W5300 for PPPoE and calls pppinit_in() for PPPoE processing phase.
For the detail, refer to "How to use PPPoE in W5300".

Parameters:
[in] | id | User ID for connecting to a PPPoE server
[in] | idlen | Length of id
[in] | passwd | User password for connecting to a PPPoE server
[in] | passwdlen | Length of passwd
Returns:
It returns the result of pppinit_in()

Definition at line 1116 of file w5300.c.

References getMR(), getSn_IR(), MR_FS, MR_PPPoE, pppinit_in(), setMR(), setPMAGICR(), setPTIMER(), setSn_CR(), setSn_IR(), setSn_MR(), Sn_CR_CLOSE, Sn_CR_OPEN, and Sn_MR_PPPoE.

Referenced by Main().

void pppterm | ( | uint8 * | mac,
 |  | uint16 | sessionid
 | ) |  |

It terminates PPPoE connection.

For the detail, refer to "How to use PPPoE in W5300".

Parameters:
[in] | mac | PPPoE server hardware address occupied by pppinit() or your PPPoE-process code.
[in] | sessionid | session ID occupied by pppinit() or your PPPoE-process code.

Definition at line 1143 of file w5300.c.

References getMR(), getSn_IR(), getSn_SSR(), MR_PPPoE, setMR(), setSn_CR(), setSn_DHAR(), setSn_DPORTR(), setSn_IR(), setSn_MR(), Sn_CR_CLOSE, Sn_CR_OPEN, Sn_CR_PDISCON, Sn_MR_PPPoE, SOCK_PPPoE, and wait_10ms().

Referenced by Main().

void setGAR ( uint8 * addr )

It sets the gateway IP address.

Parameters:
[in] addr Pointer to the gateway IP address to be set
See also:
getGAR()

Definition at line 137 of file w5300.c.

References GAR, and IINCHIP_WRITE().

Referenced by Main().

void setIMR ( uint16 mask )

It sets IMR value.

Parameters:
[in] mask The mask value to be set
See also:
getIMR()

Definition at line 106 of file w5300.c.

References IINCHIP_WRITE(), and IMR.

void setIR ( uint16 val )

It sets IR value.

Parameters:
[in] val The value to be set
See also:
getIR()

Definition at line 97 of file w5300.c.

References IINCHIP_WRITE(), and IR.

void setMR ( uint16 val )

It sets MR value.

Parameters:
[in] val The value to be set
See also:
getMR()

Definition at line 81 of file w5300.c.

References MR.

Referenced by pppinit(), and pppterm().

void setPMAGICR ( uint8 magic )

It sets PTIMER value.

Parameters:
[in] magic The byte of 4byts MAGIC number for PPPoE
See also:
getPMAGICR()

Definition at line 209 of file w5300.c.

References IINCHIP_WRITE(), and PMAGICR.

Referenced by pppinit().

void setPn_BDPTHR | ( | uint8 | p,
 |  | uint16 | depth
 | ) |  |

It sets the buffer depth of PIN "BRDYn".

Parameters:
[in] | p | The number of PIN "BRDYn". It is valid when 0 <= p <= 3.
[in] | depth | The buffer depth of PIN "BRDYn" to be set.
See also:
getPn_BDPTHR(), Pn_BRDYR

Definition at line 267 of file w5300.c.

References IINCHIP_WRITE(), and Pn_BDPTHR.

setPn_BRDYR | ( | uint8 | p,
 |  | uint8 | cfg
 | ) |  |

It sets Pn_BRDYR value.

Parameters:
[in] | p | The number of PIN "BRDYn". It is valid when 0 <= p <= 3.
[in] | cfg | The configuration values of Pn_BRDYR to be set.
See also:
getPn_BRDYR(), Pn_BDPTHR

Definition at line 257 of file w5300.c.

References IINCHIP_WRITE(), and Pn_BRDYR.

void setPTIMER ( uint8 time )

It sets PTIMER value.

Parameters:
[in] time LCP echo-request transmittion timer value to be set. The unit is 25ms.
See also:
getPTIMER()

Definition at line 200 of file w5300.c.

References IINCHIP_WRITE(), and PTIMER.

Referenced by pppinit().

void setRCR ( uint8 retry )

It sets RCR value.

Parameters:
[in] retry The retry count of retransmittion to be set.
See also:
getRCR()

Definition at line 185 of file w5300.c.

References IINCHIP_WRITE(), and RCR.

void setRTR ( uint16 timeout )

It sets RTR value.

Parameters:
[in] timeout The timeout value to be set. The unit is 100us.
See also:
getRTR()

Definition at line 176 of file w5300.c.

References IINCHIP_WRITE(), and RTR.

void setSHAR ( uint8 * addr )

It sets the source hardware address.

Parameters:
[in] addr Pointer to the source hardware address to be set.
See also:
getSHAR()

Definition at line 123 of file w5300.c.

References IINCHIP_WRITE(), and SHAR.

Referenced by Main().

void setSIPR ( uint8 * addr )

It sets the source IP address.

Parameters:
[in] addr Pointer to the source IP address to be set
See also:
getSIR()

Definition at line 163 of file w5300.c.

References IINCHIP_WRITE(), and SIPR.

Referenced by Main().

void setSn_CR | ( | SOCKET | s,
 |  | uint16 | com
 | ) |  |

It sets Sn_CR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | com | The command value of s-th SOCKET.
Note:
It is blocked until Sn_CR is cleared.
See also:
getSn_CR()

Definition at line 299 of file w5300.c.

References IINCHIP_READ(), IINCHIP_WRITE(), and Sn_CR.

Referenced by close(), connect(), disconnect(), listen(), pppinit(), pppinit_in(), pppterm(), recv(), recvfrom(), send(), sendto(), and socket().

void setSn_DHAR | ( | SOCKET | s,
 |  | uint8 * | addr
 | ) |  |

It sets Sn_DHAR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | addr | Pointer to the destination hardware address of s-th SOCKET to be set.
Note:
It is also used when you set PPPoE server hardware address.
Refer to PDHAR
See also:
getSn_DHAR()

Definition at line 358 of file w5300.c.

References IINCHIP_WRITE(), and Sn_DHAR.

Referenced by pppterm().

void setSn_DIPR | ( | SOCKET | s,
 |  | uint8 * | addr
 | ) |  |

It sets Sn_DIPR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | addr | Pointer to the destination IP address of s-th SOCKET to be set.
See also:
getSn_DIPR()

Definition at line 386 of file w5300.c.

References IINCHIP_WRITE(), and Sn_DIPR.

void setSn_DPORTR | ( | SOCKET | s,
 |  | uint16 | port
 | ) |  |

It sets Sn_DPORTR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | port | The desintinaton port number of s-th SOCKET
Note:
It is also used when you set the PPP session ID.
Refer to PSIDR

Definition at line 372 of file w5300.c.

References IINCHIP_WRITE(), and Sn_DPORTR.

Referenced by pppterm().

void setSn_FRAGR | ( | SOCKET | s,
 |  | uint8 | frag
 | ) |  |

It sets Sn_FRAGR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | frag | The Sn_FRAGR value of s-th SOCKET to be set.
Note:
W5300 doesn't support the packet fragment at the IP layer.
Even though Sn_FRAGR is configured, IP data is not fragmented.
See also:
getSn_FRAGR()

Definition at line 506 of file w5300.c.

References IINCHIP_WRITE(), and Sn_FRAGR.

void setSn_IMR | ( | SOCKET | s,
 |  | uint8 | mask
 | ) |  |

It sets Sn_IMR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | mask | The interrupt mask value of s-th SOCKET.
See also:
getSn_IMR(), Sn_IR, IR_SnINT

Definition at line 309 of file w5300.c.

References IINCHIP_WRITE(), and Sn_IMR.

void setSn_IR | ( | SOCKET | s,
 |  | uint8 | ir
 | ) |  |

It sets Sn_IR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | ir | The interrupt status of s-th SOCKET to be cleared.
See also:
getSn_IR(), Sn_IMR, IR_SnINT

Definition at line 322 of file w5300.c.

References IINCHIP_WRITE(), Sn_IR, and SOCK_INT.

Referenced by close(), loopback_tcpc(), loopback_tcps(), pppinit(), pppinit_in(), pppterm(), recv(), send(), and sendto().

void setSn_KPALVTR | ( | SOCKET | s,
 |  | uint8 | time
 | ) |  |

It sets Sn_KPALVTR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | time | The keep alive timer value of s-th SOCKET to be set. The unit is 5 seconds.
Note:
When Sn_KPALVTR > 0, KEEP ALIVE(KA) packet is automatically transmitted and Sn_CR_SEND_KEEP is ignored.
When Sn_KPALVTR = 0, KA packet is manually transmitted by Sn_CR_SEND_KEEP.
See also:
getSn_KPALVTR()

Definition at line 410 of file w5300.c.

References IINCHIP_READ(), IINCHIP_WRITE(), and Sn_KPALVTR.

void setSn_MR | ( | SOCKET | s,
 |  | uint16 | mode
 | ) |  |

It sets Sn_MR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | mode | The mode value of s-th SOCKETn.
See also:
getSn_MR()

Definition at line 290 of file w5300.c.

References IINCHIP_WRITE(), and Sn_MR.

Referenced by pppinit(), and pppterm().

void setSn_MSSR | ( | SOCKET | s,
 |  | uint16 | mss
 | ) |  |

It sets Sn_MSSR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | mss | The MSS value of s-th SOCKET to be set.
Note:
When receiving the fragment MTU of ICMP message at UDP mode, You should be set Sn_MSSR to FMTUR by using this function.
Refer to FMTUR, IR_FMTU.
See also:
getSn_MSSR()

Definition at line 397 of file w5300.c.

References IINCHIP_WRITE(), and Sn_MSSR.

void setSn_PROTOR | ( | SOCKET | s,
 |  | uint8 | pronum
 | ) |  |

It sets Sn_PROTOR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | pronum | The protocol number of s-th SOCKET to be set. pronum does't support both 0x06(TCP) and 0x11(UDP) number.
See also:
getSn_PROTOR()

Definition at line 476 of file w5300.c.

References IINCHIP_READ(), IINCHIP_WRITE(), and Sn_PROTOR.

void setSn_TOSR | ( | SOCKET | s,
 |  | uint8 | tos
 | ) |  |

It sets Sn_TOSR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | tos | The TOS value of s-th SOCKET to be set.
See also:
getSn_TOSR()

Definition at line 487 of file w5300.c.

References IINCHIP_WRITE(), and Sn_TOSR.

void setSn_TTLR | ( | SOCKET | s,
 |  | uint8 | ttl
 | ) |  |

It sets Sn_TTLR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | ttl | The TTL value of s-th SOCKET to be set.
See also:
getSn_TTLR()

Definition at line 496 of file w5300.c.

References IINCHIP_WRITE(), and Sn_TTLR.

void setSn_TX_FIFOR | ( | SOCKET | s,
 |  | uint16 | data
 | ) |  |

It sets Sn_TX_FIFOR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
data | The data value to be written into internal TX memory of of s-th SOCKET, through Sn_TX_FIFOR.

Definition at line 459 of file w5300.c.

References IINCHIP_WRITE(), and Sn_TX_FIFOR.

void setSn_TX_WRSR | ( | SOCKET | s,
 |  | uint32 | size
 | ) |  |

It gets Sn_KPALVTR value.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | size | The byte size of data written in interanl TX memory of s-th SOCKET.
See also:
getSn_TX_WRSR()

Definition at line 424 of file w5300.c.

References IINCHIP_WRITE(), and Sn_TX_WRSR.

Referenced by pppinit_in(), recv(), send(), and sendto().

void setSUBR ( uint8 * addr )

It sets the subnet mask address.

Parameters:
[in] addr Pointer to the subnet mask address to be set
See also:
setSUBR()

Definition at line 150 of file w5300.c.

References IINCHIP_WRITE(), and SUBR.

Referenced by Main().

uint8 sysinit | ( | uint8 * | tx_size,
 |  | uint8 * | rx_size
 | ) |  |

It allocate internal TX/RX memory of each SOCKET.

Parameters:
[in] tx_size The pointer to allocate tx_size[n] to the internal TX memory of each SOCKET.
( 0 <= n <= MAX_SOCK_NUM-1).
TX memory size of each SOCKET is configurable in the range of 0~64Kbytes. Total memory size of each SOCKET's TX memory should be the multiple of 8.
[in] rx_size The pointer to allocate rx_size[n] to the internal RX memory of each SOCKET.
( 0 <= n <= MAX_SOCK_NUM-1).
RX memory size of each SOCKET is configurable in the range of 0~64Kbytes. Total memory size of each SOCKET's TX memory and RX memory should be 128Kbytes.
Returns:
If success, it returns 1. Otherwize 0.

Definition at line 577 of file w5300.c.

References IINCHIP_READ(), IINCHIP_WRITE(), MAX_SOCK_NUM, MTYPER, RMS01R, RMS23R, RMS45R, RMS67R, RXMEM_SIZE, TMS01R, TMS23R, TMS45R, TMS67R, and TXMEM_SIZE.

Referenced by Main().

void wait_10ms ( uint32 ms )

Delay function.

Parameters:
[in] ms - wait time It waits for the ms time.
Todo:
These delay functions depend on the MCU. Therefore, These function should be replaced with yours.

Definition at line 1200 of file w5300.c.

References wait_1ms().

Referenced by close(), iinchip_init(), pppinit_in(), and pppterm().

uint32 wiz_read_buf | ( | SOCKET | s,
 |  | uint8 * | buf,
 |  | uint32 | len
 | ) |  |

It copies data to your buffer from internal RX memory.

It copies the len bytes of internal RX memory of s-th SOCKET to buf through Sn_RX_FIFOR.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[out] buf Destination buffer to copy
The length of buf should be equal or greater than len + 1, in order to prevent the memory violation.
[in] | len | bytes of internal RX memory of s-th SOCKET to copy.
Returns:
The copied byte number
Note:
In case using interrupt or multi-task, it is protected with IINCHIP_CRITICAL_SECTION_ENTER() & IINCHIP_CRITICAL_SECTION_EXIT() while Sn_RX_FIFOR read.
If no use, it can be occured some problem such as invalid PACKET_INFO or DATA.

Definition at line 714 of file w5300.c.

References IDM_AR, IDM_DR, IINCHIP_CRITICAL_SECTION_ENTER, IINCHIP_CRITICAL_SECTION_EXIT, IINCHIP_READ(), and Sn_RX_FIFOR.

Referenced by pppinit_in(), recv(), and recvfrom().

uint32 wiz_write_buf | ( | SOCKET | s,
 |  | uint8 * | buf,
 |  | uint32 | len
 | ) |  |

It copies data to interna1 TX memory.

It copies the len bytes of buf to internal TX memory of s-th SOCKET through Sn_TX_FIFOR.

Parameters:
[in] | s | SOCKET number. It is valid when 0 <= s <= MAX_SOCK_NUM - 1.
[in] | buf | Source buffer to copy from
[in] | len | bytes of data to copy.
Returns:
The copied byte number
Note:
In case using interrupt or multi-task, it is protected with IINCHIP_CRITICAL_SECTION_ENTER() & IINCHIP_CRITICAL_SECTION_EXIT() while Sn_TX_FIFOR write.
If no use, it can be occured some problem such that invalid DATA are transmitted.

Definition at line 648 of file w5300.c.

References IDM_AR, IDM_DR, IINCHIP_CRITICAL_SECTION_ENTER, IINCHIP_CRITICAL_SECTION_EXIT, IINCHIP_WRITE(), and Sn_TX_FIFOR.

Referenced by pppinit_in(), send(), and sendto().

Generated on Fri Jan 2 12:20:00 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Data Fields

  • File List
  • Globals
  • All
  • Functions
  • Variables
  • Typedefs
  • Defines
  • _
  • c
  • d
  • f
  • g
  • i
  • l
  • m
  • p
  • r
  • s
  • t
  • u
  • v
  • w
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:

- _ -

  • __DEF_C__ : iinchip_conf.h
  • __DEF_IINCHIP_ADDRESS_MODE__ : iinchip_conf.h
  • __DEF_IINCHIP_BUF_OP__ : iinchip_conf.h
  • __DEF_IINCHIP_DBG__ : iinchip_conf.h
  • __DEF_IINCHIP_DIRECT_MODE__ : iinchip_conf.h
  • __DEF_IINCHIP_INDIRECT_MODE__ : iinchip_conf.h
  • __DEF_IINCHIP_INT__ : iinchip_conf.h
  • __DEF_IINCHIP_MAP_BASE__ : iinchip_conf.h
  • __DEF_IINCHIP_PPP__ : iinchip_conf.h
  • __DEF_MCU_DEP_DMA__ : iinchip_conf.h
  • __DEF_MCU_DEP_INLINE_ASM__ : iinchip_conf.h
Generated on Fri Jan 2 12:20:01 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Data Fields

  • File List
  • Globals
  • All
  • Functions
  • Variables
  • Typedefs
  • Defines
  • _
  • c
  • d
  • f
  • g
  • i
  • l
  • m
  • p
  • r
  • s
  • t
  • u
  • v
  • w
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:

- l -

  • listen() : socket.h , socket.c
  • loopback_tcpc() : main.c
  • loopback_tcps() : main.c
  • loopback_udp() : main.c
Generated on Fri Jan 2 12:20:01 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Data Fields

  • File List
  • Globals
  • All
  • Functions
  • Variables
  • Typedefs
  • Defines
  • _
  • c
  • d
  • f
  • g
  • i
  • l
  • m
  • p
  • r
  • s
  • t
  • u
  • v
  • w
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:

- m -

  • Main() : main.c
  • MAX_SOCK_NUM : iinchip_conf.h
  • MR : w5300.h
  • MR_DBS : w5300.h
  • MR_DBW : w5300.h
  • MR_FS : w5300.h
  • MR_IND : w5300.h
  • MR_MPF : w5300.h
  • MR_MT : w5300.h
  • MR_PB : w5300.h
  • MR_PPPoE : w5300.h
  • MR_RDH : w5300.h
  • MR_RST : w5300.h
  • MR_WDF : w5300.h
  • MTYPER : w5300.h
Generated on Fri Jan 2 12:20:01 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Data Fields

  • File List
  • Globals
  • All
  • Functions
  • Variables
  • Typedefs
  • Defines
  • _
  • c
  • d
  • f
  • g
  • i
  • l
  • m
  • p
  • r
  • s
  • t
  • u
  • v
  • w
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:

- c -

  • check_sendok_flag : socket.c
  • close() : socket.h , socket.c
  • COMMON_REG_BASE : iinchip_conf.h
  • connect() : socket.h , socket.c
Generated on Fri Jan 2 12:20:01 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Data Fields

  • File List
  • Globals
  • All
  • Functions
  • Variables
  • Typedefs
  • Defines
  • _
  • c
  • d
  • f
  • g
  • i
  • l
  • m
  • p
  • r
  • s
  • t
  • u
  • v
  • w
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:

- d -

  • disconnect() : socket.h , socket.c
Generated on Fri Jan 2 12:20:01 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Data Fields

  • File List
  • Globals
  • All
  • Functions
  • Variables
  • Typedefs
  • Defines
  • _
  • c
  • d
  • f
  • g
  • i
  • l
  • m
  • p
  • r
  • s
  • t
  • u
  • v
  • w
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:

- f -

  • FMTUR : w5300.h
Generated on Fri Jan 2 12:20:01 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Data Fields

  • File List
  • Globals
  • All
  • Functions
  • Variables
  • Typedefs
  • Defines
  • _
  • c
  • d
  • f
  • g
  • i
  • l
  • m
  • p
  • r
  • s
  • t
  • u
  • v
  • w
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:

- g -

  • GAR : w5300.h
  • getFMTUR() : w5300.h , w5300.c
  • getGAR() : w5300.h , w5300.c
  • getIDR() : w5300.h , w5300.c
  • getIINCHIP_RxMAX() : w5300.h , w5300.c
  • getIINCHIP_TxMAX() : w5300.h , w5300.c
  • getIMR() : w5300.h , w5300.c
  • getIR() : w5300.h , w5300.c
  • getMR() : w5300.h , w5300.c
  • getPATR() : w5300.h , w5300.c
  • getPDHAR() : w5300.h , w5300.c
  • getPMAGICR() : w5300.h , w5300.c
  • getPn_BDPTHR() : w5300.h , w5300.c
  • getPn_BRDYR() : w5300.h , w5300.c
  • getPSIDR() : w5300.h , w5300.c
  • getPTIMER() : w5300.h , w5300.c
  • getRCR() : w5300.h , w5300.c
  • getRTR() : w5300.h , w5300.c
  • getSHAR() : w5300.h , w5300.c
  • getSIPR() : w5300.h , w5300.c
  • getSn_CR() : w5300.h , w5300.c
  • getSn_DHAR() : w5300.c , w5300.h
  • getSn_DIPR() : w5300.h , w5300.c
  • getSn_FRAGR() : w5300.c , w5300.h
  • getSn_IMR() : w5300.h , w5300.c
  • getSn_IR() : w5300.h , w5300.c
  • getSn_KPALVTR() : w5300.h , w5300.c
  • getSn_MR() : w5300.c , w5300.h
  • getSn_MSSR() : w5300.c , w5300.h
  • getSn_PROTOR() : w5300.c , w5300.h
  • getSn_RX_FIFOR() : w5300.c , w5300.h
  • getSn_RX_RSR() : w5300.c , w5300.h
  • getSn_SSR() : w5300.h , w5300.c
  • getSn_TOSR() : w5300.c , w5300.h
  • getSn_TTLR() : w5300.h , w5300.c
  • getSn_TX_FSR() : w5300.c , w5300.h
  • getSn_TX_WRSR() : w5300.h , w5300.c
  • getSUBR() : w5300.c , w5300.h
  • getUIPR() : w5300.c , w5300.h
  • getUPORTR() : w5300.h , w5300.c
Generated on Fri Jan 2 12:20:01 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Data Fields

  • File List
  • Globals
  • All
  • Functions
  • Variables
  • Typedefs
  • Defines
  • _
  • c
  • d
  • f
  • g
  • i
  • l
  • m
  • p
  • r
  • s
  • t
  • u
  • v
  • w
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:

- i -

  • IDM_AR : w5300.h
  • IDM_DR : w5300.h
  • IDR : w5300.h
  • IINCHIP_CRITICAL_SECTION_ENTER : iinchip_conf.h
  • IINCHIP_CRITICAL_SECTION_EXIT : iinchip_conf.h
  • iinchip_init() : w5300.h , w5300.c
  • iinchip_irq() : w5300.h , w5300.c
  • IINCHIP_READ() : w5300.h , w5300.c
  • iinchip_source_port : socket.c
  • IINCHIP_WRITE() : w5300.h , w5300.c
  • IMR : w5300.h
  • int16 : types.h
  • int32 : types.h
  • int8 : types.h
  • IPPROTO_GGP : w5300.h
  • IPPROTO_ICMP : w5300.h
  • IPPROTO_IDP : w5300.h
  • IPPROTO_IGMP : w5300.h
  • IPPROTO_IP : w5300.h
  • IPPROTO_ND : w5300.h
  • IPPROTO_PUP : w5300.h
  • IPPROTO_RAW : w5300.h
  • IPPROTO_TCP : w5300.h
  • IPPROTO_UDP : w5300.h
  • IR : w5300.h
  • IR_DPUR : w5300.h
  • IR_FMTU : w5300.h
  • IR_IPCF : w5300.h
  • IR_PPPT : w5300.h
  • IR_SnINT : w5300.h
Generated on Fri Jan 2 12:20:01 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Data Fields

  • File List
  • Globals
  • All
  • Functions
  • Variables
  • Typedefs
  • Defines
  • _
  • c
  • d
  • f
  • g
  • i
  • l
  • m
  • p
  • r
  • s
  • t
  • u
  • v
  • w
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:

- p -

  • PATR : w5300.h
  • PDHAR : w5300.h
  • PMAGICR : w5300.h
  • Pn_BDPTHR : w5300.h
  • Pn_BRDYR : w5300.h
  • Pn_MT : w5300.h
  • Pn_PEN : w5300.h
  • Pn_PPL : w5300.h
  • Pn_SN : w5300.h
  • PPP_OPTION_BUF_LEN : w5300.c
  • pppinit() : w5300.h , w5300.c
  • pppinit_in() : w5300.c
  • pppterm() : w5300.c , w5300.h
  • PSIDR : w5300.h
  • PTIMER : w5300.h
Generated on Fri Jan 2 12:20:01 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Data Fields

  • File List
  • Globals
  • All
  • Functions
  • Variables
  • Typedefs
  • Defines
  • _
  • c
  • d
  • f
  • g
  • i
  • l
  • m
  • p
  • r
  • s
  • t
  • u
  • v
  • w
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:

- r -

  • RCR : w5300.h
  • recv() : socket.h , socket.c
  • recvfrom() : socket.h , socket.c
  • RMS01R : w5300.h
  • RMS23R : w5300.h
  • RMS45R : w5300.h
  • RMS67R : w5300.h
  • RTR : w5300.h
  • RXMEM_SIZE : w5300.c
Generated on Fri Jan 2 12:20:01 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Data Fields

  • File List
  • Globals
  • All
  • Functions
  • Variables
  • Typedefs
  • Defines
  • _
  • c
  • d
  • f
  • g
  • i
  • l
  • m
  • p
  • r
  • s
  • t
  • u
  • v
  • w
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:

- s -

  • send() : socket.h , socket.c
  • sendto() : socket.c , socket.h
  • setGAR() : w5300.h , w5300.c
  • setIMR() : w5300.c , w5300.h
  • setIR() : w5300.h , w5300.c
  • setMR() : w5300.h , w5300.c
  • setPMAGICR() : w5300.h , w5300.c
  • setPn_BDPTHR() : w5300.c , w5300.h
  • setPn_BRDYR() : w5300.h , w5300.c
  • setPTIMER() : w5300.h , w5300.c
  • setRCR() : w5300.h , w5300.c
  • setRTR() : w5300.h , w5300.c
  • setSHAR() : w5300.h , w5300.c
  • setSIPR() : w5300.h , w5300.c
  • setSn_CR() : w5300.h , w5300.c
  • setSn_DHAR() : w5300.c , w5300.h
  • setSn_DIPR() : w5300.h , w5300.c
  • setSn_DPORTR() : w5300.h , w5300.c
  • setSn_FRAGR() : w5300.h , w5300.c
  • setSn_IMR() : w5300.h , w5300.c
  • setSn_IR() : w5300.h , w5300.c
  • setSn_KPALVTR() : w5300.h , w5300.c
  • setSn_MR() : w5300.h , w5300.c
  • setSn_MSSR() : w5300.h , w5300.c
  • setSn_PROTOR() : w5300.h , w5300.c
  • setSn_TOSR() : w5300.h , w5300.c
  • setSn_TTLR() : w5300.h , w5300.c
  • setSn_TX_FIFOR() : w5300.h , w5300.c
  • setSn_TX_WRSR() : w5300.h , w5300.c
  • setSUBR() : w5300.h , w5300.c
  • SHAR : w5300.h
  • SIPR : w5300.h
  • Sn_CR : w5300.h
  • Sn_CR_CLOSE : w5300.h
  • Sn_CR_CONNECT : w5300.h
  • Sn_CR_DISCON : w5300.h
  • Sn_CR_LISTEN : w5300.h
  • Sn_CR_OPEN : w5300.h
  • Sn_CR_PCJ : w5300.h
  • Sn_CR_PCN : w5300.h
  • Sn_CR_PCON : w5300.h
  • Sn_CR_PCR : w5300.h
  • Sn_CR_PDISCON : w5300.h
  • Sn_CR_RECV : w5300.h
  • Sn_CR_SEND : w5300.h
  • Sn_CR_SEND_KEEP : w5300.h
  • Sn_CR_SEND_MAC : w5300.h
  • Sn_DHAR : w5300.h
  • Sn_DIPR : w5300.h
  • Sn_DPORTR : w5300.h
  • Sn_FRAGR : w5300.h
  • Sn_IMR : w5300.h
  • Sn_IR : w5300.h
  • Sn_IR_CON : w5300.h
  • Sn_IR_DISCON : w5300.h
  • Sn_IR_PFAIL : w5300.h
  • Sn_IR_PNEXT : w5300.h
  • Sn_IR_PRECV : w5300.h
  • Sn_IR_RECV : w5300.h
  • Sn_IR_SENDOK : w5300.h
  • Sn_IR_TIMEOUT : w5300.h
  • Sn_KPALVTR : w5300.h
  • Sn_MR : w5300.h
  • Sn_MR_ALIGN : w5300.h
  • Sn_MR_CLOSE : w5300.h
  • Sn_MR_IGMPv : w5300.h
  • Sn_MR_IPRAW : w5300.h
  • Sn_MR_MACRAW : w5300.h
  • Sn_MR_MF : w5300.h
  • Sn_MR_MULTI : w5300.h
  • Sn_MR_ND : w5300.h
  • Sn_MR_PPPoE : w5300.h
  • Sn_MR_TCP : w5300.h
  • Sn_MR_UDP : w5300.h
  • Sn_MSSR : w5300.h
  • Sn_PORTR : w5300.h
  • Sn_PROTOR : w5300.h
  • Sn_RX_FIFOR : w5300.h
  • Sn_RX_RSR : w5300.h
  • Sn_SSR : w5300.h
  • Sn_TOSR : w5300.h
  • Sn_TTLR : w5300.h
  • Sn_TX_FIFOR : w5300.h
  • Sn_TX_FSR : w5300.h
  • Sn_TX_WRSR : w5300.h
  • SOCK_ARP : w5300.h
  • SOCK_CLOSE_WAIT : w5300.h
  • SOCK_CLOSED : w5300.h
  • SOCK_CLOSING : w5300.h
  • SOCK_ESTABLISHED : w5300.h
  • SOCK_FIN_WAIT : w5300.h
  • SOCK_INIT : w5300.h
  • SOCK_INT : w5300.c
  • SOCK_IPRAW : w5300.h
  • SOCK_LAST_ACK : w5300.h
  • SOCK_LISTEN : w5300.h
  • SOCK_MACRAW : w5300.h
  • SOCK_PPPoE : w5300.h
  • SOCK_SYNRECV : w5300.h
  • SOCK_SYNSENT : w5300.h
  • SOCK_TIME_WAIT : w5300.h
  • SOCK_UDP : w5300.h
  • socket() : socket.c
  • SOCKET : types.h
  • socket() : socket.h
  • SOCKET_REG_BASE : iinchip_conf.h
  • SUBR : w5300.h
  • sysinit() : w5300.h , w5300.c
Generated on Fri Jan 2 12:20:01 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Data Fields

  • File List
  • Globals
  • All
  • Functions
  • Variables
  • Typedefs
  • Defines
  • _
  • c
  • d
  • f
  • g
  • i
  • l
  • m
  • p
  • r
  • s
  • t
  • u
  • v
  • w
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:

- t -

  • TMS01R : w5300.h
  • TMS23R : w5300.h
  • TMS45R : w5300.h
  • TMS67R : w5300.h
  • TXMEM_SIZE : w5300.c
Generated on Fri Jan 2 12:20:01 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Data Fields

  • File List
  • Globals
  • All
  • Functions
  • Variables
  • Typedefs
  • Defines
  • _
  • c
  • d
  • f
  • g
  • i
  • l
  • m
  • p
  • r
  • s
  • t
  • u
  • v
  • w
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:

- u -

  • uint16 : types.h
  • uint32 : types.h
  • uint8 : types.h
  • UIPR : w5300.h
  • UPORTR : w5300.h
Generated on Fri Jan 2 12:20:01 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Data Fields

  • File List
  • Globals
  • All
  • Functions
  • Variables
  • Typedefs
  • Defines
  • _
  • c
  • d
  • f
  • g
  • i
  • l
  • m
  • p
  • r
  • s
  • t
  • u
  • v
  • w
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:

- v -

  • vint16 : types.h
  • vint32 : types.h
  • vint8 : types.h
  • vuint16 : types.h
  • vuint32 : types.h
  • vuint8 : types.h
Generated on Fri Jan 2 12:20:01 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Data Fields

  • File List
  • Globals
  • All
  • Functions
  • Variables
  • Typedefs
  • Defines
  • _
  • c
  • d
  • f
  • g
  • i
  • l
  • m
  • p
  • r
  • s
  • t
  • u
  • v
  • w
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:

- w -

  • wait_10ms() : w5300.h , w5300.c
  • wait_1ms() : w5300.c , w5300.h
  • wait_1us() : w5300.h , w5300.c
  • wiz_read_buf() : w5300.h , w5300.c
  • wiz_write_buf() : w5300.c , w5300.h
Generated on Fri Jan 2 12:20:01 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Data Fields

  • File List
  • Globals
  • All
  • Functions
  • Variables
  • Typedefs
  • Defines
  • _
  • c
  • f
  • g
  • i
  • m
  • p
  • r
  • s
  • t
  • u

- _ -

  • __DEF_C__ : iinchip_conf.h
  • __DEF_IINCHIP_ADDRESS_MODE__ : iinchip_conf.h
  • __DEF_IINCHIP_BUF_OP__ : iinchip_conf.h
  • __DEF_IINCHIP_DBG__ : iinchip_conf.h
  • __DEF_IINCHIP_DIRECT_MODE__ : iinchip_conf.h
  • __DEF_IINCHIP_INDIRECT_MODE__ : iinchip_conf.h
  • __DEF_IINCHIP_INT__ : iinchip_conf.h
  • __DEF_IINCHIP_MAP_BASE__ : iinchip_conf.h
  • __DEF_IINCHIP_PPP__ : iinchip_conf.h
  • __DEF_MCU_DEP_DMA__ : iinchip_conf.h
  • __DEF_MCU_DEP_INLINE_ASM__ : iinchip_conf.h

- c -

  • COMMON_REG_BASE : iinchip_conf.h

- f -

  • FMTUR : w5300.h

- g -

  • GAR : w5300.h

- i -

  • IDM_AR : w5300.h
  • IDM_DR : w5300.h
  • IDR : w5300.h
  • IINCHIP_CRITICAL_SECTION_ENTER : iinchip_conf.h
  • IINCHIP_CRITICAL_SECTION_EXIT : iinchip_conf.h
  • IMR : w5300.h
  • IPPROTO_GGP : w5300.h
  • IPPROTO_ICMP : w5300.h
  • IPPROTO_IDP : w5300.h
  • IPPROTO_IGMP : w5300.h
  • IPPROTO_IP : w5300.h
  • IPPROTO_ND : w5300.h
  • IPPROTO_PUP : w5300.h
  • IPPROTO_RAW : w5300.h
  • IPPROTO_TCP : w5300.h
  • IPPROTO_UDP : w5300.h
  • IR : w5300.h
  • IR_DPUR : w5300.h
  • IR_FMTU : w5300.h
  • IR_IPCF : w5300.h
  • IR_PPPT : w5300.h
  • IR_SnINT : w5300.h

- m -

  • MAX_SOCK_NUM : iinchip_conf.h
  • MR : w5300.h
  • MR_DBS : w5300.h
  • MR_DBW : w5300.h
  • MR_FS : w5300.h
  • MR_IND : w5300.h
  • MR_MPF : w5300.h
  • MR_MT : w5300.h
  • MR_PB : w5300.h
  • MR_PPPoE : w5300.h
  • MR_RDH : w5300.h
  • MR_RST : w5300.h
  • MR_WDF : w5300.h
  • MTYPER : w5300.h

- p -

  • PATR : w5300.h
  • PDHAR : w5300.h
  • PMAGICR : w5300.h
  • Pn_BDPTHR : w5300.h
  • Pn_BRDYR : w5300.h
  • Pn_MT : w5300.h
  • Pn_PEN : w5300.h
  • Pn_PPL : w5300.h
  • Pn_SN : w5300.h
  • PPP_OPTION_BUF_LEN : w5300.c
  • PSIDR : w5300.h
  • PTIMER : w5300.h

- r -

  • RCR : w5300.h
  • RMS01R : w5300.h
  • RMS23R : w5300.h
  • RMS45R : w5300.h
  • RMS67R : w5300.h
  • RTR : w5300.h

- s -

  • SHAR : w5300.h
  • SIPR : w5300.h
  • Sn_CR : w5300.h
  • Sn_CR_CLOSE : w5300.h
  • Sn_CR_CONNECT : w5300.h
  • Sn_CR_DISCON : w5300.h
  • Sn_CR_LISTEN : w5300.h
  • Sn_CR_OPEN : w5300.h
  • Sn_CR_PCJ : w5300.h
  • Sn_CR_PCN : w5300.h
  • Sn_CR_PCON : w5300.h
  • Sn_CR_PCR : w5300.h
  • Sn_CR_PDISCON : w5300.h
  • Sn_CR_RECV : w5300.h
  • Sn_CR_SEND : w5300.h
  • Sn_CR_SEND_KEEP : w5300.h
  • Sn_CR_SEND_MAC : w5300.h
  • Sn_DHAR : w5300.h
  • Sn_DIPR : w5300.h
  • Sn_DPORTR : w5300.h
  • Sn_FRAGR : w5300.h
  • Sn_IMR : w5300.h
  • Sn_IR : w5300.h
  • Sn_IR_CON : w5300.h
  • Sn_IR_DISCON : w5300.h
  • Sn_IR_PFAIL : w5300.h
  • Sn_IR_PNEXT : w5300.h
  • Sn_IR_PRECV : w5300.h
  • Sn_IR_RECV : w5300.h
  • Sn_IR_SENDOK : w5300.h
  • Sn_IR_TIMEOUT : w5300.h
  • Sn_KPALVTR : w5300.h
  • Sn_MR : w5300.h
  • Sn_MR_ALIGN : w5300.h
  • Sn_MR_CLOSE : w5300.h
  • Sn_MR_IGMPv : w5300.h
  • Sn_MR_IPRAW : w5300.h
  • Sn_MR_MACRAW : w5300.h
  • Sn_MR_MF : w5300.h
  • Sn_MR_MULTI : w5300.h
  • Sn_MR_ND : w5300.h
  • Sn_MR_PPPoE : w5300.h
  • Sn_MR_TCP : w5300.h
  • Sn_MR_UDP : w5300.h
  • Sn_MSSR : w5300.h
  • Sn_PORTR : w5300.h
  • Sn_PROTOR : w5300.h
  • Sn_RX_FIFOR : w5300.h
  • Sn_RX_RSR : w5300.h
  • Sn_SSR : w5300.h
  • Sn_TOSR : w5300.h
  • Sn_TTLR : w5300.h
  • Sn_TX_FIFOR : w5300.h
  • Sn_TX_FSR : w5300.h
  • Sn_TX_WRSR : w5300.h
  • SOCK_ARP : w5300.h
  • SOCK_CLOSE_WAIT : w5300.h
  • SOCK_CLOSED : w5300.h
  • SOCK_CLOSING : w5300.h
  • SOCK_ESTABLISHED : w5300.h
  • SOCK_FIN_WAIT : w5300.h
  • SOCK_INIT : w5300.h
  • SOCK_IPRAW : w5300.h
  • SOCK_LAST_ACK : w5300.h
  • SOCK_LISTEN : w5300.h
  • SOCK_MACRAW : w5300.h
  • SOCK_PPPoE : w5300.h
  • SOCK_SYNRECV : w5300.h
  • SOCK_SYNSENT : w5300.h
  • SOCK_TIME_WAIT : w5300.h
  • SOCK_UDP : w5300.h
  • SOCKET_REG_BASE : iinchip_conf.h
  • SUBR : w5300.h

- t -

  • TMS01R : w5300.h
  • TMS23R : w5300.h
  • TMS45R : w5300.h
  • TMS67R : w5300.h

- u -

  • UIPR : w5300.h
  • UPORTR : w5300.h
Generated on Fri Jan 2 12:20:01 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Data Fields

  • File List
  • Globals
  • All
  • Functions
  • Variables
  • Typedefs
  • Defines
  • c
  • d
  • g
  • i
  • l
  • m
  • p
  • r
  • s
  • w

- c -

  • close() : socket.h , socket.c
  • connect() : socket.h , socket.c

- d -

  • disconnect() : socket.h , socket.c

- g -

  • getFMTUR() : w5300.h , w5300.c
  • getGAR() : w5300.c , w5300.h
  • getIDR() : w5300.h , w5300.c
  • getIINCHIP_RxMAX() : w5300.c , w5300.h
  • getIINCHIP_TxMAX() : w5300.h , w5300.c
  • getIMR() : w5300.h , w5300.c
  • getIR() : w5300.h , w5300.c
  • getMR() : w5300.c , w5300.h
  • getPATR() : w5300.h , w5300.c
  • getPDHAR() : w5300.h , w5300.c
  • getPMAGICR() : w5300.h , w5300.c
  • getPn_BDPTHR() : w5300.h , w5300.c
  • getPn_BRDYR() : w5300.h , w5300.c
  • getPSIDR() : w5300.h , w5300.c
  • getPTIMER() : w5300.h , w5300.c
  • getRCR() : w5300.c , w5300.h
  • getRTR() : w5300.h , w5300.c
  • getSHAR() : w5300.h , w5300.c
  • getSIPR() : w5300.h , w5300.c
  • getSn_CR() : w5300.h , w5300.c
  • getSn_DHAR() : w5300.h , w5300.c
  • getSn_DIPR() : w5300.h , w5300.c
  • getSn_FRAGR() : w5300.h , w5300.c
  • getSn_IMR() : w5300.h , w5300.c
  • getSn_IR() : w5300.h , w5300.c
  • getSn_KPALVTR() : w5300.c , w5300.h
  • getSn_MR() : w5300.h , w5300.c
  • getSn_MSSR() : w5300.h , w5300.c
  • getSn_PROTOR() : w5300.h , w5300.c
  • getSn_RX_FIFOR() : w5300.h , w5300.c
  • getSn_RX_RSR() : w5300.c , w5300.h
  • getSn_SSR() : w5300.c , w5300.h
  • getSn_TOSR() : w5300.c , w5300.h
  • getSn_TTLR() : w5300.c , w5300.h
  • getSn_TX_FSR() : w5300.h , w5300.c
  • getSn_TX_WRSR() : w5300.c , w5300.h
  • getSUBR() : w5300.h , w5300.c
  • getUIPR() : w5300.c , w5300.h
  • getUPORTR() : w5300.h , w5300.c

- i -

  • iinchip_init() : w5300.h , w5300.c
  • iinchip_irq() : w5300.c , w5300.h
  • IINCHIP_READ() : w5300.h , w5300.c
  • IINCHIP_WRITE() : w5300.c , w5300.h

- l -

  • listen() : socket.h , socket.c
  • loopback_tcpc() : main.c
  • loopback_tcps() : main.c
  • loopback_udp() : main.c

- m -

  • Main() : main.c

- p -

  • pppinit() : w5300.h , w5300.c
  • pppinit_in() : w5300.c
  • pppterm() : w5300.h , w5300.c

- r -

  • recv() : socket.h , socket.c
  • recvfrom() : socket.h , socket.c

- s -

  • send() : socket.h , socket.c
  • sendto() : socket.c , socket.h
  • setGAR() : w5300.h , w5300.c
  • setIMR() : w5300.c , w5300.h
  • setIR() : w5300.h , w5300.c
  • setMR() : w5300.h , w5300.c
  • setPMAGICR() : w5300.h , w5300.c
  • setPn_BDPTHR() : w5300.c , w5300.h
  • setPn_BRDYR() : w5300.h , w5300.c
  • setPTIMER() : w5300.h , w5300.c
  • setRCR() : w5300.h , w5300.c
  • setRTR() : w5300.h , w5300.c
  • setSHAR() : w5300.h , w5300.c
  • setSIPR() : w5300.h , w5300.c
  • setSn_CR() : w5300.h , w5300.c
  • setSn_DHAR() : w5300.c , w5300.h
  • setSn_DIPR() : w5300.h , w5300.c
  • setSn_DPORTR() : w5300.h , w5300.c
  • setSn_FRAGR() : w5300.h , w5300.c
  • setSn_IMR() : w5300.c , w5300.h
  • setSn_IR() : w5300.h , w5300.c
  • setSn_KPALVTR() : w5300.h , w5300.c
  • setSn_MR() : w5300.c , w5300.h
  • setSn_MSSR() : w5300.h , w5300.c
  • setSn_PROTOR() : w5300.h , w5300.c
  • setSn_TOSR() : w5300.c , w5300.h
  • setSn_TTLR() : w5300.c , w5300.h
  • setSn_TX_FIFOR() : w5300.h , w5300.c
  • setSn_TX_WRSR() : w5300.c , w5300.h
  • setSUBR() : w5300.h , w5300.c
  • socket() : socket.h , socket.c
  • sysinit() : w5300.h , w5300.c

- w -

  • wait_10ms() : w5300.h , w5300.c
  • wait_1ms() : w5300.c , w5300.h
  • wait_1us() : w5300.h , w5300.c
  • wiz_read_buf() : w5300.h , w5300.c
  • wiz_write_buf() : w5300.c , w5300.h
Generated on Fri Jan 2 12:20:01 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Data Fields

  • File List
  • Globals
  • All
  • Functions
  • Variables
  • Typedefs
  • Defines

  • int16 : types.h
  • int32 : types.h
  • int8 : types.h
  • SOCKET : types.h
  • uint16 : types.h
  • uint32 : types.h
  • uint8 : types.h
  • vint16 : types.h
  • vint32 : types.h
  • vint8 : types.h
  • vuint16 : types.h
  • vuint32 : types.h
  • vuint8 : types.h
Generated on Fri Jan 2 12:20:01 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Data Fields

  • File List
  • Globals
  • All
  • Functions
  • Variables
  • Typedefs
  • Defines

  • check_sendok_flag : socket.c
  • iinchip_source_port : socket.c
  • RXMEM_SIZE : w5300.c
  • SOCK_INT : w5300.c
  • TXMEM_SIZE : w5300.c
Generated on Fri Jan 2 12:20:01 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: include/iinchip_conf.h Source File

include/iinchip_conf.h

Go to the documentation of this file.
00001 #ifndef _IINCHIP_CONF_H_
00002 #define _IINCHIP_CONF_H_
00003
00041 #define __DEF_IINCHIP_DBG__
00042 #define __DEF_IINCHIP_INT__
00043 #define __DEF_IINCHIP_PPP__
00048 #define MAX_SOCK_NUM            8
00049
00050
00051 #define __DEF_IINCHIP_DIRECT_MODE__     1
00052 #define __DEF_IINCHIP_INDIRECT_MODE__   2
00064 #define __DEF_IINCHIP_ADDRESS_MODE__           __DEF_IINCHIP_DIRECT_MODE__
00065 //#define __DEF_IINCHIP_ADDRESS_MODE__         __DEF_IINCHIP_INDIRECT_MODE__
00066
00085 #define __DEF_IINCHIP_MAP_BASE__ 0x08000000
00086
00087 #if (__DEF_IINCHIP_ADDRESS_MODE__ == __DEF_IINCHIP_DIRECT_MODE__)
00088    #define COMMON_REG_BASE   __DEF_IINCHIP_MAP_BASE__
00089    #define SOCKET_REG_BASE   __DEF_IINCHIP_MAP_BASE__ + 0x0200
00090 #else
00091    #define COMMON_REG_BASE     0
00092    #define SOCKET_REG_BASE     0x0200
00093 #endif
00094
00095 #define SOCKET_REG_SIZE    0x40     // SOCKET Regsiter Count per Channel
00096
00097
00098
00099
00100 #define __DEF_C__                  0
00101 #define __DEF_MCU_DEP_INLINE_ASM__ 1
00102 #define __DEF_MCU_DEP_DMA__        2
00120 #define __DEF_IINCHIP_BUF_OP__      __DEF_C__
00121 //#define __DEF_IINCHIP_BUF_OP__    __DEF_MCU_DEP_INLINE_ASM__
00122 //#define __DEF_IINCHIP_BUF_OP__    __DEF_MCU_DEP_DMA__
00123
00124
00138 #define IINCHIP_CRITICAL_SECTION_ENTER() {}
00139
00155 #define IINCHIP_CRITICAL_SECTION_EXIT() {}
00156
00157
00158 #endif
Generated on Fri Jan 2 12:19:59 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: main.c Source File

main.c

Go to the documentation of this file.
00001
00034 #include "main.h"
00035 #include "xscale.h"
00036 #include "socket.h"
00037
00038
00039 LOADER_STATUS   status;           // for serial port
00040
00041 void InitXHyper255A(void);       // Intialize MCU
00042
00043 /* Definition of example code */
00044 void     loopback_tcps(SOCKET s, uint16 port, uint8* buf,uint16 mode);
00045 void     loopback_tcpc(SOCKET s, uint8* addr, uint16 port, uint8* buf,uint16 mode);
00046 void     loopback_udp(SOCKET s, uint16 port, uint8* buf, uint16 mode);
00047
00048
00055 void Main()
00056 {
00057    uint8 tx_mem_conf[8] = {8,8,8,8,8,8,8,8};          // for setting TMSR regsiter
00058    uint8 rx_mem_conf[8] = {8,8,8,8,8,8,8,8};          // for setting RMSR regsiter
00059
00060    uint8 * data_buf = (uint8 *) 0xA10E0000;         // buffer for loopack data
00061
00062    uint8 ip[4] = {192,168,111,200};                   // for setting SIP register
00063    uint8 gw[4] = {192,168,111,1};                     // for setting GAR register
00064    uint8 sn[4] = {255,255,255,0};                     // for setting SUBR register
00065    uint8 mac[6] = {0x00,0x08,0xDC,0x00,111,200};      // for setting SHAR register
00066
00067    uint8 serverip[4] = {192,168,111,78};              // "TCP SERVER" IP address for loopback_tcpc()
00068
00069    status.terminalSpeed = SERIAL_SPEED;
00070    status.downloadSpeed = SERIAL_DOWNLOAD_SPEED;
00071
00072    data_buf = (uint8*)0xA10F0000;
00073
00074    InitXHyper255A();                                  // initiate MCU
00075    SerialInit(status.terminalSpeed);                  // initiate serial port
00076
00077    /* initiate W5300 */
00078    iinchip_init();
00079
00080    /* allocate internal TX/RX Memory of W5300 */
00081    if(!sysinit(tx_mem_conf,rx_mem_conf))
00082    {
00083       printf("MEMORY CONFIG ERR.\r\n");
00084       while(1);
00085    }
00086
00087    //setMR(getMR()|MR_FS);                            // If Little-endian, set MR_FS.
00088
00089    setSHAR(mac);                                      // set source hardware address
00090
00091    #ifdef __DEF_IINCHIP_PPP__
00092       if(pppinit((uint8*)"test01", 6, (uint8*)"pppoe1000", 9)!=1)
00093       {
00094          printf("PPPoE fail.\r\n");
00095          while(1);
00096       }
00097       close(0);
00098    #else
00099       /* configure network information */
00100       setGAR(gw);                                     // set gateway IP address
00101       setSUBR(sn);                                    // set subnet mask address
00102       setSIPR(ip);                                    // set source IP address
00103    #endif
00104
00105    /* verify network information */
00106    getSHAR(mac);                                      // get source hardware address
00107    getGAR(gw);                                        // get gateway IP address
00108    getSUBR(sn);                                       // get subnet mask address
00109    getSIPR(ip);                                       // get source IP address
00110
00111    printf("SHAR : %02x:%02x:%02x:%02x:%02x:%02x\r\n",mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);
00112    printf("GWR  : %d.%d.%d.%d\r\n",gw[0],gw[1],gw[2],gw[3]);
00113    printf("SUBR : %d.%d.%d.%d\r\n",sn[0],sn[1],sn[2],sn[3]);
00114    printf("SIPR : %d.%d.%d.%d\r\n",ip[0],ip[1],ip[2],ip[3]);
00115
00116    while(1)
00117    {
00118       loopback_tcps(0,5000,data_buf,0);
00119       loopback_tcps(1,5000,data_buf,0);
00120       loopback_tcps(2,5000,data_buf,0);
00121       loopback_tcps(3,5000,data_buf,0);
00122       loopback_tcps(4,5000,data_buf,0);
00123       loopback_tcps(5,5000,data_buf,0);
00124       loopback_tcpc(6,serverip, 3000, data_buf,0);
00125       loopback_udp(7,3000,data_buf,0);
00126    }
00127
00128    #ifdef __DEF_IINCHIP_PPP__
00129    {
00130       uint8 ppp_mac[6];
00131       getPDHAR(ppp_mac);
00132       pppterm(ppp_mac, getPSIDR());
00133    }
00134    #endif
00135
00136    while(1);
00137 }
00138
00139
00140 void InitXHyper255A(void)
00141 {
00142    ADDR32(GPIO_BASE+GPDR2) |= GPDR2_VALUE; //~0x0;//((ADDR32(GPIO_BASE+GPDR2) & 0x0001FFFF) | GPDR2_VALUE);
00143    ADDR32(GPIO_BASE+GAFR2_L) |= GAFR2L_VALUE;
00144    ADDR32(MEM_CTL_BASE+MSC1) = 0x00008259;//0x000095F8;
00145 }
00146
00162 void     loopback_tcps(SOCKET s, uint16 port, uint8* buf, uint16 mode)
00163 {
00164    uint32 len;
00165
00166    switch(getSn_SSR(s))                // check SOCKET status
00167    {                                   // ------------
00168       case SOCK_ESTABLISHED:           // ESTABLISHED?
00169          if(getSn_IR(s) & Sn_IR_CON)   // check Sn_IR_CON bit
00170          {
00171             printf("%d : Connect OK\r\n",s);
00172             setSn_IR(s,Sn_IR_CON);     // clear Sn_IR_CON
00173          }
00174          if((len=getSn_RX_RSR(s)) > 0) // check the size of received data
00175          {
00176             len = recv(s,buf,len);     // recv
00177             if(len !=send(s,buf,len))  // send
00178             {
00179                printf("%d : Send Fail.len=%d\r\n",s,len);
00180             }
00181          }
00182          break;
00183                                        // ---------------
00184    case SOCK_CLOSE_WAIT:               // PASSIVE CLOSED
00185          disconnect(s);                // disconnect
00186          break;
00187                                        // --------------
00188    case SOCK_CLOSED:                   // CLOSED
00189       close(s);                        // close the SOCKET
00190       socket(s,Sn_MR_TCP,port,mode);   // open the SOCKET
00191       break;
00192                                        // ------------------------------
00193    case SOCK_INIT:                     // The SOCKET opened with TCP mode
00194       listen(s);                       // listen to any connection request from "TCP CLIENT"
00195       printf("%d : LOOPBACK_TCPS(%d) Started.\r\n",s,port);
00196       break;
00197    default:
00198       break;
00199    }
00200 }
00201
00218 void     loopback_tcpc(SOCKET s, uint8* addr, uint16 port, uint8* buf, uint16 mode)
00219 {
00220    uint32 len;
00221    static uint16 any_port = 1000;
00222
00223    switch(getSn_SSR(s))                   // check SOCKET status
00224    {                                      // ------------
00225       case SOCK_ESTABLISHED:              // ESTABLISHED?
00226          if(getSn_IR(s) & Sn_IR_CON)      // check Sn_IR_CON bit
00227          {
00228             printf("%d : Connect OK\r\n",s);
00229             setSn_IR(s,Sn_IR_CON);        // clear Sn_IR_CON
00230          }
00231          if((len=getSn_RX_RSR(s)) > 0)    // check the size of received data
00232          {
00233             len = recv(s,buf,len);        // recv
00234             if(len !=send(s,buf,len))     // send
00235             {
00236                printf("%d : Send Fail.len=%d\r\n",s,len);
00237             }
00238          }
00239          break;
00240                                           // ---------------
00241    case SOCK_CLOSE_WAIT:                  // PASSIVE CLOSED
00242          disconnect(s);                   // disconnect
00243          break;
00244                                           // --------------
00245    case SOCK_CLOSED:                      // CLOSED
00246       close(s);                           // close the SOCKET
00247       socket(s,Sn_MR_TCP,any_port++,mode);// open the SOCKET with TCP mode and any source port number
00248       break;
00249                                           // ------------------------------
00250    case SOCK_INIT:                        // The SOCKET opened with TCP mode
00251       connect(s, addr, port);             // Try to connect to "TCP SERVER"
00252       printf("%d : LOOPBACK_TCPC(%d.%d.%d.%d:%d) Started.\r\n",s,addr[0],addr[1],addr[2],addr[3],port);
00253       break;
00254    default:
00255       break;
00256    }
00257 }
00258
00274 void     loopback_udp(SOCKET s, uint16 port, uint8* buf, uint16 mode)
00275 {
00276    uint32 len;
00277    uint8 destip[4];
00278    uint16 destport;
00279
00280    switch(getSn_SSR(s))
00281    {
00282                                                          // -------------------------------
00283       case SOCK_UDP:                                     //
00284          if((len=getSn_RX_RSR(s)) > 0)                   // check the size of received data
00285          {
00286             len = recvfrom(s,buf,len,destip,&destport);  // receive data from a destination
00287             if(len !=sendto(s,buf,len,destip,destport))  // send the data to the destination
00288             {
00289                printf("%d : Sendto Fail.len=%d,",s,len);
00290                printf("%d.%d.%d.%d(%d)\r\n",destip[0],destip[1],destip[2],destip[3],destport);
00291             }
00292          }
00293          break;
00294                                                          // -----------------
00295       case SOCK_CLOSED:                                  // CLOSED
00296          close(s);                                       // close the SOCKET
00297          socket(s,Sn_MR_UDP,port,mode);                  // open the SOCKET with UDP mode
00298          break;
00299       default:
00300          break;
00301    }
00302 }
Generated on Fri Jan 2 12:19:59 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: Page Index

Related Pages

Here is a list of all related documentation pages:
  • Todo List
  • Waring List
  • Bug List
Generated on Fri Jan 2 12:19:59 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: socket.c Source File

socket.c

Go to the documentation of this file.
00001
00018 #include "socket.h"
00019 #include "lstring.h"
00020 #include "string.h"
00021
00028 uint16   iinchip_source_port;
00029
00035 uint8    check_sendok_flag[MAX_SOCK_NUM];
00036
00037
00038 uint8    socket(SOCKET s, uint8 protocol, uint16 port, uint16 flag)
00039 {
00040    IINCHIP_WRITE(Sn_MR(s),(uint16)(protocol | flag)); // set Sn_MR with protocol & flag
00041    if (port != 0) IINCHIP_WRITE(Sn_PORTR(s),port);
00042    else
00043    {
00044       iinchip_source_port++;     // if don't set the source port, set local_port number.
00045       IINCHIP_WRITE(Sn_PORTR(s),iinchip_source_port);
00046    }
00047    setSn_CR(s, Sn_CR_OPEN);      // open s-th SOCKET
00048
00049    check_sendok_flag[s] = 1;     // initialize the sendok flag.
00050
00051    #ifdef __DEF_IINCHIP_DBG__
00052       printf("%d : Sn_MR=0x%04x,Sn_PORTR=0x%04x(%d),Sn_SSR=%04x\r\n",s,IINCHIP_READ(Sn_MR(s)),IINCHIP_READ(Sn_PORTR(s)),IINCHIP_READ(Sn_PORTR(s)),getSn_SSR(s));
00053    #endif
00054    return 1;
00055 }
00056
00057 void     close(SOCKET s)
00058 {
00059    // M_08082008 : It is fixed the problem that Sn_SSR cannot be changed a undefined value to the defined value.
00060    //              Refer to Errata of W5300
00061    //Check if the transmit data is remained or not.
00062    if( ((getSn_MR(s)& 0x0F) == Sn_MR_TCP) && (getSn_TX_FSR(s) != getIINCHIP_TxMAX(s)) )
00063    {
00064       uint16 loop_cnt =0;
00065       while(getSn_TX_FSR(s) != getIINCHIP_TxMAX(s))
00066       {
00067          if(loop_cnt++ > 10)
00068          {
00069             uint8 destip[4];
00070             // M_11252008 : modify dest ip address
00071             //getSIPR(destip);
00072             destip[0] = 0;destip[1] = 0;destip[2] = 0;destip[3] = 1;
00073             socket(s,Sn_MR_UDP,0x3000,0);
00074             sendto(s,(uint8*)"x",1,destip,0x3000); // send the dummy data to an unknown destination(0.0.0.1).
00075             break; // M_11252008 : added break statement
00076          }
00077          wait_10ms(10);
00078       }
00079    };
00081    setSn_IR(s ,0x00FF);          // Clear the remained interrupt bits.
00082    setSn_CR(s ,Sn_CR_CLOSE);     // Close s-th SOCKET
00083 }
00084
00085
00086 uint8    connect(SOCKET s, uint8 * addr, uint16 port)
00087 {
00088    if
00089    (
00090       ((addr[0] == 0xFF) && (addr[1] == 0xFF) && (addr[2] == 0xFF) && (addr[3] == 0xFF)) ||
00091       ((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) ||
00092       (port == 0x00)
00093    )
00094    {
00095       #ifdef __DEF_IINCHIP_DBG__
00096          printf("%d : Fail[invalid ip,port]\r\n",s);
00097       #endif
00098       return 0;
00099    }
00100
00101    // set destination IP
00102    IINCHIP_WRITE(Sn_DIPR(s),((uint16)addr[0]<<8)+(uint16)addr[1]);
00103    IINCHIP_WRITE(Sn_DIPR2(s),((uint16)addr[2]<<8)+(uint16)addr[3]);
00104    // set destination port number
00105    IINCHIP_WRITE(Sn_DPORTR(s),port);
00106
00107    // Connect
00108    setSn_CR(s,Sn_CR_CONNECT);
00109
00110    return 1;
00111 }
00112
00113 void     disconnect(SOCKET s)
00114 {
00115    setSn_CR(s,Sn_CR_DISCON);     // Disconnect
00116 }
00117
00118 uint8    listen(SOCKET s)
00119 {
00120    if (getSn_SSR(s) != SOCK_INIT)
00121    {
00122       #ifdef __DEF_IINCHIP_DBG__
00123          printf("%d : SOCKET is not created!\r\n",s);
00124       #endif
00125       return 0;
00126    }
00127
00128    setSn_CR(s,Sn_CR_LISTEN);     // listen
00129
00130    return 1;
00131 }
00132
00133 uint32   send(SOCKET s, uint8 * buf, uint32 len)
00134 {
00135    uint8 status=0;
00136    uint32 ret=0;
00137    uint32 freesize=0;
00138    #ifdef __DEF_IINCHIP_DBG__
00139       uint32 loopcnt = 0;
00140
00141       printf("%d : send()\r\n",s);
00142    #endif
00143
00144    ret = len;
00145    if (len > getIINCHIP_TxMAX(s)) ret = getIINCHIP_TxMAX(s); // check size not to exceed MAX size.
00146
00147
00148
00149    /*
00150     * \note if you want to use non blocking function, <b>"do{}while(freesize < ret)"</b> code block
00151     * can be replaced with the below code. \n
00152     * \code
00153     *       while((freesize = getSn_TX_FSR(s))==0);
00154     *       ret = freesize;
00155     * \endcode
00156     */
00157    // -----------------------
00158    // NOTE : CODE BLOCK START
00159    do
00160    {
00161       freesize = getSn_TX_FSR(s);
00162       status = getSn_SSR(s);
00163       #ifdef __DEF_IINCHIP_DBG__
00164          printf("%d : freesize=%ld\r\n",s,freesize);
00165          if(loopcnt++ > 0x0010000)
00166          {
00167             printf("%d : freesize=%ld,status=%04x\r\n",s,freesize,status);
00168             printf("%d:Send Size=%08lx(%d)\r\n",s,ret,ret);
00169             printf("MR=%04x\r\n",*((vuint16*)MR));
00170             loopcnt = 0;
00171          }
00172       #endif
00173       if ((status != SOCK_ESTABLISHED) && (status != SOCK_CLOSE_WAIT)) return 0;
00174    } while (freesize < ret);
00175    // NOTE : CODE BLOCK END
00176    // ---------------------
00177
00178    wiz_write_buf(s,buf,ret);                 // copy data
00179
00180    #ifdef __DEF_IINCHIP_DBG__
00181       loopcnt=0;
00182    #endif
00183
00184    if(!check_sendok_flag[s])                 // if first send, skip.
00185    {
00186       while (!(getSn_IR(s) & Sn_IR_SENDOK))  // wait previous SEND command completion.
00187       {
00188       #ifdef __DEF_IINCHIP_DBG__
00189
00190          if(loopcnt++ > 0x010000)
00191          {
00192             printf("%d:Sn_SSR(%04x)\r\n",s,status);
00193             printf("%d:Send Size=%08lx(%d)\r\n",s,ret,ret);
00194             printf("MR=%04x\r\n",*((vuint16*)MR));
00195             loopcnt = 0;
00196          }
00197       #endif
00198          if (getSn_SSR(s) == SOCK_CLOSED)    // check timeout or abnormal closed.
00199          {
00200             #ifdef __DEF_IINCHIP_DBG__
00201                printf("%d : Send Fail. SOCK_CLOSED.\r\n",s);
00202             #endif
00203             return 0;
00204          }
00205       }
00206       setSn_IR(s, Sn_IR_SENDOK);             // clear Sn_IR_SENDOK
00207    }
00208    else check_sendok_flag[s] = 0;
00209
00210    // send
00211    setSn_TX_WRSR(s,ret);
00212    setSn_CR(s,Sn_CR_SEND);
00213
00214    return ret;
00215 }
00216
00217 uint32   recv(SOCKET s, uint8 * buf, uint32 len)
00218 {
00219    uint16 pack_size=0;
00220
00221    #ifdef __DEF_IINCHIP_DBG__
00222       printf("%d : recv()\r\n",s);
00223    #endif
00224
00225    if(IINCHIP_READ(Sn_MR(s)) & Sn_MR_ALIGN)
00226    {
00227       wiz_read_buf(s, buf, (uint32)len);
00228       setSn_CR(s,Sn_CR_RECV);
00229       return len;
00230    }
00231
00232
00233    wiz_read_buf(s,(uint8*)&pack_size,2);        // extract the PACKET-INFO(DATA packet length)
00234    if( (*(vint16*)MR) & MR_FS )
00235       pack_size = ((((pack_size << 8 ) & 0xFF00)) | ((pack_size >> 8)& 0x00FF));
00236
00237    #ifdef __DEF_IINCHIP_DBG__
00238       printf("%d:pack_size=%d\r\n",s,pack_size);
00239    #endif
00240
00241    wiz_read_buf(s, buf, (uint32)pack_size);     // copy data
00242
00243    setSn_CR(s,Sn_CR_RECV);                      // recv
00244
00245    /*
00246    * \warning  send a packet for updating window size. This code block must be only used when W5300 do only receiving data.
00247    */
00248    // ------------------------
00249    // WARNING CODE BLOCK START
00250
00251    // M_15052008 : Replace Sn_CR_SEND with Sn_CR_SEND_KEEP.
00252    //if(!(getSn_IR(s) & Sn_IR_SENDOK))
00253    //{
00254    //   setSn_TX_WRSR(s,0);                    // size = 0
00255    //   setSn_CR(s,Sn_CR_SEND);                // send
00256    //   while(!(getSn_IR(s) & Sn_IR_SENDOK));  // wait SEND command completion
00257    //   setSn_IR(s,Sn_IR_SENDOK);              // clear Sn_IR_SENDOK bit
00258    //}
00259
00260    // M_04072008 : Replace Sn_CR_SEND_KEEP with Sn_CR_SEND.
00261    //if(getSn_RX_RSR(s) == 0)                     // send the window-update packet when the window size is full
00262    //{
00263    //   uint8 keep_time = 0;
00264    //   if((keep_time=getSn_KPALVTR(s)) != 0x00) setSn_KPALVTR(s,0x00); // disables the auto-keep-alive-process
00265    //   setSn_CR(s,Sn_CR_SEND_KEEP);              // send a keep-alive packet by command
00266    //   setSn_KPALVTR(s,keep_time);               // restore the previous keep-alive-timer value
00267    //}
00268    if(getSn_RX_RSR(s) == 0)                     // check if the window size is full or not
00269    { /* Sn_RX_RSR can be compared with another value instead of ¡®0¡¯,
00270       according to the host performance of receiving data */
00271       setSn_TX_WRSR(s,1);                       // size : 1 byte dummy size
00272       IINCHIP_WRITE(Sn_TX_FIFOR(s),0x0000);     // write dummy data into tx memory
00273       setSn_CR(s,Sn_CR_SEND);                   // send
00274       while(!(getSn_IR(s) & Sn_IR_SENDOK));     // wait SEND command completion
00275       setSn_IR(s,Sn_IR_SENDOK);                 // clear Sn_IR_SENDOK bit
00276    }
00277
00278    // WARNING CODE BLOCK END
00279    // ----------------------
00280
00281    return (uint32)pack_size;
00282 }
00283
00284 uint32   sendto(SOCKET s, uint8 * buf, uint32 len, uint8 * addr, uint16 port)
00285 {
00286    uint8 status=0;
00287    uint8 isr=0;
00288    uint32 ret=0;
00289
00290    #ifdef __DEF_IINCHIP_DBG__
00291       printf("%d : sendto():%d.%d.%d.%d(%d), len=%d\r\n",s, addr[0], addr[1], addr[2], addr[3] , port, len);
00292    #endif
00293
00294    if
00295    (
00296       ((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) ||
00297       ((port == 0x00)) ||(len == 0)
00298    )
00299    {
00300       #ifdef __DEF_IINCHIP_DBG__
00301          printf("%d : Fail[%d.%d.%d.%d, %.d, %d]\r\n",s, addr[0], addr[1], addr[2], addr[3] , port, len);
00302       #endif
00303       return 0;
00304    }
00305
00306
00307    if (len > getIINCHIP_TxMAX(s)) ret = getIINCHIP_TxMAX(s); // check size not to exceed MAX size.
00308    else ret = len;
00309
00310    // set destination IP address
00311    IINCHIP_WRITE(Sn_DIPR(s),(((uint16)addr[0])<<8) + (uint16) addr[1]);
00312    IINCHIP_WRITE(Sn_DIPR2(s),(((uint16)addr[2])<<8) + (uint16) addr[3]);
00313    // set destination port number
00314    IINCHIP_WRITE(Sn_DPORTR(s),port);
00315
00316    wiz_write_buf(s, buf, ret);                              // copy data
00317    // send
00318    setSn_TX_WRSR(s,ret);
00319    setSn_CR(s, Sn_CR_SEND);
00320
00321    while (!((isr = getSn_IR(s)) & Sn_IR_SENDOK))            // wait SEND command completion
00322    {
00323       status = getSn_SSR(s);                                // warning ---------------------------------------
00324       if ((status == SOCK_CLOSED) || (isr & Sn_IR_TIMEOUT)) // Sn_IR_TIMEOUT causes the decrement of Sn_TX_FSR
00325       {                                                     // -----------------------------------------------
00326          #ifdef __DEF_IINCHIP_DBG__
00327             printf("%d: send fail.status=0x%02x,isr=%02x\r\n",status,isr);
00328          #endif
00329          setSn_IR(s,Sn_IR_TIMEOUT);
00330          return 0;
00331       }
00332    }
00333    setSn_IR(s, Sn_IR_SENDOK); // Clear Sn_IR_SENDOK
00334
00335    #ifdef __DEF_IINCHIP_DBG__
00336       printf("%d : send()end\r\n",s);
00337    #endif
00338
00339    return ret;
00340 }
00341
00342 uint32   recvfrom(SOCKET s, uint8 * buf, uint32 len, uint8 * addr, uint16  *port)
00343 {
00344    uint16 head[4];
00345    uint32 data_len=0;
00346    uint16 crc[2];
00347
00348    #ifdef __DEF_IINCHIP_DBG__
00349       printf("recvfrom()\r\n");
00350    #endif
00351
00352    if ( len > 0 )
00353    {
00354       switch (IINCHIP_READ(Sn_MR(s)) & 0x07)       // check the mode of s-th SOCKET
00355       {                                            // -----------------------------
00356          case Sn_MR_UDP :                          // UDP mode
00357             wiz_read_buf(s, (uint8*)head, 8);      // extract the PACKET-INFO
00358             // read peer's IP address, port number.
00359             if(*((vuint16*)MR) & MR_FS)            // check FIFO swap bit
00360             {
00361                head[0] = ((((head[0] << 8 ) & 0xFF00)) | ((head[0] >> 8)& 0x00FF));
00362                head[1] = ((((head[1] << 8 ) & 0xFF00)) | ((head[1] >> 8)& 0x00FF));
00363                head[2] = ((((head[2] << 8 ) & 0xFF00)) | ((head[2] >> 8)& 0x00FF));
00364                head[3] = ((((head[3] << 8 ) & 0xFF00)) | ((head[3] >> 8)& 0x00FF));
00365             }
00366             addr[0] = (uint8)(head[0] >> 8);       // destination IP address
00367             addr[1] = (uint8)head[0];
00368             addr[2] = (uint8)(head[1]>>8);
00369             addr[3] = (uint8)head[1];
00370             *port = head[2];                       // destination port number
00371             data_len = (uint32)head[3];            // DATA packet length
00372
00373             #ifdef __DEF_IINCHIP_DBG__
00374                printf("UDP msg arrived:%d(0x%04x)\r\n",data_len,data_len);
00375                printf("source Port : %d\r\n", *port);
00376                printf("source IP : %d.%d.%d.%d\r\n", addr[0], addr[1], addr[2], addr[3]);
00377             #endif
00378
00379             wiz_read_buf(s, buf, data_len);        // data copy.
00380             break;
00381                                                    // -----------------------
00382          case Sn_MR_IPRAW :                        // IPRAW mode
00383             wiz_read_buf(s, (uint8*)head, 6);      // extract the PACKET-INFO
00384             if(*((vuint16*)MR) & MR_FS)            // check FIFO swap bit
00385             {
00386                head[0] = ((((head[0] << 8 ) & 0xFF00)) | ((head[0] >> 8)& 0x00FF));
00387                head[1] = ((((head[1] << 8 ) & 0xFF00)) | ((head[1] >> 8)& 0x00FF));
00388                head[2] = ((((head[2] << 8 ) & 0xFF00)) | ((head[2] >> 8)& 0x00FF));
00389             }
00390             addr[0] = (uint8)(head[0] >> 8);       // destination IP address
00391             addr[1] = (uint8)head[0];
00392             addr[2] = (uint8)(head[1]>>8);
00393             addr[3] = (uint8)head[1];
00394             data_len = (uint32)head[2];            // DATA packet length
00395
00396             #ifdef __DEF_IINCHIP_DBG__
00397                printf("IP RAW msg arrived\r\n");
00398                printf("source IP : %d.%d.%d.%d\r\n", addr[0], addr[1], addr[2], addr[3]);
00399             #endif
00400
00401             wiz_read_buf(s, buf, data_len);        // data copy.
00402             break;
00403                                                    // -----------------------
00404          case Sn_MR_MACRAW :                       // MACRAW mode
00405             wiz_read_buf(s,(uint8*)head,2);        // extract the PACKET-INFO
00406             if(*((vuint16*)MR) & MR_FS)            // check FIFO swap bit
00407                head[0] = ((((head[0] << 8 ) & 0xFF00)) | ((head[0] >> 8)& 0x00FF));
00408             data_len = (uint32)head[0];            // DATA packet length
00409             wiz_read_buf(s, buf, data_len);        // data copy.
00410             wiz_read_buf(s,(uint8*)crc, 4);        // extract CRC data and ignore it.
00411
00412             break;
00413          default :
00414             break;
00415       }
00416       setSn_CR(s,Sn_CR_RECV);                      // recv
00417    }
00418    #ifdef __DEF_IINCHIP_DBG__
00419       printf("recvfrom() end ..\r\n");
00420    #endif
00421
00422    return data_len;
00423 }
Generated on Fri Jan 2 12:19:59 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: include/socket.h Source File

include/socket.h

Go to the documentation of this file.
00001 #ifndef _SOCKET_H_
00002 #define _SOCKET_H_
00003
00025 #include "types.h"
00026 #include "w5300.h"
00027
00078 /**********************************
00079  * define function of SOCKET APIs *
00080  **********************************/
00081
00094 uint8    socket(SOCKET s, uint8 protocol, uint16 port, uint16 flag);
00095
00106 void     close(SOCKET s);                                                           // Close socket
00107
00118 uint8    connect(SOCKET s, uint8 * addr, uint16 port);
00119
00127 void     disconnect(SOCKET s);
00128
00137 uint8    listen(SOCKET s);
00138
00159 uint32   send(SOCKET s, uint8 * buf, uint32 len);
00160
00161
00211 uint32   recv(SOCKET s, uint8 * buf, uint32 len);
00212
00241 uint32   sendto(SOCKET s, uint8 * buf, uint32 len, uint8 * addr, uint16 port);
00242
00349 uint32   recvfrom(SOCKET s, uint8 * buf, uint32 len, uint8 * addr, uint16  *port);
00350
00351 #endif
00352 /* _SOCKET_H_ */
00353
00354
Generated on Fri Jan 2 12:19:59 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: include/types.h Source File

include/types.h

Go to the documentation of this file.
00001 #ifndef _TYPE_H_
00002 #define _TYPE_H_
00003
00014 typedef char int8;
00016 typedef volatile char vint8;
00018 typedef unsigned char uint8;
00020 typedef volatile unsigned char vuint8;
00022 typedef short int16;
00024 typedef volatile short vint16;
00026 typedef unsigned short uint16;
00028 typedef volatile unsigned short vuint16;
00030 typedef long int32;
00032 typedef volatile long vint32;
00034 typedef unsigned long uint32;
00036 typedef volatile unsigned long vuint32;
00047 typedef uint8 SOCKET;
00048
00049
00050 typedef unsigned long   ulong;
00051 typedef unsigned short  ushort;
00052 typedef unsigned char   uchar;
00053 typedef unsigned int    uint;
00054
00055 #ifndef __cplusplus
00056 typedef int                             bool;
00057 #define true                    1
00058 #define false                   0
00059 #endif
00060
00061 // print in hex value.
00062 // type= 8 : print in format "ff".
00063 // type=16 : print in format "ffff".
00064 // type=32 : print in format "ffffffff".
00065 typedef enum {
00066         VAR_LONG=32,
00067         VAR_SHORT=16,
00068         VAR_CHAR=8
00069 } VAR_TYPE;
00070
00071 #ifndef NULL
00072 #define NULL (void *)0
00073 #endif
00074
00075 #endif          /* _TYPE_H_ */
Generated on Fri Jan 2 12:19:59 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: w5300.c Source File

w5300.c

Go to the documentation of this file.
00001
00019 #include "w5300.h"
00020 #include "lstring.h"
00021
00022 #include "md5.h"
00023
00030 uint32 TXMEM_SIZE[MAX_SOCK_NUM];
00031
00038 uint32 RXMEM_SIZE[MAX_SOCK_NUM];
00039
00045 uint8 SOCK_INT[MAX_SOCK_NUM];
00046
00047
00048 /***********************
00049  * Basic I/O  Function *
00050  ***********************/
00051
00052 uint16   IINCHIP_READ(uint32 addr)
00053 {
00054  #if (__DEF_IINCHIP_ADDRESS_MODE__ == __DEF_IINCHIP_DIRECT_MODE__)
00055       return (*((vuint16*)addr));
00056  #else
00057       vuint16  data;
00058       IINCHIP_CRITICAL_SECTION_ENTER();
00059       *((vuint16*)IDM_AR) = (uint16)addr;
00060       data = *((vuint16*)IDM_DR);
00061       IINCHIP_CRITICAL_SECTION_EXIT();
00062       return data;
00063  #endif
00064 }
00065 void     IINCHIP_WRITE(uint32 addr,uint16 data)
00066 {
00067 #if (__DEF_IINCHIP_ADDRESS_MODE__ == __DEF_IINCHIP_DIRECT_MODE__)
00068       (*((vuint16*)addr)) = data;
00069 #else
00070       IINCHIP_CRITICAL_SECTION_ENTER();
00071       *((vuint16*)IDM_AR) = addr;
00072       *((vuint16*)IDM_DR) = data;
00073       IINCHIP_CRITICAL_SECTION_EXIT();
00074 #endif
00075 }
00076
00077 uint16   getMR(void)
00078 {
00079    return *((vint16*)MR);
00080 }
00081 void     setMR(uint16 val)
00082 {
00083    *((vint16*)MR) = val;
00084 }
00085
00086
00087 /***********************************
00088  * COMMON Register Access Function *
00089  ***********************************/
00090
00091 /* Interrupt */
00092
00093 uint16   getIR(void)
00094 {
00095    return IINCHIP_READ(IR);
00096 }
00097 void     setIR(uint16 val)
00098 {
00099    IINCHIP_WRITE(IR, val);
00100 }
00101
00102 uint16   getIMR(void)
00103 {
00104    return IINCHIP_READ(IMR);
00105 }
00106 void     setIMR(uint16 mask)
00107 {
00108    IINCHIP_WRITE(IMR, mask);
00109 }
00110
00111
00112 /* Network Information */
00113
00114 void     getSHAR(uint8 * addr)
00115 {
00116    addr[0] = (uint8)(IINCHIP_READ(SHAR)>>8);
00117    addr[1] = (uint8)IINCHIP_READ(SHAR);
00118    addr[2] = (uint8)(IINCHIP_READ(SHAR2)>>8);
00119    addr[3] = (uint8)IINCHIP_READ(SHAR2);
00120    addr[4] = (uint8)(IINCHIP_READ(SHAR4)>>8);
00121    addr[5] = (uint8)IINCHIP_READ(SHAR4);
00122 }
00123 void     setSHAR(uint8 * addr)
00124 {
00125    IINCHIP_WRITE(SHAR,(((uint16)addr[0])<<8)+addr[1]);
00126    IINCHIP_WRITE(SHAR2,((uint16)addr[2]<<8)+addr[3]);
00127    IINCHIP_WRITE(SHAR4,((uint16)addr[4]<<8)+addr[5]);
00128 }
00129
00130 void     getGAR(uint8 * addr)
00131 {
00132         addr[0] = (uint8)(IINCHIP_READ(GAR)>>8);
00133         addr[1] = (uint8)IINCHIP_READ(GAR);
00134         addr[2] = (uint8)(IINCHIP_READ(GAR2)>>8);
00135         addr[3] = (uint8)IINCHIP_READ(GAR2);
00136 }
00137 void     setGAR(uint8 * addr)
00138 {
00139         IINCHIP_WRITE(GAR, ((uint16)addr[0]<<8)+(uint16)addr[1]);
00140         IINCHIP_WRITE(GAR2,((uint16)addr[2]<<8)+(uint16)addr[3]);
00141 }
00142
00143 void     getSUBR(uint8 * addr)
00144 {
00145         addr[0] = (uint8)(IINCHIP_READ(SUBR)>>8);
00146         addr[1] = (uint8)IINCHIP_READ(SUBR);
00147         addr[2] = (uint8)(IINCHIP_READ(SUBR2)>>8);
00148         addr[3] = (uint8)IINCHIP_READ(SUBR2);
00149 }
00150 void     setSUBR(uint8 * addr)
00151 {
00152         IINCHIP_WRITE(SUBR, ((uint16)addr[0]<<8)+(uint16)addr[1]);
00153         IINCHIP_WRITE(SUBR2,((uint16)addr[2]<<8)+(uint16)addr[3]);
00154 }
00155
00156 void     getSIPR(uint8 * addr)
00157 {
00158         addr[0] = (uint8)(IINCHIP_READ(SIPR)>>8);
00159         addr[1] = (uint8)IINCHIP_READ(SIPR);
00160         addr[2] = (uint8)(IINCHIP_READ(SIPR2)>>8);
00161         addr[3] = (uint8)IINCHIP_READ(SIPR2);
00162 }
00163 void     setSIPR(uint8 * addr)
00164 {
00165         IINCHIP_WRITE(SIPR,((uint16)addr[0]<<8)+(uint16)addr[1]);
00166         IINCHIP_WRITE(SIPR2,((uint16)addr[2]<<8)+(uint16)addr[3]);
00167 }
00168
00169
00170 /* Retransmittion */
00171
00172 uint16   getRTR(void)
00173 {
00174    return IINCHIP_READ(RTR);
00175 }
00176 void     setRTR(uint16 timeout)
00177 {
00178         IINCHIP_WRITE(RTR,timeout);
00179 }
00180
00181 uint8    getRCR(void)
00182 {
00183    return (uint8)IINCHIP_READ(RCR);
00184 }
00185 void     setRCR(uint8 retry)
00186 {
00187    IINCHIP_WRITE(RCR,retry);
00188 }
00189
00190 /* PPPoE */
00191 uint16   getPATR(void)
00192 {
00193    return IINCHIP_READ(PATR);
00194 }
00195
00196 uint8    getPTIMER(void)
00197 {
00198    return (uint8)IINCHIP_READ(PTIMER);
00199 }
00200 void     setPTIMER(uint8 time)
00201 {
00202    IINCHIP_WRITE(PTIMER,time);
00203 }
00204
00205 uint8    getPMAGICR(void)
00206 {
00207    return (uint8)IINCHIP_READ(PMAGICR);
00208 }
00209 void     setPMAGICR(uint8 magic)
00210 {
00211    IINCHIP_WRITE(PMAGICR,magic);
00212 }
00213
00214 uint16   getPSIDR(void)
00215 {
00216    return IINCHIP_READ(PSIDR);
00217 }
00218
00219 void     getPDHAR(uint8* addr)
00220 {
00221    addr[0] = (uint8)(IINCHIP_READ(PDHAR) >> 8);
00222    addr[1] = (uint8)IINCHIP_READ(PDHAR);
00223    addr[2] = (uint8)(IINCHIP_READ(PDHAR2) >> 8);
00224    addr[3] = (uint8)IINCHIP_READ(PDHAR2);
00225    addr[4] = (uint8)(IINCHIP_READ(PDHAR4) >> 8);
00226    addr[5] = (uint8)IINCHIP_READ(PDHAR4);
00227 }
00228
00229
00230 /* ICMP packets */
00231
00232 void     getUIPR(uint8* addr)
00233 {
00234    addr[0] = (uint8)(IINCHIP_READ(UIPR) >> 8);
00235    addr[1] = (uint8)IINCHIP_READ(UIPR);
00236    addr[2] = (uint8)(IINCHIP_READ(UIPR2) >> 8);
00237    addr[3] = (uint8)IINCHIP_READ(UIPR2);
00238 }
00239
00240 uint16   getUPORTR(void)
00241 {
00242    return IINCHIP_READ(UPORTR);
00243 }
00244
00245 uint16   getFMTUR(void)
00246 {
00247    return IINCHIP_READ(FMTUR);
00248 }
00249
00250
00251 /* PIN "BRYDn" */
00252
00253 uint8    getPn_BRDYR(uint8 p)
00254 {
00255    return (uint8)IINCHIP_READ(Pn_BRDYR(p));
00256 }
00257 void     setPn_BRDYR(uint8 p, uint8 cfg)
00258 {
00259    IINCHIP_WRITE(Pn_BRDYR(p),cfg);
00260 }
00261
00262
00263 uint16   getPn_BDPTHR(uint8 p)
00264 {
00265    return IINCHIP_READ(Pn_BDPTHR(p));
00266 }
00267 void     setPn_BDPTHR(uint8 p, uint16 depth)
00268 {
00269    IINCHIP_WRITE(Pn_BDPTHR(p),depth);
00270 }
00271
00272
00273 /* IINCHIP ID */
00274 uint16   getIDR(void)
00275 {
00276    return IINCHIP_READ(IDR);
00277 }
00278
00279
00280 /***********************************
00281  * SOCKET Register Access Function *
00282  ***********************************/
00283
00284 /* SOCKET control */
00285
00286 uint16   getSn_MR(SOCKET s)
00287 {
00288    return IINCHIP_READ(Sn_MR(s));
00289 }
00290 void     setSn_MR(SOCKET s, uint16 mode)
00291 {
00292    IINCHIP_WRITE(Sn_MR(s),mode);
00293 }
00294
00295 uint8    getSn_CR(SOCKET s)
00296 {
00297    return IINCHIP_READ(Sn_CR(s));
00298 }
00299 void     setSn_CR(SOCKET s, uint16 com)
00300 {
00301    IINCHIP_WRITE(Sn_CR(s),com);
00302    while(IINCHIP_READ(Sn_CR(s))); // wait until Sn_CR is cleared.
00303 }
00304
00305 uint8    getSn_IMR(SOCKET s)
00306 {
00307    return (uint8)IINCHIP_READ(Sn_IMR(s));
00308 }
00309 void     setSn_IMR(SOCKET s, uint8 mask)
00310 {
00311    IINCHIP_WRITE(Sn_IMR(s),mask);
00312 }
00313
00314 uint8    getSn_IR(SOCKET s)
00315 {
00316    #ifdef __DEF_IINCHIP_INT__    // In case of using ISR routine of iinchip
00317       return SOCK_INT[s];
00318    #else                         // In case of processing directly
00319       return (uint8)IINCHIP_READ(Sn_IR(s));
00320    #endif
00321 }
00322 void     setSn_IR(SOCKET s, uint8 ir)
00323 {
00324    #ifdef __DEF_IINCHIP_INT__    // In case of using ISR routine of iinchip
00325       SOCK_INT[s] = SOCK_INT[s] & ~(ir);
00326    #else                         // In case of processing directly
00327       IINCHIP_WRITE(Sn_IR(s),ir);
00328    #endif
00329 }
00330
00331
00332 /* SOCKET information */
00333
00334 uint8    getSn_SSR(SOCKET s)
00335 {
00336    uint8 ssr, ssr1;
00337    ssr = (uint8)IINCHIP_READ(Sn_SSR(s));     // first read
00338
00339    while(1)
00340    {
00341       ssr1 = (uint8)IINCHIP_READ(Sn_SSR(s)); // second read
00342       if(ssr == ssr1) break;                 // if first == sencond, Sn_SSR value is valid.
00343       ssr = ssr1;                            // if first <> second, save second value into first.
00344    }
00345    return ssr;
00346 }
00347
00348 void     getSn_DHAR(SOCKET s, uint8* addr)
00349 {
00350    addr[0] = (uint8)(IINCHIP_READ(Sn_DHAR(s))>>8);
00351    addr[1] = (uint8)IINCHIP_READ(Sn_DHAR(s));
00352    addr[2] = (uint8)(IINCHIP_READ(Sn_DHAR2(s))>>8);
00353    addr[3] = (uint8)IINCHIP_READ(Sn_DHAR2(s));
00354    addr[4] = (uint8)(IINCHIP_READ(Sn_DHAR4(s))>>8);
00355    addr[5] = (uint8)IINCHIP_READ(Sn_DHAR4(s));
00356 }
00357
00358 void     setSn_DHAR(SOCKET s, uint8* addr)
00359 {
00360    IINCHIP_WRITE(Sn_DHAR(s),  ((uint16)(addr[0]<<8)) + addr[1]);
00361    IINCHIP_WRITE(Sn_DHAR2(s), ((uint16)(addr[2]<<8)) + addr[3]);
00362    IINCHIP_WRITE(Sn_DHAR4(s), ((uint16)(addr[4]<<8)) + addr[5]);
00363 }
00364
00365 // M_15052008 : Delete this function
00366 //uint16   getSn_DPORTR(SOCKET s)
00367 //{
00368 //   return IINCHIP_READ(Sn_DPORTR(s));
00369 //}
00370
00371
00372 void     setSn_DPORTR(SOCKET s, uint16 port)
00373 {
00374    IINCHIP_WRITE(Sn_DPORTR(s),port);
00375 }
00376
00377 void     getSn_DIPR(SOCKET s, uint8* addr)
00378 {
00379    addr[0] = (uint8)(IINCHIP_READ(Sn_DIPR(s))>>8);
00380    addr[1] = (uint8)IINCHIP_READ(Sn_DIPR(s));
00381    addr[2] = (uint8)(IINCHIP_READ(Sn_DIPR2(s))>>8);
00382 // M_15052008 : Replace Sn_DHAR2 with Sn_DIPR2.
00383 // addr[3] = (uint8)IINCHIP_READ(Sn_DHAR2(s));
00384    addr[3] = (uint8)IINCHIP_READ(Sn_DIPR2(s));
00385 }
00386 void     setSn_DIPR(SOCKET s, uint8* addr)
00387 {
00388    IINCHIP_WRITE(Sn_DIPR(s),  ((uint16)(addr[0]<<8)) + addr[1]);
00389    IINCHIP_WRITE(Sn_DIPR2(s), ((uint16)(addr[2]<<8)) + addr[3]);
00390 }
00391
00392 uint16   getSn_MSSR(SOCKET s)
00393 {
00394    return IINCHIP_READ(Sn_MSSR(s));
00395 }
00396
00397 void     setSn_MSSR(SOCKET s, uint16 mss)
00398 {
00399    IINCHIP_WRITE(Sn_MSSR(s),mss);
00400 }
00401
00402
00403 /* SOCKET communication */
00404
00405 uint8    getSn_KPALVTR(SOCKET s)
00406 {
00407    return (uint8)(IINCHIP_READ(Sn_KPALVTR(s)) >> 8);
00408 }
00409
00410 void     setSn_KPALVTR(SOCKET s, uint8 time)
00411 {
00412    uint16 keepalive=0;
00413    keepalive = (IINCHIP_READ(Sn_KPALVTR(s)) & 0x00FF) + ((uint16)time<<8);
00414    IINCHIP_WRITE(Sn_KPALVTR(s),keepalive);
00415 }
00416
00417 uint32   getSn_TX_WRSR(SOCKET s)
00418 {
00419    uint32 tx_write_size=0;
00420    tx_write_size = IINCHIP_READ(Sn_TX_WRSR(s));
00421    tx_write_size = (tx_write_size << 16) + IINCHIP_READ(Sn_TX_WRSR2(s));
00422    return tx_write_size;
00423 }
00424 void     setSn_TX_WRSR(SOCKET s, uint32 size)
00425 {
00426    IINCHIP_WRITE(Sn_TX_WRSR(s), (uint16)(size >> 16));
00427    IINCHIP_WRITE(Sn_TX_WRSR2(s), (uint16)size);
00428 }
00429
00430 uint32   getSn_TX_FSR(SOCKET s)
00431 {
00432    uint32 free_tx_size=0;
00433    uint32 free_tx_size1=0;
00434    while(1)
00435    {
00436       free_tx_size = IINCHIP_READ(Sn_TX_FSR(s));                           // read
00437       free_tx_size = (free_tx_size << 16) + IINCHIP_READ(Sn_TX_FSR2(s));
00438       if(free_tx_size == free_tx_size1) break;                             // if first == sencond, Sn_TX_FSR value is valid.
00439       free_tx_size1 = free_tx_size;                                        // save second value into first
00440    }
00441    return free_tx_size;
00442 }
00443
00444 uint32   getSn_RX_RSR(SOCKET s)
00445 {
00446    uint32 received_rx_size=0;
00447    uint32 received_rx_size1=1;
00448    while(1)
00449    {
00450       received_rx_size = IINCHIP_READ(Sn_RX_RSR(s));
00451       received_rx_size = (received_rx_size << 16) + IINCHIP_READ(Sn_RX_RSR2(s)); // read
00452       if(received_rx_size == received_rx_size1) break;
00453       received_rx_size1 = received_rx_size;                                      // if first == sencond, Sn_RX_RSR value is valid.
00454    }                                                                             // save second value into first
00455    return received_rx_size;
00456 }
00457
00458
00459 void     setSn_TX_FIFOR(SOCKET s, uint16 data)
00460 {
00461    IINCHIP_WRITE(Sn_TX_FIFOR(s),data);
00462 }
00463
00464 uint16   getSn_RX_FIFOR(SOCKET s)
00465 {
00466    return IINCHIP_READ(Sn_RX_FIFOR(s));
00467 }
00468
00469
00470 /* IP header field */
00471
00472 uint8    getSn_PROTOR(SOCKET s)
00473 {
00474    return (uint8)IINCHIP_READ(Sn_PROTOR(s));
00475 }
00476 void     setSn_PROTOR(SOCKET s, uint8 pronum)
00477 {
00478    uint16 protocolnum;
00479    protocolnum = IINCHIP_READ(Sn_PROTOR(s)) & 0xFF00 + pronum;
00480    IINCHIP_WRITE(Sn_PROTOR(s),protocolnum);
00481 }
00482
00483 uint8    getSn_TOSR(SOCKET s)
00484 {
00485    return (uint8)IINCHIP_READ(Sn_TOSR(s));
00486 }
00487 void     setSn_TOSR(SOCKET s, uint8 tos)
00488 {
00489    IINCHIP_WRITE(Sn_TOSR(s),tos);
00490 }
00491
00492 uint8    getSn_TTLR(SOCKET s)
00493 {
00494    return (uint8)IINCHIP_READ(Sn_TTLR(s));
00495 }
00496 void     setSn_TTLR(SOCKET s, uint8 ttl)
00497 {
00498    IINCHIP_WRITE(Sn_TTLR(s),ttl);
00499 }
00500
00501 uint8    getSn_FRAGR(SOCKET s)
00502 {
00503    return (uint8)IINCHIP_READ(Sn_FRAGR(s));
00504 }
00505
00506 void     setSn_FRAGR(SOCKET s, uint8 frag)
00507 {
00508    IINCHIP_WRITE(Sn_FRAGR(s),frag);
00509 }
00510
00511
00512 /*******
00513  * ETC *
00514  *******/
00515
00516 /* Initialization & Interrupt request routine */
00517
00518 void     iinchip_init(void)
00519 {
00520    *((uint16*)MR) = MR_RST;
00521    wait_10ms(20);
00522    #if (__DEF_IINCHIP_ADDRESS_MODE__ == __DEF_IINCHIP_INDIRECT_MODE__)
00523       *((vint16*)MR) |= MR_IND;
00524       #ifdef __DEF_IINCHIP_DBG__
00525               printf("MR value is %04x\r\n",*((vuint16*)MR));
00526       #endif
00527    #endif
00528 }
00529
00530 //This statement is commented for using 'Doxygen'.
00531 //#ifdef __DEF_IINCHIP_INT__
00536 void     iinchip_irq(void)
00537 {
00538    uint16 int_val;
00539    uint16 idx;
00540    IINCHIP_CRITICAL_SECTION_ENTER();
00541    // M_01052008 : replaced '==' with '='
00542    //while(int_val == IINCHIP_READ(IR))  // process all interrupt
00543    while((int_val = IINCHIP_READ(IR)))  // process all interrupt
00544    {
00545       for(idx = 0 ; idx < MAX_SOCK_NUM ; idx++)
00546       {
00547          if (int_val & IR_SnINT(idx))  // check the SOCKETn interrupt
00548          {
00549             SOCK_INT[idx] |= (uint8)IINCHIP_READ(Sn_IR(idx)); // Save the interrupt stauts to SOCK_INT[idx]
00550             IINCHIP_WRITE(Sn_IR(idx),(uint16)SOCK_INT[idx]);  // Clear the interrupt status bit of SOCKETn
00551          }
00552       }
00553
00554       if (int_val & (IR_IPCF << 8))    // check the IP conflict interrupt
00555       {
00556          printf("IP conflict : %04x\r\n", int_val);
00557       }
00558       if (int_val & (IR_DPUR << 8))    // check the unreachable destination interrupt
00559       {
00560          printf("INT Port Unreachable : %04x\r\n", int_val);
00561          printf("UIPR : %d.%d.%d.%d\r\n", (uint8)(IINCHIP_READ(UIPR)>>8),
00562                                           (uint8)IINCHIP_READ(UIPR),
00563                                           (uint8)(IINCHIP_READ(UIPR2)>>8),
00564                                           (uint8)IINCHIP_READ(UIPR2));
00565          printf("UPORTR : %04x\r\n", IINCHIP_READ(UPORTR));
00566       }
00567       IINCHIP_WRITE(IR, int_val & 0xFF00);
00568    }
00569    IINCHIP_CRITICAL_SECTION_EXIT();
00570 }
00571 //This statement is commented for using 'Doxygen'.
00572 //#endif
00573
00574
00575 /* Internal memory operation */
00576
00577 uint8    sysinit(uint8* tx_size, uint8* rx_size)
00578 {
00579    uint16 i;
00580    uint16 ssum=0,rsum=0;
00581    uint mem_cfg = 0;
00582
00583    for(i=0; i < MAX_SOCK_NUM; i++)
00584    {
00585       if(tx_size[i] > 64)
00586       {
00587       #ifdef __DEF_IINCHIP_DBG__
00588          printf("Illegal Channel(%d) TX Memory Size.\r\n",i);
00589       #endif
00590          return 0;
00591       }
00592       if(rx_size[i] > 64)
00593       {
00594       #ifdef __DEF_IINCHIP_DBG__
00595          printf("Illegal Channel(%d) RX Memory Size.\r\n",i);
00596       #endif
00597          return 0;
00598       }
00599       ssum += (uint16)tx_size[i];
00600       rsum += (uint16)rx_size[i];
00601       TXMEM_SIZE[i] = ((uint32)tx_size[i]) << 10;
00602       RXMEM_SIZE[i] = ((uint32)rx_size[i]) << 10;
00603    }
00604    if( (ssum % 8) || ((ssum + rsum) != 128) )
00605    {
00606    #ifdef __DEF_IINCHIP_DBG__
00607       printf("Illegal Memory Allocation\r\n");
00608    #endif
00609       return 0;
00610    }
00611
00612    IINCHIP_WRITE(TMS01R,((uint16)tx_size[0] << 8) + (uint16)tx_size[1]);
00613    IINCHIP_WRITE(TMS23R,((uint16)tx_size[2] << 8) + (uint16)tx_size[3]);
00614    IINCHIP_WRITE(TMS45R,((uint16)tx_size[4] << 8) + (uint16)tx_size[5]);
00615    IINCHIP_WRITE(TMS67R,((uint16)tx_size[6] << 8) + (uint16)tx_size[7]);
00616
00617    IINCHIP_WRITE(RMS01R,((uint16)rx_size[0] << 8) + (uint16)rx_size[1]);
00618    IINCHIP_WRITE(RMS23R,((uint16)rx_size[2] << 8) + (uint16)rx_size[3]);
00619    IINCHIP_WRITE(RMS45R,((uint16)rx_size[4] << 8) + (uint16)rx_size[5]);
00620    IINCHIP_WRITE(RMS67R,((uint16)rx_size[6] << 8) + (uint16)rx_size[7]);
00621
00622    for(i=0; i <ssum/8 ; i++)
00623    {
00624       mem_cfg <<= 1;
00625       mem_cfg |= 1;
00626    }
00627
00628    IINCHIP_WRITE(MTYPER,mem_cfg);
00629
00630    #ifdef __DEF_IINCHIP_DBG__
00631       printf("Total TX Memory Size = %dKB\r\n",ssum);
00632       printf("Total RX Memory Size = %dKB\r\n",rsum);
00633       printf("Ch : TX SIZE : RECV SIZE\r\n");
00634       printf("%02d : %07dKB : %07dKB \r\n", 0, (uint8)(IINCHIP_READ(TMS01R)>>8),(uint8)(IINCHIP_READ(RMS01R)>>8));
00635       printf("%02d : %07dKB : %07dKB \r\n", 1, (uint8)IINCHIP_READ(TMS01R),(uint8)IINCHIP_READ(RMS01R));
00636       printf("%02d : %07dKB : %07dKB \r\n", 2, (uint8)(IINCHIP_READ(TMS23R)>>8),(uint8)(IINCHIP_READ(RMS23R)>>8));
00637       printf("%02d : %07dKB : %07dKB \r\n", 3, (uint8)IINCHIP_READ(TMS23R),(uint8)IINCHIP_READ(RMS23R));
00638       printf("%02d : %07dKB : %07dKB \r\n", 4, (uint8)(IINCHIP_READ(TMS45R)>>8),(uint8)(IINCHIP_READ(RMS45R)>>8));
00639       printf("%02d : %07dKB : %07dKB \r\n", 5, (uint8)IINCHIP_READ(TMS45R),(uint8)IINCHIP_READ(RMS45R));
00640       printf("%02d : %07dKB : %07dKB \r\n", 6, (uint8)(IINCHIP_READ(TMS67R)>>8),(uint8)(IINCHIP_READ(RMS67R)>>8));
00641       printf("%02d : %07dKB : %07dKB \r\n", 7, (uint8)IINCHIP_READ(TMS67R),(uint8)IINCHIP_READ(RMS67R));
00642       printf("\r\nMTYPER=%04x\r\n",IINCHIP_READ(MTYPER));
00643    #endif
00644
00645    return 1;
00646 }
00647
00648 uint32   wiz_write_buf(SOCKET s,uint8* buf,uint32 len)
00649 {
00650 #if (__DEF_IINCHIP_ADDRESS_MODE__ == __DEF_IINCHIP_DIRECT_MODE__)
00651    #if (__DEF_IINCHIP_BUF_OP__ == __DEF_C__)
00652       uint32 idx=0;
00653       // M_08082008
00654       IINCHIP_CRITICAL_SECTION_ENTER();
00655       for (idx = 0; idx < len; idx+=2)
00656          IINCHIP_WRITE(Sn_TX_FIFOR(s),*((uint16*)(buf+idx)));
00657       // M_08082008
00658       IINCHIP_CRITICAL_SECTION_EXIT();
00659    #elif (__DEF_IINCHIP_BUF_OP__ == __DEF_MCU_DEP_INLINE_ASM__)
00660       register uint16 data;
00661       register uint16 loop;
00662       loop = len;
00663       // M_08082008
00664       IINCHIP_CRITICAL_SECTION_ENTER();
00665       __asm
00666       {
00667       fifo_write_loop:
00668         // ARM version
00669         LDRH    data, [buf], #2
00670         STRH    data, [Sn_TX_FIFOR(s)]
00671         SUBS    loop,loop, #2
00672         BNE     fifo_write_loop
00673       }
00674       // M_08082008
00675       IINCHIP_CRITICAL_SECTION_EXIT();
00676    #elif (__DEF_IINCHIP_BUF_OP__ == __DEF_MCU_DEP_DMA__)
00677       #error "You should do implement this block."
00678    #endif
00679 #elif (__DEF_IINCHIP_ADDRESS_MODE__ == __DEF_IINCHIP_INDIRECT_MODE__)
00680    #if (__DEF_IINCHIP_BUF_OP__ == __DEF_C__) */
00681       uint32 idx=0;
00682       IINCHIP_CRITICAL_SECTION_ENTER();
00683       *((vuint16*)IDM_AR) = Sn_TX_FIFOR(s);
00684       for (idx = 0; idx < len; idx+=2)
00685           *((vuint16*)IDM_DR) = *((uint16*)(buf+idx));
00686       IINCHIP_CRITICAL_SECTION_EXIT();
00687    #elif (__DEF_IINCHIP_BUF_OP__ == __DEF_MCU_DEP_INLINE_ASM__)
00688       register uint16 data=0;
00689       register uint16 loop;
00690       loop = len;
00691       IINCHIP_CRITICAL_SECTION_ENTER();
00692       *((vuint16*)IDM_AR) = Sn_TX_FIFOR(s);
00693       __asm
00694       {
00695       fifo_write_loop:
00696         // ARM version
00697         LDRH    data, [buf], #2
00698         STRH    data, [IDM_DR]
00699         SUBS    loop,loop, #2
00700         BNE     fifo_write_loop
00701       }
00702       IINCHIP_CRITICAL_SECTION_EXIT();
00703    #elif (__DEF_IINCHIP_BUF_OP__ == __DEF_MCU_DEP_DMA__)
00704       #error "You should do implement this block."
00705    #else
00706       #error "Undefined __DEF_IINCHIP_BUF_OP__"
00707    #endif
00708 #else
00709    #error "Undefined __DEF_IINCHIP_ADDRESS_MODE__"
00710 #endif
00711     return len;
00712 }
00713
00714 uint32   wiz_read_buf(SOCKET s, uint8* buf,uint32 len)
00715 {
00716 #if (__DEF_IINCHIP_ADDRESS_MODE__ == __DEF_IINCHIP_DIRECT_MODE__)
00717    #if (__DEF_IINCHIP_BUF_OP__ == __DEF_C__)
00718       uint32 idx;
00719       // M_08082008
00720       IINCHIP_CRITICAL_SECTION_ENTER();
00721       for (idx = 0; idx < len; idx+=2)
00722          *((uint16*)(buf+idx)) = IINCHIP_READ(Sn_RX_FIFOR(s));
00723       // M_08082008
00724       IINCHIP_CRITICAL_SECTION_EXIT();
00725    #elif (__DEF_IINCHIP_BUF_OP__ == __DEF_MCU_DEP_INLINE_ASM__)
00726       register uint16 data=0;
00727       register int16 loop;
00728       loop = (int16) len;
00729       // M_08082008
00730       IINCHIP_CRITICAL_SECTION_ENTER();
00731       __asm
00732       {
00733       fifo_read_loop:
00734         // ARM version
00735         LDRH    data, [Sn_RX_FIFOR(s)]
00736         STRH    data, [buf], #2
00737         SUBS    loop,loop, #2
00738         BNE     fifo_read_loop
00739       }
00740       // M_08082008
00741       IINCHIP_CRITICAL_SECTION_EXIT();
00742    #elif (__DEF_IINCHIP_BUF_OP__ == __DEF_MCU_DEP_DMA__)
00743       #error "You should do implement this block."
00744    #else
00745       #error "Undefined __DEF_IINCHIP_BUF_OP__"
00746    #endif
00747 #elif (__DEF_IINCHIP_ADDRESS_MODE__ == __DEF_IINCHIP_INDIRECT_MODE__)
00748    #if (__DEF_IINCHIP_BUF_OP__ == __DEF_C__) */
00749       uint32 idx=0;
00750       IINCHIP_CRITICAL_SECTION_ENTER();
00751       *((vuint16*)IDM_AR) = Sn_RX_FIFOR(s);
00752       for (idx = 0; idx < len; idx+=2)
00753          *((uint16*)(buf+idx)) = *((vuint16*)IDM_DR);
00754       IINCHIP_CRITICAL_SECTION_EXIT();
00755    #elif (__DEF_IINCHIP_BUF_OP__ == __DEF_MCU_DEP_INLINE_ASM__)
00756       register uint16 data=0;
00757       register int16 loop;
00758       loop = (int16)len;
00759       IINCHIP_CRITICAL_SECTION_ENTER();
00760       *((vuint16*)IDM_AR) = Sn_RX_FIFOR(s);
00761       __asm
00762       {
00763       fifo_read_loop:
00764         // ARM version
00765         LDRH    data, [IDM_DR]
00766         STRH    data, [buf], #2
00767         SUBS    loop,loop, #2
00768         BNE     fifo_read_loop
00769       }
00770       IINCHIP_CRITICAL_SECTION_EXIT();
00771    #elif (__DEF_IINCHIP_BUF_OP__ == __DEF_MCU_DEP_DMA__)
00772       #error "You should do implement this block."
00773    #else
00774       #error "Undefined __DEF_IINCHIP_BUF_OP__"
00775    #endif
00776 #else
00777    #error "Undefined __DEF_IINCHIP_ADDRESS_MODE__"
00778 #endif
00779     return len;
00780 }
00781
00782
00783 uint32   getIINCHIP_TxMAX(SOCKET s)
00784 {
00785    return TXMEM_SIZE[s];
00786 }
00787
00788 uint32   getIINCHIP_RxMAX(SOCKET s)
00789 {
00790    return RXMEM_SIZE[s];
00791 }
00792
00793
00794 // This statement is commented for using 'Doxygen'.
00795 //#ifdef __DEF_IINCHIP_PPP__
00796
00800 #define PPP_OPTION_BUF_LEN 64
00801
00821 uint8    pppinit_in(uint8 * id, uint8 idlen, uint8 * passwd, uint8 passwdlen)
00822 {
00823    uint8 loop_idx = 0;
00824    uint8 isr = 0;
00825    uint8 buf[PPP_OPTION_BUF_LEN];
00826    uint32 len;
00827    uint8 str[PPP_OPTION_BUF_LEN];
00828    uint8 str_idx,dst_idx;
00829
00831    // PHASE1. PPPoE Discovery //
00833    // start to connect pppoe connection
00834    printf("-- PHASE 1. PPPoE Discovery process --");
00835    printf(" ok\r\n");
00836    printf("\r\n");
00837    setSn_CR(0,Sn_CR_PCON);
00838    wait_10ms(100);
00839
00840    // check if PPPoE discovery phase is success or not
00841    loop_idx = 0;
00842    while (!(getSn_IR(0) & Sn_IR_PNEXT))
00843    {
00844       printf(".");
00845       if (loop_idx++ == 10) // timeout
00846       {
00847          printf("timeout before LCP\r\n");
00848          return 3;
00849       }
00850       wait_10ms(100);
00851    }
00852    setSn_IR(0,Sn_IR_PNEXT);
00853
00855    // PHASE2. LCP process //
00857    printf("-- PHASE 2. LCP process --");
00858    {
00859       // Magic number option
00860       // option format (type value + length value + data)
00861       // write magic number value
00862       buf[0] = 0x05; // type value
00863       buf[1] = 0x06; // length value
00864       buf[2] = 0x01; buf[3] = 0x01; buf[4] = 0x01; buf[5]= 0x01; // data
00865       // for MRU option, 1492 0x05d4
00866       // buf[6] = 0x01; buf[7] = 0x04; buf[8] = 0x05; buf[9] = 0xD4;
00867    }
00868    wiz_write_buf(0,buf, 0x06);
00869    setSn_TX_WRSR(0,0x06);
00870    setSn_CR(0,Sn_CR_PCR); // send LCP request to PPPoE server
00871    wait_10ms(100);
00872
00873    while (!((isr = getSn_IR(0)) & Sn_IR_PNEXT))
00874    {
00875       if (isr & Sn_IR_PRECV)     // Not support option
00876       {
00877          len = getSn_RX_RSR(0);
00878          if ( len > 2 )
00879          {
00880             wiz_read_buf(0,str, 2);
00881             len = ((uint16)str[0] << 8) + str[1];
00882             wiz_read_buf(0,(str+2), len);
00883             setSn_CR(0,Sn_CR_RECV);
00884             // get option length
00885             len = (uint32)str[4]; len = ((len & 0xff) << 8) + (uint32)str[5];
00886             len += 2;
00887             str_idx = 6; dst_idx = 0; // PPP header is 6 byte, so starts at 6.
00888             do
00889             {
00890                if ((str[str_idx] == 0x01) || (str[str_idx] == 0x02) || (str[str_idx] == 0x03) || (str[str_idx] == 0x05))
00891                {
00892                   // skip as length of support option. str_idx+1 is option's length.
00893                   str_idx += str[str_idx+1];
00894                }
00895                else
00896                {
00897                   // not support option , REJECT
00898                   memcpy((uint8 *)(buf+dst_idx), (uint8 *)(str+str_idx), str[str_idx+1]);
00899                   dst_idx += str[str_idx+1]; str_idx += str[str_idx+1];
00900                }
00901             } while (str_idx != len);
00902
00903             // send LCP REJECT packet
00904             wiz_write_buf(0,buf, dst_idx);
00905             setSn_TX_WRSR(0,dst_idx);
00906             setSn_CR(0,Sn_CR_PCJ);
00907             setSn_IR(0,Sn_IR_PRECV);
00908          }
00909       }
00910       printf(".");
00911       if (loop_idx++ == 10) // timeout
00912       {
00913          printf("timeout after LCP\r\n");
00914          return 3;
00915       }
00916       wait_10ms(100);
00917    }
00918    setSn_IR(0,Sn_IR_PNEXT);
00919    printf(" ok\r\n");
00920    printf("\r\n");
00921
00923    // PHASE 3. PPPoE Authentication //
00925    printf("-- PHASE 3. PPPoE Authentication mode --\r\n");
00926    printf("Authentication protocol : %04x, ", getPATR());
00927    loop_idx = 0;
00928    if (getPATR() == 0xC023)         // PAP type
00929    {
00930       printf("PAP\r\n"); // in case of adsl normally supports PAP.
00931       // send authentication data
00932       // copy (idlen + id + passwdlen + passwd)
00933       buf[loop_idx] = idlen; loop_idx++;
00934       memcpy((uint8 *)(buf+loop_idx), (uint8 *)(id), idlen); loop_idx += idlen;
00935       buf[loop_idx] = passwdlen; loop_idx++;
00936       memcpy((uint8 *)(buf+loop_idx), (uint8 *)(passwd), passwdlen); loop_idx += passwdlen;
00937       wiz_write_buf(0,buf, loop_idx);
00938       setSn_TX_WRSR(0,loop_idx);
00939       setSn_CR(0,Sn_CR_PCR);
00940       wait_10ms(100);
00941    }
00942    else if (getPATR() == 0xC223)    // CHAP type
00943    {
00944       uint8 chal_len;
00945       md5_ctx context;
00946       uint8  digest[16];
00947
00948       len = getSn_RX_RSR(0);
00949       if ( len > 2 )
00950       {
00951          wiz_read_buf(0,str,2);
00952          len = ((uint32)str[0] << 8) + (uint32)str[1];
00953          wiz_read_buf(0, str, len);
00954          setSn_CR(0,Sn_CR_RECV);
00955          #ifdef __DEF_IINCHIP_DBG__
00956          {
00957             int16 i;
00958             printf("recv CHAP\r\n");
00959             for (i = 0; i < 32; i++) printf ("%02X ", str[i]);
00960             printf("\r\n");
00961          }
00962          #endif
00963          // str is C2 23 xx CHAL_ID xx xx CHAP_LEN CHAP_DATA
00964          // index  0  1  2  3       4  5  6        7 ...
00965
00966          memset(buf,0x00,64);
00967          buf[loop_idx] = str[3]; loop_idx++; // chal_id
00968          memcpy((uint8 *)(buf+loop_idx), (uint8 *)(passwd), passwdlen); loop_idx += passwdlen; //passwd
00969          chal_len = str[6]; // chal_id
00970          memcpy((uint8 *)(buf+loop_idx), (uint8 *)(str+7), chal_len); loop_idx += chal_len; //challenge
00971          buf[loop_idx] = 0x80;
00972          #ifdef __DEF_IINCHIP_DBG__
00973          {
00974             int16 i;
00975             printf("CHAP proc d1\r\n");
00976
00977             for (i = 0; i < 64; i++) printf ("%02X ", buf[i]);
00978             printf("\r\n");
00979          }
00980          #endif
00981
00982          md5_init(&context);
00983          md5_update(&context, buf, loop_idx);
00984          md5_final(digest, &context);
00985
00986          #ifdef __DEF_IINCHIP_DBG__
00987          {
00988             uint i;
00989             printf("CHAP proc d1\r\n");
00990             for (i = 0; i < 16; i++) printf ("%02X", digest[i]);
00991             printf("\r\n");
00992          }
00993          #endif
00994          loop_idx = 0;
00995          buf[loop_idx] = 16; loop_idx++; // hash_len
00996          memcpy((uint8 *)(buf+loop_idx), (uint8 *)(digest), 16); loop_idx += 16; // hashed value
00997          memcpy((uint8 *)(buf+loop_idx), (uint8 *)(id), idlen); loop_idx += idlen; // id
00998          wiz_write_buf(0,buf, loop_idx);
00999          setSn_TX_WRSR(0,loop_idx);
01000          setSn_CR(0,Sn_CR_PCR);
01001          wait_10ms(100);
01002       }
01003    }
01004    else
01005    {
01006       printf("Not support\r\n");
01007       #ifdef __DEF_IINCHIP_DBG__
01008          printf("Not support PPP Auth type: %.4x\r\n",getPATR());
01009       #endif
01010       return 4;
01011    }
01012    printf("\r\n");
01013
01014    printf("-- Waiting for PPPoE server's admission --");
01015    loop_idx = 0;
01016    while (!((isr = getSn_IR(0)) & Sn_IR_PNEXT))
01017    {
01018       if (isr & Sn_IR_PFAIL)
01019       {
01020          printf("failed\r\nReinput id, password..\r\n");
01021          return 2;
01022       }
01023       printf(".");
01024       if (loop_idx++ == 10) // timeout
01025       {
01026          printf("timeout after PAP\r\n");
01027          return 3;
01028       }
01029       wait_10ms(100);
01030    }
01031    setSn_IR(0,Sn_IR_PNEXT);
01032    printf("ok\r\n");
01033    printf("\r\n");
01034
01036    // PHASE 4. IPCP process //
01038    printf("-- PHASE 4. IPCP process --");
01039    // IP Address
01040    buf[0] = 0x03; buf[1] = 0x06; buf[2] = 0x00; buf[3] = 0x00; buf[4] = 0x00; buf[5] = 0x00;
01041    wiz_write_buf(0,buf, 6);
01042    setSn_TX_WRSR(0,6);
01043    setSn_CR(0,Sn_CR_PCR);
01044    wait_10ms(100);
01045
01046    loop_idx = 0;
01047    while (1)
01048    {
01049       if (getSn_IR(0) & Sn_IR_PRECV)
01050       {
01051          len = getSn_RX_RSR(0);
01052          if ( len > 2 )
01053          {
01054             wiz_read_buf(0,str,2);
01055             len = ((uint32)str[0] << 8) + (uint32)str[1];
01056             wiz_read_buf(0, str, len);
01057             setSn_CR(0,Sn_CR_RECV);
01058             str_idx = 6; dst_idx = 0;
01059             if (str[2] == 0x03) // in case of NAK
01060             {
01061                do
01062                {
01063                   if (str[str_idx] == 0x03) // request only ip information
01064                   {
01065                      memcpy((uint8 *)(buf+dst_idx), (uint8 *)(str+str_idx), str[str_idx+1]);
01066                      dst_idx += str[str_idx+1]; str_idx += str[str_idx+1];
01067                   }
01068                   else
01069                   {
01070                      // skip byte
01071                      str_idx += str[str_idx+1];
01072                   }
01073                   // for debug
01074                   //printf("s: %d, d: %d, l: %d", str_idx, dst_idx, len);
01075                } while (str_idx != len);
01076                wiz_write_buf(0,buf, dst_idx);
01077                setSn_TX_WRSR(0,dst_idx);
01078                setSn_CR(0,Sn_CR_PCR); // send ipcp request
01079                wait_10ms(100);
01080                break;
01081             }
01082          }
01083          setSn_IR(0,Sn_IR_PRECV);
01084       }
01085       printf(".");
01086       if (loop_idx++ == 10) // timeout
01087       {
01088          printf("timeout after IPCP\r\n");
01089          return 3;
01090       }
01091       wait_10ms(100);
01092       wiz_write_buf(0, buf, 6);
01093       setSn_TX_WRSR(0,6);
01094       setSn_CR(0,Sn_CR_PCR); //ipcp re-request
01095    }
01096
01097    loop_idx = 0;
01098    while (!(getSn_IR(0) & Sn_IR_PNEXT))
01099    {
01100       printf(".");
01101       if (loop_idx++ == 10) // timeout
01102       {
01103          printf("timeout after IPCP NAK\r\n");
01104          return 3;
01105       }
01106       wait_10ms(100);
01107       setSn_CR(0,Sn_CR_PCR); // send ipcp request
01108    }
01109    setSn_IR(0,Sn_IR_PNEXT);
01110    printf("ok\r\n");
01111    printf("\r\n");
01112    return 1;
01113    // after this function, the pppoe server's mac address and pppoe session id is saved in PHAR and PSIDR repectly.
01114 }
01115
01116 uint8    pppinit(uint8 *id, uint8 idlen, uint8 *passwd, uint8 passwdlen)
01117 {
01118         uint8 ret;
01119         uint8 isr;
01120
01121         // PHASE0. PPPoE setup
01122
01123         printf("-- PHASE 0. PPPoE setup process --\r\n");
01124         printf("\r\n");
01125         setMR(getMR()|MR_PPPoE);                     // set PPPoE mode
01126         setMR(getMR()|MR_FS);                        // If little-endian, set MR_FS. Otherwise, comment.
01127
01128         isr =  getSn_IR(0);
01129         setSn_IR(0,(uint16)isr);                     // clear the previous value of Sn_IR(0)
01130
01131         setPTIMER(200);                              // set LPC request time to 5 seconds
01132         setPMAGICR(0x01);                            // set the magic number
01133         setSn_MR(0, Sn_MR_PPPoE);                    // set Sn_MR(0) to PPPoE mode
01134         setSn_CR(0,Sn_CR_OPEN);                      //open SOCKET0 with PPPoE mode
01135
01136         ret = pppinit_in(id, idlen, passwd, passwdlen); // process the PPPoE message
01137
01138         setSn_CR(0, Sn_CR_CLOSE);                       // close PPPoE SOCKET0
01139
01140         return ret;
01141 }
01142
01143 void    pppterm(uint8 *mac, uint16 sessionid)
01144 {
01145    uint8 isr;
01146    #ifdef __DEF_IINCHIP_DBG__
01147       printf("pppterm()\r\n");
01148    #endif
01149
01150    // set PPPoE mode
01151    setMR(getMR() | MR_PPPoE);
01152
01153    // set pppoe server's mac address and session id
01154    // must be setted these value.
01155    setSn_DHAR(0, mac);
01156    setSn_DPORTR(0,sessionid);
01157
01158    // clear the previous value of Sn_IR(0)
01159         isr =  getSn_IR(0);
01160         setSn_IR(0,(uint16)isr);
01161
01162    //open SOCKET0 with PPPoE mode
01163         setSn_MR(0, Sn_MR_PPPoE);
01164         setSn_CR(0,Sn_CR_OPEN);
01165    while(getSn_SSR(0) != SOCK_PPPoE)
01166
01167    // close PPPoE connection
01168    setSn_CR(0,Sn_CR_PDISCON);
01169    wait_10ms(100);
01170    // close socket
01171    setSn_CR(0,Sn_CR_CLOSE);
01172
01173    #ifdef __DEF_IINCHIP_DBG__
01174       printf("pppterm() end ..\r\n");
01175    #endif
01176 }
01177 // This statement is commented for using 'Doxygen'.
01178 //#endif
01179
01180
01181 void  wait_1us(uint32 us)
01182 {
01183    uint32 i,j;
01184    for(i = 0; i < us ; i++)
01185    {
01186       for(j = 0; j < 100; j++);
01187    }
01188 }
01189
01190 void  wait_1ms(uint32 ms)
01191 {
01192    uint32 i;
01193    for(i = 0; i < ms ; i++)
01194    {
01195      wait_1us(1000);
01196    }
01197
01198 }
01199
01200 void  wait_10ms(uint32 ms)
01201 {
01202    uint32 i;
01203    for(i = 0; i < ms ; i++)
01204    {
01205      wait_1ms(10);
01206    }
01207 }
01208
Generated on Fri Jan 2 12:19:59 2009 for W5300 - SOCKET APIs by doxygen 1.5.6


W5300 - SOCKET APIs: include/w5300.h Source File

include/w5300.h

Go to the documentation of this file.
00001 #ifndef _W5300_H_
00002 #define _W5300_H_
00003
00032 #include "iinchip_conf.h"
00033 #include "types.h"
00034
00035
00128 #define MR              (__DEF_IINCHIP_MAP_BASE__)
00129 #define MR0             MR
00130 #define MR1             (MR + 1)
00131
00141 #define IDM_AR          (__DEF_IINCHIP_MAP_BASE__ + 0x02)
00142 #define IDM_AR0         IDM_AR
00143 #define IDM_AR1         (IDM_AR + 1)
00144
00154 #define IDM_DR          (__DEF_IINCHIP_MAP_BASE__ + 0x04)
00155 #define IDM_DR0         (__DEF_IINCHIP_MAP_BASE__ + 0x04)
00156 #define IDM_DR1         (IDM_DR + 1)
00157
00178 #define IR              (COMMON_REG_BASE + 0x02)
00179 #define IR0             IR
00180 #define IR1             (IR + 1);
00181
00192 #define IMR             (COMMON_REG_BASE + 0x04)
00193 #define IMR0            IMR
00194 #define IMR1            (IMR + 1)
00195
00196
00197 //#define ICFGR           (COMMON_REG_BASE + 0x06)
00198 //#define ICFGR0          ICFGR
00199 //#define ICFGR1          (ICFGR0 + 1)
00200
00208 #define SHAR            (COMMON_REG_BASE + 0x08)
00209 #define SHAR0           SHAR
00210 #define SHAR1           (SHAR + 1)
00211 #define SHAR2           (SHAR + 2)
00212 #define SHAR3           (SHAR + 3)
00213 #define SHAR4           (SHAR + 4)
00214 #define SHAR5           (SHAR + 5)
00215
00216
00224 #define GAR             (COMMON_REG_BASE + 0x10)
00225 #define GAR0            GAR
00226 #define GAR1            (GAR + 1)
00227 #define GAR2            (GAR + 2)
00228 #define GAR3            (GAR + 3)
00229
00237 #define SUBR            (COMMON_REG_BASE + 0x14)
00238 #define SUBR0           SUBR
00239 #define SUBR1           (SUBR + 1)
00240 #define SUBR2           (SUBR + 2)
00241 #define SUBR3           (SUBR + 3)
00242
00250 #define SIPR            (COMMON_REG_BASE + 0x18)
00251 #define SIPR0           SIPR
00252 #define SIPR1           (SIPR + 1)
00253 #define SIPR2           (SIPR + 2)
00254 #define SIPR3           (SIPR + 3)
00255
00266 #define RTR             (COMMON_REG_BASE + 0x1C)
00267 #define RTR0            RTR
00268 #define RTR1            (RTR + 1)
00269
00280 #define RCR             (COMMON_REG_BASE + 0x1E)
00281 #define RCR0            RCR
00282 #define RCR1            (RCR + 1)
00283
00295 #define TMS01R          (COMMON_REG_BASE + 0x20)
00296 #define TMS23R          (TMS01R + 2)
00297 #define TMS45R          (TMS01R + 4)
00298 #define TMS67R          (TMS01R + 6)
00300 #define TMSR0           TMS01R
00301 #define TMSR1           (TMSR0 + 1)
00302 #define TMSR2           (TMSR0 + 2)
00303 #define TMSR3           (TMSR0 + 3)
00304 #define TMSR4           (TMSR0 + 4)
00305 #define TMSR5           (TMSR0 + 5)
00306 #define TMSR6           (TMSR0 + 6)
00307 #define TMSR7           (TMSR0 + 7)
00308
00309
00321 #define RMS01R          (COMMON_REG_BASE + 0x28)
00322 #define RMS23R          (RMS01R + 2)
00323 #define RMS45R          (RMS01R + 4)
00324 #define RMS67R          (RMS01R + 6)
00326 #define RMSR0           RMS01R
00327 #define RMSR1           (RMSR0 + 1)
00328 #define RMSR2           (RMSR0 + 2)
00329 #define RMSR3           (RMSR0 + 3)
00330 #define RMSR4           (RMSR0 + 4)
00331 #define RMSR5           (RMSR0 + 5)
00332 #define RMSR6           (RMSR0 + 6)
00333 #define RMSR7           (RMSR0 + 7)
00334
00335
00336
00353 #define MTYPER          (COMMON_REG_BASE + 0x30)
00354 #define MTYPER0         MTYPER
00355 #define MTYPER1         (MTYPER + 1)
00356
00369 #define PATR            (COMMON_REG_BASE + 0x32)
00370 #define PATR0           PATR
00371 #define PATR1           (PATR + 1)
00372
00373 //#define PPPALGOR      (COMMON_REG_BASE + 0x34)
00374 //#define PPPALGOR0     PPPALGOR
00375 //#define PPPALGOR1     (PPPALGOR + 1)
00376
00385 #define PTIMER          (COMMON_REG_BASE + 0x36)
00386 #define PTIMER0         PTIMER
00387 #define PTIMER1         (PTIMER + 1)
00388
00397 #define PMAGICR         (COMMON_REG_BASE + 0x38)
00398 #define PMAGICR0        PMAGICR
00399 #define PMAGICR1        (PMAGICR + 1)
00400
00401 //#define PSTATER       (COMMON_REG_BASE + 0x3A)
00402 //#define PSTATER0      PSTATER
00403 //#define PSTATER1      (PSTATER + 1)
00404
00413 #define PSIDR           (COMMON_REG_BASE + 0x3C)
00414 #define PSIDR0          PSIDR
00415 #define PSIDR1          (PSIDR + 1)
00416
00425 #define PDHAR           (COMMON_REG_BASE + 0x40)
00426 #define PDHAR0          PDHAR
00427 #define PDHAR1          (PDHAR + 1)
00428 #define PDHAR2          (PDHAR + 2)
00429 #define PDHAR3          (PDHAR + 3)
00430 #define PDHAR4          (PDHAR + 4)
00431 #define PDHAR5          (PDHAR + 5)
00432
00444 #define UIPR            (COMMON_REG_BASE + 0x48)
00445 #define UIPR0           UIPR
00446 #define UIPR1           (UIPR + 1)
00447 #define UIPR2           (UIPR + 2)
00448 #define UIPR3           (UIPR + 3)
00449
00457 #define UPORTR          (COMMON_REG_BASE + 0x4C)
00458 #define UPORTR0         UPORTR
00459 #define UPORTR1         (UPORT + 1)
00460
00461
00462
00475 #define FMTUR           (COMMON_REG_BASE + 0x4E)
00476 #define FMTUR0          FMTUR
00477 #define FMTUR1          (FMTUR + 1)
00478
00479 //#define Sn_RTCR(n)      (COMMON_REG_BASE + 0x50 + n*2)
00480 //#define Sn_RTCR0(n)     Sn_RTCR(n)
00481 //#define Sn_RTCR1(n)     (Sn_RTCR(n)+1)
00482
00500 #define Pn_BRDYR(n)     (COMMON_REG_BASE + 0x60 + n*4)
00501 #define Pn_BRDYR0(n)    Pn_BRDYR(n)
00502 #define Pn_BRDYR1(n)    (Pn_BRDYR(n) + 1)
00503
00518 #define Pn_BDPTHR(n)    (COMMON_REG_BASE + 0x60 + n*4 + 2)
00519 #define Pn_BDPTHR0(n)   Pn_BDPTHR(n)
00520 #define Pn_BDPTHR1(n)   (Pn_BDPTHR(n) + 1)
00521
00528 #define IDR             (COMMON_REG_BASE + 0xFE)
00529 #define IDR1            (IDR + 1)
00530
00531
00551 #define Sn_MR(n)        (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x00)
00552 #define Sn_MR0(n)       Sn_MR(n)
00553 #define Sn_MR1(n)       (Sn_MR(n)+1)
00554
00577 #define Sn_CR(n)        (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x02)
00578 #define Sn_CR0(n)       Sn_CR(n)
00579 #define Sn_CR1(n)       (Sn_CR(n) + 1)
00580
00593 #define Sn_IMR(n)       (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x04)
00594 #define Sn_IMR0(n)      Sn_IMR(n)
00595 #define Sn_IMR1(n)      (Sn_IMR(n)+1)
00596
00621 #define Sn_IR(n)        (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x06)
00622 #define Sn_IR0(n)       Sn_IR(n)
00623 #define Sn_IR1(n)       (Sn_IR(n)+1)
00624
00668 #define Sn_SSR(n)       (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x08)
00669 #define Sn_SSR0(n)      Sn_SSR(n)
00670 #define Sn_SSR1(n)      (Sn_SSR(n)+1)
00671
00680 #define Sn_PORTR(n)     (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x0A)
00681 #define Sn_PORTR0(n)    Sn_PORTR(n)
00682 #define Sn_PORTR1(n)    (Sn_PORTR(n)+1)
00683
00709 #define Sn_DHAR(n)      (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x0C)
00710 #define Sn_DHAR0(n)     Sn_DHAR(n)
00711 #define Sn_DHAR1(n)     (Sn_DHAR(n)+1)
00712 #define Sn_DHAR2(n)     (Sn_DHAR(n)+2)
00713 #define Sn_DHAR3(n)     (Sn_DHAR(n)+3)
00714 #define Sn_DHAR4(n)     (Sn_DHAR(n)+4)
00715 #define Sn_DHAR5(n)     (Sn_DHAR(n)+5)
00716
00735 #define Sn_DPORTR(n)    (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x12)
00736 #define Sn_DPORTR0(n)   Sn_DPORTR(n)
00737 #define Sn_DPORTR1(n)   (Sn_DPORTR(n)+1)
00738
00739
00758 #define Sn_DIPR(n)      (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x14)
00759 #define Sn_DIPR0(n)     Sn_DIPR(n)
00760 #define Sn_DIPR1(n)     (Sn_DIPR(n)+1)
00761 #define Sn_DIPR2(n)     (Sn_DIPR(n)+2)
00762 #define Sn_DIPR3(n)     (Sn_DIPR(cnnh)+3)
00763
00806 #define Sn_MSSR(n)      (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x18)
00807 #define Sn_MSSR0(n)     Sn_MSSR(n)
00808 #define Sn_MSSR1(n)     (Sn_MSSR(n)+1)
00809
00827 #define Sn_PROTOR(n)            (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x1A)
00828
00846 #define Sn_KPALVTR(n)   Sn_PROTOR(n)
00847 #define Sn_PROTOR1(n)   (Sn_PROTOR(n)+1)
00848
00856 #define Sn_TOSR(n)      (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x1C)
00857 #define Sn_TOSR0(n)     Sn_TOSR(n)
00858 #define Sn_TOSR1(n)     (Sn_TOSR(n)+1)
00859
00867 #define Sn_TTLR(n)      (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x1E)
00868 #define Sn_TTLR0(n)     Sn_TTLR(n)
00869 #define Sn_TTLR1(n)     (Sn_TTLR(n)+1)
00870
00882 #define Sn_TX_WRSR(n)           (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x20)
00883 #define Sn_TX_WRSR0(n)          Sn_TX_WRSR(n)
00884 #define Sn_TX_WRSR1(n)          (Sn_TX_WRSR(n) + 1)
00885 #define Sn_TX_WRSR2(n)          (Sn_TX_WRSR(n) + 2)
00886 #define Sn_TX_WRSR3(n)          (Sn_TX_WRSR(n) + 3)
00887
00901 #define Sn_TX_FSR(n)       (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x0024)
00902 #define Sn_TX_FSR0(n)      Sn_TX_FSR(n)
00903 #define Sn_TX_FSR1(n)      (Sn_TX_FSR(n) + 1)
00904 #define Sn_TX_FSR2(n)      (Sn_TX_FSR(n) + 2)
00905 #define Sn_TX_FSR3(n)      (Sn_TX_FSR(n) + 3)
00906
00920 #define Sn_RX_RSR(n)       (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x0028)
00921 #define Sn_RX_RSR0(n)      Sn_RX_RSR(n)
00922 #define Sn_RX_RSR1(n)      (Sn_RX_RSR(n) + 1)
00923 #define Sn_RX_RSR2(n)      (Sn_RX_RSR(n) + 2)
00924 #define Sn_RX_RSR3(n)      (Sn_RX_RSR(n) + 3)
00925
00934 #define Sn_FRAGR(n)        (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x002C)
00935 #define Sn_FRAGR0(n)       Sn_FRAGR(n)
00936 #define Sn_FRAGR1(n)       (Sn_FRAGR(n) + 1)
00937
00954 #define Sn_TX_FIFOR(n)     (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x2E)
00955 #define Sn_TX_FIFOR0(n)    Sn_TX_FIFO(n)
00956 #define Sn_TX_FIFOR1(n)    (Sn_TX_FIFO(n) + 1)
00957
00979 #define Sn_RX_FIFOR(n)     (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x30)
00980 #define Sn_RX_FIFOR0(n)    Sn_RX_FIFO(n)
00981 #define Sn_RX_FIFOR1(n)    (Sn_RX_FIFO(n) + 1)
00982
00983
00984 //#define Sn_TX_SADR(n)      (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x32)
00985 //#define Sn_TX_SADR0(n)     Sn_TX_SADR(n)
00986 //#define Sn_TX_SADR1(n)     (Sn_TX_SADR(n) + 1)
00987
00988 //#define Sn_RX_SADR(n)      (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x34)
00989 //#define Sn_RX_SADR0(n)     Sn_RX_SADR(n)
00990 //#define Sn_RX_SADR1(n)     (Sn_RX_SADR(n) + 1)
00991
00992 //#define Sn_TX_RD(n)        (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x36)
00993 //#define Sn_TX_RD0(n)       (Sn_TX_RD(n) + 1)
00994 //#define Sn_TX_RD1(n)       (Sn_TX_RD(n) + 1)
00995
00996 //#define Sn_TX_WR(n)        (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x38)
00997 //#define Sn_TX_WR0(n)       Sn_TX_WR(n)
00998 //#define Sn_TX_WR1(n)       (Sn_TX_WR(n) + 1)
00999
01000 //#define Sn_TX_ACK(n)       (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x3A)
01001 //#define Sn_TX_ACK0(n)      (Sn_TX_ACK(n) + 1)
01002 //#define Sn_TX_ACK1(n)      (Sn_TX_ACK(n) + 1)
01003
01004 //#define Sn_RX_RD(n)           (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x3C)
01005 //#define Sn_RX_RD0(n)        Sn_RX_RD(n)
01006 //#define Sn_RX_RD1(n)        (Sn_RX_RD(n) + 1)
01007
01008 //#define Sn_RX_WR(n)        (SOCKET_REG_BASE + n * SOCKET_REG_SIZE + 0x3E)
01009 //#define Sn_RX_WR0(n)        Sn_RX_WR(n)
01010 //#define Sn_RX_WR1(n)       (Sn_RX_WR(n) + 1)
01011
01012
01013
01014 /* ********************************** */
01015 /* The bit of MR regsiter defintion   */
01016 /* ********************************** */
01024 #define MR_DBW             (1 << 15)
01025
01032 #define MR_MPF             (1 << 14)
01033
01040 #define MR_WDF(X)          ((X & 0x07) << 11)
01041
01050 #define MR_RDH             (1 << 10)
01051
01052
01061 #define MR_FS              (1 << 8)
01062
01069 #define MR_RST             (1 << 7)
01070
01078 #define MR_MT              (1 << 5)
01079
01086 #define MR_PB              (1 << 4)
01087
01096 #define MR_PPPoE           (1 << 3)
01097
01106 #define MR_DBS             (1 << 2)
01107
01116 #define MR_IND             (1 << 0)
01117
01118
01119
01120 /* ********************************** */
01121 /* The bit of IR regsiter defintion   */
01122 /* ********************************** */
01127 #define IR_IPCF            (1 << 7)
01128
01134 #define IR_DPUR            (1 << 6)
01135
01140 #define IR_PPPT            (1 << 5)
01141
01147 #define IR_FMTU            (1 << 4)
01148
01155 #define IR_SnINT(n)        (0x01 << n)
01156
01157
01158 /* *************************************** */
01159 /* The bit of Pn_BRDYR regsiter defintion  */
01160 /* *************************************** */
01168 #define Pn_PEN             (1 << 7)
01169
01177 #define Pn_MT              (1 << 6)
01178
01187 #define Pn_PPL             (1 << 5)
01188
01195 #define Pn_SN(n)           ((n & 0x07) << 0)
01196
01197
01198 /* ************************************* */
01199 /* The bit of Sn_MR regsiter defintion   */
01200 /* ************************************* */
01211 #define Sn_MR_ALIGN        (1 << 8)
01212
01222 #define Sn_MR_MULTI        (1 << 7)
01223
01233 #define Sn_MR_MF           (1 << 6)
01234
01244 #define Sn_MR_IGMPv        (1 << 5)
01245
01258 #define Sn_MR_ND           (1 << 5)
01259
01273 #define Sn_MR_CLOSE        0x00
01274
01280 #define Sn_MR_TCP          0x01
01281
01287 #define Sn_MR_UDP          0x02
01288
01294 #define Sn_MR_IPRAW        0x03
01295
01302 #define Sn_MR_MACRAW       0x04
01303
01312 #define Sn_MR_PPPoE        0x05
01313
01314
01315 /* **************************** */
01316 /* The values of CR defintion   */
01317 /* **************************** */
01318 #define Sn_CR_OPEN         0x01
01319
01332 #define Sn_CR_LISTEN       0x02
01333
01351 #define Sn_CR_CONNECT      0x04
01352
01371 #define Sn_CR_DISCON       0x08
01372
01392 #define Sn_CR_CLOSE        0x10
01393
01400 #define Sn_CR_SEND         0x20
01401
01425 #define Sn_CR_SEND_MAC     0x21
01426
01438 #define Sn_CR_SEND_KEEP    0x22
01439
01458 #define Sn_CR_RECV         0x40
01459
01468 #define Sn_CR_PCON         0x23
01469
01477 #define Sn_CR_PDISCON      0x24
01478
01486 #define Sn_CR_PCR          0x25
01487
01495 #define Sn_CR_PCN          0x26
01496
01504 #define Sn_CR_PCJ          0x27
01505
01514 /* ******************************* */
01515 /* The values of Sn_IR defintion   */
01516 /* ******************************* */
01517 #define Sn_IR_PRECV        0x80
01518
01525 #define Sn_IR_PFAIL        0x40
01526
01533 #define Sn_IR_PNEXT        0x20
01534
01541 #define Sn_IR_SENDOK       0x10
01542
01548 #define Sn_IR_TIMEOUT      0x08
01549
01555 #define Sn_IR_RECV         0x04
01556
01562 #define Sn_IR_DISCON       0x02
01563
01569 #define Sn_IR_CON          0x01
01570
01576 /* ******************************** */
01577 /* The values of Sn_SSR defintion   */
01578 /* ******************************** */
01579 #define SOCK_CLOSED        0x00
01580
01589 #define SOCK_ARP           0x01
01590
01607 #define SOCK_INIT          0x13
01608
01618 #define SOCK_LISTEN        0x14
01619
01631 #define SOCK_SYNSENT       0x15
01632
01644 #define SOCK_SYNRECV       0x16
01645
01655 #define SOCK_ESTABLISHED   0x17
01656
01666 #define SOCK_FIN_WAIT      0x18
01667
01678 #define SOCK_CLOSING       0x1A
01679
01685 #define SOCK_TIME_WAIT     0x1B
01686
01692 #define SOCK_CLOSE_WAIT    0x1C
01693
01703 #define SOCK_LAST_ACK      0x1D
01704
01710 #define SOCK_UDP           0x22
01711
01720 #define SOCK_IPRAW         0x32
01721
01730 #define SOCK_MACRAW        0x42
01731
01740 #define SOCK_PPPoE         0x5F
01741
01752 /* IP PROTOCOL */
01753 #define IPPROTO_IP         0
01754 #define IPPROTO_ICMP       1
01755 #define IPPROTO_IGMP       2
01756 #define IPPROTO_GGP        3
01757 #define IPPROTO_TCP        6
01758 #define IPPROTO_PUP        12
01759 #define IPPROTO_UDP        17
01760 #define IPPROTO_IDP        22
01761 #define IPPROTO_ND         77
01762 #define IPPROTO_RAW        255
01811 /* ********************* *
01812  * Basic I/O  Function   *
01813  * ********************* */
01814
01824 uint16   IINCHIP_READ(uint32 addr);
01825
01838 void     IINCHIP_WRITE(uint32 addr,uint16 data);
01839
01846 uint16   getMR(void);
01847
01854 void     setMR(uint16 val);
01855
01856
01857 /* ********************************* *
01858  * COMMON Register Access Function   *
01859  * ********************************* */
01860
01867 uint16   getIR(void);
01868
01875 void     setIR(uint16 val);
01876
01883 uint16   getIMR(void);
01884
01891 void     setIMR(uint16 mask); // set interrupt mask.
01892
01899 void     getSHAR(uint8 * addr);
01900
01907 void     setSHAR(uint8 * addr);   // set local MAC address
01908
01915 void     getGAR(uint8 * addr);
01916
01923 void     setGAR(uint8 * addr);    // set gateway address
01924
01931 void     getSUBR(uint8 * addr);
01932
01939 void     setSUBR(uint8 * addr); // set subnet mask address
01940
01947 void     getSIPR(uint8 * addr);
01948
01955 void     setSIPR(uint8 * addr); // set local IP address
01956
01963 uint16   getRTR(void);
01964
01971 void     setRTR(uint16 timeout); // set retry duration for data transmission, connection, closing ...
01972
01979 uint8    getRCR(void);
01986 void     setRCR(uint8 retry);
01987
01993 uint16   getPATR(void);
01994
02001 uint8    getPTIMER(void);
02002
02009 void     setPTIMER(uint8 time);
02010
02017 uint8    getPMAGICR(void);
02024 void     setPMAGICR(uint8 magic);
02025
02035 uint16   getPSIDR(void);
02036
02042 void     getPDHAR(uint8* addr);
02043
02056 void     getUIPR(uint8* addr);
02057
02065 uint16   getUPORTR(void);
02066
02073 uint16   getFMTUR(void);
02074
02082 uint8    getPn_BRDYR(uint8 p);
02083
02091 void     setPn_BRDYR(uint8 p, uint8 cfg);
02092
02100 uint16   getPn_BDPTHR(uint8 p);
02101
02109 void     setPn_BDPTHR(uint8 p, uint16 depth);
02110
02116 uint16   getIDR(void);
02117
02118
02119
02120 /* ********************************* *
02121  * SOCKET Register Access Function   *
02122  * ********************************* */
02123
02131 uint16   getSn_MR(SOCKET s);
02132
02140 void     setSn_MR(SOCKET s, uint16 mode);
02141
02149 uint8    getSn_CR(SOCKET s);
02160 void     setSn_CR(SOCKET s, uint16 com);
02161
02169 uint8    getSn_IMR(SOCKET s);
02170
02178 void     setSn_IMR(SOCKET s, uint8 mask);
02179
02187 uint8    getSn_IR(SOCKET s);
02188
02196 void     setSn_IR(SOCKET s, uint8 ir);
02197
02210 uint8    getSn_SSR(SOCKET s);
02211
02223 void     getSn_DHAR(SOCKET s, uint8* addr);
02224
02235 void     setSn_DHAR(SOCKET s, uint8* addr);
02236
02237 // M_15052008 : Delete this function because Sn_DPORTR is write-only register.
02238 /*
02239  * \fn uint16   getSn_DPORTR(SOCKET s)
02240  * \brief It gets Sn_DPORTR value.
02241  * \param[in] s \c SOCKET number. It is valid when 0 <= s <= \ref MAX_SOCK_NUM - 1.
02242  * \return The desintinaton port number of \c s-th \c SOCKET
02243  *             It should be allocated 6bytes size.
02244  *
02245  * \note It is also used when you get the PPP session ID.\n Refer to \ref getPSIDR(), \ref PSIDR
02246  *
02247  * \sa setSn_DPORTR()
02248  */
02249 //uint16   getSn_DPORTR(SOCKET s);
02250
02259 void     setSn_DPORTR(SOCKET s, uint16 port);
02260
02269 void     getSn_DIPR(SOCKET s, uint8* addr);
02270
02278 void     setSn_DIPR(SOCKET s, uint8* addr);
02279
02287 uint16   getSn_MSSR(SOCKET s);
02288
02300 void     setSn_MSSR(SOCKET s, uint16 mss);
02301
02309 uint8    getSn_KPALVTR(SOCKET s);
02310
02322 void     setSn_KPALVTR(SOCKET s, uint8 time);
02323
02331 uint32   getSn_TX_WRSR(SOCKET s);
02332
02340 void     setSn_TX_WRSR(SOCKET s, uint32 size);
02341
02354 uint32   getSn_TX_FSR(SOCKET s);
02355
02367 uint32   getSn_RX_RSR(SOCKET s);
02368
02376 void     setSn_TX_FIFOR(SOCKET s, uint16 data);
02377
02385 uint16   getSn_RX_FIFOR(SOCKET s);
02386
02394 uint8    getSn_PROTOR(SOCKET s);
02395
02404 void     setSn_PROTOR(SOCKET s, uint8 pronum);
02405
02413 uint8    getSn_TOSR(SOCKET s);
02414
02422 void     setSn_TOSR(SOCKET s, uint8 tos);
02423
02431 uint8    getSn_TTLR(SOCKET s);
02432
02440 void     setSn_TTLR(SOCKET s, uint8 ttl);
02441
02449 uint8    getSn_FRAGR(SOCKET s);
02461 void     setSn_FRAGR(SOCKET s, uint8 frag);
02462
02463
02464
02465 /* ***** *
02466  *  ETC  *
02467  * ***** */
02468
02469 /* Initialization & Interrupt request routine */
02470
02481 void     iinchip_init(void);
02482
02487 #ifdef __DEF_IINCHIP_INT__
02488    void     iinchip_irq(void);
02489 #endif
02490
02491
02492 /* Interanl memory operation */
02493
02509 uint8    sysinit(uint8* tx_size, uint8* rx_size); // setting tx/rx buf size
02510
02511
02525 uint32   wiz_write_buf(SOCKET s,uint8* buf,uint32 len);
02526
02527
02543 uint32   wiz_read_buf(SOCKET s, uint8* buf,uint32 len);
02544
02545
02552 uint32   getIINCHIP_TxMAX(SOCKET s);
02553
02560 uint32   getIINCHIP_RxMAX(SOCKET s);
02561
02562
02563
02564 #ifdef __DEF_IINCHIP_PPP__
02565
02576    uint8    pppinit(uint8 *id, uint8 idlen, uint8 *passwd, uint8 passwdlen);
02584    void    pppterm(uint8 *mac, uint16 sessionid);
02585 #endif
02586
02592 void  wait_1us(uint32 us);
02598 void  wait_1ms(uint32 ms);
02607 void  wait_10ms(uint32 ms);
02608
02609 #endif
Generated on Fri Jan 2 12:19:59 2009 for W5300 - SOCKET APIs by doxygen 1.5.6