17 Commits

Author SHA1 Message Date
0957fc4830 add seconds since epoch to datetime struct 2021-02-07 18:35:10 +01:00
27f646860d install from Makefile 2020-11-11 22:30:06 +01:00
f8730808d1 disable dhcp debugging 2020-11-09 19:50:31 +01:00
26d4f89d0c dhcp debugging 2020-11-09 15:07:24 +01:00
1cdb6d2eda tune Makefile 2020-11-09 10:24:18 +01:00
181cfae6cc CFLAGS 2020-11-08 16:30:18 +01:00
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
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
0bad15ab48 Added each of the devices have to has a different XID. 2020-02-18 12:54:51 +09:00
9 changed files with 121 additions and 32 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

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

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

@ -56,7 +56,8 @@
/* If you want to display debug & processing 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. */
@ -417,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);
@ -515,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);
@ -576,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);
@ -598,10 +599,12 @@ int8_t parseDHCPMSG(void)
{ {
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]) ||
@ -609,7 +612,7 @@ int8_t parseDHCPMSG(void)
(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_ #ifdef _DHCP_DEBUG_
printf("No My DHCP Message. This message is ignored.\r\n"); logMsg("No My DHCP Message. This message is ignored.\r\n");
#endif #endif
return 0; return 0;
} }
@ -619,7 +622,7 @@ int8_t parseDHCPMSG(void)
((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])) ) ((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_ #ifdef _DHCP_DEBUG_
printf("Another DHCP sever send a response message. This is ignored.\r\n"); logMsg("Another DHCP sever send a response message. This is ignored.\r\n");
#endif #endif
return 0; return 0;
} }
@ -728,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];
@ -744,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
@ -761,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();
@ -775,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;
@ -806,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();
@ -848,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;
@ -912,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;
@ -946,7 +949,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

@ -55,7 +55,7 @@ extern "C" {
* @details If you want to display debug & processing message, Define _DHCP_DEBUG_ * @details If you want to display debug & processing message, Define _DHCP_DEBUG_
* @note If defined, it depends 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 */

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

@ -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;

View File

@ -56,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
@ -63,7 +64,7 @@ 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);

68
Makefile Normal file
View 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)