Compare commits
131 Commits
v3.1.2
...
WolfgangsO
Author | SHA1 | Date | |
---|---|---|---|
0957fc4830
|
|||
27f646860d | |||
f8730808d1 | |||
26d4f89d0c
|
|||
1cdb6d2eda
|
|||
181cfae6cc
|
|||
7f58783400
|
|||
cae27e3acb | |||
0446055537
|
|||
a33e0f8381
|
|||
46df6545d9
|
|||
727db71b79
|
|||
4c75a8fa48
|
|||
5323a6d8e4
|
|||
8db71e5eb4
|
|||
cbf5b6e908 | |||
a9141a7ade | |||
0bad15ab48 | |||
de18368e5d | |||
1fadc591bc | |||
18aeb30431 | |||
96857e86aa | |||
84f4b6d030 | |||
587d26e341 | |||
47dec417fa | |||
af704a0d23 | |||
863973b22e | |||
b58bfbdbc8 | |||
dacf22ca48 | |||
3016459cc9 | |||
890a73fb8b | |||
7dd9ef0c2a | |||
fe116b361b | |||
40dc8d1f1e | |||
16657be394 | |||
c166849712 | |||
81e94dcc22 | |||
dd053614b5 | |||
798d505bff | |||
dac948e885 | |||
c2356c8777 | |||
c5be3a85b9 | |||
ca5348784f | |||
4b2cd30cb8 | |||
435cedca91 | |||
f3a575c8b4 | |||
4de4aa0816 | |||
dc10163277 | |||
b135a73a94 | |||
db469a1dc7 | |||
b70a532f8d | |||
21f6528af2 | |||
c2940b08bf | |||
cafc29ecee | |||
d1f87bd19f | |||
8dde2af871 | |||
6676770d63 | |||
bac969f04e | |||
2163c8b29c | |||
183daf143d | |||
c69d27b875 | |||
28e8a16b54 | |||
a832944757 | |||
72d9df579b | |||
3939dc4925 | |||
15b79ef7c0 | |||
b8e3c63cff | |||
8ebd860b08 | |||
aaaf41eff1 | |||
433f4bb409 | |||
18c878db9c | |||
e20beebfc2 | |||
7bac9a1f99 | |||
74bf44ddc0 | |||
879b8a1828 | |||
01d6b321bc | |||
1c6b068fa0 | |||
2166370f1d | |||
556bee8d4a | |||
a8b1f0a05c | |||
640eb5a863 | |||
e3855b86e8 | |||
81d0d9d981 | |||
d96daf13f0 | |||
47b6ea8bf7 | |||
4ddea28229 | |||
345fa577be | |||
fdeac309b6 | |||
f41e8900ec | |||
a0f6c13fc2 | |||
66ddef5307 | |||
49d630a3e4 | |||
bd0f13fc5b | |||
d0172c176a | |||
55e910b5b1 | |||
28b119ecc2 | |||
5f73fee3a1 | |||
5e64b7d299 | |||
832c720413 | |||
1425b8289a | |||
4eb03edf27 | |||
d343bb6b9f | |||
09d0928dfc | |||
da5043b60c | |||
7459a44257 | |||
2837ea44ec | |||
6a26540c33 | |||
2fccf578fe | |||
a553bb9a25 | |||
95de3e41d8 | |||
741ac43e4c | |||
63eb244701 | |||
08a9ca70ce | |||
0f6b317da2 | |||
438d8791b9 | |||
f94eee7608 | |||
c077993fd3 | |||
eb5cb5acdc | |||
5c278b5732 | |||
0cbef5673c | |||
196fac7b60 | |||
b4e24ff958 | |||
b6814ec8a6 | |||
069a81350e | |||
3de6bedd1d | |||
6411bf0ab7 | |||
9c5cc07ce5 | |||
4a8ec8d53e | |||
115db169b5 | |||
d616b1bdb1 | |||
de4d8028b5 |
1901
.gitignore
vendored
1901
.gitignore
vendored
File diff suppressed because it is too large
Load Diff
@ -34,6 +34,7 @@ int32_t loopback_tcps(uint8_t sn, uint8_t* buf, uint16_t port)
|
|||||||
ret = recv(sn, buf, size);
|
ret = recv(sn, buf, size);
|
||||||
|
|
||||||
if(ret <= 0) return ret; // check SOCKERR_BUSY & SOCKERR_XXX. For showing the occurrence of SOCKERR_BUSY.
|
if(ret <= 0) return ret; // check SOCKERR_BUSY & SOCKERR_XXX. For showing the occurrence of SOCKERR_BUSY.
|
||||||
|
size = (uint16_t) ret;
|
||||||
sentsize = 0;
|
sentsize = 0;
|
||||||
|
|
||||||
while(size != sentsize)
|
while(size != sentsize)
|
||||||
@ -91,7 +92,7 @@ int32_t loopback_tcpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destpo
|
|||||||
// uint16_t destport = 5000;
|
// uint16_t destport = 5000;
|
||||||
|
|
||||||
// Port number for TCP client (will be increased)
|
// Port number for TCP client (will be increased)
|
||||||
uint16_t any_port = 50000;
|
static uint16_t any_port = 50000;
|
||||||
|
|
||||||
// Socket Status Transitions
|
// Socket Status Transitions
|
||||||
// Check the W5500 Socket n status register (Sn_SR, The 'Sn_SR' controlled by Sn_CR command or Packet send/recv status)
|
// Check the W5500 Socket n status register (Sn_SR, The 'Sn_SR' controlled by Sn_CR command or Packet send/recv status)
|
||||||
@ -115,6 +116,7 @@ int32_t loopback_tcpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destpo
|
|||||||
ret = recv(sn, buf, size); // Data Receive process (H/W Rx socket buffer -> User's buffer)
|
ret = recv(sn, buf, size); // Data Receive process (H/W Rx socket buffer -> User's buffer)
|
||||||
|
|
||||||
if(ret <= 0) return ret; // If the received data length <= 0, receive failed and process end
|
if(ret <= 0) return ret; // If the received data length <= 0, receive failed and process end
|
||||||
|
size = (uint16_t) ret;
|
||||||
sentsize = 0;
|
sentsize = 0;
|
||||||
|
|
||||||
// Data sentsize control
|
// Data sentsize control
|
||||||
@ -151,7 +153,10 @@ int32_t loopback_tcpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destpo
|
|||||||
|
|
||||||
case SOCK_CLOSED:
|
case SOCK_CLOSED:
|
||||||
close(sn);
|
close(sn);
|
||||||
if((ret=socket(sn, Sn_MR_TCP, any_port++, 0x00)) != sn) return ret; // TCP socket open with 'any_port' port number
|
if((ret=socket(sn, Sn_MR_TCP, any_port++, 0x00)) != sn){
|
||||||
|
if(any_port == 0xffff) any_port = 50000;
|
||||||
|
return ret; // TCP socket open with 'any_port' port number
|
||||||
|
}
|
||||||
#ifdef _LOOPBACK_DEBUG_
|
#ifdef _LOOPBACK_DEBUG_
|
||||||
//printf("%d:TCP client loopback start\r\n",sn);
|
//printf("%d:TCP client loopback start\r\n",sn);
|
||||||
//printf("%d:Socket opened\r\n",sn);
|
//printf("%d:Socket opened\r\n",sn);
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
#ifndef _LOOPBACK_H_
|
#ifndef _LOOPBACK_H_
|
||||||
#define _LOOPBACK_H_
|
#define _LOOPBACK_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/* Loopback test debug message printout enable */
|
/* Loopback test debug message printout enable */
|
||||||
@ -27,4 +31,8 @@ int32_t loopback_tcpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destpo
|
|||||||
/* UDP Loopback test example */
|
/* UDP Loopback test example */
|
||||||
int32_t loopback_udps(uint8_t sn, uint8_t* buf, uint16_t port);
|
int32_t loopback_udps(uint8_t sn, uint8_t* buf, uint16_t port);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
113
Application/multicast/multicast.c
Normal file
113
Application/multicast/multicast.c
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
#include "multicast.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "socket.h"
|
||||||
|
#include "wizchip_conf.h"
|
||||||
|
|
||||||
|
|
||||||
|
int32_t multicast_loopback(uint8_t sn, uint8_t* buf, uint8_t* multicast_ip, uint16_t multicast_port)
|
||||||
|
{
|
||||||
|
int32_t ret;
|
||||||
|
uint16_t size, sentsize;
|
||||||
|
uint8_t destip[4];
|
||||||
|
uint16_t destport, port=3000;
|
||||||
|
|
||||||
|
switch(getSn_SR(sn))
|
||||||
|
{
|
||||||
|
case SOCK_UDP :
|
||||||
|
if((size = getSn_RX_RSR(sn)) > 0)
|
||||||
|
{
|
||||||
|
if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
|
||||||
|
ret = recvfrom(sn, buf, size, destip, (uint16_t*)&destport);
|
||||||
|
if(ret <= 0)
|
||||||
|
{
|
||||||
|
#ifdef _MULTICAST_DEBUG_
|
||||||
|
printf("%d: recvfrom error. %ld\r\n",sn,ret);
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
size = (uint16_t) ret;
|
||||||
|
sentsize = 0;
|
||||||
|
while(sentsize != size)
|
||||||
|
{
|
||||||
|
ret = sendto(sn, buf+sentsize, size-sentsize, destip, destport);
|
||||||
|
if(ret < 0)
|
||||||
|
{
|
||||||
|
#ifdef _MULTICAST_DEBUG_
|
||||||
|
printf("%d: sendto error. %ld\r\n",sn,ret);
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case SOCK_CLOSED:
|
||||||
|
#ifdef _MULTICAST_DEBUG_
|
||||||
|
printf("%d:Multicast Loopback start\r\n",sn);
|
||||||
|
#endif
|
||||||
|
setSn_DIPR(0, multicast_ip);
|
||||||
|
setSn_DPORT(0, multicast_port);
|
||||||
|
if((ret = socket(sn, Sn_MR_UDP, port, Sn_MR_MULTI)) != sn)
|
||||||
|
return ret;
|
||||||
|
#ifdef _MULTICAST_DEBUG_
|
||||||
|
printf("%d:Opened, UDP Multicast Socket\r\n", sn);
|
||||||
|
printf("%d:Multicast Group IP - %d.%d.%d.%d\r\n", sn, multicast_ip[0], multicast_ip[1], multicast_ip[2], multicast_ip[3]);
|
||||||
|
printf("%d:Multicast Group Port - %d\r\n", sn, multicast_port);
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t multicast_recv(uint8_t sn, uint8_t* buf, uint8_t* multicast_ip, uint16_t multicast_port)
|
||||||
|
{
|
||||||
|
int32_t ret;
|
||||||
|
uint16_t size, port=3000;
|
||||||
|
uint8_t destip[4];
|
||||||
|
uint16_t destport;
|
||||||
|
|
||||||
|
switch(getSn_SR(sn))
|
||||||
|
{
|
||||||
|
case SOCK_UDP :
|
||||||
|
if((size = getSn_RX_RSR(sn)) > 0)
|
||||||
|
{
|
||||||
|
if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
|
||||||
|
ret = recvfrom(sn, buf, size, destip, (uint16_t*)&destport);
|
||||||
|
if(ret <= 0)
|
||||||
|
{
|
||||||
|
#ifdef _MULTICAST_DEBUG_
|
||||||
|
printf("%d: recvfrom error. %ld\r\n",sn,ret);
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
size = (uint16_t) ret;
|
||||||
|
#ifdef _MULTICAST_DEBUG_
|
||||||
|
printf("\r\nrecv size : %d\r\n", size);
|
||||||
|
for(int i=0; i<size; i++)
|
||||||
|
printf("%c", buf[i]);
|
||||||
|
printf("\r\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SOCK_CLOSED:
|
||||||
|
#ifdef _MULTICAST_DEBUG_
|
||||||
|
printf("%d:Multicast Recv start\r\n",sn);
|
||||||
|
#endif
|
||||||
|
setSn_DIPR(sn, multicast_ip);
|
||||||
|
setSn_DPORT(sn, multicast_port);
|
||||||
|
if((ret = socket(sn, Sn_MR_UDP, port, Sn_MR_MULTI)) != sn)
|
||||||
|
return ret;
|
||||||
|
#ifdef _MULTICAST_DEBUG_
|
||||||
|
printf("%d:Opened, UDP Multicast Socket\r\n", sn);
|
||||||
|
printf("%d:Multicast Group IP - %d.%d.%d.%d\r\n", sn, multicast_ip[0], multicast_ip[1], multicast_ip[2], multicast_ip[3]);
|
||||||
|
printf("%d:Multicast Group Port - %d\r\n", sn, multicast_port);
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
28
Application/multicast/multicast.h
Normal file
28
Application/multicast/multicast.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#ifndef _MULTICAST_H_
|
||||||
|
#define _MULTICAST_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/* Multicast test debug message printout enable */
|
||||||
|
#define _MULTICAST_DEBUG_
|
||||||
|
|
||||||
|
#ifndef DATA_BUF_SIZE
|
||||||
|
#define DATA_BUF_SIZE 2048
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* UDP Multicast Loopback test example */
|
||||||
|
int32_t multicast_loopback(uint8_t sn, uint8_t* buf, uint8_t* multicast_ip, uint16_t multicast_port);
|
||||||
|
|
||||||
|
/* UDP Multicast Recv test example */
|
||||||
|
int32_t multicast_recv(uint8_t sn, uint8_t* buf, uint8_t* multicast_ip, uint16_t multicast_port);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -42,7 +42,7 @@
|
|||||||
|
|
||||||
#if (_WIZCHIP_ == 5100)
|
#if (_WIZCHIP_ == 5100)
|
||||||
/**
|
/**
|
||||||
@brief This function writes the data into W5200 registers.
|
@brief This function writes the data into W5100 registers.
|
||||||
*/
|
*/
|
||||||
void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb )
|
void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb )
|
||||||
{
|
{
|
||||||
@ -76,7 +76,7 @@ void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb )
|
|||||||
WIZCHIP_CRITICAL_EXIT();
|
WIZCHIP_CRITICAL_EXIT();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@brief This function reads the value from W5200 registers.
|
@brief This function reads the value from W5100 registers.
|
||||||
*/
|
*/
|
||||||
uint8_t WIZCHIP_READ(uint32_t AddrSel)
|
uint8_t WIZCHIP_READ(uint32_t AddrSel)
|
||||||
{
|
{
|
||||||
@ -116,7 +116,7 @@ uint8_t WIZCHIP_READ(uint32_t AddrSel)
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief This function writes into W5200 memory(Buffer)
|
@brief This function writes into W5100 memory(Buffer)
|
||||||
*/
|
*/
|
||||||
void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len)
|
void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len)
|
||||||
{
|
{
|
||||||
@ -169,7 +169,7 @@ void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief This function reads into W5200 memory(Buffer)
|
@brief This function reads into W5100 memory(Buffer)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void WIZCHIP_READ_BUF (uint32_t AddrSel, uint8_t* pBuf, uint16_t len)
|
void WIZCHIP_READ_BUF (uint32_t AddrSel, uint8_t* pBuf, uint16_t len)
|
||||||
|
@ -40,6 +40,11 @@
|
|||||||
|
|
||||||
#ifndef _W5100_H_
|
#ifndef _W5100_H_
|
||||||
#define _W5100_H_
|
#define _W5100_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "wizchip_conf.h"
|
#include "wizchip_conf.h"
|
||||||
|
|
||||||
@ -1850,6 +1855,10 @@ void wiz_recv_ignore(uint8_t sn, uint16_t len);
|
|||||||
#endif
|
#endif
|
||||||
/// @endcond
|
/// @endcond
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif //_W5100_H_
|
#endif //_W5100_H_
|
||||||
|
|
||||||
|
|
||||||
|
425
Ethernet/W5100S/w5100s.c
Normal file
425
Ethernet/W5100S/w5100s.c
Normal file
@ -0,0 +1,425 @@
|
|||||||
|
//*****************************************************************************
|
||||||
|
//
|
||||||
|
//! \file w5100S.c
|
||||||
|
//! \brief W5100S HAL Interface.
|
||||||
|
//! \version 1.0.0
|
||||||
|
//! \date 2018/03/29
|
||||||
|
//! \par Revision history
|
||||||
|
//! <2018/03/29> 1st Release
|
||||||
|
//! \author Peter
|
||||||
|
//!
|
||||||
|
//! Copyright (c) 2013, WIZnet Co., LTD.
|
||||||
|
//! All rights reserved.
|
||||||
|
//!
|
||||||
|
//! Redistribution and use in source and binary forms, with or without
|
||||||
|
//! modification, are permitted provided that the following conditions
|
||||||
|
//! are met:
|
||||||
|
//!
|
||||||
|
//! * Redistributions of source code must retain the above copyright
|
||||||
|
//! notice, this list of conditions and the following disclaimer.
|
||||||
|
//! * Redistributions in binary form must reproduce the above copyright
|
||||||
|
//! notice, this list of conditions and the following disclaimer in the
|
||||||
|
//! documentation and/or other materials provided with the distribution.
|
||||||
|
//! * Neither the name of the <ORGANIZATION> nor the names of its
|
||||||
|
//! contributors may be used to endorse or promote products derived
|
||||||
|
//! from this software without specific prior written permission.
|
||||||
|
//!
|
||||||
|
//! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
//! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
//! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
//! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||||
|
//! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
//! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
//! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
//! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
//! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
//! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||||
|
//! THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
//*****************************************************************************
|
||||||
|
|
||||||
|
#include "w5100s.h"
|
||||||
|
|
||||||
|
#if (_WIZCHIP_ == W5100S)
|
||||||
|
/**
|
||||||
|
@brief This function writes the data into W5100S registers.
|
||||||
|
*/
|
||||||
|
void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb )
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
WIZCHIP_CRITICAL_ENTER();
|
||||||
|
WIZCHIP.CS._select();
|
||||||
|
|
||||||
|
#if( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_))
|
||||||
|
WIZCHIP.IF.SPI._write_byte(0xF0);
|
||||||
|
WIZCHIP.IF.SPI._write_byte((AddrSel & 0xFF00) >> 8);
|
||||||
|
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF) >> 0);
|
||||||
|
WIZCHIP.IF.SPI._write_byte(wb); // Data write (write 1byte data)
|
||||||
|
#elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_5500_) )
|
||||||
|
WIZCHIP.IF.SPI._write_byte((AddrSel & 0xFF00) >> 8);
|
||||||
|
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF) >> 0);
|
||||||
|
WIZCHIP.IF.SPI._write_byte(0xF0);
|
||||||
|
WIZCHIP.IF.SPI._write_byte(wb); // Data write (write 1byte data)
|
||||||
|
#elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) )
|
||||||
|
|
||||||
|
//add indirect bus
|
||||||
|
//M20150601 : Rename the function for integrating with ioLibrary
|
||||||
|
//WIZCHIP.IF.BUS._write_byte(IDM_AR0,(AddrSel & 0xFF00) >> 8);
|
||||||
|
//WIZCHIP.IF.BUS._write_byte(IDM_AR1,(AddrSel & 0x00FF));
|
||||||
|
//WIZCHIP.IF.BUS._write_byte(IDM_DR,wb);
|
||||||
|
WIZCHIP.IF.BUS._write_data(IDM_AR0,(AddrSel & 0xFF00) >> 8);
|
||||||
|
WIZCHIP.IF.BUS._write_data(IDM_AR1,(AddrSel & 0x00FF));
|
||||||
|
WIZCHIP.IF.BUS._write_data(IDM_DR,wb);
|
||||||
|
#else
|
||||||
|
#error "Unknown _WIZCHIP_IO_MODE_ in W5100. !!!"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
WIZCHIP.CS._deselect();
|
||||||
|
WIZCHIP_CRITICAL_EXIT();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
@brief This function reads the value from W5100S registers.
|
||||||
|
*/
|
||||||
|
uint8_t WIZCHIP_READ(uint32_t AddrSel)
|
||||||
|
{
|
||||||
|
uint8_t ret;
|
||||||
|
int i;
|
||||||
|
WIZCHIP_CRITICAL_ENTER();
|
||||||
|
WIZCHIP.CS._select();
|
||||||
|
|
||||||
|
#if( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_))
|
||||||
|
WIZCHIP.IF.SPI._write_byte(0x0F);
|
||||||
|
WIZCHIP.IF.SPI._write_byte((AddrSel & 0xFF00) >> 8);
|
||||||
|
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF) >> 0);
|
||||||
|
ret = WIZCHIP.IF.SPI._read_byte();
|
||||||
|
#elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_5500_) )
|
||||||
|
WIZCHIP.IF.SPI._write_byte((AddrSel & 0xFF00) >> 8);
|
||||||
|
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF) >> 0);
|
||||||
|
WIZCHIP.IF.SPI._write_byte(0x0F);
|
||||||
|
ret = WIZCHIP.IF.SPI._read_byte();
|
||||||
|
#elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) )
|
||||||
|
|
||||||
|
//add indirect bus
|
||||||
|
//M20150601 : Rename the function for integrating with ioLibrary
|
||||||
|
//WIZCHIP.IF.BUS._write_byte(IDM_AR0,(AddrSel & 0xFF00) >> 8);
|
||||||
|
//WIZCHIP.IF.BUS._write_byte(IDM_AR1,(AddrSel & 0x00FF));
|
||||||
|
//ret = WIZCHIP.IF.BUS._read_byte(IDM_DR);
|
||||||
|
WIZCHIP.IF.BUS._write_data(IDM_AR0,(AddrSel & 0xFF00) >> 8);
|
||||||
|
WIZCHIP.IF.BUS._write_data(IDM_AR1,(AddrSel & 0x00FF));
|
||||||
|
ret = WIZCHIP.IF.BUS._read_data(IDM_DR);
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error "Unknown _WIZCHIP_IO_MODE_ in W5100S. !!!"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
WIZCHIP.CS._deselect();
|
||||||
|
WIZCHIP_CRITICAL_EXIT();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief This function writes into W5100S memory(Buffer)
|
||||||
|
*/
|
||||||
|
void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len)
|
||||||
|
{
|
||||||
|
uint16_t i = 0;
|
||||||
|
int j,k,l;
|
||||||
|
WIZCHIP_CRITICAL_ENTER();
|
||||||
|
WIZCHIP.CS._select(); //M20150601 : Moved here.
|
||||||
|
|
||||||
|
#if((_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_))
|
||||||
|
|
||||||
|
WIZCHIP.IF.SPI._write_byte(0xF0);
|
||||||
|
WIZCHIP.IF.SPI._write_byte((((uint16_t)(AddrSel+i)) & 0xFF00) >> 8);
|
||||||
|
WIZCHIP.IF.SPI._write_byte((((uint16_t)(AddrSel+i)) & 0x00FF) >> 0);
|
||||||
|
|
||||||
|
for(i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
WIZCHIP.IF.SPI._write_byte(pBuf[i]); // Data write (write 1byte data)
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_5500_) )
|
||||||
|
|
||||||
|
WIZCHIP.IF.SPI._write_byte((((uint16_t)(AddrSel+i)) & 0xFF00) >> 8);
|
||||||
|
WIZCHIP.IF.SPI._write_byte((((uint16_t)(AddrSel+i)) & 0x00FF) >> 0);
|
||||||
|
WIZCHIP.IF.SPI._write_byte(0xF0);
|
||||||
|
|
||||||
|
for(i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
WIZCHIP.IF.SPI._write_byte(pBuf[i]); // Data write (write 1byte data)
|
||||||
|
}
|
||||||
|
#elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) )
|
||||||
|
//M20150601 : Rename the function for integrating with ioLibrary
|
||||||
|
/*
|
||||||
|
WIZCHIP_WRITE(MR,WIZCHIP_READ(MR) | MR_AI);
|
||||||
|
WIZCHIP.IF.BUS._write_byte(IDM_AR0,(AddrSel & 0xFF00) >> 8);
|
||||||
|
WIZCHIP.IF.BUS._write_byte(IDM_AR1,(AddrSel & 0x00FF));
|
||||||
|
for(i = 0 ; i < len; i++)
|
||||||
|
WIZCHIP.IF.BUS._write_byte(IDM_DR,pBuf[i]);
|
||||||
|
WIZCHIP_WRITE(MR, WIZCHIP_READ(MR) & ~MR_AI);
|
||||||
|
*/
|
||||||
|
setMR(getMR()|MR_AI);
|
||||||
|
WIZCHIP.IF.BUS._write_data(IDM_AR0,(AddrSel & 0xFF00) >> 8);
|
||||||
|
WIZCHIP.IF.BUS._write_data(IDM_AR1,(AddrSel & 0x00FF));
|
||||||
|
for(i = 0 ; i < len; i++)
|
||||||
|
WIZCHIP.IF.BUS._write_data(IDM_DR,pBuf[i]);
|
||||||
|
setMR(getMR() & ~MR_AI);
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error "Unknown _WIZCHIP_IO_MODE_ in W5100S. !!!!"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
WIZCHIP.CS._deselect(); //M20150601 : Moved here.
|
||||||
|
WIZCHIP_CRITICAL_EXIT();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief This function reads into W5100S memory(Buffer)
|
||||||
|
*/
|
||||||
|
|
||||||
|
void WIZCHIP_READ_BUF (uint32_t AddrSel, uint8_t* pBuf, uint16_t len)
|
||||||
|
{
|
||||||
|
uint16_t i = 0;
|
||||||
|
WIZCHIP_CRITICAL_ENTER();
|
||||||
|
WIZCHIP.CS._select(); //M20150601 : Moved here.
|
||||||
|
|
||||||
|
#if( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_) )
|
||||||
|
|
||||||
|
WIZCHIP.IF.SPI._write_byte(0x0F);
|
||||||
|
WIZCHIP.IF.SPI._write_byte((uint16_t)((AddrSel+i) & 0xFF00) >> 8);
|
||||||
|
WIZCHIP.IF.SPI._write_byte((uint16_t)((AddrSel+i) & 0x00FF) >> 0);
|
||||||
|
|
||||||
|
for(i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
pBuf[i] = WIZCHIP.IF.SPI._read_byte();
|
||||||
|
}
|
||||||
|
#elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_5500_) )
|
||||||
|
|
||||||
|
WIZCHIP.IF.SPI._write_byte((uint16_t)((AddrSel+i) & 0xFF00) >> 8);
|
||||||
|
WIZCHIP.IF.SPI._write_byte((uint16_t)((AddrSel+i) & 0x00FF) >> 0);
|
||||||
|
WIZCHIP.IF.SPI._write_byte(0x0F);
|
||||||
|
|
||||||
|
for(i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
pBuf[i] = WIZCHIP.IF.SPI._read_byte();
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) )
|
||||||
|
//M20150601 : Rename the function for integrating with ioLibrary
|
||||||
|
/*
|
||||||
|
WIZCHIP_WRITE(MR, WIZCHIP_READ(MR) | MR_AI);
|
||||||
|
WIZCHIP.IF.BUS._write_byte(IDM_AR0,(AddrSel & 0xFF00) >> 8);
|
||||||
|
WIZCHIP.IF.BUS._write_byte(IDM_AR1,(AddrSel & 0x00FF));
|
||||||
|
for(i = 0 ; i < len; i++)
|
||||||
|
pBuf[i] = WIZCHIP.IF.BUS._read_byte(IDM_DR);
|
||||||
|
WIZCHIP_WRITE(MR, WIZCHIP_READ(MR) & ~MR_AI);
|
||||||
|
*/
|
||||||
|
setMR(getMR() | MR_AI);
|
||||||
|
WIZCHIP.IF.BUS._write_data(IDM_AR0,(AddrSel & 0xFF00) >> 8);
|
||||||
|
WIZCHIP.IF.BUS._write_data(IDM_AR1,(AddrSel & 0x00FF));
|
||||||
|
for(i = 0 ; i < len; i++)
|
||||||
|
pBuf[i] = WIZCHIP.IF.BUS._read_data(IDM_DR);
|
||||||
|
setMR(getMR() & ~MR_AI);
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error "Unknown _WIZCHIP_IO_MODE_ in W5100S. !!!!"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
WIZCHIP.CS._deselect(); //M20150601 : Moved Here.
|
||||||
|
WIZCHIP_CRITICAL_EXIT();
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////
|
||||||
|
// Socket N regsiter IO function //
|
||||||
|
///////////////////////////////////
|
||||||
|
|
||||||
|
uint16_t getSn_TX_FSR(uint8_t sn)
|
||||||
|
{
|
||||||
|
uint16_t val=0,val1=0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
val1 = WIZCHIP_READ(Sn_TX_FSR(sn));
|
||||||
|
val1 = (val1 << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_FSR(sn),1));
|
||||||
|
if (val1 != 0)
|
||||||
|
{
|
||||||
|
val = WIZCHIP_READ(Sn_TX_FSR(sn));
|
||||||
|
val = (val << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_FSR(sn),1));
|
||||||
|
}
|
||||||
|
}while (val != val1);
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t getSn_RX_RSR(uint8_t sn)
|
||||||
|
{
|
||||||
|
uint16_t val=0,val1=0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
val1 = WIZCHIP_READ(Sn_RX_RSR(sn));
|
||||||
|
val1 = (val1 << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RSR(sn),1));
|
||||||
|
if (val1 != 0)
|
||||||
|
{
|
||||||
|
val = WIZCHIP_READ(Sn_RX_RSR(sn));
|
||||||
|
val = (val << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RSR(sn),1));
|
||||||
|
}
|
||||||
|
}while (val != val1);
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////
|
||||||
|
// Sn_TXBUF & Sn_RXBUF IO function //
|
||||||
|
/////////////////////////////////////
|
||||||
|
uint32_t getSn_RxBASE(uint8_t sn)
|
||||||
|
{
|
||||||
|
int8_t i;
|
||||||
|
#if ( _WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_DIR_)
|
||||||
|
uint32_t rxbase = _W5100S_IO_BASE_ + _WIZCHIP_IO_RXBUF_;
|
||||||
|
#else
|
||||||
|
uint32_t rxbase = _WIZCHIP_IO_RXBUF_;
|
||||||
|
#endif
|
||||||
|
for(i = 0; i < sn; i++)
|
||||||
|
rxbase += getSn_RxMAX(i);
|
||||||
|
|
||||||
|
return rxbase;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t getSn_TxBASE(uint8_t sn)
|
||||||
|
{
|
||||||
|
int8_t i;
|
||||||
|
#if ( _WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_DIR_)
|
||||||
|
uint32_t txbase = _W5100S_IO_BASE_ + _WIZCHIP_IO_TXBUF_;
|
||||||
|
#else
|
||||||
|
uint32_t txbase = _WIZCHIP_IO_TXBUF_;
|
||||||
|
#endif
|
||||||
|
for(i = 0; i < sn; i++)
|
||||||
|
txbase += getSn_TxMAX(i);
|
||||||
|
return txbase;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief This function is being called by send() and sendto() function also. for copy the data form application buffer to Transmite buffer of the chip.
|
||||||
|
|
||||||
|
This function read the Tx write pointer register and after copy the data in buffer update the Tx write pointer
|
||||||
|
register. User should read upper byte first and lower byte later to get proper value.
|
||||||
|
And this function is being used for copy the data form application buffer to Transmite
|
||||||
|
buffer of the chip. It calculate the actual physical address where one has to write
|
||||||
|
the data in transmite buffer. Here also take care of the condition while it exceed
|
||||||
|
the Tx memory uper-bound of socket.
|
||||||
|
|
||||||
|
*/
|
||||||
|
void wiz_send_data(uint8_t sn, uint8_t *wizdata, uint16_t len)
|
||||||
|
{
|
||||||
|
uint16_t ptr;
|
||||||
|
uint16_t size;
|
||||||
|
uint16_t dst_mask;
|
||||||
|
uint16_t dst_ptr;
|
||||||
|
|
||||||
|
ptr = getSn_TX_WR(sn);
|
||||||
|
|
||||||
|
dst_mask = ptr & getSn_TxMASK(sn);
|
||||||
|
dst_ptr = getSn_TxBASE(sn) + dst_mask;
|
||||||
|
|
||||||
|
if (dst_mask + len > getSn_TxMAX(sn))
|
||||||
|
{
|
||||||
|
size = getSn_TxMAX(sn) - dst_mask;
|
||||||
|
WIZCHIP_WRITE_BUF(dst_ptr, wizdata, size);
|
||||||
|
wizdata += size;
|
||||||
|
size = len - size;
|
||||||
|
dst_ptr = getSn_TxBASE(sn);
|
||||||
|
WIZCHIP_WRITE_BUF(dst_ptr, wizdata, size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WIZCHIP_WRITE_BUF(dst_ptr, wizdata, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr += len;
|
||||||
|
|
||||||
|
setSn_TX_WR(sn, ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief This function is being called by recv() also. This function is being used for copy the data form Receive buffer of the chip to application buffer.
|
||||||
|
|
||||||
|
This function read the Rx read pointer register
|
||||||
|
and after copy the data from receive buffer update the Rx write pointer register.
|
||||||
|
User should read upper byte first and lower byte later to get proper value.
|
||||||
|
It calculate the actual physical address where one has to read
|
||||||
|
the data from Receive buffer. Here also take care of the condition while it exceed
|
||||||
|
the Rx memory uper-bound of socket.
|
||||||
|
*/
|
||||||
|
void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint16_t len)
|
||||||
|
{
|
||||||
|
uint16_t ptr;
|
||||||
|
uint16_t size;
|
||||||
|
uint16_t src_mask;
|
||||||
|
uint16_t src_ptr;
|
||||||
|
|
||||||
|
ptr = getSn_RX_RD(sn);
|
||||||
|
|
||||||
|
src_mask = (uint32_t)ptr & getSn_RxMASK(sn);
|
||||||
|
src_ptr = (getSn_RxBASE(sn) + src_mask);
|
||||||
|
|
||||||
|
|
||||||
|
if( (src_mask + len) > getSn_RxMAX(sn) )
|
||||||
|
{
|
||||||
|
size = getSn_RxMAX(sn) - src_mask;
|
||||||
|
WIZCHIP_READ_BUF((uint32_t)src_ptr, (uint8_t*)wizdata, size);
|
||||||
|
wizdata += size;
|
||||||
|
size = len - size;
|
||||||
|
src_ptr = getSn_RxBASE(sn);
|
||||||
|
WIZCHIP_READ_BUF(src_ptr, (uint8_t*)wizdata, size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WIZCHIP_READ_BUF(src_ptr, (uint8_t*)wizdata, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr += len;
|
||||||
|
|
||||||
|
setSn_RX_RD(sn, ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wiz_recv_ignore(uint8_t sn, uint16_t len)
|
||||||
|
{
|
||||||
|
uint16_t ptr;
|
||||||
|
|
||||||
|
ptr = getSn_RX_RD(sn);
|
||||||
|
|
||||||
|
ptr += len;
|
||||||
|
setSn_RX_RD(sn,ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wiz_mdio_write(uint8_t PHYMDIO_regadr, uint16_t var)
|
||||||
|
{
|
||||||
|
WIZCHIP_WRITE(PHYRAR,PHYMDIO_regadr);
|
||||||
|
WIZCHIP_WRITE(PHYDIR, (uint8_t)(var >> 8));
|
||||||
|
WIZCHIP_WRITE(PHYDIR+1, (uint8_t)(var));
|
||||||
|
WIZCHIP_WRITE(PHYACR, PHYACR_WRITE);
|
||||||
|
while(WIZCHIP_READ(PHYACR)); //wait for command complete
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t wiz_mdio_read(uint8_t PHYMDIO_regadr)
|
||||||
|
{
|
||||||
|
WIZCHIP_WRITE(PHYRAR,PHYMDIO_regadr);
|
||||||
|
WIZCHIP_WRITE(PHYACR, PHYACR_READ);
|
||||||
|
while(WIZCHIP_READ(PHYACR)); //wait for command complete
|
||||||
|
return ((uint16_t)WIZCHIP_READ(PHYDOR) << 8) | WIZCHIP_READ(PHYDOR+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wiz_delay_ms(uint32_t milliseconds)
|
||||||
|
{
|
||||||
|
uint32_t i;
|
||||||
|
for(i = 0 ; i < milliseconds ; i++)
|
||||||
|
{
|
||||||
|
//Write any values to clear the TCNTCLKR register
|
||||||
|
setTCNTCLKR(0xff);
|
||||||
|
|
||||||
|
// Wait until counter register value reaches 10.(10 = 1ms : TCNTR is 100us tick counter register)
|
||||||
|
while(getTCNTR() < 0x0a){}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
3323
Ethernet/W5100S/w5100s.h
Normal file
3323
Ethernet/W5100S/w5100s.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -40,6 +40,11 @@
|
|||||||
|
|
||||||
#ifndef _W5200_H
|
#ifndef _W5200_H
|
||||||
#define _W5200_H
|
#define _W5200_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "wizchip_conf.h"
|
#include "wizchip_conf.h"
|
||||||
|
|
||||||
@ -2095,6 +2100,10 @@ void wiz_recv_ignore(uint8_t sn, uint16_t len);
|
|||||||
#endif
|
#endif
|
||||||
/// \endcond
|
/// \endcond
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif //_W5200_H_
|
#endif //_W5200_H_
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
#ifndef _W5300_H_
|
#ifndef _W5300_H_
|
||||||
#define _W5300_H_
|
#define _W5300_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
//*****************************************************************************
|
//*****************************************************************************
|
||||||
//
|
//
|
||||||
//! \file w5300.h
|
//! \file w5300.h
|
||||||
@ -900,16 +905,16 @@
|
|||||||
|
|
||||||
|
|
||||||
/************************************/
|
/************************************/
|
||||||
/* The bit of IR regsiter defintion */
|
/* The bit of IR regsiter definition */
|
||||||
/************************************/
|
/************************************/
|
||||||
#define IR_IPCF (1 << 15) /**< IP conflict bit of \ref IR. To clear, Write the bit to '1'. */
|
#define IR_IPCF (1 << 7) /**< IP conflict bit of \ref IR. To clear, Write the bit to '1'. */
|
||||||
#define IR_DPUR (1 << 14) /**< Destination port unreachable bit of \ref IR. To clear, Write the bit to '1'. */
|
#define IR_DPUR (1 << 6) /**< Destination port unreachable bit of \ref IR. To clear, Write the bit to '1'. */
|
||||||
#define IR_PPPT (1 << 13) /**< PPPoE terminate bit of \ref IR. To clear, Write the bit to '1'. */
|
#define IR_PPPT (1 << 5) /**< PPPoE terminate bit of \ref IR. To clear, Write the bit to '1'. */
|
||||||
#define IR_FMTU (1 << 12) /**< Fragment MTU bit of IR. To clear, Write the bit to '1'. */
|
#define IR_FMTU (1 << 4) /**< Fragment MTU bit of IR. To clear, Write the bit to '1'. */
|
||||||
#define IR_SnINT(n) (0x01 << n) /**< SOCKETn interrupt occurrence bit of \ref IR. To clear, Clear \ref Sn_IR*/
|
#define IR_SnINT(n) (0x01 << n) /**< SOCKETn interrupt occurrence bit of \ref IR. To clear, Clear \ref Sn_IR*/
|
||||||
|
|
||||||
/*****************************************/
|
/*****************************************/
|
||||||
/* The bit of Pn_BRDYR regsiter defintion*/
|
/* The bit of Pn_BRDYR regsiter definition*/
|
||||||
/*****************************************/
|
/*****************************************/
|
||||||
#define Pn_PEN (1 << 7) /**< PIN 'BRDYn' enable bit of Pn_BRDYR. */
|
#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_MT (1 << 6) /**< PIN memory type bit of Pn_BRDYR. */
|
||||||
@ -918,7 +923,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/***************************************/
|
/***************************************/
|
||||||
/* The bit of Sn_MR regsiter defintion */
|
/* The bit of Sn_MR regsiter definition */
|
||||||
/***************************************/
|
/***************************************/
|
||||||
/**
|
/**
|
||||||
* @brief Alignment bit of \ref Sn_MR.
|
* @brief Alignment bit of \ref Sn_MR.
|
||||||
@ -1015,7 +1020,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/******************************/
|
/******************************/
|
||||||
/* The values of CR defintion */
|
/* The values of CR definition */
|
||||||
/******************************/
|
/******************************/
|
||||||
/**
|
/**
|
||||||
* @brief Initialize or open a socket
|
* @brief Initialize or open a socket
|
||||||
@ -1115,7 +1120,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/*********************************/
|
/*********************************/
|
||||||
/* The values of Sn_IR defintion */
|
/* The values of Sn_IR definition */
|
||||||
/*********************************/
|
/*********************************/
|
||||||
#define Sn_IR_PRECV 0x80 /**< It is set in the case that option data which is not supported is received. Refer to \ref Sn_IR */
|
#define Sn_IR_PRECV 0x80 /**< It is set in the case that option data which is not supported is received. Refer to \ref Sn_IR */
|
||||||
#define Sn_IR_PFAIL 0x40 /**< It is set in the case that PAP authentication is failed. Refer to \ref Sn_IR */
|
#define Sn_IR_PFAIL 0x40 /**< It is set in the case that PAP authentication is failed. Refer to \ref Sn_IR */
|
||||||
@ -1127,7 +1132,7 @@
|
|||||||
#define Sn_IR_CON 0x01 /**< It is set one time when the connection is successful and then @ref Sn_SR is changed to @ref SOCK_ESTABLISHED. */
|
#define Sn_IR_CON 0x01 /**< It is set one time when the connection is successful and then @ref Sn_SR is changed to @ref SOCK_ESTABLISHED. */
|
||||||
|
|
||||||
/**********************************/
|
/**********************************/
|
||||||
/* The values of Sn_SSR defintion */
|
/* The values of Sn_SSR definition */
|
||||||
/**********************************/
|
/**********************************/
|
||||||
/**
|
/**
|
||||||
* @brief The state of SOCKET intialized or closed
|
* @brief The state of SOCKET intialized or closed
|
||||||
@ -1328,14 +1333,14 @@ void WIZCHIP_WRITE(uint32_t AddrSel, uint16_t wb );
|
|||||||
* @ingroup Common_register_access_function_W5300
|
* @ingroup Common_register_access_function_W5300
|
||||||
* @brief Set Mode Register
|
* @brief Set Mode Register
|
||||||
* @param (@ref iodata_t)mr The value to be set.
|
* @param (@ref iodata_t)mr The value to be set.
|
||||||
* @sa setMR()
|
* @sa getMR()
|
||||||
*/
|
*/
|
||||||
#if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_)
|
#if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_)
|
||||||
#if (_WIZCHIP_IO_BUS_WIDTH_ == 8)
|
#if (_WIZCHIP_IO_BUS_WIDTH_ == 8)
|
||||||
#define setMR(mr) \
|
#define setMR(mr) \
|
||||||
(*((uint8_t*)MR) = (uint8_t)((mr) >> 8)); (*((uint8_t*)WIZCHIP_OFFSET_INC(MR,1)) = (uint8_t)((mr) & 0xFF))
|
(*((uint8_t*)MR) = (uint8_t)((mr) >> 8)); (*((uint8_t*)WIZCHIP_OFFSET_INC(MR,1)) = (uint8_t)((mr) & 0xFF))
|
||||||
#elif (_WIZCHIP_IO_BUS_WIDTH_ == 16)
|
#elif (_WIZCHIP_IO_BUS_WIDTH_ == 16)
|
||||||
#define setMR(mr) (*((uint16_t*)MR)) = (uint16_t)((mr) & 0xFFFF))
|
#define setMR(mr) (*((uint16_t*)MR) = (uint16_t)((mr) & 0xFFFF))
|
||||||
#else
|
#else
|
||||||
#error "Unknown _WIZCHIP_IO_BUS_WIDTH_. You should be define _WIZCHIP_IO_BUS_WIDTH as 8 or 16."
|
#error "Unknown _WIZCHIP_IO_BUS_WIDTH_. You should be define _WIZCHIP_IO_BUS_WIDTH as 8 or 16."
|
||||||
#endif
|
#endif
|
||||||
@ -1343,11 +1348,11 @@ void WIZCHIP_WRITE(uint32_t AddrSel, uint16_t wb );
|
|||||||
#error "Unknown _WIZCHIP_IO_MODE_"
|
#error "Unknown _WIZCHIP_IO_MODE_"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup Common_register_access_function_W5300
|
* @ingroup Common_register_access_function_W5300
|
||||||
* @brief Get @ref MR.
|
* @brief Get @ref MR.
|
||||||
* @return @ref iodata_t. The value of Mode register.
|
* @return @ref iodata_t. The value of Mode register.
|
||||||
* @sa getMR()
|
* @sa setMR()
|
||||||
*/
|
*/
|
||||||
#if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_)
|
#if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_)
|
||||||
#if (_WIZCHIP_IO_BUS_WIDTH_ == 8)
|
#if (_WIZCHIP_IO_BUS_WIDTH_ == 8)
|
||||||
@ -1988,7 +1993,7 @@ uint8_t getRMSR(uint8_t sn);
|
|||||||
* @return uint16_t. Variable of @ref Sn_PORTR.
|
* @return uint16_t. Variable of @ref Sn_PORTR.
|
||||||
* @sa setSn_PORTR()
|
* @sa setSn_PORTR()
|
||||||
*/
|
*/
|
||||||
#define getSn_PORTR(sn, port) \
|
#define getSn_PORTR(sn) \
|
||||||
WIZCHIP_READ(Sn_PORTR(sn))
|
WIZCHIP_READ(Sn_PORTR(sn))
|
||||||
#define getSn_PORT(sn) getSn_PORTR(sn) ///< For compatible ioLibrary
|
#define getSn_PORT(sn) getSn_PORTR(sn) ///< For compatible ioLibrary
|
||||||
|
|
||||||
@ -2120,7 +2125,7 @@ uint8_t getRMSR(uint8_t sn);
|
|||||||
* @sa getSn_PROTOR()
|
* @sa getSn_PROTOR()
|
||||||
*/
|
*/
|
||||||
#define setSn_PROTOR(sn, proto) \
|
#define setSn_PROTOR(sn, proto) \
|
||||||
WIZCHIP_WRITE(Sn_PROTOR(sn),(WIZCHIP_READ(Sn_PROTOR(sn) & 0xFF00) | (((uint16_t)proto) & 0x00FF))
|
WIZCHIP_WRITE(Sn_PROTOR(sn),(WIZCHIP_READ(Sn_PROTOR(sn)) & 0xFF00) | (((uint16_t)proto) & 0x00FF))
|
||||||
#define setSn_PROTO(sn,proto) setSn_PROTOR(sn,proto) ///< For compatible ioLibrary
|
#define setSn_PROTO(sn,proto) setSn_PROTOR(sn,proto) ///< For compatible ioLibrary
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2242,7 +2247,7 @@ uint32_t getSn_RX_RSR(uint8_t sn);
|
|||||||
* @sa getSn_FRAGR()
|
* @sa getSn_FRAGR()
|
||||||
*/
|
*/
|
||||||
#define setSn_FRAGR(sn, frag) \
|
#define setSn_FRAGR(sn, frag) \
|
||||||
WIZCHIP_WRITE(Sn_FRAGR(sn), (uint16_t)(frag >>8))
|
WIZCHIP_WRITE(Sn_FRAGR(sn), ((uint16_t)frag) & 0x00FF)
|
||||||
#define setSn_FRAG(sn,frag) setSn_FRAGR(sn,flag)
|
#define setSn_FRAG(sn,frag) setSn_FRAGR(sn,flag)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2253,7 +2258,7 @@ uint32_t getSn_RX_RSR(uint8_t sn);
|
|||||||
* @sa setSn_FRAGR()
|
* @sa setSn_FRAGR()
|
||||||
*/
|
*/
|
||||||
#define getSn_FRAGR(sn) \
|
#define getSn_FRAGR(sn) \
|
||||||
(WIZCHIP_READ(Sn_FRAG(sn)) << 8)
|
(WIZCHIP_READ(Sn_FRAG(sn)))
|
||||||
#define getSn_FRAG(sn) getSn_FRAGR(sn)
|
#define getSn_FRAG(sn) getSn_FRAGR(sn)
|
||||||
|
|
||||||
|
|
||||||
@ -2324,4 +2329,8 @@ void wiz_recv_ignore(uint8_t sn, uint32_t len);
|
|||||||
#endif
|
#endif
|
||||||
/// \endcond
|
/// \endcond
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // _W5300_H_
|
#endif // _W5300_H_
|
||||||
|
@ -48,6 +48,10 @@
|
|||||||
#ifndef _W5500_H_
|
#ifndef _W5500_H_
|
||||||
#define _W5500_H_
|
#define _W5500_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "wizchip_conf.h"
|
#include "wizchip_conf.h"
|
||||||
|
|
||||||
@ -2152,4 +2156,8 @@ void wiz_recv_ignore(uint8_t sn, uint16_t len);
|
|||||||
#endif
|
#endif
|
||||||
/// @endcond
|
/// @endcond
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // _W5500_H_
|
#endif // _W5500_H_
|
||||||
|
@ -117,12 +117,13 @@ int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag)
|
|||||||
uint32_t taddr;
|
uint32_t taddr;
|
||||||
getSIPR((uint8_t*)&taddr);
|
getSIPR((uint8_t*)&taddr);
|
||||||
if(taddr == 0) return SOCKERR_SOCKINIT;
|
if(taddr == 0) return SOCKERR_SOCKINIT;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case Sn_MR_UDP :
|
case Sn_MR_UDP :
|
||||||
case Sn_MR_MACRAW :
|
case Sn_MR_MACRAW :
|
||||||
|
case Sn_MR_IPRAW :
|
||||||
break;
|
break;
|
||||||
#if ( _WIZCHIP_ < 5200 )
|
#if ( _WIZCHIP_ < 5200 )
|
||||||
case Sn_MR_IPRAW :
|
|
||||||
case Sn_MR_PPPoE :
|
case Sn_MR_PPPoE :
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
@ -203,7 +204,7 @@ int8_t close(uint8_t sn)
|
|||||||
//if( ((getSn_MR(s)& 0x0F) == Sn_MR_TCP) && (getSn_TX_FSR(s) != getSn_TxMAX(s)) )
|
//if( ((getSn_MR(s)& 0x0F) == Sn_MR_TCP) && (getSn_TX_FSR(s) != getSn_TxMAX(s)) )
|
||||||
if( ((getSn_MR(sn)& 0x0F) == Sn_MR_TCP) && (getSn_TX_FSR(sn) != getSn_TxMAX(sn)) )
|
if( ((getSn_MR(sn)& 0x0F) == Sn_MR_TCP) && (getSn_TX_FSR(sn) != getSn_TxMAX(sn)) )
|
||||||
{
|
{
|
||||||
uint8 destip[4] = {0, 0, 0, 1};
|
uint8_t destip[4] = {0, 0, 0, 1};
|
||||||
// TODO
|
// TODO
|
||||||
// You can wait for completing to sending data;
|
// You can wait for completing to sending data;
|
||||||
// wait about 1 second;
|
// wait about 1 second;
|
||||||
@ -496,9 +497,12 @@ int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t
|
|||||||
switch(getSn_MR(sn) & 0x0F)
|
switch(getSn_MR(sn) & 0x0F)
|
||||||
{
|
{
|
||||||
case Sn_MR_UDP:
|
case Sn_MR_UDP:
|
||||||
case Sn_MR_IPRAW:
|
|
||||||
case Sn_MR_MACRAW:
|
case Sn_MR_MACRAW:
|
||||||
|
// break;
|
||||||
|
// #if ( _WIZCHIP_ < 5200 )
|
||||||
|
case Sn_MR_IPRAW:
|
||||||
break;
|
break;
|
||||||
|
// #endif
|
||||||
default:
|
default:
|
||||||
return SOCKERR_SOCKMODE;
|
return SOCKERR_SOCKMODE;
|
||||||
}
|
}
|
||||||
@ -514,10 +518,14 @@ int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t
|
|||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
//if(*((uint32_t*)addr) == 0) return SOCKERR_IPINVALID;
|
//if(*((uint32_t*)addr) == 0) return SOCKERR_IPINVALID;
|
||||||
if((taddr == 0)&(getSn_MR(sn)&Sn_MR_MACRAW != Sn_MR_MACRAW)) return SOCKERR_IPINVALID;
|
if((taddr == 0) && ((getSn_MR(sn)&Sn_MR_MACRAW) != Sn_MR_MACRAW)) return SOCKERR_IPINVALID;
|
||||||
if((port == 0)&(getSn_MR(sn)&Sn_MR_MACRAW != Sn_MR_MACRAW)) return SOCKERR_PORTZERO;
|
if((port == 0) && ((getSn_MR(sn)&Sn_MR_MACRAW) != Sn_MR_MACRAW)) return SOCKERR_PORTZERO;
|
||||||
tmp = getSn_SR(sn);
|
tmp = getSn_SR(sn);
|
||||||
if(tmp != SOCK_MACRAW && tmp != SOCK_UDP && tmp != SOCK_IPRAW) return SOCKERR_SOCKSTATUS;
|
//#if ( _WIZCHIP_ < 5200 )
|
||||||
|
if((tmp != SOCK_MACRAW) && (tmp != SOCK_UDP) && (tmp != SOCK_IPRAW)) return SOCKERR_SOCKSTATUS;
|
||||||
|
//#else
|
||||||
|
// if(tmp != SOCK_MACRAW && tmp != SOCK_UDP) return SOCKERR_SOCKSTATUS;
|
||||||
|
//#endif
|
||||||
|
|
||||||
setSn_DIPR(sn,addr);
|
setSn_DIPR(sn,addr);
|
||||||
setSn_DPORT(sn,port);
|
setSn_DPORT(sn,port);
|
||||||
@ -606,10 +614,10 @@ int32_t recvfrom(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16
|
|||||||
switch((mr=getSn_MR(sn)) & 0x0F)
|
switch((mr=getSn_MR(sn)) & 0x0F)
|
||||||
{
|
{
|
||||||
case Sn_MR_UDP:
|
case Sn_MR_UDP:
|
||||||
|
case Sn_MR_IPRAW:
|
||||||
case Sn_MR_MACRAW:
|
case Sn_MR_MACRAW:
|
||||||
break;
|
break;
|
||||||
#if ( _WIZCHIP_ < 5200 )
|
#if ( _WIZCHIP_ < 5200 )
|
||||||
case Sn_MR_IPRAW:
|
|
||||||
case Sn_MR_PPPoE:
|
case Sn_MR_PPPoE:
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
@ -711,7 +719,7 @@ int32_t recvfrom(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16
|
|||||||
else pack_len = sock_remained_size[sn];
|
else pack_len = sock_remained_size[sn];
|
||||||
wiz_recv_data(sn,buf,pack_len);
|
wiz_recv_data(sn,buf,pack_len);
|
||||||
break;
|
break;
|
||||||
#if ( _WIZCHIP_ < 5200 )
|
//#if ( _WIZCHIP_ < 5200 )
|
||||||
case Sn_MR_IPRAW:
|
case Sn_MR_IPRAW:
|
||||||
if(sock_remained_size[sn] == 0)
|
if(sock_remained_size[sn] == 0)
|
||||||
{
|
{
|
||||||
@ -735,7 +743,7 @@ int32_t recvfrom(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16
|
|||||||
else pack_len = sock_remained_size[sn];
|
else pack_len = sock_remained_size[sn];
|
||||||
wiz_recv_data(sn, buf, pack_len); // data copy.
|
wiz_recv_data(sn, buf, pack_len); // data copy.
|
||||||
break;
|
break;
|
||||||
#endif
|
//#endif
|
||||||
default:
|
default:
|
||||||
wiz_recv_ignore(sn, pack_len); // data copy.
|
wiz_recv_ignore(sn, pack_len); // data copy.
|
||||||
sock_remained_size[sn] = pack_len;
|
sock_remained_size[sn] = pack_len;
|
||||||
@ -851,7 +859,7 @@ int8_t setsockopt(uint8_t sn, sockopt_type sotype, void* arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#if _WIZCHIP_ > 5200
|
#if !( (_WIZCHIP_ == 5100) || (_WIZCHIP_ == 5200) )
|
||||||
case SO_KEEPALIVEAUTO:
|
case SO_KEEPALIVEAUTO:
|
||||||
CHECK_SOCKMODE(Sn_MR_TCP);
|
CHECK_SOCKMODE(Sn_MR_TCP);
|
||||||
setSn_KPALVTR(sn,*(uint8_t*)arg);
|
setSn_KPALVTR(sn,*(uint8_t*)arg);
|
||||||
@ -879,7 +887,7 @@ int8_t getsockopt(uint8_t sn, sockopt_type sotype, void* arg)
|
|||||||
*(uint8_t*) arg = getSn_TOS(sn);
|
*(uint8_t*) arg = getSn_TOS(sn);
|
||||||
break;
|
break;
|
||||||
case SO_MSS:
|
case SO_MSS:
|
||||||
*(uint8_t*) arg = getSn_MSSR(sn);
|
*(uint16_t*) arg = getSn_MSSR(sn);
|
||||||
break;
|
break;
|
||||||
case SO_DESTIP:
|
case SO_DESTIP:
|
||||||
getSn_DIPR(sn, (uint8_t*)arg);
|
getSn_DIPR(sn, (uint8_t*)arg);
|
||||||
@ -903,13 +911,17 @@ int8_t getsockopt(uint8_t sn, sockopt_type sotype, void* arg)
|
|||||||
*(uint8_t*) arg = getSn_SR(sn);
|
*(uint8_t*) arg = getSn_SR(sn);
|
||||||
break;
|
break;
|
||||||
case SO_REMAINSIZE:
|
case SO_REMAINSIZE:
|
||||||
if(getSn_MR(sn) == Sn_MR_TCP)
|
if(getSn_MR(sn) & Sn_MR_TCP)
|
||||||
*(uint16_t*)arg = getSn_RX_RSR(sn);
|
*(uint16_t*)arg = getSn_RX_RSR(sn);
|
||||||
else
|
else
|
||||||
*(uint16_t*)arg = sock_remained_size[sn];
|
*(uint16_t*)arg = sock_remained_size[sn];
|
||||||
break;
|
break;
|
||||||
case SO_PACKINFO:
|
case SO_PACKINFO:
|
||||||
CHECK_SOCKMODE(Sn_MR_TCP);
|
//CHECK_SOCKMODE(Sn_MR_TCP);
|
||||||
|
#if _WIZCHIP_ != 5300
|
||||||
|
if((getSn_MR(sn) == Sn_MR_TCP))
|
||||||
|
return SOCKERR_SOCKMODE;
|
||||||
|
#endif
|
||||||
*(uint8_t*)arg = sock_pack_info[sn];
|
*(uint8_t*)arg = sock_pack_info[sn];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -84,6 +84,9 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef _SOCKET_H_
|
#ifndef _SOCKET_H_
|
||||||
#define _SOCKET_H_
|
#define _SOCKET_H_
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "wizchip_conf.h"
|
#include "wizchip_conf.h"
|
||||||
|
|
||||||
@ -387,7 +390,7 @@ typedef enum
|
|||||||
SO_DESTPORT, ///< Set the destination Port number. @ref Sn_DPORT ( @ref setSn_DPORT(), @ref getSn_DPORT() )
|
SO_DESTPORT, ///< Set the destination Port number. @ref Sn_DPORT ( @ref setSn_DPORT(), @ref getSn_DPORT() )
|
||||||
#if _WIZCHIP_ != 5100
|
#if _WIZCHIP_ != 5100
|
||||||
SO_KEEPALIVESEND, ///< Valid only in setsockopt. Manually send keep-alive packet in TCP mode, Not supported in W5100
|
SO_KEEPALIVESEND, ///< Valid only in setsockopt. Manually send keep-alive packet in TCP mode, Not supported in W5100
|
||||||
#if _WIZCHIP_ > 5200
|
#if !( (_WIZCHIP_ == 5100) || (_WIZCHIP_ == 5200) )
|
||||||
SO_KEEPALIVEAUTO, ///< Set/Get keep-alive auto transmission timer in TCP mode, Not supported in W5100, W5200
|
SO_KEEPALIVEAUTO, ///< Set/Get keep-alive auto transmission timer in TCP mode, Not supported in W5100, W5200
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@ -479,4 +482,8 @@ int8_t setsockopt(uint8_t sn, sockopt_type sotype, void* arg);
|
|||||||
*/
|
*/
|
||||||
int8_t getsockopt(uint8_t sn, sockopt_type sotype, void* arg);
|
int8_t getsockopt(uint8_t sn, sockopt_type sotype, void* arg);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // _SOCKET_H_
|
#endif // _SOCKET_H_
|
||||||
|
@ -80,7 +80,7 @@ void wizchip_cris_exit(void) {}
|
|||||||
* null function is called.
|
* null function is called.
|
||||||
*/
|
*/
|
||||||
//void wizchip_cs_select(void) {};
|
//void wizchip_cs_select(void) {};
|
||||||
void wizchip_cs_select(void) {}
|
__attribute__((weak)) void wizchip_cs_select(void) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Default function to deselect chip.
|
* @brief Default function to deselect chip.
|
||||||
@ -88,7 +88,7 @@ void wizchip_cs_select(void) {}
|
|||||||
* null function is called.
|
* null function is called.
|
||||||
*/
|
*/
|
||||||
//void wizchip_cs_deselect(void) {};
|
//void wizchip_cs_deselect(void) {};
|
||||||
void wizchip_cs_deselect(void) {}
|
__attribute__((weak)) void wizchip_cs_deselect(void) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Default function to read in direct or indirect interface.
|
* @brief Default function to read in direct or indirect interface.
|
||||||
@ -114,7 +114,7 @@ void wizchip_bus_writedata(uint32_t AddrSel, iodata_t wb) { *((volatile iodata
|
|||||||
* null function is called.
|
* null function is called.
|
||||||
*/
|
*/
|
||||||
//uint8_t wizchip_spi_readbyte(void) {return 0;};
|
//uint8_t wizchip_spi_readbyte(void) {return 0;};
|
||||||
uint8_t wizchip_spi_readbyte(void) {return 0;}
|
__attribute__((weak)) uint8_t wizchip_spi_readbyte(void) {return 0;}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Default function to write in SPI interface.
|
* @brief Default function to write in SPI interface.
|
||||||
@ -122,7 +122,7 @@ uint8_t wizchip_spi_readbyte(void) {return 0;}
|
|||||||
* null function is called.
|
* null function is called.
|
||||||
*/
|
*/
|
||||||
//void wizchip_spi_writebyte(uint8_t wb) {};
|
//void wizchip_spi_writebyte(uint8_t wb) {};
|
||||||
void wizchip_spi_writebyte(uint8_t wb) {}
|
__attribute__((weak)) void wizchip_spi_writebyte(uint8_t wb) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Default function to burst read in SPI interface.
|
* @brief Default function to burst read in SPI interface.
|
||||||
@ -130,7 +130,7 @@ void wizchip_spi_writebyte(uint8_t wb) {}
|
|||||||
* null function is called.
|
* null function is called.
|
||||||
*/
|
*/
|
||||||
//void wizchip_spi_readburst(uint8_t* pBuf, uint16_t len) {};
|
//void wizchip_spi_readburst(uint8_t* pBuf, uint16_t len) {};
|
||||||
void wizchip_spi_readburst(uint8_t* pBuf, uint16_t len) {}
|
__attribute__((weak)) void wizchip_spi_readburst(uint8_t* pBuf, uint16_t len) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Default function to burst write in SPI interface.
|
* @brief Default function to burst write in SPI interface.
|
||||||
@ -138,7 +138,7 @@ void wizchip_spi_readburst(uint8_t* pBuf, uint16_t len) {}
|
|||||||
* null function is called.
|
* null function is called.
|
||||||
*/
|
*/
|
||||||
//void wizchip_spi_writeburst(uint8_t* pBuf, uint16_t len) {};
|
//void wizchip_spi_writeburst(uint8_t* pBuf, uint16_t len) {};
|
||||||
void wizchip_spi_writeburst(uint8_t* pBuf, uint16_t len) {}
|
__attribute__((weak)) void wizchip_spi_writeburst(uint8_t* pBuf, uint16_t len) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @\ref _WIZCHIP instance
|
* @\ref _WIZCHIP instance
|
||||||
@ -163,21 +163,28 @@ _WIZCHIP WIZCHIP =
|
|||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
_WIZCHIP WIZCHIP =
|
_WIZCHIP WIZCHIP =
|
||||||
{
|
{
|
||||||
_WIZCHIP_IO_MODE_,
|
_WIZCHIP_IO_MODE_,
|
||||||
_WIZCHIP_ID_ ,
|
_WIZCHIP_ID_ ,
|
||||||
|
{
|
||||||
wizchip_cris_enter,
|
wizchip_cris_enter,
|
||||||
wizchip_cris_exit,
|
wizchip_cris_exit
|
||||||
|
},
|
||||||
|
{
|
||||||
wizchip_cs_select,
|
wizchip_cs_select,
|
||||||
wizchip_cs_deselect,
|
wizchip_cs_deselect
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{
|
||||||
//M20150601 : Rename the function
|
//M20150601 : Rename the function
|
||||||
//wizchip_bus_readbyte,
|
//wizchip_bus_readbyte,
|
||||||
//wizchip_bus_writebyte
|
//wizchip_bus_writebyte
|
||||||
wizchip_bus_readdata,
|
wizchip_bus_readdata,
|
||||||
wizchip_bus_writedata,
|
wizchip_bus_writedata
|
||||||
// wizchip_spi_readbyte,
|
},
|
||||||
// wizchip_spi_writebyte
|
|
||||||
};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
static uint8_t _DNS_[4]; // DNS server ip address
|
static uint8_t _DNS_[4]; // DNS server ip address
|
||||||
@ -276,7 +283,7 @@ void reg_wizchip_spiburst_cbfunc(void (*spi_rb)(uint8_t* pBuf, uint16_t len), vo
|
|||||||
|
|
||||||
int8_t ctlwizchip(ctlwizchip_type cwtype, void* arg)
|
int8_t ctlwizchip(ctlwizchip_type cwtype, void* arg)
|
||||||
{
|
{
|
||||||
#if _WIZCHIP_ == 5200 || _WIZCHIP_ == 5500
|
#if _WIZCHIP_ == W5100S || _WIZCHIP_ == W5200 || _WIZCHIP_ == W5500
|
||||||
uint8_t tmp = 0;
|
uint8_t tmp = 0;
|
||||||
#endif
|
#endif
|
||||||
uint8_t* ptmp[2] = {0,0};
|
uint8_t* ptmp[2] = {0,0};
|
||||||
@ -305,8 +312,8 @@ int8_t ctlwizchip(ctlwizchip_type cwtype, void* arg)
|
|||||||
*((intr_kind*)arg) = wizchip_getinterruptmask();
|
*((intr_kind*)arg) = wizchip_getinterruptmask();
|
||||||
break;
|
break;
|
||||||
//M20150601 : This can be supported by W5200, W5500
|
//M20150601 : This can be supported by W5200, W5500
|
||||||
//#if _WIZCHIP_ > 5100
|
//#if _WIZCHIP_ > W5100
|
||||||
#if (_WIZCHIP_ == 5200 || _WIZCHIP_ == 5500)
|
#if (_WIZCHIP_ == W5200 || _WIZCHIP_ == W5500)
|
||||||
case CW_SET_INTRTIME:
|
case CW_SET_INTRTIME:
|
||||||
setINTLEVEL(*(uint16_t*)arg);
|
setINTLEVEL(*(uint16_t*)arg);
|
||||||
break;
|
break;
|
||||||
@ -322,7 +329,7 @@ int8_t ctlwizchip(ctlwizchip_type cwtype, void* arg)
|
|||||||
((uint8_t*)arg)[4] = WIZCHIP.id[4];
|
((uint8_t*)arg)[4] = WIZCHIP.id[4];
|
||||||
((uint8_t*)arg)[5] = 0;
|
((uint8_t*)arg)[5] = 0;
|
||||||
break;
|
break;
|
||||||
#if _WIZCHIP_ == 5500
|
#if _WIZCHIP_ == W5100S || _WIZCHIP_ == W5500
|
||||||
case CW_RESET_PHY:
|
case CW_RESET_PHY:
|
||||||
wizphy_reset();
|
wizphy_reset();
|
||||||
break;
|
break;
|
||||||
@ -337,7 +344,7 @@ int8_t ctlwizchip(ctlwizchip_type cwtype, void* arg)
|
|||||||
case CW_SET_PHYPOWMODE:
|
case CW_SET_PHYPOWMODE:
|
||||||
return wizphy_setphypmode(*(uint8_t*)arg);
|
return wizphy_setphypmode(*(uint8_t*)arg);
|
||||||
#endif
|
#endif
|
||||||
#if _WIZCHIP_ == 5200 || _WIZCHIP_ == 5500
|
#if _WIZCHIP_ == W5100S || _WIZCHIP_ == W5200 || _WIZCHIP_ == W5500
|
||||||
case CW_GET_PHYPOWMODE:
|
case CW_GET_PHYPOWMODE:
|
||||||
tmp = wizphy_getphypmode();
|
tmp = wizphy_getphypmode();
|
||||||
if((int8_t)tmp == -1) return -1;
|
if((int8_t)tmp == -1) return -1;
|
||||||
@ -412,13 +419,16 @@ void wizchip_sw_reset(void)
|
|||||||
int8_t wizchip_init(uint8_t* txsize, uint8_t* rxsize)
|
int8_t wizchip_init(uint8_t* txsize, uint8_t* rxsize)
|
||||||
{
|
{
|
||||||
int8_t i;
|
int8_t i;
|
||||||
|
#if _WIZCHIP_ < W5200
|
||||||
|
int8_t j;
|
||||||
|
#endif
|
||||||
int8_t tmp = 0;
|
int8_t tmp = 0;
|
||||||
wizchip_sw_reset();
|
wizchip_sw_reset();
|
||||||
if(txsize)
|
if(txsize)
|
||||||
{
|
{
|
||||||
tmp = 0;
|
tmp = 0;
|
||||||
//M20150601 : For integrating with W5300
|
//M20150601 : For integrating with W5300
|
||||||
#if _WIZCHIP_ == 5300
|
#if _WIZCHIP_ == W5300
|
||||||
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
||||||
{
|
{
|
||||||
if(txsize[i] >= 64) return -1; //No use 64KB even if W5300 support max 64KB memory allocation
|
if(txsize[i] >= 64) return -1; //No use 64KB even if W5300 support max 64KB memory allocation
|
||||||
@ -430,16 +440,31 @@ int8_t wizchip_init(uint8_t* txsize, uint8_t* rxsize)
|
|||||||
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
||||||
{
|
{
|
||||||
tmp += txsize[i];
|
tmp += txsize[i];
|
||||||
|
|
||||||
|
#if _WIZCHIP_ < W5200 //2016.10.28 peter add condition for w5100 and w5100s
|
||||||
|
if(tmp > 8) return -1;
|
||||||
|
#else
|
||||||
if(tmp > 16) return -1;
|
if(tmp > 16) return -1;
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
|
||||||
setSn_TXBUF_SIZE(i, txsize[i]);
|
|
||||||
}
|
}
|
||||||
|
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
||||||
|
{
|
||||||
|
#if _WIZCHIP_ < W5200 //2016.10.28 peter add condition for w5100
|
||||||
|
j = 0;
|
||||||
|
while((txsize[i] >> j != 1)&&(txsize[i] !=0)){j++;}
|
||||||
|
setSn_TXBUF_SIZE(i, j);
|
||||||
|
#else
|
||||||
|
setSn_TXBUF_SIZE(i, txsize[i]);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if(rxsize)
|
if(rxsize)
|
||||||
{
|
{
|
||||||
tmp = 0;
|
tmp = 0;
|
||||||
#if _WIZCHIP_ == 5300
|
#if _WIZCHIP_ == W5300
|
||||||
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
||||||
{
|
{
|
||||||
if(rxsize[i] >= 64) return -1; //No use 64KB even if W5300 support max 64KB memory allocation
|
if(rxsize[i] >= 64) return -1; //No use 64KB even if W5300 support max 64KB memory allocation
|
||||||
@ -451,12 +476,24 @@ int8_t wizchip_init(uint8_t* txsize, uint8_t* rxsize)
|
|||||||
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
||||||
{
|
{
|
||||||
tmp += rxsize[i];
|
tmp += rxsize[i];
|
||||||
|
#if _WIZCHIP_ < W5200 //2016.10.28 peter add condition for w5100 and w5100s
|
||||||
|
if(tmp > 8) return -1;
|
||||||
|
#else
|
||||||
if(tmp > 16) return -1;
|
if(tmp > 16) return -1;
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
||||||
|
{
|
||||||
|
#if _WIZCHIP_ < W5200 // add condition for w5100
|
||||||
|
j = 0;
|
||||||
|
while((rxsize[i] >> j != 1)&&(txsize[i] !=0)){j++;}
|
||||||
|
setSn_RXBUF_SIZE(i, j);
|
||||||
|
#else
|
||||||
setSn_RXBUF_SIZE(i, rxsize[i]);
|
setSn_RXBUF_SIZE(i, rxsize[i]);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -465,26 +502,31 @@ void wizchip_clrinterrupt(intr_kind intr)
|
|||||||
{
|
{
|
||||||
uint8_t ir = (uint8_t)intr;
|
uint8_t ir = (uint8_t)intr;
|
||||||
uint8_t sir = (uint8_t)((uint16_t)intr >> 8);
|
uint8_t sir = (uint8_t)((uint16_t)intr >> 8);
|
||||||
#if _WIZCHIP_ < 5500
|
#if _WIZCHIP_ < W5500
|
||||||
ir |= (1<<4); // IK_WOL
|
ir |= (1<<4); // IK_WOL
|
||||||
#endif
|
#endif
|
||||||
#if _WIZCHIP_ == 5200
|
#if _WIZCHIP_ == W5200
|
||||||
ir |= (1 << 6);
|
ir |= (1 << 6);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if _WIZCHIP_ < 5200
|
#if _WIZCHIP_ < W5200
|
||||||
sir &= 0x0F;
|
sir &= 0x0F;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if _WIZCHIP_ == 5100
|
#if _WIZCHIP_ <= W5100S
|
||||||
ir |= sir;
|
ir |= sir;
|
||||||
setIR(ir);
|
setIR(ir);
|
||||||
//A20150601 : For integrating with W5300
|
//A20150601 : For integrating with W5300
|
||||||
#elif _WIZCHIP_ == 5300
|
#elif _WIZCHIP_ == W5300
|
||||||
setIR( ((((uint16_t)ir) << 8) | (((uint16_t)sir) & 0x00FF)) );
|
setIR( ((((uint16_t)ir) << 8) | (((uint16_t)sir) & 0x00FF)) );
|
||||||
#else
|
#else
|
||||||
setIR(ir);
|
setIR(ir);
|
||||||
setSIR(sir);
|
//M20200227 : For clear
|
||||||
|
//setSIR(sir);
|
||||||
|
for(ir=0; ir<8; ir++){
|
||||||
|
if(sir & (0x01 <<ir) ) setSn_IR(ir, 0xff);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -493,11 +535,11 @@ intr_kind wizchip_getinterrupt(void)
|
|||||||
uint8_t ir = 0;
|
uint8_t ir = 0;
|
||||||
uint8_t sir = 0;
|
uint8_t sir = 0;
|
||||||
uint16_t ret = 0;
|
uint16_t ret = 0;
|
||||||
#if _WIZCHIP_ == 5100
|
#if _WIZCHIP_ <= W5100S
|
||||||
ir = getIR();
|
ir = getIR();
|
||||||
sir = ir & 0x0F;
|
sir = ir & 0x0F;
|
||||||
//A20150601 : For integrating with W5300
|
//A20150601 : For integrating with W5300
|
||||||
#elif _WIZCHIP_ == 5300
|
#elif _WIZCHIP_ == W5300
|
||||||
ret = getIR();
|
ret = getIR();
|
||||||
ir = (uint8_t)(ret >> 8);
|
ir = (uint8_t)(ret >> 8);
|
||||||
sir = (uint8_t)ret;
|
sir = (uint8_t)ret;
|
||||||
@ -507,11 +549,11 @@ intr_kind wizchip_getinterrupt(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//M20150601 : For Integrating with W5300
|
//M20150601 : For Integrating with W5300
|
||||||
//#if _WIZCHIP_ < 5500
|
//#if _WIZCHIP_ < W5500
|
||||||
#if _WIZCHIP_ < 5200
|
#if _WIZCHIP_ < W5200
|
||||||
ir &= ~(1<<4); // IK_WOL
|
ir &= ~(1<<4); // IK_WOL
|
||||||
#endif
|
#endif
|
||||||
#if _WIZCHIP_ == 5200
|
#if _WIZCHIP_ == W5200
|
||||||
ir &= ~(1 << 6);
|
ir &= ~(1 << 6);
|
||||||
#endif
|
#endif
|
||||||
ret = sir;
|
ret = sir;
|
||||||
@ -523,19 +565,19 @@ void wizchip_setinterruptmask(intr_kind intr)
|
|||||||
{
|
{
|
||||||
uint8_t imr = (uint8_t)intr;
|
uint8_t imr = (uint8_t)intr;
|
||||||
uint8_t simr = (uint8_t)((uint16_t)intr >> 8);
|
uint8_t simr = (uint8_t)((uint16_t)intr >> 8);
|
||||||
#if _WIZCHIP_ < 5500
|
#if _WIZCHIP_ < W5500
|
||||||
imr &= ~(1<<4); // IK_WOL
|
imr &= ~(1<<4); // IK_WOL
|
||||||
#endif
|
#endif
|
||||||
#if _WIZCHIP_ == 5200
|
#if _WIZCHIP_ == W5200
|
||||||
imr &= ~(1 << 6);
|
imr &= ~(1 << 6);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if _WIZCHIP_ == 5100
|
#if _WIZCHIP_ < W5200
|
||||||
simr &= 0x0F;
|
simr &= 0x0F;
|
||||||
imr |= simr;
|
imr |= simr;
|
||||||
setIMR(imr);
|
setIMR(imr);
|
||||||
//A20150601 : For integrating with W5300
|
//A20150601 : For integrating with W5300
|
||||||
#elif _WIZCHIP_ == 5300
|
#elif _WIZCHIP_ == W5300
|
||||||
setIMR( ((((uint16_t)imr) << 8) | (((uint16_t)simr) & 0x00FF)) );
|
setIMR( ((((uint16_t)imr) << 8) | (((uint16_t)simr) & 0x00FF)) );
|
||||||
#else
|
#else
|
||||||
setIMR(imr);
|
setIMR(imr);
|
||||||
@ -548,11 +590,11 @@ intr_kind wizchip_getinterruptmask(void)
|
|||||||
uint8_t imr = 0;
|
uint8_t imr = 0;
|
||||||
uint8_t simr = 0;
|
uint8_t simr = 0;
|
||||||
uint16_t ret = 0;
|
uint16_t ret = 0;
|
||||||
#if _WIZCHIP_ == 5100
|
#if _WIZCHIP_ < W5200
|
||||||
imr = getIMR();
|
imr = getIMR();
|
||||||
simr = imr & 0x0F;
|
simr = imr & 0x0F;
|
||||||
//A20150601 : For integrating with W5300
|
//A20150601 : For integrating with W5300
|
||||||
#elif _WIZCHIP_ == 5300
|
#elif _WIZCHIP_ == W5300
|
||||||
ret = getIMR();
|
ret = getIMR();
|
||||||
imr = (uint8_t)(ret >> 8);
|
imr = (uint8_t)(ret >> 8);
|
||||||
simr = (uint8_t)ret;
|
simr = (uint8_t)ret;
|
||||||
@ -561,10 +603,10 @@ intr_kind wizchip_getinterruptmask(void)
|
|||||||
simr = getSIMR();
|
simr = getSIMR();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if _WIZCHIP_ < 5500
|
#if _WIZCHIP_ < W5500
|
||||||
imr &= ~(1<<4); // IK_WOL
|
imr &= ~(1<<4); // IK_WOL
|
||||||
#endif
|
#endif
|
||||||
#if _WIZCHIP_ == 5200
|
#if _WIZCHIP_ == W5200
|
||||||
imr &= ~(1 << 6); // IK_DEST_UNREACH
|
imr &= ~(1 << 6); // IK_DEST_UNREACH
|
||||||
#endif
|
#endif
|
||||||
ret = simr;
|
ret = simr;
|
||||||
@ -574,35 +616,35 @@ intr_kind wizchip_getinterruptmask(void)
|
|||||||
|
|
||||||
int8_t wizphy_getphylink(void)
|
int8_t wizphy_getphylink(void)
|
||||||
{
|
{
|
||||||
int8_t tmp;
|
int8_t tmp = PHY_LINK_OFF;
|
||||||
#if _WIZCHIP_ == 5200
|
#if _WIZCHIP_ == W5100S
|
||||||
|
if(getPHYSR() & PHYSR_LNK)
|
||||||
|
tmp = PHY_LINK_ON;
|
||||||
|
#elif _WIZCHIP_ == W5200
|
||||||
if(getPHYSTATUS() & PHYSTATUS_LINK)
|
if(getPHYSTATUS() & PHYSTATUS_LINK)
|
||||||
tmp = PHY_LINK_ON;
|
tmp = PHY_LINK_ON;
|
||||||
else
|
#elif _WIZCHIP_ == W5500
|
||||||
tmp = PHY_LINK_OFF;
|
|
||||||
#elif _WIZCHIP_ == 5500
|
|
||||||
if(getPHYCFGR() & PHYCFGR_LNK_ON)
|
if(getPHYCFGR() & PHYCFGR_LNK_ON)
|
||||||
tmp = PHY_LINK_ON;
|
tmp = PHY_LINK_ON;
|
||||||
else
|
|
||||||
tmp = PHY_LINK_OFF;
|
|
||||||
#else
|
#else
|
||||||
tmp = -1;
|
tmp = -1;
|
||||||
#endif
|
#endif
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if _WIZCHIP_ > 5100
|
#if _WIZCHIP_ > W5100
|
||||||
|
|
||||||
int8_t wizphy_getphypmode(void)
|
int8_t wizphy_getphypmode(void)
|
||||||
{
|
{
|
||||||
int8_t tmp = 0;
|
int8_t tmp = 0;
|
||||||
#if _WIZCHIP_ == 5200
|
#if _WIZCHIP_ == W5200
|
||||||
if(getPHYSTATUS() & PHYSTATUS_POWERDOWN)
|
if(getPHYSTATUS() & PHYSTATUS_POWERDOWN)
|
||||||
tmp = PHY_POWER_DOWN;
|
tmp = PHY_POWER_DOWN;
|
||||||
else
|
else
|
||||||
tmp = PHY_POWER_NORM;
|
tmp = PHY_POWER_NORM;
|
||||||
#elif _WIZCHIP_ == 5500
|
#elif _WIZCHIP_ == 5500
|
||||||
if(getPHYCFGR() & PHYCFGR_OPMDC_PDOWN)
|
if((getPHYCFGR() & PHYCFGR_OPMDC_ALLA) == PHYCFGR_OPMDC_PDOWN)
|
||||||
tmp = PHY_POWER_DOWN;
|
tmp = PHY_POWER_DOWN;
|
||||||
else
|
else
|
||||||
tmp = PHY_POWER_NORM;
|
tmp = PHY_POWER_NORM;
|
||||||
@ -613,7 +655,89 @@ int8_t wizphy_getphypmode(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if _WIZCHIP_ == 5500
|
#if _WIZCHIP_ == W5100S
|
||||||
|
void wizphy_reset(void)
|
||||||
|
{
|
||||||
|
uint16_t tmp = wiz_mdio_read(PHYMDIO_BMCR);
|
||||||
|
tmp |= BMCR_RESET;
|
||||||
|
wiz_mdio_write(PHYMDIO_BMCR, tmp);
|
||||||
|
while(wiz_mdio_read(PHYMDIO_BMCR)&BMCR_RESET){}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wizphy_setphyconf(wiz_PhyConf* phyconf)
|
||||||
|
{
|
||||||
|
uint16_t tmp = wiz_mdio_read(PHYMDIO_BMCR);
|
||||||
|
if(phyconf->mode == PHY_MODE_AUTONEGO)
|
||||||
|
tmp |= BMCR_AUTONEGO;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tmp &= ~BMCR_AUTONEGO;
|
||||||
|
if(phyconf->duplex == PHY_DUPLEX_FULL)
|
||||||
|
{
|
||||||
|
tmp |= BMCR_DUP;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tmp &= ~BMCR_DUP;
|
||||||
|
}
|
||||||
|
if(phyconf->speed == PHY_SPEED_100)
|
||||||
|
{
|
||||||
|
tmp |= BMCR_SPEED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tmp &= ~BMCR_SPEED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wiz_mdio_write(PHYMDIO_BMCR, tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wizphy_getphyconf(wiz_PhyConf* phyconf)
|
||||||
|
{
|
||||||
|
uint16_t tmp = 0;
|
||||||
|
tmp = wiz_mdio_read(PHYMDIO_BMCR);
|
||||||
|
phyconf->by = PHY_CONFBY_SW;
|
||||||
|
if(tmp & BMCR_AUTONEGO)
|
||||||
|
{
|
||||||
|
phyconf->mode = PHY_MODE_AUTONEGO;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
phyconf->mode = PHY_MODE_MANUAL;
|
||||||
|
if(tmp&BMCR_DUP) phyconf->duplex = PHY_DUPLEX_FULL;
|
||||||
|
else phyconf->duplex = PHY_DUPLEX_HALF;
|
||||||
|
if(tmp&BMCR_SPEED) phyconf->speed = PHY_SPEED_100;
|
||||||
|
else phyconf->speed = PHY_SPEED_10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int8_t wizphy_setphypmode(uint8_t pmode)
|
||||||
|
{
|
||||||
|
uint16_t tmp = 0;
|
||||||
|
tmp = wiz_mdio_read(PHYMDIO_BMCR);
|
||||||
|
if( pmode == PHY_POWER_DOWN)
|
||||||
|
{
|
||||||
|
tmp |= BMCR_PWDN;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tmp &= ~BMCR_PWDN;
|
||||||
|
}
|
||||||
|
wiz_mdio_write(PHYMDIO_BMCR, tmp);
|
||||||
|
tmp = wiz_mdio_read(PHYMDIO_BMCR);
|
||||||
|
if( pmode == PHY_POWER_DOWN)
|
||||||
|
{
|
||||||
|
if(tmp & BMCR_PWDN) return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if((tmp & BMCR_PWDN) != BMCR_PWDN) return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if _WIZCHIP_ == W5500
|
||||||
void wizphy_reset(void)
|
void wizphy_reset(void)
|
||||||
{
|
{
|
||||||
uint8_t tmp = getPHYCFGR();
|
uint8_t tmp = getPHYCFGR();
|
||||||
@ -755,7 +879,7 @@ void wizchip_getnetinfo(wiz_NetInfo* pnetinfo)
|
|||||||
int8_t wizchip_setnetmode(netmode_type netmode)
|
int8_t wizchip_setnetmode(netmode_type netmode)
|
||||||
{
|
{
|
||||||
uint8_t tmp = 0;
|
uint8_t tmp = 0;
|
||||||
#if _WIZCHIP_ != 5500
|
#if _WIZCHIP_ != W5500
|
||||||
if(netmode & ~(NM_WAKEONLAN | NM_PPPOE | NM_PINGBLOCK)) return -1;
|
if(netmode & ~(NM_WAKEONLAN | NM_PPPOE | NM_PINGBLOCK)) return -1;
|
||||||
#else
|
#else
|
||||||
if(netmode & ~(NM_WAKEONLAN | NM_PPPOE | NM_PINGBLOCK | NM_FORCEARP)) return -1;
|
if(netmode & ~(NM_WAKEONLAN | NM_PPPOE | NM_PINGBLOCK | NM_FORCEARP)) return -1;
|
||||||
|
@ -54,14 +54,29 @@
|
|||||||
#ifndef _WIZCHIP_CONF_H_
|
#ifndef _WIZCHIP_CONF_H_
|
||||||
#define _WIZCHIP_CONF_H_
|
#define _WIZCHIP_CONF_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
/**
|
/**
|
||||||
* @brief Select WIZCHIP.
|
* @brief Select WIZCHIP.
|
||||||
* @todo You should select one, \b 5100, \b 5200, \b 5300, \b 5500 or etc. \n\n
|
* @todo You should select one, \b W5100, \b W5100S, \b W5200, \b W5300, \b W5500 or etc. \n\n
|
||||||
* ex> <code> #define \_WIZCHIP_ 5500 </code>
|
* ex> <code> #define \_WIZCHIP_ W5500 </code>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define W5100 5100
|
||||||
|
#define W5100S 5100+5
|
||||||
|
#define W5200 5200
|
||||||
|
#define W5300 5300
|
||||||
|
#define W5500 5500
|
||||||
|
|
||||||
|
|
||||||
|
#define _WIZCHIP_ W5500
|
||||||
|
|
||||||
|
|
||||||
#ifndef _WIZCHIP_
|
#ifndef _WIZCHIP_
|
||||||
#define _WIZCHIP_ 5500 // 5100, 5200, 5300, 5500
|
#define _WIZCHIP_ W5100S // W5100, W5100S, W5200, W5300, W5500
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define _WIZCHIP_IO_MODE_NONE_ 0x0000
|
#define _WIZCHIP_IO_MODE_NONE_ 0x0000
|
||||||
@ -77,9 +92,9 @@
|
|||||||
|
|
||||||
#define _WIZCHIP_IO_MODE_SPI_VDM_ (_WIZCHIP_IO_MODE_SPI_ + 1) /**< SPI interface mode for variable length data*/
|
#define _WIZCHIP_IO_MODE_SPI_VDM_ (_WIZCHIP_IO_MODE_SPI_ + 1) /**< SPI interface mode for variable length data*/
|
||||||
#define _WIZCHIP_IO_MODE_SPI_FDM_ (_WIZCHIP_IO_MODE_SPI_ + 2) /**< SPI interface mode for fixed length data mode*/
|
#define _WIZCHIP_IO_MODE_SPI_FDM_ (_WIZCHIP_IO_MODE_SPI_ + 2) /**< SPI interface mode for fixed length data mode*/
|
||||||
|
#define _WIZCHIP_IO_MODE_SPI_5500_ (_WIZCHIP_IO_MODE_SPI_ + 3) /**< SPI interface mode for fixed length data mode*/
|
||||||
|
|
||||||
|
#if (_WIZCHIP_ == W5100)
|
||||||
#if (_WIZCHIP_ == 5100)
|
|
||||||
#define _WIZCHIP_ID_ "W5100\0"
|
#define _WIZCHIP_ID_ "W5100\0"
|
||||||
/**
|
/**
|
||||||
* @brief Define interface mode.
|
* @brief Define interface mode.
|
||||||
@ -94,11 +109,25 @@
|
|||||||
//A20150401 : Indclude W5100.h file
|
//A20150401 : Indclude W5100.h file
|
||||||
#include "W5100/w5100.h"
|
#include "W5100/w5100.h"
|
||||||
|
|
||||||
#elif (_WIZCHIP_ == 5200)
|
#elif (_WIZCHIP_ == W5100S)
|
||||||
|
#define _WIZCHIP_ID_ "W5100S\0"
|
||||||
|
/**
|
||||||
|
* @brief Define interface mode.
|
||||||
|
* @todo you should select interface mode as chip. Select one of @ref \_WIZCHIP_IO_MODE_SPI_ , @ref \_WIZCHIP_IO_MODE_BUS_DIR_ or @ref \_WIZCHIP_IO_MODE_BUS_INDIR_
|
||||||
|
*/
|
||||||
|
// #define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_BUS_INDIR_
|
||||||
|
//#define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_SPI_5500_
|
||||||
|
#define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_SPI_
|
||||||
|
|
||||||
|
//A20150601 : Define the unit of IO DATA.
|
||||||
|
typedef uint8_t iodata_t;
|
||||||
|
//A20150401 : Indclude W5100.h file
|
||||||
|
#include "W5100S/w5100s.h"
|
||||||
|
#elif (_WIZCHIP_ == W5200)
|
||||||
#define _WIZCHIP_ID_ "W5200\0"
|
#define _WIZCHIP_ID_ "W5200\0"
|
||||||
/**
|
/**
|
||||||
* @brief Define interface mode.
|
* @brief Define interface mode.
|
||||||
* @todo you should select interface mode as chip. Select one of @ref \_WIZCHIP_IO_MODE_SPI_ or @ref \_WIZCHIP_IO_MODE_BUS_INDIR_
|
* @todo you should select interface mode as chip. Select one of @ref \_WIZCHIP_IO_MODE_SPI_ or @ref \ _WIZCHIP_IO_MODE_BUS_INDIR_
|
||||||
*/
|
*/
|
||||||
#ifndef _WIZCHIP_IO_MODE_
|
#ifndef _WIZCHIP_IO_MODE_
|
||||||
// #define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_BUS_INDIR_
|
// #define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_BUS_INDIR_
|
||||||
@ -107,15 +136,15 @@
|
|||||||
//A20150601 : Define the unit of IO DATA.
|
//A20150601 : Define the unit of IO DATA.
|
||||||
typedef uint8_t iodata_t;
|
typedef uint8_t iodata_t;
|
||||||
#include "W5200/w5200.h"
|
#include "W5200/w5200.h"
|
||||||
#elif (_WIZCHIP_ == 5500)
|
#elif (_WIZCHIP_ == W5500)
|
||||||
#define _WIZCHIP_ID_ "W5500\0"
|
#define _WIZCHIP_ID_ "W5500\0"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Define interface mode. \n
|
* @brief Define interface mode. \n
|
||||||
* @todo Should select interface mode as chip.
|
* @todo Should select interface mode as chip.
|
||||||
* - @ref \_WIZCHIP_IO_MODE_SPI_ \n
|
* - @ref \_WIZCHIP_IO_MODE_SPI_ \n
|
||||||
* -@ref \_WIZCHIP_IO_MODE_SPI_VDM_ : Valid only in @ref \_WIZCHIP_ == 5500 \n
|
* -@ref \_WIZCHIP_IO_MODE_SPI_VDM_ : Valid only in @ref \_WIZCHIP_ == W5500 \n
|
||||||
* -@ref \_WIZCHIP_IO_MODE_SPI_FDM_ : Valid only in @ref \_WIZCHIP_ == 5500 \n
|
* -@ref \_WIZCHIP_IO_MODE_SPI_FDM_ : Valid only in @ref \_WIZCHIP_ == W5500 \n
|
||||||
* - @ref \_WIZCHIP_IO_MODE_BUS_ \n
|
* - @ref \_WIZCHIP_IO_MODE_BUS_ \n
|
||||||
* - @ref \_WIZCHIP_IO_MODE_BUS_DIR_ \n
|
* - @ref \_WIZCHIP_IO_MODE_BUS_DIR_ \n
|
||||||
* - @ref \_WIZCHIP_IO_MODE_BUS_INDIR_ \n
|
* - @ref \_WIZCHIP_IO_MODE_BUS_INDIR_ \n
|
||||||
@ -130,7 +159,7 @@
|
|||||||
//A20150601 : Define the unit of IO DATA.
|
//A20150601 : Define the unit of IO DATA.
|
||||||
typedef uint8_t iodata_t;
|
typedef uint8_t iodata_t;
|
||||||
#include "W5500/w5500.h"
|
#include "W5500/w5500.h"
|
||||||
#elif ( _WIZCHIP_ == 5300)
|
#elif ( _WIZCHIP_ == W5300)
|
||||||
#define _WIZCHIP_ID_ "W5300\0"
|
#define _WIZCHIP_ID_ "W5300\0"
|
||||||
/**
|
/**
|
||||||
* @brief Define interface mode.
|
* @brief Define interface mode.
|
||||||
@ -172,6 +201,12 @@
|
|||||||
* @ref \_WIZCHIP_IO_MODE_BUS_DIR_, @ref \_WIZCHIP_IO_MODE_BUS_INDIR_). \n\n
|
* @ref \_WIZCHIP_IO_MODE_BUS_DIR_, @ref \_WIZCHIP_IO_MODE_BUS_INDIR_). \n\n
|
||||||
* ex> <code> #define \_WIZCHIP_IO_BASE_ 0x00008000 </code>
|
* ex> <code> #define \_WIZCHIP_IO_BASE_ 0x00008000 </code>
|
||||||
*/
|
*/
|
||||||
|
#if _WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_
|
||||||
|
#define _WIZCHIP_IO_BASE_ 0x60000000 // for 5100S IND
|
||||||
|
#elif _WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_
|
||||||
|
#define _WIZCHIP_IO_BASE_ 0x00000000 // for 5100S SPI
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef _WIZCHIP_IO_BASE_
|
#ifndef _WIZCHIP_IO_BASE_
|
||||||
#define _WIZCHIP_IO_BASE_ 0x00000000 // 0x8000
|
#define _WIZCHIP_IO_BASE_ 0x00000000 // 0x8000
|
||||||
#endif
|
#endif
|
||||||
@ -184,7 +219,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if _WIZCHIP_ > 5100
|
#if _WIZCHIP_ >= W5200
|
||||||
#define _WIZCHIP_SOCK_NUM_ 8 ///< The count of independant socket of @b WIZCHIP
|
#define _WIZCHIP_SOCK_NUM_ 8 ///< The count of independant socket of @b WIZCHIP
|
||||||
#else
|
#else
|
||||||
#define _WIZCHIP_SOCK_NUM_ 4 ///< The count of independant socket of @b WIZCHIP
|
#define _WIZCHIP_SOCK_NUM_ 4 ///< The count of independant socket of @b WIZCHIP
|
||||||
@ -201,7 +236,7 @@
|
|||||||
typedef struct __WIZCHIP
|
typedef struct __WIZCHIP
|
||||||
{
|
{
|
||||||
uint16_t if_mode; ///< host interface mode
|
uint16_t if_mode; ///< host interface mode
|
||||||
uint8_t id[6]; ///< @b WIZCHIP ID such as @b 5100, @b 5200, @b 5500, and so on.
|
uint8_t id[7]; ///< @b WIZCHIP ID such as @b 5100, @b 5200, @b 5500, and so on.
|
||||||
/**
|
/**
|
||||||
* The set of critical section callback func.
|
* The set of critical section callback func.
|
||||||
*/
|
*/
|
||||||
@ -272,7 +307,7 @@ typedef enum
|
|||||||
CW_GET_ID, ///< Gets WIZCHIP name.
|
CW_GET_ID, ///< Gets WIZCHIP name.
|
||||||
|
|
||||||
//D20150601 : For no modification your application code
|
//D20150601 : For no modification your application code
|
||||||
//#if _WIZCHIP_ == 5500
|
//#if _WIZCHIP_ == W5500
|
||||||
CW_RESET_PHY, ///< Resets internal PHY. Valid Only W5500
|
CW_RESET_PHY, ///< Resets internal PHY. Valid Only W5500
|
||||||
CW_SET_PHYCONF, ///< When PHY configured by internal register, PHY operation mode (Manual/Auto, 10/100, Half/Full). Valid Only W5000
|
CW_SET_PHYCONF, ///< When PHY configured by internal register, PHY operation mode (Manual/Auto, 10/100, Half/Full). Valid Only W5000
|
||||||
CW_GET_PHYCONF, ///< Get PHY operation mode in internal register. Valid Only W5500
|
CW_GET_PHYCONF, ///< Get PHY operation mode in internal register. Valid Only W5500
|
||||||
@ -280,7 +315,7 @@ typedef enum
|
|||||||
CW_SET_PHYPOWMODE, ///< Set PHY power mode as normal and down when PHYSTATUS.OPMD == 1. Valid Only W5500
|
CW_SET_PHYPOWMODE, ///< Set PHY power mode as normal and down when PHYSTATUS.OPMD == 1. Valid Only W5500
|
||||||
//#endif
|
//#endif
|
||||||
//D20150601 : For no modification your application code
|
//D20150601 : For no modification your application code
|
||||||
//#if _WIZCHIP_ == 5200 || _WIZCHIP_ == 5500
|
//#if _WIZCHIP_ == W5200 || _WIZCHIP_ == W5500
|
||||||
CW_GET_PHYPOWMODE, ///< Get PHY Power mode as down or normal, Valid Only W5100, W5200
|
CW_GET_PHYPOWMODE, ///< Get PHY Power mode as down or normal, Valid Only W5100, W5200
|
||||||
CW_GET_PHYLINK ///< Get PHY Link status, Valid Only W5100, W5200
|
CW_GET_PHYLINK ///< Get PHY Link status, Valid Only W5100, W5200
|
||||||
//#endif
|
//#endif
|
||||||
@ -308,15 +343,15 @@ typedef enum
|
|||||||
*/
|
*/
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
#if _WIZCHIP_ == 5500
|
#if _WIZCHIP_ == W5500
|
||||||
IK_WOL = (1 << 4), ///< Wake On Lan by receiving the magic packet. Valid in W500.
|
IK_WOL = (1 << 4), ///< Wake On Lan by receiving the magic packet. Valid in W500.
|
||||||
#elif _WIZCHIP_ == 5300
|
#elif _WIZCHIP_ == W5300
|
||||||
IK_FMTU = (1 << 4), ///< Received a ICMP message (Fragment MTU)
|
IK_FMTU = (1 << 4), ///< Received a ICMP message (Fragment MTU)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
IK_PPPOE_TERMINATED = (1 << 5), ///< PPPoE Disconnected
|
IK_PPPOE_TERMINATED = (1 << 5), ///< PPPoE Disconnected
|
||||||
|
|
||||||
#if _WIZCHIP_ != 5200
|
#if _WIZCHIP_ != W5200
|
||||||
IK_DEST_UNREACH = (1 << 6), ///< Destination IP & Port Unreachable, No use in W5200
|
IK_DEST_UNREACH = (1 << 6), ///< Destination IP & Port Unreachable, No use in W5200
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -326,14 +361,14 @@ typedef enum
|
|||||||
IK_SOCK_1 = (1 << 9), ///< Socket 1 interrupt
|
IK_SOCK_1 = (1 << 9), ///< Socket 1 interrupt
|
||||||
IK_SOCK_2 = (1 << 10), ///< Socket 2 interrupt
|
IK_SOCK_2 = (1 << 10), ///< Socket 2 interrupt
|
||||||
IK_SOCK_3 = (1 << 11), ///< Socket 3 interrupt
|
IK_SOCK_3 = (1 << 11), ///< Socket 3 interrupt
|
||||||
#if _WIZCHIP_ > 5100
|
#if _WIZCHIP_ > W5100S
|
||||||
IK_SOCK_4 = (1 << 12), ///< Socket 4 interrupt, No use in 5100
|
IK_SOCK_4 = (1 << 12), ///< Socket 4 interrupt, No use in 5100
|
||||||
IK_SOCK_5 = (1 << 13), ///< Socket 5 interrupt, No use in 5100
|
IK_SOCK_5 = (1 << 13), ///< Socket 5 interrupt, No use in 5100
|
||||||
IK_SOCK_6 = (1 << 14), ///< Socket 6 interrupt, No use in 5100
|
IK_SOCK_6 = (1 << 14), ///< Socket 6 interrupt, No use in 5100
|
||||||
IK_SOCK_7 = (1 << 15), ///< Socket 7 interrupt, No use in 5100
|
IK_SOCK_7 = (1 << 15), ///< Socket 7 interrupt, No use in 5100
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if _WIZCHIP_ > 5100
|
#if _WIZCHIP_ > W5100S
|
||||||
IK_SOCK_ALL = (0xFF << 8) ///< All Socket interrupt
|
IK_SOCK_ALL = (0xFF << 8) ///< All Socket interrupt
|
||||||
#else
|
#else
|
||||||
IK_SOCK_ALL = (0x0F << 8) ///< All Socket interrupt
|
IK_SOCK_ALL = (0x0F << 8) ///< All Socket interrupt
|
||||||
@ -354,7 +389,7 @@ typedef enum
|
|||||||
#define PHY_POWER_DOWN 1 ///< PHY power down mode
|
#define PHY_POWER_DOWN 1 ///< PHY power down mode
|
||||||
|
|
||||||
|
|
||||||
#if _WIZCHIP_ == 5500
|
#if _WIZCHIP_ == W5100S || _WIZCHIP_ == W5500
|
||||||
/**
|
/**
|
||||||
* @ingroup DATA_TYPE
|
* @ingroup DATA_TYPE
|
||||||
* It configures PHY configuration when CW_SET PHYCONF or CW_GET_PHYCONF in W5500,
|
* It configures PHY configuration when CW_SET PHYCONF or CW_GET_PHYCONF in W5500,
|
||||||
@ -402,7 +437,7 @@ typedef struct wiz_NetInfo_t
|
|||||||
*/
|
*/
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
#if _WIZCHIP_ == 5500
|
#if _WIZCHIP_ == W5500
|
||||||
NM_FORCEARP = (1<<1), ///< Force to APP send whenever udp data is sent. Valid only in W5500
|
NM_FORCEARP = (1<<1), ///< Force to APP send whenever udp data is sent. Valid only in W5500
|
||||||
#endif
|
#endif
|
||||||
NM_WAKEONLAN = (1<<5), ///< Wake On Lan
|
NM_WAKEONLAN = (1<<5), ///< Wake On Lan
|
||||||
@ -545,12 +580,13 @@ void wizchip_setinterruptmask(intr_kind intr);
|
|||||||
*/
|
*/
|
||||||
intr_kind wizchip_getinterruptmask(void);
|
intr_kind wizchip_getinterruptmask(void);
|
||||||
|
|
||||||
#if _WIZCHIP_ > 5100
|
//todo
|
||||||
|
#if _WIZCHIP_ > W5100
|
||||||
int8_t wizphy_getphylink(void); ///< get the link status of phy in WIZCHIP. No use in W5100
|
int8_t wizphy_getphylink(void); ///< get the link status of phy in WIZCHIP. No use in W5100
|
||||||
int8_t wizphy_getphypmode(void); ///< get the power mode of PHY in WIZCHIP. No use in W5100
|
int8_t wizphy_getphypmode(void); ///< get the power mode of PHY in WIZCHIP. No use in W5100
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if _WIZCHIP_ == 5500
|
#if _WIZCHIP_ == W5100S || _WIZCHIP_ == W5500
|
||||||
void wizphy_reset(void); ///< Reset phy. Vailid only in W5500
|
void wizphy_reset(void); ///< Reset phy. Vailid only in W5500
|
||||||
/**
|
/**
|
||||||
* @ingroup extra_functions
|
* @ingroup extra_functions
|
||||||
@ -621,5 +657,8 @@ void wizchip_settimeout(wiz_NetTimeout* nettime);
|
|||||||
* @param nettime @ref _RTR_ value and @ref _RCR_ value. Refer to @ref wiz_NetTimeout.
|
* @param nettime @ref _RTR_ value and @ref _RCR_ value. Refer to @ref wiz_NetTimeout.
|
||||||
*/
|
*/
|
||||||
void wizchip_gettimeout(wiz_NetTimeout* nettime);
|
void wizchip_gettimeout(wiz_NetTimeout* nettime);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // _WIZCHIP_CONF_H_
|
#endif // _WIZCHIP_CONF_H_
|
||||||
|
@ -2,10 +2,11 @@
|
|||||||
//
|
//
|
||||||
//! \file dhcp.c
|
//! \file dhcp.c
|
||||||
//! \brief DHCP APIs implement file.
|
//! \brief DHCP APIs implement file.
|
||||||
//! \details Processig DHCP protocol as DISCOVER, OFFER, REQUEST, ACK, NACK and DECLINE.
|
//! \details Processing DHCP protocol as DISCOVER, OFFER, REQUEST, ACK, NACK and DECLINE.
|
||||||
//! \version 1.1.0
|
//! \version 1.1.1
|
||||||
//! \date 2013/11/18
|
//! \date 2019/10/08
|
||||||
//! \par Revision history
|
//! \par Revision history
|
||||||
|
//! <2019/10/08> compare DHCP server ip address
|
||||||
//! <2013/11/18> 1st Release
|
//! <2013/11/18> 1st Release
|
||||||
//! <2012/12/20> V1.1.0
|
//! <2012/12/20> V1.1.0
|
||||||
//! 1. Optimize code
|
//! 1. Optimize code
|
||||||
@ -52,10 +53,11 @@
|
|||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
#include "dhcp.h"
|
#include "dhcp.h"
|
||||||
|
|
||||||
/* If you want to display debug & procssing message, Define _DHCP_DEBUG_ in dhcp.h */
|
/* If you want to display debug & processing message, Define _DHCP_DEBUG_ in dhcp.h */
|
||||||
|
|
||||||
#ifdef _DHCP_DEBUG_
|
#ifdef _DHCP_DEBUG_
|
||||||
#include <stdio.h>
|
//#include <stdio.h>
|
||||||
|
int logMsg(const char *format, ...);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* DHCP state machine. */
|
/* DHCP state machine. */
|
||||||
@ -65,7 +67,7 @@
|
|||||||
#define STATE_DHCP_LEASED 3 ///< ReceiveD ACK and IP leased
|
#define STATE_DHCP_LEASED 3 ///< ReceiveD ACK and IP leased
|
||||||
#define STATE_DHCP_REREQUEST 4 ///< send REQUEST for maintaining leased IP
|
#define STATE_DHCP_REREQUEST 4 ///< send REQUEST for maintaining leased IP
|
||||||
#define STATE_DHCP_RELEASE 5 ///< No use
|
#define STATE_DHCP_RELEASE 5 ///< No use
|
||||||
#define STATE_DHCP_STOP 6 ///< Stop procssing DHCP
|
#define STATE_DHCP_STOP 6 ///< Stop processing DHCP
|
||||||
|
|
||||||
#define DHCP_FLAGSBROADCAST 0x8000 ///< The broadcast value of flags in @ref RIP_MSG
|
#define DHCP_FLAGSBROADCAST 0x8000 ///< The broadcast value of flags in @ref RIP_MSG
|
||||||
#define DHCP_FLAGSUNICAST 0x0000 ///< The unicast value of flags in @ref RIP_MSG
|
#define DHCP_FLAGSUNICAST 0x0000 ///< The unicast value of flags in @ref RIP_MSG
|
||||||
@ -192,6 +194,7 @@ typedef struct {
|
|||||||
uint8_t DHCP_SOCKET; // Socket number for DHCP
|
uint8_t DHCP_SOCKET; // Socket number for DHCP
|
||||||
|
|
||||||
uint8_t DHCP_SIP[4]; // DHCP Server IP address
|
uint8_t DHCP_SIP[4]; // DHCP Server IP address
|
||||||
|
uint8_t DHCP_REAL_SIP[4]; // For extract my DHCP server in a few DHCP server
|
||||||
|
|
||||||
// Network information from DHCP Server
|
// Network information from DHCP Server
|
||||||
uint8_t OLD_allocated_ip[4] = {0, }; // Previous IP address
|
uint8_t OLD_allocated_ip[4] = {0, }; // Previous IP address
|
||||||
@ -228,6 +231,7 @@ void (*dhcp_ip_conflict)(void) = default_ip_conflict; /* handler to be called
|
|||||||
|
|
||||||
void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void));
|
void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void));
|
||||||
|
|
||||||
|
char NibbleToHex(uint8_t nibble);
|
||||||
|
|
||||||
/* send DISCOVER message to DHCP server */
|
/* send DISCOVER message to DHCP server */
|
||||||
void send_DHCP_DISCOVER(void);
|
void send_DHCP_DISCOVER(void);
|
||||||
@ -244,7 +248,7 @@ int8_t check_DHCP_leasedIP(void);
|
|||||||
/* check the timeout in DHCP process */
|
/* check the timeout in DHCP process */
|
||||||
uint8_t check_DHCP_timeout(void);
|
uint8_t check_DHCP_timeout(void);
|
||||||
|
|
||||||
/* Intialize to timeout process. */
|
/* Initialize to timeout process. */
|
||||||
void reset_DHCP_timeout(void);
|
void reset_DHCP_timeout(void);
|
||||||
|
|
||||||
/* Parse message as OFFER and ACK and NACK from DHCP server.*/
|
/* Parse message as OFFER and ACK and NACK from DHCP server.*/
|
||||||
@ -258,7 +262,7 @@ void default_ip_assign(void)
|
|||||||
setGAR (DHCP_allocated_gw);
|
setGAR (DHCP_allocated_gw);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The default handler of ip chaged */
|
/* The default handler of ip changed */
|
||||||
void default_ip_update(void)
|
void default_ip_update(void)
|
||||||
{
|
{
|
||||||
/* WIZchip Software Reset */
|
/* WIZchip Software Reset */
|
||||||
@ -268,7 +272,7 @@ void default_ip_update(void)
|
|||||||
setSHAR(DHCP_CHADDR);
|
setSHAR(DHCP_CHADDR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The default handler of ip chaged */
|
/* The default handler of ip changed */
|
||||||
void default_ip_conflict(void)
|
void default_ip_conflict(void)
|
||||||
{
|
{
|
||||||
// WIZchip Software Reset
|
// WIZchip Software Reset
|
||||||
@ -355,8 +359,16 @@ void send_DHCP_DISCOVER(void)
|
|||||||
uint16_t k = 0;
|
uint16_t k = 0;
|
||||||
|
|
||||||
makeDHCPMSG();
|
makeDHCPMSG();
|
||||||
|
DHCP_SIP[0]=0;
|
||||||
|
DHCP_SIP[1]=0;
|
||||||
|
DHCP_SIP[2]=0;
|
||||||
|
DHCP_SIP[3]=0;
|
||||||
|
DHCP_REAL_SIP[0]=0;
|
||||||
|
DHCP_REAL_SIP[1]=0;
|
||||||
|
DHCP_REAL_SIP[2]=0;
|
||||||
|
DHCP_REAL_SIP[3]=0;
|
||||||
|
|
||||||
k = 4; // beacaue MAGIC_COOKIE already made by makeDHCPMSG()
|
k = 4; // because MAGIC_COOKIE already made by makeDHCPMSG()
|
||||||
|
|
||||||
// Option Request Param
|
// Option Request Param
|
||||||
pDHCPMSG->OPT[k++] = dhcpMessageType;
|
pDHCPMSG->OPT[k++] = dhcpMessageType;
|
||||||
@ -379,10 +391,13 @@ void send_DHCP_DISCOVER(void)
|
|||||||
pDHCPMSG->OPT[k++] = 0; // fill zero length of hostname
|
pDHCPMSG->OPT[k++] = 0; // fill zero length of hostname
|
||||||
for(i = 0 ; HOST_NAME[i] != 0; i++)
|
for(i = 0 ; HOST_NAME[i] != 0; i++)
|
||||||
pDHCPMSG->OPT[k++] = HOST_NAME[i];
|
pDHCPMSG->OPT[k++] = HOST_NAME[i];
|
||||||
pDHCPMSG->OPT[k++] = DHCP_CHADDR[3];
|
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[3] >> 4);
|
||||||
pDHCPMSG->OPT[k++] = DHCP_CHADDR[4];
|
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[3]);
|
||||||
pDHCPMSG->OPT[k++] = DHCP_CHADDR[5];
|
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[4] >> 4);
|
||||||
pDHCPMSG->OPT[k - (i+3+1)] = i+3; // length of hostname
|
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[4]);
|
||||||
|
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[5] >> 4);
|
||||||
|
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[5]);
|
||||||
|
pDHCPMSG->OPT[k - (i+6+1)] = i+6; // length of hostname
|
||||||
|
|
||||||
pDHCPMSG->OPT[k++] = dhcpParamRequest;
|
pDHCPMSG->OPT[k++] = dhcpParamRequest;
|
||||||
pDHCPMSG->OPT[k++] = 0x06; // length of request
|
pDHCPMSG->OPT[k++] = 0x06; // length of request
|
||||||
@ -403,7 +418,7 @@ void send_DHCP_DISCOVER(void)
|
|||||||
ip[3] = 255;
|
ip[3] = 255;
|
||||||
|
|
||||||
#ifdef _DHCP_DEBUG_
|
#ifdef _DHCP_DEBUG_
|
||||||
printf("> Send DHCP_DISCOVER\r\n");
|
logMsg("> Send DHCP_DISCOVER\r\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sendto(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT);
|
sendto(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT);
|
||||||
@ -439,7 +454,7 @@ void send_DHCP_REQUEST(void)
|
|||||||
ip[3] = 255;
|
ip[3] = 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
k = 4; // beacaue MAGIC_COOKIE already made by makeDHCPMSG()
|
k = 4; // because MAGIC_COOKIE already made by makeDHCPMSG()
|
||||||
|
|
||||||
// Option Request Param.
|
// Option Request Param.
|
||||||
pDHCPMSG->OPT[k++] = dhcpMessageType;
|
pDHCPMSG->OPT[k++] = dhcpMessageType;
|
||||||
@ -478,10 +493,13 @@ void send_DHCP_REQUEST(void)
|
|||||||
pDHCPMSG->OPT[k++] = 0; // length of hostname
|
pDHCPMSG->OPT[k++] = 0; // length of hostname
|
||||||
for(i = 0 ; HOST_NAME[i] != 0; i++)
|
for(i = 0 ; HOST_NAME[i] != 0; i++)
|
||||||
pDHCPMSG->OPT[k++] = HOST_NAME[i];
|
pDHCPMSG->OPT[k++] = HOST_NAME[i];
|
||||||
pDHCPMSG->OPT[k++] = DHCP_CHADDR[3];
|
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[3] >> 4);
|
||||||
pDHCPMSG->OPT[k++] = DHCP_CHADDR[4];
|
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[3]);
|
||||||
pDHCPMSG->OPT[k++] = DHCP_CHADDR[5];
|
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[4] >> 4);
|
||||||
pDHCPMSG->OPT[k - (i+3+1)] = i+3; // length of hostname
|
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[4]);
|
||||||
|
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[5] >> 4);
|
||||||
|
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[5]);
|
||||||
|
pDHCPMSG->OPT[k - (i+6+1)] = i+6; // length of hostname
|
||||||
|
|
||||||
pDHCPMSG->OPT[k++] = dhcpParamRequest;
|
pDHCPMSG->OPT[k++] = dhcpParamRequest;
|
||||||
pDHCPMSG->OPT[k++] = 0x08;
|
pDHCPMSG->OPT[k++] = 0x08;
|
||||||
@ -498,7 +516,7 @@ void send_DHCP_REQUEST(void)
|
|||||||
for (i = k; i < OPT_SIZE; i++) pDHCPMSG->OPT[i] = 0;
|
for (i = k; i < OPT_SIZE; i++) pDHCPMSG->OPT[i] = 0;
|
||||||
|
|
||||||
#ifdef _DHCP_DEBUG_
|
#ifdef _DHCP_DEBUG_
|
||||||
printf("> Send DHCP_REQUEST\r\n");
|
logMsg("> Send DHCP_REQUEST\r\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sendto(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT);
|
sendto(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT);
|
||||||
@ -514,7 +532,7 @@ void send_DHCP_DECLINE(void)
|
|||||||
|
|
||||||
makeDHCPMSG();
|
makeDHCPMSG();
|
||||||
|
|
||||||
k = 4; // beacaue MAGIC_COOKIE already made by makeDHCPMSG()
|
k = 4; // because MAGIC_COOKIE already made by makeDHCPMSG()
|
||||||
|
|
||||||
*((uint8_t*)(&pDHCPMSG->flags)) = ((DHCP_FLAGSUNICAST & 0xFF00)>> 8);
|
*((uint8_t*)(&pDHCPMSG->flags)) = ((DHCP_FLAGSUNICAST & 0xFF00)>> 8);
|
||||||
*((uint8_t*)(&pDHCPMSG->flags)+1) = (DHCP_FLAGSUNICAST & 0x00FF);
|
*((uint8_t*)(&pDHCPMSG->flags)+1) = (DHCP_FLAGSUNICAST & 0x00FF);
|
||||||
@ -559,7 +577,7 @@ void send_DHCP_DECLINE(void)
|
|||||||
ip[3] = 0xFF;
|
ip[3] = 0xFF;
|
||||||
|
|
||||||
#ifdef _DHCP_DEBUG_
|
#ifdef _DHCP_DEBUG_
|
||||||
printf("\r\n> Send DHCP_DECLINE\r\n");
|
logMsg("\r\n> Send DHCP_DECLINE\r\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sendto(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT);
|
sendto(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT);
|
||||||
@ -574,24 +592,41 @@ int8_t parseDHCPMSG(void)
|
|||||||
|
|
||||||
uint8_t * p;
|
uint8_t * p;
|
||||||
uint8_t * e;
|
uint8_t * e;
|
||||||
uint8_t type;
|
uint8_t type = 0;
|
||||||
uint8_t opt_len;
|
uint8_t opt_len;
|
||||||
|
|
||||||
if((len = getSn_RX_RSR(DHCP_SOCKET)) > 0)
|
if((len = getSn_RX_RSR(DHCP_SOCKET)) > 0)
|
||||||
{
|
{
|
||||||
len = recvfrom(DHCP_SOCKET, (uint8_t *)pDHCPMSG, len, svr_addr, &svr_port);
|
len = recvfrom(DHCP_SOCKET, (uint8_t *)pDHCPMSG, len, svr_addr, &svr_port);
|
||||||
#ifdef _DHCP_DEBUG_
|
#ifdef _DHCP_DEBUG_
|
||||||
printf("DHCP message : %d.%d.%d.%d(%d) %d received. \r\n",svr_addr[0],svr_addr[1],svr_addr[2], svr_addr[3],svr_port, len);
|
logMsg("DHCP message : %d.%d.%d.%d(%d) %d received. \r\n",svr_addr[0],svr_addr[1],svr_addr[2], svr_addr[3],svr_port, len);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else return 0;
|
else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (svr_port == DHCP_SERVER_PORT) {
|
if (svr_port == DHCP_SERVER_PORT) {
|
||||||
// compare mac address
|
// compare mac address
|
||||||
if ( (pDHCPMSG->chaddr[0] != DHCP_CHADDR[0]) || (pDHCPMSG->chaddr[1] != DHCP_CHADDR[1]) ||
|
if ( (pDHCPMSG->chaddr[0] != DHCP_CHADDR[0]) || (pDHCPMSG->chaddr[1] != DHCP_CHADDR[1]) ||
|
||||||
(pDHCPMSG->chaddr[2] != DHCP_CHADDR[2]) || (pDHCPMSG->chaddr[3] != DHCP_CHADDR[3]) ||
|
(pDHCPMSG->chaddr[2] != DHCP_CHADDR[2]) || (pDHCPMSG->chaddr[3] != DHCP_CHADDR[3]) ||
|
||||||
(pDHCPMSG->chaddr[4] != DHCP_CHADDR[4]) || (pDHCPMSG->chaddr[5] != DHCP_CHADDR[5]) )
|
(pDHCPMSG->chaddr[4] != DHCP_CHADDR[4]) || (pDHCPMSG->chaddr[5] != DHCP_CHADDR[5]) )
|
||||||
|
{
|
||||||
|
#ifdef _DHCP_DEBUG_
|
||||||
|
logMsg("No My DHCP Message. This message is ignored.\r\n");
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
type = 0;
|
}
|
||||||
|
//compare DHCP server ip address
|
||||||
|
if((DHCP_SIP[0]!=0) || (DHCP_SIP[1]!=0) || (DHCP_SIP[2]!=0) || (DHCP_SIP[3]!=0)){
|
||||||
|
if( ((svr_addr[0]!=DHCP_SIP[0])|| (svr_addr[1]!=DHCP_SIP[1])|| (svr_addr[2]!=DHCP_SIP[2])|| (svr_addr[3]!=DHCP_SIP[3])) &&
|
||||||
|
((svr_addr[0]!=DHCP_REAL_SIP[0])|| (svr_addr[1]!=DHCP_REAL_SIP[1])|| (svr_addr[2]!=DHCP_REAL_SIP[2])|| (svr_addr[3]!=DHCP_REAL_SIP[3])) )
|
||||||
|
{
|
||||||
|
#ifdef _DHCP_DEBUG_
|
||||||
|
logMsg("Another DHCP sever send a response message. This is ignored.\r\n");
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
p = (uint8_t *)(&pDHCPMSG->op);
|
p = (uint8_t *)(&pDHCPMSG->op);
|
||||||
p = p + 240; // 240 = sizeof(RIP_MSG) + MAGIC_COOKIE size in RIP_MSG.opt - sizeof(RIP_MSG.opt)
|
p = p + 240; // 240 = sizeof(RIP_MSG) + MAGIC_COOKIE size in RIP_MSG.opt - sizeof(RIP_MSG.opt)
|
||||||
e = p + (len - 240);
|
e = p + (len - 240);
|
||||||
@ -655,6 +690,10 @@ int8_t parseDHCPMSG(void)
|
|||||||
DHCP_SIP[1] = *p++;
|
DHCP_SIP[1] = *p++;
|
||||||
DHCP_SIP[2] = *p++;
|
DHCP_SIP[2] = *p++;
|
||||||
DHCP_SIP[3] = *p++;
|
DHCP_SIP[3] = *p++;
|
||||||
|
DHCP_REAL_SIP[0]=svr_addr[0];
|
||||||
|
DHCP_REAL_SIP[1]=svr_addr[1];
|
||||||
|
DHCP_REAL_SIP[2]=svr_addr[2];
|
||||||
|
DHCP_REAL_SIP[3]=svr_addr[3];
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
p++;
|
p++;
|
||||||
@ -692,7 +731,7 @@ uint8_t DHCP_run(void)
|
|||||||
case STATE_DHCP_DISCOVER :
|
case STATE_DHCP_DISCOVER :
|
||||||
if (type == DHCP_OFFER){
|
if (type == DHCP_OFFER){
|
||||||
#ifdef _DHCP_DEBUG_
|
#ifdef _DHCP_DEBUG_
|
||||||
printf("> Receive DHCP_OFFER\r\n");
|
logMsg("> Receive DHCP_OFFER\r\n");
|
||||||
#endif
|
#endif
|
||||||
DHCP_allocated_ip[0] = pDHCPMSG->yiaddr[0];
|
DHCP_allocated_ip[0] = pDHCPMSG->yiaddr[0];
|
||||||
DHCP_allocated_ip[1] = pDHCPMSG->yiaddr[1];
|
DHCP_allocated_ip[1] = pDHCPMSG->yiaddr[1];
|
||||||
@ -708,7 +747,7 @@ uint8_t DHCP_run(void)
|
|||||||
if (type == DHCP_ACK) {
|
if (type == DHCP_ACK) {
|
||||||
|
|
||||||
#ifdef _DHCP_DEBUG_
|
#ifdef _DHCP_DEBUG_
|
||||||
printf("> Receive DHCP_ACK\r\n");
|
logMsg("> Receive DHCP_ACK\r\n");
|
||||||
#endif
|
#endif
|
||||||
if (check_DHCP_leasedIP()) {
|
if (check_DHCP_leasedIP()) {
|
||||||
// Network info assignment from DHCP
|
// Network info assignment from DHCP
|
||||||
@ -725,7 +764,7 @@ uint8_t DHCP_run(void)
|
|||||||
} else if (type == DHCP_NAK) {
|
} else if (type == DHCP_NAK) {
|
||||||
|
|
||||||
#ifdef _DHCP_DEBUG_
|
#ifdef _DHCP_DEBUG_
|
||||||
printf("> Receive DHCP_NACK\r\n");
|
logMsg("> Receive DHCP_NACK\r\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
reset_DHCP_timeout();
|
reset_DHCP_timeout();
|
||||||
@ -739,7 +778,7 @@ uint8_t DHCP_run(void)
|
|||||||
if ((dhcp_lease_time != INFINITE_LEASETIME) && ((dhcp_lease_time/2) < dhcp_tick_1s)) {
|
if ((dhcp_lease_time != INFINITE_LEASETIME) && ((dhcp_lease_time/2) < dhcp_tick_1s)) {
|
||||||
|
|
||||||
#ifdef _DHCP_DEBUG_
|
#ifdef _DHCP_DEBUG_
|
||||||
printf("> Maintains the IP address \r\n");
|
logMsg("> Maintains the IP address \r\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
type = 0;
|
type = 0;
|
||||||
@ -770,19 +809,19 @@ uint8_t DHCP_run(void)
|
|||||||
ret = DHCP_IP_CHANGED;
|
ret = DHCP_IP_CHANGED;
|
||||||
dhcp_ip_update();
|
dhcp_ip_update();
|
||||||
#ifdef _DHCP_DEBUG_
|
#ifdef _DHCP_DEBUG_
|
||||||
printf(">IP changed.\r\n");
|
logMsg(">IP changed.\r\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
#ifdef _DHCP_DEBUG_
|
#ifdef _DHCP_DEBUG_
|
||||||
else printf(">IP is continued.\r\n");
|
else logMsg(">IP is continued.\r\n");
|
||||||
#endif
|
#endif
|
||||||
reset_DHCP_timeout();
|
reset_DHCP_timeout();
|
||||||
dhcp_state = STATE_DHCP_LEASED;
|
dhcp_state = STATE_DHCP_LEASED;
|
||||||
} else if (type == DHCP_NAK) {
|
} else if (type == DHCP_NAK) {
|
||||||
|
|
||||||
#ifdef _DHCP_DEBUG_
|
#ifdef _DHCP_DEBUG_
|
||||||
printf("> Receive DHCP_NACK, Failed to maintain ip\r\n");
|
logMsg("> Receive DHCP_NACK, Failed to maintain ip\r\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
reset_DHCP_timeout();
|
reset_DHCP_timeout();
|
||||||
@ -812,18 +851,18 @@ uint8_t check_DHCP_timeout(void)
|
|||||||
|
|
||||||
switch ( dhcp_state ) {
|
switch ( dhcp_state ) {
|
||||||
case STATE_DHCP_DISCOVER :
|
case STATE_DHCP_DISCOVER :
|
||||||
// printf("<<timeout>> state : STATE_DHCP_DISCOVER\r\n");
|
// logMsg("<<timeout>> state : STATE_DHCP_DISCOVER\r\n");
|
||||||
send_DHCP_DISCOVER();
|
send_DHCP_DISCOVER();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STATE_DHCP_REQUEST :
|
case STATE_DHCP_REQUEST :
|
||||||
// printf("<<timeout>> state : STATE_DHCP_REQUEST\r\n");
|
// logMsg("<<timeout>> state : STATE_DHCP_REQUEST\r\n");
|
||||||
|
|
||||||
send_DHCP_REQUEST();
|
send_DHCP_REQUEST();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STATE_DHCP_REREQUEST :
|
case STATE_DHCP_REREQUEST :
|
||||||
// printf("<<timeout>> state : STATE_DHCP_REREQUEST\r\n");
|
// logMsg("<<timeout>> state : STATE_DHCP_REREQUEST\r\n");
|
||||||
|
|
||||||
send_DHCP_REQUEST();
|
send_DHCP_REQUEST();
|
||||||
break;
|
break;
|
||||||
@ -876,7 +915,7 @@ int8_t check_DHCP_leasedIP(void)
|
|||||||
// UDP send Timeout occurred : allocated IP address is unique, DHCP Success
|
// UDP send Timeout occurred : allocated IP address is unique, DHCP Success
|
||||||
|
|
||||||
#ifdef _DHCP_DEBUG_
|
#ifdef _DHCP_DEBUG_
|
||||||
printf("\r\n> Check leased IP - OK\r\n");
|
logMsg("\r\n> Check leased IP - OK\r\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -897,7 +936,7 @@ void DHCP_init(uint8_t s, uint8_t * buf)
|
|||||||
getSHAR(DHCP_CHADDR);
|
getSHAR(DHCP_CHADDR);
|
||||||
if((DHCP_CHADDR[0] | DHCP_CHADDR[1] | DHCP_CHADDR[2] | DHCP_CHADDR[3] | DHCP_CHADDR[4] | DHCP_CHADDR[5]) == 0x00)
|
if((DHCP_CHADDR[0] | DHCP_CHADDR[1] | DHCP_CHADDR[2] | DHCP_CHADDR[3] | DHCP_CHADDR[4] | DHCP_CHADDR[5]) == 0x00)
|
||||||
{
|
{
|
||||||
// assing temporary mac address, you should be set SHAR before call this function.
|
// assigning temporary mac address, you should be set SHAR before call this function.
|
||||||
DHCP_CHADDR[0] = 0x00;
|
DHCP_CHADDR[0] = 0x00;
|
||||||
DHCP_CHADDR[1] = 0x08;
|
DHCP_CHADDR[1] = 0x08;
|
||||||
DHCP_CHADDR[2] = 0xdc;
|
DHCP_CHADDR[2] = 0xdc;
|
||||||
@ -910,10 +949,14 @@ void DHCP_init(uint8_t s, uint8_t * buf)
|
|||||||
DHCP_SOCKET = s; // SOCK_DHCP
|
DHCP_SOCKET = s; // SOCK_DHCP
|
||||||
pDHCPMSG = (RIP_MSG*)buf;
|
pDHCPMSG = (RIP_MSG*)buf;
|
||||||
DHCP_XID = 0x12345678;
|
DHCP_XID = 0x12345678;
|
||||||
|
{
|
||||||
|
DHCP_XID += DHCP_CHADDR[3];
|
||||||
|
DHCP_XID += DHCP_CHADDR[4];
|
||||||
|
DHCP_XID += DHCP_CHADDR[5];
|
||||||
|
DHCP_XID += (DHCP_CHADDR[3] ^ DHCP_CHADDR[4] ^ DHCP_CHADDR[5]);
|
||||||
|
}
|
||||||
// WIZchip Netinfo Clear
|
// WIZchip Netinfo Clear
|
||||||
setSIPR(zeroip);
|
setSIPR(zeroip);
|
||||||
setSIPR(zeroip);
|
|
||||||
setGAR(zeroip);
|
setGAR(zeroip);
|
||||||
|
|
||||||
reset_DHCP_timeout();
|
reset_DHCP_timeout();
|
||||||
@ -921,7 +964,7 @@ void DHCP_init(uint8_t s, uint8_t * buf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Rset the DHCP timeout count and retry count. */
|
/* Reset the DHCP timeout count and retry count. */
|
||||||
void reset_DHCP_timeout(void)
|
void reset_DHCP_timeout(void)
|
||||||
{
|
{
|
||||||
dhcp_tick_1s = 0;
|
dhcp_tick_1s = 0;
|
||||||
@ -971,6 +1014,13 @@ uint32_t getDHCPLeasetime(void)
|
|||||||
return dhcp_lease_time;
|
return dhcp_lease_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char NibbleToHex(uint8_t nibble)
|
||||||
|
{
|
||||||
|
nibble &= 0x0F;
|
||||||
|
if (nibble <= 9)
|
||||||
|
return nibble + '0';
|
||||||
|
else
|
||||||
|
return nibble + ('A'-0x0A);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,9 +3,10 @@
|
|||||||
//! \file dhcp.h
|
//! \file dhcp.h
|
||||||
//! \brief DHCP APIs Header file.
|
//! \brief DHCP APIs Header file.
|
||||||
//! \details Processig DHCP protocol as DISCOVER, OFFER, REQUEST, ACK, NACK and DECLINE.
|
//! \details Processig DHCP protocol as DISCOVER, OFFER, REQUEST, ACK, NACK and DECLINE.
|
||||||
//! \version 1.1.0
|
//! \version 1.1.1
|
||||||
//! \date 2013/11/18
|
//! \date 2019/10/08
|
||||||
//! \par Revision history
|
//! \par Revision history
|
||||||
|
//! <2019/10/08> compare DHCP server ip address
|
||||||
//! <2013/11/18> 1st Release
|
//! <2013/11/18> 1st Release
|
||||||
//! <2012/12/20> V1.1.0
|
//! <2012/12/20> V1.1.0
|
||||||
//! 1. Move unreferenced DEFINE to dhcp.c
|
//! 1. Move unreferenced DEFINE to dhcp.c
|
||||||
@ -45,16 +46,20 @@
|
|||||||
#ifndef _DHCP_H_
|
#ifndef _DHCP_H_
|
||||||
#define _DHCP_H_
|
#define _DHCP_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @brief
|
* @brief
|
||||||
* @details If you want to display debug & procssing message, Define _DHCP_DEBUG_
|
* @details If you want to display debug & processing message, Define _DHCP_DEBUG_
|
||||||
* @note If defined, it dependens on <stdio.h>
|
* @note If defined, it depends on <stdio.h>
|
||||||
*/
|
*/
|
||||||
//#define _DHCP_DEBUG_
|
// #define _DHCP_DEBUG_
|
||||||
|
|
||||||
|
|
||||||
/* Retry to processing DHCP */
|
/* Retry to processing DHCP */
|
||||||
#define MAX_DHCP_RETRY 2 ///< Maxium retry count
|
#define MAX_DHCP_RETRY 2 ///< Maximum retry count
|
||||||
#define DHCP_WAIT_TIME 10 ///< Wait Time 10s
|
#define DHCP_WAIT_TIME 10 ///< Wait Time 10s
|
||||||
|
|
||||||
|
|
||||||
@ -63,7 +68,7 @@
|
|||||||
#define DHCP_CLIENT_PORT 68 ///< DHCP client port number
|
#define DHCP_CLIENT_PORT 68 ///< DHCP client port number
|
||||||
|
|
||||||
|
|
||||||
#define MAGIC_COOKIE 0x63825363 ///< Any number. You can be modifyed it any number
|
#define MAGIC_COOKIE 0x63825363 ///< You should not modify it number.
|
||||||
|
|
||||||
#define DCHP_HOST_NAME "WIZnet\0"
|
#define DCHP_HOST_NAME "WIZnet\0"
|
||||||
|
|
||||||
@ -72,18 +77,18 @@
|
|||||||
*/
|
*/
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
DHCP_FAILED = 0, ///< Procssing Fail
|
DHCP_FAILED = 0, ///< Processing Fail
|
||||||
DHCP_RUNNING, ///< Procssing DHCP proctocol
|
DHCP_RUNNING, ///< Processing DHCP protocol
|
||||||
DHCP_IP_ASSIGN, ///< First Occupy IP from DHPC server (if cbfunc == null, act as default default_ip_assign)
|
DHCP_IP_ASSIGN, ///< First Occupy IP from DHPC server (if cbfunc == null, act as default default_ip_assign)
|
||||||
DHCP_IP_CHANGED, ///< Change IP address by new ip from DHCP (if cbfunc == null, act as default default_ip_update)
|
DHCP_IP_CHANGED, ///< Change IP address by new ip from DHCP (if cbfunc == null, act as default default_ip_update)
|
||||||
DHCP_IP_LEASED, ///< Stand by
|
DHCP_IP_LEASED, ///< Stand by
|
||||||
DHCP_STOPPED ///< Stop procssing DHCP protocol
|
DHCP_STOPPED ///< Stop processing DHCP protocol
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @brief DHCP client initialization (outside of the main loop)
|
* @brief DHCP client initialization (outside of the main loop)
|
||||||
* @param s - socket number
|
* @param s - socket number
|
||||||
* @param buf - buffer for procssing DHCP message
|
* @param buf - buffer for processing DHCP message
|
||||||
*/
|
*/
|
||||||
void DHCP_init(uint8_t s, uint8_t * buf);
|
void DHCP_init(uint8_t s, uint8_t * buf);
|
||||||
|
|
||||||
@ -97,7 +102,7 @@ void DHCP_time_handler(void);
|
|||||||
* @brief Register call back function
|
* @brief Register call back function
|
||||||
* @param ip_assign - callback func when IP is assigned from DHCP server first
|
* @param ip_assign - callback func when IP is assigned from DHCP server first
|
||||||
* @param ip_update - callback func when IP is changed
|
* @param ip_update - callback func when IP is changed
|
||||||
* @prarm ip_conflict - callback func when the assigned IP is conflict with others.
|
* @param ip_conflict - callback func when the assigned IP is conflict with others.
|
||||||
*/
|
*/
|
||||||
void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void));
|
void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void));
|
||||||
|
|
||||||
@ -116,7 +121,7 @@ void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_co
|
|||||||
uint8_t DHCP_run(void);
|
uint8_t DHCP_run(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @brief Stop DHCP procssing
|
* @brief Stop DHCP processing
|
||||||
* @note If you want to restart. call DHCP_init() and DHCP_run()
|
* @note If you want to restart. call DHCP_init() and DHCP_run()
|
||||||
*/
|
*/
|
||||||
void DHCP_stop(void);
|
void DHCP_stop(void);
|
||||||
@ -145,8 +150,12 @@ void getDNSfromDHCP(uint8_t* ip);
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* @brief Get the leased time by DHCP sever
|
* @brief Get the leased time by DHCP sever
|
||||||
* @retrun unit 1s
|
* @return unit 1s
|
||||||
*/
|
*/
|
||||||
uint32_t getDHCPLeasetime(void);
|
uint32_t getDHCPLeasetime(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _DHCP_H_ */
|
#endif /* _DHCP_H_ */
|
||||||
|
@ -120,6 +120,7 @@ uint8_t DNS_SOCKET; // SOCKET number for DNS
|
|||||||
uint16_t DNS_MSGID; // DNS message ID
|
uint16_t DNS_MSGID; // DNS message ID
|
||||||
|
|
||||||
uint32_t dns_1s_tick; // for timout of DNS processing
|
uint32_t dns_1s_tick; // for timout of DNS processing
|
||||||
|
static uint8_t retry_count;
|
||||||
|
|
||||||
/* converts uint16_t from network buffer to a host byte order integer. */
|
/* converts uint16_t from network buffer to a host byte order integer. */
|
||||||
uint16_t get16(uint8_t * s)
|
uint16_t get16(uint8_t * s)
|
||||||
@ -339,7 +340,7 @@ int8_t parseDNSMSG(struct dhdr * pdhdr, uint8_t * pbuf, uint8_t * ip_from_dns)
|
|||||||
uint8_t * cp;
|
uint8_t * cp;
|
||||||
|
|
||||||
msg = pbuf;
|
msg = pbuf;
|
||||||
memset(pdhdr, 0, sizeof(pdhdr));
|
memset(pdhdr, 0, sizeof(*pdhdr));
|
||||||
|
|
||||||
pdhdr->id = get16(&msg[0]);
|
pdhdr->id = get16(&msg[0]);
|
||||||
tmp = get16(&msg[2]);
|
tmp = get16(&msg[2]);
|
||||||
@ -367,7 +368,7 @@ int8_t parseDNSMSG(struct dhdr * pdhdr, uint8_t * pbuf, uint8_t * ip_from_dns)
|
|||||||
{
|
{
|
||||||
cp = dns_question(msg, cp);
|
cp = dns_question(msg, cp);
|
||||||
#ifdef _DNS_DEUBG_
|
#ifdef _DNS_DEUBG_
|
||||||
printf("MAX_DOMAIN_NAME is too small, it should be redfine in dns.h"
|
printf("MAX_DOMAIN_NAME is too small, it should be redfine in dns.h");
|
||||||
#endif
|
#endif
|
||||||
if(!cp) return -1;
|
if(!cp) return -1;
|
||||||
}
|
}
|
||||||
@ -377,7 +378,7 @@ int8_t parseDNSMSG(struct dhdr * pdhdr, uint8_t * pbuf, uint8_t * ip_from_dns)
|
|||||||
{
|
{
|
||||||
cp = dns_answer(msg, cp, ip_from_dns);
|
cp = dns_answer(msg, cp, ip_from_dns);
|
||||||
#ifdef _DNS_DEUBG_
|
#ifdef _DNS_DEUBG_
|
||||||
printf("MAX_DOMAIN_NAME is too small, it should be redfine in dns.h"
|
printf("MAX_DOMAIN_NAME is too small, it should be redfine in dns.h");
|
||||||
#endif
|
#endif
|
||||||
if(!cp) return -1;
|
if(!cp) return -1;
|
||||||
}
|
}
|
||||||
@ -472,7 +473,6 @@ int16_t dns_makequery(uint16_t op, char * name, uint8_t * buf, uint16_t len)
|
|||||||
|
|
||||||
int8_t check_DNS_timeout(void)
|
int8_t check_DNS_timeout(void)
|
||||||
{
|
{
|
||||||
static uint8_t retry_count;
|
|
||||||
|
|
||||||
if(dns_1s_tick >= DNS_WAIT_TIME)
|
if(dns_1s_tick >= DNS_WAIT_TIME)
|
||||||
{
|
{
|
||||||
@ -507,6 +507,9 @@ int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns)
|
|||||||
uint16_t len, port;
|
uint16_t len, port;
|
||||||
int8_t ret_check_timeout;
|
int8_t ret_check_timeout;
|
||||||
|
|
||||||
|
retry_count = 0;
|
||||||
|
dns_1s_tick = 0;
|
||||||
|
|
||||||
// Socket open
|
// Socket open
|
||||||
socket(DNS_SOCKET, Sn_MR_UDP, 0, 0);
|
socket(DNS_SOCKET, Sn_MR_UDP, 0, 0);
|
||||||
|
|
||||||
@ -536,6 +539,7 @@ int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns)
|
|||||||
#ifdef _DNS_DEBUG_
|
#ifdef _DNS_DEBUG_
|
||||||
printf("> DNS Server is not responding : %d.%d.%d.%d\r\n", dns_ip[0], dns_ip[1], dns_ip[2], dns_ip[3]);
|
printf("> DNS Server is not responding : %d.%d.%d.%d\r\n", dns_ip[0], dns_ip[1], dns_ip[2], dns_ip[3]);
|
||||||
#endif
|
#endif
|
||||||
|
close(DNS_SOCKET);
|
||||||
return 0; // timeout occurred
|
return 0; // timeout occurred
|
||||||
}
|
}
|
||||||
else if (ret_check_timeout == 0) {
|
else if (ret_check_timeout == 0) {
|
||||||
@ -558,6 +562,3 @@ void DNS_time_handler(void)
|
|||||||
{
|
{
|
||||||
dns_1s_tick++;
|
dns_1s_tick++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,6 +51,10 @@
|
|||||||
#ifndef _DNS_H_
|
#ifndef _DNS_H_
|
||||||
#define _DNS_H_
|
#define _DNS_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
/*
|
/*
|
||||||
* @brief Define it for Debug & Monitor DNS processing.
|
* @brief Define it for Debug & Monitor DNS processing.
|
||||||
@ -98,4 +102,8 @@ int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns);
|
|||||||
*/
|
*/
|
||||||
void DNS_time_handler(void);
|
void DNS_time_handler(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _DNS_H_ */
|
#endif /* _DNS_H_ */
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
#ifndef _FTPC_H_
|
#ifndef _FTPC_H_
|
||||||
#define _FTPC_H_
|
#define _FTPC_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -116,4 +120,8 @@ char proc_ftpc(char * buf);
|
|||||||
int pportc(char * arg);
|
int pportc(char * arg);
|
||||||
uint8_t* User_Keyboard_MSG();
|
uint8_t* User_Keyboard_MSG();
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // _FTPC_H_
|
#endif // _FTPC_H_
|
||||||
|
@ -29,6 +29,10 @@
|
|||||||
|
|
||||||
/* $Id: stdio_private.h,v 1.6 2003/01/07 22:17:24 joerg_wunsch Exp $ */
|
/* $Id: stdio_private.h,v 1.6 2003/01/07 22:17:24 joerg_wunsch Exp $ */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@ -65,3 +69,7 @@ struct __file {
|
|||||||
#define SCANF_MIN 1
|
#define SCANF_MIN 1
|
||||||
#define SCANF_STD 2
|
#define SCANF_STD 2
|
||||||
#define SCANF_FLT 3
|
#define SCANF_FLT 3
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
#ifndef _FTPD_H_
|
#ifndef _FTPD_H_
|
||||||
#define _FTPD_H_
|
#define _FTPD_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Wiznet.
|
* Wiznet.
|
||||||
* (c) Copyright 2002, Wiznet.
|
* (c) Copyright 2002, Wiznet.
|
||||||
@ -142,4 +146,9 @@ long recvfile(uint8_t s);
|
|||||||
#if defined(F_FILESYSTEM)
|
#if defined(F_FILESYSTEM)
|
||||||
void print_filedsc(FIL *fil);
|
void print_filedsc(FIL *fil);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // _FTPD_H_
|
#endif // _FTPD_H_
|
||||||
|
@ -28,6 +28,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: stdio_private.h,v 1.6 2003/01/07 22:17:24 joerg_wunsch Exp $ */
|
/* $Id: stdio_private.h,v 1.6 2003/01/07 22:17:24 joerg_wunsch Exp $ */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -65,3 +68,7 @@ struct __file {
|
|||||||
#define SCANF_MIN 1
|
#define SCANF_MIN 1
|
||||||
#define SCANF_STD 2
|
#define SCANF_STD 2
|
||||||
#define SCANF_FLT 3
|
#define SCANF_FLT 3
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -295,14 +295,10 @@ int MQTTYield(MQTTClient* c, int timeout_ms)
|
|||||||
TimerInit(&timer);
|
TimerInit(&timer);
|
||||||
TimerCountdownMS(&timer, timeout_ms);
|
TimerCountdownMS(&timer, timeout_ms);
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if (cycle(c, &timer) == FAILURE)
|
if (cycle(c, &timer) == FAILURE)
|
||||||
{
|
{
|
||||||
rc = FAILURE;
|
rc = FAILURE;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} while (!TimerIsExpired(&timer));
|
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -410,6 +406,9 @@ int MQTTSubscribe(MQTTClient* c, const char* topicFilter, enum QoS qos, messageH
|
|||||||
int len = 0;
|
int len = 0;
|
||||||
MQTTString topic = MQTTString_initializer;
|
MQTTString topic = MQTTString_initializer;
|
||||||
topic.cstring = (char *)topicFilter;
|
topic.cstring = (char *)topicFilter;
|
||||||
|
// This was added because enum QoS was previously typed to *int which resulted in HardFault and unaligned integer read.
|
||||||
|
// This coping below makes sure the parameter for MQTTSerialize_subscribe is always char no matter what compiler is using for enums
|
||||||
|
char charQos = (char)qos;
|
||||||
|
|
||||||
#if defined(MQTT_TASK)
|
#if defined(MQTT_TASK)
|
||||||
MutexLock(&c->mutex);
|
MutexLock(&c->mutex);
|
||||||
@ -420,7 +419,7 @@ int MQTTSubscribe(MQTTClient* c, const char* topicFilter, enum QoS qos, messageH
|
|||||||
TimerInit(&timer);
|
TimerInit(&timer);
|
||||||
TimerCountdownMS(&timer, c->command_timeout_ms);
|
TimerCountdownMS(&timer, c->command_timeout_ms);
|
||||||
|
|
||||||
len = MQTTSerialize_subscribe(c->buf, c->buf_size, 0, getNextPacketId(c), 1, &topic, (int*)&qos);
|
len = MQTTSerialize_subscribe(c->buf, c->buf_size, 0, getNextPacketId(c), 1, &topic, &charQos);
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
goto exit;
|
goto exit;
|
||||||
if ((rc = sendPacket(c, len, &timer)) != SUCCESSS) // send the subscribe packet
|
if ((rc = sendPacket(c, len, &timer)) != SUCCESSS) // send the subscribe packet
|
||||||
|
@ -119,8 +119,6 @@ char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf,
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
int rem_length = 0;
|
int rem_length = 0;
|
||||||
MQTTHeader header = {0};
|
MQTTHeader header = {0};
|
||||||
int strindex = 0;
|
|
||||||
|
|
||||||
header.byte = buf[index++];
|
header.byte = buf[index++];
|
||||||
index += MQTTPacket_decodeBuf(&buf[index], &rem_length);
|
index += MQTTPacket_decodeBuf(&buf[index], &rem_length);
|
||||||
|
|
||||||
@ -130,7 +128,7 @@ char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf,
|
|||||||
{
|
{
|
||||||
unsigned char sessionPresent, connack_rc;
|
unsigned char sessionPresent, connack_rc;
|
||||||
if (MQTTDeserialize_connack(&sessionPresent, &connack_rc, buf, buflen) == 1)
|
if (MQTTDeserialize_connack(&sessionPresent, &connack_rc, buf, buflen) == 1)
|
||||||
strindex = MQTTStringFormat_connack(strbuf, strbuflen, connack_rc, sessionPresent);
|
MQTTStringFormat_connack(strbuf, strbuflen, connack_rc, sessionPresent);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PUBLISH:
|
case PUBLISH:
|
||||||
@ -141,7 +139,7 @@ char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf,
|
|||||||
MQTTString topicName = MQTTString_initializer;
|
MQTTString topicName = MQTTString_initializer;
|
||||||
if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName,
|
if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName,
|
||||||
&payload, &payloadlen, buf, buflen) == 1)
|
&payload, &payloadlen, buf, buflen) == 1)
|
||||||
strindex = MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, packetid,
|
MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, packetid,
|
||||||
topicName, payload, payloadlen);
|
topicName, payload, payloadlen);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -153,7 +151,7 @@ char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf,
|
|||||||
unsigned char packettype, dup;
|
unsigned char packettype, dup;
|
||||||
unsigned short packetid;
|
unsigned short packetid;
|
||||||
if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1)
|
if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1)
|
||||||
strindex = MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid);
|
MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SUBACK:
|
case SUBACK:
|
||||||
@ -162,20 +160,20 @@ char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf,
|
|||||||
int maxcount = 1, count = 0;
|
int maxcount = 1, count = 0;
|
||||||
int grantedQoSs[1];
|
int grantedQoSs[1];
|
||||||
if (MQTTDeserialize_suback(&packetid, maxcount, &count, grantedQoSs, buf, buflen) == 1)
|
if (MQTTDeserialize_suback(&packetid, maxcount, &count, grantedQoSs, buf, buflen) == 1)
|
||||||
strindex = MQTTStringFormat_suback(strbuf, strbuflen, packetid, count, grantedQoSs);
|
MQTTStringFormat_suback(strbuf, strbuflen, packetid, count, grantedQoSs);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case UNSUBACK:
|
case UNSUBACK:
|
||||||
{
|
{
|
||||||
unsigned short packetid;
|
unsigned short packetid;
|
||||||
if (MQTTDeserialize_unsuback(&packetid, buf, buflen) == 1)
|
if (MQTTDeserialize_unsuback(&packetid, buf, buflen) == 1)
|
||||||
strindex = MQTTStringFormat_ack(strbuf, strbuflen, UNSUBACK, 0, packetid);
|
MQTTStringFormat_ack(strbuf, strbuflen, UNSUBACK, 0, packetid);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PINGREQ:
|
case PINGREQ:
|
||||||
case PINGRESP:
|
case PINGRESP:
|
||||||
case DISCONNECT:
|
case DISCONNECT:
|
||||||
strindex = snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);
|
snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return strbuf;
|
return strbuf;
|
||||||
@ -187,7 +185,6 @@ char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf,
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
int rem_length = 0;
|
int rem_length = 0;
|
||||||
MQTTHeader header = {0};
|
MQTTHeader header = {0};
|
||||||
int strindex = 0;
|
|
||||||
|
|
||||||
header.byte = buf[index++];
|
header.byte = buf[index++];
|
||||||
index += MQTTPacket_decodeBuf(&buf[index], &rem_length);
|
index += MQTTPacket_decodeBuf(&buf[index], &rem_length);
|
||||||
@ -199,7 +196,7 @@ char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf,
|
|||||||
MQTTPacket_connectData data;
|
MQTTPacket_connectData data;
|
||||||
int rc;
|
int rc;
|
||||||
if ((rc = MQTTDeserialize_connect(&data, buf, buflen)) == 1)
|
if ((rc = MQTTDeserialize_connect(&data, buf, buflen)) == 1)
|
||||||
strindex = MQTTStringFormat_connect(strbuf, strbuflen, &data);
|
MQTTStringFormat_connect(strbuf, strbuflen, &data);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PUBLISH:
|
case PUBLISH:
|
||||||
@ -210,7 +207,7 @@ char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf,
|
|||||||
MQTTString topicName = MQTTString_initializer;
|
MQTTString topicName = MQTTString_initializer;
|
||||||
if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName,
|
if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName,
|
||||||
&payload, &payloadlen, buf, buflen) == 1)
|
&payload, &payloadlen, buf, buflen) == 1)
|
||||||
strindex = MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, packetid,
|
MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, packetid,
|
||||||
topicName, payload, payloadlen);
|
topicName, payload, payloadlen);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -222,7 +219,7 @@ char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf,
|
|||||||
unsigned char packettype, dup;
|
unsigned char packettype, dup;
|
||||||
unsigned short packetid;
|
unsigned short packetid;
|
||||||
if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1)
|
if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1)
|
||||||
strindex = MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid);
|
MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SUBSCRIBE:
|
case SUBSCRIBE:
|
||||||
@ -234,7 +231,7 @@ char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf,
|
|||||||
int requestedQoSs[1];
|
int requestedQoSs[1];
|
||||||
if (MQTTDeserialize_subscribe(&dup, &packetid, maxcount, &count,
|
if (MQTTDeserialize_subscribe(&dup, &packetid, maxcount, &count,
|
||||||
topicFilters, requestedQoSs, buf, buflen) == 1)
|
topicFilters, requestedQoSs, buf, buflen) == 1)
|
||||||
strindex = MQTTStringFormat_subscribe(strbuf, strbuflen, dup, packetid, count, topicFilters, requestedQoSs);;
|
MQTTStringFormat_subscribe(strbuf, strbuflen, dup, packetid, count, topicFilters, requestedQoSs);;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case UNSUBSCRIBE:
|
case UNSUBSCRIBE:
|
||||||
@ -244,13 +241,13 @@ char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf,
|
|||||||
int maxcount = 1, count = 0;
|
int maxcount = 1, count = 0;
|
||||||
MQTTString topicFilters[1];
|
MQTTString topicFilters[1];
|
||||||
if (MQTTDeserialize_unsubscribe(&dup, &packetid, maxcount, &count, topicFilters, buf, buflen) == 1)
|
if (MQTTDeserialize_unsubscribe(&dup, &packetid, maxcount, &count, topicFilters, buf, buflen) == 1)
|
||||||
strindex = MQTTStringFormat_unsubscribe(strbuf, strbuflen, dup, packetid, count, topicFilters);
|
MQTTStringFormat_unsubscribe(strbuf, strbuflen, dup, packetid, count, topicFilters);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PINGREQ:
|
case PINGREQ:
|
||||||
case PINGRESP:
|
case PINGRESP:
|
||||||
case DISCONNECT:
|
case DISCONNECT:
|
||||||
strindex = snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);
|
snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
strbuf[strbuflen] = '\0';
|
strbuf[strbuflen] = '\0';
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
DLLExport int MQTTSerialize_subscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid,
|
DLLExport int MQTTSerialize_subscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid,
|
||||||
int count, MQTTString topicFilters[], int requestedQoSs[]);
|
int count, MQTTString topicFilters[], char requestedQoSs[]);
|
||||||
|
|
||||||
DLLExport int MQTTDeserialize_subscribe(unsigned char* dup, unsigned short* packetid,
|
DLLExport int MQTTDeserialize_subscribe(unsigned char* dup, unsigned short* packetid,
|
||||||
int maxcount, int* count, MQTTString topicFilters[], int requestedQoSs[], unsigned char* buf, int len);
|
int maxcount, int* count, MQTTString topicFilters[], int requestedQoSs[], unsigned char* buf, int len);
|
||||||
|
@ -48,7 +48,7 @@ int MQTTSerialize_subscribeLength(int count, MQTTString topicFilters[])
|
|||||||
* @return the length of the serialized data. <= 0 indicates error
|
* @return the length of the serialized data. <= 0 indicates error
|
||||||
*/
|
*/
|
||||||
int MQTTSerialize_subscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid, int count,
|
int MQTTSerialize_subscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid, int count,
|
||||||
MQTTString topicFilters[], int requestedQoSs[])
|
MQTTString topicFilters[], char requestedQoSs[])
|
||||||
{
|
{
|
||||||
unsigned char *ptr = buf;
|
unsigned char *ptr = buf;
|
||||||
MQTTHeader header = {0};
|
MQTTHeader header = {0};
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
#include "mqtt_interface.h"
|
#include "mqtt_interface.h"
|
||||||
#include "wizchip_conf.h"
|
#include "wizchip_conf.h"
|
||||||
|
#include "socket.h"
|
||||||
|
|
||||||
unsigned long MilliTimer;
|
unsigned long MilliTimer;
|
||||||
|
|
||||||
@ -122,12 +123,15 @@ void NewNetwork(Network* n, int sn) {
|
|||||||
* that contains the configuration information for the Network.
|
* that contains the configuration information for the Network.
|
||||||
* buffer : pointer to a read buffer.
|
* buffer : pointer to a read buffer.
|
||||||
* len : buffer length.
|
* len : buffer length.
|
||||||
|
* @retval received data length or SOCKERR code
|
||||||
*/
|
*/
|
||||||
int w5x00_read(Network* n, unsigned char* buffer, int len)
|
int w5x00_read(Network* n, unsigned char* buffer, int len, long time)
|
||||||
{
|
{
|
||||||
|
|
||||||
if((getSn_SR(n->my_socket) == SOCK_ESTABLISHED) && (getSn_RX_RSR(n->my_socket)>0))
|
if((getSn_SR(n->my_socket) == SOCK_ESTABLISHED) && (getSn_RX_RSR(n->my_socket)>0))
|
||||||
return recv(n->my_socket, buffer, len);
|
return recv(n->my_socket, buffer, len);
|
||||||
|
|
||||||
|
return SOCK_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -136,11 +140,14 @@ int w5x00_read(Network* n, unsigned char* buffer, int len)
|
|||||||
* that contains the configuration information for the Network.
|
* that contains the configuration information for the Network.
|
||||||
* buffer : pointer to a read buffer.
|
* buffer : pointer to a read buffer.
|
||||||
* len : buffer length.
|
* len : buffer length.
|
||||||
|
* @retval length of data sent or SOCKERR code
|
||||||
*/
|
*/
|
||||||
int w5x00_write(Network* n, unsigned char* buffer, int len)
|
int w5x00_write(Network* n, unsigned char* buffer, int len, long time)
|
||||||
{
|
{
|
||||||
if(getSn_SR(n->my_socket) == SOCK_ESTABLISHED)
|
if(getSn_SR(n->my_socket) == SOCK_ESTABLISHED)
|
||||||
return send(n->my_socket, buffer, len);
|
return send(n->my_socket, buffer, len);
|
||||||
|
|
||||||
|
return SOCK_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -160,9 +167,9 @@ void w5x00_disconnect(Network* n)
|
|||||||
* ip : server iP.
|
* ip : server iP.
|
||||||
* port : server port.
|
* port : server port.
|
||||||
*/
|
*/
|
||||||
int ConnectNetwork(Network* n, char* ip, int port)
|
void ConnectNetwork(Network* n, uint8_t* ip, uint16_t port)
|
||||||
{
|
{
|
||||||
uint8_t myport = 12345;
|
uint16_t myport = 12345;
|
||||||
|
|
||||||
socket(n->my_socket,Sn_MR_TCP,myport,0);
|
socket(n->my_socket,Sn_MR_TCP,myport,0);
|
||||||
connect(n->my_socket,ip,port);
|
connect(n->my_socket,ip,port);
|
||||||
|
@ -212,6 +212,13 @@ int main(void)
|
|||||||
#ifndef __MQTT_INTERFACE_H_
|
#ifndef __MQTT_INTERFACE_H_
|
||||||
#define __MQTT_INTERFACE_H_
|
#define __MQTT_INTERFACE_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @brief MQTT MilliTimer handler
|
* @brief MQTT MilliTimer handler
|
||||||
* @note MUST BE register to your system 1m Tick timer handler
|
* @note MUST BE register to your system 1m Tick timer handler
|
||||||
@ -234,8 +241,8 @@ typedef struct Network Network;
|
|||||||
struct Network
|
struct Network
|
||||||
{
|
{
|
||||||
int my_socket;
|
int my_socket;
|
||||||
int (*mqttread) (Network*, unsigned char*, int, int);
|
int (*mqttread) (Network*, unsigned char*, int, long);
|
||||||
int (*mqttwrite) (Network*, unsigned char*, int, int);
|
int (*mqttwrite) (Network*, unsigned char*, int, long);
|
||||||
void (*disconnect) (Network*);
|
void (*disconnect) (Network*);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -251,10 +258,14 @@ int TimerLeftMS(Timer*);
|
|||||||
/*
|
/*
|
||||||
* @brief Network interface porting
|
* @brief Network interface porting
|
||||||
*/
|
*/
|
||||||
int w5x00_read(Network*, unsigned char*, int);
|
int w5x00_read(Network*, unsigned char*, int, long);
|
||||||
int w5x00_write(Network*, unsigned char*, int);
|
int w5x00_write(Network*, unsigned char*, int, long);
|
||||||
void w5x00_disconnect(Network*);
|
void w5x00_disconnect(Network*);
|
||||||
void NewNetwork(Network* n, int sn);
|
void NewNetwork(Network* n, int sn);
|
||||||
int ConnectNetwork(Network*, char*, int);
|
void ConnectNetwork(Network* n, uint8_t* ip, uint16_t port);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif //__MQTT_INTERFACE_H_
|
#endif //__MQTT_INTERFACE_H_
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
#ifndef _SNMP_H_
|
#ifndef _SNMP_H_
|
||||||
#define _SNMP_H_
|
#define _SNMP_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
// SNMP Debug Message (dump) Enable
|
// SNMP Debug Message (dump) Enable
|
||||||
#define _SNMP_DEBUG_
|
#define _SNMP_DEBUG_
|
||||||
|
|
||||||
@ -111,4 +115,8 @@ void SNMP_time_handler(void);
|
|||||||
uint32_t getSNMPTimeTick(void);
|
uint32_t getSNMPTimeTick(void);
|
||||||
void currentUptime(void *ptr, uint8_t *len);
|
void currentUptime(void *ptr, uint8_t *len);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
#ifndef _SNMP_CUSTOM_H_
|
#ifndef _SNMP_CUSTOM_H_
|
||||||
#define _SNMP_CUSTOM_H_
|
#define _SNMP_CUSTOM_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
@ -30,4 +34,8 @@ void initTable();
|
|||||||
/* SNMP Trap: warmStart(1) */
|
/* SNMP Trap: warmStart(1) */
|
||||||
void initial_Trap(uint8_t * managerIP, uint8_t * agentIP);
|
void initial_Trap(uint8_t * managerIP, uint8_t * agentIP);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -71,7 +71,7 @@ uint16_t ntp_retry_cnt=0; //counting the ntp retry number
|
|||||||
48) UTC+13:00 Tonga
|
48) UTC+13:00 Tonga
|
||||||
49) UTC+14:00 Kiribati (Line Islands)
|
49) UTC+14:00 Kiribati (Line Islands)
|
||||||
*/
|
*/
|
||||||
void get_seconds_from_ntp_server(uint8_t *buf, uint16_t idx)
|
uint64_t get_seconds_from_ntp_server(uint8_t *buf, uint16_t idx)
|
||||||
{
|
{
|
||||||
tstamp seconds = 0;
|
tstamp seconds = 0;
|
||||||
uint8_t i=0;
|
uint8_t i=0;
|
||||||
@ -79,6 +79,8 @@ void get_seconds_from_ntp_server(uint8_t *buf, uint16_t idx)
|
|||||||
{
|
{
|
||||||
seconds = (seconds << 8) | buf[idx + i];
|
seconds = (seconds << 8) | buf[idx + i];
|
||||||
}
|
}
|
||||||
|
uint64_t rawSeconds = seconds;
|
||||||
|
|
||||||
switch (time_zone)
|
switch (time_zone)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
@ -132,7 +134,7 @@ void get_seconds_from_ntp_server(uint8_t *buf, uint16_t idx)
|
|||||||
case 20:
|
case 20:
|
||||||
seconds -= 1*3600;
|
seconds -= 1*3600;
|
||||||
break;
|
break;
|
||||||
case 21: //<2F><EFBFBD>?
|
case 21: //<2F>?
|
||||||
case 22:
|
case 22:
|
||||||
break;
|
break;
|
||||||
case 23:
|
case 23:
|
||||||
@ -213,6 +215,8 @@ void get_seconds_from_ntp_server(uint8_t *buf, uint16_t idx)
|
|||||||
|
|
||||||
//calculation for date
|
//calculation for date
|
||||||
calcdatetime(seconds);
|
calcdatetime(seconds);
|
||||||
|
|
||||||
|
return rawSeconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SNTP_init(uint8_t s, uint8_t *ntp_server, uint8_t tz, uint8_t *buf)
|
void SNTP_init(uint8_t s, uint8_t *ntp_server, uint8_t tz, uint8_t *buf)
|
||||||
@ -262,7 +266,7 @@ int8_t SNTP_run(datetime *time)
|
|||||||
if (RSR_len > MAX_SNTP_BUF_SIZE) RSR_len = MAX_SNTP_BUF_SIZE; // if Rx data size is lager than TX_RX_MAX_BUF_SIZE
|
if (RSR_len > MAX_SNTP_BUF_SIZE) RSR_len = MAX_SNTP_BUF_SIZE; // if Rx data size is lager than TX_RX_MAX_BUF_SIZE
|
||||||
recvfrom(NTP_SOCKET, data_buf, RSR_len, (uint8_t *)&destip, &destport);
|
recvfrom(NTP_SOCKET, data_buf, RSR_len, (uint8_t *)&destip, &destport);
|
||||||
|
|
||||||
get_seconds_from_ntp_server(data_buf,startindex);
|
time->seconds = get_seconds_from_ntp_server(data_buf,startindex);
|
||||||
time->yy = Nowdatetime.yy;
|
time->yy = Nowdatetime.yy;
|
||||||
time->mo = Nowdatetime.mo;
|
time->mo = Nowdatetime.mo;
|
||||||
time->dd = Nowdatetime.dd;
|
time->dd = Nowdatetime.dd;
|
||||||
|
@ -8,6 +8,10 @@
|
|||||||
#ifndef SNTP_H_
|
#ifndef SNTP_H_
|
||||||
#define SNTP_H_
|
#define SNTP_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -52,6 +56,7 @@ typedef struct _datetime
|
|||||||
uint8_t hh;
|
uint8_t hh;
|
||||||
uint8_t mm;
|
uint8_t mm;
|
||||||
uint8_t ss;
|
uint8_t ss;
|
||||||
|
uint64_t seconds;
|
||||||
} datetime;
|
} datetime;
|
||||||
|
|
||||||
#define ntp_port 123 //ntp server port number
|
#define ntp_port 123 //ntp server port number
|
||||||
@ -59,10 +64,14 @@ typedef struct _datetime
|
|||||||
#define UTC_ADJ_HRS 9 // SEOUL : GMT+9
|
#define UTC_ADJ_HRS 9 // SEOUL : GMT+9
|
||||||
#define EPOCH 1900 // NTP start year
|
#define EPOCH 1900 // NTP start year
|
||||||
|
|
||||||
void get_seconds_from_ntp_server(uint8_t *buf, uint16_t idx);
|
uint64_t get_seconds_from_ntp_server(uint8_t *buf, uint16_t idx);
|
||||||
void SNTP_init(uint8_t s, uint8_t *ntp_server, uint8_t tz, uint8_t *buf);
|
void SNTP_init(uint8_t s, uint8_t *ntp_server, uint8_t tz, uint8_t *buf);
|
||||||
int8_t SNTP_run(datetime *time);
|
int8_t SNTP_run(datetime *time);
|
||||||
tstamp changedatetime_to_seconds(void);
|
tstamp changedatetime_to_seconds(void);
|
||||||
void calcdatetime(tstamp seconds);
|
void calcdatetime(tstamp seconds);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* SNTP_H_ */
|
#endif /* SNTP_H_ */
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
#ifndef __NETUTIL_H__
|
#ifndef __NETUTIL_H__
|
||||||
#define __NETUTIL_H__
|
#define __NETUTIL_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define SYSTEM_LITTLE_ENDIAN
|
#define SYSTEM_LITTLE_ENDIAN
|
||||||
@ -16,4 +20,8 @@ uint32_t htonl(uint32_t hostlong);
|
|||||||
uint32_t ntohs(uint16_t netshort);
|
uint32_t ntohs(uint16_t netshort);
|
||||||
uint32_t ntohl(uint32_t netlong);
|
uint32_t ntohl(uint32_t netlong);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -7,6 +7,10 @@
|
|||||||
#ifndef __TFTP_H__
|
#ifndef __TFTP_H__
|
||||||
#define __TFTP_H__
|
#define __TFTP_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define F_APP_TFTP
|
#define F_APP_TFTP
|
||||||
@ -90,4 +94,8 @@ int TFTP_run(void);
|
|||||||
void TFTP_read_request(uint32_t server_ip, uint8_t *filename);
|
void TFTP_read_request(uint32_t server_ip, uint8_t *filename);
|
||||||
void tftp_timeout_handler(void);
|
void tftp_timeout_handler(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /*__TFTP_H__ */
|
#endif /*__TFTP_H__ */
|
||||||
|
@ -8,6 +8,10 @@
|
|||||||
#ifndef __HTTPPARSER_H__
|
#ifndef __HTTPPARSER_H__
|
||||||
#define __HTTPPARSER_H__
|
#define __HTTPPARSER_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
//#define _HTTPPARSER_DEBUG_
|
//#define _HTTPPARSER_DEBUG_
|
||||||
|
|
||||||
#define HTTP_SERVER_PORT 80 /**< HTTP server well-known port number */
|
#define HTTP_SERVER_PORT 80 /**< HTTP server well-known port number */
|
||||||
@ -147,4 +151,8 @@ uint16_t ATOI(uint8_t * str, uint8_t base);
|
|||||||
void mid(char* src, char* s1, char* s2, char* sub);
|
void mid(char* src, char* s1, char* s2, char* sub);
|
||||||
void inet_addr_(uint8_t * addr, uint8_t * ip);
|
void inet_addr_(uint8_t * addr, uint8_t * ip);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* end of __HTTPPARSER_H__ */
|
#endif /* end of __HTTPPARSER_H__ */
|
||||||
|
@ -169,7 +169,7 @@ void httpServer_run(uint8_t seqnum)
|
|||||||
|
|
||||||
gettime = get_httpServer_timecount();
|
gettime = get_httpServer_timecount();
|
||||||
// Check the TX socket buffer for End of HTTP response sends
|
// Check the TX socket buffer for End of HTTP response sends
|
||||||
while(getSn_TX_FSR(s) != (getSn_TXBUF_SIZE(s)*1024))
|
while(getSn_TX_FSR(s) != (getSn_TxMAX(s)))
|
||||||
{
|
{
|
||||||
if((get_httpServer_timecount() - gettime) > 3)
|
if((get_httpServer_timecount() - gettime) > 3)
|
||||||
{
|
{
|
||||||
|
@ -8,6 +8,10 @@
|
|||||||
#ifndef __HTTPSERVER_H__
|
#ifndef __HTTPSERVER_H__
|
||||||
#define __HTTPSERVER_H__
|
#define __HTTPSERVER_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
// HTTP Server debug message enable
|
// HTTP Server debug message enable
|
||||||
#define _HTTPSERVER_DEBUG_
|
#define _HTTPSERVER_DEBUG_
|
||||||
|
|
||||||
@ -100,4 +104,8 @@ uint8_t display_reg_webContent_list(void);
|
|||||||
void httpServer_time_handler(void);
|
void httpServer_time_handler(void);
|
||||||
uint32_t get_httpServer_timecount(void);
|
uint32_t get_httpServer_timecount(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -12,6 +12,10 @@
|
|||||||
#ifndef __HTTPUTIL_H__
|
#ifndef __HTTPUTIL_H__
|
||||||
#define __HTTPUTIL_H__
|
#define __HTTPUTIL_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "httpServer.h"
|
#include "httpServer.h"
|
||||||
#include "httpParser.h"
|
#include "httpParser.h"
|
||||||
|
|
||||||
@ -21,4 +25,8 @@ uint8_t http_post_cgi_handler(uint8_t * uri_name, st_http_request * p_http_reque
|
|||||||
uint8_t predefined_get_cgi_processor(uint8_t * uri_name, uint8_t * buf, uint16_t * len);
|
uint8_t predefined_get_cgi_processor(uint8_t * uri_name, uint8_t * buf, uint16_t * len);
|
||||||
uint8_t predefined_set_cgi_processor(uint8_t * uri_name, uint8_t * uri, uint8_t * buf, uint16_t * len);
|
uint8_t predefined_set_cgi_processor(uint8_t * uri_name, uint8_t * uri, uint8_t * buf, uint16_t * len);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
68
Makefile
Normal file
68
Makefile
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
WIZCHIP?=W5500
|
||||||
|
ENABLE_DHCP?=yes
|
||||||
|
ENABLE_DNS?=yes
|
||||||
|
ENABLE_HTTPSERVER?=yes
|
||||||
|
ENABLE_MQTT?=no
|
||||||
|
ENABLE_SNTP?=yes
|
||||||
|
|
||||||
|
CFLAGS?=-mcpu=cortex-m3 -mthumb -Og -fdata-sections -ffunction-sections -g -gdwarf-2
|
||||||
|
|
||||||
|
CC=arm-none-eabi-gcc
|
||||||
|
AR=arm-none-eabi-ar
|
||||||
|
|
||||||
|
CFLAGS+=-iquote Ethernet -Wall -D_WIZCHIP_=$(WIZCHIP)
|
||||||
|
|
||||||
|
OBJDIR=build
|
||||||
|
VPATH=Ethernet:Ethernet/W5500
|
||||||
|
ifeq ($(ENABLE_DHCP),yes)
|
||||||
|
VPATH+=Internet/DHCP
|
||||||
|
endif
|
||||||
|
ifeq ($(ENABLE_DNS),yes)
|
||||||
|
VPATH+=Internet/DNS
|
||||||
|
endif
|
||||||
|
ifeq ($(ENABLE_MQTT),yes)
|
||||||
|
VPATH+=Internet/MQTT:Internet/MQTT/MQTTPacket/src
|
||||||
|
endif
|
||||||
|
ifeq ($(ENABLE_HTTPSERVER),yes)
|
||||||
|
VPATH+=Internet/httpServer
|
||||||
|
endif
|
||||||
|
ifeq ($(ENABLE_SNTP),yes)
|
||||||
|
VPATH+=Internet/SNTP
|
||||||
|
endif
|
||||||
|
|
||||||
|
OBJS=$(addprefix $(OBJDIR)/,wizchip_conf.o socket.o w5500.o)
|
||||||
|
ifeq ($(ENABLE_DHCP),yes)
|
||||||
|
OBJS+=$(addprefix $(OBJDIR)/,dhcp.o)
|
||||||
|
endif
|
||||||
|
ifeq ($(ENABLE_DNS),yes)
|
||||||
|
OBJS+=$(addprefix $(OBJDIR)/,dns.o)
|
||||||
|
endif
|
||||||
|
ifeq ($(ENABLE_HTTPSERVER),yes)
|
||||||
|
OBJS+=$(addprefix $(OBJDIR)/,httpParser.o httpServer.o httpUtil.o)
|
||||||
|
endif
|
||||||
|
ifeq ($(ENABLE_SNTP),yes)
|
||||||
|
OBJS+=$(addprefix $(OBJDIR)/,sntp.o)
|
||||||
|
endif
|
||||||
|
ifeq ($(ENABLE_MQTT),yes)
|
||||||
|
OBJS+=$(addprefix $(OBJDIR)/,MQTTConnectClient.o MQTTConnectServer.o MQTTDeserializePublish.o \
|
||||||
|
MQTTFormat.o MQTTPacket.o MQTTSerializePublish.o MQTTSubscribeClient.o MQTTSubscribeServer.o \
|
||||||
|
MQTTUnsubscribeClient.o MQTTUnsubscribeServer.o mqtt_interface.o MQTTClient.o)
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
all: $(OBJS)
|
||||||
|
$(AR) rcs w5500.a $^
|
||||||
|
cp w5500.a ../build/
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.c
|
||||||
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
$(OBJS): | $(OBJDIR)
|
||||||
|
|
||||||
|
$(OBJDIR):
|
||||||
|
mkdir $(OBJDIR)
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
-rm -rf $(OBJDIR)
|
12
README.md
12
README.md
@ -1,14 +1,14 @@
|
|||||||
#ioLibrary Driver
|
# ioLibrary Driver
|
||||||
The ioLibrary means “Internet Offload Library” for WIZnet chip. It includes drivers and application protocols.
|
The ioLibrary means “Internet Offload Library” for WIZnet chip. It includes drivers and application protocols.
|
||||||
The driver (ioLibrary) can be used for the application design of WIZnet TCP/IP chips as [W5500](http://wizwiki.net/wiki/doku.php?id=products:w5500:start), W5300, W5200 and W5100.
|
The driver (ioLibrary) can be used for the application design of WIZnet TCP/IP chips as [W5500](http://wizwiki.net/wiki/doku.php?id=products:w5500:start), W5300, W5200, W5100 [W5100S](http://wizwiki.net/wiki/doku.php?id=products:w5100s:start).
|
||||||
|
|
||||||
##ioLibrary
|
## ioLibrary
|
||||||
This driver provides the Berkeley Socket type APIs.
|
This driver provides the Berkeley Socket type APIs.
|
||||||
- Directory Structure
|
- Directory Structure
|
||||||
<!-- ioLibrary pic -->
|
<!-- ioLibrary pic -->
|
||||||

|

|
||||||
|
|
||||||
- Ethernet : SOCKET APIs like BSD & WIZCHIP([W5500](http://wizwiki.net/wiki/doku.php?id=products:w5500:start) / W5300 / W5200 / W5100) Driver
|
- Ethernet : SOCKET APIs like BSD & WIZCHIP([W5500](http://wizwiki.net/wiki/doku.php?id=products:w5500:start) / W5300 / W5200 / W5100 / [W5100S](http://wizwiki.net/wiki/doku.php?id=products:w5100s:start)) Driver
|
||||||
- Internet :
|
- Internet :
|
||||||
- DHCP client
|
- DHCP client
|
||||||
- DNS client
|
- DNS client
|
||||||
@ -23,11 +23,13 @@ This driver provides the Berkeley Socket type APIs.
|
|||||||
|
|
||||||
## How to add an ioLibrary in project through github site.
|
## How to add an ioLibrary in project through github site.
|
||||||
- Example, refer to https://www.youtube.com/watch?v=mt815RBGdsA
|
- Example, refer to https://www.youtube.com/watch?v=mt815RBGdsA
|
||||||
- [ioLibrary Doxygen doument](https://github.com/Wiznet/ioLibrary_Driver/blob/master/Ethernet/SOCKET_APIs_V2.0.chm) : Refer to **TODO** in this document
|
- [ioLibrary Doxygen doument](https://github.com/Wiznet/ioLibrary_Driver/blob/master/Ethernet/Socket_APIs_V3.0.3.chm) : Refer to **TODO** in this document
|
||||||
- Define what chip is used in **wizchip_conf.h**
|
- Define what chip is used in **wizchip_conf.h**
|
||||||
- Define what Host I/F mode is used in **wizchip_conf.h**
|
- Define what Host I/F mode is used in **wizchip_conf.h**
|
||||||
|
|
||||||
## Revision History
|
## Revision History
|
||||||
|
* ioLibrary V4.0.0 Released : 29, MAR, 2018
|
||||||
|
* New features added: Library for W5100S added.
|
||||||
* ioLibrary V3.1.1 Released : 14, Dec, 2016
|
* ioLibrary V3.1.1 Released : 14, Dec, 2016
|
||||||
* Bug fixed : In Socket.c Fixed MACraw & IPraw sendto function.
|
* Bug fixed : In Socket.c Fixed MACraw & IPraw sendto function.
|
||||||
* ioLibrary V3.1.0 Released : 05, Dec, 2016
|
* ioLibrary V3.1.0 Released : 05, Dec, 2016
|
||||||
|
BIN
iolibrary.chm
Normal file
BIN
iolibrary.chm
Normal file
Binary file not shown.
22
license.txt
Normal file
22
license.txt
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
Copyright (c) 2014 WIZnet Co.,Ltd.
|
||||||
|
Copyright (c) WIZnet ioLibrary Project.
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
Reference in New Issue
Block a user