17 Commits

Author SHA1 Message Date
7f58783400 tune makefile 2020-11-08 14:50:36 +01:00
cae27e3acb tune makefile 2020-11-08 14:04:59 +01:00
0446055537 define to use W5500 chip and mark SPI functions to be replaced as weak 2020-11-07 21:14:04 +01:00
a33e0f8381 build a static library containing all created objects 2020-11-07 21:13:17 +01:00
46df6545d9 ignore built library 2020-11-07 21:12:44 +01:00
727db71b79 ignore my build directory 2020-11-07 20:55:13 +01:00
4c75a8fa48 beautify code in strange if/else format 2020-11-07 20:54:55 +01:00
5323a6d8e4 fix issue in dns, no wizchip_close, hopefully close was meant 2020-11-07 20:54:25 +01:00
8db71e5eb4 add Makefile 2020-11-07 20:53:45 +01:00
Taylor.An
cbf5b6e908 Merge pull request #96 from Wiznet/FIxedwiz_clrinterrupt()
Modify wizchip_clrinterrupt() to set Sn_IR for clearing SIR.
2020-03-02 17:21:16 +09:00
becky
a9141a7ade Modify wizchip_clrinterrupt() to set Sn_IR for clearing SIR. 2020-02-27 12:58:29 +09:00
irina
0bad15ab48 Added each of the devices have to has a different XID. 2020-02-18 12:54:51 +09:00
becky
de18368e5d Modify getSn_TXBUF_SIZE(s)*1024 - > getSn_TxMAX(s)
It is not compatable to W5100.
It is only valid on W5500
2020-02-17 16:29:08 +09:00
Taylor.An
1fadc591bc Merge pull request #95 from MrDiba/patch-1
Added a break to remove compiler warning.
2020-02-03 17:04:12 +09:00
MrDiba
18aeb30431 Added a break to remove compiler warning.
Compiler warned that there was no break at the end of the case statement. Added the break.
2020-01-27 16:30:24 +01:00
becky jeong
96857e86aa Merge pull request #93 from Wiznet/addApplicationmulticast
add multicast example
2019-12-27 16:10:15 +09:00
becky
84f4b6d030 add multicast example 2019-12-27 16:09:24 +09:00
10 changed files with 241 additions and 11 deletions

4
.gitignore vendored
View File

@@ -1,3 +1,7 @@
# Wolfgangs own stuff
build
w5500.a
# Windows image file caches # Windows image file caches
Thumbs.db Thumbs.db
ehthumbs.db ehthumbs.db

View 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;
}

View 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

View File

@@ -117,6 +117,7 @@ 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 :

View File

@@ -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
@@ -521,7 +521,12 @@ void wizchip_clrinterrupt(intr_kind intr)
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
} }

View File

@@ -71,6 +71,10 @@ extern "C" {
#define W5300 5300 #define W5300 5300
#define W5500 5500 #define W5500 5500
#define _WIZCHIP_ W5500
#ifndef _WIZCHIP_ #ifndef _WIZCHIP_
#define _WIZCHIP_ W5100S // W5100, W5100S, W5200, W5300, W5500 #define _WIZCHIP_ W5100S // W5100, W5100S, W5200, W5300, W5500
#endif #endif

View File

@@ -601,7 +601,9 @@ int8_t parseDHCPMSG(void)
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); 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);
#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]) ||
@@ -946,7 +948,12 @@ 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);
setGAR(zeroip); setGAR(zeroip);

View File

@@ -539,7 +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
wizchip_close(DNS_SOCKET); close(DNS_SOCKET);
return 0; // timeout occurred return 0; // timeout occurred
} }
else if (ret_check_timeout == 0) { else if (ret_check_timeout == 0) {

View File

@@ -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)
{ {

68
Makefile Normal file
View File

@@ -0,0 +1,68 @@
WIZCHIP=W5500
ENABLE_DHCP=yes
ENABLE_DNS=yes
ENABLE_HTTPSERVER=yes
ENABLE_MQTT=yes
ENABLE_SNTP=yes
# =====================================================================
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 $^
$(OBJDIR)/%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
$(OBJS): | $(OBJDIR)
$(OBJDIR):
mkdir $(OBJDIR)
.PHONY: clean
clean:
-rm -rf $(OBJDIR)