diff --git a/.vscode/settings.json b/.vscode/settings.json index 83abcc8..37286d8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,8 @@ "ch32v003fun.h": "c", "w5500.h": "c", "wizchip_conf.h": "c", - "socket.h": "c" + "socket.h": "c", + "type_traits": "c", + "compare": "c" } } \ No newline at end of file diff --git a/lib/ioLibrary_Driver/DNS/dns.c b/lib/ioLibrary_Driver/DNS/dns.c index 22e1e20..01b4e31 100644 --- a/lib/ioLibrary_Driver/DNS/dns.c +++ b/lib/ioLibrary_Driver/DNS/dns.c @@ -117,7 +117,7 @@ struct dhdr uint8_t* pDNSMSG; // DNS message buffer uint8_t DNS_SOCKET; // SOCKET number for DNS -uint16_t DNS_MSGID; // DNS message ID +volatile uint16_t DNS_MSGID; // DNS message ID uint32_t dns_1s_tick; // for timout of DNS processing static uint8_t retry_count; @@ -368,7 +368,7 @@ int8_t parseDNSMSG(struct dhdr * pdhdr, uint8_t * pbuf, uint8_t * ip_from_dns) { cp = dns_question(msg, cp); #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 if(!cp) return -1; } @@ -378,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); #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 if(!cp) return -1; } @@ -399,7 +399,6 @@ int8_t parseDNSMSG(struct dhdr * pdhdr, uint8_t * pbuf, uint8_t * ip_from_dns) else return 0; } - /* * MAKE DNS QUERY MESSAGE * @@ -410,20 +409,26 @@ int8_t parseDNSMSG(struct dhdr * pdhdr, uint8_t * pbuf, uint8_t * ip_from_dns) * len - is the MAX. size of buffer. * Returns : the pointer to the DNS message. */ -int16_t dns_makequery(uint16_t op, char * name, uint8_t * buf, uint16_t len) -{ - uint8_t *cp; +// #pragma GCC push_options +// #pragma GCC optimize("O0") +int16_t dns_makequery(uint16_t op, char *name, uint8_t *buf, uint16_t len) { + uint8_t *cp = buf; char *cp1; char sname[MAXCNAME]; char *dname; uint16_t p; uint16_t dlen; - cp = buf; - + // Ensuring name fits into sname + if (strlen(name) >= MAXCNAME) { + // Handle error - name too long + printf("Error: Name too long.\n"); + return -1; + } + DNS_MSGID++; cp = put16(cp, DNS_MSGID); - p = (op << 11) | 0x0100; /* Recursion desired */ + p = (op << 11) | 0x0100; // Recursion desired cp = put16(cp, p); cp = put16(cp, 1); cp = put16(cp, 0); @@ -433,34 +438,38 @@ int16_t dns_makequery(uint16_t op, char * name, uint8_t * buf, uint16_t len) strcpy(sname, name); dname = sname; dlen = strlen(dname); - for (;;) - { - /* Look for next dot */ - cp1 = strchr(dname, '.'); - if (cp1 != NULL) len = cp1 - dname; /* More to come */ - else len = dlen; /* Last component */ + for (;;) { + cp1 = strchr(dname, '.'); // Look for next dot + uint16_t component_len = cp1 != NULL ? cp1 - dname : dlen; - *cp++ = len; /* Write length of component */ - if (len == 0) break; + *cp++ = component_len; // Write length of component + if (component_len == 0) break; // Handle empty component - /* Copy component up to (but not including) dot */ - strncpy((char *)cp, dname, len); - cp += len; - if (cp1 == NULL) - { - *cp++ = 0; /* Last one; write null and finish */ + memcpy(cp, dname, component_len); // Copy component up to (but not including) dot + cp += component_len; + + if (cp1 == NULL) { + *cp++ = 0; // Last one; write null terminator break; } - dname += len+1; - dlen -= len+1; + + dname += component_len + 1; // Move past current component and dot + dlen -= component_len + 1; + + // Ensures dlen is still valid + if (dlen <= 0) { + printf("Error: dlen is non-positive.\n"); + return -1; + } } - cp = put16(cp, 0x0001); /* type */ - cp = put16(cp, 0x0001); /* class */ + cp = put16(cp, 0x0001); // type + cp = put16(cp, 0x0001); // class - return ((int16_t)((uint32_t)(cp) - (uint32_t)(buf))); + return (int16_t)((uint32_t)(cp) - (uint32_t)(buf)); } +// #pragma GCC pop_options /* * CHECK DNS TIMEOUT @@ -526,17 +535,17 @@ int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns) { if (len > MAX_DNS_BUF_SIZE) len = MAX_DNS_BUF_SIZE; len = recvfrom(DNS_SOCKET, pDNSMSG, len, ip, &port); - #ifdef _DNS_DEBUG_ - printf("> Receive DNS message from %d.%d.%d.%d(%d). len = %d\r\n", ip[0], ip[1], ip[2], ip[3],port,len); + #ifdef _DNS_DEBUG_ + printf("> Receive DNS message from %d.%d.%d.%d(%d). len = %d\r\n", ip[0], ip[1], ip[2], ip[3],port,len); // Print the partial DNS message - printf("> Partial DNS message: "); - for (int i = 0; i < len; i++) { - printf("%02X ", pDNSMSG[i]); // Print each byte in hexadecimal format - } - printf("\r\n"); - #endif - ret = parseDNSMSG(&dhp, pDNSMSG, ip_from_dns); + printf("> Partial DNS message: "); + for (int i = 0; i < len; i++) { + printf("%02X ", pDNSMSG[i]); // Print each byte in hexadecimal format + } + printf("\r\n"); + #endif + ret = parseDNSMSG(&dhp, pDNSMSG, ip_from_dns); break; } // Check Timeout diff --git a/lib/ioLibrary_Driver/FTPClient/ftpc.c b/lib/ioLibrary_Driver/FTPClient/ftpc.c deleted file mode 100644 index 6c35920..0000000 --- a/lib/ioLibrary_Driver/FTPClient/ftpc.c +++ /dev/null @@ -1,584 +0,0 @@ -#include "ftpc.h" - -un_l2cval remote_ip; -uint16_t remote_port; -un_l2cval local_ip; -uint16_t local_port; -uint8_t connect_state_control_ftpc = 0; -uint8_t connect_state_data_ftpc = 0; -uint8_t gModeActivePassiveflag = 0; -uint8_t FTP_destip[4] = {192, 168, 10, 230}; // For FTP client examples; destination network info -uint16_t FTP_destport = 21; // For FTP client examples; destination network info -uint8_t gMenuStart = 0; -uint8_t gDataSockReady = 0; -uint8_t gDataPutGetStart = 0; -static uint8_t gMsgBuf[20]={0,}; - -struct ftpc ftpc; -struct Command Command; - -void ftpc_init(uint8_t * src_ip) -{ - ftpc.dsock_mode = ACTIVE_MODE; - - local_ip.cVal[0] = src_ip[0]; - local_ip.cVal[1] = src_ip[1]; - local_ip.cVal[2] = src_ip[2]; - local_ip.cVal[3] = src_ip[3]; - local_port = 35000; - strcpy(ftpc.workingdir, "/"); - socket(CTRL_SOCK, Sn_MR_TCP, FTP_destport, 0x0); -} -uint8_t ftpc_run(uint8_t * dbuf) -{ -#ifndef Need_UARTGetCharBlocking_func - uint16_t size = 0; - long ret = 0; - uint32_t send_byte, recv_byte; - uint32_t blocklen; - uint32_t remain_filesize; - uint32_t remain_datasize; - uint8_t msg_c; - uint8_t dat[50]={0,}; - uint32_t totalSize = 0, availableSize = 0; - - switch(getSn_SR(CTRL_SOCK)) - { - case SOCK_ESTABLISHED : - if(!connect_state_control_ftpc){ - printf("%d:FTP Connected\r\n", CTRL_SOCK); - strcpy(ftpc.workingdir, "/"); - connect_state_control_ftpc = 1; - } - if(gMenuStart){ - gMenuStart = 0; - printf("\r\n----------------------------------------\r\n"); - printf("Press menu key\r\n"); - printf("----------------------------------------\r\n"); - printf("1> View FTP Server Directory\r\n"); - printf("2> View My Directory\r\n"); - printf("3> Sets the type of file to be transferred. Current state : %s\r\n", (ftpc.type==ASCII_TYPE)?"Ascii":"Binary"); - printf("4> Sets Data Connection. Current state : %s\r\n", (ftpc.dsock_mode==ACTIVE_MODE)?"Active":"Passive"); - printf("5> Put File to Server\r\n"); - printf("6> Get File from Server\r\n"); -#if defined(F_FILESYSTEM) - printf("7> Delete My File\r\n"); -#endif - printf("----------------------------------------\r\n"); - while(1){ - msg_c=ftp_getc(); - if(msg_c=='1'){ - if(ftpc.dsock_mode==PASSIVE_MODE){ - sprintf(dat,"PASV\r\n"); - send(CTRL_SOCK, (uint8_t *)dat, strlen(dat)); - Command.First = f_dir; - break; - } - else{ - wiz_NetInfo gWIZNETINFO; - ctlnetwork(CN_GET_NETINFO, (void*) &gWIZNETINFO); - sprintf(dat,"PORT %d,%d,%d,%d,%d,%d\r\n", gWIZNETINFO.ip[0], gWIZNETINFO.ip[1], gWIZNETINFO.ip[2], gWIZNETINFO.ip[3], (uint8_t)(local_port>>8), (uint8_t)(local_port&0x00ff)); - send(CTRL_SOCK, (uint8_t *)dat, strlen(dat)); - Command.First = f_dir; - - gModeActivePassiveflag = 1; - break; - } - break; - } - else if(msg_c=='5'){ - if(ftpc.dsock_mode==PASSIVE_MODE){ - sprintf(dat,"PASV\r\n"); - send(CTRL_SOCK, (uint8_t *)dat, strlen(dat)); - Command.First = f_put; - break; - } - else{ - wiz_NetInfo gWIZNETINFO; - ctlnetwork(CN_GET_NETINFO, (void*) &gWIZNETINFO); - sprintf(dat,"PORT %d,%d,%d,%d,%d,%d\r\n", gWIZNETINFO.ip[0], gWIZNETINFO.ip[1], gWIZNETINFO.ip[2], gWIZNETINFO.ip[3], (uint8_t)(local_port>>8), (uint8_t)(local_port&0x00ff)); - send(CTRL_SOCK, (uint8_t *)dat, strlen(dat)); - Command.First = f_put; - - gModeActivePassiveflag = 1; - break; - } - } - else if(msg_c=='6'){ - if(ftpc.dsock_mode==PASSIVE_MODE){ - sprintf(dat,"PASV\r\n"); - send(CTRL_SOCK, (uint8_t *)dat, strlen(dat)); - Command.First = f_get; - break; - } - else{ - wiz_NetInfo gWIZNETINFO; - ctlnetwork(CN_GET_NETINFO, (void*) &gWIZNETINFO); - sprintf(dat,"PORT %d,%d,%d,%d,%d,%d\r\n", gWIZNETINFO.ip[0], gWIZNETINFO.ip[1], gWIZNETINFO.ip[2], gWIZNETINFO.ip[3], (uint8_t)(local_port>>8), (uint8_t)(local_port&0x00ff)); - send(CTRL_SOCK, (uint8_t *)dat, strlen(dat)); - Command.First = f_get; - - gModeActivePassiveflag = 1; - break; - } - } - else if(msg_c=='2'){ -#if defined(F_FILESYSTEM) - scan_files(ftpc.workingdir, dbuf, (int *)&size); - printf("\r\n%s\r\n", dbuf); -#else - if (strncmp(ftpc.workingdir, "/$Recycle.Bin", sizeof("/$Recycle.Bin")) != 0) - size = sprintf(dbuf, "drwxr-xr-x 1 ftp ftp 0 Dec 31 2014 $Recycle.Bin\r\n-rwxr-xr-x 1 ftp ftp 512 Dec 31 2014 test.txt\r\n"); - printf("\r\n%s\r\n", dbuf); -#endif - gMenuStart = 1; - break; - } - else if(msg_c=='3'){ - printf("1> ASCII\r\n"); - printf("2> BINARY\r\n"); - while(1){ - msg_c=ftp_getc(); - if(msg_c=='1'){ - sprintf(dat,"TYPE %c\r\n", TransferAscii); - ftpc.type = ASCII_TYPE; - send(CTRL_SOCK, (uint8_t *)dat, strlen(dat)); - break; - } - else if(msg_c=='2'){ - sprintf(dat,"TYPE %c\r\n", TransferBinary); - ftpc.type = IMAGE_TYPE; - send(CTRL_SOCK, (uint8_t *)dat, strlen(dat)); - break; - } - else{ - printf("\r\nRetry...\r\n"); - } - } - break; - } - else if(msg_c=='4'){ - printf("1> ACTIVE\r\n"); - printf("2> PASSIVE\r\n"); - while(1){ - msg_c=ftp_getc(); - if(msg_c=='1'){ - ftpc.dsock_mode=ACTIVE_MODE; - break; - } - else if(msg_c=='2'){ - ftpc.dsock_mode=PASSIVE_MODE; - break; - } - else{ - printf("\r\nRetry...\r\n"); - } - } - gMenuStart = 1; - break; - } -#if defined(F_FILESYSTEM) - else if(msg_c=='7'){ - printf(">del filename?"); - sprintf(ftpc.filename, "/%s\r\n", User_Keyboard_MSG()); - if (f_unlink((const char *)ftpc.filename) != 0){ - printf("\r\nCould not delete.\r\n"); - } - else{ - printf("\r\nDeleted.\r\n"); - } - gMenuStart = 1; - break; - } -#endif - else{ - printf("\r\nRetry...\r\n"); - } - } - } - if(gDataSockReady){ - gDataSockReady = 0; - switch(Command.First){ - case f_dir: - sprintf(dat,"LIST\r\n"); - send(CTRL_SOCK, (uint8_t *)dat, strlen(dat)); - break; - case f_put: - printf(">put file name?"); - sprintf(dat,"STOR %s\r\n", User_Keyboard_MSG()); - send(CTRL_SOCK, (uint8_t *)dat, strlen(dat)); - break; - case f_get: - printf(">get file name?"); - sprintf(dat,"RETR %s\r\n", User_Keyboard_MSG()); - send(CTRL_SOCK, (uint8_t *)dat, strlen(dat)); - break; - default: - printf("Command.First = default\r\n"); - break; - } - } - if((size = getSn_RX_RSR(CTRL_SOCK)) > 0){ // Don't need to check SOCKERR_BUSY because it doesn't not occur. - memset(dbuf, 0, _MAX_SS); - if(size > _MAX_SS) size = _MAX_SS - 1; - ret = recv(CTRL_SOCK,dbuf,size); - dbuf[ret] = '\0'; - if(ret != size) - { - if(ret==SOCK_BUSY) return 0; - if(ret < 0){ - printf("%d:recv() error:%ld\r\n",CTRL_SOCK,ret); - close(CTRL_SOCK); - return ret; - } - } - printf("Rcvd Command: %s\r\n", dbuf); - proc_ftpc((char *)dbuf); - } - break; - case SOCK_CLOSE_WAIT : - printf("%d:CloseWait\r\n",CTRL_SOCK); - if((ret=disconnect(CTRL_SOCK)) != SOCK_OK) return ret; - printf("%d:Closed\r\n",CTRL_SOCK); - break; - case SOCK_CLOSED : - printf("%d:FTPStart\r\n",CTRL_SOCK); - if((ret=socket(CTRL_SOCK, Sn_MR_TCP, FTP_destport, 0x0)) != CTRL_SOCK){ - printf("%d:socket() error:%ld\r\n", CTRL_SOCK, ret); - close(CTRL_SOCK); - return ret; - } - break; - case SOCK_INIT : - printf("%d:Opened\r\n",CTRL_SOCK); - if((ret = connect(CTRL_SOCK, FTP_destip, FTP_destport)) != SOCK_OK){ - printf("%d:Connect error\r\n",CTRL_SOCK); - return ret; - } - connect_state_control_ftpc = 0; - printf("%d:Connectting...\r\n",CTRL_SOCK); - break; - default : - break; - } - - switch(getSn_SR(DATA_SOCK)){ - case SOCK_ESTABLISHED : - if(!connect_state_data_ftpc){ - printf("%d:FTP Data socket Connected\r\n", DATA_SOCK); - connect_state_data_ftpc = 1; - } - if(gDataPutGetStart){ - switch(Command.Second){ - case s_dir: - printf("dir waiting...\r\n"); - if((size = getSn_RX_RSR(DATA_SOCK)) > 0){ // Don't need to check SOCKERR_BUSY because it doesn't not occur. - printf("ok\r\n"); - memset(dbuf, 0, _MAX_SS); - if(size > _MAX_SS) size = _MAX_SS - 1; - ret = recv(DATA_SOCK,dbuf,size); - dbuf[ret] = '\0'; - if(ret != size){ - if(ret==SOCK_BUSY) return 0; - if(ret < 0){ - printf("%d:recv() error:%ld\r\n",CTRL_SOCK,ret); - close(DATA_SOCK); - return ret; - } - } - printf("Rcvd Data:\n\r%s\n\r", dbuf); - gDataPutGetStart = 0; - Command.Second = s_nocmd; - } - break; - case s_put: - printf("put waiting...\r\n"); - if(strlen(ftpc.workingdir) == 1) - sprintf(ftpc.filename, "/%s", (uint8_t *)gMsgBuf); - else - sprintf(ftpc.filename, "%s/%s", ftpc.workingdir, (uint8_t *)gMsgBuf); -#if defined(F_FILESYSTEM) - ftpc.fr = f_open(&(ftpc.fil), (const char *)ftpc.filename, FA_READ); - if(ftpc.fr == FR_OK){ - remain_filesize = ftpc.fil.fsize; - printf("f_open return FR_OK\r\n"); - do{ - memset(dbuf, 0, _MAX_SS); - if(remain_filesize > _MAX_SS) - send_byte = _MAX_SS; - else - send_byte = remain_filesize; - ftpc.fr = f_read(&(ftpc.fil), (void *)dbuf, send_byte , (UINT *)&blocklen); - if(ftpc.fr != FR_OK){ - break; - } - printf("#"); - send(DATA_SOCK, dbuf, blocklen); - remain_filesize -= blocklen; - }while(remain_filesize != 0); - printf("\r\nFile read finished\r\n"); - ftpc.fr = f_close(&(ftpc.fil)); - } - else{ - printf("File Open Error: %d\r\n", ftpc.fr); - ftpc.fr = f_close(&(ftpc.fil)); - } -#else - remain_filesize = strlen(ftpc.filename); - do{ - memset(dbuf, 0, _MAX_SS); - blocklen = sprintf(dbuf, "%s", ftpc.filename); - printf("########## dbuf:%s\r\n", dbuf); - send(DATA_SOCK, dbuf, blocklen); - remain_filesize -= blocklen; - }while(remain_filesize != 0); -#endif - gDataPutGetStart = 0; - Command.Second = s_nocmd; - disconnect(DATA_SOCK); - break; - case s_get: - printf("get waiting...\r\n"); - if(strlen(ftpc.workingdir) == 1) - sprintf(ftpc.filename, "/%s", (uint8_t *)gMsgBuf); - else - sprintf(ftpc.filename, "%s/%s", ftpc.workingdir, (uint8_t *)gMsgBuf); -#if defined(F_FILESYSTEM) - ftpc.fr = f_open(&(ftpc.fil), (const char *)ftpc.filename, FA_CREATE_ALWAYS | FA_WRITE); - if(ftpc.fr == FR_OK){ - printf("f_open return FR_OK\r\n"); - while(1){ - if((remain_datasize = getSn_RX_RSR(DATA_SOCK)) > 0){ - while(1){ - memset(dbuf, 0, _MAX_SS); - if(remain_datasize > _MAX_SS) recv_byte = _MAX_SS; - else recv_byte = remain_datasize; - ret = recv(DATA_SOCK, dbuf, recv_byte); - ftpc.fr = f_write(&(ftpc.fil), (const void *)dbuf, (UINT)ret, (UINT *)&blocklen); - remain_datasize -= blocklen; - if(ftpc.fr != FR_OK){ - printf("f_write failed\r\n"); - break; - } - if(remain_datasize <= 0) break; - } - if(ftpc.fr != FR_OK){ - printf("f_write failed\r\n"); - break; - } - printf("#"); - } - else{ - if(getSn_SR(DATA_SOCK) != SOCK_ESTABLISHED) break; - } - } - printf("\r\nFile write finished\r\n"); - ftpc.fr = f_close(&(ftpc.fil)); - gDataPutGetStart = 0; - }else{ - printf("File Open Error: %d\r\n", ftpc.fr); - } -#else - while(1){ - if((remain_datasize = getSn_RX_RSR(DATA_SOCK)) > 0){ - while(1){ - memset(dbuf, 0, _MAX_SS); - if(remain_datasize > _MAX_SS) - recv_byte = _MAX_SS; - else - recv_byte = remain_datasize; - ret = recv(DATA_SOCK, dbuf, recv_byte); - printf("########## dbuf:%s\r\n", dbuf); - remain_datasize -= ret; - if(remain_datasize <= 0) - break; - } - }else{ - if(getSn_SR(DATA_SOCK) != SOCK_ESTABLISHED) - break; - } - } - gDataPutGetStart = 0; - Command.Second = s_nocmd; -#endif - break; - default: - printf("Command.Second = default\r\n"); - break; - } - } - break; - case SOCK_CLOSE_WAIT : - printf("%d:CloseWait\r\n",DATA_SOCK); - if((ret=disconnect(DATA_SOCK)) != SOCK_OK) return ret; - printf("%d:Closed\r\n",DATA_SOCK); - break; - case SOCK_CLOSED : - if(ftpc.dsock_state == DATASOCK_READY){ - if(ftpc.dsock_mode == PASSIVE_MODE){ - printf("%d:FTPDataStart, port : %d\r\n",DATA_SOCK, local_port); - if((ret=socket(DATA_SOCK, Sn_MR_TCP, local_port, 0x0)) != DATA_SOCK){ - printf("%d:socket() error:%ld\r\n", DATA_SOCK, ret); - close(DATA_SOCK); - return ret; - } - local_port++; - if(local_port > 50000) - local_port = 35000; - }else{ - printf("%d:FTPDataStart, port : %d\r\n",DATA_SOCK, local_port); - if((ret=socket(DATA_SOCK, Sn_MR_TCP, local_port, 0x0)) != DATA_SOCK){ - printf("%d:socket() error:%ld\r\n", DATA_SOCK, ret); - close(DATA_SOCK); - return ret; - } - local_port++; - if(local_port > 50000) - local_port = 35000; - } - ftpc.dsock_state = DATASOCK_START; - } - break; - - case SOCK_INIT : - printf("%d:Opened\r\n",DATA_SOCK); - if(ftpc.dsock_mode == ACTIVE_MODE){ - if( (ret = listen(DATA_SOCK)) != SOCK_OK){ - printf("%d:Listen error\r\n",DATA_SOCK); - return ret; - } - gDataSockReady = 1; - printf("%d:Listen ok\r\n",DATA_SOCK); - }else{ - if((ret = connect(DATA_SOCK, remote_ip.cVal, remote_port)) != SOCK_OK){ - printf("%d:Connect error\r\n", DATA_SOCK); - return ret; - } - gDataSockReady = 1; - } - connect_state_data_ftpc = 0; - break; - default : - break; - } -#endif - return 0; -} - -char proc_ftpc(char * buf) -{ - uint16_t Responses; - uint8_t dat[30]={0,}; - - Responses =(buf[0]-'0')*100+(buf[1]-'0')*10+(buf[2]-'0'); - - switch(Responses){ - case R_220: /* Service ready for new user. */ - printf("\r\nInput your User ID > "); - sprintf(dat,"USER %s\r\n", User_Keyboard_MSG()); - printf("\r\n"); - send(CTRL_SOCK, (uint8_t *)dat, strlen(dat)); - break; - - case R_331: /* User name okay, need password. */ - printf("\r\nInput your Password > "); - sprintf(dat,"PASS %s\r\n", User_Keyboard_MSG()); - printf("\r\n"); - send(CTRL_SOCK, (uint8_t *)dat, strlen(dat)); - break; - case R_230: /* User logged in, proceed */ - printf("\r\nUser logged in, proceed\r\n"); - - sprintf(dat,"TYPE %c\r\n", TransferAscii); - ftpc.type = ASCII_TYPE; - send(CTRL_SOCK, (uint8_t *)dat, strlen(dat)); - break; - case R_200: - if((ftpc.dsock_mode==ACTIVE_MODE)&&gModeActivePassiveflag){ - ftpc.dsock_state = DATASOCK_READY; - gModeActivePassiveflag = 0; - } - else{ - gMenuStart = 1; - } - break; - case R_150: - switch(Command.First){ - case f_dir: - Command.First = f_nocmd; - Command.Second = s_dir; - gDataPutGetStart = 1; - break; - case f_get: - Command.First = f_nocmd; - Command.Second = s_get; - gDataPutGetStart = 1; - break; - case f_put: - Command.First = f_nocmd; - Command.Second = s_put; - gDataPutGetStart = 1; - break; - default : - printf("Command.First = default\r\n"); - break; - } - break; - case R_226: - gMenuStart = 1; - break; - case R_227: - if (pportc(buf) == -1){ - printf("Bad port syntax\r\n"); - } - else{ - printf("Go Open Data Sock...\r\n "); - ftpc.dsock_mode = PASSIVE_MODE; - ftpc.dsock_state = DATASOCK_READY; - } - break; - default: - printf("\r\nDefault Status = %d\r\n",(uint16_t)Responses); - gDataSockReady = 1; - break; - } - return 1; -} -int pportc(char * arg) -{ - int i; - char* tok=0; - strtok(arg,"("); - for (i = 0; i < 4; i++) - { - if(i==0) tok = strtok(NULL,",\r\n"); - else tok = strtok(NULL,","); - remote_ip.cVal[i] = (uint8_t)atoi(tok); - if (!tok){ - printf("bad pport : %s\r\n", arg); - return -1; - } - } - remote_port = 0; - for (i = 0; i < 2; i++){ - tok = strtok(NULL,",\r\n"); - remote_port <<= 8; - remote_port += atoi(tok); - if (!tok){ - printf("bad pport : %s\r\n", arg); - return -1; - } - } - printf("ip : %d.%d.%d.%d, port : %d\r\n", remote_ip.cVal[0], remote_ip.cVal[1], remote_ip.cVal[2], remote_ip.cVal[3], remote_port); - return 0; -} -uint8_t* User_Keyboard_MSG() -{ - uint8_t i=0; - do{ - gMsgBuf[i] = ftp_getc(); - i++; - }while(gMsgBuf[i-1]!=0x0d); - gMsgBuf[i-1]=0; - return gMsgBuf; -} diff --git a/lib/ioLibrary_Driver/FTPClient/ftpc.h b/lib/ioLibrary_Driver/FTPClient/ftpc.h deleted file mode 100644 index ef2be52..0000000 --- a/lib/ioLibrary_Driver/FTPClient/ftpc.h +++ /dev/null @@ -1,130 +0,0 @@ -#ifndef _FTPC_H_ -#define _FTPC_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "socket.h" - -/* If you need this header, use it. */ -//#include "stdio_private.h" - -#define F_APP_FTPC - -/* If your target support a file system, you have to activate this feature and implement. */ -//#define F_FILESYSTEM - -/* Change to your Chipset Uart function, you have to activate this feature and implement. - * Change!! -> Board_UARTGetCharBlocking() - * Below is an example of a function of lpc_chip library. */ -//#define ftp_getc() Board_UARTGetCharBlocking() - -#ifdef F_FILESYSTEM -#include "ff.h" -#endif - -#ifndef ftp_getc() -#define Need_UARTGetCharBlocking_func -#else -/* Change library - * Change!! -> board_api.h, - * Below is an example of a function of lpc_chip library. */ -#include "board_api.h" -#endif - - -#define LINELEN 100 -#ifndef F_FILESYSTEM -#define _MAX_SS 512 -#endif - -#define CTRL_SOCK 2 -#define DATA_SOCK 3 - -/* FTP Responses */ -#define R_150 150 /* File status ok; opening data conn */ -#define R_200 200 /* 'Generic' command ok */ -#define R_220 220 /* Service ready for new user. */ -#define R_226 226 /* Closing data connection. File transfer/abort successful */ -#define R_227 227 /* Entering passive mode (h1,h2,h3,h4,p1,p2) */ -#define R_230 230 /* User logged in, proceed */ -#define R_331 331 /* User name okay, need password. */ - -#define TransferAscii 'A' -#define TransferBinary 'I' - -enum ftpc_type { - ASCII_TYPE, - IMAGE_TYPE, -}; - -enum ftpc_datasock_state{ - DATASOCK_IDLE, - DATASOCK_READY, - DATASOCK_START -}; - -enum ftpc_datasock_mode{ - PASSIVE_MODE, - ACTIVE_MODE -}; -enum CommandFirst { - f_nocmd, - f_dir, - f_put, - f_get, -}; -enum CommandSecond { - s_nocmd, - s_dir, - s_put, - s_get, -}; -struct Command { - enum CommandFirst First; - enum CommandSecond Second; -}; -struct ftpc { - uint8_t control; /* Control stream */ - uint8_t data; /* Data stream */ - - enum ftpc_type type; /* Transfer type */ - - enum ftpc_datasock_state dsock_state; - enum ftpc_datasock_mode dsock_mode; - - char workingdir[LINELEN]; - char filename[LINELEN]; - -#ifdef F_FILESYSTEM - FIL fil; // FatFs File objects - FRESULT fr; // FatFs function common result code -#endif -}; - -#ifndef un_I2cval -typedef union _un_l2cval { - uint32_t lVal; - uint8_t cVal[4]; -}un_l2cval; -#endif - -void ftpc_init(uint8_t * src_ip); -uint8_t ftpc_run(uint8_t * dbuf); -char proc_ftpc(char * buf); -int pportc(char * arg); -uint8_t* User_Keyboard_MSG(); - -#ifdef __cplusplus -} -#endif - -#endif // _FTPC_H_ diff --git a/lib/ioLibrary_Driver/FTPClient/stdio_private.h b/lib/ioLibrary_Driver/FTPClient/stdio_private.h deleted file mode 100644 index a81d94c..0000000 --- a/lib/ioLibrary_Driver/FTPClient/stdio_private.h +++ /dev/null @@ -1,75 +0,0 @@ -/* Copyright (c) 2002, Joerg Wunsch - 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 copyright holders nor the names of - 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. -*/ - -/* $Id: stdio_private.h,v 1.6 2003/01/07 22:17:24 joerg_wunsch Exp $ */ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -struct __file { - char *buf; /* buffer pointer */ - unsigned char unget; /* ungetc() buffer */ - uint8_t flags; /* flags, see below */ -#define __SRD 0x0001 /* OK to read */ -#define __SWR 0x0002 /* OK to write */ -#define __SSTR 0x0004 /* this is an sprintf/snprintf string */ -#define __SPGM 0x0008 /* fmt string is in progmem */ -#define __SERR 0x0010 /* found error */ -#define __SEOF 0x0020 /* found EOF */ -#define __SUNGET 0x040 /* ungetc() happened */ -#if 0 -/* possible future extensions, will require uint16_t flags */ -#define __SRW 0x0080 /* open for reading & writing */ -#define __SLBF 0x0100 /* line buffered */ -#define __SNBF 0x0200 /* unbuffered */ -#define __SMBF 0x0400 /* buf is from malloc */ -#endif - int size; /* size of buffer */ - int len; /* characters read or written so far */ - int (*put)(char); /* function to write one char to device */ - int (*get)(void); /* function to read one char from device */ -}; - -/* values for PRINTF_LEVEL */ -#define PRINTF_MIN 1 -#define PRINTF_STD 2 -#define PRINTF_FLT 3 - -/* values for SCANF_LEVEL */ -#define SCANF_MIN 1 -#define SCANF_STD 2 -#define SCANF_FLT 3 - -#ifdef __cplusplus -} -#endif diff --git a/lib/ioLibrary_Driver/FTPServer/README.md b/lib/ioLibrary_Driver/FTPServer/README.md deleted file mode 100755 index c4905e6..0000000 --- a/lib/ioLibrary_Driver/FTPServer/README.md +++ /dev/null @@ -1,64 +0,0 @@ -# FTP Server - -## init wizchip -### variable and function - - uint8_t gFTPBUF[_MAX_SS]; - uint8_t wiznet_memsize[2][8] = {{8,8,8,8,8,8,8,8}, {8,8,8,8,8,8,8,8}}; - #define ETH_MAX_BUF_SIZE 2048 - uint8_t ethBuf0[ETH_MAX_BUF_SIZE]; - wiz_NetInfo gWIZNETINFO = { - .mac = {0x00, 0x08, 0xdc, 0x11, 0x22, 0x33}, - .ip = {192, 168, 15, 111}, - .sn = {255, 255, 255, 0}, - .gw = {192, 168, 15, 1}, - .dns = {8, 8, 8, 8}, - .dhcp = NETINFO_STATIC - - - -### run init funciton in main funcion - - Reset_WIZCHIP(); - reg_wizchip_bus_cbfunc(Chip_read, Chip_write); - reg_wizchip_cs_cbfunc(ChipCsEnable, ChipCsDisable); - - if (ctlwizchip(CW_INIT_WIZCHIP, (void*)wiznet_memsize) == -1) - { - printf("WIZchip memory initialization failed\r\n"); - } - - ctlnetwork(CN_SET_NETINFO, (void *)&gWIZNETINFO); - print_network_information(); - - -## Run function - - if((ret = ftpd_run(gFTPBUF)) < 0) - { - porintf(" FTP server Error %d \r\n", ret); - } - -## FTP ID & PASSWORD - -### USED ID -#### ID Enable in ftpd_init function - - ftp.ID_Enable = STATUS_USED; - -#### ID Setting - - #define ftp_ID "wiznet" - -### USED PASSWORD -#### PW Enable in ftpd_init function - - ftp.PW_Enable = STATUS_USED; - -#### PW Setting - - #define ftp_PW "wiznet54321" - -### Connedtion remain count - - #define remain_time 400000 diff --git a/lib/ioLibrary_Driver/FTPServer/ftpd.c b/lib/ioLibrary_Driver/FTPServer/ftpd.c deleted file mode 100644 index 0a71f62..0000000 --- a/lib/ioLibrary_Driver/FTPServer/ftpd.c +++ /dev/null @@ -1,1233 +0,0 @@ -/* -* Wiznet. -* (c) Copyright 2002, Wiznet. -* -* Filename : ftpd.c -* Version : 1.0 -* Programmer(s) : -* Created : 2003/01/28 -* Description : FTP daemon. (AVR-GCC Compiler) -*/ - - -#include -#include -#include -#include -#include -#include -#include "socket.h" -#include "ftpd.h" - -/* If you need this header, use it. */ -//#include "stdio_private.h" - -/* Command table */ -static char *commands[] = { - "user", - "acct", - "pass", - "type", - "list", - "cwd", - "dele", - "name", - "quit", - "retr", - "stor", - "port", - "nlst", - "pwd", - "xpwd", - "mkd", - "xmkd", - "xrmd", - "rmd ", - "stru", - "mode", - "syst", - "xmd5", - "xcwd", - "feat", - "pasv", - "size", - "mlsd", - "appe", - NULL -}; - -#if 0 -/* Response messages */ -char banner[] = "220 %s FTP version %s ready.\r\n"; -char badcmd[] = "500 Unknown command '%s'\r\n"; -char binwarn[] = "100 Warning: type is ASCII and %s appears to be binary\r\n"; -char unsupp[] = "500 Unsupported command or option\r\n"; -char givepass[] = "331 Enter PASS command\r\n"; -char logged[] = "230 Logged in\r\n"; -char typeok[] = "200 Type %s OK\r\n"; -char only8[] = "501 Only logical bytesize 8 supported\r\n"; -char deleok[] = "250 File deleted\r\n"; -char mkdok[] = "200 MKD ok\r\n"; -char delefail[] = "550 Delete failed: %s\r\n"; -char pwdmsg[] = "257 \"%s\" is current directory\r\n"; -char badtype[] = "501 Unknown type \"%s\"\r\n"; -char badport[] = "501 Bad port syntax\r\n"; -char unimp[] = "502 Command does not implemented yet.\r\n"; -char bye[] = "221 Goodbye!\r\n"; -char nodir[] = "553 Can't read directory \"%s\": %s\r\n"; -char cantopen[] = "550 Can't read file \"%s\": %s\r\n"; -char sending[] = "150 Opening data connection for %s (%d.%d.%d.%d,%d)\r\n"; -char cantmake[] = "553 Can't create \"%s\": %s\r\n"; -char writerr[] = "552 Write error: %s\r\n"; -char portok[] = "200 PORT command successful.\r\n"; -char rxok[] = "226 Transfer complete.\r\n"; -char txok[] = "226 Transfer complete.\r\n"; -char noperm[] = "550 Permission denied\r\n"; -char noconn[] = "425 Data connection reset\r\n"; -char lowmem[] = "421 System overloaded, try again later\r\n"; -char notlog[] = "530 Please log in with USER and PASS\r\n"; -char userfirst[] = "503 Login with USER first.\r\n"; -char okay[] = "200 Ok\r\n"; -char syst[] = "215 %s Type: L%d Version: %s\r\n"; -char sizefail[] = "550 File not found\r\n"; -#endif -#define remain_time 400000 -#define connect_timeout_en 1 -#define ftp_ID "wiznet" -#define ftp_PW "wiznet54321" - -un_l2cval remote_ip; -uint16_t remote_port; -un_l2cval local_ip; -uint16_t local_port; -uint8_t connect_state_control = 0; -uint8_t connect_state_control1 = 0; -uint8_t connect_state_data = 0; -uint8_t connect_count = 0; -uint32_t con_remain_cnt1 = 0; -uint32_t con_remain_cnt2 = 0; -uint8_t cur_sn = CTRL_SOCK; -struct ftpd ftp; - -int current_year = 2014; -int current_month = 12; -int current_day = 31; -int current_hour = 10; -int current_min = 10; -int current_sec = 30; - -int fsprintf(uint8_t s, const char *format, ...) -{ - int i; -/* - char buf[LINELEN]; - FILE f; - va_list ap; - - f.flags = __SWR | __SSTR; - f.buf = buf; - f.size = INT_MAX; - va_start(ap, format); - i = vfprintf(&f, format, ap); - va_end(ap); - buf[f.len] = 0; - - send(s, (uint8_t *)buf, strlen(buf)); -*/ - return i; -} - -void ftpd_init(uint8_t * src_ip) -{ - ftp.state = FTPS_NOT_LOGIN; - ftp.current_cmd = NO_CMD; - ftp.dsock_mode = ACTIVE_MODE; - - ftp.ID_Enable = STATUS_USED; - ftp.PW_Enable = STATUS_USED; - - if(ftp.ID_Enable == STATUS_USED) - { - strcpy(ftp.username, ftp_ID); - printf(" FTP ID[%d]:%s \r\n", strlen(ftp.username), ftp.username); - } - if(ftp.PW_Enable == STATUS_USED) - { - strcpy(ftp.userpassword, ftp_PW); - printf(" FTP PW[%d]:%s \r\n", strlen(ftp.userpassword), ftp.userpassword); - } - - - - local_ip.cVal[0] = src_ip[0]; - local_ip.cVal[1] = src_ip[1]; - local_ip.cVal[2] = src_ip[2]; - local_ip.cVal[3] = src_ip[3]; - local_port = 35000; - - strcpy(ftp.workingdir, "/"); - - socket(CTRL_SOCK, Sn_MR_TCP, IPPORT_FTP, 0x0); - socket(CTRL_SOCK1, Sn_MR_TCP, IPPORT_FTP, 0x0); -} - -uint8_t ftpd_run(uint8_t * dbuf) -{ - uint16_t size = 0, i; - long ret = 0; - uint32_t blocklen, send_byte, recv_byte; - uint32_t remain_filesize; - int32_t remain_datasize; - //static uint32_t con_remain_cnt1 = 0; - //static uint32_t con_remain_cnt2 = 0; -#if defined(F_FILESYSTEM) - //FILINFO fno; -#endif - - //memset(dbuf, 0, sizeof(_MAX_SS)); - ////////////////////////FTP Control 1 - #if 1 - switch(getSn_SR(CTRL_SOCK)) - { - case SOCK_ESTABLISHED : - if(!connect_state_control) - { -#if defined(_FTP_DEBUG_) - printf("%d:FTP Connected\r\n", CTRL_SOCK); -#endif - //fsprintf(CTRL_SOCK, banner, HOSTNAME, VERSION); - strcpy(ftp.workingdir, "/"); - sprintf((char *)dbuf, "220 %s FTP version %s ready.\r\n", HOSTNAME, VERSION); - ret = send(CTRL_SOCK, (uint8_t *)dbuf, strlen((const char *)dbuf)); - -#if defined(_FTP_DEBUG_) - printf("%d:send() [%s]\r\n",CTRL_SOCK,dbuf); -#endif - if(ret < 0) - { -#if defined(_FTP_DEBUG_) - printf("%d:send() error:%ld\r\n",CTRL_SOCK,ret); -#endif - close(CTRL_SOCK); - return ret; - } - connect_state_control = 1; - } - #if connect_timeout_en - else - { - if(con_remain_cnt1 > remain_time) - { - if((ret=disconnect(CTRL_SOCK)) != SOCK_OK) return ret; - #if defined(_FTP_DEBUG_) - printf("%d:Timeout Closed\r\n",CTRL_SOCK); - #endif - } - #if defined(_FTP_DEBUG_) - else if(((con_remain_cnt1 % 10000) == 0) && (con_remain_cnt1 != 0)) - { - printf("%d:Timeout Count:%ld\r\n", CTRL_SOCK, con_remain_cnt1); - } - #endif - con_remain_cnt1++; - } - #endif - -#if defined(_FTP_DEBUG_) - //printf("ftp socket %d\r\n", CTRL_SOCK); -#endif - - if((size = getSn_RX_RSR(CTRL_SOCK)) > 0) // Don't need to check SOCKERR_BUSY because it doesn't not occur. - { -#if defined(_FTP_DEBUG_) - printf("%d:size: %d\r\n", CTRL_SOCK, size); -#endif - - memset(dbuf, 0, _MAX_SS); - - if(size > _MAX_SS) size = _MAX_SS - 1; - - ret = recv(CTRL_SOCK,dbuf,size); - dbuf[ret] = '\0'; - if(ret != size) - { - if(ret==SOCK_BUSY) return 0; - if(ret < 0) - { -#if defined(_FTP_DEBUG_) - printf("%d:recv() error:%ld\r\n",CTRL_SOCK,ret); -#endif - close(CTRL_SOCK); - return ret; - } - } -#if defined(_FTP_DEBUG_) - printf("%d:Rcvd Command: %s", CTRL_SOCK, dbuf); -#endif - proc_ftpd(CTRL_SOCK, (char *)dbuf); - con_remain_cnt1 = 0; - } - break; - - case SOCK_CLOSE_WAIT : -#if defined(_FTP_DEBUG_) - printf("%d:CloseWait\r\n",CTRL_SOCK); -#endif - if((ret=disconnect(CTRL_SOCK)) != SOCK_OK) return ret; -#if defined(_FTP_DEBUG_) - printf("%d:Closed\r\n",CTRL_SOCK); -#endif - break; - - case SOCK_CLOSED : -#if defined(_FTP_DEBUG_) - printf("%d:FTPStart\r\n",CTRL_SOCK); -#endif - if((ret=socket(CTRL_SOCK, Sn_MR_TCP, IPPORT_FTP, 0x0)) != CTRL_SOCK) - { -#if defined(_FTP_DEBUG_) - printf("%d:socket() error:%ld\r\n", CTRL_SOCK, ret); -#endif - close(CTRL_SOCK); - return ret; - } - break; - - case SOCK_INIT : -#if defined(_FTP_DEBUG_) - printf("%d:Opened\r\n",CTRL_SOCK); -#endif - //strcpy(ftp.workingdir, "/"); - if( (ret = listen(CTRL_SOCK)) != SOCK_OK) - { -#if defined(_FTP_DEBUG_) - printf("%d:Listen error\r\n",CTRL_SOCK); -#endif - return ret; - } - connect_state_control = 0; - con_remain_cnt1 = 0; - -#if defined(_FTP_DEBUG_) - printf("%d:Listen ok\r\n",CTRL_SOCK); -#endif - break; - - default : - break; - } - ////////////////////////FTP Control 2 - - switch(getSn_SR(CTRL_SOCK1)) - { - case SOCK_ESTABLISHED : - if(!connect_state_control1) - { -#if defined(_FTP_DEBUG_) - printf("%d:FTP Connected\r\n", CTRL_SOCK1); -#endif - strcpy(ftp.workingdir, "/"); - sprintf((char *)dbuf, "220 %s FTP version %s ready.\r\n", HOSTNAME, VERSION); - ret = send(CTRL_SOCK1, (uint8_t *)dbuf, strlen((const char *)dbuf)); - -#if defined(_FTP_DEBUG_) - printf("%d:send() [%s]\r\n",CTRL_SOCK1,dbuf); -#endif - if(ret < 0) - { -#if defined(_FTP_DEBUG_) - printf("%d:send() error:%ld\r\n",CTRL_SOCK1,ret); -#endif - close(CTRL_SOCK1); - return ret; - } - connect_state_control1 = 1; - } - #if connect_timeout_en - else - { - if(con_remain_cnt2 > remain_time) - { - if((ret=disconnect(CTRL_SOCK1)) != SOCK_OK) return ret; - #if defined(_FTP_DEBUG_) - printf("%d:Timeout Closed\r\n",CTRL_SOCK1); - #endif - } - #if defined(_FTP_DEBUG_) - else if(((con_remain_cnt2 % 10000) == 0) && (con_remain_cnt2 != 0)) - { - printf("%d:Timeout Count:%ld\r\n", CTRL_SOCK1, con_remain_cnt2); - } - #endif - con_remain_cnt2++; - } - #endif - -#if defined(_FTP_DEBUG_) - //printf("ftp socket %d\r\n", CTRL_SOCK); -#endif - - if((size = getSn_RX_RSR(CTRL_SOCK1)) > 0) // Don't need to check SOCKERR_BUSY because it doesn't not occur. - { -#if defined(_FTP_DEBUG_) - printf("%d: size: %d\r\n", CTRL_SOCK1, size); -#endif - - memset(dbuf, 0, _MAX_SS); - - if(size > _MAX_SS) size = _MAX_SS - 1; - - ret = recv(CTRL_SOCK1,dbuf,size); - dbuf[ret] = '\0'; - if(ret != size) - { - if(ret==SOCK_BUSY) return 0; - if(ret < 0) - { -#if defined(_FTP_DEBUG_) - printf("%d:recv() error:%ld\r\n",CTRL_SOCK1,ret); -#endif - close(CTRL_SOCK1); - return ret; - } - } -#if defined(_FTP_DEBUG_) - printf("%d: Rcvd Command: %s", CTRL_SOCK1, dbuf); -#endif - proc_ftpd(CTRL_SOCK1, (char *)dbuf); - con_remain_cnt2 = 0; - } - break; - - case SOCK_CLOSE_WAIT : -#if defined(_FTP_DEBUG_) - printf("%d:CloseWait\r\n",CTRL_SOCK1); -#endif - if((ret=disconnect(CTRL_SOCK1)) != SOCK_OK) return ret; - connect_count--; -#if defined(_FTP_DEBUG_) - printf("%d:Closed\r\n",CTRL_SOCK1); -#endif - break; - - case SOCK_CLOSED : -#if defined(_FTP_DEBUG_) - printf("%d:FTPStart\r\n",CTRL_SOCK1); -#endif - if((ret=socket(CTRL_SOCK1, Sn_MR_TCP, IPPORT_FTP, 0x0)) != CTRL_SOCK1) - { -#if defined(_FTP_DEBUG_) - printf("%d:socket() error:%ld\r\n", CTRL_SOCK1, ret); -#endif - close(CTRL_SOCK1); - return ret; - } - break; - - case SOCK_INIT : -#if defined(_FTP_DEBUG_) - printf("%d:Opened\r\n",CTRL_SOCK1); -#endif - //strcpy(ftp.workingdir, "/"); - if( (ret = listen(CTRL_SOCK1)) != SOCK_OK) - { -#if defined(_FTP_DEBUG_) - printf("%d:Listen error\r\n",CTRL_SOCK1); -#endif - return ret; - } - connect_state_control1 = 0; - con_remain_cnt2 = 0; -#if defined(_FTP_DEBUG_) - printf("%d:Listen ok\r\n",CTRL_SOCK1); -#endif - break; - - default : - break; - } - - #endif -/////////////////////////////////// ftp data part -#if 1 - switch(getSn_SR(DATA_SOCK)) - { - case SOCK_ESTABLISHED : - if(!connect_state_data) - { -#if defined(_FTP_DEBUG_) - printf("%d:FTP Data socket Connected\r\n", DATA_SOCK); -#endif - connect_state_data = 1; - } - - switch(ftp.current_cmd) - { - case LIST_CMD: - case MLSD_CMD: -#if defined(_FTP_DEBUG_) - printf("previous size: %d\r\n", size); -#endif -#if defined(F_FILESYSTEM) - scan_files(ftp.workingdir, dbuf, (int *)&size); -#endif -#if defined(_FTP_DEBUG_) - printf("returned size: %d\r\n", size); - printf("%s\r\n", dbuf); -#endif -#if !defined(F_FILESYSTEM) - if (strncmp(ftp.workingdir, "/$Recycle.Bin", sizeof("/$Recycle.Bin")) != 0) - size = sprintf(dbuf, "drwxr-xr-x 1 ftp ftp 0 Dec 31 2014 $Recycle.Bin\r\n-rwxr-xr-x 1 ftp ftp 512 Dec 31 2014 test.txt\r\n"); -#endif - size = strlen(dbuf); - send(DATA_SOCK, dbuf, size); - ftp.current_cmd = NO_CMD; - disconnect(DATA_SOCK); - size = sprintf(dbuf, "226 Successfully transferred \"%s\"\r\n", ftp.workingdir); - send(cur_sn, dbuf, size); - break; - - case RETR_CMD: -#if defined(_FTP_DEBUG_) - printf("filename to retrieve : %s %d\r\n", ftp.filename, strlen(ftp.filename)); -#endif -#if defined(F_FILESYSTEM) - ftp.fr = f_open(&(ftp.fil), (const char *)ftp.filename, FA_READ); - //print_filedsc(&(ftp.fil)); - if(ftp.fr == FR_OK){ - remain_filesize = ftp.fil.fsize; -#if defined(_FTP_DEBUG_) - printf("f_open return FR_OK\r\n"); -#endif - do{ -#if defined(_FTP_DEBUG_) - //printf("remained file size: %d\r\n", ftp.fil.fsize); -#endif - memset(dbuf, 0, _MAX_SS); - - if(remain_filesize > _MAX_SS) - send_byte = _MAX_SS; - else - send_byte = remain_filesize; - - ftp.fr = f_read(&(ftp.fil), dbuf, send_byte , &blocklen); - if(ftp.fr != FR_OK) - break; -#if defined(_FTP_DEBUG_) - printf("#"); - //printf("----->fsize:%d recv:%d len:%d \r\n", remain_filesize, send_byte, blocklen); - //printf("----->fn:%s data:%s \r\n", ftp.filename, dbuf); -#endif - send(DATA_SOCK, dbuf, blocklen); - remain_filesize -= blocklen; - }while(remain_filesize != 0); -#if defined(_FTP_DEBUG_) - printf("\r\nFile read finished\r\n"); -#endif - ftp.fr = f_close(&(ftp.fil)); - }else{ -#if defined(_FTP_DEBUG_) - printf("File Open Error: %d\r\n", ftp.fr); -#endif - } -#else - remain_filesize = strlen(ftp.filename); - #if defined(_FTP_DEBUG_) - printf("<<<<<1recv data[%d]\r\n", remain_datasize); - #endif - do{ - memset(dbuf, 0, _MAX_SS); - - blocklen = sprintf(dbuf, "%s", ftp.filename); - - printf("####1[%d] dbuf:%s\r\n",remain_filesize ,dbuf); - - send(DATA_SOCK, dbuf, blocklen); - remain_filesize -= blocklen; - }while(remain_filesize != 0); - -#endif - ftp.current_cmd = NO_CMD; - disconnect(DATA_SOCK); - size = sprintf(dbuf, "226 Successfully transferred \"%s\"\r\n", ftp.filename); - send(cur_sn, dbuf, size); - break; - - case STOR_CMD: -#if defined(_FTP_DEBUG_) - printf("filename to store : %s %d\r\n", ftp.filename, strlen(ftp.filename)); -#endif -#if defined(F_FILESYSTEM) - ftp.fr = f_open(&(ftp.fil), (const char *)ftp.filename, FA_CREATE_ALWAYS | FA_WRITE); - //print_filedsc(&(ftp.fil)); - if(ftp.fr == FR_OK){ -#if defined(_FTP_DEBUG_) - printf("f_open return FR_OK\r\n"); -#endif - while(1){ - if((remain_datasize = getSn_RX_RSR(DATA_SOCK)) > 0){ - while(1){ - memset(dbuf, 0, _MAX_SS); - - if(remain_datasize > _MAX_SS) - recv_byte = _MAX_SS; - else - recv_byte = remain_datasize; - - ret = recv(DATA_SOCK, dbuf, recv_byte); -#if defined(_FTP_DEBUG_) - //printf("----->fn:%s data:%s \r\n", ftp.filename, dbuf); -#endif - - ftp.fr = f_write(&(ftp.fil), dbuf, (UINT)ret, &blocklen); -#if defined(_FTP_DEBUG_) - //printf("----->dsize:%d recv:%d len:%d \r\n", remain_datasize, ret, blocklen); -#endif - remain_datasize -= blocklen; - - if(ftp.fr != FR_OK){ -#if defined(_FTP_DEBUG_) - printf("f_write failed\r\n"); -#endif - break; - } - - if(remain_datasize <= 0) - break; - } - - if(ftp.fr != FR_OK){ -#if defined(_FTP_DEBUG_) - printf("f_write failed\r\n"); -#endif - break; - } - -#if defined(_FTP_DEBUG_) - printf("#"); -#endif - }else{ - if(getSn_SR(DATA_SOCK) != SOCK_ESTABLISHED) - break; - } - } -#if defined(_FTP_DEBUG_) - printf("\r\nFile write finished\r\n"); -#endif - ftp.fr = f_close(&(ftp.fil)); - }else{ -#if defined(_FTP_DEBUG_) - printf("File Open Error: %d\r\n", ftp.fr); -#endif - } - - //fno.fdate = (WORD)(((current_year - 1980) << 9) | (current_month << 5) | current_day); - //fno.ftime = (WORD)((current_hour << 11) | (current_min << 5) | (current_sec >> 1)); - //f_utime((const char *)ftp.filename, &fno); -#else - while(1){ - if((remain_datasize = getSn_RX_RSR(DATA_SOCK)) > 0){ - #if defined(_FTP_DEBUG_) - printf("<<<<<2recv data[%ld]\r\n", remain_datasize); - #endif - while(1){ - memset(dbuf, 0, _MAX_SS); - - if(remain_datasize > _MAX_SS) - recv_byte = _MAX_SS; - else - recv_byte = remain_datasize; - - ret = recv(DATA_SOCK, dbuf, recv_byte); - if(ret < 0) - { - #if defined(_FTP_DEBUG_) - printf("finish ret[%d\r\n", ret); - #endif - break; - } - - #if defined(_FTP_DEBUG_) - printf("#####2[%ld] dbuf:%s\r\n", remain_datasize, dbuf); - #endif - - remain_datasize -= ret; - #if defined(_FTP_DEBUG_) - printf("###ret:%ld,remain:%d\r\n",ret, remain_datasize); - #endif - - if(remain_datasize <= 0) - break; - } - }else{ - if(getSn_SR(DATA_SOCK) != SOCK_ESTABLISHED) - break; - } - } -#endif - ftp.current_cmd = NO_CMD; - disconnect(DATA_SOCK); - size = sprintf(dbuf, "226 Successfully transferred \"%s\"\r\n", ftp.filename); - send(cur_sn, dbuf, size); - break; - - case NO_CMD: - default: - break; - } - break; - - case SOCK_CLOSE_WAIT : -#if defined(_FTP_DEBUG_) - printf("%d:CloseWait\r\n",DATA_SOCK); -#endif - if((ret=disconnect(DATA_SOCK)) != SOCK_OK) return ret; -#if defined(_FTP_DEBUG_) - printf("%d:Closed\r\n",DATA_SOCK); -#endif - break; - - case SOCK_CLOSED : - if(ftp.dsock_state == DATASOCK_READY) - { - if(ftp.dsock_mode == PASSIVE_MODE){ -#if defined(_FTP_DEBUG_) - printf("%d:FTPDataStart, port : %d\r\n",DATA_SOCK, local_port); -#endif - if((ret=socket(DATA_SOCK, Sn_MR_TCP, local_port, 0x0)) != DATA_SOCK) - { -#if defined(_FTP_DEBUG_) - printf("%d:socket() error:%ld\r\n", DATA_SOCK, ret); -#endif - close(DATA_SOCK); - return ret; - } - - local_port++; - if(local_port > 50000) - local_port = 35000; - }else{ -#if defined(_FTP_DEBUG_) - printf("%d:FTPDataStart, port : %d\r\n",DATA_SOCK, IPPORT_FTPD); -#endif - if((ret=socket(DATA_SOCK, Sn_MR_TCP, IPPORT_FTPD, 0x0)) != DATA_SOCK) - { -#if defined(_FTP_DEBUG_) - printf("%d:socket() error:%ld\r\n", DATA_SOCK, ret); -#endif - close(DATA_SOCK); - return ret; - } - } - - ftp.dsock_state = DATASOCK_START; - } - break; - - case SOCK_INIT : -#if defined(_FTP_DEBUG_) - printf("%d:Opened\r\n",DATA_SOCK); -#endif - if(ftp.dsock_mode == PASSIVE_MODE){ - if( (ret = listen(DATA_SOCK)) != SOCK_OK) - { -#if defined(_FTP_DEBUG_) - printf("%d:Listen error\r\n",DATA_SOCK); -#endif - return ret; - } - -#if defined(_FTP_DEBUG_) - printf("%d:Listen ok\r\n",DATA_SOCK); -#endif - }else{ - if((ret = connect(DATA_SOCK, remote_ip.cVal, remote_port)) != SOCK_OK){ -#if defined(_FTP_DEBUG_) - printf("%d:Connect error\r\n", DATA_SOCK); -#endif - return ret; - } - } - connect_state_data = 0; - break; - - default : - break; - } -#endif - - return 0; -} - -char proc_ftpd(uint8_t sn, char * buf) -{ - char **cmdp, *cp, *arg, *tmpstr; - char sendbuf[200]; - int slen; - long ret; - - - /* Translate first word to lower case */ - for (cp = buf; *cp != ' ' && *cp != '\0'; cp++) - *cp = tolower(*cp); - - /* Find command in table; if not present, return syntax error */ - for (cmdp = commands; *cmdp != NULL; cmdp++) - if (strncmp(*cmdp, buf, strlen(*cmdp)) == 0) - break; - - if (*cmdp == NULL) - { - //fsprintf(CTRL_SOCK, badcmd, buf); - slen = sprintf(sendbuf, "500 Unknown command '%s'\r\n", buf); - send(sn, (uint8_t *)sendbuf, slen); - return 0; - } - /* Allow only USER, PASS and QUIT before logging in */ - if (ftp.state == FTPS_NOT_LOGIN) - { - switch(cmdp - commands) - { - case USER_CMD: - case PASS_CMD: - case QUIT_CMD: - break; - default: - //fsprintf(CTRL_SOCK, notlog); - slen = sprintf(sendbuf, "530 Please log in with USER and PASS\r\n"); - send(sn, (uint8_t *)sendbuf, slen); - return 0; - } - } - - arg = &buf[strlen(*cmdp)]; - while(*arg == ' ') arg++; - - /* Execute specific command */ - switch (cmdp - commands) - { - case USER_CMD : -#if defined(_FTP_DEBUG_) - printf("USER_CMD : %s", arg); -#endif - slen = strlen(arg); - arg[slen - 1] = 0x00; - arg[slen - 2] = 0x00; - if(ftp.ID_Enable == STATUS_USED) - { - if(strcmp(ftp.username, arg) != 0) - { - slen = sprintf(sendbuf, "430 Invalid username\r\n"); - ret = send(sn, (uint8_t *)sendbuf, slen); - if(ret < 0) - { - #if defined(_FTP_DEBUG_) - printf("%d:send() error:%ld\r\n",sn,ret); - #endif - close(sn); - return ret; - } - break; - } - } - else - { - strcpy(ftp.username, arg); - } - //fsprintf(CTRL_SOCK, givepass); - slen = sprintf(sendbuf, "331 Enter PASS command\r\n"); - ret = send(sn, (uint8_t *)sendbuf, slen); - if(ret < 0) - { -#if defined(_FTP_DEBUG_) - printf("%d:send() error:%ld\r\n",sn,ret); -#endif - close(sn); - return ret; - } - break; - - case PASS_CMD : -#if defined(_FTP_DEBUG_) - printf("PASS_CMD : %s", arg); -#endif - slen = strlen(arg); - arg[slen - 1] = 0x00; - arg[slen - 2] = 0x00; - if(ftp.PW_Enable == STATUS_USED) - { - if(strcmp(ftp.userpassword, arg) != 0) - { - slen = sprintf(sendbuf, "430 Invalid password\r\n"); - ret = send(sn, (uint8_t *)sendbuf, slen); - if(ret < 0) - { - #if defined(_FTP_DEBUG_) - printf("%d:send() error:%ld\r\n",sn,ret); - #endif - close(sn); - return ret; - } - break; - } - } - ftplogin(sn, arg); - break; - - case TYPE_CMD : - slen = strlen(arg); - arg[slen - 1] = 0x00; - arg[slen - 2] = 0x00; - switch(arg[0]) - { - case 'A': - case 'a': /* Ascii */ - ftp.type = ASCII_TYPE; - //fsprintf(CTRL_SOCK, typeok, arg); - slen = sprintf(sendbuf, "200 Type set to %s\r\n", arg); - send(sn, (uint8_t *)sendbuf, slen); - break; - - case 'B': - case 'b': /* Binary */ - case 'I': - case 'i': /* Image */ - ftp.type = IMAGE_TYPE; - //fsprintf(CTRL_SOCK, typeok, arg); - slen = sprintf(sendbuf, "200 Type set to %s\r\n", arg); - send(sn, (uint8_t *)sendbuf, slen); - break; - - default: /* Invalid */ - //fsprintf(CTRL_SOCK, badtype, arg); - slen = sprintf(sendbuf, "501 Unknown type \"%s\"\r\n", arg); - send(sn, (uint8_t *)sendbuf, slen); - break; - } - break; - - case FEAT_CMD : - slen = sprintf(sendbuf, "211-Features:\r\n MDTM\r\n REST STREAM\r\n SIZE\r\n MLST size*;type*;create*;modify*;\r\n MLSD\r\n UTF8\r\n CLNT\r\n MFMT\r\n211 END\r\n"); - send(sn, (uint8_t *)sendbuf, slen); - break; - - case QUIT_CMD : -#if defined(_FTP_DEBUG_) - printf("QUIT_CMD\r\n"); -#endif - //fsprintf(CTRL_SOCK, bye); - slen = sprintf(sendbuf, "221 Goodbye!\r\n"); - send(sn, (uint8_t *)sendbuf, slen); - disconnect(sn); - break; - - case RETR_CMD : - slen = strlen(arg); - arg[slen - 1] = 0x00; - arg[slen - 2] = 0x00; -#if defined(_FTP_DEBUG_) - printf("RETR_CMD\r\n"); -#endif - if(strlen(ftp.workingdir) == 1) - sprintf(ftp.filename, "/%s", arg); - else - sprintf(ftp.filename, "%s/%s", ftp.workingdir, arg); - slen = sprintf(sendbuf, "150 Opening data channel for file downloand from server of \"%s\"\r\n", ftp.filename); - send(sn, (uint8_t *)sendbuf, slen); - ftp.current_cmd = RETR_CMD; - break; - - case APPE_CMD : - case STOR_CMD: - slen = strlen(arg); - arg[slen - 1] = 0x00; - arg[slen - 2] = 0x00; -#if defined(_FTP_DEBUG_) - printf("STOR_CMD\r\n"); -#endif - if(strlen(ftp.workingdir) == 1) - sprintf(ftp.filename, "/%s", arg); - else - sprintf(ftp.filename, "%s/%s", ftp.workingdir, arg); - slen = sprintf(sendbuf, "150 Opening data channel for file upload to server of \"%s\"\r\n", ftp.filename); - send(sn, (uint8_t *)sendbuf, slen); - ftp.current_cmd = STOR_CMD; - if(ftp.dsock_mode == ACTIVE_MODE) - { - if((ret = connect(DATA_SOCK, remote_ip.cVal, remote_port)) != SOCK_OK){ - #if defined(_FTP_DEBUG_) - printf("%d:Connect error\r\n", DATA_SOCK); - #endif - return ret; - } - } - connect_state_data = 0; - break; - - case PORT_CMD: -#if defined(_FTP_DEBUG_) - printf("PORT_CMD\r\n"); -#endif - if (pport(arg) == -1){ - //fsprintf(CTRL_SOCK, badport); - slen = sprintf(sendbuf, "501 Bad port syntax\r\n"); - send(sn, (uint8_t *)sendbuf, slen); - } else{ - //fsprintf(CTRL_SOCK, portok); - ftp.dsock_mode = ACTIVE_MODE; - ftp.dsock_state = DATASOCK_READY; - slen = sprintf(sendbuf, "200 PORT command successful.\r\n"); - send(sn, (uint8_t *)sendbuf, slen); - } - break; - - case MLSD_CMD: -#if defined(_FTP_DEBUG_) - printf("MLSD_CMD\r\n"); -#endif - slen = sprintf(sendbuf, "150 Opening data channel for directory listing of \"%s\"\r\n", ftp.workingdir); - send(sn, (uint8_t *)sendbuf, slen); - ftp.current_cmd = MLSD_CMD; - break; - - case LIST_CMD: -#if defined(_FTP_DEBUG_) - printf("LIST_CMD\r\n"); -#endif - slen = sprintf(sendbuf, "150 Opening data channel for directory listing of \"%s\"\r\n", ftp.workingdir); - send(sn, (uint8_t *)sendbuf, slen); - ftp.current_cmd = LIST_CMD; - break; - - case NLST_CMD: -#if defined(_FTP_DEBUG_) - printf("NLST_CMD\r\n"); -#endif - break; - - case SYST_CMD: - slen = sprintf(sendbuf, "215 UNIX emulated by WIZnet\r\n"); - send(sn, (uint8_t *)sendbuf, slen); - break; - - case PWD_CMD: - case XPWD_CMD: - slen = sprintf(sendbuf, "257 \"%s\" is current directory.\r\n", ftp.workingdir); - send(sn, (uint8_t *)sendbuf, slen); - break; - - case PASV_CMD: - slen = sprintf(sendbuf, "227 Entering Passive Mode (%d,%d,%d,%d,%d,%d)\r\n", local_ip.cVal[0], local_ip.cVal[1], local_ip.cVal[2], local_ip.cVal[3], local_port >> 8, local_port & 0x00ff); - send(sn, (uint8_t *)sendbuf, slen); - - if(getSn_SR(DATA_SOCK) == SOCK_ESTABLISHED) - { -#if defined(_FTP_DEBUG_) - printf("data disconnect: %d\r\n", DATA_SOCK); -#endif - disconnect(DATA_SOCK); - } - ftp.dsock_mode = PASSIVE_MODE; - ftp.dsock_state = DATASOCK_READY; - cur_sn = sn; -#if defined(_FTP_DEBUG_) - printf("PASV port: %d\r\n", local_port); -#endif - break; - - case SIZE_CMD: - slen = strlen(arg); - arg[slen - 1] = 0x00; - arg[slen - 2] = 0x00; - if(slen > 3) - { - tmpstr = strrchr(arg, '/'); - *tmpstr = 0; -#if defined(F_FILESYSTEM) - slen = get_filesize(arg, tmpstr + 1); -#else - slen = _MAX_SS; -#endif - if(slen > 0) - slen = sprintf(sendbuf, "213 %d\r\n", slen); - else - slen = sprintf(sendbuf, "550 File not Found\r\n"); - } - else - { - slen = sprintf(sendbuf, "550 File not Found\r\n"); - } - send(sn, (uint8_t *)sendbuf, slen); - break; - - case CWD_CMD: - slen = strlen(arg); - arg[slen - 1] = 0x00; - arg[slen - 2] = 0x00; - if(slen > 3) - { - arg[slen - 3] = 0x00; - tmpstr = strrchr(arg, '/'); - *tmpstr = 0; -#if defined(F_FILESYSTEM) - slen = get_filesize(arg, tmpstr + 1); -#else - slen = 0; -#endif - *tmpstr = '/'; - if(slen == 0){ - slen = sprintf(sendbuf, "213 %d\r\n", slen); - strcpy(ftp.workingdir, arg); - slen = sprintf(sendbuf, "250 CWD successful. \"%s\" is current directory.\r\n", ftp.workingdir); - } - else - { - slen = sprintf(sendbuf, "550 CWD failed. \"%s\"\r\n", arg); - } - } - else - { - strcpy(ftp.workingdir, arg); - slen = sprintf(sendbuf, "250 CWD successful. \"%s\" is current directory.\r\n", ftp.workingdir); - } - send(sn, (uint8_t *)sendbuf, slen); - break; - - case MKD_CMD: - case XMKD_CMD: - slen = strlen(arg); - arg[slen - 1] = 0x00; - arg[slen - 2] = 0x00; -#if defined(F_FILESYSTEM) - if (f_mkdir(arg) != 0) - { - slen = sprintf(sendbuf, "550 Can't create directory. \"%s\"\r\n", arg); - } - else - { - slen = sprintf(sendbuf, "257 MKD command successful. \"%s\"\r\n", arg); - //strcpy(ftp.workingdir, arg); - } -#else - slen = sprintf(sendbuf, "550 Can't create directory. Permission denied\r\n"); -#endif - send(sn, (uint8_t *)sendbuf, slen); - break; - - case DELE_CMD: - slen = strlen(arg); - arg[slen - 1] = 0x00; - arg[slen - 2] = 0x00; -#if defined(F_FILESYSTEM) - if (f_unlink(arg) != 0) - { - slen = sprintf(sendbuf, "550 Could not delete. \"%s\"\r\n", arg); - } - else - { - slen = sprintf(sendbuf, "250 Deleted. \"%s\"\r\n", arg); - } -#else - slen = sprintf(sendbuf, "550 Could not delete. Permission denied\r\n"); -#endif - send(sn, (uint8_t *)sendbuf, slen); - break; - - case XCWD_CMD: - case ACCT_CMD: - case XRMD_CMD: - case RMD_CMD: - case STRU_CMD: - case MODE_CMD: - case XMD5_CMD: - //fsprintf(CTRL_SOCK, unimp); - slen = sprintf(sendbuf, "502 Command does not implemented yet.\r\n"); - send(sn, (uint8_t *)sendbuf, slen); - break; - - default: /* Invalid */ - //fsprintf(CTRL_SOCK, badcmd, arg); - slen = sprintf(sendbuf, "500 Unknown command \'%s\'\r\n", arg); - send(sn, (uint8_t *)sendbuf, slen); - break; - } - - return 1; -} - - -char ftplogin(uint8_t sn, char * pass) -{ - char sendbuf[100]; - int slen = 0; - - //memset(sendbuf, 0, DATA_BUF_SIZE); - -#if defined(_FTP_DEBUG_) - printf("%s logged in\r\n", ftp.username); -#endif - //fsprintf(CTRL_SOCK, logged); - slen = sprintf(sendbuf, "230 Logged on\r\n"); - send(sn, (uint8_t *)sendbuf, slen); - ftp.state = FTPS_LOGIN; - - return 1; -} - -int pport(char * arg) -{ - int i; - char* tok=0; - - for (i = 0; i < 4; i++) - { - if(i==0) tok = strtok(arg,",\r\n"); - else tok = strtok(NULL,","); - remote_ip.cVal[i] = (uint8_t)atoi(tok); - if (!tok) - { -#if defined(_FTP_DEBUG_) - printf("bad pport : %s\r\n", arg); -#endif - return -1; - } - } - remote_port = 0; - for (i = 0; i < 2; i++) - { - tok = strtok(NULL,",\r\n"); - remote_port <<= 8; - remote_port += atoi(tok); - if (!tok) - { -#if defined(_FTP_DEBUG_) - printf("bad pport : %s\r\n", arg); -#endif - return -1; - } - } -#if defined(_FTP_DEBUG_) - printf("ip : %d.%d.%d.%d, port : %d\r\n", remote_ip.cVal[0], remote_ip.cVal[1], remote_ip.cVal[2], remote_ip.cVal[3], remote_port); -#endif - - return 0; -} - -#if defined(F_FILESYSTEM) -void print_filedsc(FIL *fil) -{ -#if defined(_FTP_DEBUG_) - printf("File System pointer : %08X\r\n", fil->fs); - printf("File System mount ID : %d\r\n", fil->id); - printf("File status flag : %08X\r\n", fil->flag); - printf("File System pads : %08X\r\n", fil->err); - printf("File read write pointer : %08X\r\n", fil->fptr); - printf("File size : %08X\r\n", fil->fsize); - printf("File start cluster : %08X\r\n", fil->sclust); - printf("current cluster : %08X\r\n", fil->clust); - printf("current data sector : %08X\r\n", fil->dsect); - printf("dir entry sector : %08X\r\n", fil->dir_sect); - printf("dir entry pointer : %08X\r\n", fil->dir_ptr); -#endif -} -#endif diff --git a/lib/ioLibrary_Driver/FTPServer/ftpd.h b/lib/ioLibrary_Driver/FTPServer/ftpd.h deleted file mode 100644 index 62324b5..0000000 --- a/lib/ioLibrary_Driver/FTPServer/ftpd.h +++ /dev/null @@ -1,167 +0,0 @@ -#ifndef _FTPD_H_ -#define _FTPD_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/* -* Wiznet. -* (c) Copyright 2002, Wiznet. -* -* Filename : ftpd.h -* Version : 1.0 -* Programmer(s) : -* Created : 2003/01/28 -* Description : Header file of FTP daemon. (AVR-GCC Compiler) -*/ - -#include - -//#define F_FILESYSTEM // If your target support a file system, you have to activate this feature and implement. - -#if defined(F_FILESYSTEM) -#include "ff.h" -#endif - -#define F_APP_FTP -#define _FTP_DEBUG_ - - -#define LINELEN 100 -//#define DATA_BUF_SIZE 100 -#if !defined(F_FILESYSTEM) -#define _MAX_SS 512 -#endif - -#define CTRL_SOCK 2 -#define DATA_SOCK 3 -#define CTRL_SOCK1 4 - - -#define IPPORT_FTPD 20 /* FTP Data port */ -#define IPPORT_FTP 21 /* FTP Control port */ - -#define HOSTNAME "iinChip" -#define VERSION "1.0" - -#define FILENAME "a.txt" - -/* FTP commands */ -enum ftp_cmd { - USER_CMD, - ACCT_CMD, - PASS_CMD, - TYPE_CMD, - LIST_CMD, - CWD_CMD, - DELE_CMD, - NAME_CMD, - QUIT_CMD, - RETR_CMD, - STOR_CMD, - PORT_CMD, - NLST_CMD, - PWD_CMD, - XPWD_CMD, - MKD_CMD, - XMKD_CMD, - XRMD_CMD, - RMD_CMD, - STRU_CMD, - MODE_CMD, - SYST_CMD, - XMD5_CMD, - XCWD_CMD, - FEAT_CMD, - PASV_CMD, - SIZE_CMD, - MLSD_CMD, - APPE_CMD, - NO_CMD, -}; - -enum ftp_type { - ASCII_TYPE, - IMAGE_TYPE, - LOGICAL_TYPE -}; - -enum ftp_state { - FTPS_NOT_LOGIN, - FTPS_LOGIN -}; - -enum datasock_state{ - DATASOCK_IDLE, - DATASOCK_READY, - DATASOCK_START -}; - -enum datasock_mode{ - PASSIVE_MODE, - ACTIVE_MODE -}; - -enum ftp_use_status{ - STATUS_USED, - STATUS_NOT_USED -}; - -struct ftpd { - uint8_t control; /* Control stream */ - uint8_t data; /* Data stream */ - - enum ftp_type type; /* Transfer type */ - enum ftp_state state; - - enum ftp_cmd current_cmd; - - enum datasock_state dsock_state; - enum datasock_mode dsock_mode; - - enum ftp_use_status ID_Enable; - enum ftp_use_status PW_Enable; - - char username[LINELEN]; /* Arg to USER command */ - char userpassword[LINELEN]; - char workingdir[LINELEN]; - char filename[LINELEN]; - -#if defined(F_FILESYSTEM) - FIL fil; // FatFs File objects - FRESULT fr; // FatFs function common result code -#endif - -}; - -#ifndef un_I2cval -typedef union _un_l2cval { - uint32_t lVal; - uint8_t cVal[4]; -}un_l2cval; -#endif - -void ftpd_init(uint8_t * src_ip); -uint8_t ftpd_run(uint8_t * dbuf); -char proc_ftpd(uint8_t sn, char * buf); - -char ftplogin(uint8_t sn,char * pass); - -int pport(char * arg); - -int sendit(char * command); -int recvit(char * command); - -long sendfile(uint8_t s, char * command); -long recvfile(uint8_t s); - -#if defined(F_FILESYSTEM) -void print_filedsc(FIL *fil); -#endif - -#ifdef __cplusplus -} -#endif - -#endif // _FTPD_H_ diff --git a/lib/ioLibrary_Driver/FTPServer/stdio_private.h b/lib/ioLibrary_Driver/FTPServer/stdio_private.h deleted file mode 100644 index f92a32f..0000000 --- a/lib/ioLibrary_Driver/FTPServer/stdio_private.h +++ /dev/null @@ -1,74 +0,0 @@ -/* Copyright (c) 2002, Joerg Wunsch - 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 copyright holders nor the names of - 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. -*/ - -/* $Id: stdio_private.h,v 1.6 2003/01/07 22:17:24 joerg_wunsch Exp $ */ -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -struct __file { - char *buf; /* buffer pointer */ - unsigned char unget; /* ungetc() buffer */ - uint8_t flags; /* flags, see below */ -#define __SRD 0x0001 /* OK to read */ -#define __SWR 0x0002 /* OK to write */ -#define __SSTR 0x0004 /* this is an sprintf/snprintf string */ -#define __SPGM 0x0008 /* fmt string is in progmem */ -#define __SERR 0x0010 /* found error */ -#define __SEOF 0x0020 /* found EOF */ -#define __SUNGET 0x040 /* ungetc() happened */ -#if 0 -/* possible future extensions, will require uint16_t flags */ -#define __SRW 0x0080 /* open for reading & writing */ -#define __SLBF 0x0100 /* line buffered */ -#define __SNBF 0x0200 /* unbuffered */ -#define __SMBF 0x0400 /* buf is from malloc */ -#endif - int size; /* size of buffer */ - int len; /* characters read or written so far */ - int (*put)(char); /* function to write one char to device */ - int (*get)(void); /* function to read one char from device */ -}; - -/* values for PRINTF_LEVEL */ -#define PRINTF_MIN 1 -#define PRINTF_STD 2 -#define PRINTF_FLT 3 - -/* values for SCANF_LEVEL */ -#define SCANF_MIN 1 -#define SCANF_STD 2 -#define SCANF_FLT 3 - -#ifdef __cplusplus -} -#endif diff --git a/lib/ioLibrary_Driver/SNMP/snmp.c b/lib/ioLibrary_Driver/SNMP/snmp.c deleted file mode 100644 index b705097..0000000 --- a/lib/ioLibrary_Driver/SNMP/snmp.c +++ /dev/null @@ -1,927 +0,0 @@ -#include -#include -#include -#include -#include - -#include "socket.h" -#include "snmp.h" -#include "snmp_custom.h" - -/********************************************************************************************/ -/* SNMP : Functions declaration */ -/********************************************************************************************/ -// SNMP Parsing functions -int32_t findEntry(uint8_t *oid, int32_t len); -int32_t getOID(int32_t id, uint8_t *oid, uint8_t *len); -int32_t getValue( uint8_t *vptr, int32_t vlen); -int32_t getEntry(int32_t id, uint8_t *dataType, void *ptr, int32_t *len); -int32_t setEntry(int32_t id, void *val, int32_t vlen, uint8_t dataType, int32_t index); -int32_t makeTrapVariableBindings(dataEntryType *oid_data, void *ptr, uint32_t *len); - -int32_t parseLength(const uint8_t *msg, int32_t *len); -int32_t parseTLV(const uint8_t *msg, int32_t index, tlvStructType *tlv); -void insertRespLen(int32_t reqStart, int32_t respStart, int32_t size); -int32_t parseVarBind(int32_t reqType, int32_t index); -int32_t parseSequence(int32_t reqType, int32_t index); -int32_t parseSequenceOf(int32_t reqType); -int32_t parseRequest(); -int32_t parseCommunity(); -int32_t parseVersion(); -int32_t parseSNMPMessage(); - -// Debugging function -#ifdef _SNMP_DEBUG_ -void dumpCode(uint8_t* header, uint8_t* tail, uint8_t *buff, int32_t len); -#endif - -// Utils -void ipToByteArray(int8_t *ip, uint8_t *pDes); - -/********************************************************************************************/ -/* SNMP : Variable declaration */ -/********************************************************************************************/ -// SNMP message structures -struct messageStruct request_msg; -struct messageStruct response_msg; - -// SNMP Time counter -static time_t startTime = 0; -volatile uint32_t snmp_tick_10ms = 0; //volatile uint32_t snmp_tick_1ms = 0; - -// SNMP Sockets -static uint8_t SOCK_SNMP_AGENT; -static uint8_t SOCK_SNMP_TRAP; - -uint8_t packet_trap[MAX_TRAPMSG_LEN] = {0,}; -uint8_t errorStatus, errorIndex; - - -/********************************************************************************************/ -/* SNMP : Time handler */ -/********************************************************************************************/ -void currentUptime(void *ptr, uint8_t *len) -{ - time_t curTime = getSNMPTimeTick(); - - //*(uint32_t *)ptr = (uint32_t)(curTime - startTime) / 10; // calculation for 1ms tick - *(uint32_t *)ptr = (uint32_t)(curTime - startTime); // calculation for 10ms tick - *len = 4; -} - -void SNMP_time_handler(void) -{ - //snmp_tick_1ms++; - snmp_tick_10ms++; -} - -uint32_t getSNMPTimeTick(void) -{ - //return snmp_tick_1ms; - return snmp_tick_10ms; -} - - -/********************************************************************************************/ -/* SNMP : Library Part */ -/********************************************************************************************/ -/** - * @addtogroup snmp_module - * @{ - */ - -/** - * Initialize SNMP Daemon. - * This should be called just one time at first time - * - * @param none - * @return none - */ -void snmpd_init(uint8_t * managerIP, uint8_t * agentIP, uint8_t sn_agent, uint8_t sn_trap) -{ -#ifdef _SNMP_DEBUG_ - printf("\r\n - SNMP : Start SNMP Agent Daemon\r\n"); -#endif - SOCK_SNMP_AGENT = sn_agent; - SOCK_SNMP_TRAP = sn_trap; - - if((SOCK_SNMP_AGENT > _WIZCHIP_SOCK_NUM_) || (SOCK_SNMP_TRAP > _WIZCHIP_SOCK_NUM_)) return; - - startTime = getSNMPTimeTick(); // Start time (unit: 10ms) - initTable(); // Settings for OID entry values - - initial_Trap(managerIP, agentIP); - -/* - // Example Codes for SNMP Trap - { - dataEntryType enterprise_oid = {0x0a, {0x2b, 0x06, 0x01, 0x04, 0x01, 0x81, 0x9b, 0x19, 0x01, 0x00}, - SNMPDTYPE_OBJ_ID, 0x0a, {"\x2b\x06\x01\x04\x01\x81\x9b\x19\x10\x00"}, NULL, NULL}; - - dataEntryType trap_oid1 = {8, {0x2b, 6, 1, 4, 1, 0, 11, 0}, SNMPDTYPE_OCTET_STRING, 30, {""}, NULL, NULL}; - dataEntryType trap_oid2 = {8, {0x2b, 6, 1, 4, 1, 0, 12, 0}, SNMPDTYPE_INTEGER, 4, {""}, NULL, NULL}; - - strcpy((char *)trap_oid1.u.octetstring, "Alert!!!"); // String added - trap_oid2.u.intval = 123456; // Integer value added - - // Generic Trap: warmStart - snmp_sendTrap((void *)"192.168.0.214", (void *)"192.168.0.112", (void *)"public", enterprise_oid, SNMPTRAP_WARMSTART, 0, 0); - - // Enterprise-Specific Trap - snmp_sendTrap((void *)"192.168.0.214", (void *)"192.168.0.112", (void *)"public", enterprise_oid, 6, 0, 2, &trap_oid1, &trap_oid2); - } -*/ -} - - -/** - * SNMP Process Handler. - * UDP Socket and SNMP Agent transaction handling. - * - * @param none - * @return none - */ - -int32_t snmpd_run(void) -{ - int32_t ret; - int32_t len = 0; - - uint8_t svr_addr[6]; - uint16_t svr_port; - - if(SOCK_SNMP_AGENT > _WIZCHIP_SOCK_NUM_) return -99; - - switch(getSn_SR(SOCK_SNMP_AGENT)) - { - case SOCK_UDP : - if ( (len = getSn_RX_RSR(SOCK_SNMP_AGENT)) > 0) - { - request_msg.len= recvfrom(SOCK_SNMP_AGENT, request_msg.buffer, len, svr_addr, &svr_port); - } - else - { - request_msg.len = 0; - } - - if (request_msg.len > 0) - { -#ifdef _SNMP_DEBUG_ - dumpCode((void *)"\r\n[Request]\r\n", (void *)"\r\n", request_msg.buffer, request_msg.len); -#endif - // Initialize - request_msg.index = 0; - response_msg.index = 0; - errorStatus = errorIndex = 0; - memset(response_msg.buffer, 0x00, MAX_SNMPMSG_LEN); - - // Received message parsing and send response process - if (parseSNMPMessage() != -1) - { - sendto(SOCK_SNMP_AGENT, response_msg.buffer, response_msg.index, svr_addr, svr_port); - } - -#ifdef _SNMP_DEBUG_ - dumpCode((void *)"\r\n[Response]\r\n", (void *)"\r\n", response_msg.buffer, response_msg.index); -#endif - } - break; - - case SOCK_CLOSED : - if((ret = socket(SOCK_SNMP_AGENT, Sn_MR_UDP, PORT_SNMP_AGENT, 0x00)) != SOCK_SNMP_AGENT) - return ret; -#ifdef _SNMP_DEBUG_ - printf(" - [%d] UDP Socket for SNMP Agent, port [%d]\r\n", SOCK_SNMP_AGENT, PORT_SNMP_AGENT); -#endif - break; - - default : - break; - } - - - return 1; -} - - -int32_t findEntry(uint8_t *oid, int32_t len) -{ - int32_t i; - - for (i = 0 ; i < maxData ; i++) - { - if (len == snmpData[i].oidlen) - { - if (!memcmp(snmpData[i].oid, oid, len)) return(i); - } - } - - return OID_NOT_FOUND; -} - - -int32_t getOID(int32_t id, uint8_t *oid, uint8_t *len) -{ - int32_t j; - - if (!((id >= 0) && (id < maxData))) return INVALID_ENTRY_ID; - - *len = snmpData[id].oidlen; - - for (j = 0 ; j < *len ; j++) - { - oid[j] = snmpData[id].oid[j]; - } - - return SNMP_SUCCESS; -} - - -int32_t getValue( uint8_t *vptr, int32_t vlen) -{ - int32_t index = 0; - int32_t value = 0; - - while (index < vlen) - { - if (index != 0) value <<= 8; - value |= vptr[index++]; - } - - return value; -} - - -int32_t getEntry(int32_t id, uint8_t *dataType, void *ptr, int32_t *len) -{ - uint8_t * ptr_8; - int32_t value; - - uint8_t * string; - int32_t j; - - if (!((id >= 0) && (id < maxData))) return INVALID_ENTRY_ID; - - *dataType = snmpData[id].dataType; - - switch(*dataType) - { - case SNMPDTYPE_OCTET_STRING : - case SNMPDTYPE_OBJ_ID : - { - string = ptr; - - if (snmpData[id].getfunction != NULL) - { - snmpData[id].getfunction( (void *)&snmpData[id].u.octetstring, &snmpData[id].dataLen ); - } - - if ( (*dataType)==SNMPDTYPE_OCTET_STRING ) - { - snmpData[id].dataLen = (uint8_t)strlen((char const*)&snmpData[id].u.octetstring); - } - - *len = snmpData[id].dataLen; - for (j = 0 ; j < *len ; j++) - { - string[j] = snmpData[id].u.octetstring[j]; - } - } - break; - - case SNMPDTYPE_INTEGER : - case SNMPDTYPE_TIME_TICKS : - case SNMPDTYPE_COUNTER : - case SNMPDTYPE_GAUGE : - { - if (snmpData[id].getfunction != NULL) - { - snmpData[id].getfunction( (void *)&snmpData[id].u.intval, &snmpData[id].dataLen ); - } - - if(snmpData[id].dataLen) *len = snmpData[id].dataLen; - else *len = sizeof(uint32_t); - - /* - // Original code (IAR, STM32) - // This code is not working in NXP+LPCXpresso (32-bit pointer operation error) - value = (int32_t *)ptr; - *value = HTONL(snmpData[id].u.intval); - */ - - ptr_8 = ptr; - //value = HTONL(snmpData[id].u.intval); // Endian convert when processing 32bit pointer operation - value = snmpData[id].u.intval; - - for (j = 0 ; j < *len ; j++) - { - ptr_8[j] = (uint8_t)((value >> ((*len-j-1)*8))); - } - } - break; - - default : - return INVALID_DATA_TYPE; - } - - return SNMP_SUCCESS; -} - - -int32_t setEntry(int32_t id, void *val, int32_t vlen, uint8_t dataType, int32_t index) -{ - - int32_t retStatus=OID_NOT_FOUND; - int32_t j; - - if (snmpData[id].dataType != dataType) - { - errorStatus = BAD_VALUE; - errorIndex = index; - return INVALID_DATA_TYPE; - } - - switch(snmpData[id].dataType) - { - case SNMPDTYPE_OCTET_STRING : - case SNMPDTYPE_OBJ_ID : - { - uint8_t *string = val; - for (j = 0 ; j < vlen ; j++) - { - snmpData[id].u.octetstring[j] = string[j]; - } - snmpData[id].dataLen = vlen; - } - retStatus = SNMP_SUCCESS; - break; - - case SNMPDTYPE_INTEGER : - case SNMPDTYPE_TIME_TICKS : - case SNMPDTYPE_COUNTER : - case SNMPDTYPE_GAUGE : - { - snmpData[id].u.intval = getValue( (uint8_t *)val, vlen); - snmpData[id].dataLen = vlen; - - if (snmpData[id].setfunction != NULL) - { - snmpData[id].setfunction(snmpData[id].u.intval); - } - - } - retStatus = SNMP_SUCCESS; - break; - - default : - retStatus = INVALID_DATA_TYPE; - break; - - } - - return retStatus; -} - - -int32_t parseLength(const uint8_t *msg, int32_t *len) -{ - int32_t i=1; - - if (msg[0] & 0x80) - { - int32_t tlen = (msg[0] & 0x7f) - 1; - *len = msg[i++]; - - while (tlen--) - { - *len <<= 8; - *len |= msg[i++]; - } - } - else - { - *len = msg[0]; - } - - return i; -} - - -int32_t parseTLV(const uint8_t *msg, int32_t index, tlvStructType *tlv) -{ - int32_t Llen = 0; - - tlv->start = index; - - Llen = parseLength((const uint8_t *)&msg[index+1], &tlv->len ); - - tlv->vstart = index + Llen + 1; - - switch (msg[index]) - { - case SNMPDTYPE_SEQUENCE: - case GET_REQUEST: - case GET_NEXT_REQUEST: - case SET_REQUEST: - tlv->nstart = tlv->vstart; - break; - default: - tlv->nstart = tlv->vstart + tlv->len; - break; - } - - return 0; -} - - -void insertRespLen(int32_t reqStart, int32_t respStart, int32_t size) -{ - int32_t indexStart, lenLength; - uint32_t mask = 0xff; - int32_t shift = 0; - - if (request_msg.buffer[reqStart+1] & 0x80) - { - lenLength = request_msg.buffer[reqStart+1] & 0x7f; - indexStart = respStart+2; - - while (lenLength--) - { - response_msg.buffer[indexStart+lenLength] = - (uint8_t)((size & mask) >> shift); - shift+=8; - mask <<= shift; - } - } - else - { - response_msg.buffer[respStart+1] = (uint8_t)(size & 0xff); - } -} - -int32_t parseVarBind(int32_t reqType, int32_t index) -{ - int32_t seglen = 0, id; - tlvStructType name, value; - int32_t size = 0; - - //extern const int32_t maxData; - - parseTLV(request_msg.buffer, request_msg.index, &name); - - if ( request_msg.buffer[name.start] != SNMPDTYPE_OBJ_ID ) return -1; - - id = findEntry(&request_msg.buffer[name.vstart], name.len); - - if ((reqType == GET_REQUEST) || (reqType == SET_REQUEST)) - { - seglen = name.nstart - name.start; - COPY_SEGMENT(name); - size = seglen; - } - else if (reqType == GET_NEXT_REQUEST) - { - response_msg.buffer[response_msg.index] = request_msg.buffer[name.start]; - - if (++id >= maxData) - { - id = OID_NOT_FOUND; - seglen = name.nstart - name.start; - COPY_SEGMENT(name); - size = seglen; - } - else - { - request_msg.index += name.nstart - name.start; - - getOID(id, &response_msg.buffer[response_msg.index+2], &response_msg.buffer[response_msg.index+1]); - - seglen = response_msg.buffer[response_msg.index+1]+2; - response_msg.index += seglen ; - size = seglen; - } - } - - parseTLV(request_msg.buffer, request_msg.index, &value); - - if (id != OID_NOT_FOUND) - { - uint8_t dataType; - int32_t len; - - if ((reqType == GET_REQUEST) || (reqType == GET_NEXT_REQUEST)) - { - getEntry(id, &dataType, &response_msg.buffer[response_msg.index+2], &len); - - response_msg.buffer[response_msg.index] = dataType; - response_msg.buffer[response_msg.index+1] = len; - seglen = (2 + len); - response_msg.index += seglen; - - request_msg.index += (value.nstart - value.start); - - } - else if (reqType == SET_REQUEST) - { - setEntry(id, &request_msg.buffer[value.vstart], value.len, request_msg.buffer[value.start], index); - seglen = value.nstart - value.start; - COPY_SEGMENT(value); - } - } - else - { - seglen = value.nstart - value.start; - COPY_SEGMENT(value); - - errorIndex = index; - errorStatus = NO_SUCH_NAME; - } - - size += seglen; - - return size; -} - - -int32_t parseSequence(int32_t reqType, int32_t index) -{ - int32_t seglen; - tlvStructType seq; - int32_t size = 0, respLoc; - - parseTLV(request_msg.buffer, request_msg.index, &seq); - - if ( request_msg.buffer[seq.start] != SNMPDTYPE_SEQUENCE ) return -1; - - seglen = seq.vstart - seq.start; - respLoc = response_msg.index; - COPY_SEGMENT(seq); - - size = parseVarBind( reqType, index ); - insertRespLen(seq.start, respLoc, size); - size += seglen; - - return size; -} - - -int32_t parseSequenceOf(int32_t reqType) -{ - int32_t seglen; - tlvStructType seqof; - int32_t size = 0, respLoc; - int32_t index = 0; - - parseTLV(request_msg.buffer, request_msg.index, &seqof); - - if ( request_msg.buffer[seqof.start] != SNMPDTYPE_SEQUENCE_OF ) return -1; - - seglen = seqof.vstart - seqof.start; - respLoc = response_msg.index; - COPY_SEGMENT(seqof); - - while (request_msg.index < request_msg.len) - { - size += parseSequence( reqType, index++ ); - } - - insertRespLen(seqof.start, respLoc, size); - - return size; -} - - -int32_t parseRequest() -{ - int32_t ret, seglen; - tlvStructType snmpreq, requestid, errStatus, errIndex; - int32_t size = 0, respLoc, reqType; - - parseTLV(request_msg.buffer, request_msg.index, &snmpreq); - - reqType = request_msg.buffer[snmpreq.start]; - - if ( !VALID_REQUEST(reqType) ) return -1; - - seglen = snmpreq.vstart - snmpreq.start; - respLoc = snmpreq.start; - size += seglen; - COPY_SEGMENT(snmpreq); - - response_msg.buffer[snmpreq.start] = GET_RESPONSE; - - parseTLV(request_msg.buffer, request_msg.index, &requestid); - seglen = requestid.nstart - requestid.start; - size += seglen; - COPY_SEGMENT(requestid); - - parseTLV(request_msg.buffer, request_msg.index, &errStatus); - seglen = errStatus.nstart - errStatus.start; - size += seglen; - COPY_SEGMENT(errStatus); - - parseTLV(request_msg.buffer, request_msg.index, &errIndex); - seglen = errIndex.nstart - errIndex.start; - size += seglen; - COPY_SEGMENT(errIndex); - - ret = parseSequenceOf(reqType); - if (ret == -1) return -1; - else size += ret; - - insertRespLen(snmpreq.start, respLoc, size); - - if (errorStatus) - { - response_msg.buffer[errStatus.vstart] = errorStatus; - response_msg.buffer[errIndex.vstart] = errorIndex + 1; - } - - return size; -} - - -int32_t parseCommunity() -{ - int32_t seglen; - tlvStructType community; - int32_t size=0; - - parseTLV(request_msg.buffer, request_msg.index, &community); - - if (!((request_msg.buffer[community.start] == SNMPDTYPE_OCTET_STRING) && (community.len == COMMUNITY_SIZE))) - { - return -1; - } - - if (!memcmp(&request_msg.buffer[community.vstart], (int8_t *)COMMUNITY, COMMUNITY_SIZE)) - { - seglen = community.nstart - community.start; - size += seglen; - COPY_SEGMENT(community); - - size += parseRequest(); - } - else - { - return -1; - } - - return size; -} - - -int32_t parseVersion() -{ - int32_t size = 0, seglen; - tlvStructType tlv; - - size = parseTLV(request_msg.buffer, request_msg.index, &tlv); - - if (!((request_msg.buffer[tlv.start] == SNMPDTYPE_INTEGER) && (request_msg.buffer[tlv.vstart] == SNMP_V1))) - return -1; - - seglen = tlv.nstart - tlv.start; - size += seglen; - COPY_SEGMENT(tlv); - size = parseCommunity(); - - if (size == -1) return size; - else return (size + seglen); -} - - -int32_t parseSNMPMessage() -{ - int32_t size = 0, seglen, respLoc; - tlvStructType tlv; - - parseTLV(request_msg.buffer, request_msg.index, &tlv); - - if (request_msg.buffer[tlv.start] != SNMPDTYPE_SEQUENCE_OF) return -1; - - seglen = tlv.vstart - tlv.start; - respLoc = tlv.start; - COPY_SEGMENT(tlv); - - size = parseVersion(); - - if (size == -1) return -1; - else size += seglen; - - insertRespLen(tlv.start, respLoc, size); - - return 0; -} - -void ipToByteArray(int8_t *ip, uint8_t *pDes) -{ - uint32_t i, ip1=0, ip2=0, ip3=0, ip4=0; - int8_t buff[32]; - uint32_t len = (uint32_t)strlen((char const*)ip); - strcpy((char *)buff, (char const*)ip); - - for (i=0; ioidlen; - - for (j = 0 ; j < oid_data->oidlen ; j++) - { - ((uint8_t*)ptr)[j+4] = oid_data->oid[j]; - } - - switch(oid_data->dataType) - { - case SNMPDTYPE_OCTET_STRING : - case SNMPDTYPE_OBJ_ID : - { - uint8_t *string = &((uint8_t*)ptr)[4+oid_data->oidlen+2]; - - if ( oid_data->dataType==SNMPDTYPE_OCTET_STRING ) - { - oid_data->dataLen = (uint8_t)strlen((char const*)&oid_data->u.octetstring); - } - for (j = 0 ; j < oid_data->dataLen ; j++) - { - string[j] = oid_data->u.octetstring[j]; - } - - ((uint8_t*)ptr)[4+oid_data->oidlen] = oid_data->dataType; - ((uint8_t*)ptr)[4+oid_data->oidlen+1] = oid_data->dataLen; - ((uint8_t*)ptr)[1] = 2 + oid_data->oidlen + 2 + oid_data->dataLen; - *len = 4 + oid_data->oidlen + 2 + oid_data->dataLen; - } - break; - - case SNMPDTYPE_INTEGER : - case SNMPDTYPE_TIME_TICKS : - case SNMPDTYPE_COUNTER : - case SNMPDTYPE_GAUGE : - { - oid_data->dataLen = 4; - - *(int32_t*)(&((uint8_t*)ptr)[4+oid_data->oidlen+2]) = HTONL(oid_data->u.intval); - - ((uint8_t*)ptr)[4+oid_data->oidlen] = oid_data->dataType; - ((uint8_t*)ptr)[4+oid_data->oidlen+1] = oid_data->dataLen; - ((uint8_t*)ptr)[1] = 2 + oid_data->oidlen + 2 + oid_data->dataLen; - *len = 4 + oid_data->oidlen + 2 + oid_data->dataLen; - } - break; - - default : - return INVALID_DATA_TYPE; - } - - return SNMP_SUCCESS; -} - - -int32_t snmp_sendTrap(uint8_t * managerIP, uint8_t * agentIP, int8_t* community, dataEntryType enterprise_oid, uint32_t genericTrap, uint32_t specificTrap, uint32_t va_count, ...) -{ - uint32_t i; - int32_t packet_index = 0; - int32_t packet_buff1 = 0; - int32_t packet_buff2 = 0; - int32_t packet_buff3 = 0; - - va_list ap; - uint32_t length_var_bindings = 0; - uint32_t length_buff = 0; - - //SNMP Trap packet generation - packet_trap[packet_index++] = 0x30; // ASN.1 Header - - packet_trap[packet_index] = 0xff; // pdu_length, temp - packet_buff1 = packet_index++; - - packet_trap[packet_index++] = 0x02; // Version - packet_trap[packet_index++] = 0x01; - packet_trap[packet_index++] = 0x00; - - packet_trap[packet_index++] = 0x04; // Community - packet_trap[packet_index++] = (uint8_t)strlen((char const*)community); - memcpy(&(packet_trap[packet_index]), community, strlen((char const*)community)); - - packet_index = packet_index + (uint8_t)strlen((char const*)community); - - packet_trap[packet_index++] = 0xa4; // trap - packet_trap[packet_index] = 0xff; // length, temp - packet_buff2 = packet_index++; - - packet_trap[packet_index++] = 0x06; // enterprise_oid - packet_trap[packet_index++] = enterprise_oid.oidlen; - for (i=0; i> 24) & 0x000000ff) | \ - (((x) >> 8) & 0x0000ff00) | \ - (((x) << 8) & 0x00ff0000) | \ - (((x) << 24) & 0xff000000)) -#endif - -typedef struct { - uint8_t oidlen; - uint8_t oid[MAX_OID]; - uint8_t dataType; - uint8_t dataLen; - union { - uint8_t octetstring[MAX_STRING]; - uint32_t intval; - } u; - void (*getfunction)(void *, uint8_t *); - void (*setfunction)(int32_t); -} dataEntryType; - -struct messageStruct { - uint8_t buffer[MAX_SNMPMSG_LEN]; - int32_t len; - int32_t index; -}; - -typedef struct { - int32_t start; /* Absolute Index of the TLV */ - int32_t len; /* The L value of the TLV */ - int32_t vstart; /* Absolute Index of this TLV's Value */ - int32_t nstart; /* Absolute Index of the next TLV */ -} tlvStructType; - - -/********************************************************************************************/ -/* SNMP : Functions */ -/********************************************************************************************/ -// SNMP Main functions -void snmpd_init(uint8_t * managerIP, uint8_t * agentIP, uint8_t sn_agent, uint8_t sn_trap); -int32_t snmpd_run(void); -int32_t snmp_sendTrap(uint8_t * managerIP, uint8_t * agentIP, int8_t* community, dataEntryType enterprise_oid, uint32_t genericTrap, uint32_t specificTrap, uint32_t va_count, ...); - -// SNMP Time handler functions -void SNMP_time_handler(void); -uint32_t getSNMPTimeTick(void); -void currentUptime(void *ptr, uint8_t *len); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/ioLibrary_Driver/SNMP/snmp_custom.c b/lib/ioLibrary_Driver/SNMP/snmp_custom.c deleted file mode 100644 index 68590c7..0000000 --- a/lib/ioLibrary_Driver/SNMP/snmp_custom.c +++ /dev/null @@ -1,147 +0,0 @@ - -/******************************************************************************************** - * SNMP : User Customization Part - * - OID Registration - * - User defined functions for OID related - * + Integer value, String - * + I/O control / Chip registers - * + Network Informations - * + Etc. - * - *********************************************************************************************/ -#include "snmp_custom.h" - -#ifdef _USE_WIZNET_W5500_EVB_ - #include "board.h" -#endif - -dataEntryType snmpData[] = -{ - // System MIB - // SysDescr Entry - {8, {0x2b, 6, 1, 2, 1, 1, 1, 0}, - SNMPDTYPE_OCTET_STRING, 30, {"WIZnet Embedded SNMP Agent"}, - NULL, NULL}, - - // SysObjectID Entry - {8, {0x2b, 6, 1, 2, 1, 1, 2, 0}, - SNMPDTYPE_OBJ_ID, 8, {"\x2b\x06\x01\x02\x01\x01\x02\x00"}, - NULL, NULL}, - - // SysUptime Entry - {8, {0x2b, 6, 1, 2, 1, 1, 3, 0}, - SNMPDTYPE_TIME_TICKS, 0, {""}, - currentUptime, NULL}, - - // sysContact Entry - {8, {0x2b, 6, 1, 2, 1, 1, 4, 0}, - SNMPDTYPE_OCTET_STRING, 30, {"http://www.wizwiki.net/forum"}, - NULL, NULL}, - - // sysName Entry - {8, {0x2b, 6, 1, 2, 1, 1, 5, 0}, - SNMPDTYPE_OCTET_STRING, 30, {"http://www.wiznet.co.kr"}, - NULL, NULL}, - - // Location Entry - {8, {0x2b, 6, 1, 2, 1, 1, 6, 0}, - SNMPDTYPE_OCTET_STRING, 30, {"4F Humax Village"}, - NULL, NULL}, - - // SysServices - {8, {0x2b, 6, 1, 2, 1, 1, 7, 0}, - SNMPDTYPE_INTEGER, 4, {""}, - NULL, NULL}, - -#ifdef _USE_WIZNET_W5500_EVB_ - // Get the WIZnet W5500-EVB LED Status - {8, {0x2b, 6, 1, 4, 1, 6, 1, 0}, - SNMPDTYPE_OCTET_STRING, 40, {""}, - get_LEDStatus_all, NULL}, - - // Set the LED_R (RGB LED) - {8, {0x2b, 6, 1, 4, 1, 6, 1, 1}, - SNMPDTYPE_INTEGER, 4, {""}, - NULL, set_LEDStatus_R}, - - // Set the LED_G (RGB LED) - {8, {0x2b, 6, 1, 4, 1, 6, 1, 2}, - SNMPDTYPE_INTEGER, 4, {""}, - NULL, set_LEDStatus_G}, - - // Set the LED_B (RGB LED) - {8, {0x2b, 6, 1, 4, 1, 6, 1, 3}, - SNMPDTYPE_INTEGER, 4, {""}, - NULL, set_LEDStatus_B}, -#endif - - // OID Test #1 (long-length OID example, 19865) - {0x0a, {0x2b, 0x06, 0x01, 0x04, 0x01, 0x81, 0x9b, 0x19, 0x01, 0x00}, - SNMPDTYPE_OCTET_STRING, 30, {"long-length OID Test #1"}, - NULL, NULL}, - - // OID Test #2 (long-length OID example, 22210) - {0x0a, {0x2b, 0x06, 0x01, 0x04, 0x01, 0x81, 0xad, 0x42, 0x01, 0x00}, - SNMPDTYPE_OCTET_STRING, 35, {"long-length OID Test #2"}, - NULL, NULL}, - - // OID Test #2: SysObjectID Entry - {0x0a, {0x2b, 0x06, 0x01, 0x04, 0x01, 0x81, 0xad, 0x42, 0x02, 0x00}, - SNMPDTYPE_OBJ_ID, 0x0a, {"\x2b\x06\x01\x04\x01\x81\xad\x42\x02\x00"}, - NULL, NULL}, -}; - -const int32_t maxData = (sizeof(snmpData) / sizeof(dataEntryType)); - -void initTable() -{ - // Example integer value for [OID 1.3.6.1.2.1.1.7.0] - snmpData[6].u.intval = -5; - -} - - -// W5500-EVB: LED Control /////////////////////////////////////////////////////////////////////////// -#ifdef _USE_WIZNET_W5500_EVB_ -void get_LEDStatus_all(void *ptr, uint8_t *len) -{ - uint8_t led_status[3] = {0, }; - - led_status[LED_R] = (uint8_t)Board_LED_Test(LED_R); - led_status[LED_G] = (uint8_t)Board_LED_Test(LED_G); - led_status[LED_B] = (uint8_t)Board_LED_Test(LED_B); - - *len = sprintf((char *)ptr, "LED R [%s] / G [%s] / B [%s]", led_status[LED_R]?"On":"Off", led_status[LED_G]?"On":"Off", led_status[LED_B]?"On":"Off"); -} - -void set_LEDStatus_R(int32_t val) -{ - if(val == 0) Board_LED_Set(LED_R, false); - else Board_LED_Set(LED_R, true); -} - -void set_LEDStatus_G(int32_t val) -{ - if(val == 0) Board_LED_Set(LED_G, false); - else Board_LED_Set(LED_G, true); -} - -void set_LEDStatus_B(int32_t val) -{ - if(val == 0) Board_LED_Set(LED_B, false); - else Board_LED_Set(LED_B, true); -} -#endif -///////////////////////////////////////////////////////////////////////////////////////////////////// - -void initial_Trap(uint8_t * managerIP, uint8_t * agentIP) -{ - // SNMP Trap: WarmStart(1) Trap - { - dataEntryType enterprise_oid = {0x0a, {0x2b, 0x06, 0x01, 0x04, 0x01, 0x81, 0x9b, 0x19, 0x01, 0x00}, - SNMPDTYPE_OBJ_ID, 0x0a, {"\x2b\x06\x01\x04\x01\x81\x9b\x19\x10\x00"}, NULL, NULL}; - // Generic Trap: warmStart COMMUNITY - snmp_sendTrap(managerIP, agentIP, (void *)COMMUNITY, enterprise_oid, SNMPTRAP_WARMSTART, 0, 0); - } - -} diff --git a/lib/ioLibrary_Driver/SNMP/snmp_custom.h b/lib/ioLibrary_Driver/SNMP/snmp_custom.h deleted file mode 100644 index c4afa30..0000000 --- a/lib/ioLibrary_Driver/SNMP/snmp_custom.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef _SNMP_CUSTOM_H_ -#define _SNMP_CUSTOM_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include -#include - -#include "snmp.h" - -extern dataEntryType snmpData[]; -extern const int32_t maxData; - -// Define for using W5500-EVB: H/W Dependency (e.g., LEDs...) -//#define _USE_WIZNET_W5500_EVB_ - -#define COMMUNITY "public\0" -#define COMMUNITY_SIZE (strlen(COMMUNITY)) - -/* Predefined function: Response value control */ -void initTable(); - -/* User defined functions: LED control examples */ -#ifdef _USE_WIZNET_W5500_EVB_ - void get_LEDStatus_all(void *ptr, uint8_t *len); - void set_LEDStatus_R(int32_t val); - void set_LEDStatus_G(int32_t val); - void set_LEDStatus_B(int32_t val); -#endif -/* SNMP Trap: warmStart(1) */ -void initial_Trap(uint8_t * managerIP, uint8_t * agentIP); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/ioLibrary_Driver/SNMP/tools/OID_Converter/Readme.txt b/lib/ioLibrary_Driver/SNMP/tools/OID_Converter/Readme.txt deleted file mode 100644 index 4476586..0000000 --- a/lib/ioLibrary_Driver/SNMP/tools/OID_Converter/Readme.txt +++ /dev/null @@ -1,45 +0,0 @@ -============================================================ - -============================================================ - -+ Example OID for convert - 1.3.6.1.4.1.19865.1.0 - -(1) Convert Usage - CMD>>oid 1.3.6.1.4.1.19865.1.0 - => 06 0A 2B 06 01 04 01 81 9B 19 01 00 - - >> TLV(tag-length-value) Example OID - (06) Tag - (0A) Length - [2B] 1(iso).3(identified-organization) (in ASN.1 BER encoding, i.e. 1*40+3 = 0x2b) - [06] 6(dod) - [01] 1(internet) - [04] 4(private) - [01] 1(enterprise) - [81 9B 19] 19865(Vendor-Specific) - ... - -(2) Add the entry to OID table in source code (DataEntryType, put the converted value to array) - {0x0a, {0x2b, 0x06, 0x01, 0x04, 0x01, 0x81, 0x9b, 0x19, 0x01, 0x00}, - SNMPDTYPE_OCTET_STRING, 30, {"long-length OID Test"}, - NULL, NULL}, - -============================================================ -OID Converter: OID encoder/decoder -v1.3 - Matthias Gaertner 1999/2001 - Freeware -============================================================ - -The OID converter is a handy little tool to convert ASN.1 OIDs from readable dotted decimal notation to binary hexadecimal Distinguished Encoding Rules (DER) representation and vice versa. -If you're into x.509 certificates, this may be useful to you, too. - -Usage: - OID [-c|-C] [-o] {-i|1.2.3.4} - converts dotted form to ASCII HEX DER output. - OID -x [-o] {-i|hex-digits} - decodes ASCII HEX DER and gives dotted form. - -If you need more information, please refer to Matthias Gaertner's page, -http://www.rtner.de/software/oid.html - -=============================================================================================== \ No newline at end of file diff --git a/lib/ioLibrary_Driver/SNMP/tools/net-snmp-5.7(win32-bin)/snmptrapd.conf b/lib/ioLibrary_Driver/SNMP/tools/net-snmp-5.7(win32-bin)/snmptrapd.conf deleted file mode 100644 index 494e4ec..0000000 --- a/lib/ioLibrary_Driver/SNMP/tools/net-snmp-5.7(win32-bin)/snmptrapd.conf +++ /dev/null @@ -1,33 +0,0 @@ -# -# net-snmp (or ucd-snmp) persistent data file. -# -############################################################################ -# STOP STOP STOP STOP STOP STOP STOP STOP STOP -# -# **** DO NOT EDIT THIS FILE **** -# -# STOP STOP STOP STOP STOP STOP STOP STOP STOP -############################################################################ -# -# DO NOT STORE CONFIGURATION ENTRIES HERE. -# Please save normal configuration tokens for snmptrapd in SNMPCONFPATH/snmptrapd.conf. -# Only "createUser" tokens should be placed here by snmptrapd administrators. -# (Did I mention: do not edit this file?) -# - - -authCommunity log,execute,net public - - - - - - - - - - - - -engineBoots 1 -oldEngineID 0x80001f88803d6f00001ba7934e00000000 diff --git a/lib/ioLibrary_Driver/SNTP/sntp.c b/lib/ioLibrary_Driver/SNTP/sntp.c deleted file mode 100644 index 5b9c463..0000000 --- a/lib/ioLibrary_Driver/SNTP/sntp.c +++ /dev/null @@ -1,450 +0,0 @@ -/* - * sntp.c - * - * Created on: 2014. 12. 15. - * Author: Administrator - */ - - -#include - -#include "sntp.h" -#include "socket.h" - -ntpformat NTPformat; -datetime Nowdatetime; -uint8_t ntpmessage[48]; -uint8_t *data_buf; -uint8_t NTP_SOCKET; -uint8_t time_zone; -uint16_t ntp_retry_cnt=0; //counting the ntp retry number - -/* -00)UTC-12:00 Baker Island, Howland Island (both uninhabited) -01) UTC-11:00 American Samoa, Samoa -02) UTC-10:00 (Summer)French Polynesia (most), United States (Aleutian Islands, Hawaii) -03) UTC-09:30 Marquesas Islands -04) UTC-09:00 Gambier Islands;(Summer)United States (most of Alaska) -05) UTC-08:00 (Summer)Canada (most of British Columbia), Mexico (Baja California) -06) UTC-08:00 United States (California, most of Nevada, most of Oregon, Washington (state)) -07) UTC-07:00 Mexico (Sonora), United States (Arizona); (Summer)Canada (Alberta) -08) UTC-07:00 Mexico (Chihuahua), United States (Colorado) -09) UTC-06:00 Costa Rica, El Salvador, Ecuador (Galapagos Islands), Guatemala, Honduras -10) UTC-06:00 Mexico (most), Nicaragua;(Summer)Canada (Manitoba, Saskatchewan), United States (Illinois, most of Texas) -11) UTC-05:00 Colombia, Cuba, Ecuador (continental), Haiti, Jamaica, Panama, Peru -12) UTC-05:00 (Summer)Canada (most of Ontario, most of Quebec) -13) UTC-05:00 United States (most of Florida, Georgia, Massachusetts, most of Michigan, New York, North Carolina, Ohio, Washington D.C.) -14) UTC-04:30 Venezuela -15) UTC-04:00 Bolivia, Brazil (Amazonas), Chile (continental), Dominican Republic, Canada (Nova Scotia), Paraguay, -16) UTC-04:00 Puerto Rico, Trinidad and Tobago -17) UTC-03:30 Canada (Newfoundland) -18) UTC-03:00 Argentina; (Summer) Brazil (Brasilia, Rio de Janeiro, Sao Paulo), most of Greenland, Uruguay -19) UTC-02:00 Brazil (Fernando de Noronha), South Georgia and the South Sandwich Islands -20) UTC-01:00 Portugal (Azores), Cape Verde -21) UTC±00:00 Cote d'Ivoire, Faroe Islands, Ghana, Iceland, Senegal; (Summer) Ireland, Portugal (continental and Madeira) -22) UTC±00:00 Spain (Canary Islands), Morocco, United Kingdom -23) UTC+01:00 Angola, Cameroon, Nigeria, Tunisia; (Summer)Albania, Algeria, Austria, Belgium, Bosnia and Herzegovina, -24) UTC+01:00 Spain (continental), Croatia, Czech Republic, Denmark, Germany, Hungary, Italy, Kinshasa, Kosovo, -25) UTC+01:00 Macedonia, France (metropolitan), the Netherlands, Norway, Poland, Serbia, Slovakia, Slovenia, Sweden, Switzerland -26) UTC+02:00 Libya, Egypt, Malawi, Mozambique, South Africa, Zambia, Zimbabwe, (Summer)Bulgaria, Cyprus, Estonia, -27) UTC+02:00 Finland, Greece, Israel, Jordan, Latvia, Lebanon, Lithuania, Moldova, Palestine, Romania, Syria, Turkey, Ukraine -28) UTC+03:00 Belarus, Djibouti, Eritrea, Ethiopia, Iraq, Kenya, Madagascar, Russia (Kaliningrad Oblast), Saudi Arabia, -29) UTC+03:00 South Sudan, Sudan, Somalia, South Sudan, Tanzania, Uganda, Yemen -30) UTC+03:30 (Summer)Iran -31) UTC+04:00 Armenia, Azerbaijan, Georgia, Mauritius, Oman, Russia (European), Seychelles, United Arab Emirates -32) UTC+04:30 Afghanistan -33) UTC+05:00 Kazakhstan (West), Maldives, Pakistan, Uzbekistan -34) UTC+05:30 India, Sri Lanka -35) UTC+05:45 Nepal -36) UTC+06:00 Kazakhstan (most), Bangladesh, Russia (Ural: Sverdlovsk Oblast, Chelyabinsk Oblast) -37) UTC+06:30 Cocos Islands, Myanmar -38) UTC+07:00 Jakarta, Russia (Novosibirsk Oblast), Thailand, Vietnam -39) UTC+08:00 China, Hong Kong, Russia (Krasnoyarsk Krai), Malaysia, Philippines, Singapore, Taiwan, most of Mongolia, Western Australia -40) UTC+09:00 Korea, East Timor, Russia (Irkutsk Oblast), Japan -41) UTC+09:30 Australia (Northern Territory);(Summer)Australia (South Australia)) -42) UTC+10:00 Russia (Zabaykalsky Krai); (Summer)Australia (New South Wales, Queensland, Tasmania, Victoria) -43) UTC+10:30 Lord Howe Island -44) UTC+11:00 New Caledonia, Russia (Primorsky Krai), Solomon Islands -45) UTC+11:30 Norfolk Island -46) UTC+12:00 Fiji, Russia (Kamchatka Krai);(Summer)New Zealand -47) UTC+12:45 (Summer)New Zealand -48) UTC+13:00 Tonga -49) UTC+14:00 Kiribati (Line Islands) -*/ -void get_seconds_from_ntp_server(uint8_t *buf, uint16_t idx) -{ - tstamp seconds = 0; - uint8_t i=0; - for (i = 0; i < 4; i++) - { - seconds = (seconds << 8) | buf[idx + i]; - } - switch (time_zone) - { - case 0: - seconds -= 12*3600; - break; - case 1: - seconds -= 11*3600; - break; - case 2: - seconds -= 10*3600; - break; - case 3: - seconds -= (9*3600+30*60); - break; - case 4: - seconds -= 9*3600; - break; - case 5: - case 6: - seconds -= 8*3600; - break; - case 7: - case 8: - seconds -= 7*3600; - break; - case 9: - case 10: - seconds -= 6*3600; - break; - case 11: - case 12: - case 13: - seconds -= 5*3600; - break; - case 14: - seconds -= (4*3600+30*60); - break; - case 15: - case 16: - seconds -= 4*3600; - break; - case 17: - seconds -= (3*3600+30*60); - break; - case 18: - seconds -= 3*3600; - break; - case 19: - seconds -= 2*3600; - break; - case 20: - seconds -= 1*3600; - break; - case 21: //? - case 22: - break; - case 23: - case 24: - case 25: - seconds += 1*3600; - break; - case 26: - case 27: - seconds += 2*3600; - break; - case 28: - case 29: - seconds += 3*3600; - break; - case 30: - seconds += (3*3600+30*60); - break; - case 31: - seconds += 4*3600; - break; - case 32: - seconds += (4*3600+30*60); - break; - case 33: - seconds += 5*3600; - break; - case 34: - seconds += (5*3600+30*60); - break; - case 35: - seconds += (5*3600+45*60); - break; - case 36: - seconds += 6*3600; - break; - case 37: - seconds += (6*3600+30*60); - break; - case 38: - seconds += 7*3600; - break; - case 39: - seconds += 8*3600; - break; - case 40: - seconds += 9*3600; - break; - case 41: - seconds += (9*3600+30*60); - break; - case 42: - seconds += 10*3600; - break; - case 43: - seconds += (10*3600+30*60); - break; - case 44: - seconds += 11*3600; - break; - case 45: - seconds += (11*3600+30*60); - break; - case 46: - seconds += 12*3600; - break; - case 47: - seconds += (12*3600+45*60); - break; - case 48: - seconds += 13*3600; - break; - case 49: - seconds += 14*3600; - break; - - } - - //calculation for date - calcdatetime(seconds); -} - -void SNTP_init(uint8_t s, uint8_t *ntp_server, uint8_t tz, uint8_t *buf) -{ - NTP_SOCKET = s; - - NTPformat.dstaddr[0] = ntp_server[0]; - NTPformat.dstaddr[1] = ntp_server[1]; - NTPformat.dstaddr[2] = ntp_server[2]; - NTPformat.dstaddr[3] = ntp_server[3]; - - time_zone = tz; - - data_buf = buf; - - uint8_t Flag; - NTPformat.leap = 0; /* leap indicator */ - NTPformat.version = 4; /* version number */ - NTPformat.mode = 3; /* mode */ - NTPformat.stratum = 0; /* stratum */ - NTPformat.poll = 0; /* poll interval */ - NTPformat.precision = 0; /* precision */ - NTPformat.rootdelay = 0; /* root delay */ - NTPformat.rootdisp = 0; /* root dispersion */ - NTPformat.refid = 0; /* reference ID */ - NTPformat.reftime = 0; /* reference time */ - NTPformat.org = 0; /* origin timestamp */ - NTPformat.rec = 0; /* receive timestamp */ - NTPformat.xmt = 1; /* transmit timestamp */ - - Flag = (NTPformat.leap<<6)+(NTPformat.version<<3)+NTPformat.mode; //one byte Flag - memcpy(ntpmessage,(void const*)(&Flag),1); -} - -int8_t SNTP_run(datetime *time) -{ - uint16_t RSR_len; - uint32_t destip = 0; - uint16_t destport; - uint16_t startindex = 40; //last 8-byte of data_buf[size is 48 byte] is xmt, so the startindex should be 40 - - switch(getSn_SR(NTP_SOCKET)) - { - case SOCK_UDP: - if ((RSR_len = getSn_RX_RSR(NTP_SOCKET)) > 0) - { - 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); - - get_seconds_from_ntp_server(data_buf,startindex); - time->yy = Nowdatetime.yy; - time->mo = Nowdatetime.mo; - time->dd = Nowdatetime.dd; - time->hh = Nowdatetime.hh; - time->mm = Nowdatetime.mm; - time->ss = Nowdatetime.ss; - - ntp_retry_cnt=0; - close(NTP_SOCKET); - - return 1; - } - - if(ntp_retry_cnt<0xFFFF) - { - if(ntp_retry_cnt==0)//first send request, no need to wait - { - sendto(NTP_SOCKET,ntpmessage,sizeof(ntpmessage),NTPformat.dstaddr,ntp_port); - ntp_retry_cnt++; - } - else // send request again? it should wait for a while - { - if((ntp_retry_cnt % 0xFFF) == 0) //wait time - { - sendto(NTP_SOCKET,ntpmessage,sizeof(ntpmessage),NTPformat.dstaddr,ntp_port); -#ifdef _SNTP_DEBUG_ - printf("ntp retry: %d\r\n", ntp_retry_cnt); -#endif - ntp_retry_cnt++; - } - } - } - else //ntp retry fail - { - ntp_retry_cnt=0; -#ifdef _SNTP_DEBUG_ - printf("ntp retry failed!\r\n"); -#endif - close(NTP_SOCKET); - } - break; - case SOCK_CLOSED: - socket(NTP_SOCKET,Sn_MR_UDP,ntp_port,0); - break; - } - // Return value - // 0 - failed / 1 - success - return 0; -} - -void calcdatetime(tstamp seconds) -{ - uint8_t yf=0; - tstamp n=0,d=0,total_d=0,rz=0; - uint16_t y=0,r=0,yr=0; - signed long long yd=0; - - n = seconds; - total_d = seconds/(SECS_PERDAY); - d=0; - uint32_t p_year_total_sec=SECS_PERDAY*365; - uint32_t r_year_total_sec=SECS_PERDAY*366; - while(n>=p_year_total_sec) - { - if((EPOCH+r)%400==0 || ((EPOCH+r)%100!=0 && (EPOCH+r)%4==0)) - { - n = n -(r_year_total_sec); - d = d + 366; - } - else - { - n = n - (p_year_total_sec); - d = d + 365; - } - r+=1; - y+=1; - - } - - y += EPOCH; - - Nowdatetime.yy = y; - - yd=0; - yd = total_d - d; - - yf=1; - while(yd>=28) - { - - if(yf==1 || yf==3 || yf==5 || yf==7 || yf==8 || yf==10 || yf==12) - { - yd -= 31; - if(yd<0)break; - rz += 31; - } - - if (yf==2) - { - if (y%400==0 || (y%100!=0 && y%4==0)) - { - yd -= 29; - if(yd<0)break; - rz += 29; - } - else - { - yd -= 28; - if(yd<0)break; - rz += 28; - } - } - if(yf==4 || yf==6 || yf==9 || yf==11 ) - { - yd -= 30; - if(yd<0)break; - rz += 30; - } - yf += 1; - - } - Nowdatetime.mo=yf; - yr = total_d-d-rz; - - yr += 1; - - Nowdatetime.dd=yr; - - //calculation for time - seconds = seconds%SECS_PERDAY; - Nowdatetime.hh = seconds/3600; - Nowdatetime.mm = (seconds%3600)/60; - Nowdatetime.ss = (seconds%3600)%60; - -} - -tstamp changedatetime_to_seconds(void) -{ - tstamp seconds=0; - uint32_t total_day=0; - uint16_t i=0,run_year_cnt=0,l=0; - - l = Nowdatetime.yy;//low - - - for(i=EPOCH;i - -/* - * @brief Define it for Debug & Monitor DNS processing. - * @note If defined, it dependens on - */ -//#define _SNTP_DEBUG_ - -#define MAX_SNTP_BUF_SIZE sizeof(ntpformat) ///< maximum size of DNS buffer. */ - -/* for ntpclient */ -typedef signed char s_char; -typedef unsigned long long tstamp; -typedef unsigned int tdist; - -typedef struct _ntpformat -{ - - uint8_t dstaddr[4]; /* destination (local) address */ - char version; /* version number */ - char leap; /* leap indicator */ - char mode; /* mode */ - char stratum; /* stratum */ - char poll; /* poll interval */ - s_char precision; /* precision */ - tdist rootdelay; /* root delay */ - tdist rootdisp; /* root dispersion */ - char refid; /* reference ID */ - tstamp reftime; /* reference time */ - tstamp org; /* origin timestamp */ - tstamp rec; /* receive timestamp */ - tstamp xmt; /* transmit timestamp */ - - -} ntpformat; - -typedef struct _datetime -{ - uint16_t yy; - uint8_t mo; - uint8_t dd; - uint8_t hh; - uint8_t mm; - uint8_t ss; -} datetime; - -#define ntp_port 123 //ntp server port number -#define SECS_PERDAY 86400UL // seconds in a day = 60*60*24 -#define UTC_ADJ_HRS 9 // SEOUL : GMT+9 -#define EPOCH 1900 // NTP start year - -void 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); -int8_t SNTP_run(datetime *time); -tstamp changedatetime_to_seconds(void); -void calcdatetime(tstamp seconds); - -#ifdef __cplusplus -} -#endif - -#endif /* SNTP_H_ */ diff --git a/lib/ioLibrary_Driver/TFTP/netutil.c b/lib/ioLibrary_Driver/TFTP/netutil.c deleted file mode 100644 index 77b0992..0000000 --- a/lib/ioLibrary_Driver/TFTP/netutil.c +++ /dev/null @@ -1,158 +0,0 @@ -#include -#include -#include -#include "netutil.h" - -/** - * Convert a 32bit Address into a Dotted Decimal Format string. - * - * @param addr 32bit address. - * @return Dotted Decimal Format string. - */ -int8_t* inet_ntoa(uint32_t addr) -{ - static int8_t addr_str[16]; - memset(addr_str,0,16); - sprintf((char*)addr_str,"%d.%d.%d.%d",(int32_t)(addr>>24 & 0xFF),(int32_t)(addr>>16 & 0xFF),(int32_t)(addr>>8 & 0xFF),(int32_t)(addr & 0xFF)); - return addr_str; -} - -/** - * Convert a 32bit Address into a Dotted Decimal Format string. - * This is differ from inet_ntoa in fixed length. - * - * @param addr 32bit address. - * @return Dotted Decimal Format string. - */ -int8_t* inet_ntoa_pad(uint32_t addr) -{ - static int8_t addr_str[16]; - memset(addr_str,0,16); - sprintf((char*)addr_str,"%03d.%03d.%03d.%03d",(int32_t)(addr>>24 & 0xFF),(int32_t)(addr>>16 & 0xFF),(int32_t)(addr>>8 & 0xFF),(int32_t)(addr & 0xFF)); - return addr_str; -} - -/** - * Converts a string containing an (Ipv4) Internet Protocol decimal dotted address into a 32bit address. - * - * @param addr Dotted Decimal Format string. - * @return 32bit address. - */ -uint32_t inet_addr(uint8_t* addr) -{ - int8_t i; - uint32_t inetaddr = 0; - int8_t taddr[30]; - int8_t * nexttok; - int32_t num; - strcpy((char*)taddr,(char*)addr); - - nexttok = taddr; - for(i = 0; i < 4 ; i++) - { - nexttok = (int8_t*)strtok((char*)nexttok,"."); - if(nexttok[0] == '0' && nexttok[1] == 'x') num = strtol((char*)nexttok+2, NULL, 16); - else num = strtol((char*)nexttok, NULL, 10); - inetaddr = inetaddr << 8; - inetaddr |= (num & 0xFF); - nexttok = NULL; - } - return inetaddr; -} - -/** - * Swap the byte order of 16bit(short) wide variable. - * - * @param i 16bit value to swap - * @return Swapped value - */ -uint16_t swaps(uint16_t i) -{ - uint16_t ret=0; - ret = (i & 0xFF) << 8; - ret |= ((i >> 8)& 0xFF); - return ret; -} - -/** - * Swap the byte order of 32bit(long) wide variable. - * - * @param l 32bit value to convert - * @return Swapped value - */ -uint32_t swapl(uint32_t l) -{ - uint32_t ret=0; - ret = (l & 0xFF) << 24; - ret |= ((l >> 8) & 0xFF) << 16; - ret |= ((l >> 16) & 0xFF) << 8; - ret |= ((l >> 24) & 0xFF); - return ret; -} - -/** - * htons function converts a unsigned short from host to TCP/IP network byte order (which is big-endian). - * - * @param hostshort The value to convert. - * @return The value in TCP/IP network byte order. - */ -uint16_t htons(uint16_t hostshort) -{ -#ifdef SYSTEM_LITTLE_ENDIAN - return swaps(hostshort); -#else - return hostshort; -#endif -} - - -/** - * htonl function converts a unsigned long from host to TCP/IP network byte order (which is big-endian). - * - * @param hostlong The value to convert. - * @return The value in TCP/IP network byte order. - */ -uint32_t htonl(uint32_t hostlong) -{ -#ifdef SYSTEM_LITTLE_ENDIAN - return swapl(hostlong); -#else - return hostlong; -#endif -} - - -/** - * ntohs function converts a unsigned short from TCP/IP network byte order - * to host byte order (which is little-endian on Intel processors). - * - * @param netshort The value to convert. - * @return A 16-bit number in host byte order - */ -uint32_t ntohs(uint16_t netshort) -{ -#ifdef SYSTEM_LITTLE_ENDIAN - return htons(netshort); -#else - return netshort; -#endif -} - -/** - * converts a unsigned long from TCP/IP network byte order to host byte order - * (which is little-endian on Intel processors). - * - * @param netlong The value to convert. - * @return A 16-bit number in host byte order - */ -uint32_t ntohl(uint32_t netlong) -{ -#ifdef SYSTEM_LITTLE_ENDIAN - return swapl(netlong); -#else - return netlong; -#endif -} -/** - * @} - */ diff --git a/lib/ioLibrary_Driver/TFTP/netutil.h b/lib/ioLibrary_Driver/TFTP/netutil.h deleted file mode 100644 index 08375a3..0000000 --- a/lib/ioLibrary_Driver/TFTP/netutil.h +++ /dev/null @@ -1,27 +0,0 @@ - -#ifndef __NETUTIL_H__ -#define __NETUTIL_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define SYSTEM_LITTLE_ENDIAN - -int8_t* inet_ntoa(uint32_t addr); -int8_t* inet_ntoa_pad(uint32_t addr); -uint32_t inet_addr(uint8_t* addr); -uint16_t swaps(uint16_t i); -uint32_t swapl(uint32_t l); -uint16_t htons(uint16_t hostshort); -uint32_t htonl(uint32_t hostlong); -uint32_t ntohs(uint16_t netshort); -uint32_t ntohl(uint32_t netlong); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/ioLibrary_Driver/TFTP/tftp.c b/lib/ioLibrary_Driver/TFTP/tftp.c deleted file mode 100644 index 2002ca4..0000000 --- a/lib/ioLibrary_Driver/TFTP/tftp.c +++ /dev/null @@ -1,660 +0,0 @@ -/** - * @file tftp.c - * @brief TFTP Source File. - * @version 0.1.0 - * @author Sang-sik Kim - */ - -/* Includes -----------------------------------------------------*/ -#include -#include "tftp.h" -#include "socket.h" -#include "netutil.h" - -/* define -------------------------------------------------------*/ - -/* typedef ------------------------------------------------------*/ - -/* Extern Variable ----------------------------------------------*/ - -/* Extern Functions ---------------------------------------------*/ -#ifdef F_STORAGE -extern void save_data(uint8_t *data, uint32_t data_len, uint16_t block_number); -#endif - -/* Global Variable ----------------------------------------------*/ -static int g_tftp_socket = -1; - -static uint8_t g_filename[FILE_NAME_SIZE]; - -static uint32_t g_server_ip = 0; -static uint16_t g_server_port = 0; -static uint16_t g_local_port = 0; - -static uint32_t g_tftp_state = STATE_NONE; -static uint16_t g_block_num = 0; - -static uint32_t g_timeout = 5; -static uint32_t g_resend_flag = 0; -static uint32_t tftp_time_cnt = 0; -static uint32_t tftp_retry_cnt = 0; - -static uint8_t *g_tftp_rcv_buf = NULL; - -static TFTP_OPTION default_tftp_opt = { - .code = (uint8_t *)"timeout", - .value = (uint8_t *)"5" -}; - -uint8_t g_progress_state = TFTP_PROGRESS; - -#ifdef __TFTP_DEBUG__ -int dbg_level = (INFO_DBG | ERROR_DBG | IPC_DBG); -#endif - -/* static function define ---------------------------------------*/ -static void set_filename(uint8_t *file, uint32_t file_size) -{ - memcpy(g_filename, file, file_size); -} - -static inline void set_server_ip(uint32_t ipaddr) -{ - g_server_ip = ipaddr; -} - -static inline uint32_t get_server_ip() -{ - return g_server_ip; -} - -static inline void set_server_port(uint16_t port) -{ - g_server_port = port; -} - -static inline uint16_t get_server_port() -{ - return g_server_port; -} - -static inline void set_local_port(uint16_t port) -{ - g_local_port = port; -} - -static inline uint16_t get_local_port() -{ - return g_local_port; -} - -static inline uint16_t genernate_port() -{ - /* TODO */ - return 0; -} - -static inline void set_tftp_state(uint32_t state) -{ - g_tftp_state = state; -} - -static inline uint32_t get_tftp_state() -{ - return g_tftp_state; -} - -static inline void set_tftp_timeout(uint32_t timeout) -{ - g_timeout = timeout; -} - -static inline uint32_t get_tftp_timeout() -{ - return g_timeout; -} - -static inline void set_block_number(uint16_t block_number) -{ - g_block_num = block_number; -} - -static inline uint16_t get_block_number() -{ - return g_block_num; -} - -static int open_tftp_socket(uint8_t sock) -{ - uint8_t sd, sck_state; - - sd = socket(sock, Sn_MR_UDP, 51000, SF_IO_NONBLOCK); - if(sd != sock) { - //DBG_PRINT(ERROR_DBG, "[%s] socket error\r\n", __func__); - return -1; - } - - do { - getsockopt(sd , SO_STATUS, &sck_state); - } while(sck_state != SOCK_UDP); - - return sd; -} - -static int send_udp_packet(int socket, uint8_t *packet, uint32_t len, uint32_t ip, uint16_t port) -{ - int snd_len; - - ip = htonl(ip); - - snd_len = sendto(socket, packet, len, (uint8_t *)&ip, port); - if(snd_len != len) { - //DBG_PRINT(ERROR_DBG, "[%s] sendto error\r\n", __func__); - return -1; - } - - return snd_len; -} - -static int recv_udp_packet(int socket, uint8_t *packet, uint32_t len, uint32_t *ip, uint16_t *port) -{ - int ret; - uint8_t sck_state; - uint16_t recv_len; - - /* Receive Packet Process */ - ret = getsockopt(socket, SO_STATUS, &sck_state); - if(ret != SOCK_OK) { - //DBG_PRINT(ERROR_DBG, "[%s] getsockopt SO_STATUS error\r\n", __func__); - return -1; - } - - if(sck_state == SOCK_UDP) { - ret = getsockopt(socket, SO_RECVBUF, &recv_len); - if(ret != SOCK_OK) { - //DBG_PRINT(ERROR_DBG, "[%s] getsockopt SO_RECVBUF error\r\n", __func__); - return -1; - } - - if(recv_len) { - recv_len = recvfrom(socket, packet, len, (uint8_t *)ip, port); - if(recv_len < 0) { - //DBG_PRINT(ERROR_DBG, "[%s] recvfrom error\r\n", __func__); - return -1; - } - - *ip = ntohl(*ip); - - return recv_len; - } - } - return -1; -} - -static void close_tftp_socket(int socket) -{ - close(socket); -} - - -static void init_tftp(void) -{ - g_filename[0] = 0; - - set_server_ip(0); - set_server_port(0); - set_local_port(0); - - set_tftp_state(STATE_NONE); - set_block_number(0); - - /* timeout flag */ - g_resend_flag = 0; - tftp_retry_cnt = tftp_time_cnt = 0; - - g_progress_state = TFTP_PROGRESS; -} - -static void tftp_cancel_timeout(void) -{ - if(g_resend_flag) { - g_resend_flag = 0; - tftp_retry_cnt = tftp_time_cnt = 0; - } -} - -static void tftp_reg_timeout() -{ - if(g_resend_flag == 0) { - g_resend_flag = 1; - tftp_retry_cnt = tftp_time_cnt = 0; - } -} - -static void process_tftp_option(uint8_t *msg, uint32_t msg_len) -{ - /* TODO Option Process */ -} - -static void send_tftp_rrq(uint8_t *filename, uint8_t *mode, TFTP_OPTION *opt, uint8_t opt_len) -{ - uint8_t snd_buf[MAX_MTU_SIZE]; - uint8_t *pkt = snd_buf; - uint32_t i, len; - - *((uint16_t *)pkt) = htons(TFTP_RRQ); - pkt += 2; - strcpy((char *)pkt, (const char *)filename); - pkt += strlen((char *)filename) + 1; - strcpy((char *)pkt, (const char *)mode); - pkt += strlen((char *)mode) + 1; - - for(i = 0 ; i < opt_len ; i++) { - strcpy((char *)pkt, (const char *)opt[i].code); - pkt += strlen((char *)opt[i].code) + 1; - strcpy((char *)pkt, (const char *)opt[i].value); - pkt += strlen((char *)opt[i].value) + 1; - } - - len = pkt - snd_buf; - - send_udp_packet(g_tftp_socket, snd_buf, len, get_server_ip(), TFTP_SERVER_PORT); - set_tftp_state(STATE_RRQ); - set_filename(filename, strlen((char *)filename) + 1); - tftp_reg_timeout(); -#ifdef __TFTP_DEBUG__ - DBG_PRINT(IPC_DBG, ">> TFTP RRQ : FileName(%s), Mode(%s)\r\n", filename, mode); -#endif -} - -#if 0 // 2014.07.01 sskim -static void send_tftp_wrq(uint8_t *filename, uint8_t *mode, TFTP_OPTION *opt, uint8_t opt_len) -{ - uint8_t snd_buf[MAX_MTU_SIZE]; - uint8_t *pkt = snd_buf; - uint32_t i, len; - - *((uint16_t *)pkt) = htons((uint16_t)TFTP_WRQ); - pkt += 2; - strcpy((char *)pkt, (const char *)filename); - pkt += strlen((char *)filename) + 1; - strcpy((char *)pkt, (const char *)mode); - pkt += strlen((char *)mode) + 1; - - for(i = 0 ; i < opt_len ; i++) { - strcpy((char *)pkt, (const char *)opt[i].code); - pkt += strlen((char *)opt[i].code) + 1; - strcpy((char *)pkt, (const char *)opt[i].value); - pkt += strlen((char *)opt[i].value) + 1; - } - - len = pkt - snd_buf; - - send_udp_packet(g_tftp_socket , snd_buf, len, get_server_ip(), TFTP_SERVER_PORT); - set_tftp_state(STATE_WRQ); - set_filename(filename, strlen((char *)filename) + 1); - tftp_reg_timeout(); -#ifdef __TFTP_DEBUG__ - DBG_PRINT(IPC_DBG, ">> TFTP WRQ : FileName(%s), Mode(%s)\r\n", filename, mode); -#endif -} -#endif - -#if 0 // 2014.07.01 sskim -static void send_tftp_data(uint16_t block_number, uint8_t *data, uint16_t data_len) -{ - uint8_t snd_buf[MAX_MTU_SIZE]; - uint8_t *pkt = snd_buf; - uint32_t len; - - *((uint16_t *)pkt) = htons((uint16_t)TFTP_DATA); - pkt += 2; - *((uint16_t *)pkt) = htons(block_number); - pkt += 2; - memcpy(pkt, data, data_len); - pkt += data_len; - - len = pkt - snd_buf; - - send_udp_packet(g_tftp_socket , snd_buf, len, get_server_ip(), get_server_port()); - tftp_reg_timeout(); -#ifdef __TFTP_DEBUG__ - DBG_PRINT(IPC_DBG, ">> TFTP DATA : Block Number(%d), Data Length(%d)\r\n", block_number, data_len); -#endif -} -#endif - -static void send_tftp_ack(uint16_t block_number) -{ - uint8_t snd_buf[4]; - uint8_t *pkt = snd_buf; - - *((uint16_t *)pkt) = htons((uint16_t)TFTP_ACK); - pkt += 2; - *((uint16_t *)pkt) = htons(block_number); - pkt += 2; - - send_udp_packet(g_tftp_socket , snd_buf, 4, get_server_ip(), get_server_port()); - tftp_reg_timeout(); -#ifdef __TFTP_DEBUG__ - DBG_PRINT(IPC_DBG, ">> TFTP ACK : Block Number(%d)\r\n", block_number); -#endif -} - -#if 0 // 2014.07.01 sskim -static void send_tftp_oack(TFTP_OPTION *opt, uint8_t opt_len) -{ - uint8_t snd_buf[MAX_MTU_SIZE]; - uint8_t *pkt = snd_buf; - uint32_t i, len; - - *((uint16_t *)pkt) = htons((uint16_t)TFTP_OACK); - pkt += 2; - - for(i = 0 ; i < opt_len ; i++) { - strcpy((char *)pkt, (const char *)opt[i].code); - pkt += strlen((char *)opt[i].code) + 1; - strcpy((char *)pkt, (const char *)opt[i].value); - pkt += strlen((char *)opt[i].value) + 1; - } - - len = pkt - snd_buf; - - send_udp_packet(g_tftp_socket , snd_buf, len, get_server_ip(), get_server_port()); - tftp_reg_timeout(); -#ifdef __TFTP_DEBUG__ - DBG_PRINT(IPC_DBG, ">> TFTP OACK \r\n"); -#endif -} -#endif - -#if 0 // 2014.07.01 sskim -static void send_tftp_error(uint16_t error_number, uint8_t *error_message) -{ - uint8_t snd_buf[MAX_MTU_SIZE]; - uint8_t *pkt = snd_buf; - uint32_t len; - - *((uint16_t *)pkt) = htons((uint16_t)TFTP_ERROR); - pkt += 2; - *((uint16_t *)pkt) = htons(error_number); - pkt += 2; - strcpy((char *)pkt, (const char *)error_message); - pkt += strlen((char *)error_message) + 1; - - len = pkt - snd_buf; - - send_udp_packet(g_tftp_socket , snd_buf, len, get_server_ip(), get_server_port()); - tftp_reg_timeout(); -#ifdef __TFTP_DEBUG__ - DBG_PRINT(IPC_DBG, ">> TFTP ERROR : Error Number(%d)\r\n", error_number); -#endif -} -#endif - -static void recv_tftp_rrq(uint8_t *msg, uint32_t msg_len) -{ - /* When TFTP Server Mode */ -} - -static void recv_tftp_wrq(uint8_t *msg, uint32_t msg_len) -{ - /* When TFTP Server Mode */ -} - -static void recv_tftp_data(uint8_t *msg, uint32_t msg_len) -{ - TFTP_DATA_T *data = (TFTP_DATA_T *)msg; - - data->opcode = ntohs(data->opcode); - data->block_num = ntohs(data->block_num); -#ifdef __TFTP_DEBUG__ - DBG_PRINT(IPC_DBG, "<< TFTP_DATA : opcode(%d), block_num(%d)\r\n", data->opcode, data->block_num); -#endif - - switch(get_tftp_state()) - { - case STATE_RRQ : - case STATE_OACK : - if(data->block_num == 1) { - set_tftp_state(STATE_DATA); - set_block_number(data->block_num); -#ifdef F_STORAGE - save_data(data->data, msg_len - 4, data->block_num); -#endif - tftp_cancel_timeout(); - } - send_tftp_ack(data->block_num); - - if((msg_len - 4) < TFTP_BLK_SIZE) { - init_tftp(); - g_progress_state = TFTP_SUCCESS; - } - - break; - - case STATE_DATA : - if(data->block_num == (get_block_number() + 1)) { - set_block_number(data->block_num); -#ifdef F_STORAGE - save_data(data->data, msg_len - 4, data->block_num); -#endif - tftp_cancel_timeout(); - } - send_tftp_ack(data->block_num); - - if((msg_len - 4) < TFTP_BLK_SIZE) { - init_tftp(); - g_progress_state = TFTP_SUCCESS; - } - - break; - - default : - /* invalid message */ - break; - } -} - -static void recv_tftp_ack(uint8_t *msg, uint32_t msg_len) -{ -#ifdef __TFTP_DEBUG__ - DBG_PRINT(IPC_DBG, "<< TFTP_ACK : \r\n"); -#endif - - switch(get_tftp_state()) - { - case STATE_WRQ : - break; - - case STATE_ACK : - break; - - default : - /* invalid message */ - break; - } -} - -static void recv_tftp_oack(uint8_t *msg, uint32_t msg_len) -{ -#ifdef __TFTP_DEBUG__ - DBG_PRINT(IPC_DBG, "<< TFTP_OACK : \r\n"); -#endif - - switch(get_tftp_state()) - { - case STATE_RRQ : - process_tftp_option(msg, msg_len); - set_tftp_state(STATE_OACK); - tftp_cancel_timeout(); - send_tftp_ack(0); - break; - - case STATE_WRQ : - process_tftp_option(msg, msg_len); - set_tftp_state(STATE_ACK); - tftp_cancel_timeout(); - - /* TODO DATA Transfer */ - //send_tftp_data(...); - break; - - default : - /* invalid message */ - break; - } -} - -static void recv_tftp_error(uint8_t *msg, uint32_t msg_len) -{ - TFTP_ERROR_T *data= (TFTP_ERROR_T *)msg; - - data->opcode = ntohs(data->opcode); - data->error_code = ntohs(data->error_code); - -#ifdef __TFTP_DEBUG__ - DBG_PRINT(IPC_DBG, "<< TFTP_ERROR : %d (%s)\r\n", data->error_code, data->error_msg); - DBG_PRINT(ERROR_DBG, "[%s] Error Code : %d (%s)\r\n", __func__, data->error_code, data->error_msg); -#endif - init_tftp(); - g_progress_state = TFTP_FAIL; -} - -static void recv_tftp_packet(uint8_t *packet, uint32_t packet_len, uint32_t from_ip, uint16_t from_port) -{ - uint16_t opcode; - - /* Verify Server IP */ - if(from_ip != get_server_ip()) { -#ifdef __TFTP_DEBUG__ - DBG_PRINT(ERROR_DBG, "[%s] Server IP faults\r\n", __func__); - DBG_PRINT(ERROR_DBG, "from IP : %08x, Server IP : %08x\r\n", from_ip, get_server_ip()); -#endif - return; - } - - opcode = ntohs(*((uint16_t *)packet)); - - /* Set Server Port */ - if((get_tftp_state() == STATE_WRQ) || (get_tftp_state() == STATE_RRQ)) { - set_server_port(from_port); -#ifdef __TFTP_DEBUG__ - DBG_PRINT(INFO_DBG, "[%s] Set Server Port : %d\r\n", __func__, from_port); -#endif - } - - switch(opcode) - { - case TFTP_RRQ : /* When Server */ - recv_tftp_rrq(packet, packet_len); - break; - case TFTP_WRQ : /* When Server */ - recv_tftp_wrq(packet, packet_len); - break; - case TFTP_DATA : - recv_tftp_data(packet, packet_len); - break; - case TFTP_ACK : - recv_tftp_ack(packet, packet_len); - break; - case TFTP_OACK : - recv_tftp_oack(packet, packet_len); - break; - case TFTP_ERROR : - recv_tftp_error(packet, packet_len); - break; - - default : - // Unknown Mesage - break; - } -} - -/* Functions ----------------------------------------------------*/ -void TFTP_init(uint8_t socket, uint8_t *buf) -{ - init_tftp(); - - g_tftp_socket = open_tftp_socket(socket); - g_tftp_rcv_buf = buf; -} - -void TFTP_exit(void) -{ - init_tftp(); - - close_tftp_socket(g_tftp_socket); - g_tftp_socket = -1; - - g_tftp_rcv_buf = NULL; -} - -int TFTP_run(void) -{ - uint16_t len, from_port; - uint32_t from_ip; - - /* Timeout Process */ - if(g_resend_flag) { - if(tftp_time_cnt >= g_timeout) { - switch(get_tftp_state()) { - case STATE_WRQ: // 미구현 - break; - - case STATE_RRQ: - send_tftp_rrq(g_filename, (uint8_t *)TRANS_BINARY, &default_tftp_opt, 1); - break; - - case STATE_OACK: - case STATE_DATA: - send_tftp_ack(get_block_number()); - break; - - case STATE_ACK: // 미구현 - break; - - default: - break; - } - - tftp_time_cnt = 0; - tftp_retry_cnt++; - - if(tftp_retry_cnt >= 5) { - init_tftp(); - g_progress_state = TFTP_FAIL; - } - } - } - - /* Receive Packet Process */ - len = recv_udp_packet(g_tftp_socket, g_tftp_rcv_buf, MAX_MTU_SIZE, &from_ip, &from_port); - if(len < 0) { -#ifdef __TFTP_DEBUG__ - DBG_PRINT(ERROR_DBG, "[%s] recv_udp_packet error\r\n", __func__); -#endif - return g_progress_state; - } - - recv_tftp_packet(g_tftp_rcv_buf, len, from_ip, from_port); - - return g_progress_state; -} - -void TFTP_read_request(uint32_t server_ip, uint8_t *filename) -{ - set_server_ip(server_ip); -#ifdef __TFTP_DEBUG__ - DBG_PRINT(INFO_DBG, "[%s] Set Tftp Server : %x\r\n", __func__, server_ip); -#endif - - g_progress_state = TFTP_PROGRESS; - send_tftp_rrq(filename, (uint8_t *)TRANS_BINARY, &default_tftp_opt, 1); -} - -void tftp_timeout_handler(void) -{ - if(g_resend_flag) - tftp_time_cnt++; -} diff --git a/lib/ioLibrary_Driver/TFTP/tftp.h b/lib/ioLibrary_Driver/TFTP/tftp.h deleted file mode 100644 index b8f3b4d..0000000 --- a/lib/ioLibrary_Driver/TFTP/tftp.h +++ /dev/null @@ -1,101 +0,0 @@ -/** - * @file tftp.h - * @brief TFTP Header File. - * @version 0.1.0 - * @author Sang-sik Kim - */ -#ifndef __TFTP_H__ -#define __TFTP_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define F_APP_TFTP -#define __TFTP_DEBUG__ - -#define F_STORAGE // If your target support a storage, you have to activate this feature and implement. - -#define SOCK_TFTP 1 - -#define INFO_DBG 0x01 -#define ERROR_DBG 0x02 -#define DEBUG_DBG 0x04 -#define IPC_DBG 0x08 - -#define DBG_PRINT(level, format, args...) { \ - if(dbg_level & level) \ - printf(format, ##args); \ - } - -#define NORMAL_MODE 0 -#define TFTP_MODE 1 - -extern int dbg_level; - -/* tftp message */ -#define TFTP_RRQ 1 -#define TFTP_WRQ 2 -#define TFTP_DATA 3 -#define TFTP_ACK 4 -#define TFTP_ERROR 5 -#define TFTP_OACK 6 - -/* tftp state */ -#define STATE_NONE 0 -#define STATE_RRQ 1 -#define STATE_WRQ 2 -#define STATE_DATA 3 -#define STATE_ACK 4 -#define STATE_OACK 5 - -/* tftp transfer mode */ -#define TRANS_ASCII "netascii" -#define TRANS_BINARY "octet" - -/* tftp progress state */ -#define TFTP_PROGRESS 0 -#define TFTP_FAIL 1 -#define TFTP_SUCCESS 2 - -/* define */ -#define TFTP_SERVER_PORT 69 -#define TFTP_TEMP_PORT 51000 -#define TFTP_BLK_SIZE 512 -#define MAX_MTU_SIZE 1514 -#define FILE_NAME_SIZE 20 - -//#define __TFTP_DEBUG__ - -/* typedef */ -typedef struct tftp_data { - uint16_t opcode; - uint16_t block_num; - uint8_t data[0]; -} TFTP_DATA_T; - -typedef struct tftp_error { - uint16_t opcode; - uint16_t error_code; - uint8_t error_msg[0]; -} TFTP_ERROR_T; - -typedef struct tftp_option { - uint8_t *code; - uint8_t *value; -} TFTP_OPTION; - -/* Functions */ -void TFTP_init(uint8_t socket, uint8_t *buf); -void TFTP_exit(void); -int TFTP_run(void); -void TFTP_read_request(uint32_t server_ip, uint8_t *filename); -void tftp_timeout_handler(void); - -#ifdef __cplusplus -} -#endif - -#endif /*__TFTP_H__ */ diff --git a/lib/ioLibrary_Driver/W5100/w5100.c b/lib/ioLibrary_Driver/W5100/w5100.c deleted file mode 100644 index ab3ebf8..0000000 --- a/lib/ioLibrary_Driver/W5100/w5100.c +++ /dev/null @@ -1,386 +0,0 @@ -//***************************************************************************** -// -//! \file w5100.c -//! \brief W5100 HAL Interface. -//! \version 1.0.0 -//! \date 2013/10/21 -//! \par Revision history -//! <2013/10/21> 1st Release -//! \author MidnightCow -//! -//! 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 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 "w5100.h" - -#if (_WIZCHIP_ == 5100) -/** -@brief This function writes the data into W5100 registers. -*/ -void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb ) -{ - 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_BUS_DIR_) ) - //M20150601 : Rename the function for integrating with ioLibrary - //WIZCHIP.IF.BUS._write_byte(AddrSel,wb); - WIZCHIP.IF.BUS._write_data(AddrSel,wb); -#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 W5100 registers. -*/ -uint8_t WIZCHIP_READ(uint32_t AddrSel) -{ - uint8_t ret; - - 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_BUS_DIR_) ) - //M20150601 : Rename the function for integrating with ioLibrary - //ret = WIZCHIP.IF.BUS._read_byte(AddrSel); - ret = WIZCHIP.IF.BUS._read_data(AddrSel); -#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 W5100. !!!" -#endif - - WIZCHIP.CS._deselect(); - WIZCHIP_CRITICAL_EXIT(); - return ret; -} - - -/** -@brief This function writes into W5100 memory(Buffer) -*/ -void WIZCHIP_WRITE_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_)) - for(i = 0; i < len; i++) - { - //M20160715 : Depricated "M20150601 : Remove _select() to top-side" - // CS should be controlled every SPI frames - WIZCHIP.CS._select(); - 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); - WIZCHIP.IF.SPI._write_byte(pBuf[i]); // Data write (write 1byte data) - //M20160715 : Depricated "M20150601 : Remove _select() to top-side" - WIZCHIP.CS._deselect(); - } -#elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_DIR_) ) - for(i = 0; i < len; i++) - //M20150601 : Rename the function for integrating with ioLibrary - // WIZCHIP.IF.BUS._write_byte(AddrSel+i,pBuf[i]); - WIZCHIP.IF.BUS._write_data(AddrSel+i,pBuf[i]); -#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 W5100. !!!!" -#endif - - WIZCHIP.CS._deselect(); //M20150601 : Moved here. - WIZCHIP_CRITICAL_EXIT(); -} - -/** -@brief This function reads into W5100 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_)) - for(i = 0; i < len; i++) - { - //M20160715 : Depricated "M20150601 : Remove _select() to top-side" - // CS should be controlled every SPI frames - WIZCHIP.CS._select(); - 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); - pBuf[i] = WIZCHIP.IF.SPI._read_byte(); - //M20160715 : Depricated "M20150601 : Remove _select() to top-side" - WIZCHIP.CS._deselect(); - } -#elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_DIR_) ) - for(i = 0 ; i < len; i++) - //M20150601 : Rename the function for integrating with ioLibrary - // pBuf[i] = WIZCHIP.IF.BUS._read_byte(AddrSel+i); - pBuf[i] = WIZCHIP.IF.BUS._read_data(AddrSel+i); -#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 W5100. !!!!" -#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 = _W5100_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 = _W5100_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); -} - -#endif diff --git a/lib/ioLibrary_Driver/W5100/w5100.h b/lib/ioLibrary_Driver/W5100/w5100.h deleted file mode 100644 index 3396955..0000000 --- a/lib/ioLibrary_Driver/W5100/w5100.h +++ /dev/null @@ -1,1865 +0,0 @@ -//* **************************************************************************** -//! \file w5100.h -//! \brief W5100 HAL Header File. -//! \version 1.0.0 -//! \date 2013/10/21 -//! \par Revision history -//! <2013/10/21> 1st Release -//! \author MidnightCow -//! \copyright -//! -//! 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 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. -// -//***************************************************************************** - -#ifndef _W5100_H_ -#define _W5100_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include "wizchip_conf.h" - -/// \cond DOXY_APPLY_CODE -#if (_WIZCHIP_ == 5100) -/// \endcond - -#define _WIZCHIP_SN_BASE_ (0x0400) -#define _WIZCHIP_SN_SIZE_ (0x0100) -#define _WIZCHIP_IO_TXBUF_ (0x4000) /* Internal Tx buffer address of the iinchip */ -#define _WIZCHIP_IO_RXBUF_ (0x6000) /* Internal Rx buffer address of the iinchip */ - - -#define WIZCHIP_CREG_BLOCK 0x00 ///< Common register block -#define WIZCHIP_SREG_BLOCK(N) (_WIZCHIP_SN_BASE_+ _WIZCHIP_SN_SIZE_*N) ///< Socket N register block - -#define WIZCHIP_OFFSET_INC(ADDR, N) (ADDR + N) ///< Increase offset address - -#if (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_DIR_) - #define _W5100_IO_BASE_ _WIZCHIP_IO_BASE_ -#elif (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) - #define IDM_OR ((_WIZCHIP_IO_BASE + 0x0000)) - #define IDM_AR0 ((_WIZCHIP_IO_BASE_ + 0x0001)) - #define IDM_AR1 ((_WIZCHIP_IO_BASE_ + 0x0002)) - #define IDM_DR ((_WIZCHIP_IO_BASE_ + 0x0003)) - #define _W5100_IO_BASE_ 0x0000 -#elif (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_) - #define _W5100_IO_BASE_ 0x0000 -#endif - -/////////////////////////////////////// -// Definition For Legacy Chip Driver // -/////////////////////////////////////// -#define IINCHIP_READ(ADDR) WIZCHIP_READ(ADDR) ///< The defined for legacy chip driver -#define IINCHIP_WRITE(ADDR,VAL) WIZCHIP_WRITE(ADDR,VAL) ///< The defined for legacy chip driver -#define IINCHIP_READ_BUF(ADDR,BUF,LEN) WIZCHIP_READ_BUF(ADDR,BUF,LEN) ///< The defined for legacy chip driver -#define IINCHIP_WRITE_BUF(ADDR,BUF,LEN) WIZCHIP_WRITE(ADDR,BUF,LEN) ///< The defined for legacy chip driver - - -//----------- defgroup -------------------------------- - -/** - * @defgroup W5100 W5100 - * @brief WHIZCHIP register defines and I/O functions of @b W5100. - * - * - @ref WIZCHIP_register_W5100 : @ref Common_register_group_W5100 and @ref Socket_register_group_W5100 - * - @ref WIZCHIP_IO_Functions_W5100 : @ref Basic_IO_function_W5100, @ref Common_register_access_function_W5100 and @ref Socket_register_group_W5100 - */ - - /** - * @defgroup WIZCHIP_register_W5100 WIZCHIP register - * @ingroup W5100 - * @brief WIZCHIP register defines register group of W5100 . - * - * - \ref Common_register_group_W5100 : Common register group W5100 - * - \ref Socket_register_group_W5100 : \c SOCKET n register group W5100 - */ - - -/** - * @defgroup WIZCHIP_IO_Functions_W5100 WIZCHIP I/O functions - * @ingroup W5100 - * @brief This supports the basic I/O functions for \ref WIZCHIP_register_W5100. - * - * - Basic I/O function \n - * WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF() \n\n - * - * - \ref Common_register_group_W5100 access functions \n - * -# @b Mode \n - * getMR(), setMR() - * -# @b Interrupt \n - * getIR(), setIR(), getIMR(), setIMR(), - * -# Network Information \n - * getSHAR(), setSHAR(), getGAR(), setGAR(), getSUBR(), setSUBR(), getSIPR(), setSIPR() - * -# @b Retransmission \n - * getRCR(), setRCR(), getRTR(), setRTR() - * -# @b PPPoE \n - * getPTIMER(), setPTIMER(), getPMAGIC(), getPMAGIC() - * - * - \ref Socket_register_group_W5100 access functions \n - * -# SOCKET control \n - * getSn_MR(), setSn_MR(), getSn_CR(), setSn_CR(), getSn_IR(), setSn_IR() - * -# SOCKET information \n - * getSn_SR(), getSn_DHAR(), setSn_DHAR(), getSn_PORT(), setSn_PORT(), getSn_DIPR(), setSn_DIPR(), getSn_DPORT(), setSn_DPORT() - * getSn_MSSR(), setSn_MSSR() - * -# SOCKET communication \n - * getSn_RXMEM_SIZE(), setSn_RXMEM_SIZE(), getSn_TXMEM_SIZE(), setSn_TXMEM_SIZE() \n - * getSn_TX_RD(), getSn_TX_WR(), setSn_TX_WR() \n - * getSn_RX_RD(), setSn_RX_RD(), getSn_RX_WR() \n - * getSn_TX_FSR(), getSn_RX_RSR() - * -# IP header field \n - * getSn_FRAG(), setSn_FRAG(), getSn_TOS(), setSn_TOS() \n - * getSn_TTL(), setSn_TTL() - */ - -/** - * @defgroup Common_register_group_W5100 Common register - * @ingroup WIZCHIP_register_W5100 - * @brief Common register group\n - * It set the basic for the networking\n - * It set the configuration such as interrupt, network information, ICMP, etc. - * @details - * @sa MR : Mode register. - * @sa GAR, SUBR, SHAR, SIPR - * @sa IR, Sn_IR, _IMR_ : Interrupt. - * @sa _RTR_, _RCR_ : Data retransmission. - * @sa PTIMER, PMAGIC : PPPoE. - */ - - - /** - * @defgroup Socket_register_group_W5100 Socket register - * @ingroup WIZCHIP_register_W5100 - * @brief Socket register group\n - * Socket register configures and control SOCKETn which is necessary to data communication. - * @details - * @sa Sn_MR, Sn_CR, Sn_IR : SOCKETn Control - * @sa Sn_SR, Sn_PORT, Sn_DHAR, Sn_DIPR, Sn_DPORT : SOCKETn Information - * @sa Sn_MSSR, Sn_TOS, Sn_TTL, Sn_FRAG : Internet protocol. - * @sa Sn_RXMEM_SIZE, Sn_TXMEM_SIZE, Sn_TX_FSR, Sn_TX_RD, Sn_TX_WR, Sn_RX_RSR, Sn_RX_RD, Sn_RX_WR : Data communication - */ - - /** - * @defgroup Basic_IO_function_W5100 Basic I/O function - * @ingroup WIZCHIP_IO_Functions_W5100 - * @brief These are basic input/output functions to read values from register or write values to register. - */ - -/** - * @defgroup Common_register_access_function_W5100 Common register access functions - * @ingroup WIZCHIP_IO_Functions_W5100 - * @brief These are functions to access common registers. - */ - -/** - * @defgroup Socket_register_access_function_W5100 Socket register access functions - * @ingroup WIZCHIP_IO_Functions_W5100 - * @brief These are functions to access socket registers. - */ - - //----------------------------------------------------------------------------------- - -//----------------------------- W5100 Common Registers IOMAP ----------------------------- -/** - * @ingroup Common_register_group_W5100 - * @brief Mode Register address(R/W)\n - * \ref MR is used for S/W reset, ping block mode, PPPoE mode and etc. - * @details Each bit of \ref MR defined as follows. - * - * - * - *
7 6 5 4 3 2 1 0
RST Reserved WOL PB PPPoE Reserved AI IND
- * - \ref MR_RST : Reset - * - \ref MR_PB : Ping block - * - \ref MR_PPPOE : PPPoE mode - * - \ref MR_AI : Address Auto-Increment in Indirect Bus Interface - * - \ref MR_IND : Indirect Bus Interface mode - */ -#if _WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_ - #define MR (_WIZCHIP_IO_BASE_ + (0x0000)) // Mode -#else - #define MR (_W5100_IO_BASE_ + (0x0000)) // Mode -#endif - -/** - * @ingroup Common_register_group_W5100 - * @brief Gateway IP Register address(R/W) - * @details \ref GAR configures the default gateway address. - */ -#define GAR (_W5100_IO_BASE_ + (0x0001)) // GW Address - -/** - * @ingroup Common_register_group_W5100 - * @brief Subnet mask Register address(R/W) - * @details \ref SUBR configures the subnet mask address. - */ -#define SUBR (_W5100_IO_BASE_ + (0x0005)) // SN Mask Address - -/** - * @ingroup Common_register_group_W5100 - * @brief Source MAC Register address(R/W) - * @details \ref SHAR configures the source hardware address. - */ -#define SHAR (_W5100_IO_BASE_ + (0x0009)) // Source Hardware Address - -/** - * @ingroup Common_register_group_W5100 - * @brief Source IP Register address(R/W) - * @details \ref SIPR configures the source IP address. - */ -#define SIPR (_W5100_IO_BASE_ + (0x000F)) // Source IP Address - -// Reserved (_W5100_IO_BASE_ + (0x0013)) -// Reserved (_W5100_IO_BASE_ + (0x0014)) - -/** - * @ingroup Common_register_group_W5100 - * @brief Interrupt Register(R/W) - * @details \ref IR indicates the interrupt status. Each bit of \ref IR will be still until the bit will be written to by the host. - * If \ref IR is not equal to x00 INTn PIN is asserted to low until it is x00\n\n - * Each bit of \ref IR defined as follows. - * - * - * - *
7 6 5 4 3 2 1 0
CONFLICT UNREACH PPPoE Reserved S3_INT S2_INT S1_INT S0_INT
- * - \ref IR_CONFLICT : IP conflict - * - \ref IR_UNREACH : Destination unreachable - * - \ref IR_PPPoE : PPPoE connection close - * - \ref IR_SOCK(3) : SOCKET 3 Interrupt - * - \ref IR_SOCK(2) : SOCKET 2 Interrupt - * - \ref IR_SOCK(1) : SOCKET 1 Interrupt - * - \ref IR_SOCK(0) : SOCKET 0 Interrupt - */ -#define IR (_W5100_IO_BASE_ + (0x0015)) // Interrupt - -/** - * @ingroup Common_register_group_W5100 - * @brief Socket Interrupt Mask Register(R/W) - * @details Each bit of \ref _IMR_ corresponds to each bit of \ref IR. - * When a bit of \ref _IMR_ is and the corresponding bit of \ref IR is set, Interrupt will be issued. - */ -#define _IMR_ (_W5100_IO_BASE_ + (0x0016)) // Socket Interrupt Mask - -/** - * @ingroup Common_register_group_W5100 - * @brief Timeout register address( 1 is 100us )(R/W) - * @details \ref _RTR_ configures the retransmission timeout period. The unit of timeout period is 100us and the default of \ref _RTR_ is x07D0or 000 - * And so the default timeout period is 200ms(100us X 2000). During the time configured by \ref _RTR_, W5100 waits for the peer response - * to the packet that is transmitted by \ref Sn_CR (CONNECT, DISCON, CLOSE, SEND, SEND_MAC, SEND_KEEP command). - * If the peer does not respond within the \ref _RTR_ time, W5100 retransmits the packet or issues timeout. - */ -#define _RTR_ (_W5100_IO_BASE_ + (0x0017)) // Retry Time - -/** - * @ingroup Common_register_group_W5100 - * @brief Retry count register(R/W) - * @details \ref _RCR_ configures the number of time of retransmission. - * When retransmission occurs as many as ref _RCR_+1 Timeout interrupt is issued (\ref Sn_IR_TIMEOUT = '1'). - */ -#define _RCR_ (_W5100_IO_BASE_ + (0x0019)) // Retry Count -#define RMSR (_W5100_IO_BASE_ + (0x001A)) // Receicve Memory Size -#define TMSR (_W5100_IO_BASE_ + (0x001B)) // Trnasmit Memory Size - - -/** - * @ingroup Common_register_group_W5100 - * @brief PPP LCP Request Timer register in PPPoE mode(R) - * @details \ref PATR notifies authentication method that has been agreed at the connection with - * PPPoE Server. W5100 supports two types of Authentication method - PAP and CHAP. - */ -#define PATR (_W5100_IO_BASE_ + (0x001C)) - - -/** - * @ingroup Common_register_group_W5100 - * @brief PPP LCP Request Timer register in PPPoE mode(R) - * @details \ref PTIMER configures the time for sending LCP echo request. The unit of time is 25ms. - */ -#define PTIMER (_W5100_IO_BASE_ + (0x0028)) // PPP LCP RequestTimer - -/** - * @ingroup Common_register_group_W5100 - * @brief PPP LCP Magic number register in PPPoE mode(R) - * @details \ref PMAGIC configures the 4bytes magic number to be used in LCP negotiation. - */ -#define PMAGIC (_W5100_IO_BASE_ + (0x0029)) // PPP LCP Magic number - -#define UIPR0 (_W5100_IO_BASE_ + (0x002A)) -#define UPORT0 (_W5100_IO_BASE + (0x002E)) - - - -//----------------------------- W5100 Socket Registers ----------------------------- - -//--------------------------- For Backward Compatibility --------------------------- - -/** - * @ingroup Socket_register_group_W5100 - * @brief socket Mode register(R/W) - * @details \ref Sn_MR configures the option or protocol type of Socket n.\n\n - * Each bit of \ref Sn_MR defined as the following. - * - * - * - *
7 6 5 4 3 2 1 0
MULTI MF ND/MC Reserved Protocol[3] Protocol[2] Protocol[1] Protocol[0]
- * - \ref Sn_MR_MULTI : Support UDP Multicasting - * - \ref Sn_MR_MF : Support MACRAW - * - \ref Sn_MR_ND : No Delayed Ack(TCP) flag - * - \ref Sn_MR_MC : IGMP version used in UDP mulitcasting - * - Protocol - * - * - * - * - * - * - *
Protocol[3] Protocol[2] Protocol[1] Protocol[0] @b Meaning
0 0 0 0 Closed
0 0 0 1 TCP
0 0 1 0 UDP
0 1 0 0 MACRAW
- * - In case of Socket 0 - * - * - * - * - *
Protocol[3] Protocol[2] Protocol[1] Protocol[0] @b Meaning
0 1 0 0 MACRAW
0 1 0 1 PPPoE
- * - \ref Sn_MR_MACRAW : MAC LAYER RAW SOCK \n - * - \ref Sn_MR_UDP : UDP - * - \ref Sn_MR_TCP : TCP - * - \ref Sn_MR_CLOSE : Unused socket - * @note MACRAW mode should be only used in Socket 0. - */ -#define Sn_MR(sn) (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0000)) // socket Mode register - -/** - * @ingroup Socket_register_group_W5100 - * @brief Socket command register(R/W) - * @details This is used to set the command for Socket n such as OPEN, CLOSE, CONNECT, LISTEN, SEND, and RECEIVE.\n - * After W5100 accepts the command, the \ref Sn_CR register is automatically cleared to 0x00. - * Even though \ref Sn_CR is cleared to 0x00, the command is still being processed.\n - * To check whether the command is completed or not, please check the \ref Sn_IR or \ref Sn_SR. - * - \ref Sn_CR_OPEN : Initialize or open socket. - * - \ref Sn_CR_LISTEN : Wait connection request in TCP mode(Server mode) - * - \ref Sn_CR_CONNECT : Send connection request in TCP mode(Client mode) - * - \ref Sn_CR_DISCON : Send closing request in TCP mode. - * - \ref Sn_CR_CLOSE : Close socket. - * - \ref Sn_CR_SEND : Update TX buffer pointer and send data. - * - \ref Sn_CR_SEND_MAC : Send data with MAC address, so without ARP process. - * - \ref Sn_CR_SEND_KEEP : Send keep alive message. - * - \ref Sn_CR_RECV : Update RX buffer pointer and receive data. - * - In case of S0_MR(P3:P0) = S0_MR_PPPoE - * - * - * - * - * - * - * - *
Value Symbol Description
0x23 PCON PPPoE connection begins by transmitting PPPoE discovery packet
0x24 PDISCON Closes PPPoE connection
0x25 PCR In each phase, it transmits REQ message.
0x26 PCN In each phase, it transmits NAK message.
0x27 PCJ In each phase, it transmits REJECT message.
- */ -#define Sn_CR(sn) (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0001)) // channel Sn_CR register - -/** - * @ingroup Socket_register_group_W5100 - * @brief Socket interrupt register(R) - * @details \ref Sn_IR indicates the status of Socket Interrupt such as establishment, termination, receiving data, timeout).\n - * When an interrupt occurs and the corresponding bit \ref IR_SOCK(N) in \ref _IMR_ are set, \ref IR_SOCK(N) in \ref IR becomes '1'.\n - * In order to clear the \ref Sn_IR bit, the host should write the bit to \n - * - * - * - *
7 6 5 4 3 2 1 0
PRECV PFAIL PNEXT SEND_OK TIMEOUT RECV DISCON CON
- * - \ref Sn_IR_PRECV : PPP Receive Interrupt - * - \ref Sn_IR_PFAIL : PPP Fail Interrupt - * - \ref Sn_IR_PNEXT : PPP Next Phase Interrupt - * - \ref Sn_IR_SENDOK : SEND_OK Interrupt - * - \ref Sn_IR_TIMEOUT : TIMEOUT Interrupt - * - \ref Sn_IR_RECV : RECV Interrupt - * - \ref Sn_IR_DISCON : DISCON Interrupt - * - \ref Sn_IR_CON : CON Interrupt - */ -#define Sn_IR(sn) (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0002)) // channel interrupt register - -/** - * @ingroup Socket_register_group_W5100 - * @brief Socket status register(R) - * @details \ref Sn_SR indicates the status of Socket n.\n - * The status of Socket n is changed by \ref Sn_CR or some special control packet as SYN, FIN packet in TCP. - * @par Normal status - * - \ref SOCK_CLOSED : Closed - * - \ref SOCK_INIT : Initiate state - * - \ref SOCK_LISTEN : Listen state - * - \ref SOCK_ESTABLISHED : Success to connect - * - \ref SOCK_CLOSE_WAIT : Closing state - * - \ref SOCK_UDP : UDP socket - * - \ref SOCK_MACRAW : MAC raw mode socket - *@par Temporary status during changing the status of Socket n. - * - \ref SOCK_SYNSENT : This indicates Socket n sent the connect-request packet (SYN packet) to a peer. - * - \ref SOCK_SYNRECV : It indicates Socket n successfully received the connect-request packet (SYN packet) from a peer. - * - \ref SOCK_FIN_WAIT : Connection state - * - \ref SOCK_CLOSING : Closing state - * - \ref SOCK_TIME_WAIT : Closing state - * - \ref SOCK_LAST_ACK : Closing state - */ -#define Sn_SR(sn) (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0003)) // channel status register - -/** - * @ingroup Socket_register_group_W5100 - * @brief source port register(R/W) - * @details \ref Sn_PORT configures the source port number of Socket n. - * It is valid when Socket n is used in TCP/UDP mode. It should be set before OPEN command is ordered. -*/ -#define Sn_PORT(sn) (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0004)) // source port register - -/** - * @ingroup Socket_register_group_W5100 - * @brief Peer MAC register address(R/W) - * @details \ref Sn_DHAR configures the destination hardware address of Socket n when using SEND_MAC command in UDP mode or - * it indicates that it is acquired in ARP-process by CONNECT/SEND command. - */ -#define Sn_DHAR(sn) (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0006)) // Peer MAC register address - -/** - * @ingroup Socket_register_group_W5100 - * @brief Peer IP register address(R/W) - * @details \ref Sn_DIPR configures or indicates the destination IP address of Socket n. It is valid when Socket n is used in TCP/UDP mode. - * In TCP client mode, it configures an IP address of TCP server before CONNECT command. - * In TCP server mode, it indicates an IP address of TCP client after successfully establishing connection. - * In UDP mode, it configures an IP address of peer to be received the UDP packet by SEND or SEND_MAC command. - */ -#define Sn_DIPR(sn) (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x000C)) // Peer IP register address - -/** - * @ingroup Socket_register_group_W5100 - * @brief Peer port register address(R/W) - * @details \ref Sn_DPORT configures or indicates the destination port number of Socket n. It is valid when Socket n is used in TCP/UDP mode. - * In TCP clientmode, it configures the listen port number of TCP server before CONNECT command. - * In TCP Servermode, it indicates the port number of TCP client after successfully establishing connection. - * In UDP mode, it configures the port number of peer to be transmitted the UDP packet by SEND/SEND_MAC command. - */ -#define Sn_DPORT(sn) (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0010)) // Peer port register address - -/** - * @ingroup Socket_register_group_W5100 - * @brief Maximum Segment Size(Sn_MSSR0) register address(R/W) - * @details \ref Sn_MSSR configures or indicates the MTU(Maximum Transfer Unit) of Socket n. - */ -#define Sn_MSSR(sn) (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0012)) // Maximum Segment Size(Sn_MSSR0) register address - -/** - * @ingroup Socket_register_group_W5100 - * @brief IP Protocol(PROTO) Register(R/W) - * @details \ref Sn_PROTO that sets the protocol number field of the IP header at the IP layer. It is - * valid only in IPRAW mode, and ignored in other modes. - */ -#define Sn_PROTO(sn) (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0014)) // Protocol of IP Header field register in IP raw mode - -/** - * @ingroup Socket_register_group_W5100 - * @brief IP Type of Service(TOS) Register(R/W) - * @details \ref Sn_TOS configures the TOS(Type Of Service field in IP Header) of Socket n. - * It is set before OPEN command. - */ -#define Sn_TOS(sn) (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + 0x0015) // IP Type of Service(TOS) Register - -/** - * @ingroup Socket_register_group_W5100 - * @brief IP Time to live(TTL) Register(R/W) - * @details \ref Sn_TTL configures the TTL(Time To Live field in IP header) of Socket n. - * It is set before OPEN command. - */ -#define Sn_TTL(sn) (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0016)) // IP Time to live(TTL) Register - -// Reserved (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0017)) -// Reserved (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0018)) -// Reserved (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0019)) -// Reserved (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001A)) -// Reserved (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001B)) -// Reserved (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001C)) -// Reserved (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001D)) - -/** - * @ingroup Socket_register_group_W5100 - * @brief Transmit free memory size register(R) - * @details \ref Sn_TX_FSR indicates the free size of Socket n TX Buffer Block. It is initialized to the configured size by \ref Sn_TXMEM_SIZE. - * Data bigger than \ref Sn_TX_FSR should not be saved in the Socket n TX Buffer because the bigger data overwrites the previous saved data not yet sent. - * Therefore, check before saving the data to the Socket n TX Buffer, and if data is equal or smaller than its checked size, - * transmit the data with SEND/SEND_MAC command after saving the data in Socket n TX buffer. But, if data is bigger than its checked size, - * transmit the data after dividing into the checked size and saving in the Socket n TX buffer. - */ -#define Sn_TX_FSR(sn) (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0020)) // Transmit free memory size register - -/** - * @ingroup Socket_register_group_W5100 - * @brief Transmit memory read pointer register address(R) - * @details \ref Sn_TX_RD is initialized by OPEN command. However, if Sn_MR(P[3:0]) is TCP mode(001), it is re-initialized while connecting with TCP. - * After its initialization, it is auto-increased by SEND command. - * SEND command transmits the saved data from the current \ref Sn_TX_RD to the \ref Sn_TX_WR in the Socket n TX Buffer. - * After transmitting the saved data, the SEND command increases the \ref Sn_TX_RD as same as the \ref Sn_TX_WR. - * If its increment value exceeds the maximum value 0xFFFF, (greater than 0x10000 and the carry bit occurs), - * then the carry bit is ignored and will automatically update with the lower 16bits value. - */ -#define Sn_TX_RD(sn) (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0022)) // Transmit memory read pointer register address - -/** - * @ingroup Socket_register_group_W5100 - * @brief Transmit memory write pointer register address(R/W) - * @details \ref Sn_TX_WR is initialized by OPEN command. However, if Sn_MR(P[3:0]) is TCP mode(001), it is re-initialized while connecting with TCP.\n - * It should be read or be updated like as follows.\n - * 1. Read the starting address for saving the transmitting data.\n - * 2. Save the transmitting data from the starting address of Socket n TX buffer.\n - * 3. After saving the transmitting data, update \ref Sn_TX_WR to the increased value as many as transmitting data size. - * If the increment value exceeds the maximum value 0xFFFF(greater than 0x10000 and the carry bit occurs), - * then the carry bit is ignored and will automatically update with the lower 16bits value.\n - * 4. Transmit the saved data in Socket n TX Buffer by using SEND/SEND command - */ -#define Sn_TX_WR(sn) (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0024)) // Transmit memory write pointer register address - -/** - * @ingroup Socket_register_group_W5100 - * @brief Received data size register(R) - * @details \ref Sn_RX_RSR indicates the data size received and saved in Socket n RX Buffer. - * \ref Sn_RX_RSR does not exceed the \ref Sn_RXMEM_SIZE and is calculated as the difference between - * Socket n RX Write Pointer (\ref Sn_RX_WR)and Socket n RX Read Pointer (\ref Sn_RX_RD) - */ -#define Sn_RX_RSR(sn) (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0026)) // Received data size register - -/** - * @ingroup Socket_register_group_W5100 - * @brief Read point of Receive memory(R/W) - * @details \ref Sn_RX_RD is initialized by OPEN command. Make sure to be read or updated as follows.\n - * 1. Read the starting save address of the received data.\n - * 2. Read data from the starting address of Socket n RX Buffer.\n - * 3. After reading the received data, Update \ref Sn_RX_RD to the increased value as many as the reading size. - * If the increment value exceeds the maximum value 0xFFFF, that is, is greater than 0x10000 and the carry bit occurs, - * update with the lower 16bits value ignored the carry bit.\n - * 4. Order RECV command is for notifying the updated \ref Sn_RX_RD to W5100. - */ -#define Sn_RX_RD(sn) (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0028)) // Read point of Receive memory - -/** - * @ingroup Socket_register_group_W5100 - * @brief Write point of Receive memory(R) - * @details \ref Sn_RX_WR is initialized by OPEN command and it is auto-increased by the data reception. - * If the increased value exceeds the maximum value 0xFFFF, (greater than 0x10000 and the carry bit occurs), - * then the carry bit is ignored and will automatically update with the lower 16bits value. - */ -#define Sn_RX_WR(sn) (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x002A)) // Write point of Receive memory - - -//----------------------------- W5100 Register values ----------------------------- - -/* MODE register values */ -/** - * @brief Reset - * @details If this bit is All internal registers will be initialized. It will be automatically cleared as after S/W reset. - */ -#define MR_RST 0x80 ///< reset - - -/** - * @brief Ping block - * @details 0 : Disable Ping block\n - * 1 : Enable Ping block\n - * If the bit is it blocks the response to a ping request. - */ -#define MR_PB 0x10 ///< ping block - -/** - * @brief Enable PPPoE - * @details 0 : DisablePPPoE mode\n - * 1 : EnablePPPoE mode\n - * If you use ADSL, this bit should be '1'. - */ -#define MR_PPPOE 0x08 ///< enable pppoe - -/** - * @brief Address Auto-Increment in Indirect Bus Interface - * @details 0 : Disable auto-increment \n - * 1 : Enable auto-incremente \n - * At the Indirect Bus Interface mode, if this bit is set as ��1��, the address will - * be automatically increased by 1 whenever read and write are performed. - */ -#define MR_AI 0x02 ///< auto-increment in indirect mode - -/** - * @brief Indirect Bus Interface mode - * @details 0 : Disable Indirect bus Interface mode \n - * 1 : Enable Indirect bus Interface mode \n - * If this bit is set as ��1��, Indirect Bus Interface mode is set. - */ -#define MR_IND 0x01 ///< enable indirect mode - -/* IR register values */ -/** - * @brief Check IP conflict. - * @details Bit is set as when own source IP address is same with the sender IP address in the received ARP request. - */ -#define IR_CONFLICT 0x80 ///< check ip confict - -/** - * @brief Get the destination unreachable message in UDP sending. - * @details When receiving the ICMP (Destination port unreachable) packet, this bit is set as - * When this bit is Destination Information such as IP address and Port number may be checked with the corresponding @ref UIPR & @ref UPORTR. - */ -#define IR_UNREACH 0x40 ///< check destination unreachable - -/** - * @brief Get the PPPoE close message. - * @details When PPPoE is disconnected during PPPoE mode, this bit is set. - */ -#define IR_PPPoE 0x20 ///< get the PPPoE close message - -#define IR_SOCK(sn) (0x01 << sn) ///< check socket interrupt - - -// Sn_MR values -/* Sn_MR Default values */ -/** - * @brief Unused socket - * @details This configures the protocol mode of Socket n. - */ -#define Sn_MR_CLOSE 0x00 ///< unused socket - -/** - * @brief TCP - * @details This configures the protocol mode of Socket n. - */ -#define Sn_MR_TCP 0x01 ///< TCP - -/** - * @brief UDP - * @details This configures the protocol mode of Socket n. - */ -#define Sn_MR_UDP 0x02 ///< UDP -#define Sn_MR_IPRAW 0x03 ///< IP LAYER RAW SOCK - -/** - * @brief MAC LAYER RAW SOCK - * @details This configures the protocol mode of Socket n. - * @note MACRAW mode should be only used in Socket 0. - */ -#define Sn_MR_MACRAW 0x04 ///< MAC LAYER RAW SOCK - -/** - * @brief PPPoE - * @details This configures the protocol mode of Socket n. - * @note PPPoE mode should be only used in Socket 0. - */ -#define Sn_MR_PPPoE 0x05 ///< PPPoE - -/** - * @brief No Delayed Ack(TCP), Multicast flag - * @details 0 : Disable No Delayed ACK option\n - * 1 : Enable No Delayed ACK option\n - * This bit is applied only during TCP mode (P[3:0] = 001).\n - * When this bit is It sends the ACK packet without delay as soon as a Data packet is received from a peer.\n - * When this bit is It sends the ACK packet after waiting for the timeout time configured by \ref _RTR_. - */ -#define Sn_MR_ND 0x20 ///< No Delayed Ack(TCP) flag - -/** - * @brief Support UDP Multicasting - * @details 0 : using IGMP version 2\n - * 1 : using IGMP version 1\n - * This bit is applied only during UDP mode(P[3:0] = 010 and MULTI = '1') - * It configures the version for IGMP messages (Join/Leave/Report). - */ -#define Sn_MR_MC Sn_MR_ND ///< Select IGMP version 1(0) or 2(1) - -/** - * @brief MAC filter enable in @ref Sn_MR_MACRAW mode - * @details 0 : disable MAC Filtering\n - * 1 : enable MAC Filtering\n - * This bit is applied only during MACRAW mode(P[3:0] = 100.\n - * When set as W5100 can only receive broadcasting packet or packet sent to itself. - * When this bit is W5100 can receive all packets on Ethernet. - * If user wants to implement Hybrid TCP/IP stack, - * it is recommended that this bit is set as for reducing host overhead to process the all received packets. - */ -#define Sn_MR_MF 0x40 ///< Use MAC filter -#define Sn_MR_MFEN Sn_MR_MF - - -/* Sn_MR Default values */ -/** - * @brief Support UDP Multicasting - * @details 0 : disable Multicasting\n - * 1 : enable Multicasting\n - * This bit is applied only during UDP mode(P[3:0] = 010).\n - * To use multicasting, \ref Sn_DIPR & \ref Sn_DPORT should be respectively configured with the multicast group IP address & port number - * before Socket n is opened by OPEN command of \ref Sn_CR. - */ -#define Sn_MR_MULTI 0x80 ///< support multicating - -/* Sn_CR values */ -/** - * @brief Initialize or open socket - * @details Socket n is initialized and opened according to the protocol selected in Sn_MR(P3:P0). - * The table below shows the value of \ref Sn_SR corresponding to \ref Sn_MR.\n - * - * - * - * - * - * - * - * - *
\b Sn_MR (P[3:0]) \b Sn_SR
Sn_MR_CLOSE (000) --
Sn_MR_TCP (001) SOCK_INIT (0x13)
Sn_MR_UDP (010) SOCK_UDP (0x22)
S0_MR_IPRAW (011) SOCK_IPRAW (0x32)
S0_MR_MACRAW (100) SOCK_MACRAW (0x42)
S0_MR_PPPoE (101) SOCK_PPPoE (0x5F)
- */ -#define Sn_CR_OPEN 0x01 ///< initialize or open socket - -/** - * @brief Wait connection request in TCP mode(Server mode) - * @details This is valid only in TCP mode (Sn_MR(P3:P0) = \ref Sn_MR_TCP).// - * In this mode, Socket n operates as a 'TCP server' and waits for connection-request (SYN packet) from any 'TCP client'.// - * The \ref Sn_SR changes the state from SOCK_INIT to SOCKET_LISTEN.// - * When a 'TCP client' connection request is successfully established, - * the \ref Sn_SR changes from SOCK_LISTEN to SOCK_ESTABLISHED and the Sn_IR(0) becomes - * But when a 'TCP client' connection request is failed, Sn_IR(3) becomes and the status of \ref Sn_SR changes to SOCK_CLOSED. - */ -#define Sn_CR_LISTEN 0x02 ///< wait connection request in tcp mode(Server mode) - -/** - * @brief Send connection request in TCP mode(Client mode) - * @details To connect, a connect-request (SYN packet) is sent to TCP serverconfigured by \ref Sn_DIPR & Sn_DPORT(destination address & port). - * If the connect-request is successful, the \ref Sn_SR is changed to \ref SOCK_ESTABLISHED and the Sn_IR(0) becomes \n\n - * The connect-request fails in the following three cases.\n - * 1. When a @b ARPTO occurs (\ref Sn_IR[3] = '1') because destination hardware address is not acquired through the ARP-process.\n - * 2. When a @b SYN/ACK packet is not received and @b TCPTO (Sn_IR(3) ='1')\n - * 3. When a @b RST packet is received instead of a @b SYN/ACK packet. In these cases, \ref Sn_SR is changed to \ref SOCK_CLOSED. - * @note This is valid only in TCP mode and operates when Socket n acts as TCP client - */ -#define Sn_CR_CONNECT 0x04 ///< send connection request in tcp mode(Client mode) - -/** - * @brief Send closing request in TCP mode - * @details Regardless of TCP serveror TCP client the DISCON command processes the disconnect-process (Active closeor Passive close.\n - * @par Active close - * it transmits disconnect-request(FIN packet) to the connected peer\n - * @par Passive close - * When FIN packet is received from peer, a FIN packet is replied back to the peer.\n - * @details When the disconnect-process is successful (that is, FIN/ACK packet is received successfully), \ref Sn_SR is changed to \ref SOCK_CLOSED.\n - * Otherwise, TCPTO occurs (Sn_IR(3)='1') and then \ref Sn_SR is changed to \ref SOCK_CLOSED. - * @note Valid only in TCP mode. - */ -#define Sn_CR_DISCON 0x08 ///< send closing reqeuset in tcp mode - -/** - * @brief Close socket - * @details Sn_SR is changed to \ref SOCK_CLOSED. - */ -#define Sn_CR_CLOSE 0x10 - -/** - * @brief Update TX buffer pointer and send data - * @details SEND transmits all the data in the Socket n TX buffer.\n - * For more details, please refer to Socket n TX Free Size Register (\ref Sn_TX_FSR), Socket n, - * TX Write Pointer Register(\ref Sn_TX_WR), and Socket n TX Read Pointer Register(\ref Sn_TX_RD). - */ -#define Sn_CR_SEND 0x20 - -/** - * @brief Send data with MAC address, so without ARP process - * @details The basic operation is same as SEND.\n - * Normally SEND transmits data after destination hardware address is acquired by the automatic ARP-process(Address Resolution Protocol).\n - * But SEND_MAC transmits data without the automatic ARP-process.\n - * In this case, the destination hardware address is acquired from \ref Sn_DHAR configured by host, instead of APR-process. - * @note Valid only in UDP mode. - */ -#define Sn_CR_SEND_MAC 0x21 - -/** - * @brief Send keep alive message - * @details It checks the connection status by sending 1byte keep-alive packet.\n - * If the peer can not respond to the keep-alive packet during timeout time, the connection is terminated and the timeout interrupt will occur. - * @note Valid only in TCP mode. - */ -#define Sn_CR_SEND_KEEP 0x22 - -/** - * @brief Update RX buffer pointer and receive data - * @details RECV completes the processing of the received data in Socket n RX Buffer by using a RX read pointer register (\ref Sn_RX_RD).\n - * For more details, refer to Socket n RX Received Size Register (\ref Sn_RX_RSR), Socket n RX Write Pointer Register (\ref Sn_RX_WR), - * and Socket n RX Read Pointer Register (\ref Sn_RX_RD). - */ -#define Sn_CR_RECV 0x40 - -/** - * @brief PPPoE connection - * @details PPPoE connection begins by transmitting PPPoE discovery packet - */ -#define Sn_CR_PCON 0x23 - -/** - * @brief Closes PPPoE connection - * @details Closes PPPoE connection - */ -#define Sn_CR_PDISCON 0x24 - -/** - * @brief REQ message transmission - * @details In each phase, it transmits REQ message. - */ -#define Sn_CR_PCR 0x25 - -/** - * @brief NAK massage transmission - * @details In each phase, it transmits NAK message. - */ -#define Sn_CR_PCN 0x26 - -/** - * @brief REJECT message transmission - * @details In each phase, it transmits REJECT message. - */ -#define Sn_CR_PCJ 0x27 - -/* Sn_IR values */ -/** - * @brief PPP Receive Interrupt - * @details PPP Receive Interrupts when the option which is not supported is received. - */ -#define Sn_IR_PRECV 0x80 - -/** - * @brief PPP Fail Interrupt - * @details PPP Fail Interrupts when PAP Authentication is failed. - */ -#define Sn_IR_PFAIL 0x40 - -/** - * @brief PPP Next Phase Interrupt - * @details PPP Next Phase Interrupts when the phase is changed during ADSL connection process. - */ -#define Sn_IR_PNEXT 0x20 - -/** - * @brief SEND_OK Interrupt - * @details This is issued when SEND command is completed. - */ -#define Sn_IR_SENDOK 0x10 ///< complete sending - -/** - * @brief TIMEOUT Interrupt - * @details This is issued when ARPTO or TCPTO occurs. - */ -#define Sn_IR_TIMEOUT 0x08 ///< assert timeout - -/** - * @brief RECV Interrupt - * @details This is issued whenever data is received from a peer. - */ -#define Sn_IR_RECV 0x04 - -/** - * @brief DISCON Interrupt - * @details This is issued when FIN or FIN/ACK packet is received from a peer. - */ -#define Sn_IR_DISCON 0x02 - -/** - * @brief CON Interrupt - * @details This is issued one time when the connection with peer is successful and then \ref Sn_SR is changed to \ref SOCK_ESTABLISHED. - */ -#define Sn_IR_CON 0x01 - -/* Sn_SR values */ -/** - * @brief Closed - * @details This indicates that Socket n is released.\n - * When DICON, CLOSE command is ordered, or when a timeout occurs, it is changed to \ref SOCK_CLOSED regardless of previous status. - */ -#define SOCK_CLOSED 0x00 ///< closed - -/** - * @brief Initiate state - * @details This indicates Socket n is opened with TCP mode.\n - * It is changed to \ref SOCK_INIT when Sn_MR(P[3:0]) = 001)and OPEN command is ordered.\n - * After \ref SOCK_INIT, user can use LISTEN /CONNECT command. - */ -#define SOCK_INIT 0x13 ///< init state - -/** - * @brief Listen state - * @details This indicates Socket n is operating as TCP servermode and waiting for connection-request (SYN packet) from a peer (TCP client).\n - * It will change to \ref SOCK_ESTABLISHED when the connection-request is successfully accepted.\n - * Otherwise it will change to \ref SOCK_CLOSED after TCPTO occurred (Sn_IR(TIMEOUT) = '1'). - */ -#define SOCK_LISTEN 0x14 - -/** - * @brief Connection state - * @details This indicates Socket n sent the connect-request packet (SYN packet) to a peer.\n - * It is temporarily shown when \ref Sn_SR is changed from \ref SOCK_INIT to \ref SOCK_ESTABLISHED by CONNECT command.\n - * If connect-accept(SYN/ACK packet) is received from the peer at SOCK_SYNSENT, it changes to \ref SOCK_ESTABLISHED.\n - * Otherwise, it changes to \ref SOCK_CLOSED after TCPTO (\ref Sn_IR[TIMEOUT] = '1') is occurred. - */ -#define SOCK_SYNSENT 0x15 - -/** - * @brief Connection state - * @details It indicates Socket n successfully received the connect-request packet (SYN packet) from a peer.\n - * If socket n sends the response (SYN/ACK packet) to the peer successfully, it changes to \ref SOCK_ESTABLISHED. \n - * If not, it changes to \ref SOCK_CLOSED after timeout occurs (\ref Sn_IR[TIMEOUT] = '1'). - */ -#define SOCK_SYNRECV 0x16 - -/** - * @brief Success to connect - * @details This indicates the status of the connection of Socket n.\n - * It changes to \ref SOCK_ESTABLISHED when the TCP SERVERprocessed the SYN packet from the TCP CLIENTduring \ref SOCK_LISTEN, or - * when the CONNECT command is successful.\n - * During \ref SOCK_ESTABLISHED, DATA packet can be transferred using SEND or RECV command. - */ -#define SOCK_ESTABLISHED 0x17 - -/** - * @brief Closing state - * @details These indicate Socket n is closing.\n - * These are shown in disconnect-process such as active-close and passive-close.\n - * When Disconnect-process is successfully completed, or when timeout occurs, these change to \ref SOCK_CLOSED. - */ -#define SOCK_FIN_WAIT 0x18 - -/** - * @brief Closing state - * @details These indicate Socket n is closing.\n - * These are shown in disconnect-process such as active-close and passive-close.\n - * When Disconnect-process is successfully completed, or when timeout occurs, these change to \ref SOCK_CLOSED. - */ -#define SOCK_CLOSING 0x1A - -/** - * @brief Closing state - * @details These indicate Socket n is closing.\n - * These are shown in disconnect-process such as active-close and passive-close.\n - * When Disconnect-process is successfully completed, or when timeout occurs, these change to \ref SOCK_CLOSED. - */ -#define SOCK_TIME_WAIT 0x1B - -/** - * @brief Closing state - * @details This indicates Socket n received the disconnect-request (FIN packet) from the connected peer.\n - * This is half-closing status, and data can be transferred.\n - * For full-closing, DISCON command is used. But For just-closing, @ref Sn_CR_CLOSE command is used. - */ -#define SOCK_CLOSE_WAIT 0x1C - -/** - * @brief Closing state - * @details This indicates Socket n is waiting for the response (FIN/ACK packet) to the disconnect-request (FIN packet) by passive-close.\n - * It changes to \ref SOCK_CLOSED when Socket n received the response successfully, or when timeout occurs (\ref Sn_IR[TIMEOUT] = '1'). - */ -#define SOCK_LAST_ACK 0x1D - -/** - * @brief UDP socket - * @details This indicates Socket n is opened in UDP mode(Sn_MR(P[3:0]) = 010).\n - * It changes to SOCK_UDP when Sn_MR(P[3:0]) = 010 and @ref Sn_CR_OPEN command is ordered.\n - * Unlike TCP mode, data can be transfered without the connection-process. - */ -#define SOCK_UDP 0x22 ///< udp socket - -/** - * @brief IP raw mode socket - * @details TThe socket is opened in IPRAW mode. The SOCKET status is change to SOCK_IPRAW when @ref Sn_MR (P3:P0) is - * Sn_MR_IPRAW and @ref Sn_CR_OPEN command is used.\n - * IP Packet can be transferred without a connection similar to the UDP mode. -*/ -#define SOCK_IPRAW 0x32 ///< ip raw mode socket - -/** - * @brief MAC raw mode socket - * @details This indicates Socket 0 is opened in MACRAW mode (@ref Sn_MR(P[3:0]) = '100' and n=0) and is valid only in Socket 0.\n - * It changes to SOCK_MACRAW when @ref Sn_MR(P[3:0]) = '100' and @ref Sn_CR_OPEN command is ordered.\n - * Like UDP mode socket, MACRAW mode Socket 0 can transfer a MAC packet (Ethernet frame) without the connection-process. - */ -#define SOCK_MACRAW 0x42 ///< mac raw mode socket - -/** - * @brief PPPoE mode socket - * @details It is the status that SOCKET0 is open as PPPoE mode. It is changed to SOCK_PPPoE in case of S0_CR=OPEN and S0_MR - * (P3:P0)=S0_MR_PPPoE.\n - * It is temporarily used at the PPPoE -connection. - */ -#define SOCK_PPPOE 0x5F ///< pppoe socket - -// IP PROTOCOL -#define IPPROTO_IP 0 ///< Dummy for IP -#define IPPROTO_ICMP 1 ///< Control message protocol -#define IPPROTO_IGMP 2 ///< Internet group management protocol -#define IPPROTO_GGP 3 ///< GW^2 (deprecated) -#define IPPROTO_TCP 6 ///< TCP -#define IPPROTO_PUP 12 ///< PUP -#define IPPROTO_UDP 17 ///< UDP -#define IPPROTO_IDP 22 ///< XNS idp -#define IPPROTO_ND 77 ///< UNOFFICIAL net disk protocol -#define IPPROTO_RAW 255 ///< Raw IP packet - -/** - * @brief Enter a critical section - * - * @details It is provided to protect your shared code which are executed without distribution. \n \n - * - * In non-OS environment, It can be just implemented by disabling whole interrupt.\n - * In OS environment, You can replace it to critical section api supported by OS. - * - * \sa WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF() - * \sa WIZCHIP_CRITICAL_EXIT() - */ -#define WIZCHIP_CRITICAL_ENTER() WIZCHIP.CRIS._enter() - -#ifdef _exit -#undef _exit -#endif - -/** - * @brief Exit a critical section - * - * @details It is provided to protect your shared code which are executed without distribution. \n\n - * - * In non-OS environment, It can be just implemented by disabling whole interrupt. \n - * In OS environment, You can replace it to critical section api supported by OS. - * - * @sa WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF() - * @sa WIZCHIP_CRITICAL_ENTER() - */ -#define WIZCHIP_CRITICAL_EXIT() WIZCHIP.CRIS._exit() - - - -//////////////////////// -// Basic I/O Function // -//////////////////////// -// -//M20150601 : uint16_t AddrSel --> uint32_t AddrSel -// -/** - * @ingroup Basic_IO_function_W5100 - * @brief It reads 1 byte value from a register. - * @param AddrSel Register address - * @return The value of register - */ -uint8_t WIZCHIP_READ (uint32_t AddrSel); - -/** - * @ingroup Basic_IO_function_W5100 - * @brief It writes 1 byte value to a register. - * @param AddrSel Register address - * @param wb Write data - * @return void - */ -void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb ); - -/** - * @ingroup Basic_IO_function_W5100 - * @brief It reads sequence data from registers. - * @param AddrSel Register address - * @param pBuf Pointer buffer to read data - * @param len Data length - */ -void WIZCHIP_READ_BUF (uint32_t AddrSel, uint8_t* pBuf, uint16_t len); - -/** - * @ingroup Basic_IO_function_W5100 - * @brief It writes sequence data to registers. - * @param AddrSel Register address - * @param pBuf Pointer buffer to write data - * @param len Data length - */ -void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len); - - -///////////////////////////////// -// Common Register IO function // -///////////////////////////////// - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Set Mode Register - * @param (uint8_t)mr The value to be set. - * @sa getMR() - */ -#if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_) - #define setMR(mr) WIZCHIP_WRITE(MR,mr) -#else - #define setMR(mr) (*((uint8_t*)MR) = mr) -#endif - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Get @ref MR. - * @return uint8_t. The value of Mode register. - * @sa setMR() - */ -#if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_) - #define getMR() WIZCHIP_READ(MR) -#else - #define getMR() (*(uint8_t*)MR) -#endif - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Set @ref GAR. - * @param (uint8_t*)gar Pointer variable to set gateway IP address. It should be allocated 4 bytes. - * @sa getGAR() - */ -#define setGAR(gar) \ - WIZCHIP_WRITE_BUF(GAR,gar,4) - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Get @ref GAR. - * @param (uint8_t*)gar Pointer variable to get gateway IP address. It should be allocated 4 bytes. - * @sa setGAR() - */ -#define getGAR(gar) \ - WIZCHIP_READ_BUF(GAR,gar,4) - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Set @ref SUBR. - * @param (uint8_t*)subr Pointer variable to set subnet mask address. It should be allocated 4 bytes. - * @note If subr is null pointer, set the backup subnet to SUBR. \n - * If subr is 0.0.0.0, back up SUBR and clear it. \n - * Otherwize, set subr to SUBR - * @sa getSUBR() - */ -#define setSUBR(subr) \ - WIZCHIP_WRITE_BUF(SUBR,subr,4) - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Get @ref SUBR. - * @param (uint8_t*)subr Pointer variable to get subnet mask address. It should be allocated 4 bytes. - * @sa setSUBR() - */ -#define getSUBR(subr) \ - WIZCHIP_READ_BUF(SUBR, subr, 4) - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Set @ref SHAR. - * @param (uint8_t*)shar Pointer variable to set local MAC address. It should be allocated 6 bytes. - * @sa getSHAR() - */ -#define setSHAR(shar) \ - WIZCHIP_WRITE_BUF(SHAR, shar, 6) - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Get @ref SHAR. - * @param (uint8_t*)shar Pointer variable to get local MAC address. It should be allocated 6 bytes. - * @sa setSHAR() - */ -#define getSHAR(shar) \ - WIZCHIP_READ_BUF(SHAR, shar, 6) - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Set @ref SIPR. - * @param (uint8_t*)sipr Pointer variable to set local IP address. It should be allocated 4 bytes. - * @sa getSIPR() -*/ -#define setSIPR(sipr) \ - WIZCHIP_WRITE_BUF(SIPR, sipr, 4) - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Get @ref SIPR. - * @param (uint8_t*)sipr Pointer variable to get local IP address. It should be allocated 4 bytes. - * @sa setSIPR() - */ -#define getSIPR(sipr) \ - WIZCHIP_READ_BUF(SIPR, sipr, 4) - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Set \ref IR register - * @param (uint8_t)ir Value to set \ref IR register. - * @sa getIR() - */ -#define setIR(ir) \ - WIZCHIP_WRITE(IR, (ir & 0xA0)) -/** - * @ingroup Common_register_access_function_W5100 - * @brief Get \ref IR register - * @return uint8_t. Value of \ref IR register. - * @sa setIR() - */ -#define getIR() \ - (WIZCHIP_READ(IR) & 0xA0) - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Set \ref _IMR_ register - * @param (uint8_t)imr Value to set @ref _IMR_ register. - * @sa getIMR() - */ -#define setIMR(imr) \ - WIZCHIP_WRITE(_IMR_, imr) - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Get \ref _IMR_ register - * @return uint8_t. Value of @ref _IMR_ register. - * @sa setIMR() - */ -#define getIMR() \ - WIZCHIP_READ(_IMR_) - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Set \ref _RTR_ register - * @param (uint16_t)rtr Value to set @ref _RTR_ register. - * @sa getRTR() - */ -#define setRTR(rtr) {\ - WIZCHIP_WRITE(_RTR_, (uint8_t)(rtr >> 8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_RTR_,1), (uint8_t) rtr); \ - } - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Get \ref _RTR_ register - * @return uint16_t. Value of @ref _RTR_ register. - * @sa setRTR() - */ -#define getRTR() \ - (((uint16_t)WIZCHIP_READ(_RTR_) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_RTR_,1))) - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Set \ref _RCR_ register - * @param (uint8_t)rcr Value to set @ref _RCR_ register. - * @sa getRCR() - */ -#define setRCR(rcr) \ - WIZCHIP_WRITE(_RCR_, rcr) - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Get \ref _RCR_ register - * @return uint8_t. Value of @ref _RCR_ register. - * @sa setRCR() - */ -#define getRCR() \ - WIZCHIP_READ(_RCR_) - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Get \ref RMSR register - * @sa getRMSR() - */ -#define setRMSR(rmsr) \ - WIZCHIP_WRITE(RMSR) // Receicve Memory Size - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Get \ref RMSR register - * @return uint8_t. Value of @ref RMSR register. - * @sa setRMSR() - */ - #define getRMSR() \ - WIZCHIP_READ() // Receicve Memory Size - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Get \ref TMSR register - * @sa getTMSR() - */ -#define setTMSR(rmsr) \ - WIZCHIP_WRITE(TMSR) // Receicve Memory Size - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Get \ref TMSR register - * @return uint8_t. Value of @ref TMSR register. - * @sa setTMSR() - */ - - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Get \ref PATR register - * @return uint16_t. Value to set \ref PATR register - */ -#define getPATR() \ - (((uint16_t)WIZCHIP_READ(PATR) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(PATR,1))) - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Get \ref PPPALGO register - * @return uint8_t. Value to set \ref PPPALGO register - */ -#define getPPPALGO() \ - WIZCHIP_READ(PPPALGO) - - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Set \ref PTIMER register - * @param (uint8_t)ptimer Value to set \ref PTIMER register. - * @sa getPTIMER() - */ -#define setPTIMER(ptimer) \ - WIZCHIP_WRITE(PTIMER, ptimer) - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Get \ref PTIMER register - * @return uint8_t. Value of @ref PTIMER register. - * @sa setPTIMER() - */ -#define getPTIMER() \ - WIZCHIP_READ(PTIMER) - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Set \ref PMAGIC register - * @param (uint8_t)pmagic Value to set @ref PMAGIC register. - * @sa getPMAGIC() - */ -#define setPMAGIC(pmagic) \ - WIZCHIP_WRITE(PMAGIC, pmagic) - -/** - * @ingroup Common_register_access_function_W5100 - * @brief Get \ref PMAGIC register - * @return uint8_t. Value of @ref PMAGIC register. - * @sa setPMAGIC() - */ -#define getPMAGIC() \ - WIZCHIP_READ(PMAGIC) - -/////////////////////////////////// -// Socket N register I/O function // -/////////////////////////////////// -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Set @ref Sn_MR register - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ expect bit 4. - * @param mr Value to set @ref Sn_MR - * @sa getSn_MR() - */ -#define setSn_MR(sn, mr) \ - WIZCHIP_WRITE(Sn_MR(sn),mr) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get @ref Sn_MR register - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ expect bit 4. - * @return Value of @ref Sn_MR. - * @sa setSn_MR() - */ -#define getSn_MR(sn) \ - WIZCHIP_READ(Sn_MR(sn)) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Set @ref Sn_CR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t)cr Value to set @ref Sn_CR - * @sa getSn_CR() - */ -#define setSn_CR(sn, cr) \ - WIZCHIP_WRITE(Sn_CR(sn), cr) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get @ref Sn_CR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of @ref Sn_CR. - * @sa setSn_CR() - */ -#define getSn_CR(sn) \ - WIZCHIP_READ(Sn_CR(sn)) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Set @ref Sn_IR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t)ir Value to set @ref Sn_IR - * @sa getSn_IR() - */ -#define setSn_IR(sn, ir) \ - WIZCHIP_WRITE(Sn_IR(sn), ir) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get @ref Sn_IR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of @ref Sn_IR. - * @sa setSn_IR() - */ -#define getSn_IR(sn) \ - WIZCHIP_READ(Sn_IR(sn)) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get @ref Sn_SR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of @ref Sn_SR. - */ -#define getSn_SR(sn) \ - WIZCHIP_READ(Sn_SR(sn)) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Set @ref Sn_PORT register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint16_t)port Value to set @ref Sn_PORT. - * @sa getSn_PORT() - */ -#define setSn_PORT(sn, port) { \ - WIZCHIP_WRITE(Sn_PORT(sn), (uint8_t)(port >> 8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_PORT(sn),1), (uint8_t) port); \ - } - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get @ref Sn_PORT register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_PORT. - * @sa setSn_PORT() - */ -#define getSn_PORT(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_PORT(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_PORT(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Set @ref Sn_DHAR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t*)dhar Pointer variable to set socket n destination hardware address. It should be allocated 6 bytes. - * @sa getSn_DHAR() - */ -#define setSn_DHAR(sn, dhar) \ - WIZCHIP_WRITE_BUF(Sn_DHAR(sn), dhar, 6) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get @ref Sn_DHAR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t*)dhar Pointer variable to get socket n destination hardware address. It should be allocated 6 bytes. - * @sa setSn_DHAR() - */ -#define getSn_DHAR(sn, dhar) \ - WIZCHIP_READ_BUF(Sn_DHAR(sn), dhar, 6) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Set @ref Sn_DIPR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t*)dipr Pointer variable to set socket n destination IP address. It should be allocated 4 bytes. - * @sa getSn_DIPR() - */ -#define setSn_DIPR(sn, dipr) \ - WIZCHIP_WRITE_BUF(Sn_DIPR(sn), dipr, 4) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get @ref Sn_DIPR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t*)dipr Pointer variable to get socket n destination IP address. It should be allocated 4 bytes. - * @sa SetSn_DIPR() - */ -#define getSn_DIPR(sn, dipr) \ - WIZCHIP_READ_BUF(Sn_DIPR(sn), dipr, 4) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Set @ref Sn_DPORT register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint16_t)dport Value to set @ref Sn_DPORT - * @sa getSn_DPORT() - */ -#define setSn_DPORT(sn, dport) { \ - WIZCHIP_WRITE(Sn_DPORT(sn), (uint8_t) (dport>>8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_DPORT(sn),1), (uint8_t) dport); \ - } - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get @ref Sn_DPORT register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_DPORT. - * @sa setSn_DPORT() - */ -#define getSn_DPORT(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_DPORT(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_DPORT(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Set @ref Sn_MSSR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint16_t)mss Value to set @ref Sn_MSSR - * @sa setSn_MSSR() - */ -#define setSn_MSSR(sn, mss) { \ - WIZCHIP_WRITE(Sn_MSSR(sn), (uint8_t)(mss>>8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_MSSR(sn),1), (uint8_t) mss); \ - } - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get @ref Sn_MSSR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_MSSR. - * @sa setSn_MSSR() - */ -#define getSn_MSSR(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_MSSR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_MSSR(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Set @ref Sn_PROTO register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t)proto Value to set \ref Sn_PROTO - * @sa getSn_PROTO() - */ -#define setSn_PROTO(sn, proto) \ - WIZCHIP_WRITE(Sn_TOS(sn), tos) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get @ref Sn_PROTO register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of @ref Sn_PROTO. - * @sa setSn_PROTO() - */ -#define getSn_PROTO(sn) \ - WIZCHIP_READ(Sn_TOS(sn)) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Set @ref Sn_TOS register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t)tos Value to set @ref Sn_TOS - * @sa getSn_TOS() - */ -#define setSn_TOS(sn, tos) \ - WIZCHIP_WRITE(Sn_TOS(sn), tos) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get @ref Sn_TOS register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ . - * @return uint8_t. Value of Sn_TOS. - * @sa setSn_TOS() - */ -#define getSn_TOS(sn) \ - WIZCHIP_READ(Sn_TOS(sn)) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Set @ref Sn_TTL register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ . - * @param (uint8_t)ttl Value to set @ref Sn_TTL - * @sa getSn_TTL() - */ -#define setSn_TTL(sn, ttl) \ - WIZCHIP_WRITE(Sn_TTL(sn), ttl) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get @ref Sn_TTL register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ . - * @return uint8_t. Value of @ref Sn_TTL. - * @sa setSn_TTL() - */ -#define getSn_TTL(sn) \ - WIZCHIP_READ(Sn_TTL(sn)) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Set @ref Sn_RXMEM_SIZE register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ . - * @param (uint8_t)rxmemsize Value to set \ref Sn_RXMEM_SIZE - * @sa getSn_RXMEM_SIZE() - */ -#define setSn_RXMEM_SIZE(sn, rxmemsize) \ - WIZCHIP_WRITE(RMSR, (WIZCHIP_READ(RMSR) & ~(0x03 << (2*sn))) | (rxmemsize << (2*sn))) -#define setSn_RXBUF_SIZE(sn,rxmemsize) setSn_RXMEM_SIZE(sn,rxmemsize) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get @ref Sn_RXMEM_SIZE register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of @ref Sn_RXMEM. - * @sa setSn_RXMEM_SIZE() - */ -#define getSn_RXMEM_SIZE(sn) \ - ((WIZCHIP_READ(RMSR) & (0x03 << (2*sn))) >> (2*sn)) -#define getSn_RXBUF_SIZE(sn) getSn_RXMEM_SIZE(sn) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Set @ref Sn_TXMEM_SIZE register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t)txmemsize Value to set \ref Sn_TXMEM_SIZE - * @sa getSn_TXMEM_SIZE() - */ -#define setSn_TXMEM_SIZE(sn, txmemsize) \ - WIZCHIP_WRITE(TMSR, (WIZCHIP_READ(TMSR) & ~(0x03 << (2*sn))) | (txmemsize << (2*sn))) -#define setSn_TXBUF_SIZE(sn, txmemsize) setSn_TXMEM_SIZE(sn,txmemsize) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get @ref Sn_TXMEM_SIZE register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of @ref Sn_TXMEM_SIZE. - * @sa setSn_TXMEM_SIZE() - */ -#define getSn_TXMEM_SIZE(sn) \ - ((WIZCHIP_READ(TMSR) & (0x03 << (2*sn))) >> (2*sn)) -#define getSn_TXBUF_SIZE(sn) getSn_TXMEM_SIZE(sn) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get @ref Sn_TX_FSR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_TX_FSR. - */ -uint16_t getSn_TX_FSR(uint8_t sn); - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get @ref Sn_TX_RD register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_TX_RD. - */ -#define getSn_TX_RD(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_TX_RD(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_RD(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Set @ref Sn_TX_WR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint16_t)txwr Value to set @ref Sn_TX_WR - * @sa GetSn_TX_WR() - */ -#define setSn_TX_WR(sn, txwr) { \ - WIZCHIP_WRITE(Sn_TX_WR(sn), (uint8_t)(txwr>>8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_TX_WR(sn),1), (uint8_t) txwr); \ - } - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get @ref Sn_TX_WR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_TX_WR. - * @sa setSn_TX_WR() - */ -#define getSn_TX_WR(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_TX_WR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_WR(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get @ref Sn_RX_RSR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_RX_RSR. - */ -uint16_t getSn_RX_RSR(uint8_t sn); - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Set @ref Sn_RX_RD register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint16_t)rxrd Value to set @ref Sn_RX_RD - * @sa getSn_RX_RD() - */ -#define setSn_RX_RD(sn, rxrd) { \ - WIZCHIP_WRITE(Sn_RX_RD(sn), (uint8_t)(rxrd>>8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_RX_RD(sn),1), (uint8_t) rxrd); \ - } - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get @ref Sn_RX_RD register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @regurn uint16_t. Value of @ref Sn_RX_RD. - * @sa setSn_RX_RD() - */ -#define getSn_RX_RD(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_RX_RD(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RD(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Set @ref Sn_RX_WR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint16_t)rxwr Value to set \ref Sn_RX_WR - * @sa getSn_RX_WR() - */ -#define setSn_RX_WR(sn, rxwr) { \ - WIZCHIP_WRITE(Sn_RX_WR(sn), (uint8_t)(rxwr>>8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_RX_WR(sn),1), (uint8_t) rxwr); \ - } - - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get @ref Sn_RX_WR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_RX_WR. - */ -#define getSn_RX_WR(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_RX_WR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_WR(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Set @ref Sn_FRAG register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint16_t)frag Value to set \ref Sn_FRAG - * @sa getSn_FRAG() - */ -#define setSn_FRAG(sn, frag) { \ - WIZCHIP_WRITE(Sn_FRAG(sn), (uint8_t)(frag >>8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_FRAG(sn),1), (uint8_t) frag); \ - } - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get @ref Sn_FRAG register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_FRAG. - * @sa setSn_FRAG() - */ -#define getSn_FRAG(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_FRAG(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_FRAG(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get the max RX buffer size of socket sn - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Max buffer size - */ -#define getSn_RxMAX(sn) \ - ((uint16_t)(1 << getSn_RXMEM_SIZE(sn)) << 10) - - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get the max TX buffer size of socket sn - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Max buffer size - */ -#define getSn_TxMAX(sn) \ - ((uint16_t)(1 << getSn_TXMEM_SIZE(sn)) << 10) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get the mask of socket sn RX buffer. - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Mask value - */ -#define getSn_RxMASK(sn) \ - (getSn_RxMAX(sn) - 1) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get the mask of socket sn TX buffer - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Mask value - */ -#define getSn_TxMASK(sn) \ - (getSn_TxMAX(sn) - 1) - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get the base address of socket sn RX buffer. - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of Socket n RX buffer base address. - */ -uint32_t getSn_RxBASE(uint8_t sn); - -/** - * @ingroup Socket_register_access_function_W5100 - * @brief Get the base address of socket sn TX buffer. - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of Socket n TX buffer base address. - */ -uint32_t getSn_TxBASE(uint8_t sn); - -///////////////////////////////////// -// Sn_TXBUF & Sn_RXBUF IO function // -///////////////////////////////////// -/** - * @ingroup Basic_IO_function_W5100 - * @brief It copies data to internal TX memory - * - * @details This function reads the Tx write pointer register and after that, - * it copies the wizdata(pointer buffer) of the length of len(variable) bytes to internal TX memory - * and updates the Tx write pointer register. - * This function is being called by send() and sendto() function also. - * - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param wizdata Pointer buffer to write data - * @param len Data length - * @sa wiz_recv_data() - */ -void wiz_send_data(uint8_t sn, uint8_t *wizdata, uint16_t len); - -/** - * @ingroup Basic_IO_function_W5100 - * @brief It copies data to your buffer from internal RX memory - * - * @details This function read the Rx read pointer register and after that, - * it copies the received data from internal RX memory - * to wizdata(pointer variable) of the length of len(variable) bytes. - * This function is being called by recv() also. - * - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param wizdata Pointer buffer to read data - * @param len Data length - * @sa wiz_send_data() - */ -void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint16_t len); - -/** - * @ingroup Basic_IO_function_W5100 - * @brief It discard the received data in RX memory. - * @details It discards the data of the length of len(variable) bytes in internal RX memory. - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param len Data length - */ -void wiz_recv_ignore(uint8_t sn, uint16_t len); - -/// @cond DOXY_APPLY_CODE -#endif -/// @endcond - -#ifdef __cplusplus -} -#endif - -#endif //_W5100_H_ - - - diff --git a/lib/ioLibrary_Driver/W5100S/w5100s.c b/lib/ioLibrary_Driver/W5100S/w5100s.c deleted file mode 100644 index 8583eb1..0000000 --- a/lib/ioLibrary_Driver/W5100S/w5100s.c +++ /dev/null @@ -1,514 +0,0 @@ -//***************************************************************************** -// -//! \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 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 ) -{ - uint8_t spi_data[4]; - - WIZCHIP_CRITICAL_ENTER(); - WIZCHIP.CS._select(); - -#if( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_)) - if(!WIZCHIP.IF.SPI._write_burst) // byte operation - { - 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) - } - else // burst operation - { - spi_data[0] = 0xF0; - spi_data[1] = (AddrSel & 0xFF00) >> 8; - spi_data[2] = (AddrSel & 0x00FF) >> 0; - spi_data[3] = wb; - WIZCHIP.IF.SPI._write_burst(spi_data, 4); - } -#elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_5500_) ) - if(!WIZCHIP.IF.SPI._write_burst) // byte operation - { - 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) - } - else // burst operation - { - spi_data[0] = (AddrSel & 0xFF00) >> 8; - spi_data[1] = (AddrSel & 0x00FF) >> 0; - spi_data[2] = 0xF0; - spi_data[3] = wb; - WIZCHIP.IF.SPI._write_burst(spi_data, 4); - - } -#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; - uint8_t spi_data[3]; - WIZCHIP_CRITICAL_ENTER(); - WIZCHIP.CS._select(); - -#if( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_)) - if(!WIZCHIP.IF.SPI._read_burst || !WIZCHIP.IF.SPI._write_burst) // byte operation - { - WIZCHIP.IF.SPI._write_byte(0x0F); - WIZCHIP.IF.SPI._write_byte((AddrSel & 0xFF00) >> 8); - WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF) >> 0); - } - else - { - spi_data[0] = 0x0F; - spi_data[1] = (AddrSel & 0xFF00) >> 8; - spi_data[2] = (AddrSel & 0x00FF) >> 0; - WIZCHIP.IF.SPI._write_burst(spi_data, 3); - } - ret = WIZCHIP.IF.SPI._read_byte(); -#elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_5500_) ) - if(!WIZCHIP.IF.SPI._read_burst || !WIZCHIP.IF.SPI._write_burst) // burst operation - { - WIZCHIP.IF.SPI._write_byte((AddrSel & 0xFF00) >> 8); - WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF) >> 0); - WIZCHIP.IF.SPI._write_byte(0x0F); - } - else - { - spi_data[0] = (AddrSel & 0xFF00) >> 8; - spi_data[1] = (AddrSel & 0x00FF) >> 0; - spi_data[2] = 0x0F - WIZCHIP.IF.SPI._write_burst(spi_data, 3); - } - 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) -{ - uint8_t spi_data[3]; - uint16_t i = 0; - - WIZCHIP_CRITICAL_ENTER(); - WIZCHIP.CS._select(); //M20150601 : Moved here. - -#if((_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_)) - - if(!WIZCHIP.IF.SPI._write_burst) // byte operation - { - 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) - } - } - else // burst operation - { - spi_data[0] = 0xF0; - spi_data[1] = (((uint16_t)(AddrSel+i)) & 0xFF00) >> 8; - spi_data[2] = (((uint16_t)(AddrSel+i)) & 0x00FF) >> 0; - WIZCHIP.IF.SPI._write_burst(spi_data, 3); - WIZCHIP.IF.SPI._write_burst(pBuf, len); - } - -#elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_5500_) ) - if(!WIZCHIP.IF.SPI._write_burst) // byte operation - { - 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) - } - } - else // burst operation - { - spi_data[0] = (((uint16_t)(AddrSel+i)) & 0xFF00) >> 8; - spi_data[1] = (((uint16_t)(AddrSel+i)) & 0x00FF) >> 0; - spi_data[2] = 0xF0; - WIZCHIP.IF.SPI._write_burst(spi_data, 3); - WIZCHIP.IF.SPI._write_burst(pBuf, len); - } -#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) -{ - uint8_t spi_data[3]; - uint16_t i = 0; - WIZCHIP_CRITICAL_ENTER(); - WIZCHIP.CS._select(); //M20150601 : Moved here. - -#if( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_) ) - if(!WIZCHIP.IF.SPI._read_burst || !WIZCHIP.IF.SPI._write_burst) // byte operation - { - 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(); - } - } - else // burst operation - { - spi_data[0] = 0x0F; - spi_data[1] = (uint16_t)((AddrSel+i) & 0xFF00) >> 8; - spi_data[2] = (uint16_t)((AddrSel+i) & 0x00FF) >> 0; - WIZCHIP.IF.SPI._write_burst(spi_data, 3); - WIZCHIP.IF.SPI._read_burst(pBuf, len); - - } -#elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_5500_) ) - if(!WIZCHIP.IF.SPI._read_burst || !WIZCHIP.IF.SPI._write_burst) // byte operation - { - 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(); - } - } - else // burst operation - { - spi_data[0] = (uint16_t)((AddrSel+i) & 0xFF00) >> 8; - spi_data[1] = (uint16_t)((AddrSel+i) & 0x00FF) >> 0; - spi_data[2] = 0x0F; - WIZCHIP.IF.SPI._write_burst(spi_data, 3); - WIZCHIP.IF.SPI._read_burst(pBuf, len); - } - - -#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 diff --git a/lib/ioLibrary_Driver/W5100S/w5100s.h b/lib/ioLibrary_Driver/W5100S/w5100s.h deleted file mode 100644 index 3daa8b4..0000000 --- a/lib/ioLibrary_Driver/W5100S/w5100s.h +++ /dev/null @@ -1,3322 +0,0 @@ -//* **************************************************************************** -//! \file w5100S.h -//! \brief W5100S HAL Header File. -//! \version 1.0.0 -//! \date 2018/03/29 -//! \par Revision history -//! <2018/03/29> 1st Release -//! \author Peter -//! \copyright -//! -//! 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 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. -// -//***************************************************************************** - - -#ifndef _W5100S_H_ -#define _W5100S_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include "wizchip_conf.h" - -/// \cond DOXY_APPLY_CODE -#if (_WIZCHIP_ == W5100S) -/// \endcond - -#define _WIZCHIP_SN_BASE_ (0x0400) -#define _WIZCHIP_SN_SIZE_ (0x0100) -#define _WIZCHIP_IO_TXBUF_ (0x4000) /* Internal Tx buffer address of the iinchip */ -#define _WIZCHIP_IO_RXBUF_ (0x6000) /* Internal Rx buffer address of the iinchip */ - - -#define WIZCHIP_CREG_BLOCK 0x00 ///< Common register block -#define WIZCHIP_SREG_BLOCK(N) (_WIZCHIP_SN_BASE_+ _WIZCHIP_SN_SIZE_*N) ///< Socket N register block - -#define WIZCHIP_OFFSET_INC(ADDR, N) (ADDR + N) ///< Increase offset address - -#if (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_DIR_) - #define _W5100S_IO_BASE_ _WIZCHIP_IO_BASE_ -#elif (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) - #define IDM_OR ((_WIZCHIP_IO_BASE + 0x0000)) - #define IDM_AR0 ((_WIZCHIP_IO_BASE_ + 0x0001)) - #define IDM_AR1 ((_WIZCHIP_IO_BASE_ + 0x0002)) - #define IDM_DR ((_WIZCHIP_IO_BASE_ + 0x0003)) - #define _W5100S_IO_BASE_ 0x0000 -#elif (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_) - #define _W5100S_IO_BASE_ 0x0000 -#endif - -/////////////////////////////////////// -// Definition For Legacy Chip Driver // -/////////////////////////////////////// -#define IINCHIP_READ(ADDR) WIZCHIP_READ(ADDR) ///< The defined for legacy chip driver -#define IINCHIP_WRITE(ADDR,VAL) WIZCHIP_WRITE(ADDR,VAL) ///< The defined for legacy chip driver -#define IINCHIP_READ_BUF(ADDR,BUF,LEN) WIZCHIP_READ_BUF(ADDR,BUF,LEN) ///< The defined for legacy chip driver -#define IINCHIP_WRITE_BUF(ADDR,BUF,LEN) WIZCHIP_WRITE(ADDR,BUF,LEN) ///< The defined for legacy chip driver - - -//----------- defgroup -------------------------------- - -/** - * @defgroup W5100S W5100S - * @brief WHIZCHIP register defines and I/O functions of @b W5100S. - * - * - @ref WIZCHIP_register_W5100S: @ref Common_register_group_W5100S and @ref Socket_register_group_W5100S - * - @ref WIZCHIP_IO_Functions_W5100S: @ref Basic_IO_function_W5100S, @ref Common_register_access_function_W5100S and @ref Special_function_W5100S - */ - - /** - * @defgroup WIZCHIP_register_W5100S WIZCHIP register - * @ingroup W5100S - * @brief WIZCHIP register defines register group of W5100S . - * - * - \ref Common_register_group_W5100S : Common register group W5100S - * - \ref Socket_register_group_W5100S : \c SOCKET n register group W5100S - */ - - -/** - * @defgroup WIZCHIP_IO_Functions_W5100S WIZCHIP I/O functions - * @ingroup W5100S - * @brief This supports the basic I/O functions for \ref WIZCHIP_register_W5100S. - * - * - Basic I/O function \n - * WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF(), wiz_recv_data(), wiz_recv_ignore(), wiz_send_data() \n\n - * - * - \ref Common_register_group_W5100S access functions \n - * -# @b Mode \n - * getMR(), setMR() - * -# @b Interrupt \n - * getIR(), setIR(), getIMR(), setIMR(), - * -# Network Information \n - * getSHAR(), setSHAR(), getGAR(), setGAR(), getSUBR(), setSUBR(), getSIPR(), setSIPR() - * -# @b Retransmission \n - * getRCR(), setRCR(), getRTR(), setRTR() - * -# @b PPPoE \n - * getPTIMER(), setPTIMER(), getPMAGIC(), getPMAGIC() - * - * - \ref Socket_register_group_W5100S access functions \n - * -# SOCKET control \n - * getSn_MR(), setSn_MR(), getSn_CR(), setSn_CR(), getSn_IR(), setSn_IR() - * -# SOCKET information \n - * getSn_SR(), getSn_DHAR(), setSn_DHAR(), getSn_PORT(), setSn_PORT(), getSn_DIPR(), setSn_DIPR(), getSn_DPORT(), setSn_DPORT() - * getSn_MSSR(), setSn_MSSR() - * -# SOCKET communication \n - * getSn_RXMEM_SIZE(), setSn_RXMEM_SIZE(), getSn_TXMEM_SIZE(), setSn_TXMEM_SIZE() \n - * getSn_TX_RD(), getSn_TX_WR(), setSn_TX_WR() \n - * getSn_RX_RD(), setSn_RX_RD(), getSn_RX_WR() \n - * getSn_TX_FSR(), getSn_RX_RSR() - * -# IP header field \n - * getSn_FRAG(), setSn_FRAG(), getSn_TOS(), setSn_TOS() \n - * getSn_TTL(), setSn_TTL() - */ - -/** - * @defgroup Common_register_group_W5100S Common register - * @ingroup WIZCHIP_register_W5100S - * @brief Common register group\n - * It set the basic for the networking\n - * It set the configuration such as interrupt, network information, ICMP, etc. - * @details - * @sa MR : Mode register. - * @sa GAR, SUBR, SHAR, SIPR - * @sa IR, Sn_IR, _IMR_ : Interrupt. - * @sa _RTR_, _RCR_ : Data retransmission. - * @sa PTIMER, PMAGIC : PPPoE. - */ - - - /** - * @defgroup Socket_register_group_W5100S Socket register - * @ingroup WIZCHIP_register_W5100S - * @brief Socket register group\n - * Socket register configures and control SOCKETn which is necessary to data communication. - * @details - * @sa Sn_MR, Sn_CR, Sn_IR : SOCKETn Control - * @sa Sn_SR, Sn_PORT, Sn_DHAR, Sn_DIPR, Sn_DPORT : SOCKETn Information - * @sa Sn_MSSR, Sn_TOS, Sn_TTL, Sn_FRAGR : Internet protocol. - * @sa Sn_RXMEM_SIZE, Sn_TXMEM_SIZE, Sn_TX_FSR, Sn_TX_RD, Sn_TX_WR, Sn_RX_RSR, Sn_RX_RD, Sn_RX_WR : Data communication - */ - - /** - * @defgroup Basic_IO_function_W5100S Basic I/O function - * @ingroup WIZCHIP_IO_Functions_W5100S - * @brief These are basic input/output functions to read values from register or write values to register. - */ - -/** - * @defgroup Common_register_access_function_W5100S Common register access functions - * @ingroup WIZCHIP_IO_Functions_W5100S - * @brief These are functions to access common registers. - */ - -/** - * @defgroup Socket_register_access_function_W5100S Socket register access functions - * @ingroup WIZCHIP_IO_Functions_W5100S - * @brief These are functions to access socket registers. - */ - - /** - * @defgroup Special_function_W5100S Special functions - * @ingroup WIZCHIP_IO_Functions_W5100S - * @brief These are special functions to access to the PHY - */ - - //----------------------------------------------------------------------------------- - -//----------------------------- W5100S Common Registers IOMAP ----------------------------- -/** - * @ingroup Common_register_group_W5100S - * @brief Mode Register address(R/W)\n - * \ref MR is used for S/W reset, ping block mode, PPPoE mode and etc. - * @details Each bit of \ref MR defined as follows. - * - * - * - *
7 6 5 4 3 2 1 0
RST Reserved WOL PB PPPoE Reserved AI IND
- * - \ref MR_RST : Reset - * - \ref MR_PB : Ping block - * - \ref MR_PPPOE : PPPoE mode - * - \ref MR_AI : Address Auto-Increment in Indirect Bus Interface - * - \ref MR_IND : Indirect Bus Interface mode - */ -#if _WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_ - #define MR (_WIZCHIP_IO_BASE_ + (0x0000)) // Mode -#else - #define MR (_W5100S_IO_BASE_ + (0x0000)) // Mode -#endif - -/** - * @ingroup Common_register_group_W5100S - * @brief Gateway IP Register address(R/W) - * @details \ref GAR configures the default gateway address. - */ -#define GAR (_W5100S_IO_BASE_ + (0x0001)) // GW Address - -/** - * @ingroup Common_register_group_W5100S - * @brief Subnet mask Register address(R/W) - * @details \ref SUBR configures the subnet mask address. - */ -#define SUBR (_W5100S_IO_BASE_ + (0x0005)) // SN Mask Address - -/** - * @ingroup Common_register_group_W5100S - * @brief Source MAC Register address(R/W) - * @details \ref SHAR configures the source hardware address. - */ -#define SHAR (_W5100S_IO_BASE_ + (0x0009)) // Source Hardware Address - -/** - * @ingroup Common_register_group_W5100S - * @brief Source IP Register address(R/W) - * @details \ref SIPR configures the source IP address. - */ -#define SIPR (_W5100S_IO_BASE_ + (0x000F)) // Source IP Address - -// Reserved (_W5100S_IO_BASE_ + (0x0013)) -// Reserved (_W5100S_IO_BASE_ + (0x0014)) - -/** - * @ingroup Common_register_group_W5100S - * @brief Interrupt Register(R/W) - * @details \ref IR indicates the interrupt status. Each bit of \ref IR will be still until the bit will be written to by the host. - * If \ref IR is not equal to x00 INTn PIN is asserted to low until it is x00\n\n - * Each bit of \ref IR defined as follows. - * - * - * - *
7 6 5 4 3 2 1 0
CONFLICT UNREACH PPPoE Reserved S3_INT S2_INT S1_INT S0_INT
- * - \ref IR_CONFLICT : IP conflict - * - \ref IR_UNREACH : Destination unreachable - * - \ref IR_PPPoE : PPPoE connection close - * - \ref IR_SOCK(3) : SOCKET 3 Interrupt - * - \ref IR_SOCK(2) : SOCKET 2 Interrupt - * - \ref IR_SOCK(1) : SOCKET 1 Interrupt - * - \ref IR_SOCK(0) : SOCKET 0 Interrupt - */ -#define IR (_W5100S_IO_BASE_ + (0x0015)) // Interrupt - -/** - * @ingroup Common_register_group_W5100S - * @brief Socket Interrupt Mask Register(R/W) - * @details Each bit of \ref _IMR_ corresponds to each bit of \ref IR. - * When a bit of \ref _IMR_ is and the corresponding bit of \ref IR is set, Interrupt will be issued. - */ -#define _IMR_ (_W5100S_IO_BASE_ + (0x0016)) // Socket Interrupt Mask - -/** - * @ingroup Common_register_group_W5100S - * @brief Timeout register address( 1 is 100us )(R/W) - * @details \ref _RTR_ configures the retransmission timeout period. The unit of timeout period is 100us and the default of \ref _RTR_ is x07D0or 000 - * And so the default timeout period is 200ms(100us X 2000). During the time configured by \ref _RTR_, W5100S waits for the peer response - * to the packet that is transmitted by \ref Sn_CR (CONNECT, DISCON, CLOSE, SEND, SEND_MAC, SEND_KEEP command). - * If the peer does not respond within the \ref _RTR_ time, W5100S retransmits the packet or issues timeout. - */ -#define _RTR_ (_W5100S_IO_BASE_ + (0x0017)) // Retry Time - -/** - * @ingroup Common_register_group_W5100S - * @brief Retry count register(R/W) - * @details \ref _RCR_ configures the number of time of retransmission. - * When retransmission occurs as many as ref _RCR_+1 Timeout interrupt is issued (\ref Sn_IR_TIMEOUT = '1'). - */ -#define _RCR_ (_W5100S_IO_BASE_ + (0x0019)) // Retry Count - -/** - * @ingroup Common_register_group_W5100S - * @brief Receive Memory Size Register - * @details \ref RMSR register configures RX bufffer Size of the SOCKET - * The sum of the RX buffers can not exceed 8kB. - * - * - * - *
7 6 5 4 3 2 1 0
S3-1 S3-0 S2-1 S2-0 S1-1 S1-0 S0-1 S0-0
- * - * - * - * - * - * - *
Memory SizeSn-1Sn-0
1KB00
2KB01
4KB10
8KB11
- */ -#define RMSR (_W5100S_IO_BASE_ + (0x001A)) // Receive Memory Size - -/** - * @ingroup Common_register_group_W5100S - * @brief Transmit Memory Size Register - * @details \ref TMSR register configures TX bufffer Size of the SOCKET - * The sum of the TX buffers can not exceed 8kB. - * - * - * - *
7 6 5 4 3 2 1 0
S3-1 S3-0 S2-1 S2-0 S1-1 S1-0 S0-1 S0-0
- * - * - * - * - * - * - *
Memory SizeSn-1Sn-0
1KB00
2KB01
4KB10
8KB11
- */ -#define TMSR (_W5100S_IO_BASE_ + (0x001B)) // Transmit Memory Size - -/** - * @ingroup Common_register_group_W5100S - * @brief Interrupt register 2 - * @details \ref IR2 indicates the interrupt status. - * Each bit of IR2 will be still until the bit will be written to by the host. - * - * - * - *
7:1 0
Reserved WOL
- * - \ref IR2_WOL : WOL MAGIC PACKET Interrupt Mask - */ -#define IR2 (_W5100S_IO_BASE_ + (0x0020)) - -/** - * @ingroup Common_register_group_W5100S - * @brief Interrupt mask register 2 - * @details \ref IMR2 Each bit of IMR2 corresponds to each bit of IR2. - * When a bit of IMR2 is and the corresponding bit of IR2 is set, Interrupt will be issued. - */ -#define IMR2 (_W5100S_IO_BASE_ + (0x0021)) - - -/** - * @ingroup Common_register_group_W5100S - * @brief PPP LCP Request Timer register in PPPoE mode(R) - * @details \ref PTIMER configures the time for sending LCP echo request. The unit of time is 25ms. - */ -#define PTIMER (_W5100S_IO_BASE_ + (0x0028)) // PPP LCP RequestTimer - -/** - * @ingroup Common_register_group_W5100S - * @brief PPP LCP Magic number register in PPPoE mode(R) - * @details \ref PMAGIC configures the 4bytes magic number to be used in LCP negotiation. - */ -#define PMAGIC (_W5100S_IO_BASE_ + (0x0029)) // PPP LCP Magic number - -/** - * @ingroup Common_register_group_W5100S - * @brief Unreachable IP address register - * @details \ref - */ -#define UIPR (_W5100S_IO_BASE_ + (0x002A)) - -/** - * @ingroup Common_register_group_W5100S - * @brief Unreachable Port register - * @details \ref - */ -#define UPORTR (_W5100S_IO_BASE_ + (0x002E)) - -/* register for W5100S only */ - -/*------------------------------------------ Common registers ------------------------------------------*/ - -/** - * @ingroup Common_register_group_W5100S - * @brief MR2 Mode register 2 - * @details \reg - */ -#define MR2 (_W5100S_IO_BASE_ + (0x0030)) - - -/** - * @ingroup Common_register_group_W5100S - * @brief Destination Hardware address in PPPoE - * @details \reg - */ -#define PHAR (_W5100S_IO_BASE_ + (0x0032)) - -/** - * @ingroup Common_register_group_W5100S - * @brief Session ID in PPPoE - * @details \reg - */ -#define PSIDR (_W5100S_IO_BASE_ + (0x0038)) - -/** - * @ingroup Common_register_group_W5100S - * @brief Maximum receive Unit in PPPoE - * @details \reg - */ -#define PMRUR (_W5100S_IO_BASE_ + (0x003A)) - - -/*------------------------------------------ PHY registers ------------------------------------------*/ - -/** - * @ingroup Common_register_group_W5100S - * @brief PHY status register - * @details \reg - */ -#define PHYSR (_W5100S_IO_BASE_ + (0x003C)) - -/** - * @ingroup Common_register_group_W5100S - * @brief PHY status register(hidden) - * @details \reg - */ -#define PHYSR1 (_W5100S_IO_BASE_ + (0x003D)) - -/** - * @ingroup Common_register_group_W5100S - * @brief PHY Address value - * @details \reg - */ -#define PHYAR (_W5100S_IO_BASE_ + (0x003E)) - -/** - * @ingroup Common_register_group_W5100S - * @brief PHY Register address - * @details \reg - */ -#define PHYRAR (_W5100S_IO_BASE_ + (0x003F)) - -/** - * @ingroup Common_register_group_W5100S - * @brief PHY Data input register - * @details \reg - */ -#define PHYDIR (_W5100S_IO_BASE_ + (0x0040)) - -/** - * @ingroup Common_register_group_W5100S - * @brief PHY data output register - * @details \reg - */ -#define PHYDOR (_W5100S_IO_BASE_ + (0x0042)) - -/** - * @ingroup Common_register_group_W5100S - * @brief PHY Action register - * @details \reg - */ -#define PHYACR (_W5100S_IO_BASE_ + (0x0044)) - -/** - * @ingroup Common_register_group_W5100S - * @brief PHY Division register - * @details \reg - */ -#define PHYDIVR (_W5100S_IO_BASE_ + (0x0045)) - -/** - * @ingroup Common_register_group_W5100S - * @brief PHY Control register 0 - * @details \reg - */ -#define PHYCR0 (_W5100S_IO_BASE_ + (0x0046)) -/** - * @ingroup Common_register_group_W5100S - * @brief PHY Control register 1 - * @details \reg - */ -#define PHYCR1 (_W5100S_IO_BASE_ + (0x0047)) - -/*------------------------------------------ Socket Less registers ------------------------------------------*/ - -/** - * @ingroup Common_register_group_W5100S - * @brief Socket-less control register - * @details \reg - */ -#define SLCR (_W5100S_IO_BASE_ + (0x004C)) - -/** - * @ingroup Common_register_group_W5100S - * @brief Socket-less retry time register - * @details \reg - */ -#define SLRTR (_W5100S_IO_BASE_ + (0x004D)) - - -/** - * @ingroup Common_register_group_W5100S - * @brief Socket-less retry count register - * @details \reg - */ -#define SLRCR (_W5100S_IO_BASE_ + (0x004F)) - -/** - * @ingroup Common_register_group_W5100S - * @brief Socket-less peer IP address register - * @details \reg - */ -#define SLPIPR (_W5100S_IO_BASE_ + (0x0050)) - -/** - * @ingroup Common_register_group_W5100S - * @brief Socket-less peer hardware address register - * @details \reg - */ -#define SLPHAR (_W5100S_IO_BASE_ + (0x0054)) - -/** - * @ingroup Common_register_group_W5100S - * @brief Ping sequence number register - * @details \reg - */ -#define PINGSEQR (_W5100S_IO_BASE_ + (0x005A)) - -/** - * @ingroup Common_register_group_W5100S - * @brief Ping ID register - * @details \reg - */ -#define PINGIDR (_W5100S_IO_BASE_ + (0x005C)) - -/** - * @ingroup Common_register_group_W5100S - * @brief Socket-less interrupt mask register - * @details \reg - */ -#define SLIMR (_W5100S_IO_BASE_ + (0x005E)) - -/** - * @ingroup Common_register_group_W5100S - * @brief Socket-less interrupt register - * @details \reg - */ -#define SLIR (_W5100S_IO_BASE_ + (0x005F)) - -/** - * @ingroup Common_register_group_W5100S - * @brief DBGOUT(hidden) - * @details \reg - */ -#define DBGOUT (_W5100S_IO_BASE_ + (0x0060)) - -/** - * @ingroup Common_register_group_W5100S - * @brief NICMAXCOLR(hidden) - * @details \reg - */ -#define NICMAXCOLR (_W5100S_IO_BASE_ + (0x0063)) -/*------------------------------------------ CFG registers ------------------------------------------*/ - -/** - * @ingroup Common_register_group_W5100S - * @brief Chip Configuration locking register - * @details \reg - */ -#define CHIPLCKR (_W5100S_IO_BASE_ + (0x0070)) - -/** - * @ingroup Common_register_group_W5100S - * @brief Network Configuration locking register - * @details \reg - */ -#define NETLCKR (_W5100S_IO_BASE_ + (0x0071)) - -/** - * @ingroup Common_register_group_W5100S - * @brief PHY Configuration locking register - * @details \reg - */ -#define PHYLCKR (_W5100S_IO_BASE_ + (0x0072)) - -/** - * @ingroup Common_register_group_W5100S - * @brief version register - * @details \reg - */ -#define VERR (_W5100S_IO_BASE_ + (0x0080)) - -/** - * @ingroup Common_register_group_W5100S - * @brief Core 100us Counter register - * @details \reg - */ -#define TCNTR (_W5100S_IO_BASE_ + (0x0082)) - -/** - * @ingroup Common_register_group_W5100S - * @brief Core 100us Counter clear register - * @details \reg - */ -#define TCNTCLKR (_W5100S_IO_BASE_ + (0x0088)) - -//----------------------------- W5100S Socket Registers ----------------------------- - -//--------------------------- For Backward Compatibility --------------------------- - -/** - * @ingroup Socket_register_group_W5100S - * @brief socket Mode register(R/W) - * @details \ref Sn_MR configures the option or protocol type of Socket n.\n\n - * Each bit of \ref Sn_MR defined as the following. - * - * - * - *
7 6 5 4 3 2 1 0
MULTI MF ND/MC Reserved Protocol[3] Protocol[2] Protocol[1] Protocol[0]
- * - \ref Sn_MR_MULTI : Support UDP Multicasting - * - \ref Sn_MR_MF : Support MACRAW - * - \ref Sn_MR_ND : No Delayed Ack(TCP) flag - * - \ref Sn_MR_MC : IGMP version used in UDP mulitcasting - * - Protocol - * - * - * - * - * - * - *
Protocol[3] Protocol[2] Protocol[1] Protocol[0] @b Meaning
0 0 0 0 Closed
0 0 0 1 TCP
0 0 1 0 UDP
0 1 0 0 MACRAW
- * - In case of Socket 0 - * - * - * - * - *
Protocol[3] Protocol[2] Protocol[1] Protocol[0] @b Meaning
0 1 0 0 MACRAW
0 1 0 1 PPPoE
- * - \ref Sn_MR_MACRAW : MAC LAYER RAW SOCK \n - * - \ref Sn_MR_UDP : UDP - * - \ref Sn_MR_TCP : TCP - * - \ref Sn_MR_CLOSE : Unused socket - * @note MACRAW mode should be only used in Socket 0. - */ -#define Sn_MR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0000)) // socket Mode register - -/** - * @ingroup Socket_register_group_W5100S - * @brief Socket command register(R/W) - * @details This is used to set the command for Socket n such as OPEN, CLOSE, CONNECT, LISTEN, SEND, and RECEIVE.\n - * After W5100S accepts the command, the \ref Sn_CR register is automatically cleared to 0x00. - * Even though \ref Sn_CR is cleared to 0x00, the command is still being processed.\n - * To check whether the command is completed or not, please check the \ref Sn_IR or \ref Sn_SR. - * - \ref Sn_CR_OPEN : Initialize or open socket. - * - \ref Sn_CR_LISTEN : Wait connection request in TCP mode(Server mode) - * - \ref Sn_CR_CONNECT : Send connection request in TCP mode(Client mode) - * - \ref Sn_CR_DISCON : Send closing request in TCP mode. - * - \ref Sn_CR_CLOSE : Close socket. - * - \ref Sn_CR_SEND : Update TX buffer pointer and send data. - * - \ref Sn_CR_SEND_MAC : Send data with MAC address, so without ARP process. - * - \ref Sn_CR_SEND_KEEP : Send keep alive message. - * - \ref Sn_CR_RECV : Update RX buffer pointer and receive data. - * - In case of S0_MR(P3:P0) = S0_MR_PPPoE - * - * - * - * - * - * - * - *
Value Symbol Description
0x23 PCON PPPoE connection begins by transmitting PPPoE discovery packet
0x24 PDISCON Closes PPPoE connection
0x25 PCR In each phase, it transmits REQ message.
0x26 PCN In each phase, it transmits NAK message.
0x27 PCJ In each phase, it transmits REJECT message.
- */ -#define Sn_CR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0001)) // channel Sn_CR register - -/** - * @ingroup Socket_register_group_W5100S - * @brief Socket interrupt register(R) - * @details \ref Sn_IR indicates the status of Socket Interrupt such as establishment, termination, receiving data, timeout).\n - * When an interrupt occurs and the corresponding bit \ref IR_SOCK(N) in \ref _IMR_ are set, \ref IR_SOCK(N) in \ref IR becomes '1'.\n - * In order to clear the \ref Sn_IR bit, the host should write the bit to \n - * - * - * - *
7 6 5 4 3 2 1 0
PRECV PFAIL PNEXT SEND_OK TIMEOUT RECV DISCON CON
- * - \ref Sn_IR_PRECV : PPP Receive Interrupt - * - \ref Sn_IR_PFAIL : PPP Fail Interrupt - * - \ref Sn_IR_PNEXT : PPP Next Phase Interrupt - * - \ref Sn_IR_SENDOK : SEND_OK Interrupt - * - \ref Sn_IR_TIMEOUT : TIMEOUT Interrupt - * - \ref Sn_IR_RECV : RECV Interrupt - * - \ref Sn_IR_DISCON : DISCON Interrupt - * - \ref Sn_IR_CON : CON Interrupt - */ -#define Sn_IR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0002)) // channel interrupt register - -/** - * @ingroup Socket_register_group_W5100S - * @brief Socket status register(R) - * @details \ref Sn_SR indicates the status of Socket n.\n - * The status of Socket n is changed by \ref Sn_CR or some special control packet as SYN, FIN packet in TCP. - * @par Normal status - * - \ref SOCK_CLOSED : Closed - * - \ref SOCK_INIT : Initiate state - * - \ref SOCK_LISTEN : Listen state - * - \ref SOCK_ESTABLISHED : Success to connect - * - \ref SOCK_CLOSE_WAIT : Closing state - * - \ref SOCK_UDP : UDP socket - * - \ref SOCK_MACRAW : MAC raw mode socket - *@par Temporary status during changing the status of Socket n. - * - \ref SOCK_SYNSENT : This indicates Socket n sent the connect-request packet (SYN packet) to a peer. - * - \ref SOCK_SYNRECV : It indicates Socket n successfully received the connect-request packet (SYN packet) from a peer. - * - \ref SOCK_FIN_WAIT : Connection state - * - \ref SOCK_CLOSING : Closing state - * - \ref SOCK_TIME_WAIT : Closing state - * - \ref SOCK_LAST_ACK : Closing state - */ -#define Sn_SR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0003)) // channel status register - -/** - * @ingroup Socket_register_group_W5100S - * @brief source port register(R/W) - * @details \ref Sn_PORT configures the source port number of Socket n. - * It is valid when Socket n is used in TCP/UDP mode. It should be set before OPEN command is ordered. -*/ -#define Sn_PORT(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0004)) // source port register - -/** - * @ingroup Socket_register_group_W5100S - * @brief Peer MAC register address(R/W) - * @details \ref Sn_DHAR configures the destination hardware address of Socket n when using SEND_MAC command in UDP mode or - * it indicates that it is acquired in ARP-process by CONNECT/SEND command. - */ -#define Sn_DHAR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0006)) // Peer MAC register address - -/** - * @ingroup Socket_register_group_W5100S - * @brief Peer IP register address(R/W) - * @details \ref Sn_DIPR configures or indicates the destination IP address of Socket n. It is valid when Socket n is used in TCP/UDP mode. - * In TCP client mode, it configures an IP address of TCP server before CONNECT command. - * In TCP server mode, it indicates an IP address of TCP client after successfully establishing connection. - * In UDP mode, it configures an IP address of peer to be received the UDP packet by SEND or SEND_MAC command. - */ -#define Sn_DIPR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x000C)) // Peer IP register address - -/** - * @ingroup Socket_register_group_W5100S - * @brief Peer port register address(R/W) - * @details \ref Sn_DPORT configures or indicates the destination port number of Socket n. It is valid when Socket n is used in TCP/UDP mode. - * In TCP clientmode, it configures the listen port number of TCP server before CONNECT command. - * In TCP Servermode, it indicates the port number of TCP client after successfully establishing connection. - * In UDP mode, it configures the port number of peer to be transmitted the UDP packet by SEND/SEND_MAC command. - */ -#define Sn_DPORT(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0010)) // Peer port register address - -/** - * @ingroup Socket_register_group_W5100S - * @brief Maximum Segment Size(Sn_MSSR0) register address(R/W) - * @details \ref Sn_MSSR configures or indicates the MTU(Maximum Transfer Unit) of Socket n. - */ -#define Sn_MSSR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0012)) // Maximum Segment Size(Sn_MSSR0) register address - -/** - * @ingroup Socket_register_group_W5100S - * @brief IP Protocol(PROTO) Register(R/W) - * @details \ref Sn_PROTO that sets the protocol number field of the IP header at the IP layer. It is - * valid only in IPRAW mode, and ignored in other modes. - */ -#define Sn_PROTO(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0014)) // Protocol of IP Header field register in IP raw mode - -/** - * @ingroup Socket_register_group_W5100S - * @brief IP Type of Service(TOS) Register(R/W) - * @details \ref Sn_TOS configures the TOS(Type Of Service field in IP Header) of Socket n. - * It is set before OPEN command. - */ -#define Sn_TOS(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + 0x0015) // IP Type of Service(TOS) Register - -/** - * @ingroup Socket_register_group_W5100S - * @brief IP Time to live(TTL) Register(R/W) - * @details \ref Sn_TTL configures the TTL(Time To Live field in IP header) of Socket n. - * It is set before OPEN command. - */ -#define Sn_TTL(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0016)) // IP Time to live(TTL) Register - -// Reserved (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0017)) -// Reserved (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0018)) -// Reserved (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0019)) -// Reserved (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001A)) -// Reserved (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001B)) -// Reserved (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001C)) -// Reserved (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001D)) - - - -/** - * @ingroup Socket_register_group_W5100S - * @brief Receive memory size register(R/W) - * @details @ref Sn_RXBUF_SIZE configures the RX buffer block size of Socket n. - * Socket n RX Buffer Block size can be configured with 1,2,4 and 8Kbytes. - * If a different size is configured, the data cannot be normally received from a peer. - * Although Socket n RX Buffer Block size is initially configured to 2Kbytes, - * user can re-configure its size using @ref Sn_RXBUF_SIZE. The total sum of @ref Sn_RXBUF_SIZE can not be exceed 8Kbytes. - * When exceeded, the data reception error is occurred. - */ -#define Sn_RXBUF_SIZE(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001E)) - -/** - * @ingroup Socket_register_group_W5100S - * @brief Transmit memory size register(R/W) - * @details @ref Sn_TXBUF_SIZE configures the TX buffer block size of Socket n. Socket n TX Buffer Block size can be configured with 1,2,4 and 8Kbytes. - * If a different size is configured, the data cannot be normally transmitted to a peer. - * Although Socket n TX Buffer Block size is initially configured to 2Kbytes, - * user can be re-configure its size using @ref Sn_TXBUF_SIZE. The total sum of @ref Sn_TXBUF_SIZE can not be exceed 8Kbytes. - * When exceeded, the data transmission error is occurred. - */ -#define Sn_TXBUF_SIZE(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001F)) - - -/** - * @ingroup Socket_register_group_W5100S - * @brief Transmit free memory size register(R) - * @details \ref Sn_TX_FSR indicates the free size of Socket n TX Buffer Block. It is initialized to the configured size by \ref Sn_TXMEM_SIZE. - * Data bigger than \ref Sn_TX_FSR should not be saved in the Socket n TX Buffer because the bigger data overwrites the previous saved data not yet sent. - * Therefore, check before saving the data to the Socket n TX Buffer, and if data is equal or smaller than its checked size, - * transmit the data with SEND/SEND_MAC command after saving the data in Socket n TX buffer. But, if data is bigger than its checked size, - * transmit the data after dividing into the checked size and saving in the Socket n TX buffer. - */ -#define Sn_TX_FSR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0020)) // Transmit free memory size register - -/** - * @ingroup Socket_register_group_W5100S - * @brief Transmit memory read pointer register address(R) - * @details \ref Sn_TX_RD is initialized by OPEN command. However, if Sn_MR(P[3:0]) is TCP mode(001), it is re-initialized while connecting with TCP. - * After its initialization, it is auto-increased by SEND command. - * SEND command transmits the saved data from the current \ref Sn_TX_RD to the \ref Sn_TX_WR in the Socket n TX Buffer. - * After transmitting the saved data, the SEND command increases the \ref Sn_TX_RD as same as the \ref Sn_TX_WR. - * If its increment value exceeds the maximum value 0xFFFF, (greater than 0x10000 and the carry bit occurs), - * then the carry bit is ignored and will automatically update with the lower 16bits value. - */ -#define Sn_TX_RD(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0022)) // Transmit memory read pointer register address - -/** - * @ingroup Socket_register_group_W5100S - * @brief Transmit memory write pointer register address(R/W) - * @details \ref Sn_TX_WR is initialized by OPEN command. However, if Sn_MR(P[3:0]) is TCP mode(001), it is re-initialized while connecting with TCP.\n - * It should be read or be updated like as follows.\n - * 1. Read the starting address for saving the transmitting data.\n - * 2. Save the transmitting data from the starting address of Socket n TX buffer.\n - * 3. After saving the transmitting data, update \ref Sn_TX_WR to the increased value as many as transmitting data size. - * If the increment value exceeds the maximum value 0xFFFF(greater than 0x10000 and the carry bit occurs), - * then the carry bit is ignored and will automatically update with the lower 16bits value.\n - * 4. Transmit the saved data in Socket n TX Buffer by using SEND/SEND command - */ -#define Sn_TX_WR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0024)) // Transmit memory write pointer register address - -/** - * @ingroup Socket_register_group_W5100S - * @brief Received data size register(R) - * @details \ref Sn_RX_RSR indicates the data size received and saved in Socket n RX Buffer. - * \ref Sn_RX_RSR does not exceed the \ref Sn_RXMEM_SIZE and is calculated as the difference between - * Socket n RX Write Pointer (\ref Sn_RX_WR)and Socket n RX Read Pointer (\ref Sn_RX_RD) - */ -#define Sn_RX_RSR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0026)) // Received data size register - -/** - * @ingroup Socket_register_group_W5100S - * @brief Read point of Receive memory(R/W) - * @details \ref Sn_RX_RD is initialized by OPEN command. Make sure to be read or updated as follows.\n - * 1. Read the starting save address of the received data.\n - * 2. Read data from the starting address of Socket n RX Buffer.\n - * 3. After reading the received data, Update \ref Sn_RX_RD to the increased value as many as the reading size. - * If the increment value exceeds the maximum value 0xFFFF, that is, is greater than 0x10000 and the carry bit occurs, - * update with the lower 16bits value ignored the carry bit.\n - * 4. Order RECV command is for notifying the updated \ref Sn_RX_RD to W5100S. - */ -#define Sn_RX_RD(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0028)) // Read point of Receive memory - -/** - * @ingroup Socket_register_group_W5100S - * @brief Write point of Receive memory(R) - * @details \ref Sn_RX_WR is initialized by OPEN command and it is auto-increased by the data reception. - * If the increased value exceeds the maximum value 0xFFFF, (greater than 0x10000 and the carry bit occurs), - * then the carry bit is ignored and will automatically update with the lower 16bits value. - */ -#define Sn_RX_WR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x002A)) // Write point of Receive memory - - -//todo -/** - * @ingroup Socket_register_group_W5100S - * @brief Socket interrupt mask register - * @details Register address to configure the interrupt mask of the socket - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ expect bit 4. - * - */ -#define Sn_IMR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x002C)) - -/** - * @ingroup Socket_register_group_W5100S - * @brief Socket fragment field register - * @details Register to configure the Fragment field of IP Header - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ expect bit 4. - */ -#define Sn_FRAGR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x002D)) // and +1 - -/** - * @ingroup Socket_register_group_W5100S - * @brief Socket Mode register 2 - * @details Register to set mode 2 - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ expect bit 4. - */ -#define Sn_MR2(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x002F)) - -/** - * @ingroup Socket_register_group_W5100S - * @brief Socket n Keep Alive Timer Register - * @details Register to set the transmission period of keep alive packet. - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ expect bit 4. - */ -#define Sn_KPALVTR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0030)) - -/** todo delete - * @ingroup Socket_register_group_W5100S - * @brief Socket n Timer Status Register - * @details - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ expect bit 4. - */ -//#define Sn_TSR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0031)) - -/** - * @ingroup Socket_register_group_W5100S - * @brief Socket n Retry Time-value Register - * @details Register to set the retry time value - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ expect bit 4. - */ -#define Sn_RTR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0032)) - -/** - * @ingroup Socket_register_group_W5100S - * @brief Socket n Retry Count-value Register - * @details Register to set the retry count value - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ expect bit 4. - */ -#define Sn_RCR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0034)) - - -/*----------------------------- W5100S Register values -----------------------------*/ - -/* MODE register values */ -/** - * @brief Reset - * @details If this bit is All internal registers will be initialized. It will be automatically cleared as after S/W reset. - */ -#define MR_RST 0x80 ///< reset - - -/** - * @brief Ping block - * @details 0 : Disable Ping block\n - * 1 : Enable Ping block\n - * If the bit is it blocks the response to a ping request. - */ -#define MR_PB 0x10 ///< ping block - -/** - * @brief Enable PPPoE - * @details 0 : DisablePPPoE mode\n - * 1 : EnablePPPoE mode\n - * If you use ADSL, this bit should be '1'. - */ -#define MR_PPPOE 0x08 ///< enable pppoe - -/** - * @brief Address Auto-Increment in Indirect Bus Interface - * @details 0 : Disable auto-increment \n - * 1 : Enable auto-incremente \n - * At the Indirect Bus Interface mode, if this bit is set as the address will - * be automatically increased by 1 whenever read and write are performed. - */ -#define MR_AI 0x02 ///< auto-increment in indirect mode - -/** - * @brief Indirect Bus Interface mode - * @details 0 : Disable Indirect bus Interface mode \n - * 1 : Enable Indirect bus Interface mode \n - * If this bit is set as Indirect Bus Interface mode is set. - */ -#define MR_IND 0x01 ///< enable indirect mode - -/* IR register values */ -/** - * @brief Check IP conflict. - * @details Bit is set as when own source IP address is same with the sender IP address in the received ARP request. - */ -#define IR_CONFLICT 0x80 ///< check ip confict - -/** - * @brief Get the destination unreachable message in UDP sending. - * @details When receiving the ICMP (Destination port unreachable) packet, this bit is set as - * When this bit is Destination Information such as IP address and Port number may be checked with the corresponding @ref UIPR & @ref UPORTR. - */ -#define IR_UNREACH 0x40 ///< check destination unreachable - -/** - * @brief Get the PPPoE close message. - * @details When PPPoE is disconnected during PPPoE mode, this bit is set. - */ -#define IR_PPPoE 0x20 ///< get the PPPoE close message - -/** - * @brief Socket interrupt bit - * @details Indicates whether each socket interrupt has occured. - */ -#define IR_SOCK(sn) (0x01 << sn) ///< check socket interrupt - -/** - * @brief IP conflict interrupt mask bit - * @details If this bit is set, IP conflict interrupt is enabled. - */ -#define IMR_CONFLICT 0x80 - -/** - * @brief Destination port unreachable interrupt mask bit - * @details If this bit is set, destination port unreachable interrupt is enabled. - */ -#define IMR_UNREACH 0x40 - -/** - * @brief PADT/LCPT interrupt mask bit(PPPoE) - * @details If this bit is set, PADT/LCPT interrupt is enabled. - */ -#define IMR_PPPoE 0x20 - -/** - * @brief Socket interrupt mask bit - * @details If this bit is set, each socket interrupt is enabled. - */ -#define IMR_SOCK(sn) (0x01 << sn) - -/** - * @brief Socket-less command register bit - * @details ARP command - */ -#define SLCMD_ARP (1<<1) - -/** - * @brief Socket-less command register bit - * @details ARP command - */ -#define SLCMD_PING (1<<0) - -/** - * @brief Socket-less command interrupt and interrupt mask register bit - * @details Request command time out interrupt and interrupt mask - */ -#define SLIR_TIMEOUT (1<<2) - -/** -* @brief Socket less command interrupt and interrupt mask register bit -* @details Socket less command ARP interrupt and interrupt mask -*/ -#define SLIR_ARP (1<<1) - -/** -* @brief Socket less command interrupt and interrupt mask register bit -* @details Socket less command PING interrupt and interruptmask -*/ -#define SLIR_PING (1<<0) - - - -// Sn_MR values -/* Sn_MR Default values */ -/** - * @brief Unused socket - * @details This configures the protocol mode of Socket n. - */ -#define Sn_MR_CLOSE 0x00 ///< unused socket - -/** - * @brief TCP - * @details This configures the protocol mode of Socket n. - */ -#define Sn_MR_TCP 0x01 ///< TCP - -/** - * @brief UDP - * @details This configures the protocol mode of Socket n. - */ -#define Sn_MR_UDP 0x02 ///< UDP -#define Sn_MR_IPRAW 0x03 ///< IP LAYER RAW SOCK - -/** - * @brief MAC LAYER RAW SOCK - * @details This configures the protocol mode of Socket n. - * @note MACRAW mode should be only used in Socket 0. - */ -#define Sn_MR_MACRAW 0x04 ///< MAC LAYER RAW SOCK - -/** - * @brief PPPoE - * @details This configures the protocol mode of Socket n. - * @note PPPoE mode should be only used in Socket 0. - */ -#define Sn_MR_PPPoE 0x05 ///< PPPoE - -/** - * @brief No Delayed Ack(TCP), Multicast flag - * @details 0 : Disable No Delayed ACK option\n - * 1 : Enable No Delayed ACK option\n - * This bit is applied only during TCP mode (P[3:0] = 001).\n - * When this bit is It sends the ACK packet without delay as soon as a Data packet is received from a peer.\n - * When this bit is It sends the ACK packet after waiting for the timeout time configured by \ref _RTR_. - */ -#define Sn_MR_ND 0x20 ///< No Delayed Ack(TCP) flag - -/** - * @brief Support UDP Multicasting - * @details 0 : using IGMP version 2\n - * 1 : using IGMP version 1\n - * This bit is applied only during UDP mode(P[3:0] = 010 and MULTI = '1') - * It configures the version for IGMP messages (Join/Leave/Report). - */ -#define Sn_MR_MC Sn_MR_ND ///< Select IGMP version 1(0) or 2(1) - -/** - * @brief MAC filter enable in @ref Sn_MR_MACRAW mode - * @details 0 : disable MAC Filtering\n - * 1 : enable MAC Filtering\n - * This bit is applied only during MACRAW mode(P[3:0] = 100.\n - * When set as W5100S can only receive broadcasting packet or packet sent to itself. - * When this bit is W5100S can receive all packets on Ethernet. - * If user wants to implement Hybrid TCP/IP stack, - * it is recommended that this bit is set as for reducing host overhead to process the all received packets. - */ -#define Sn_MR_MF 0x40 ///< Use MAC filter -#define Sn_MR_MFEN Sn_MR_MF - - -/* Sn_MR Default values */ -/** - * @brief Support UDP Multicasting - * @details 0 : disable Multicasting\n - * 1 : enable Multicasting\n - * This bit is applied only during UDP mode(P[3:0] = 010).\n - * To use multicasting, \ref Sn_DIPR & \ref Sn_DPORT should be respectively configured with the multicast group IP address & port number - * before Socket n is opened by OPEN command of \ref Sn_CR. - */ -#define Sn_MR_MULTI 0x80 ///< support multicating - -/* Sn_CR values */ -/** - * @brief Initialize or open socket - * @details Socket n is initialized and opened according to the protocol selected in Sn_MR(P3:P0). - * The table below shows the value of \ref Sn_SR corresponding to \ref Sn_MR.\n - * - * - * - * - * - * - * - * - *
\b Sn_MR (P[3:0]) \b Sn_SR
Sn_MR_CLOSE (000) --
Sn_MR_TCP (001) SOCK_INIT (0x13)
Sn_MR_UDP (010) SOCK_UDP (0x22)
S0_MR_IPRAW (011) SOCK_IPRAW (0x32)
S0_MR_MACRAW (100) SOCK_MACRAW (0x42)
S0_MR_PPPoE (101) SOCK_PPPoE (0x5F)
- */ -#define Sn_CR_OPEN 0x01 ///< initialize or open socket - -/** - * @brief Wait connection request in TCP mode(Server mode) - * @details This is valid only in TCP mode (Sn_MR(P3:P0) = \ref Sn_MR_TCP).// - * In this mode, Socket n operates as a 'TCP server' and waits for connection-request (SYN packet) from any 'TCP client'.// - * The \ref Sn_SR changes the state from SOCK_INIT to SOCKET_LISTEN.// - * When a 'TCP client' connection request is successfully established, - * the \ref Sn_SR changes from SOCK_LISTEN to SOCK_ESTABLISHED and the Sn_IR(0) becomes - * But when a 'TCP client' connection request is failed, Sn_IR(3) becomes and the status of \ref Sn_SR changes to SOCK_CLOSED. - */ -#define Sn_CR_LISTEN 0x02 ///< wait connection request in tcp mode(Server mode) - -/** - * @brief Send connection request in TCP mode(Client mode) - * @details To connect, a connect-request (SYN packet) is sent to TCP serverconfigured by \ref Sn_DIPR & Sn_DPORT(destination address & port). - * If the connect-request is successful, the \ref Sn_SR is changed to \ref SOCK_ESTABLISHED and the Sn_IR(0) becomes \n\n - * The connect-request fails in the following three cases.\n - * 1. When a @b ARPTO occurs (\ref Sn_IR[3] = '1') because destination hardware address is not acquired through the ARP-process.\n - * 2. When a @b SYN/ACK packet is not received and @b TCPTO (Sn_IR(3) ='1')\n - * 3. When a @b RST packet is received instead of a @b SYN/ACK packet. In these cases, \ref Sn_SR is changed to \ref SOCK_CLOSED. - * @note This is valid only in TCP mode and operates when Socket n acts as TCP client - */ -#define Sn_CR_CONNECT 0x04 ///< send connection request in tcp mode(Client mode) - -/** - * @brief Send closing request in TCP mode - * @details Regardless of TCP serveror TCP client the DISCON command processes the disconnect-process (Active closeor Passive close.\n - * @par Active close - * it transmits disconnect-request(FIN packet) to the connected peer\n - * @par Passive close - * When FIN packet is received from peer, a FIN packet is replied back to the peer.\n - * @details When the disconnect-process is successful (that is, FIN/ACK packet is received successfully), \ref Sn_SR is changed to \ref SOCK_CLOSED.\n - * Otherwise, TCPTO occurs (Sn_IR(3)='1') and then \ref Sn_SR is changed to \ref SOCK_CLOSED. - * @note Valid only in TCP mode. - */ -#define Sn_CR_DISCON 0x08 ///< send closing reqeuset in tcp mode - -/** - * @brief Close socket - * @details Sn_SR is changed to \ref SOCK_CLOSED. - */ -#define Sn_CR_CLOSE 0x10 - -/** - * @brief Update TX buffer pointer and send data - * @details SEND transmits all the data in the Socket n TX buffer.\n - * For more details, please refer to Socket n TX Free Size Register (\ref Sn_TX_FSR), Socket n, - * TX Write Pointer Register(\ref Sn_TX_WR), and Socket n TX Read Pointer Register(\ref Sn_TX_RD). - */ -#define Sn_CR_SEND 0x20 - -/** - * @brief Send data with MAC address, so without ARP process - * @details The basic operation is same as SEND.\n - * Normally SEND transmits data after destination hardware address is acquired by the automatic ARP-process(Address Resolution Protocol).\n - * But SEND_MAC transmits data without the automatic ARP-process.\n - * In this case, the destination hardware address is acquired from \ref Sn_DHAR configured by host, instead of APR-process. - * @note Valid only in UDP mode. - */ -#define Sn_CR_SEND_MAC 0x21 - -/** - * @brief Send keep alive message - * @details It checks the connection status by sending 1byte keep-alive packet.\n - * If the peer can not respond to the keep-alive packet during timeout time, the connection is terminated and the timeout interrupt will occur. - * @note Valid only in TCP mode. - */ -#define Sn_CR_SEND_KEEP 0x22 - -/** - * @brief Update RX buffer pointer and receive data - * @details RECV completes the processing of the received data in Socket n RX Buffer by using a RX read pointer register (\ref Sn_RX_RD).\n - * For more details, refer to Socket n RX Received Size Register (\ref Sn_RX_RSR), Socket n RX Write Pointer Register (\ref Sn_RX_WR), - * and Socket n RX Read Pointer Register (\ref Sn_RX_RD). - */ -#define Sn_CR_RECV 0x40 - -/** - * @brief - * @details - */ -#define Sn_CR_IGMP_JOIN 0x23 - -/** - * @brief - * @details - */ -#define Sn_CR_IGMP_LEAVE 0x24 - - -/* Sn_IR values */ - -/** - * @brief SEND_OK Interrupt - * @details This is issued when SEND command is completed. - */ -#define Sn_IR_SENDOK 0x10 ///< complete sending - -/** - * @brief TIMEOUT Interrupt - * @details This is issued when ARPTO or TCPTO occurs. - */ -#define Sn_IR_TIMEOUT 0x08 ///< assert timeout - -/** - * @brief RECV Interrupt - * @details This is issued whenever data is received from a peer. - */ -#define Sn_IR_RECV 0x04 - -/** - * @brief DISCON Interrupt - * @details This is issued when FIN or FIN/ACK packet is received from a peer. - */ -#define Sn_IR_DISCON 0x02 - -/** - * @brief CON Interrupt - * @details This is issued one time when the connection with peer is successful and then \ref Sn_SR is changed to \ref SOCK_ESTABLISHED. - */ -#define Sn_IR_CON 0x01 - -/* Sn_SR values */ -/** - * @brief Closed - * @details This indicates that Socket n is released.\n - * When DICON, CLOSE command is ordered, or when a timeout occurs, it is changed to \ref SOCK_CLOSED regardless of previous status. - */ -#define SOCK_CLOSED 0x00 ///< closed - -/** - * @brief Initiate state - * @details This indicates Socket n is opened with TCP mode.\n - * It is changed to \ref SOCK_INIT when Sn_MR(P[3:0]) = 001)and OPEN command is ordered.\n - * After \ref SOCK_INIT, user can use LISTEN /CONNECT command. - */ -#define SOCK_INIT 0x13 ///< init state - -/** - * @brief Listen state - * @details This indicates Socket n is operating as TCP servermode and waiting for connection-request (SYN packet) from a peer (TCP client).\n - * It will change to \ref SOCK_ESTABLISHED when the connection-request is successfully accepted.\n - * Otherwise it will change to \ref SOCK_CLOSED after TCPTO occurred (Sn_IR(TIMEOUT) = '1'). - */ -#define SOCK_LISTEN 0x14 - -/** - * @brief Connection state - * @details This indicates Socket n sent the connect-request packet (SYN packet) to a peer.\n - * It is temporarily shown when \ref Sn_SR is changed from \ref SOCK_INIT to \ref SOCK_ESTABLISHED by CONNECT command.\n - * If connect-accept(SYN/ACK packet) is received from the peer at SOCK_SYNSENT, it changes to \ref SOCK_ESTABLISHED.\n - * Otherwise, it changes to \ref SOCK_CLOSED after TCPTO (\ref Sn_IR[TIMEOUT] = '1') is occurred. - */ -#define SOCK_SYNSENT 0x15 - -/** - * @brief Connection state - * @details It indicates Socket n successfully received the connect-request packet (SYN packet) from a peer.\n - * If socket n sends the response (SYN/ACK packet) to the peer successfully, it changes to \ref SOCK_ESTABLISHED. \n - * If not, it changes to \ref SOCK_CLOSED after timeout occurs (\ref Sn_IR[TIMEOUT] = '1'). - */ -#define SOCK_SYNRECV 0x16 - -/** - * @brief Success to connect - * @details This indicates the status of the connection of Socket n.\n - * It changes to \ref SOCK_ESTABLISHED when the TCP SERVERprocessed the SYN packet from the TCP CLIENTduring \ref SOCK_LISTEN, or - * when the CONNECT command is successful.\n - * During \ref SOCK_ESTABLISHED, DATA packet can be transferred using SEND or RECV command. - */ -#define SOCK_ESTABLISHED 0x17 - -/** - * @brief Closing state - * @details These indicate Socket n is closing.\n - * These are shown in disconnect-process such as active-close and passive-close.\n - * When Disconnect-process is successfully completed, or when timeout occurs, these change to \ref SOCK_CLOSED. - */ -#define SOCK_FIN_WAIT 0x18 - -/** - * @brief Closing state - * @details These indicate Socket n is closing.\n - * These are shown in disconnect-process such as active-close and passive-close.\n - * When Disconnect-process is successfully completed, or when timeout occurs, these change to \ref SOCK_CLOSED. - */ -#define SOCK_CLOSING 0x1A - -/** - * @brief Closing state - * @details These indicate Socket n is closing.\n - * These are shown in disconnect-process such as active-close and passive-close.\n - * When Disconnect-process is successfully completed, or when timeout occurs, these change to \ref SOCK_CLOSED. - */ -#define SOCK_TIME_WAIT 0x1B - -/** - * @brief Closing state - * @details This indicates Socket n received the disconnect-request (FIN packet) from the connected peer.\n - * This is half-closing status, and data can be transferred.\n - * For full-closing, DISCON command is used. But For just-closing, @ref Sn_CR_CLOSE command is used. - */ -#define SOCK_CLOSE_WAIT 0x1C - -/** - * @brief Closing state - * @details This indicates Socket n is waiting for the response (FIN/ACK packet) to the disconnect-request (FIN packet) by passive-close.\n - * It changes to \ref SOCK_CLOSED when Socket n received the response successfully, or when timeout occurs (\ref Sn_IR[TIMEOUT] = '1'). - */ -#define SOCK_LAST_ACK 0x1D - -/** - * @brief UDP socket - * @details This indicates Socket n is opened in UDP mode(Sn_MR(P[3:0]) = 010).\n - * It changes to SOCK_UDP when Sn_MR(P[3:0]) = 010 and @ref Sn_CR_OPEN command is ordered.\n - * Unlike TCP mode, data can be transfered without the connection-process. - */ -#define SOCK_UDP 0x22 ///< udp socket - -/** - * @brief IP raw mode socket - * @details TThe socket is opened in IPRAW mode. The SOCKET status is change to SOCK_IPRAW when @ref Sn_MR (P3:P0) is - * Sn_MR_IPRAW and @ref Sn_CR_OPEN command is used.\n - * IP Packet can be transferred without a connection similar to the UDP mode. -*/ -#define SOCK_IPRAW 0x32 ///< ip raw mode socket - -/** - * @brief MAC raw mode socket - * @details This indicates Socket 0 is opened in MACRAW mode (@ref Sn_MR(P[3:0]) = '100' and n=0) and is valid only in Socket 0.\n - * It changes to SOCK_MACRAW when @ref Sn_MR(P[3:0]) = '100' and @ref Sn_CR_OPEN command is ordered.\n - * Like UDP mode socket, MACRAW mode Socket 0 can transfer a MAC packet (Ethernet frame) without the connection-process. - */ -#define SOCK_MACRAW 0x42 ///< mac raw mode socket - -/** - * @brief PPPoE mode socket - * @details It is the status that SOCKET0 is open as PPPoE mode. It is changed to SOCK_PPPoE in case of S0_CR=OPEN and S0_MR - * (P3:P0)=S0_MR_PPPoE.\n - * It is temporarily used at the PPPoE -connection. - */ -#define SOCK_PPPOE 0x5F ///< pppoe socket - -// IP PROTOCOL -#define IPPROTO_IP 0 ///< Dummy for IP -#define IPPROTO_ICMP 1 ///< Control message protocol -#define IPPROTO_IGMP 2 ///< Internet group management protocol -#define IPPROTO_GGP 3 ///< GW^2 (deprecated) -#define IPPROTO_TCP 6 ///< TCP -#define IPPROTO_PUP 12 ///< PUP -#define IPPROTO_UDP 17 ///< UDP -#define IPPROTO_IDP 22 ///< XNS idp -#define IPPROTO_ND 77 ///< UNOFFICIAL net disk protocol -#define IPPROTO_RAW 255 ///< Raw IP packet - - - -/*----------------------------- W5100S !!Only!! Register values -----------------------------*/ - -//todo -/* MODE2 register values */ - -/** - * @brief Clock select bit - * @details With this bit, system clock can be selected to be 25Mhz or 100Mhz - * 1: 25Mhz - * 0: 100Mhz (default) - */ -#define MR2_CLKSEL (1<<7) - -/** - * @brief Interrupt pin enable bit - * @details This bit enables interrupt. - * 1: Enable interrupt - * 0: Disable interrupt - */ -#define MR2_G_IEN (1<<6) - - -/** - * @brief No TCP Reset Packet send - * @details This bit prevents sending reset packet. - * 1: Block TCP reset packet send - * 0: TCP Reset packet send - */ -#define MR2_NOTCPRST (1<<5) - -/** - * @brief Unreachable Packet Send Block bit - * @details This bit prevents sending Destination Port Unreachable Packet. - * 1: Block Destination Port Unreachable Packet Send - * 0: Destination Port Unreachable Packet Send - */ -#define MR2_UDPURB (1<<4) - -/** - * @brief Wake On LAN - * @details This bit enables WOL packet to be received. - * 1: WOL packet can be received. - * 0: WOL packet cannot be received. - */ -#define MR2_WOL (1<<3) - -/**todo - * @brief MACRAW No Size Check - * @details - */ -#define MR2_MNOSCHK (1<<2) - -/** - * @brief UDP force ARP - * @details This bit can enables to force ARP for each send command. - * 1: UDP Force ARP Enable - * 0: UDP Force ARP Disable. - * - */ -#define MR2_UDPFARP (1<<1) - -/**todo - * @brief Skip SRC Hardware Address - * @details This bit can enables to receive without checking the hardware address of the peer. - * 1: - */ -#define MR2_SSRCHA (1<<0) - - - -/* Common interrupt register 2 values */ - -/**todo - * @brief magic packet - * @details - */ -#define IR2_MGC (1<<1) - -/**todo - * @brief Magic packet interrupt mask bit - * @details If this bit is set, each socket interrupt is enabled. - */ -#define IMR2_MGC (1<<1) - -/**todo - * @brief - * @details - */ -//#define IR2_MGD (1<<1) /* Reserved */ - - -/* PHY status register 0 values */ - -/**todo - * @brief Ethernet CABLE OFF Signal - * @details - */ -#define PHYSR_CABOFF (1<<7) - -/**todo - * @brief - * @details - */ -#define PHYSR_MD2 (1<<5) - -/**todo - * @brief - * @details - */ -#define PHYSR_MD1 (1<<4) - -/**todo - * @brief - * @details - */ -#define PHYSR_MD0 (1<<3) - -/**todo - * @brief - * @details - */ -#define PHYSR_DUP (1<<2) - -/**todo - * @brief - * @details - */ -#define PHYSR_SPD (1<<1) - -/**todo - * @brief LINKDONE register - * @details If 1 Linked successfully, if 0 no link - */ -#define PHYSR_LNK (1<<0) - - -/* PHY status register 10 values */ - -/** - * @brieftodo - * @details - */ -#define PHYSR1_RXPG (1<<2) - -/** - * @brieftodo - * @details - */ -#define PHYSR1_LPI (1<<1) - -/** - * @brieftodo - * @details - */ -#define PHYSR1_CLDN (1<<0) - -#define PHYCR_AUTONEGO_ENABLE (0<<2) -#define PHYCR_AUTONEGO_DISABLE (1<<2) - -#define PHYCR_SPD_10 (1<<1) -#define PHYCR_SPD_100 (0<<1) - -#define PHYCR_HALF_DUP (1<<0) -#define PHYCR_FULL_DUP (0<<0) - -#define PHYCR1_RST (0<<0) - -#define PHYCR1_PWDN_ENABLE (1<<5) -#define PHYCR1_PWDN_DISABLE (0<<5) - - -/* Socket n MODE register 2 values */ - -/** - * @brief Broadcast Blocking bit in MACRAW mode - * @details In MACRAW mode, this bit is set to ????to block the broadcast packet. - */ -#define Sn_MR2_MBBLK (1<<6) - -/** - * @brief Multicast Blocking bit in MACRAW mode - * @details In MACRAW mode, this bit is set to ????to block the multicast packet. - */ -#define Sn_MR2_MMBLK (1<<5) - -/** - * @brief IPv6 packet Blocking bit in MACRAW mode - * @details In MACRAW mode, this bit is set to ????to block the IPv6 packet. - */ -#define Sn_MR2_IPV6BLK (1<<4) - - -/** - * @brief Broadcast Blocking bit in UDP mode - * @details In UDP mode, this bit is set to ????to block the broadcast packet. - */ -#define Sn_MR2_UBBLK (1<<1) - - -/** - * @brief TCP Force PSH bit - * @details When the SOCKET transmits data in TCP mode, PSH Flag is set to all packets. - */ -#define Sn_MR2_FPSH Sn_MR2_UBBLK - -/** - * @brief Unicast Blocking bit in UDP mode - * @details In UDP mode, this bit is set to ????to block the Unicast packet. - */ -#define Sn_MR2_UUBLK (1<<0) - -/*----------------------------For PHY Control-------------------------------*/ - -/********************/ -/* Register Address */ -/********************/ - -//Basic mode control register, basic register -#define PHYMDIO_BMCR 0x00 - -//Basic mode status register, basic register -#define PHYMDIO_BMSR 0x01 - -//--------------------------------------Not used-------------------------------------------// -////PHY identifier register 1, extended register -//#define PHY_IDR1 0x02 //not used -// -////PHY identifier register 2, extended register -//#define PHY_IDR2 0x03 //not used -// -////Auto-negotiation advertisement register, extended register -//#define PHY_ANAR 0x04 //not used -// -////Auto-negotiation link partner ability register, extended register -//#define PHY_ANLPAR 0x05 //not used -// -////Auto-negotiation expansion register, extended register -//#define PHY_ANER 0x06 //not used -// -////Auto-negotiation next page transmit -//#define PHY_ANNP 0x07 //not used -// -////Auto-negotiation link partner of the next page receive -//#define PHY_ANLPNP 0x08 //not used -// -////MMD access control register -//#define PHY_REGCR 0x09 //not used -// -////MMD access address data register -//#define PHY_ADDAR 0x0e //not used -//--------------------------------------Not used-------------------------------------------// - -/********************/ -/* Bit definitions */ -/********************/ - -//For BMCR register -#define BMCR_RESET (1<<15) -#define BMCR_MLOOPBACK (1<<14) -#define BMCR_SPEED (1<<13) -#define BMCR_AUTONEGO (1<<12) -#define BMCR_PWDN (1<<11) -#define BMCR_ISOLATE (1<<10) -#define BMCR_RSTNEGO (1<<9) -#define BMCR_DUP (1<<8) -#define BMCR_COLTEST (1<<7) - -//For BMSR register -#define BMSR_AUTONEGO_COMPL (1<<5) -#define BMSR_REMOTE_FAULT (1<<4) -#define BMSR_LINK_STATUS (1<<2) -#define BMSR_JAB_DETECT (1<<1) -#define EXTENDED_CAPA (1<<0) - -//--------------------------------------Not used-------------------------------------------// -////For ANAR register -//#define ANAR_NP (1<<15) -//#define ANAR_ACK (1<<14) -//#define ANAR_RF (1<<13) -//#define ANAR_ASM (3<<10) -//#define ANAR_T4 (1<<9) -//#define ANAR_TX_FD (1<<8) -//#define ANAR_TX_HD (1<<7) -//#define ANAR_10_FD (1<<6) -//#define ANAR_10_HD (1<<5) -//#define ANAR_SELECTOR (0x1F<<0) -// -////For ANAR register -//#define ANLPAR_NP (1<<15) -//#define ANLPAR_ACK (1<<14) -//#define ANLPAR_RF (1<<13) -//#define ANLPAR_LP_DIR (1<<11) -//#define ANLPAR_PAUSE (1<<10) -//#define ANLPAR_T4 (1<<9) -//#define ANLPAR_TX_FD (1<<8) -//#define ANLPAR_TX_HD (1<<7) -//#define ANLPAR_10_FD (1<<6) -//#define ANLPAR_10_HD (1<<5) -//#define ANLPAR_SELECTOR (0x1F<<0) - -/**/ -/* MDIO register*/ -//PCS_CTL_1 | PCS control 1 register -//PCS_STS_1 | PCS status 1 register -//EEE_ABILITY | EEE capability register -//WAKE_ER_CNTR | EEE wake error counter -//EEE_ADVR | EEE Advertisement register -//EEE_LPAR | EEE link partner ability register - -//--------------------------------------Not used-------------------------------------------// - -/********************/ -/*Functions for PHY */ -/********************/ -//todo move this definition to bit area -#define PHYACR_READ 0x02 -#define PHYACR_WRITE 0x01 - - - - -/** - * @brief Enter a critical section - * - * @details It is provided to protect your shared code which are executed without distribution. \n \n - * - * In non-OS environment, It can be just implemented by disabling whole interrupt.\n - * In OS environment, You can replace it to critical section api supported by OS. - * - * \sa WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF() - * \sa WIZCHIP_CRITICAL_EXIT() - */ -#define WIZCHIP_CRITICAL_ENTER() WIZCHIP.CRIS._enter() - -#ifdef _exit -#undef _exit -#endif - -/** - * @brief Exit a critical section - * - * @details It is provided to protect your shared code which are executed without distribution. \n\n - * - * In non-OS environment, It can be just implemented by disabling whole interrupt. \n - * In OS environment, You can replace it to critical section api supported by OS. - * - * @sa WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF() - * @sa WIZCHIP_CRITICAL_ENTER() - */ -#define WIZCHIP_CRITICAL_EXIT() WIZCHIP.CRIS._exit() - - - -//////////////////////// -// Basic I/O Function // -//////////////////////// -// -//M20150601 : uint16_t AddrSel --> uint32_t AddrSel -// -/** - * @ingroup Basic_IO_function_W5100S - * @brief It reads 1 byte value from a register. - * @param AddrSel Register address - * @return The value of register - */ -uint8_t WIZCHIP_READ (uint32_t AddrSel); - -/** - * @ingroup Basic_IO_function_W5100S - * @brief It writes 1 byte value to a register. - * @param AddrSel Register address - * @param wb Write data - * @return void - */ -void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb ); - -/** - * @ingroup Basic_IO_function_W5100S - * @brief It reads sequence data from registers. - * @param AddrSel Register address - * @param pBuf Pointer buffer to read data - * @param len Data length - */ -void WIZCHIP_READ_BUF (uint32_t AddrSel, uint8_t* pBuf, uint16_t len); - -/** - * @ingroup Basic_IO_function_W5100S - * @brief It writes sequence data to registers. - * @param AddrSel Register address - * @param pBuf Pointer buffer to write data - * @param len Data length - */ -void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len); - - -///////////////////////////////// -// Common Register IO function // -///////////////////////////////// - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set Mode Register - * @param (uint8_t)mr The value to be set. - * @sa getMR() - */ -#if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_) - #define setMR(mr) WIZCHIP_WRITE(MR,mr) -#else - #define setMR(mr) (*((uint8_t*)MR) = mr) -#endif - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get @ref MR. - * @return uint8_t. The value of Mode register. - * @sa setMR() - */ -#if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_) - #define getMR() WIZCHIP_READ(MR) -#else - #define getMR() (*(uint8_t*)MR) -#endif - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set @ref GAR. - * @param (uint8_t*)gar Pointer variable to set gateway IP address. It should be allocated 4 bytes. - * @sa getGAR() - */ -#define setGAR(gar) \ - WIZCHIP_WRITE_BUF(GAR,gar,4) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get @ref GAR. - * @param (uint8_t*)gar Pointer variable to get gateway IP address. It should be allocated 4 bytes. - * @sa setGAR() - */ -#define getGAR(gar) \ - WIZCHIP_READ_BUF(GAR,gar,4) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set @ref SUBR. - * @param (uint8_t*)subr Pointer variable to set subnet mask address. It should be allocated 4 bytes. - * @note If subr is null pointer, set the backup subnet to SUBR. \n - * If subr is 0.0.0.0, back up SUBR and clear it. \n - * Otherwize, set subr to SUBR - * @sa getSUBR() - */ -#define setSUBR(subr) \ - WIZCHIP_WRITE_BUF(SUBR,subr,4) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get @ref SUBR. - * @param (uint8_t*)subr Pointer variable to get subnet mask address. It should be allocated 4 bytes. - * @sa setSUBR() - */ -#define getSUBR(subr) \ - WIZCHIP_READ_BUF(SUBR, subr, 4) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set @ref SHAR. - * @param (uint8_t*)shar Pointer variable to set local MAC address. It should be allocated 6 bytes. - * @sa getSHAR() - */ -#define setSHAR(shar) \ - WIZCHIP_WRITE_BUF(SHAR, shar, 6) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get @ref SHAR. - * @param (uint8_t*)shar Pointer variable to get local MAC address. It should be allocated 6 bytes. - * @sa setSHAR() - */ -#define getSHAR(shar) \ - WIZCHIP_READ_BUF(SHAR, shar, 6) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set @ref SIPR. - * @param (uint8_t*)sipr Pointer variable to set local IP address. It should be allocated 4 bytes. - * @sa getSIPR() -*/ -#define setSIPR(sipr) \ - WIZCHIP_WRITE_BUF(SIPR, sipr, 4) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get @ref SIPR. - * @param (uint8_t*)sipr Pointer variable to get local IP address. It should be allocated 4 bytes. - * @sa setSIPR() - */ -#define getSIPR(sipr) \ - WIZCHIP_READ_BUF(SIPR, sipr, 4) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref IR register - * @param (uint8_t)ir Value to set \ref IR register. - * @sa getIR() - */ -#define setIR(ir) \ - WIZCHIP_WRITE(IR, (ir & 0xE0)) //peter 2016.11.07 unreachable interrupt bit added - //WIZCHIP_WRITE(IR, (ir & 0xA0)) -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref IR register - * @return uint8_t. Value of \ref IR register. - * @sa setIR() - */ -#define getIR() \ - WIZCHIP_READ(IR) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref _IMR_ register - * @param (uint8_t)imr Value to set @ref _IMR_ register. - * @sa getIMR() - */ -#define setIMR(imr) \ - WIZCHIP_WRITE(_IMR_, imr) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref _IMR_ register - * @return uint8_t. Value of @ref _IMR_ register. - * @sa setIMR() - */ -#define getIMR() \ - WIZCHIP_READ(_IMR_) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref _RTR_ register - * @param (uint16_t)rtr Value to set @ref _RTR_ register. - * @sa getRTR() - */ -#define setRTR(rtr) {\ - WIZCHIP_WRITE(_RTR_, (uint8_t)(rtr >> 8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_RTR_,1), (uint8_t) rtr); \ - } - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref _RTR_ register - * @return uint16_t. Value of @ref _RTR_ register. - * @sa setRTR() - */ -#define getRTR() \ - (((uint16_t)WIZCHIP_READ(_RTR_) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_RTR_,1))) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref _RCR_ register - * @param (uint8_t)rcr Value to set @ref _RCR_ register. - * @sa getRCR() - */ -#define setRCR(rcr) \ - WIZCHIP_WRITE(_RCR_, rcr) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref _RCR_ register - * @return uint8_t. Value of @ref _RCR_ register. - * @sa setRCR() - */ -#define getRCR() \ - WIZCHIP_READ(_RCR_) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref RMSR register - * @sa getRMSR() - */ -#define setRMSR(rmsr) \ - WIZCHIP_WRITE(RMSR,rmsr) // Receicve Memory Size - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref RMSR register - * @return uint8_t. Value of @ref RMSR register. - * @sa setRMSR() - */ - #define getRMSR() \ - WIZCHIP_READ(RMSR) // Receicve Memory Size - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref TMSR register - * @sa getTMSR() - */ -#define setTMSR(tmsr) \ - WIZCHIP_WRITE(TMSR,tmsr) // Receicve Memory Size - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref TMSR register - * @return uint8_t. Value of @ref TMSR register. - * @sa setTMSR() - */ -#define getTMSR() \ - WIZCHIP_READ(TMSR) - - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref PATR register - * @return uint16_t. Value to set \ref PATR register - */ -#define getPATR() \ - (((uint16_t)WIZCHIP_READ(PATR) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(PATR,1))) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref PPPALGO register - * @return uint8_t. Value to set \ref PPPALGO register - */ -#define getPPPALGO() \ - WIZCHIP_READ(PPPALGO) - - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref PTIMER register - * @param (uint8_t)ptimer Value to set \ref PTIMER register. - * @sa getPTIMER() - */ -#define setPTIMER(ptimer) \ - WIZCHIP_WRITE(PTIMER, ptimer) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref PTIMER register - * @return uint8_t. Value of @ref PTIMER register. - * @sa setPTIMER() - */ -#define getPTIMER() \ - WIZCHIP_READ(PTIMER) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref PMAGIC register - * @param (uint8_t)pmagic Value to set @ref PMAGIC register. - * @sa getPMAGIC() - */ -#define setPMAGIC(pmagic) \ - WIZCHIP_WRITE(PMAGIC, pmagic) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref PMAGIC register - * @return uint8_t. Value of @ref PMAGIC register. - * @sa setPMAGIC() - */ -#define getPMAGIC() \ - WIZCHIP_READ(PMAGIC) - - -//todo Functions for W5100S - -/*----------------------------------------------------------------------*/ -/* W5100S only */ -/*----------------------------------------------------------------------*/ - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref IR2 register - * @param (uint8_t)ir2 Value to set @ref IR2 register. - * @sa getIR2() - */ -#define setIR2(ir2) \ - WIZCHIP_WRITE(IR2, ir2) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref IR2 register - * @return uint8_t. Value of @ref IR2 register. - * @sa setIR2() - */ -#define getIR2() \ - WIZCHIP_READ(IR2) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref IMR2 register - * @param (uint8_t)imr2 Value to set @ref IMR2 register. - * @sa setIMR2() - */ -#define setIMR2(imr2) \ - WIZCHIP_WRITE(IMR2,imr2) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref IMR2 register - * @return uint8_t. Value of @ref IMR2 register. - * @sa getIMR2() - */ -#define getIMR2() \ - WIZCHIP_READ(IMR2) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref UIPR(Unreachable IP Address Register) registers - * @param (uint8_t*)uipr Value to set @ref UIPR registers. - * @sa setUIPR() - */ -#define setUIPR(uipr) \ - WIZCHIP_WRITE_BUF(UIPR,uipr,4) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref UIPR(Unreachable IP Address Register) registers - * @param (uint8_t*)uipr Value to get @ref UIPR registers - * @sa setUIPR() - */ -#define getUIPR(uipr) \ - WIZCHIP_READ_BUF(UIPR,uipr,4) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref UPORTR(Unreachable Port Address Register) register - * @param (uint16_t)uportr Value to set @ref UPORTR register. - * @sa getUPORTR() - */ -#define setUPORTR(uportr) {\ - WIZCHIP_WRITE(UPORTR, (uint8_t)(uportr >> 8)); \ - WIZCHIP_WRITE(UPORTR+1, (uint8_t) uportr); \ - } - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref UPORTR(Unreachable Port Address Register) register - * @return uint16_t. Value of @ref UPORTR register. - * @sa setUPORTR() - */ -#define getUPORTR() \ - (((uint16_t)WIZCHIP_READ(UPORTR) << 8) + WIZCHIP_READ(UPORTR+1)) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref MR2 register - * @param (uint8_t)mr2 Value to set @ref MR2 registers. - * @sa getMR2() - */ -#define setMR2(mr2) \ - WIZCHIP_WRITE(MR2,mr2) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref MR2 register - * @return uint8_t. Value of @ref MR2 register. - * @sa setMR2() - */ -#define getMR2() \ - WIZCHIP_READ(MR2) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref PHAR registers - * @param (uint8_t*)phar Value to set @ref PHAR registers. - * @sa getPHAR() - */ -#define setPHAR(phar) \ - WIZCHIP_WRITE_BUF(PHAR,phar,6) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref PHAR registers - * @param (uint8_t*)phar Pointer variable to get @ref PHAR registers. - * @sa setPHAR() - */ -#define getPHAR(phar) \ - WIZCHIP_READ_BUF(PHAR,phar,6) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref PSIDR register - * @param (uint16_t)psidr Value to set @ref PSIDR register. - * @sa getPSIDR() - */ -#define setPSIDR(psidr) {\ - WIZCHIP_WRITE(PSIDR, (uint8_t)(psidr >> 8)); \ - WIZCHIP_WRITE(PSIDR+1, (uint8_t) psidr); \ - } - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref PSIDR register - * @return uint16_t. Value of @ref PSIDR register. - * @sa setPSIDR() - */ -#define getPSIDR() \ - (((uint16_t)WIZCHIP_READ(PSIDR) << 8) + WIZCHIP_READ(PSIDR+1)) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref PMRUR register - * @param (uint16_t)pmrur Value to set @ref PMRUR register. - * @sa getPMRUR() - */ -#define setPMRUR(pmrur) {\ - WIZCHIP_WRITE(PMRUR, (uint8_t)(pmrur >> 8)); \ - WIZCHIP_WRITE(PMRUR+1, (uint8_t) pmrur); \ - } - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref PMRUR register - * @return uint16_t. Value of @ref PMRUR register. - * @sa setPMRUR() - */ -#define getPMRUR() \ - (((uint16_t)WIZCHIP_READ(PMRUR) << 8) + WIZCHIP_READ(PMRUR+1)) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref PHYSR register - * @return uint8_t. Value of @ref PHYSR register. - * @sa setPHYSR() - */ -#define getPHYSR() \ - WIZCHIP_READ(PHYSR) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref PHYSR1 register - * @return uint8_t. Value of @ref PHYSR1 register. - * @sa setPHYSR1() - */ -#define getPHYSR1() \ - WIZCHIP_READ(PHYSR1) - -/** - * For internal uses - * The address of the PHY is fixed as "0x0A". - */ -#define getPHYAR() \ - WIZCHIP_READ(PHYAR) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref PHYRAR register - * @return uint8_t. Value of @ref PHYRAR register. - * @sa setPHYRAR() - */ -#define getPHYRAR() \ - WIZCHIP_READ(PHYRAR) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref PHYRR register - * @param (uint8_t)phyrar Value to set @ref PHYRR register. - * @sa getPHYRR() - */ -#define setPHYRR(phyrar) \ - WIZCHIP_WRITE(PHYRAR, phyrar) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref PHYDIR register - * @return uint16_t. Value of @ref PHYDIR register. - * @sa setPHYRAR() - */ -//read the value of the phy data input register -#define getPHYDIR() \ - (((uint16_t)WIZCHIP_READ(PHYDIR+1) << 8) + WIZCHIP_READ(PHYDIR)) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref PHYDIR register - * @param (uint16_t)phydir Value to set @ref PHYDIR register. - * @sa getPHYDIR() - */ -//write the value of the phy data input register -#define setPHYDIR(phydir) {\ - WIZCHIP_WRITE(PHYDIR+1, (uint8_t)(phydir >> 8)); \ - WIZCHIP_WRITE(PHYDIR, (uint8_t) phydir); \ - } - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref PHYDOR register - * @return uint16_t. Value of @ref PHYDOR register. - * @sa setPHYDOR() - */ -//read the value of the phy data output register -#define getPHYDOR() \ - (((uint16_t)WIZCHIP_READ(PHYDOR+1) << 8) + WIZCHIP_READ(PHYDOR)) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref PHYDOR register - * @param (uint16_t)phydor Value to set @ref PHYDOR register. - * @sa getPHYDOR() - */ -//write the value of the phy data output register -#define setPHYDOR(phydor) {\ - WIZCHIP_WRITE(PHYDOR, (uint8_t)(phydor >> 8)); \ - WIZCHIP_WRITE(PHYDOR+1, (uint8_t) phydor); \ - } - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref PHYACR register - * @return uint8_t. Value of @ref PHYACR register. - * @sa setPHYACR() - */ -//read the value of the phy action register ***This register will be cleared automatically*** -#define getPHYACR() \ - WIZCHIP_READ(PHYACR) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref PHYACR register - * @param (uint8_t)phyacr Value to set @ref PHYACR register. - * @sa getPHYACR() - */ -//write the value of the phy action register -#define setPHYACR(phyacr) \ - WIZCHIP_WRITE(PHYACR,phyacr) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref PHYDIVR register - * @param (uint8_t)phydivr Value to set @ref PHYDIVR register. - * @sa getPHYDIVR() - */ -#define setPHYDIVR(phydivr) \ - WIZCHIP_WRITE(PHYDIVR, phydivr) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref PHYDIVR register - * @return uint8_t. Value of @ref PHYDIVR register. - * @sa setPHYDIVR() - */ -#define getPHYDIVR() \ - WIZCHIP_READ(PHYDIVR) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref PHYCR0 register - * @param (uint8_t)phych0 Value to set @ref PHYCR0 register. - * @sa getPHYCR0() - */ -#define setPHYCR0(phych0) \ - WIZCHIP_WRITE(PHYCR0,phych0) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref PHYCR0 register - * @return uint8_t. Value of @ref PHYCR0 register. - * @sa setPHYCR0() - */ -#define getPHYCR0() \ - WIZCHIP_READ(PHYCR0) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref PHYCR1 register - * @param (uint8_t)phycr1 Value to set @ref PHYCR1 register. - * @sa getPHYCR1() - */ -#define setPHYCR1(phycr1) \ - WIZCHIP_WRITE(PHYCR1,phycr1) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref PHYCR1 register - * @return uint8_t. Value of @ref PHYCR1 register. - * @sa setPHYCR1() - */ -#define getPHYCR1() \ - WIZCHIP_READ(PHYCR1) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref SLCR register - * @param (uint8_t)rqcr Value to set @ref SLCR register. - * @sa getSLCR() - */ -#define setSLCR(rqcr) \ - WIZCHIP_WRITE(SLCR, rqcr) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref SLCR register - * @return uint8_t. Value of @ref SLCR register. - * @sa setSLCR() - */ -#define getSLCR() \ - WIZCHIP_READ(SLCR) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref SLRTR register - * @param (uint16_t)slrtr Value to set @ref SLRTR register. - * @sa getSLRTR() - */ -#define setSLRTR(slrtr) \ - WIZCHIP_WRITE(SLRTR, (uint8_t)(slrtr >> 8)); \ - WIZCHIP_WRITE(SLRTR+1, (uint8_t) slrtr); \ - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref SLRTR register - * @return uint16_t. Value of @ref SLRTR register. - * @sa setSLRTR() - */ -#define getSLRTR() \ - (((uint16_t)WIZCHIP_READ(SLRTR) << 8) + WIZCHIP_READ(SLRTR+1)) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref SLRCR register - * @param (uint8_t)slrcr Value to set @ref SLRCR register. - * @sa getSLRCR() - */ -#define setSLRCR(slrcr) \ - WIZCHIP_WRITE(SLRCR,slrcr) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref SLRCR register - * @return uint8_t. Value of @ref SLRCR register. - * @sa setSLRCR() - */ -#define getSLRCR() \ - WIZCHIP_READ(SLRCR) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref SLPIPR registers - * @param (uint8_t*)slpipr Values to set @ref SLPIPR registers. - * @sa getSLPIPR() - */ -#define setSLPIPR(slpipr) \ - WIZCHIP_WRITE_BUF(SLPIPR,slpipr,4) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref SLPIPR registers - * @param (uint8_t*)slpipr Values to get @ref SLPIPR registers. - * @sa getSLPIPR() - */ -#define getSLPIPR(slpipr) \ - WIZCHIP_READ_BUF(SLPIPR,slpipr,4) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref SLPHAR registers - * @param (uint8_t*)slphar Values to set @ref SLPHAR registers. - * @sa getSLPHAR() - */ -#define setSLPHAR(slphar) \ - WIZCHIP_WRITE_BUF(SLPHAR,slphar,6) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref SLPHAR registers - * @param (uint8_t*)slphar Values to get @ref SLPHAR registers. - * @sa getSLPHAR() - */ -#define getSLPHAR(slphar) \ - WIZCHIP_READ_BUF(SLPHAR,slphar,6) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref PINGSEQR register - * @param (uint16_t)pingseqr Value to set @ref PINGSEQR register. - * @sa getPINGSEQR() - */ -#define setPINGSEQR(pingseqr) {\ - WIZCHIP_WRITE(PINGSEQR, (uint8_t)(pingseqr >> 8)); \ - WIZCHIP_WRITE(PINGSEQR+1, (uint8_t) pingseqr); \ - } - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref PINGSEQR register - * @return uint16_t. Value of @ref PINGSEQR register. - * @sa setPINGSEQR() - */ -#define getPINGSEQR() \ - (((uint16_t)WIZCHIP_READ(PINGSEQR) << 8) + WIZCHIP_READ(PINGSEQR+1)) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref PINGIDR register - * @param (uint16_t)pingidr Value to set @ref PINGIDR register. - * @sa getPINGIDR() - */ -#define setPINGIDR(pingidr) {\ - WIZCHIP_WRITE(PINGIDR, (uint8_t)(pingidr >> 8)); \ - WIZCHIP_WRITE(PINGIDR+1, (uint8_t) pingidr); \ - } - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref PINGIDR register - * @return uint16_t. Value of @ref PINGIDR register. - * @sa setPINGIDR() - */ -#define getPINGIDR() \ - (((uint16_t)WIZCHIP_READ(PINGIDR) << 8) + WIZCHIP_READ(PINGIDR+1)) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref SLIMR register - * @param (uint8_t)slimr Value to set @ref SLIMR register. - * @sa getSLIMR() - */ -#define setSLIMR(slimr) \ - WIZCHIP_WRITE(SLIMR, slimr) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref SLIMR register - * @return uint8_t. Value of @ref SLIMR register. - * @sa setSLIMR() - */ -#define getSLIMR() \ - WIZCHIP_READ(SLIMR) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref SLIR register - * @param (uint8_t)slir Value to set @ref SLIR register. - * @sa getSLIMR() - */ -#define setSLIR(slir) \ - WIZCHIP_WRITE(SLIR, slir) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref SLIMR register - * @return uint8_t. Value of @ref SLIMR register. - * @sa setSLIMR() - */ -#define getSLIR() \ - WIZCHIP_READ(SLIR) - -/*Hidden functions for W5100S*/ -#define setDBGOUT(dbgout) {\ - WIZCHIP_WRITE(DBGOUT,(uint8_t)(dbgout >> 16)); \ - WIZCHIP_WRITE(DBGOUT,(uint8_t)(dbgout >> 8)); \ - WIZCHIP_WRITE(DBGOUT,(uint8_t)(dbgout)); \ - } - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref NICMAXCOLR register - * @param (uint8_t)nicmaxcolr Value to set @ref NICMAXCOLR register. - * @sa getNICMAXCOLR() - */ -#define setNICMAXCOLR(nicmaxcolr) \ - WIZCHIP_WRITE(NICMAXCOLR,nicmaxcolr) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref NICMAXCOLR register - * @return uint8_t. Value of @ref NICMAXCOLR register. - * @sa setNICMAXCOLR() - */ -#define getNICMAXCOLR() \ - WIZCHIP_READ(NICMAXCOLR) - -/*Clock lock/unlock*/ - -/** - * @ingroup Common_register_access_function_W5100S - * @brief LOCK Chip Information - * @sa CHIPULLOCK() - */ -#define CHIPLOCK() \ - WIZCHIP_WRITE(CHIPLCKR,0xff) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Unlock Chip Information - * @sa CHIPLOCK() - */ -#define CHIPUNLOCK() \ - WIZCHIP_WRITE(CHIPLCKR,0xCE) - - -/** - * @ingroup Common_register_access_function_W5100S - * @brief LOCK Chip Information - * @sa CHIPULLOCK() - */ -/*Network information lock/unlock*/ -#define NETLOCK() \ - WIZCHIP_WRITE(NETLCKR,0x3A) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Unlock Chip Information - * @sa CHIPLOCK() - */ -#define NETUNLOCK() \ - WIZCHIP_WRITE(NETLCKR,0xC5) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Lock PHYCR0,CR1 Information - * @sa CHIPULLOCK() - */ -/*PHY CR0,CR1 lock/unlock*/ -#define PHYLOCK() \ - WIZCHIP_WRITE(PHYLCKR,0xff) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Lock PHYCR0,CR1 Information - * @sa CHIPULLOCK() - */ -#define PHYUNLOCK() \ - WIZCHIP_WRITE(PHYLCKR,0x53) - -/** - * @ingroup Version register_access_function_W5100SS - * @brief Get version information. - * @return uint16_t. It must be "0x51" - */ -#define getVER() \ - (WIZCHIP_READ(VERR)) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Get \ref TCNTR register - * @return uint16_t. Value of @ref TCNTR register. - * @sa setNTCNTR() - */ -/*Get 100us internal counter*/ -#define getTCNTR() \ - (((uint16_t)WIZCHIP_READ(TCNTR) << 8) + WIZCHIP_READ(TCNTR+1)) - -/** - * @ingroup Common_register_access_function_W5100S - * @brief Set \ref TCNTR register - * @param (uint8_t) - Value to set @ref TCNTR register. - * @sa getTCNTCLKR() - */ -/*Reset 100us internal counter(TCNTR)*/ -#define setTCNTCLKR(var) \ - WIZCHIP_WRITE(TCNTCLKR, var) - -/*w5100s only end*/ - - - - - -/////////////////////////////////// -// Socket N register I/O function // -/////////////////////////////////// -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Set @ref Sn_MR register - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ expect bit 4. - * @param mr Value to set @ref Sn_MR - * @sa getSn_MR() - */ -#define setSn_MR(sn, mr) \ - WIZCHIP_WRITE(Sn_MR(sn),mr) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get @ref Sn_MR register - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ expect bit 4. - * @return Value of @ref Sn_MR. - * @sa setSn_MR() - */ -#define getSn_MR(sn) \ - WIZCHIP_READ(Sn_MR(sn)) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Set @ref Sn_CR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t)cr Value to set @ref Sn_CR - * @sa getSn_CR() - */ -#define setSn_CR(sn, cr) \ - WIZCHIP_WRITE(Sn_CR(sn), cr) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get @ref Sn_CR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of @ref Sn_CR. - * @sa setSn_CR() - */ -#define getSn_CR(sn) \ - WIZCHIP_READ(Sn_CR(sn)) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Set @ref Sn_IR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t)ir Value to set @ref Sn_IR - * @sa getSn_IR() - */ -#define setSn_IR(sn, ir) \ - WIZCHIP_WRITE(Sn_IR(sn), ir) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get @ref Sn_IR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of @ref Sn_IR. - * @sa setSn_IR() - */ -#define getSn_IR(sn) \ - WIZCHIP_READ(Sn_IR(sn)) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get @ref Sn_SR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of @ref Sn_SR. - */ -#define getSn_SR(sn) \ - WIZCHIP_READ(Sn_SR(sn)) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Set @ref Sn_PORT register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint16_t)port Value to set @ref Sn_PORT. - * @sa getSn_PORT() - */ -#define setSn_PORT(sn, port) { \ - WIZCHIP_WRITE(Sn_PORT(sn), (uint8_t)(port >> 8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_PORT(sn),1), (uint8_t) port); \ - } - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get @ref Sn_PORT register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_PORT. - * @sa setSn_PORT() - */ -#define getSn_PORT(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_PORT(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_PORT(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Set @ref Sn_DHAR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t*)dhar Pointer variable to set socket n destination hardware address. It should be allocated 6 bytes. - * @sa getSn_DHAR() - */ -#define setSn_DHAR(sn, dhar) \ - WIZCHIP_WRITE_BUF(Sn_DHAR(sn), dhar, 6) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get @ref Sn_DHAR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t*)dhar Pointer variable to get socket n destination hardware address. It should be allocated 6 bytes. - * @sa setSn_DHAR() - */ -#define getSn_DHAR(sn, dhar) \ - WIZCHIP_READ_BUF(Sn_DHAR(sn), dhar, 6) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Set @ref Sn_DIPR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t*)dipr Pointer variable to set socket n destination IP address. It should be allocated 4 bytes. - * @sa getSn_DIPR() - */ -#define setSn_DIPR(sn, dipr) \ - WIZCHIP_WRITE_BUF(Sn_DIPR(sn), dipr, 4) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get @ref Sn_DIPR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t*)dipr Pointer variable to get socket n destination IP address. It should be allocated 4 bytes. - * @sa SetSn_DIPR() - */ -#define getSn_DIPR(sn, dipr) \ - WIZCHIP_READ_BUF(Sn_DIPR(sn), dipr, 4) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Set @ref Sn_DPORT register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint16_t)dport Value to set @ref Sn_DPORT - * @sa getSn_DPORT() - */ -#define setSn_DPORT(sn, dport) { \ - WIZCHIP_WRITE(Sn_DPORT(sn), (uint8_t) (dport>>8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_DPORT(sn),1), (uint8_t) dport); \ - } - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get @ref Sn_DPORT register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_DPORT. - * @sa setSn_DPORT() - */ -#define getSn_DPORT(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_DPORT(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_DPORT(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Set @ref Sn_MSSR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint16_t)mss Value to set @ref Sn_MSSR - * @sa setSn_MSSR() - */ -#define setSn_MSSR(sn, mss) { \ - WIZCHIP_WRITE(Sn_MSSR(sn), (uint8_t)(mss>>8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_MSSR(sn),1), (uint8_t) mss); \ - } - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get @ref Sn_MSSR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_MSSR. - * @sa setSn_MSSR() - */ -#define getSn_MSSR(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_MSSR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_MSSR(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Set @ref Sn_PROTO register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t)proto Value to set \ref Sn_PROTO - * @sa getSn_PROTO() - */ -#define setSn_PROTO(sn, proto) \ - WIZCHIP_WRITE(Sn_PROTO(sn), proto) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get @ref Sn_PROTO register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of @ref Sn_PROTO. - * @sa setSn_PROTO() - */ -#define getSn_PROTO(sn) \ - WIZCHIP_READ(Sn_PROTO(sn)) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Set @ref Sn_TOS register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t)tos Value to set @ref Sn_TOS - * @sa getSn_TOS() - */ -#define setSn_TOS(sn, tos) \ - WIZCHIP_WRITE(Sn_TOS(sn), tos) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get @ref Sn_TOS register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ . - * @return uint8_t. Value of Sn_TOS. - * @sa setSn_TOS() - */ -#define getSn_TOS(sn) \ - WIZCHIP_READ(Sn_TOS(sn)) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Set @ref Sn_TTL register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ . - * @param (uint8_t)ttl Value to set @ref Sn_TTL - * @sa getSn_TTL() - */ -#define setSn_TTL(sn, ttl) \ - WIZCHIP_WRITE(Sn_TTL(sn), ttl) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get @ref Sn_TTL register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ . - * @return uint8_t. Value of @ref Sn_TTL. - * @sa setSn_TTL() - */ -#define getSn_TTL(sn) \ - WIZCHIP_READ(Sn_TTL(sn)) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Set @ref Sn_RXMEM_SIZE register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ . - * @param (uint8_t)rxmemsize Value to set \ref Sn_RXMEM_SIZE - * @sa getSn_RXMEM_SIZE() - */ -#define setSn_RXMEM_SIZE(sn, rxmemsize) \ - WIZCHIP_WRITE(RMSR, (WIZCHIP_READ(RMSR) & ~(0x03 << (2*sn))) | (rxmemsize << (2*sn))) -#define setSn_RXBUF_SIZE(sn,rxmemsize) setSn_RXMEM_SIZE(sn,rxmemsize) -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get @ref Sn_RXMEM_SIZE register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of @ref Sn_RXMEM. - * @sa setSn_RXMEM_SIZE() - */ -#define getSn_RXMEM_SIZE(sn) \ - ((WIZCHIP_READ(RMSR) & (0x03 << (2*sn))) >> (2*sn)) -#define getSn_RXBUF_SIZE(sn) getSn_RXMEM_SIZE(sn) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Set @ref Sn_TXMEM_SIZE register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t)txmemsize Value to set \ref Sn_TXMEM_SIZE - * @sa getSn_TXMEM_SIZE() - */ -#define setSn_TXMEM_SIZE(sn, txmemsize) \ - WIZCHIP_WRITE(TMSR, (WIZCHIP_READ(TMSR) & ~(0x03 << (2*sn))) | (txmemsize << (2*sn))) -#define setSn_TXBUF_SIZE(sn, txmemsize) setSn_TXMEM_SIZE(sn,txmemsize) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get @ref Sn_TXMEM_SIZE register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of @ref Sn_TXMEM_SIZE. - * @sa setSn_TXMEM_SIZE() - */ -#define getSn_TXMEM_SIZE(sn) \ - ((WIZCHIP_READ(TMSR) & (0x03 << (2*sn))) >> (2*sn)) -#define getSn_TXBUF_SIZE(sn) getSn_TXMEM_SIZE(sn) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get @ref Sn_TX_FSR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_TX_FSR. - */ -uint16_t getSn_TX_FSR(uint8_t sn); - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get @ref Sn_TX_RD register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_TX_RD. - */ -#define getSn_TX_RD(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_TX_RD(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_RD(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Set @ref Sn_TX_WR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint16_t)txwr Value to set @ref Sn_TX_WR - * @sa GetSn_TX_WR() - */ -#define setSn_TX_WR(sn, txwr) { \ - WIZCHIP_WRITE(Sn_TX_WR(sn), (uint8_t)(txwr>>8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_TX_WR(sn),1), (uint8_t) txwr); \ - } - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get @ref Sn_TX_WR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_TX_WR. - * @sa setSn_TX_WR() - */ -#define getSn_TX_WR(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_TX_WR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_WR(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get @ref Sn_RX_RSR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_RX_RSR. - */ -uint16_t getSn_RX_RSR(uint8_t sn); - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Set @ref Sn_RX_RD register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint16_t)rxrd Value to set @ref Sn_RX_RD - * @sa getSn_RX_RD() - */ -#define setSn_RX_RD(sn, rxrd) { \ - WIZCHIP_WRITE(Sn_RX_RD(sn), (uint8_t)(rxrd>>8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_RX_RD(sn),1), (uint8_t) rxrd); \ - } - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get @ref Sn_RX_RD register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @regurn uint16_t. Value of @ref Sn_RX_RD. - * @sa setSn_RX_RD() - */ -#define getSn_RX_RD(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_RX_RD(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RD(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Set @ref Sn_RX_WR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint16_t)rxwr Value to set \ref Sn_RX_WR - * @sa getSn_RX_WR() - */ -#define setSn_RX_WR(sn, rxwr) { \ - WIZCHIP_WRITE(Sn_RX_WR(sn), (uint8_t)(rxwr>>8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_RX_WR(sn),1), (uint8_t) rxwr); \ - } - - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get @ref Sn_RX_WR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_RX_WR. - */ -#define getSn_RX_WR(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_RX_WR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_WR(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Set @ref Sn_FRAGR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint16_t)frag Value to set \ref Sn_FRAGR - * @sa getSn_FRAG() - */ -#define setSn_FRAGR(sn, fragr) { \ - WIZCHIP_WRITE(Sn_FRAGR(sn), (uint8_t)(fragr >>8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_FRAGR(sn),1), (uint8_t) fragr); \ - } - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get @ref Sn_FRAGR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_FRAGR. - * @sa setSn_FRAG() - */ -#define getSn_FRAGR(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_FRAGR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_FRAGR(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get the max RX buffer size of socket sn - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Max buffer size - */ -#define getSn_RxMAX(sn) \ - ((uint16_t)(0x0001 << getSn_RXMEM_SIZE(sn)) << 10) - - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get the max TX buffer size of socket sn - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Max buffer size - */ -#define getSn_TxMAX(sn) \ - ((uint16_t)(0x0001 << getSn_TXMEM_SIZE(sn)) << 10) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get the mask of socket sn RX buffer. - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Mask value - */ -#define getSn_RxMASK(sn) \ - (getSn_RxMAX(sn) - 1) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get the mask of socket sn TX buffer - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Mask value - */ -#define getSn_TxMASK(sn) \ - (getSn_TxMAX(sn) - 1) - - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get the base address of socket sn RX buffer. - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of Socket n RX buffer base address. - */ -uint32_t getSn_RxBASE(uint8_t sn); - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get the base address of socket sn TX buffer. - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of Socket n TX buffer base address. - */ -uint32_t getSn_TxBASE(uint8_t sn); - - -/*socket register W5100S only*/ - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Set the interrupt mask register of socket sn. - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint16_t)imr Value to set \ref Sn_IMR - * @sa getSn_IMR(sn) - */ -#define setSn_IMR(sn,imr) \ - WIZCHIP_WRITE(Sn_IMR(sn),imr) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get the interrupt mask register of socket sn. - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of Socket n interrupt mask register. - */ -#define getSn_IMR(sn) \ - WIZCHIP_READ(Sn_IMR(sn)) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Set the Sn_MR2 value of socket sn. - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param mr2 Value of Sn_MR2 register to set. - */ -#define setSn_MR2(sn,mr2) \ - WIZCHIP_WRITE(Sn_MR2(sn), mr2) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get the Sn_MR2 value of socket sn. - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of Socket n Sn_MR2 register. - */ -#define getSn_MR2(sn) \ - WIZCHIP_READ(Sn_MR2(sn)) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Set the Sn_KPALVTR value of socket sn. - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param kpalvtr Value of the Sn_KPALVTR register to set. - */ -#define setSn_KPALVTR(sn,kpalvtr) \ - WIZCHIP_WRITE(Sn_KPALVTR(sn), kpalvtr) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get the Sn_KPALVTR value of socket sn - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of the Sn_KPALVTR register. - */ -#define getSn_KPALVTR(sn) \ - WIZCHIP_READ(Sn_KPALVTR(sn)) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get the Sn_TSR register of socket sn. - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of the Socket n Sn_TSR register. - */ -#define getSn_TSR(sn) \ - WIZCHIP_READ(Sn_TSR(sn)) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Set the Sn_RTR register of socket sn. - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint16_t)rtr Value of the Socket n Sn_RTR register to set. - */ -#define setSn_RTR(sn,rtr) { \ - WIZCHIP_WRITE(Sn_RTR(sn), (uint8_t)(rtr >> 8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_RTR(sn),1), (uint8_t) rtr); \ - } - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get the Sn_RTR register of socket sn. - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of the Socket n Sn_RTR register. - */ -#define getSn_RTR(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_RTR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RTR(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Set the Sn_RCR register of socket sn. - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of the Socket n Sn_RCR register to set. - */ -#define setSn_RCR(sn,rcr) \ - WIZCHIP_WRITE(Sn_RCR(sn),rcr) - -/** - * @ingroup Socket_register_access_function_W5100S - * @brief Get the Sn_RCR of socket sn. - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of the Socket n Sn_RCR. - */ -#define getSn_RCR(sn) \ - WIZCHIP_READ(Sn_RCR(sn)) - -///////////////////////////////////// -// Sn_TXBUF & Sn_RXBUF IO function // -///////////////////////////////////// -/** - * @ingroup Basic_IO_function_W5100S - * @brief It copies data to internal TX memory - * - * @details This function reads the Tx write pointer register and after that, - * it copies the wizdata(pointer buffer) of the length of len(variable) bytes to internal TX memory - * and updates the Tx write pointer register. - * This function is being called by send() and sendto() function also. - * - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param wizdata Pointer buffer to write data - * @param len Data length - * @sa wiz_recv_data() - */ -void wiz_send_data(uint8_t sn, uint8_t *wizdata, uint16_t len); - -/** - * @ingroup Basic_IO_function_W5100S - * @brief It copies data to your buffer from internal RX memory - * - * @details This function read the Rx read pointer register and after that, - * it copies the received data from internal RX memory - * to wizdata(pointer variable) of the length of len(variable) bytes. - * This function is being called by recv() also. - * - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param wizdata Pointer buffer to read data - * @param len Data length - * @sa wiz_send_data() - */ -void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint16_t len); - -/** - * @ingroup Basic_IO_function_W5100S - * @brief It discard the received data in RX memory. - * @details It discards the data of the length of len(variable) bytes in internal RX memory. - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param len Data length - */ -void wiz_recv_ignore(uint8_t sn, uint16_t len); - -/** - * @ingroup Special_function_W5100S - * @brief Write data to the PHY via MDC/MDIO interface. - * @details Write command data to the PHY via MDC/MDIO interface. - * @param (uint8_t)PHYMDIO_regadr Address of the PHY register. It should be PHYMDIO_BMCR or PHYMDIO_BMSR. - * @param (uint16_t)var Data to write to the PHY register. Please refer to the bit definitions of the BMCR and BMSR register. - */ -void wiz_mdio_write(uint8_t PHYMDIO_regadr, uint16_t var); - -/** - * @ingroup Special_function_W5100S - * @brief Read data from the PHY via MDC/MDIO interface. - * @details Read command or status data from the PHY via MDC/MDIO interface. - * @param (uint8_t)PHYMDIO_regadr Address of the PHY register. It should be PHYMDIO_BMCR or PHYMDIO_BMSR. - * @return The value of the PHY register - */ -uint16_t wiz_mdio_read(uint8_t PHYMDIO_regadr); - -/** - * @ingroup Special_function_W5100S - * @brief Delay function - * @details Delay function using internal 100us timer of the W5100S - * @param (uint32_t)ms Time to delay in milliseconds. - */ -void wiz_delay_ms(uint32_t ms); - -/// @cond DOXY_APPLY_CODE -#endif -/// @endcond - -#ifdef __cplusplus -} -#endif - -#endif //_W5100S_H_ - - - diff --git a/lib/ioLibrary_Driver/W5200/w5200.c b/lib/ioLibrary_Driver/W5200/w5200.c deleted file mode 100644 index 52bd5f5..0000000 --- a/lib/ioLibrary_Driver/W5200/w5200.c +++ /dev/null @@ -1,353 +0,0 @@ -//***************************************************************************** -// -//! \file w5200.c -//! \brief W5200 HAL Interface. -//! \version 1.0.0 -//! \date 2013/10/21 -//! \par Revision history -//! <2013/10/21> 1st Release -//! \author MidnightCow -//! -//! 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 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 "w5200.h" - -#if (_WIZCHIP_ == 5200) -/** -@brief This function writes the data into W5200 registers. -*/ -void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb ) -{ - WIZCHIP_CRITICAL_ENTER(); - WIZCHIP.CS._select(); - -#if( (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_)) - WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8); - WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0); - WIZCHIP.IF.SPI._write_byte(_W5200_SPI_WRITE_); // Data write command and Write data length upper - WIZCHIP.IF.SPI._write_byte(0x01); // Write data length lower - WIZCHIP.IF.SPI._write_byte(wb); // Data write (write 1byte data) - -#elif ( (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_) ) - - //add indirect bus - //M20150601 : Rename the function for integrating with W5300 - //WIZCHIP.IF.BUS._write_byte(IDM_AR0,(AddrSel & 0x0000FF00) >> 8); - //WIZCHIP.IF.BUS._write_byte(IDM_AR1,(AddrSel & 0x000000FF)); - //WIZCHIP.IF.BUS._write_byte(IDM_DR,wb); - WIZCHIP.IF.BUS._write_data(IDM_AR0,(AddrSel & 0x0000FF00) >> 8); - WIZCHIP.IF.BUS._write_data(IDM_AR1,(AddrSel & 0x000000FF)); - WIZCHIP.IF.BUS._write_data(IDM_DR,wb); - -#else - #error "Unknown _WIZCHIP_IO_MODE_ in W5200. !!!" -#endif - - WIZCHIP.CS._deselect(); - WIZCHIP_CRITICAL_EXIT(); -} -/** -@brief This function reads the value from W5200 registers. -*/ -uint8_t WIZCHIP_READ(uint32_t AddrSel) -{ - uint8_t ret; - - WIZCHIP_CRITICAL_ENTER(); - WIZCHIP.CS._select(); - -#if( (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_)) - WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8); - WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0); - WIZCHIP.IF.SPI._write_byte(_W5200_SPI_READ_); // Read data length upper - WIZCHIP.IF.SPI._write_byte(0x01); // Data length lower - ret = WIZCHIP.IF.SPI._read_byte(); - -#elif ( (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_) ) - - //add indirect bus - //M20150601 : Rename the function for integrating with W5300 - //WIZCHIP.IF.BUS._write_byte(IDM_AR0,(AddrSel & 0x0000FF00) >> 8); - //WIZCHIP.IF.BUS._write_byte(IDM_AR1,(AddrSel & 0x000000FF)); - //ret = WIZCHIP.IF.BUS._read_byte(IDM_DR); - WIZCHIP.IF.BUS._write_data(IDM_AR0,(AddrSel & 0x0000FF00) >> 8); - WIZCHIP.IF.BUS._write_data(IDM_AR1,(AddrSel & 0x000000FF)); - ret = WIZCHIP.IF.BUS._read_data(IDM_DR); - -#else - #error "Unknown _WIZCHIP_IO_MODE_ in W5200. !!!" -#endif - - WIZCHIP.CS._deselect(); - WIZCHIP_CRITICAL_EXIT(); - return ret; -} - - -/** -@brief This function writes into W5200 memory(Buffer) -*/ -void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len) -{ - uint16_t i = 0; - WIZCHIP_CRITICAL_ENTER(); - WIZCHIP.CS._select(); - -#if( (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_)) - WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8); - WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0); - WIZCHIP.IF.SPI._write_byte(_W5200_SPI_WRITE_ | ((len & 0x7F00) >> 8)); // Write data op code and length upper - WIZCHIP.IF.SPI._write_byte((len & 0x00FF) >> 0); // length lower - for(i = 0; i < len; i++) - WIZCHIP.IF.SPI._write_byte(pBuf[i]); - -#elif ( (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_) ) - //M20150601 : Rename the function for integrating with W5300 - /* - WIZCHIP_WRITE(MR,WIZCHIP_READ(MR) | MR_AI); - WIZCHIP.IF.BUS._write_byte(IDM_AR0,(AddrSel & 0x0000FF00) >> 8); - WIZCHIP.IF.BUS._write_byte(IDM_AR1,(AddrSel & 0x000000FF)); - 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 & 0x0000FF00) >> 8); - WIZCHIP.IF.BUS._write_data(IDM_AR1,(AddrSel & 0x000000FF)); - for(i = 0 ; i < len; i++) - WIZCHIP.IF.BUS._write_data(IDM_DR,pBuf[i]); - WIZCHIP_WRITE(MR, WIZCHIP_READ(MR) & ~MR_AI); -#else - #error "Unknown _WIZCHIP_IO_MODE_ in W5200. !!!!" -#endif - - WIZCHIP.CS._deselect(); - WIZCHIP_CRITICAL_EXIT(); -} - -/** -@brief This function reads into W5200 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(); - -#if( (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_)) - WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8); - WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0); - WIZCHIP.IF.SPI._write_byte( _W5200_SPI_READ_ | ((len & 0x7F00) >> 8)); // Write data op code and length upper - WIZCHIP.IF.SPI._write_byte((len & 0x00FF) >> 0); // length lower - for(i = 0; i < len; i++) - pBuf[i] = WIZCHIP.IF.SPI._read_byte(); - -#elif ( (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_) ) - //M20150601 : Rename the function for integrating with W5300 - /* - WIZCHIP_WRITE(MR, WIZCHIP_READ(MR) | MR_AI); - WIZCHIP.IF.BUS._write_byte(IDM_AR0,(AddrSel & 0x0000FF00) >> 8); - WIZCHIP.IF.BUS._write_byte(IDM_AR1,(AddrSel & 0x000000FF)); - 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 & 0x0000FF00) >> 8); - WIZCHIP.IF.BUS._write_data(IDM_AR1,(AddrSel & 0x000000FF)); - 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 W5200. !!!!" -#endif - - WIZCHIP.CS._deselect(); - 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 // -///////////////////////////////////// - -uint16_t getSn_RxBASE(uint8_t sn) -{ - int8_t i; - uint16_t rxbase = _WIZCHIP_IO_RXBUF_; - for(i = 0; i < sn; i++) - rxbase += getSn_RxMAX(i); - return rxbase; -} - -uint16_t getSn_TxBASE(uint8_t sn) -{ - int8_t i; - uint16_t txbase = _WIZCHIP_IO_TXBUF_; - 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; - uint8_t * dst_ptr; - - ptr = getSn_TX_WR(sn); - - - dst_mask = (uint32_t)ptr & getSn_TxMASK(sn); - dst_ptr = (uint8_t*)((uint32_t)getSn_TxBASE(sn) + dst_mask); - - if (dst_mask + len > getSn_TxMAX(sn)) - { - size = getSn_TxMAX(sn) - dst_mask; - WIZCHIP_WRITE_BUF((uint32_t)dst_ptr, wizdata, size); - wizdata += size; - size = len - size; - dst_ptr = (uint8_t*)((uint32_t)getSn_TxBASE(sn)); - WIZCHIP_WRITE_BUF((uint32_t)dst_ptr, wizdata, size); - } - else - { - WIZCHIP_WRITE_BUF((uint32_t)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; - uint8_t * src_ptr; - - ptr = getSn_RX_RD(sn); - - src_mask = (uint32_t)ptr & getSn_RxMASK(sn); - src_ptr = (uint8_t *)((uint32_t)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 = (uint8_t*)((uint32_t)getSn_RxBASE(sn)); - WIZCHIP_READ_BUF((uint32_t)src_ptr, (uint8_t*)wizdata, size); - } - else - { - WIZCHIP_READ_BUF((uint32_t)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); -} - -#endif diff --git a/lib/ioLibrary_Driver/W5200/w5200.h b/lib/ioLibrary_Driver/W5200/w5200.h deleted file mode 100644 index 0fcfe3e..0000000 --- a/lib/ioLibrary_Driver/W5200/w5200.h +++ /dev/null @@ -1,2110 +0,0 @@ -//* **************************************************************************** -//! \file w5200.h -//! \brief W5200 HAL Header File. -//! \version 1.0.0 -//! \date 2015/03/23 -//! \par Revision history -//! <2013/10/21> 1st Release -//! \author MidnightCow -//! \copyright -//! -//! 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 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. -// -//***************************************************************************** - -#ifndef _W5200_H -#define _W5200_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include "wizchip_conf.h" - -/// \cond DOXY_APPLY_CODE -#if (_WIZCHIP_ == 5200) -/// \endcond - -#define _WIZCHIP_SN_BASE_ (0x4000) -#define _WIZCHIP_SN_SIZE_ (0x0100) -#define _WIZCHIP_IO_TXBUF_ (0x8000) /* Internal Tx buffer address of the iinchip */ -#define _WIZCHIP_IO_RXBUF_ (0xC000) /* Internal Rx buffer address of the iinchip */ - -#define _W5200_SPI_READ_ (0x00 << 7) ///< SPI interface Read operation in Control Phase -#define _W5200_SPI_WRITE_ (0x01 << 7) ///< SPI interface Write operation in Control Phase - -#define WIZCHIP_CREG_BLOCK 0x00 ///< Common register block -#define WIZCHIP_SREG_BLOCK(N) (_WIZCHIP_SN_BASE_+ _WIZCHIP_SN_SIZE_*N) ///< Socket N register block - -#define WIZCHIP_OFFSET_INC(ADDR, N) (ADDR + N) ///< Increase offset address - -#if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_) - #define IDM_AR0 ((_WIZCHIP_IO_BASE_ + 0x0001)) - #define IDM_AR1 ((_WIZCHIP_IO_BASE_ + 0x0002)) - #define IDM_DR ((_WIZCHIP_IO_BASE_ + 0x0003)) - #define _W5200_IO_BASE_ 0x0000 -#elif (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_) - #define _W5200_IO_BASE_ 0x0000 -#endif - -/////////////////////////////////////// -// Definition For Legacy Chip Driver // -/////////////////////////////////////// -#define IINCHIP_READ(ADDR) WIZCHIP_READ(ADDR) ///< The defined for legacy chip driver -#define IINCHIP_WRITE(ADDR,VAL) WIZCHIP_WRITE(ADDR,VAL) ///< The defined for legacy chip driver -#define IINCHIP_READ_BUF(ADDR,BUF,LEN) WIZCHIP_READ_BUF(ADDR,BUF,LEN) ///< The defined for legacy chip driver -#define IINCHIP_WRITE_BUF(ADDR,BUF,LEN) WIZCHIP_WRITE(ADDR,BUF,LEN) ///< The defined for legacy chip driver - - -//----------- defgroup -------------------------------- - -/** - * @defgroup W5200 W5200 - * @brief WHIZCHIP register defines and I/O functions of @b W5200. - * - * - @ref WIZCHIP_register_W5200 : @ref Common_register_group_W5200 and @ref Socket_register_group_W5200 - * - @ref WIZCHIP_IO_Functions_W5200 : @ref Basic_IO_function_W5200, @ref Common_register_access_function_W5200 and @ref Socket_register_group_W5200 - */ - - /** - * @defgroup WIZCHIP_register_W5200 WIZCHIP register - * @ingroup W5200 - * @brief WIZCHIP register defines register group of W5200 . - * - * - \ref Common_register_group_W5200 : Common register group w5200 - * - \ref Socket_register_group_W5200 : \c SOCKET n register group w5200 - */ - - -/** - * @defgroup WIZCHIP_IO_Functions_W5200 WIZCHIP I/O functions - * @ingroup W5200 - * @brief This supports the basic I/O functions for \ref WIZCHIP_register_W5200. - * - * - Basic I/O function \n - * WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF() \n\n - * - * - \ref Common_register_group_W5200 access functions \n - * -# @b Mode \n - * getMR(), setMR() - * -# @b Interrupt \n - * getIR(), setIR(), getIMR(), setIMR(), getIR2(), setIR2(), getIMR2(), setIMR2(), getINTLEVEL(), setINTLEVEL() - * -# Network Information \n - * getSHAR(), setSHAR(), getGAR(), setGAR(), getSUBR(), setSUBR(), getSIPR(), setSIPR() - * -# @b Retransmission \n - * getRCR(), setRCR(), getRTR(), setRTR() - * -# @b PPPoE \n - * getPTIMER(), setPTIMER(), getPMAGIC(), getPMAGIC() - * -# @b etc. \n - * getPHYSTATUS(), getVERSIONR() \n\n - * - * - \ref Socket_register_group_W5200 access functions \n - * -# SOCKET control \n - * getSn_MR(), setSn_MR(), getSn_CR(), setSn_CR(), getSn_IMR(), setSn_IMR(), getSn_IR(), setSn_IR() - * -# SOCKET information \n - * getSn_SR(), getSn_DHAR(), setSn_DHAR(), getSn_PORT(), setSn_PORT(), getSn_DIPR(), setSn_DIPR(), getSn_DPORT(), setSn_DPORT() - * getSn_MSSR(), setSn_MSSR() - * -# SOCKET communication \n - * getSn_RXMEM_SIZE(), setSn_RXMEM_SIZE(), getSn_TXMEM_SIZE(), setSn_TXMEM_SIZE() \n - * getSn_TX_RD(), getSn_TX_WR(), setSn_TX_WR() \n - * getSn_RX_RD(), setSn_RX_RD(), getSn_RX_WR() \n - * getSn_TX_FSR(), getSn_RX_RSR() - * -# IP header field \n - * getSn_FRAG(), setSn_FRAG(), getSn_TOS(), setSn_TOS() \n - * getSn_TTL(), setSn_TTL() - */ - -/** - * @defgroup Common_register_group_W5200 Common register - * @ingroup WIZCHIP_register_W5200 - * @brief Common register group\n - * It set the basic for the networking\n - * It set the configuration such as interrupt, network information, ICMP, etc. - * @details - * @sa MR : Mode register. - * @sa GAR, SUBR, SHAR, SIPR - * @sa INTLEVEL, IR, _IMR_, IR2, IMR2 : Interrupt. - * @sa _RTR_, _RCR_ : Data retransmission. - * @sa PTIMER, PMAGIC : PPPoE. - * @sa PHYSTATUS, VERSIONR : etc. - */ - - - /** - * @defgroup Socket_register_group_W5200 Socket register - * @ingroup WIZCHIP_register_W5200 - * @brief Socket register group\n - * Socket register configures and control SOCKETn which is necessary to data communication. - * @details - * @sa Sn_MR, Sn_CR, Sn_IR, Sn_IMR : SOCKETn Control - * @sa Sn_SR, Sn_PORT, Sn_DHAR, Sn_DIPR, Sn_DPORT : SOCKETn Information - * @sa Sn_MSSR, Sn_TOS, Sn_TTL, Sn_FRAG : Internet protocol. - * @sa Sn_RXMEM_SIZE, Sn_TXMEM_SIZE, Sn_TX_FSR, Sn_TX_RD, Sn_TX_WR, Sn_RX_RSR, Sn_RX_RD, Sn_RX_WR : Data communication - */ - - /** - * @defgroup Basic_IO_function_W5200 Basic I/O function - * @ingroup WIZCHIP_IO_Functions_W5200 - * @brief These are basic input/output functions to read values from register or write values to register. - */ - -/** - * @defgroup Common_register_access_function_W5200 Common register access functions - * @ingroup WIZCHIP_IO_Functions_W5200 - * @brief These are functions to access common registers. - */ - -/** - * @defgroup Socket_register_access_function_W5200 Socket register access functions - * @ingroup WIZCHIP_IO_Functions_W5200 - * @brief These are functions to access socket registers. - */ - - //----------------------------------------------------------------------------------- - -//----------------------------- W5200 Common Registers IOMAP ----------------------------- -/** - * @ingroup Common_register_group_W5200 - * @brief Mode Register address(R/W)\n - * \ref MR is used for S/W reset, ping block mode, PPPoE mode and etc. - * @details Each bit of \ref MR defined as follows. - * - * - * - *
7 6 5 4 3 2 1 0
RST Reserved WOL PB PPPoE Reserved AI IND
- * - \ref MR_RST : Reset - * - \ref MR_WOL : Wake on LAN - * - \ref MR_PB : Ping block - * - \ref MR_PPPOE : PPPoE mode - * - \ref MR_AI : Address Auto-Increment in Indirect Bus Interface - * - \ref MR_IND : Indirect Bus Interface mode - */ -#if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_) - #define MR (_WIZCHIP_IO_BASE_ + (0x0000)) // Mode -#else - #define MR (_W5200_IO_BASE_ + (0x0000)) // Mode -#endif - -/** - * @ingroup Common_register_group_W5200 - * @brief Gateway IP Register address(R/W) - * @details \ref GAR configures the default gateway address. - */ -#define GAR (_W5200_IO_BASE_ + (0x0001)) // GW Address - -/** - * @ingroup Common_register_group_W5200 - * @brief Subnet mask Register address(R/W) - * @details \ref SUBR configures the subnet mask address. - */ -#define SUBR (_W5200_IO_BASE_ + (0x0005)) // SN Mask Address - -/** - * @ingroup Common_register_group_W5200 - * @brief Source MAC Register address(R/W) - * @details \ref SHAR configures the source hardware address. - */ -#define SHAR (_W5200_IO_BASE_ + (0x0009)) // Source Hardware Address - -/** - * @ingroup Common_register_group_W5200 - * @brief Source IP Register address(R/W) - * @details \ref SIPR configures the source IP address. - */ -#define SIPR (_W5200_IO_BASE_ + (0x000F)) // Source IP Address - -// Reserved (_W5200_IO_BASE_ + (0x0013)) -// Reserved (_W5200_IO_BASE_ + (0x0014)) - -/** - * @ingroup Common_register_group_W5200 - * @brief Interrupt Register(R/W) - * @details \ref IR indicates the interrupt status. Each bit of \ref IR will be still until the bit will be written to by the host. - * If \ref IR is not equal to x00 INTn PIN is asserted to low until it is x00\n\n - * Each bit of \ref IR defined as follows. - * - * - * - *
7 6 5 4 3 2 1 0
CONFLICT Reserved PPPoE Reserved Reserved Reserved Reserved Reserved
- * - \ref IR_CONFLICT : IP conflict - * - \ref IR_PPPoE : PPPoE connection close - */ -#define IR (_W5200_IO_BASE_ + (0x0015)) // Interrupt - -/** - * @ingroup Common_register_group_W5200 - * @brief Socket Interrupt Mask Register(R/W) - * @details Each bit of \ref _IMR_ corresponds to each bit of \ref IR2. - * When a bit of \ref _IMR_ is and the corresponding bit of \ref IR2 is Interrupt will be issued. - * In other words, if a bit of \ref _IMR_, an interrupt will be not issued even if the corresponding bit of \ref IR2 is set - * @note This Register is same operated as SMIR of W5100, W5300 and W5550.\n - * So, \ref setSIMR() set a value to _IMR_ for integrating with ioLibrary - */ -#define _IMR_ (_W5200_IO_BASE_ + (0x0016)) // Socket Interrupt Mask - -/** - * @ingroup Common_register_group_W5200 - * @brief Timeout register address( 1 is 100us )(R/W) - * @details \ref _RTR_ configures the retransmission timeout period. The unit of timeout period is 100us and the default of \ref _RTR_ is x07D0. - * And so the default timeout period is 200ms(100us X 2000). During the time configured by \ref _RTR_, W5200 waits for the peer response - * to the packet that is transmitted by \ref Sn_CR (CONNECT, DISCON, CLOSE, SEND, SEND_MAC, SEND_KEEP command). - * If the peer does not respond within the \ref _RTR_ time, W5200 retransmits the packet or issues timeout. - */ -#define _RTR_ (_W5200_IO_BASE_ + (0x0017)) // Retry Time - -/** - * @ingroup Common_register_group_W5200 - * @brief Retry count register(R/W) - * @details \ref _RCR_ configures the number of time of retransmission. - * When retransmission occurs as many as ref _RCR_+1 Timeout interrupt is issued (\ref Sn_IR_TIMEOUT = '1'). - */ -#define _RCR_ (_W5200_IO_BASE_ + (0x0019)) // Retry Count - -// Reserved (_W5200_IO_BASE_ + (0x001A)) -// Reserved (_W5200_IO_BASE_ + (0x001B)) - -/** - * @ingroup Common_register_group_W5200 - * @brief PPP LCP Request Timer register in PPPoE mode(R) - * @details \ref PATR notifies authentication method that has been agreed at the connection with - * PPPoE Server. W5200 supports two types of Authentication method - PAP and CHAP. - */ -#define PATR (_W5200_IO_BASE_ + (0x001C)) - -/** - * @ingroup Common_register_group_W5200 - * @brief PPP LCP Request Timer register in PPPoE mode(R) - * @details \ref PPPALGO notifies authentication algorithm in PPPoE mode. For detailed information, - * please refer to PPPoE application note. - */ -#define PPPALGO (_W5200_IO_BASE_ + (0x001E)) // Authentication Algorithm in PPPoE - -/** - * @ingroup Common_register_group_W5200 - * @brief chip version register address(R) - * @details \ref VERSIONR always indicates the W5200 version as @b 0x03. - */ -#define VERSIONR (_W5200_IO_BASE_ + (0x001F)) // Chip version - -// Reserved (_W5200_IO_BASE_ + (0x0020)) -// Reserved (_W5200_IO_BASE_ + (0x0021)) -// Reserved (_W5200_IO_BASE_ + (0x0022)) -// Reserved (_W5200_IO_BASE_ + (0x0023)) -// Reserved (_W5200_IO_BASE_ + (0x0024)) -// Reserved (_W5200_IO_BASE_ + (0x0025)) -// Reserved (_W5200_IO_BASE_ + (0x0026)) -// Reserved (_W5200_IO_BASE_ + (0x0027)) - -/** - * @ingroup Common_register_group_W5200 - * @brief PPP LCP Request Timer register in PPPoE mode(R) - * @details \ref PTIMER configures the time for sending LCP echo request. The unit of time is 25ms. - */ -#define PTIMER (_W5200_IO_BASE_ + (0x0028)) // PPP LCP RequestTimer - -/** - * @ingroup Common_register_group_W5200 - * @brief PPP LCP Magic number register in PPPoE mode(R) - * @details \ref PMAGIC configures the 4bytes magic number to be used in LCP negotiation. - */ -#define PMAGIC (_W5200_IO_BASE_ + (0x0029)) // PPP LCP Magic number - -// Reserved (_W5200_IO_BASE_ + (0x002A)) -// Reserved (_W5200_IO_BASE_ + (0x002B)) -// Reserved (_W5200_IO_BASE_ + (0x002C)) -// Reserved (_W5200_IO_BASE_ + (0x002D)) -// Reserved (_W5200_IO_BASE_ + (0x002E)) -// Reserved (_W5200_IO_BASE_ + (0x002F)) - -/** - * @ingroup Common_register_group_W5200 - * @brief Set Interrupt low level timer register address(R/W) - * @details \ref INTLEVEL configures the Interrupt Assert Time. - */ -#define INTLEVEL (_W5200_IO_BASE_ + (0x0030)) // Interrupt Low Level Timer - -// Reserved (_W5200_IO_BASE_ + (0x0032)) -// Reserved (_W5200_IO_BASE_ + (0x0033)) - -/** - * @ingroup Common_register_group_W5200 - * @brief Socket Interrupt Register(R/W) - * @details \ref IR2 indicates the interrupt status of Socket.\n - * Each bit of \ref IR2 be still until \ref Sn_IR is cleared by the host.\n - * If \ref Sn_IR is not equal to x00 the n-th bit of \ref IR2 is and INTn PIN is asserted until \ref IR2 is x00 */ -#define IR2 (_W5200_IO_BASE_ + (0x0034)) // Socket Interrupt - -/** - * @ingroup Common_register_group_W5200 - * @brief PHYSTATUS(R/W) - * @details \ref PHYSTATUS is the Register to indicate W5200 status of PHY. - * - * - * - *
7 6 5 4 3 2 1 0
Reserved Reserved LINK POWERSAVE POWERDOWN Reserved Reserved Reserved
- * - \ref PHYSTATUS_LINK : Link Status Register[Read Only] - * - \ref PHYSTATUS_POWERSAVE : Power save mode of PHY[R/W] - * - \ref PHYSTATUS_POWERDOWN : Power down mode of PHY[R/W] - */ -#define PHYSTATUS (_W5200_IO_BASE_ + (0x0035)) // PHY Status - -/** - * @ingroup Common_register_group_W5200 - * @brief Interrupt mask register(R/W) - * @details \ref IMR2 is used to mask interrupts. Each bit of \ref _IMR_ corresponds to each bit of \ref IR. - * When a bit of \ref IMR2 is and the corresponding bit of \ref IR is an interrupt will be issued. In other words, - * if a bit of \ref IMR2 is an interrupt will not be issued even if the corresponding bit of \ref IR is \n\n - * Each bit of \ref IMR2 defined as the following. - * - * - * - *
7 6 5 4 3 2 1 0
IM_IR7 Reserved IM_IR5 Reserved Reserved Reserved Reserved Reserved
- * - \ref IM_IR7 : IP Conflict Interrupt Mask - * - \ref IM_IR5 : PPPoE Close Interrupt Mask - * @note This Register is same operated as _IMR_ of W5100, W5300 and W5550.\n - * So, \ref setIMR() set a value to IMR2 for integrating with ioLibrary - */ -#define IMR2 (_W5200_IO_BASE_ + (0x0036)) // Interrupt Mask - - -//----------------------------- W5200 Socket Registers ----------------------------- - -//--------------------------- For Backward Compatibility --------------------------- - -/** - * @ingroup Socket_register_group_W5200 - * @brief socket Mode register(R/W) - * @details \ref Sn_MR configures the option or protocol type of Socket n.\n\n - * Each bit of \ref Sn_MR defined as the following. - * - * - * - *
7 6 5 4 3 2 1 0
MULTI MF ND/MC Reserved Protocol[3] Protocol[2] Protocol[1] Protocol[0]
- * - \ref Sn_MR_MULTI : Support UDP Multicasting - * - \ref Sn_MR_MF : Support MACRAW - * - \ref Sn_MR_ND : No Delayed Ack(TCP) flag - * - \ref Sn_MR_MC : IGMP version used in UDP mulitcasting - * - Protocol - * - * - * - * - * - * - *
Protocol[3] Protocol[2] Protocol[1] Protocol[0] @b Meaning
0 0 0 0 Closed
0 0 0 1 TCP
0 0 1 0 UDP
0 1 0 0 MACRAW
- * - In case of Socket 0 - * - * - * - * - *
Protocol[3] Protocol[2] Protocol[1] Protocol[0] @b Meaning
0 1 0 0 MACRAW
0 1 0 1 PPPoE
- * - \ref Sn_MR_MACRAW : MAC LAYER RAW SOCK \n - * - \ref Sn_MR_UDP : UDP - * - \ref Sn_MR_TCP : TCP - * - \ref Sn_MR_CLOSE : Unused socket - * @note MACRAW mode should be only used in Socket 0. - */ -#define Sn_MR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0000)) // socket Mode register - -/** - * @ingroup Socket_register_group_W5200 - * @brief Socket command register(R/W) - * @details This is used to set the command for Socket n such as OPEN, CLOSE, CONNECT, LISTEN, SEND, and RECEIVE.\n - * After W5200 accepts the command, the \ref Sn_CR register is automatically cleared to 0x00. - * Even though \ref Sn_CR is cleared to 0x00, the command is still being processed.\n - * To check whether the command is completed or not, please check the \ref Sn_IR or \ref Sn_SR. - * - \ref Sn_CR_OPEN : Initialize or open socket. - * - \ref Sn_CR_LISTEN : Wait connection request in TCP mode(Server mode) - * - \ref Sn_CR_CONNECT : Send connection request in TCP mode(Client mode) - * - \ref Sn_CR_DISCON : Send closing request in TCP mode. - * - \ref Sn_CR_CLOSE : Close socket. - * - \ref Sn_CR_SEND : Update TX buffer pointer and send data. - * - \ref Sn_CR_SEND_MAC : Send data with MAC address, so without ARP process. - * - \ref Sn_CR_SEND_KEEP : Send keep alive message. - * - \ref Sn_CR_RECV : Update RX buffer pointer and receive data. - * - In case of S0_MR(P3:P0) = S0_MR_PPPoE - * - * - * - * - * - * - * - *
Value Symbol Description
0x23 PCON PPPoE connection begins by transmitting PPPoE discovery packet
0x24 PDISCON Closes PPPoE connection
0x25 PCR In each phase, it transmits REQ message.
0x26 PCN In each phase, it transmits NAK message.
0x27 PCJ In each phase, it transmits REJECT message.
- */ -#define Sn_CR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0001)) // channel Sn_CR register - -/** - * @ingroup Socket_register_group_W5200 - * @brief Socket interrupt register(R) - * @details \ref Sn_IR indicates the status of Socket Interrupt such as establishment, termination, receiving data, timeout).\n - * When an interrupt occurs and the corresponding bit of \ref Sn_IMR is the corresponding bit of \ref Sn_IR becomes \n - * In order to clear the \ref Sn_IR bit, the host should write the bit to \n - * - * - * - *
7 6 5 4 3 2 1 0
PRECV PFAIL PNEXT SEND_OK TIMEOUT RECV DISCON CON
- * - \ref Sn_IR_PRECV : PPP Receive Interrupt - * - \ref Sn_IR_PFAIL : PPP Fail Interrupt - * - \ref Sn_IR_PNEXT : PPP Next Phase Interrupt - * - \ref Sn_IR_SENDOK : SEND_OK Interrupt - * - \ref Sn_IR_TIMEOUT : TIMEOUT Interrupt - * - \ref Sn_IR_RECV : RECV Interrupt - * - \ref Sn_IR_DISCON : DISCON Interrupt - * - \ref Sn_IR_CON : CON Interrupt - */ -#define Sn_IR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0002)) // channel interrupt register - -/** - * @ingroup Socket_register_group_W5200 - * @brief Socket status register(R) - * @details \ref Sn_SR indicates the status of Socket n.\n - * The status of Socket n is changed by \ref Sn_CR or some special control packet as SYN, FIN packet in TCP. - * @par Normal status - * - \ref SOCK_CLOSED : Closed - * - \ref SOCK_INIT : Initiate state - * - \ref SOCK_LISTEN : Listen state - * - \ref SOCK_ESTABLISHED : Success to connect - * - \ref SOCK_CLOSE_WAIT : Closing state - * - \ref SOCK_UDP : UDP socket - * - \ref SOCK_MACRAW : MAC raw mode socket - *@par Temporary status during changing the status of Socket n. - * - \ref SOCK_SYNSENT : This indicates Socket n sent the connect-request packet (SYN packet) to a peer. - * - \ref SOCK_SYNRECV : It indicates Socket n successfully received the connect-request packet (SYN packet) from a peer. - * - \ref SOCK_FIN_WAIT : Connection state - * - \ref SOCK_CLOSING : Closing state - * - \ref SOCK_TIME_WAIT : Closing state - * - \ref SOCK_LAST_ACK : Closing state - */ -#define Sn_SR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0003)) // channel status register - -/** - * @ingroup Socket_register_group_W5200 - * @brief source port register(R/W) - * @details \ref Sn_PORT configures the source port number of Socket n. - * It is valid when Socket n is used in TCP/UDP mode. It should be set before OPEN command is ordered. -*/ -#define Sn_PORT(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0004)) // source port register - -/** - * @ingroup Socket_register_group_W5200 - * @brief Peer MAC register address(R/W) - * @details \ref Sn_DHAR configures the destination hardware address of Socket n when using SEND_MAC command in UDP mode or - * it indicates that it is acquired in ARP-process by CONNECT/SEND command. - */ -#define Sn_DHAR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0006)) // Peer MAC register address - -/** - * @ingroup Socket_register_group_W5200 - * @brief Peer IP register address(R/W) - * @details \ref Sn_DIPR configures or indicates the destination IP address of Socket n. It is valid when Socket n is used in TCP/UDP mode. - * In TCP client mode, it configures an IP address of TCP server before CONNECT command. - * In TCP server mode, it indicates an IP address of TCP client after successfully establishing connection. - * In UDP mode, it configures an IP address of peer to be received the UDP packet by SEND or SEND_MAC command. - */ -#define Sn_DIPR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x000C)) // Peer IP register address - -/** - * @ingroup Socket_register_group_W5200 - * @brief Peer port register address(R/W) - * @details \ref Sn_DPORT configures or indicates the destination port number of Socket n. It is valid when Socket n is used in TCP/UDP mode. - * In TCP clientmode, it configures the listen port number of TCP server before CONNECT command. - * In TCP Servermode, it indicates the port number of TCP client after successfully establishing connection. - * In UDP mode, it configures the port number of peer to be transmitted the UDP packet by SEND/SEND_MAC command. - */ -#define Sn_DPORT(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0010)) // Peer port register address - -/** - * @ingroup Socket_register_group_W5200 - * @brief Maximum Segment Size(Sn_MSSR0) register address(R/W) - * @details \ref Sn_MSSR configures or indicates the MTU(Maximum Transfer Unit) of Socket n. - */ -#define Sn_MSSR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0012)) // Maximum Segment Size(Sn_MSSR0) register address - -/** - * @ingroup Socket_register_group_W5200 - * @brief IP Protocol(PROTO) Register(R/W) - * @details \ref Sn_PROTO that sets the protocol number field of the IP header at the IP layer. It is - * valid only in IPRAW mode, and ignored in other modes. - */ -#define Sn_PROTO(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0014)) // Protocol of IP Header field register in IP raw mode - -/** - * @ingroup Socket_register_group_W5200 - * @brief IP Type of Service(TOS) Register(R/W) - * @details \ref Sn_TOS configures the TOS(Type Of Service field in IP Header) of Socket n. - * It is set before OPEN command. - */ -#define Sn_TOS(sn) (WIZCHIP_SREG_BLOCK(sn) + 0x0015) // IP Type of Service(TOS) Register - -/** - * @ingroup Socket_register_group_W5200 - * @brief IP Time to live(TTL) Register(R/W) - * @details \ref Sn_TTL configures the TTL(Time To Live field in IP header) of Socket n. - * It is set before OPEN command. - */ -#define Sn_TTL(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0016)) // IP Time to live(TTL) Register - -// Reserved (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0017)) -// Reserved (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0018)) -// Reserved (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0019)) -// Reserved (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001A)) -// Reserved (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001B)) -// Reserved (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001C)) -// Reserved (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001D)) - -/** - * @ingroup Socket_register_group_W5200 - * @brief Receive memory size register(R/W) - * @details \ref Sn_RXMEM_SIZE configures the RX buffer block size of Socket n. - * Socket n RX Buffer Block size can be configured with 1,2,4,8, and 16 Kbytes. - * If a different size is configured, the data cannot be normally received from a peer. - * Although Socket n RX Buffer Block size is initially configured to 2Kbytes, - * user can re-configure its size using \ref Sn_RXMEM_SIZE. The total sum of \ref Sn_RXMEM_SIZE can not be exceed 16Kbytes. - * When exceeded, the data reception error is occurred. - */ -#define Sn_RXMEM_SIZE(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001E)) // Receive memory size reigster - -/** - * @ingroup Socket_register_group_W5200 - * @brief Transmit memory size register(R/W) - * @details \ref Sn_TXMEM_SIZE configures the TX buffer block size of Socket n. Socket n TX Buffer Block size can be configured with 1,2,4,8, and 16 Kbytes. - * If a different size is configured, the data can't be normally transmitted to a peer. - * Although Socket n TX Buffer Block size is initially configured to 2Kbytes, - * user can be re-configure its size using \ref Sn_TXMEM_SIZE. The total sum of \ref Sn_TXMEM_SIZE can not be exceed 16Kbytes. - * When exceeded, the data transmission error is occurred. - */ -#define Sn_TXMEM_SIZE(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001F)) // Transmit memory size reigster - -/** - * @ingroup Socket_register_group_W5200 - * @brief Transmit free memory size register(R) - * @details \ref Sn_TX_FSR indicates the free size of Socket n TX Buffer Block. It is initialized to the configured size by \ref Sn_TXMEM_SIZE. - * Data bigger than \ref Sn_TX_FSR should not be saved in the Socket n TX Buffer because the bigger data overwrites the previous saved data not yet sent. - * Therefore, check before saving the data to the Socket n TX Buffer, and if data is equal or smaller than its checked size, - * transmit the data with SEND/SEND_MAC command after saving the data in Socket n TX buffer. But, if data is bigger than its checked size, - * transmit the data after dividing into the checked size and saving in the Socket n TX buffer. - */ -#define Sn_TX_FSR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0020)) // Transmit free memory size register - -/** - * @ingroup Socket_register_group_W5200 - * @brief Transmit memory read pointer register address(R) - * @details \ref Sn_TX_RD is initialized by OPEN command. However, if Sn_MR(P[3:0]) is TCP mode(001), it is re-initialized while connecting with TCP. - * After its initialization, it is auto-increased by SEND command. - * SEND command transmits the saved data from the current \ref Sn_TX_RD to the \ref Sn_TX_WR in the Socket n TX Buffer. - * After transmitting the saved data, the SEND command increases the \ref Sn_TX_RD as same as the \ref Sn_TX_WR. - * If its increment value exceeds the maximum value 0xFFFF, (greater than 0x10000 and the carry bit occurs), - * then the carry bit is ignored and will automatically update with the lower 16bits value. - */ -#define Sn_TX_RD(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0022)) // Transmit memory read pointer register address - -/** - * @ingroup Socket_register_group_W5200 - * @brief Transmit memory write pointer register address(R/W) - * @details \ref Sn_TX_WR is initialized by OPEN command. However, if Sn_MR(P[3:0]) is TCP mode(001), it is re-initialized while connecting with TCP.\n - * It should be read or be updated like as follows.\n - * 1. Read the starting address for saving the transmitting data.\n - * 2. Save the transmitting data from the starting address of Socket n TX buffer.\n - * 3. After saving the transmitting data, update \ref Sn_TX_WR to the increased value as many as transmitting data size. - * If the increment value exceeds the maximum value 0xFFFF(greater than 0x10000 and the carry bit occurs), - * then the carry bit is ignored and will automatically update with the lower 16bits value.\n - * 4. Transmit the saved data in Socket n TX Buffer by using SEND/SEND command - */ -#define Sn_TX_WR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0024)) // Transmit memory write pointer register address - -/** - * @ingroup Socket_register_group_W5200 - * @brief Received data size register(R) - * @details \ref Sn_RX_RSR indicates the data size received and saved in Socket n RX Buffer. - * \ref Sn_RX_RSR does not exceed the \ref Sn_RXMEM_SIZE and is calculated as the difference between - * Socket n RX Write Pointer (\ref Sn_RX_WR)and Socket n RX Read Pointer (\ref Sn_RX_RD) - */ -#define Sn_RX_RSR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0026)) // Received data size register - -/** - * @ingroup Socket_register_group_W5200 - * @brief Read point of Receive memory(R/W) - * @details \ref Sn_RX_RD is initialized by OPEN command. Make sure to be read or updated as follows.\n - * 1. Read the starting save address of the received data.\n - * 2. Read data from the starting address of Socket n RX Buffer.\n - * 3. After reading the received data, Update \ref Sn_RX_RD to the increased value as many as the reading size. - * If the increment value exceeds the maximum value 0xFFFF, that is, is greater than 0x10000 and the carry bit occurs, - * update with the lower 16bits value ignored the carry bit.\n - * 4. Order RECV command is for notifying the updated \ref Sn_RX_RD to W5200. - */ -#define Sn_RX_RD(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0028)) // Read point of Receive memory - -/** - * @ingroup Socket_register_group_W5200 - * @brief Write point of Receive memory(R) - * @details \ref Sn_RX_WR is initialized by OPEN command and it is auto-increased by the data reception. - * If the increased value exceeds the maximum value 0xFFFF, (greater than 0x10000 and the carry bit occurs), - * then the carry bit is ignored and will automatically update with the lower 16bits value. - */ -#define Sn_RX_WR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x002A)) // Write point of Receive memory - -/** - * @ingroup Socket_register_group_W5200 - * @brief socket interrupt mask register(R) - * @details \ref Sn_IMR masks the interrupt of Socket n. - * Each bit corresponds to each bit of \ref Sn_IR. When a Socket n Interrupt is occurred and the corresponding bit of \ref Sn_IMR is - * the corresponding bit of \ref Sn_IR becomes When both the corresponding bit of \ref Sn_IMR and \ref Sn_IR are and the n-th bit of \ref IR is - * Host is interrupted by asserted INTn PIN to low. - */ -#define Sn_IMR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x002C)) // socket interrupt mask register - -/** - * @ingroup Socket_register_group_W5200 - * @brief Fragment field value in IP header register(R/W) - * @details \ref Sn_FRAG configures the FRAG(Fragment field in IP header). - */ -#define Sn_FRAG(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x002D)) // frag field value in IP header register - - -//----------------------------- W5200 Register values ----------------------------- - -/* MODE register values */ -/** - * @brief Reset - * @details If this bit is All internal registers will be initialized. It will be automatically cleared as after S/W reset. - */ -#define MR_RST 0x80 ///< reset - -/** - * @brief Wake on LAN - * @details 0 : Disable WOL mode\n - * 1 : Enable WOL mode\n - * If WOL mode is enabled and the received magic packet over UDP has been normally processed, the Interrupt PIN (INTn) asserts to low. - * When using WOL mode, the UDP Socket should be opened with any source port number. (Refer to Socket n Mode Register (\ref Sn_MR) for opening Socket.) - * @note The magic packet over UDP supported by W5200 consists of 6 bytes synchronization stream (xFFFFFFFFFFFF and - * 16 times Target MAC address stream in UDP payload. The options such like password are ignored. You can use any UDP source port number for WOL mode. - */ -#define MR_WOL 0x20 ///< Wake on Lan - -/** - * @brief Ping block - * @details 0 : Disable Ping block\n - * 1 : Enable Ping block\n - * If the bit is it blocks the response to a ping request. - */ -#define MR_PB 0x10 ///< ping block - -/** - * @brief Enable PPPoE - * @details 0 : DisablePPPoE mode\n - * 1 : EnablePPPoE mode\n - * If you use ADSL, this bit should be '1'. - */ -#define MR_PPPOE 0x08 ///< enable pppoe - -/** - * @brief Address Auto-Increment in Indirect Bus Interface - * @details 0 : Disable auto-increment \n - * 1 : Enable auto-incremente \n - * At the Indirect Bus Interface mode, if this bit is set as ��1��, the address will - * be automatically increased by 1 whenever read and write are performed. - */ -#define MR_AI 0x02 ///< auto-increment in indirect mode - -/** - * @brief Indirect Bus Interface mode - * @details 0 : Disable Indirect bus Interface mode \n - * 1 : Enable Indirect bus Interface mode \n - * If this bit is set as ��1��, Indirect Bus Interface mode is set. - */ -#define MR_IND 0x01 ///< enable indirect mode - -/* IR register values */ -/** - * @brief Check IP conflict. - * @details Bit is set as when own source IP address is same with the sender IP address in the received ARP request. - */ -#define IR_CONFLICT 0x80 ///< check ip confict - -/** - * @brief Get the PPPoE close message. - * @details When PPPoE is disconnected during PPPoE mode, this bit is set. - */ -#define IR_PPPoE 0x20 ///< get the PPPoE close message - -/** - * @brief Link Status [Read Only] - * @details 0: Link down \n 1: Link up \n - */ -#define PHYSTATUS_LINK 0x20 - -/** - * @brief Power save mode of PHY - * @details 0: Disable Power save mode \n 1: Enable Power save mode \n - */ -#define PHYSTATUS_POWERSAVE 0x10 - -/** - * @brief Power down mode of PHY - * @details 0: Disable Power down mode \n 1: Enable Power down mode\n - */ -#define PHYSTATUS_POWERDOWN 0x08 - -// Sn_MR values -/* Sn_MR Default values */ -/** - * @brief Unused socket - * @details This configures the protocol mode of Socket n. - */ -#define Sn_MR_CLOSE 0x00 ///< unused socket - -/** - * @brief TCP - * @details This configures the protocol mode of Socket n. - */ -#define Sn_MR_TCP 0x01 ///< TCP - -/** - * @brief UDP - * @details This configures the protocol mode of Socket n. - */ -#define Sn_MR_UDP 0x02 ///< UDP -#define Sn_MR_IPRAW 0x03 ///< IP LAYER RAW SOCK - -/** - * @brief MAC LAYER RAW SOCK - * @details This configures the protocol mode of Socket n. - * @note MACRAW mode should be only used in Socket 0. - */ -#define Sn_MR_MACRAW 0x04 ///< MAC LAYER RAW SOCK - -/** - * @brief PPPoE - * @details This configures the protocol mode of Socket n. - * @note PPPoE mode should be only used in Socket 0. - */ -#define Sn_MR_PPPOE 0x05 ///< PPPoE - -/** - * @brief No Delayed Ack(TCP), Multicast flag - * @details 0 : Disable No Delayed ACK option\n - * 1 : Enable No Delayed ACK option\n - * This bit is applied only during TCP mode (P[3:0] = 001).\n - * When this bit is It sends the ACK packet without delay as soon as a Data packet is received from a peer.\n - * When this bit is It sends the ACK packet after waiting for the timeout time configured by \ref _RTR_. - */ -#define Sn_MR_ND 0x20 ///< No Delayed Ack(TCP) flag - -/* Sn_MR Default values */ -/** - * @brief Support UDP Multicasting - * @details 0 : disable Multicasting\n - * 1 : enable Multicasting\n - * This bit is applied only during UDP mode(P[3:0] = 010).\n - * To use multicasting, \ref Sn_DIPR & \ref Sn_DPORT should be respectively configured with the multicast group IP address & port number - * before Socket n is opened by OPEN command of \ref Sn_CR. - */ -#define Sn_MR_MC Sn_MR_ND ///< Select IGMP version 1(0) or 2(1) - -/** - * @brief Multicast Blocking in \ref Sn_MR_MACRAW mode - * @details 0 : using IGMP version 2\n - * 1 : using IGMP version 1\n - * This bit is applied only during UDP mode(P[3:0] = 010 and MULTI = '1') - * It configures the version for IGMP messages (Join/Leave/Report). - */ -#define Sn_MR_MF 0x40 ///< Use MAC filter -#define Sn_MR_MFEN Sn_MR_MF - -/* Sn_MR Default values */ -/** - * @brief Support UDP Multicasting - * @details 0 : disable Multicasting\n - * 1 : enable Multicasting\n - * This bit is applied only during UDP mode(P[3:0] = 010).\n - * To use multicasting, \ref Sn_DIPR & \ref Sn_DPORT should be respectively configured with the multicast group IP address & port number - * before Socket n is opened by OPEN command of \ref Sn_CR. - */ -#define Sn_MR_MULTI 0x80 ///< support multicating - -/* Sn_CR values */ -/** - * @brief Initialize or open socket - * @details Socket n is initialized and opened according to the protocol selected in Sn_MR(P3:P0). - * The table below shows the value of \ref Sn_SR corresponding to \ref Sn_MR.\n - * - * - * - * - * - * - * - * - *
\b Sn_MR (P[3:0]) \b Sn_SR
Sn_MR_CLOSE (000) --
Sn_MR_TCP (001) SOCK_INIT (0x13)
Sn_MR_UDP (010) SOCK_UDP (0x22)
S0_MR_IPRAW (011) SOCK_IPRAW (0x32)
S0_MR_MACRAW (100) SOCK_MACRAW (0x42)
S0_MR_PPPoE (101) SOCK_PPPoE (0x5F)
- */ -#define Sn_CR_OPEN 0x01 ///< initialize or open socket - -/** - * @brief Wait connection request in TCP mode(Server mode) - * @details This is valid only in TCP mode (Sn_MR(P3:P0) = \ref Sn_MR_TCP).// - * In this mode, Socket n operates as a 'TCP server' and waits for connection-request (SYN packet) from any 'TCP client'.// - * The \ref Sn_SR changes the state from SOCK_INIT to SOCKET_LISTEN.// - * When a 'TCP client' connection request is successfully established, - * the \ref Sn_SR changes from SOCK_LISTEN to SOCK_ESTABLISHED and the Sn_IR(0) becomes - * But when a 'TCP client' connection request is failed, Sn_IR(3) becomes and the status of \ref Sn_SR changes to SOCK_CLOSED. - */ -#define Sn_CR_LISTEN 0x02 ///< wait connection request in tcp mode(Server mode) - -/** - * @brief Send connection request in TCP mode(Client mode) - * @details To connect, a connect-request (SYN packet) is sent to TCP serverconfigured by \ref Sn_DIPR & Sn_DPORT(destination address & port). - * If the connect-request is successful, the \ref Sn_SR is changed to \ref SOCK_ESTABLISHED and the Sn_IR(0) becomes \n\n - * The connect-request fails in the following three cases.\n - * 1. When a @b ARPTO occurs (\ref Sn_IR[3] = '1') because destination hardware address is not acquired through the ARP-process.\n - * 2. When a @b SYN/ACK packet is not received and @b TCPTO (Sn_IR(3) ='1')\n - * 3. When a @b RST packet is received instead of a @b SYN/ACK packet. In these cases, \ref Sn_SR is changed to \ref SOCK_CLOSED. - * @note This is valid only in TCP mode and operates when Socket n acts as TCP client - */ -#define Sn_CR_CONNECT 0x04 ///< send connection request in tcp mode(Client mode) - -/** - * @brief Send closing request in TCP mode - * @details Regardless of TCP serveror TCP client the DISCON command processes the disconnect-process (Active closeor Passive close.\n - * @par Active close - * it transmits disconnect-request(FIN packet) to the connected peer\n - * @par Passive close - * When FIN packet is received from peer, a FIN packet is replied back to the peer.\n - * @details When the disconnect-process is successful (that is, FIN/ACK packet is received successfully), \ref Sn_SR is changed to \ref SOCK_CLOSED.\n - * Otherwise, TCPTO occurs (Sn_IR(3)='1') and then \ref Sn_SR is changed to \ref SOCK_CLOSED. - * @note Valid only in TCP mode. - */ -#define Sn_CR_DISCON 0x08 ///< send closing reqeuset in tcp mode - -/** - * @brief Close socket - * @details Sn_SR is changed to \ref SOCK_CLOSED. - */ -#define Sn_CR_CLOSE 0x10 - -/** - * @brief Update TX buffer pointer and send data - * @details SEND transmits all the data in the Socket n TX buffer.\n - * For more details, please refer to Socket n TX Free Size Register (\ref Sn_TX_FSR), Socket n, - * TX Write Pointer Register(\ref Sn_TX_WR), and Socket n TX Read Pointer Register(\ref Sn_TX_RD). - */ -#define Sn_CR_SEND 0x20 - -/** - * @brief Send data with MAC address, so without ARP process - * @details The basic operation is same as SEND.\n - * Normally SEND transmits data after destination hardware address is acquired by the automatic ARP-process(Address Resolution Protocol).\n - * But SEND_MAC transmits data without the automatic ARP-process.\n - * In this case, the destination hardware address is acquired from \ref Sn_DHAR configured by host, instead of APR-process. - * @note Valid only in UDP mode. - */ -#define Sn_CR_SEND_MAC 0x21 - -/** - * @brief Send keep alive message - * @details It checks the connection status by sending 1byte keep-alive packet.\n - * If the peer can not respond to the keep-alive packet during timeout time, the connection is terminated and the timeout interrupt will occur. - * @note Valid only in TCP mode. - */ -#define Sn_CR_SEND_KEEP 0x22 - -/** - * @brief Update RX buffer pointer and receive data - * @details RECV completes the processing of the received data in Socket n RX Buffer by using a RX read pointer register (\ref Sn_RX_RD).\n - * For more details, refer to Socket n RX Received Size Register (\ref Sn_RX_RSR), Socket n RX Write Pointer Register (\ref Sn_RX_WR), - * and Socket n RX Read Pointer Register (\ref Sn_RX_RD). - */ -#define Sn_CR_RECV 0x40 - -/** - * @brief PPPoE connection - * @details PPPoE connection begins by transmitting PPPoE discovery packet - */ -#define Sn_CR_PCON 0x23 - -/** - * @brief Closes PPPoE connection - * @details Closes PPPoE connection - */ -#define Sn_CR_PDISCON 0x24 - -/** - * @brief REQ message transmission - * @details In each phase, it transmits REQ message. - */ -#define Sn_CR_PCR 0x25 - -/** - * @brief NAK massage transmission - * @details In each phase, it transmits NAK message. - */ -#define Sn_CR_PCN 0x26 - -/** - * @brief REJECT message transmission - * @details In each phase, it transmits REJECT message. - */ -#define Sn_CR_PCJ 0x27 - -/* Sn_IR values */ -/** - * @brief PPP Receive Interrupt - * @details PPP Receive Interrupts when the option which is not supported is received. - */ -#define Sn_IR_PRECV 0x80 - -/** - * @brief PPP Fail Interrupt - * @details PPP Fail Interrupts when PAP Authentication is failed. - */ -#define Sn_IR_PFAIL 0x40 - -/** - * @brief PPP Next Phase Interrupt - * @details PPP Next Phase Interrupts when the phase is changed during ADSL connection process. - */ -#define Sn_IR_PNEXT 0x20 - -/** - * @brief SEND_OK Interrupt - * @details This is issued when SEND command is completed. - */ -#define Sn_IR_SENDOK 0x10 ///< complete sending - -/** - * @brief TIMEOUT Interrupt - * @details This is issued when ARPTO or TCPTO occurs. - */ -#define Sn_IR_TIMEOUT 0x08 ///< assert timeout - -/** - * @brief RECV Interrupt - * @details This is issued whenever data is received from a peer. - */ -#define Sn_IR_RECV 0x04 - -/** - * @brief DISCON Interrupt - * @details This is issued when FIN or FIN/ACK packet is received from a peer. - */ -#define Sn_IR_DISCON 0x02 - -/** - * @brief CON Interrupt - * @details This is issued one time when the connection with peer is successful and then \ref Sn_SR is changed to \ref SOCK_ESTABLISHED. - */ -#define Sn_IR_CON 0x01 - -/* Sn_SR values */ -/** - * @brief Closed - * @details This indicates that Socket n is released.\n - * When DICON, CLOSE command is ordered, or when a timeout occurs, it is changed to \ref SOCK_CLOSED regardless of previous status. - */ -#define SOCK_CLOSED 0x00 ///< closed - -/** - * @brief Initiate state - * @details This indicates Socket n is opened with TCP mode.\n - * It is changed to \ref SOCK_INIT when Sn_MR(P[3:0]) = 001)and OPEN command is ordered.\n - * After \ref SOCK_INIT, user can use LISTEN /CONNECT command. - */ -#define SOCK_INIT 0x13 ///< init state - -/** - * @brief Listen state - * @details This indicates Socket n is operating as TCP servermode and waiting for connection-request (SYN packet) from a peer (TCP client).\n - * It will change to \ref SOCK_ESTABLISHED when the connection-request is successfully accepted.\n - * Otherwise it will change to \ref SOCK_CLOSED after TCPTO occurred (Sn_IR(TIMEOUT) = '1'). - */ -#define SOCK_LISTEN 0x14 - -/** - * @brief Connection state - * @details This indicates Socket n sent the connect-request packet (SYN packet) to a peer.\n - * It is temporarily shown when \ref Sn_SR is changed from \ref SOCK_INIT to \ref SOCK_ESTABLISHED by CONNECT command.\n - * If connect-accept(SYN/ACK packet) is received from the peer at SOCK_SYNSENT, it changes to \ref SOCK_ESTABLISHED.\n - * Otherwise, it changes to \ref SOCK_CLOSED after TCPTO (\ref Sn_IR[TIMEOUT] = '1') is occurred. - */ -#define SOCK_SYNSENT 0x15 - -/** - * @brief Connection state - * @details It indicates Socket n successfully received the connect-request packet (SYN packet) from a peer.\n - * If socket n sends the response (SYN/ACK packet) to the peer successfully, it changes to \ref SOCK_ESTABLISHED. \n - * If not, it changes to \ref SOCK_CLOSED after timeout occurs (\ref Sn_IR[TIMEOUT] = '1'). - */ -#define SOCK_SYNRECV 0x16 - -/** - * @brief Success to connect - * @details This indicates the status of the connection of Socket n.\n - * It changes to \ref SOCK_ESTABLISHED when the TCP SERVERprocessed the SYN packet from the TCP CLIENTduring \ref SOCK_LISTEN, or - * when the CONNECT command is successful.\n - * During \ref SOCK_ESTABLISHED, DATA packet can be transferred using SEND or RECV command. - */ -#define SOCK_ESTABLISHED 0x17 - -/** - * @brief Closing state - * @details These indicate Socket n is closing.\n - * These are shown in disconnect-process such as active-close and passive-close.\n - * When Disconnect-process is successfully completed, or when timeout occurs, these change to \ref SOCK_CLOSED. - */ -#define SOCK_FIN_WAIT 0x18 - -/** - * @brief Closing state - * @details These indicate Socket n is closing.\n - * These are shown in disconnect-process such as active-close and passive-close.\n - * When Disconnect-process is successfully completed, or when timeout occurs, these change to \ref SOCK_CLOSED. - */ -#define SOCK_CLOSING 0x1A - -/** - * @brief Closing state - * @details These indicate Socket n is closing.\n - * These are shown in disconnect-process such as active-close and passive-close.\n - * When Disconnect-process is successfully completed, or when timeout occurs, these change to \ref SOCK_CLOSED. - */ -#define SOCK_TIME_WAIT 0x1B - -/** - * @brief Closing state - * @details This indicates Socket n received the disconnect-request (FIN packet) from the connected peer.\n - * This is half-closing status, and data can be transferred.\n - * For full-closing, DISCON command is used. But For just-closing, CLOSE command is used. - */ -#define SOCK_CLOSE_WAIT 0x1C - -/** - * @brief Closing state - * @details This indicates Socket n is waiting for the response (FIN/ACK packet) to the disconnect-request (FIN packet) by passive-close.\n - * It changes to \ref SOCK_CLOSED when Socket n received the response successfully, or when timeout occurs (\ref Sn_IR[TIMEOUT] = '1'). - */ -#define SOCK_LAST_ACK 0x1D - -/** - * @brief UDP socket - * @details This indicates Socket n is opened in UDP mode(Sn_MR(P[3:0]) = 010).\n - * It changes to SOCK_UDP when Sn_MR(P[3:0]) = 010 and OPEN command is ordered.\n - * Unlike TCP mode, data can be transfered without the connection-process. - */ -#define SOCK_UDP 0x22 ///< udp socket - -/** -* @brief IP raw mode socket - * @details TThe socket is opened in IPRAW mode. The SOCKET status is change to SOCK_IPRAW when Sn_MR (P3:P0) is - * Sn_MR_IPRAW and OPEN command is used.\n - * IP Packet can be transferred without a connection similar to the UDP mode. -*/ -#define SOCK_IPRAW 0x32 ///< ip raw mode socket - -/** - * @brief MAC raw mode socket - * @details This indicates Socket 0 is opened in MACRAW mode (S0_MR(P[3:0]) = 100and is valid only in Socket 0.\n - * It changes to SOCK_MACRAW when S0_MR(P[3:0] = 100)and OPEN command is ordered.\n - * Like UDP mode socket, MACRAW mode Socket 0 can transfer a MAC packet (Ethernet frame) without the connection-process. - */ -#define SOCK_MACRAW 0x42 ///< mac raw mode socket - -/** - * @brief PPPoE mode socket - * @details It is the status that SOCKET0 is open as PPPoE mode. It is changed to SOCK_PPPoE in case of S0_CR=OPEN and S0_MR - * (P3:P0)=S0_MR_PPPoE.\n - * It is temporarily used at the PPPoE -connection. - */ -#define SOCK_PPPOE 0x5F ///< pppoe socket - -// IP PROTOCOL -#define IPPROTO_IP 0 ///< Dummy for IP -#define IPPROTO_ICMP 1 ///< Control message protocol -#define IPPROTO_IGMP 2 ///< Internet group management protocol -#define IPPROTO_GGP 3 ///< GW^2 (deprecated) -#define IPPROTO_TCP 6 ///< TCP -#define IPPROTO_PUP 12 ///< PUP -#define IPPROTO_UDP 17 ///< UDP -#define IPPROTO_IDP 22 ///< XNS idp -#define IPPROTO_ND 77 ///< UNOFFICIAL net disk protocol -#define IPPROTO_RAW 255 ///< Raw IP packet - -/** - * @brief Enter a critical section - * - * @details It is provided to protect your shared code which are executed without distribution. \n \n - * - * In non-OS environment, It can be just implemented by disabling whole interrupt.\n - * In OS environment, You can replace it to critical section api supported by OS. - * - * \sa WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF() - * \sa WIZCHIP_CRITICAL_EXIT() - */ -#define WIZCHIP_CRITICAL_ENTER() WIZCHIP.CRIS._enter() - -#ifdef _exit -#undef _exit -#endif - -/** - * @brief Exit a critical section - * - * @details It is provided to protect your shared code which are executed without distribution. \n\n - * - * In non-OS environment, It can be just implemented by disabling whole interrupt. \n - * In OS environment, You can replace it to critical section api supported by OS. - * - * @sa WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF() - * @sa WIZCHIP_CRITICAL_ENTER() - */ -#define WIZCHIP_CRITICAL_EXIT() WIZCHIP.CRIS._exit() - - - -//////////////////////// -// Basic I/O Function // -//////////////////////// -/** - * @ingroup Basic_IO_function_W5200 - * @brief It reads 1 byte value from a register. - * @param AddrSel Register address - * @return The value of register - */ -uint8_t WIZCHIP_READ (uint32_t AddrSel); - -/** - * @ingroup Basic_IO_function_W5200 - * @brief It writes 1 byte value to a register. - * @param AddrSel Register address - * @param wb Write data - * @return void - */ -void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb ); - -/** - * @ingroup Basic_IO_function_W5200 - * @brief It reads sequence data from registers. - * @param AddrSel Register address - * @param pBuf Pointer buffer to read data - * @param len Data length - */ -void WIZCHIP_READ_BUF (uint32_t AddrSel, uint8_t* pBuf, uint16_t len); - -/** - * @ingroup Basic_IO_function_W5200 - * @brief It writes sequence data to registers. - * @param AddrSel Register address - * @param pBuf Pointer buffer to write data - * @param len Data length - */ -void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len); - - -///////////////////////////////// -// Common Register IO function // -///////////////////////////////// - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Set Mode Register - * @param (uint8_t)mr The value to be set. - * @sa getMR() - */ -#if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_) - #define setMR(mr) WIZCHIP_WRITE(MR,mr) -#else - #define setMR(mr) (*((uint8_t*)MR) = mr) -#endif - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Get @ref MR. - * @return uint8_t. The value of Mode register. - * @sa setMR() - */ -#if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_) - #define getMR() WIZCHIP_READ(MR) -#else - #define getMR() (*(uint8_t*)MR) -#endif - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Set @ref GAR. - * @param (uint8_t*)gar Pointer variable to set gateway IP address. It should be allocated 4 bytes. - * @sa getGAR() - */ -#define setGAR(gar) \ - WIZCHIP_WRITE_BUF(GAR,gar,4) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Get @ref GAR. - * @param (uint8_t*)gar Pointer variable to get gateway IP address. It should be allocated 4 bytes. - * @sa setGAR() - */ -#define getGAR(gar) \ - WIZCHIP_READ_BUF(GAR,gar,4) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Set @ref SUBR. - * @param (uint8_t*)subr Pointer variable to set subnet mask address. It should be allocated 4 bytes. - * @note If subr is null pointer, set the backup subnet to SUBR. \n - * If subr is 0.0.0.0, back up SUBR and clear it. \n - * Otherwize, set subr to SUBR - * @sa getSUBR() - */ -#define setSUBR(subr) \ - WIZCHIP_WRITE_BUF(SUBR, subr,4) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Get @ref SUBR. - * @param (uint8_t*)subr Pointer variable to get subnet mask address. It should be allocated 4 bytes. - * @sa setSUBR() - */ -#define getSUBR(subr) \ - WIZCHIP_READ_BUF(SUBR, subr, 4) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Set @ref SHAR. - * @param (uint8_t*)shar Pointer variable to set local MAC address. It should be allocated 6 bytes. - * @sa getSHAR() - */ -#define setSHAR(shar) \ - WIZCHIP_WRITE_BUF(SHAR, shar, 6) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Get @ref SHAR. - * @param (uint8_t*)shar Pointer variable to get local MAC address. It should be allocated 6 bytes. - * @sa setSHAR() - */ -#define getSHAR(shar) \ - WIZCHIP_READ_BUF(SHAR, shar, 6) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Set @ref SIPR. - * @param (uint8_t*)sipr Pointer variable to set local IP address. It should be allocated 4 bytes. - * @sa getSIPR() -*/ -#define setSIPR(sipr) \ - WIZCHIP_WRITE_BUF(SIPR, sipr, 4) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Get @ref SIPR. - * @param (uint8_t*)sipr Pointer variable to get local IP address. It should be allocated 4 bytes. - * @sa setSIPR() - */ -#define getSIPR(sipr) \ - WIZCHIP_READ_BUF(SIPR, sipr, 4) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Set \ref IR register - * @param (uint8_t)ir Value to set \ref IR register. - * @sa getIR() - */ -#define setIR(ir) \ - WIZCHIP_WRITE(IR, (ir & 0xA0)) -/** - * @ingroup Common_register_access_function_W5200 - * @brief Get \ref IR register - * @return uint8_t. Value of \ref IR register. - * @sa setIR() - */ -#define getIR() \ - (WIZCHIP_READ(IR) & 0xA0) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Set \ref IMR2 register - * @param (uint8_t)imr Value to set @ref IMR2 register. - * @sa getIMR() - */ -//M20150410 : Replace _IMR_ with IMR2 for integrating with ioLibrary -/* -#define setIMR(imr) \ - WIZCHIP_WRITE(_IMR_, imr) -*/ -#define setIMR(imr) \ - WIZCHIP_WRITE(IMR2, imr & 0xA0) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Get \ref IMR2 register - * @return uint8_t. Value of @ref IMR2 register. - * @sa setIMR() - */ -//M20150410 : Replace _IMR_ with IMR2 for integrating with ioLibrary -/* -#define getIMR() \ - WIZCHIP_READ(_IMR_) -*/ -#define getIMR() \ - (WIZCHIP_READ(IMR2) & 0xA0) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Set \ref _RTR_ register - * @param (uint16_t)rtr Value to set @ref _RTR_ register. - * @sa getRTR() - */ -#define setRTR(rtr) {\ - WIZCHIP_WRITE(_RTR_, (uint8_t)(rtr >> 8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_RTR_,1), (uint8_t) rtr); \ - } - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Get \ref _RTR_ register - * @return uint16_t. Value of @ref _RTR_ register. - * @sa setRTR() - */ -#define getRTR() \ - (((uint16_t)WIZCHIP_READ(_RTR_) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_RTR_,1))) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Set \ref _RCR_ register - * @param (uint8_t)rcr Value to set @ref _RCR_ register. - * @sa getRCR() - */ -#define setRCR(rcr) \ - WIZCHIP_WRITE(_RCR_, rcr) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Get \ref _RCR_ register - * @return uint8_t. Value of @ref _RCR_ register. - * @sa setRCR() - */ -#define getRCR() \ - WIZCHIP_READ(_RCR_) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Get \ref PATR register - * @return uint16_t. Value to set \ref PATR register - */ -#define getPATR() \ - (((uint16_t)WIZCHIP_READ(PATR) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(PATR,1))) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Get \ref PPPALGO register - * @return uint8_t. Value to set \ref PPPALGO register - */ -#define getPPPALGO() \ - WIZCHIP_READ(PPPALGO) - - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Get \ref VERSIONR register - * @return uint8_t. Value to set \ref VERSIONR register - */ -#define getVERSIONR() \ - WIZCHIP_READ(VERSIONR) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Set \ref PTIMER register - * @param (uint8_t)ptimer Value to set \ref PTIMER register. - * @sa getPTIMER() - */ -#define setPTIMER(ptimer) \ - WIZCHIP_WRITE(PTIMER, ptimer) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Get \ref PTIMER register - * @return uint8_t. Value of @ref PTIMER register. - * @sa setPTIMER() - */ -#define getPTIMER() \ - WIZCHIP_READ(PTIMER) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Set \ref PMAGIC register - * @param (uint8_t)pmagic Value to set @ref PMAGIC register. - * @sa getPMAGIC() - */ -#define setPMAGIC(pmagic) \ - WIZCHIP_WRITE(PMAGIC, pmagic) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Get \ref PMAGIC register - * @return uint8_t. Value of @ref PMAGIC register. - * @sa setPMAGIC() - */ -#define getPMAGIC() \ - WIZCHIP_READ(PMAGIC) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Set @ref INTLEVEL register - * @param (uint16_t)intlevel Value to set @ref INTLEVEL register. - * @sa getINTLEVEL() - */ -#define setINTLEVEL(intlevel) {\ - WIZCHIP_WRITE(INTLEVEL, (uint8_t)(intlevel >> 8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(INTLEVEL,1), (uint8_t) intlevel); \ - } -/** - * @ingroup Common_register_access_function_W5200 - * @brief Get @ref INTLEVEL register - * @return uint16_t. Value of @ref INTLEVEL register. - * @sa setINTLEVEL() - */ -#define getINTLEVEL() \ - (((uint16_t)WIZCHIP_READ(INTLEVEL) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(INTLEVEL,1))) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Set \ref IR2 register - * @param (uint8_t)ir2 Value to set \ref IR2 register. - * @sa getIR2() - */ -#define setIR2(ir2) \ - WIZCHIP_WRITE(IR2, ir2) -#define setSIR(ir2) setIR2(ir2) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Get \ref IR2 register - * @return uint8_t. Value of \ref IR2 register. - * @sa setIR2() - */ -#define getIR2() \ - WIZCHIP_READ(IR2) -#define getSIR() getIR2() - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Get \ref PHYSTATUS register - * @return uint8_t. Value to set \ref PHYSTATUS register. - */ -#define getPHYSTATUS() \ - WIZCHIP_READ(PHYSTATUS) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Set \ref _IMR_ register - * @param (uint8_t)imr2 Value to set \ref IMR2 register. - * @sa getIMR2() - * @note If possible, Don't use this function. Instead, Use setSIMR() for compatible with ioLibrary. - */ - //M20150410 : Replace IMR2 with _IMR_ for integrating with ioLibrary -/* -#define setIMR2(imr2) \ - WIZCHIP_WRITE(IMR2, (imr2 & 0xA0)) -*/ -#define setIMR2(imr2) \ - WIZCHIP_WRITE(_IMR_, imr2) -#define setSIMR(imr2) setIMR2(imr2) - -/** - * @ingroup Common_register_access_function_W5200 - * @brief Get \ref _IMR_ register - * @return uint8_t. Value of \ref IMR2 register. - * @sa setIMR2() - */ - //M20150410 : Replace IMR2 with _IMR_ for integrating with ioLibrary -/* -#define getIMR2() \ - (WIZCHIP_READ(IMR2) & 0xA0) -*/ -#define getIMR2() \ - WIZCHIP_READ(_IMR_) -#define getSIMR() getIMR2() -/////////////////////////////////// -// Socket N register I/O function // -/////////////////////////////////// -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Set @ref Sn_MR register - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ expect bit 4. - * @param mr Value to set @ref Sn_MR - * @sa getSn_MR() - */ -#define setSn_MR(sn, mr) \ - WIZCHIP_WRITE(Sn_MR(sn),mr) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get @ref Sn_MR register - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ expect bit 4. - * @return Value of @ref Sn_MR. - * @sa setSn_MR() - */ -#define getSn_MR(sn) \ - WIZCHIP_READ(Sn_MR(sn)) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Set @ref Sn_CR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t)cr Value to set @ref Sn_CR - * @sa getSn_CR() - */ -#define setSn_CR(sn, cr) \ - WIZCHIP_WRITE(Sn_CR(sn), cr) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get @ref Sn_CR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of @ref Sn_CR. - * @sa setSn_CR() - */ -#define getSn_CR(sn) \ - WIZCHIP_READ(Sn_CR(sn)) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Set @ref Sn_IR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t)ir Value to set @ref Sn_IR - * @sa getSn_IR() - */ -#define setSn_IR(sn, ir) \ - WIZCHIP_WRITE(Sn_IR(sn), ir) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get @ref Sn_IR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of @ref Sn_IR. - * @sa setSn_IR() - */ -#define getSn_IR(sn) \ - WIZCHIP_READ(Sn_IR(sn)) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Set @ref Sn_IMR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t)imr Value to set @ref Sn_IMR - * @sa getSn_IMR() -*/ -#define setSn_IMR(sn, imr) \ - WIZCHIP_WRITE(Sn_IMR(sn), imr) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get @ref Sn_IMR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of @ref Sn_IMR. - * @sa setSn_IMR() - */ -#define getSn_IMR(sn) \ - WIZCHIP_READ(Sn_IMR(sn)) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get @ref Sn_SR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of @ref Sn_SR. - */ -#define getSn_SR(sn) \ - WIZCHIP_READ(Sn_SR(sn)) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Set @ref Sn_PORT register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint16_t)port Value to set @ref Sn_PORT. - * @sa getSn_PORT() - */ -#define setSn_PORT(sn, port) { \ - WIZCHIP_WRITE(Sn_PORT(sn), (uint8_t)(port >> 8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_PORT(sn),1), (uint8_t) port); \ - } - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get @ref Sn_PORT register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_PORT. - * @sa setSn_PORT() - */ -#define getSn_PORT(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_PORT(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_PORT(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Set @ref Sn_DHAR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t*)dhar Pointer variable to set socket n destination hardware address. It should be allocated 6 bytes. - * @sa getSn_DHAR() - */ -#define setSn_DHAR(sn, dhar) \ - WIZCHIP_WRITE_BUF(Sn_DHAR(sn), dhar, 6) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get @ref Sn_DHAR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t*)dhar Pointer variable to get socket n destination hardware address. It should be allocated 6 bytes. - * @sa setSn_DHAR() - */ -#define getSn_DHAR(sn, dhar) \ - WIZCHIP_READ_BUF(Sn_DHAR(sn), dhar, 6) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Set @ref Sn_DIPR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t*)dipr Pointer variable to set socket n destination IP address. It should be allocated 4 bytes. - * @sa getSn_DIPR() - */ -#define setSn_DIPR(sn, dipr) \ - WIZCHIP_WRITE_BUF(Sn_DIPR(sn), dipr, 4) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get @ref Sn_DIPR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t*)dipr Pointer variable to get socket n destination IP address. It should be allocated 4 bytes. - * @sa SetSn_DIPR() - */ -#define getSn_DIPR(sn, dipr) \ - WIZCHIP_READ_BUF(Sn_DIPR(sn), dipr, 4) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Set @ref Sn_DPORT register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint16_t)dport Value to set @ref Sn_DPORT - * @sa getSn_DPORT() - */ -#define setSn_DPORT(sn, dport) { \ - WIZCHIP_WRITE(Sn_DPORT(sn), (uint8_t) (dport>>8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_DPORT(sn),1), (uint8_t) dport); \ - } - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get @ref Sn_DPORT register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_DPORT. - * @sa setSn_DPORT() - */ -#define getSn_DPORT(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_DPORT(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_DPORT(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Set @ref Sn_MSSR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint16_t)mss Value to set @ref Sn_MSSR - * @sa setSn_MSSR() - */ -#define setSn_MSSR(sn, mss) { \ - WIZCHIP_WRITE(Sn_MSSR(sn), (uint8_t)(mss>>8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_MSSR(sn),1), (uint8_t) mss); \ - } - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get @ref Sn_MSSR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_MSSR. - * @sa setSn_MSSR() - */ -#define getSn_MSSR(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_MSSR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_MSSR(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Set @ref Sn_PROTO register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t)proto Value to set \ref Sn_PROTO - * @sa getSn_PROTO() - */ -//M20150601 : Fixed Wrong Register address -/* -#define setSn_PROTO(sn, proto) \ - WIZCHIP_WRITE(Sn_TOS(sn), tos) -*/ -#define setSn_PROTO(sn, proto) \ - WIZCHIP_WRITE(Sn_PROTO(sn), proto) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get @ref Sn_PROTO register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of @ref Sn_PROTO. - * @sa setSn_PROTO() - */ -//M20150601 : Fixed Wrong Register address -/* -#define getSn_PROTO(sn) \ - WIZCHIP_READ(Sn_TOS(sn)) -*/ -#define getSn_PROTO(sn) \ - WIZCHIP_READ(Sn_PROTO(sn)) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Set @ref Sn_TOS register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t)tos Value to set @ref Sn_TOS - * @sa getSn_TOS() - */ -#define setSn_TOS(sn, tos) \ - WIZCHIP_WRITE(Sn_TOS(sn), tos) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get @ref Sn_TOS register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ . - * @return uint8_t. Value of Sn_TOS. - * @sa setSn_TOS() - */ -#define getSn_TOS(sn) \ - WIZCHIP_READ(Sn_TOS(sn)) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Set @ref Sn_TTL register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ . - * @param (uint8_t)ttl Value to set @ref Sn_TTL - * @sa getSn_TTL() - */ -#define setSn_TTL(sn, ttl) \ - WIZCHIP_WRITE(Sn_TTL(sn), ttl) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get @ref Sn_TTL register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ . - * @return uint8_t. Value of @ref Sn_TTL. - * @sa setSn_TTL() - */ -#define getSn_TTL(sn) \ - WIZCHIP_READ(Sn_TTL(sn)) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Set @ref Sn_RXMEM_SIZE register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ . - * @param (uint8_t)rxmemsize Value to set \ref Sn_RXMEM_SIZE - * @sa getSn_RXMEM_SIZE() - */ -#define setSn_RXMEM_SIZE(sn, rxmemsize) \ - WIZCHIP_WRITE(Sn_RXMEM_SIZE(sn),rxmemsize) - -#define setSn_RXBUF_SIZE(sn,rxmemsize) setSn_RXMEM_SIZE(sn,rxmemsize) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get @ref Sn_RXMEM_SIZE register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of @ref Sn_RXMEM. - * @sa setSn_RXMEM_SIZE() - */ -#define getSn_RXMEM_SIZE(sn) \ - WIZCHIP_READ(Sn_RXMEM_SIZE(sn)) - -#define getSn_RXBUF_SIZE(sn) getSn_RXMEM_SIZE(sn) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Set @ref Sn_TXMEM_SIZE register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t)txmemsize Value to set \ref Sn_TXMEM_SIZE - * @sa getSn_TXMEM_SIZE() - */ -#define setSn_TXMEM_SIZE(sn, txmemsize) \ - WIZCHIP_WRITE(Sn_TXMEM_SIZE(sn), txmemsize) - -#define setSn_TXBUF_SIZE(sn, txmemsize) setSn_TXMEM_SIZE(sn,txmemsize) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get @ref Sn_TXMEM_SIZE register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of @ref Sn_TXMEM_SIZE. - * @sa setSn_TXMEM_SIZE() - */ -#define getSn_TXMEM_SIZE(sn) \ - WIZCHIP_READ(Sn_TXMEM_SIZE(sn)) - -#define getSn_TXBUF_SIZE(sn) getSn_TXMEM_SIZE(sn) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get @ref Sn_TX_FSR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_TX_FSR. - */ -uint16_t getSn_TX_FSR(uint8_t sn); - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get @ref Sn_TX_RD register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_TX_RD. - */ -#define getSn_TX_RD(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_TX_RD(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_RD(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Set @ref Sn_TX_WR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint16_t)txwr Value to set @ref Sn_TX_WR - * @sa GetSn_TX_WR() - */ -#define setSn_TX_WR(sn, txwr) { \ - WIZCHIP_WRITE(Sn_TX_WR(sn), (uint8_t)(txwr>>8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_TX_WR(sn),1), (uint8_t) txwr); \ - } - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get @ref Sn_TX_WR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_TX_WR. - * @sa setSn_TX_WR() - */ -#define getSn_TX_WR(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_TX_WR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_WR(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get @ref Sn_RX_RSR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_RX_RSR. - */ -uint16_t getSn_RX_RSR(uint8_t sn); - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Set @ref Sn_RX_RD register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint16_t)rxrd Value to set @ref Sn_RX_RD - * @sa getSn_RX_RD() - */ -#define setSn_RX_RD(sn, rxrd) { \ - WIZCHIP_WRITE(Sn_RX_RD(sn), (uint8_t)(rxrd>>8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_RX_RD(sn),1), (uint8_t) rxrd); \ - } - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get @ref Sn_RX_RD register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_RX_RD. - * @sa setSn_RX_RD() - */ -#define getSn_RX_RD(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_RX_RD(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RD(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Set @ref Sn_RX_WR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint16_t)rxwr Value to set \ref Sn_RX_WR - * @sa getSn_RX_WR() - */ -#define setSn_RX_WR(sn, rxwr) { \ - WIZCHIP_WRITE(Sn_RX_WR(sn), (uint8_t)(rxwr>>8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_RX_WR(sn),1), (uint8_t) rxwr); \ - } - - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get @ref Sn_RX_WR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_RX_WR. - */ -#define getSn_RX_WR(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_RX_WR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_WR(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Set @ref Sn_IMR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t)imr Value to set \ref Sn_IMR - * @sa getSn_IMR() - */ -#define setSn_IMR(sn ,imr) \ - WIZCHIP_WRITE(Sn_IMR(sn), imr) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get @ref Sn_IMR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of @ref Sn_IMR. - * @sa setSn_IMR() - */ -#define getSn_IMR(sn) \ - WIZCHIP_READ(Sn_IMR(sn)) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Set @ref Sn_FRAG register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint16_t)frag Value to set \ref Sn_FRAG - * @sa getSn_FRAG() - */ -#define setSn_FRAG(sn, frag) { \ - WIZCHIP_WRITE(Sn_FRAG(sn), (uint8_t)(frag >>8)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_FRAG(sn),1), (uint8_t) frag); \ - } - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get @ref Sn_FRAG register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of @ref Sn_FRAG. - * @sa setSn_FRAG() - */ -#define getSn_FRAG(sn) \ - (((uint16_t)WIZCHIP_READ(Sn_FRAG(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_FRAG(sn),1))) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get the max RX buffer size of socket sn - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Max buffer size - */ -#define getSn_RxMAX(sn) \ - ((uint16_t)getSn_RXMEM_SIZE(sn) << 10) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get the max TX buffer size of socket sn - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Max buffer size - */ -#define getSn_TxMAX(sn) \ - ((uint16_t)getSn_TXMEM_SIZE(sn) << 10) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get the mask of socket sn RX buffer. - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Mask value - */ -#define getSn_RxMASK(sn) \ - ((uint16_t)getSn_RxMAX(sn) - 1) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get the mask of socket sn TX buffer - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Mask value - */ -#define getSn_TxMASK(sn) \ - ((uint16_t)getSn_TxMAX(sn) - 1) - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get the base address of socket sn RX buffer. - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of Socket n RX buffer base address. - */ -uint16_t getSn_RxBASE(uint8_t sn); - -/** - * @ingroup Socket_register_access_function_W5200 - * @brief Get the base address of socket sn TX buffer. - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint16_t. Value of Socket n TX buffer base address. - */ -uint16_t getSn_TxBASE(uint8_t sn); - -///////////////////////////////////// -// Sn_TXBUF & Sn_RXBUF IO function // -///////////////////////////////////// -/** - * @ingroup Basic_IO_function_W5200 - * @brief It copies data to internal TX memory - * - * @details This function reads the Tx write pointer register and after that, - * it copies the wizdata(pointer buffer) of the length of len(variable) bytes to internal TX memory - * and updates the Tx write pointer register. - * This function is being called by send() and sendto() function also. - * - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param wizdata Pointer buffer to write data - * @param len Data length - * @sa wiz_recv_data() - */ -void wiz_send_data(uint8_t sn, uint8_t *wizdata, uint16_t len); - -/** - * @ingroup Basic_IO_function_W5200 - * @brief It copies data to your buffer from internal RX memory - * - * @details This function read the Rx read pointer register and after that, - * it copies the received data from internal RX memory - * to wizdata(pointer variable) of the length of len(variable) bytes. - * This function is being called by recv() also. - * - * @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param wizdata Pointer buffer to read data - * @param len Data length - * @sa wiz_send_data() - */ -void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint16_t len); - -/** - * @ingroup Basic_IO_function_W5200 - * @brief It discard the received data in RX memory. - * @details It discards the data of the length of len(variable) bytes in internal RX memory. - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param len Data length - */ -void wiz_recv_ignore(uint8_t sn, uint16_t len); - -/// \cond DOXY_APPLY_CODE -#endif -/// \endcond - -#ifdef __cplusplus -} -#endif - -#endif //_W5200_H_ - - - diff --git a/lib/ioLibrary_Driver/W5300/w5300.c b/lib/ioLibrary_Driver/W5300/w5300.c deleted file mode 100644 index 4b5e60b..0000000 --- a/lib/ioLibrary_Driver/W5300/w5300.c +++ /dev/null @@ -1,225 +0,0 @@ -//***************************************************************************** -// -//! \file w5300.h -//! \brief W5300 HAL implement File. -//! \version 1.0.0 -//! \date 2015/05/01 -//! \par Revision history -//! <2015/05/01> 1st Released for integrating with ioLibrary -//! Download the latest version directly from GitHub. Please visit the our GitHub repository for ioLibrary. -//! >> https://github.com/Wiznet/ioLibrary_Driver -//! \author MidnightCow -//! \copyright -//! -//! Copyright (c) 2015, 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 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 -#include "wizchip_conf.h" - -#if _WIZCHIP_ == 5300 - - extern uint8_t sock_remained_byte[_WIZCHIP_SOCK_NUM_]; - extern uint8_t sock_pack_info[_WIZCHIP_SOCK_NUM_]; - - -/*********************** - * Basic I/O Function * - ***********************/ - -void WIZCHIP_WRITE(uint32_t AddrSel, uint16_t wb ) -{ - WIZCHIP_CRITICAL_ENTER(); - WIZCHIP.CS._select(); - -#if ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_DIR_) ) - #if(_WIZCHIP_IO_BUS_WIDTH_ == 8) - WIZCHIP.IF.BUS._write_data(AddrSel, (uint8_t)(wb>>8)); - WIZCHIP.IF.BUS._write_data(WIZCHIP_OFFSET_INC(AddrSel,1),(uint8_t)wb); - #elif(_WIZCHIP_IO_BUS_WIDTH_ == 16) - WIZCHIP.IF.BUS._write_data(AddrSel, wb); - #else - #error "Abnoraml _WIZCHIP_IO_BUS_WIDTH_. Should be 8 or 16" - #endif -#elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) ) - #if(_WIZCHIP_IO_BUS_WIDTH_ == 8) - WIZCHIP.IF.BUS._write_data(IDM_AR, (uint8_t)(AddrSel >> 8)); - WIZCHIP.IF.BUS._write_data(WIZCHIP_OFFSET_INC(IDM_AR,1),(uint8_t)AddrSel); - WIZCHIP.IF.BUS._write_data(IDM_DR,(uint8_t)(wb>>8)); - WIZCHIP.IF.BUS._write_data(WIZCHIP_OFFSET_INC(IDM_DR,1),(uint8_t)wb); - #elif(_WIZCHIP_IO_BUS_WIDTH_ == 16) - WIZCHIP.IF.BUS._write_data(IDM_AR, (uint16_t)AddrSel); - WIZCHIP.IF.BUS._write_data(IDM_DR, wb); - #else - #error "Abnoraml _WIZCHIP_IO_BUS_WIDTH_. Should be 8 or 16" - #endif -#else - #error "Unknown _WIZCHIP_IO_MODE_ in W5300. !!!" -#endif - - WIZCHIP.CS._deselect(); - WIZCHIP_CRITICAL_EXIT(); -} - -uint16_t WIZCHIP_READ(uint32_t AddrSel) -{ - uint16_t ret; - - WIZCHIP_CRITICAL_ENTER(); - WIZCHIP.CS._select(); - -#if ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_DIR_) ) - #if (_WIZCHIP_IO_BUS_WIDTH_ == 8) - ret = (((uint16_t)WIZCHIP.IF.BUS._read_data(AddrSel)) << 8) | - (((uint16_t)WIZCHIP.IF.BUS._read_data(WIZCHIP_OFFSET_INC(AddrSel,1))) & 0x00FF) ; - #elif(_WIZCHIP_IO_BUS_WIDTH_ == 16) - ret = WIZCHIP.IF.BUS._read_data(AddrSel); - #else - #error "Abnoraml _WIZCHIP_IO_BUS_WIDTH_. Should be 8 or 16" - #endif -#elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) ) - #if(_WIZCHIP_IO_BUS_WIDTH_ == 8) - WIZCHIP.IF.BUS._write_data(IDM_AR, (uint8_t)(AddrSel >> 8)); - WIZCHIP.IF.BUS._write_data(WIZCHIP_OFFSET_INC(IDM_AR,1),(uint8_t)AddrSel); - ret = (((uint16_t)WIZCHIP.IF.BUS._read_data(IDM_DR)) << 8) | - (((uint16_t)WIZCHIP.IF.BUS._read_data(WIZCHIP_OFFSET_INC(IDM_DR,1))) & 0x00FF); - #elif(_WIZCHIP_IO_BUS_WIDTH_ == 16) - WIZCHIP.IF.BUS._write_data(IDM_AR, (uint16_t)AddrSel); - ret = WIZCHIP.IF.BUS._read_data(IDM_DR); - #else - #error "Abnoraml _WIZCHIP_IO_BUS_WIDTH_. Should be 8 or 16" - #endif -#else - #error "Unknown _WIZCHIP_IO_MODE_ in W5300. !!!" -#endif - - WIZCHIP.CS._deselect(); - WIZCHIP_CRITICAL_EXIT(); - return ret; -} - - -void setTMSR(uint8_t sn,uint8_t tmsr) -{ - uint16_t tmem; - tmem = WIZCHIP_READ(WIZCHIP_OFFSET_INC(TMS01R, (sn & 0xFE))); - if(sn & 0x01) tmem = (tmem & 0xFF00) | (((uint16_t)tmsr ) & 0x00FF) ; - else tmem = (tmem & 0x00FF) | (((uint16_t)tmsr) << 8) ; - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(TMS01R, (sn & 0xFE)),tmem); -} - -uint8_t getTMSR(uint8_t sn) -{ - if(sn & 0x01) - return (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(TMS01R, (sn & 0xFE))) & 0x00FF); - return (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(TMS01R, (sn & 0xFE))) >> 8); -} - -void setRMSR(uint8_t sn,uint8_t rmsr) -{ - uint16_t rmem; - rmem = WIZCHIP_READ(WIZCHIP_OFFSET_INC(RMS01R, (sn & 0xFE))); - if(sn & 0x01) rmem = (rmem & 0xFF00) | (((uint16_t)rmsr ) & 0x00FF) ; - else rmem = (rmem & 0x00FF) | (((uint16_t)rmsr) << 8) ; - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(RMS01R, (sn & 0xFE)),rmem); -} - -uint8_t getRMSR(uint8_t sn) -{ - if(sn & 0x01) - return (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(RMS01R, (sn & 0xFE))) & 0x00FF); - return (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(RMS01R, (sn & 0xFE))) >> 8); -} - -uint32_t getSn_TX_FSR(uint8_t sn) -{ - uint32_t free_tx_size=0; - uint32_t free_tx_size1=1; - while(1) - { - free_tx_size = (((uint32_t)WIZCHIP_READ(Sn_TX_FSR(sn))) << 16) | - (((uint32_t)WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_FSR(sn),2))) & 0x0000FFFF); // read - if(free_tx_size == free_tx_size1) break; // if first == sencond, Sn_TX_FSR value is valid. - free_tx_size1 = free_tx_size; // save second value into first - } - return free_tx_size; -} - -uint32_t getSn_RX_RSR(uint8_t sn) -{ - uint32_t received_rx_size=0; - uint32_t received_rx_size1=1; - while(1) - { - received_rx_size = (((uint32_t)WIZCHIP_READ(Sn_RX_RSR(sn))) << 16) | - (((uint32_t)WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RSR(sn),2))) & 0x0000FFFF); - if(received_rx_size == received_rx_size1) break; - received_rx_size1 = received_rx_size; // if first == sencond, Sn_RX_RSR value is valid. - } // save second value into first - return received_rx_size + (uint32_t)((sock_pack_info[sn] & 0x02) ? 1 : 0); -} - - -void wiz_send_data(uint8_t sn, uint8_t *wizdata, uint32_t len) -{ - uint32_t i = 0; - if(len == 0) return; - - for(i = 0; i < len ; i += 2) - setSn_TX_FIFOR(sn, (((uint16_t)wizdata[i]) << 8) | (((uint16_t)wizdata[i+1]) & 0x00FF)) -} - -void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint32_t len) -{ - uint16_t rd = 0; - uint32_t i = 0; - - if(len == 0) return; - - for(i = 0; i < len; i++) - { - if((i & 0x01)==0) - { - rd = getSn_RX_FIFOR(sn); - wizdata[i] = (uint8_t)(rd >> 8); - } - else wizdata[i] = (uint8_t)rd; // For checking the memory access violation - } - sock_remained_byte[sn] = (uint8_t)rd; // back up the remaind fifo byte. -} - -void wiz_recv_ignore(uint8_t sn, uint32_t len) -{ - uint32_t i = 0; - for(i = 0; i < len ; i += 2) getSn_RX_FIFOR(sn); -} - - -#endif diff --git a/lib/ioLibrary_Driver/W5300/w5300.h b/lib/ioLibrary_Driver/W5300/w5300.h deleted file mode 100644 index a8bcd18..0000000 --- a/lib/ioLibrary_Driver/W5300/w5300.h +++ /dev/null @@ -1,2336 +0,0 @@ -#ifndef _W5300_H_ -#define _W5300_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -//***************************************************************************** -// -//! \file w5300.h -//! \brief W5300 HAL Header File. -//! \version 1.0.0 -//! \date 2015/05/01 -//! \par Revision history -//! <2015/05/01> 1st Released for integrating with ioLibrary -//! Download the latest version directly from GitHub. Please visit the our GitHub repository for ioLibrary. -//! >> https://github.com/Wiznet/ioLibrary_Driver -//! \author MidnightCow -//! \copyright -//! -//! Copyright (c) 2015, 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 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 -#include "wizchip_conf.h" - -/// \cond DOXY_APPLY_CODE -#if (_WIZCHIP_ == 5300) -/// \endcond - -#define _WIZCHIP_SN_BASE_ (0x0200) -#define _WIZCHIP_SN_SIZE_ (0x0040) - - -#define WIZCHIP_CREG_BLOCK 0x00 ///< Common register block -#define WIZCHIP_SREG_BLOCK(N) (_WIZCHIP_SN_BASE_+ _WIZCHIP_SN_SIZE_*N) ///< Socket N register block - -#define WIZCHIP_OFFSET_INC(ADDR, N) (ADDR + N) ///< Increase offset address - -#if (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_DIR_) - #define _W5300_IO_BASE_ _WIZCHIP_IO_BASE_ -#elif (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) - #define IDM_AR ((_WIZCHIP_IO_BASE_ + 0x0002)) ///< Indirect mode address register - #define IDM_DR ((_WIZCHIP_IO_BASE_ + 0x0004)) ///< Indirect mode data register - #define _W5300_IO_BASE_ 0x0000 -#elif (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_) - #error "Unkonw _WIZCHIP_IO_MODE_" -#endif - -/////////////////////////////////////// -// Definition For Legacy Chip Driver // -/////////////////////////////////////// -#define IINCHIP_READ(ADDR) WIZCHIP_READ(ADDR) ///< The defined for legacy chip driver -#define IINCHIP_WRITE(ADDR,VAL) WIZCHIP_WRITE(ADDR,VAL) ///< The defined for legacy chip driver -//#define IINCHIP_READ_BUF(ADDR,BUF,LEN) WIZCHIP_READ_BUF(ADDR,BUF,LEN) ///< The defined for legacy chip driver -//#define IINCHIP_WRITE_BUF(ADDR,BUF,LEN) WIZCHIP_WRITE(ADDR,BUF,LEN) ///< The defined for legacy chip driver - -//-------------------------- defgroup --------------------------------- -/** - * @defgroup W5300 W5300 - * - * @brief WHIZCHIP register defines and I/O functions of @b W5300. - * - * - @ref WIZCHIP_register_W5300 : @ref Common_register_group_W5300 and @ref Socket_register_group_W5300 - * - @ref WIZCHIP_IO_Functions_W5300 : @ref Basic_IO_function_W5300, @ref Common_register_access_function_W5300 and @ref Socket_register_access_function_W5300 - */ - - -/** - * @defgroup WIZCHIP_register_W5300 WIZCHIP register - * @ingroup W5300 - * - * @brief WHIZCHIP register defines register group of @b W5300. - * - * - @ref Common_register_group_W5300 : Common register group - * - @ref Socket_register_group_W5300 : \c SOCKET n register group - */ - - -/** - * @defgroup WIZCHIP_IO_Functions_W5300 WIZCHIP I/O functions - * @ingroup W5300 - * - * @brief This supports the basic I/O functions for @ref WIZCHIP_register_W5300. - * - * - Basic I/O function \n - * WIZCHIP_READ(), WIZCHIP_WRITE() \n\n - * - * - @ref Common_register_group_W5300 access functions \n - * -# @b Mode \n - * getMR(), setMR() - * -# @b Interrupt \n - * getIR(), setIR(), getIMR(), setIMR(), getSIR(), setSIR(), getSIMR(), setSIMR() - * -# Network Information \n - * getSHAR(), setSHAR(), getGAR(), setGAR(), getSUBR(), setSUBR(), getSIPR(), setSIPR() - * -# @b Retransmission \n - * getRCR(), setRCR(), getRTR(), setRTR() - * -# @b PPPoE \n - * getPTIMER(), setPTIMER(), getPMAGIC(), getPMAGIC(), getPSID(), setPSID(), getPHAR(), setPHAR(), getPMRU(), setPMRU() - * -# ICMP packet \n - * getUIPR(), getUPORTR() - * -# @b Socket Memory \n - * getMTYPER(), setMTYPER() \n - * getTMS01R(), getTMS23R(), getTMS45R(), getTMS67R(), setTMS01R(), setTMS23R(), setTMS45R(), setTMS67R() \n - * getRMS01R(), getRMS23R(), getRMS45R(), getRMS67R(), setRMS01R(), setRMS23R(), setRMS45R(), setRMS67R() \n - * -# @b etc. \n - * getPn_BRDYR(), setPn_BRDYR(), getPn_BDPTHR(), setPn_BDPTHR(), getIDR() \n\n - * - * - \ref Socket_register_group_W5300 access functions \n - * -# SOCKET control \n - * getSn_MR(), setSn_MR(), getSn_CR(), setSn_CR(), getSn_IMR(), setSn_IMR(), getSn_IR(), setSn_IR() - * -# SOCKET information \n - * getSn_SR(), getSn_DHAR(), setSn_DHAR(), getSn_PORT(), setSn_PORT(), getSn_DIPR(), setSn_DIPR(), getSn_DPORT(), setSn_DPORT() - * getSn_MSSR(), setSn_MSSR() - * -# SOCKET communication \n - * getSn_RXBUF_SIZE(), setSn_RXBUF_SIZE(), getSn_TXBUF_SIZE(), setSn_TXBUF_SIZE() \n - * getSn_TX_RD(), getSn_TX_WR(), setSn_TX_WR() \n - * getSn_RX_RD(), setSn_RX_RD(), getSn_RX_WR() \n - * getSn_TX_FSR(), getSn_RX_RSR(), getSn_KPALVTR(), setSn_KPALVTR() - * -# IP header field \n - * getSn_FRAG(), setSn_FRAG(), getSn_TOS(), setSn_TOS() \n - * getSn_TTL(), setSn_TTL() - */ - - -/** - * @defgroup Common_register_group_W5300 Common register - * @ingroup WIZCHIP_register_W5300 - * - * @brief Common register group\n - * It set the basic for the networking\n - * It set the configuration such as interrupt, network information, ICMP, etc. - * @details - * @sa MR : Mode register. - * @sa GAR, SUBR, SHAR, SIPR : Network Configuration - * @sa IR, _IMR_ : Interrupt. - * @sa MTYPER, TMS01R,TMS23R, TMS45R, TMS67R,RMS01R,RMS23R, RMS45R, RMS67R : Socket TX/RX memory - * @sa _RTR_, _RCR_ : Data retransmission. - * @sa PTIMER, PMAGIC, PSID, PDHAR : PPPoE. - * @sa UIPR, UPORTR, FMTUR : ICMP message. - * @sa Pn_BRDYR, Pn_BDPTHR, IDR : etc. - */ - - -/** - * @defgroup Socket_register_group_W5300 Socket register - * @ingroup WIZCHIP_register_W5300 - * - * @brief Socket register group.\n - * Socket register configures and control SOCKETn which is necessary to data communication. - * @details - * @sa Sn_MR, Sn_CR, Sn_IR, Sn_IMR : SOCKETn Control - * @sa Sn_SR, Sn_PORT, Sn_DHAR, Sn_DIPR, Sn_DPORT : SOCKETn Information - * @sa Sn_MSSR, Sn_TOS, Sn_TTL, Sn_KPALVTR, Sn_FRAG : Internet protocol. - * @sa Sn_TX_WRSR, Sn_TX_FSR, Sn_TX_RD, Sn_TX_WR, Sn_RX_RSR, Sn_RX_RD, Sn_RX_WR, Sn_TX_FIFOR, Sn_RX_FIFOR : Data communication - */ - - - /** - * @defgroup Basic_IO_function_W5300 Basic I/O function - * @ingroup WIZCHIP_IO_Functions_W5300 - * @brief These are basic input/output functions to read values from register or write values to register. - */ - -/** - * @defgroup Common_register_access_function_W5300 Common register access functions - * @ingroup WIZCHIP_IO_Functions_W5300 - * @brief These are functions to access common registers. - */ - -/** - * @defgroup Socket_register_access_function_W5300 Socket register access functions - * @ingroup WIZCHIP_IO_Functions_W5300 - * @brief These are functions to access socket registers. - */ - -//------------------------------- defgroup end -------------------------------------------- - -//----------------------------- W5300 Common Registers ----------------------------- -/** - * @ingroup Common_register_group_W5300 - * @brief Mode Register address(R/W)\n - * @ref MR is used for S/W reset, ping block mode, PPPoE mode and etc. - * @details Each bit of @ref MR defined as follows. - * - * - * - * - * - *
15 14 13 12 11 10 9 8
DBW MPF WDFRDF Reserved FS
7 6 5 4 3 2 1 0
RST Reserved WOL PB PPPoE Reserved FARP Reserved
- * - \ref MR_DBW : Data bus width (0 : 8 Bit, 1 : 16 Bit), Read Only - * - \ref MR_MPF : Received a Pause Frame from MAC layer (0 : Normal Frame, 1 : Pause Frame), Read Only - * - \ref MR_WDF : Write Data Fetch time (When CS signal is low, W5300 Fetch a written data by Host after PLL_CLK * MR_WDF) - * - \ref MR_RDH : Read Data Hold time (0 : No use data hold time, 1 : Use data hold time, 2 PLL_CLK) - * - \ref MR_FS : FIFO Swap (0 : Disable Swap, 1 : Enable Swap) - * - \ref MR_RST : Reset - * - \ref MR_WOL : Wake on LAN - * - \ref MR_PB : Ping block - * - \ref MR_PPPOE : PPPoE mode - * - \ref MR_FARP : Force ARP mode - */ -#define MR (_WIZCHIP_IO_BASE_) - -/** - * @ingroup Common_register_group_W5300 - * @brief Interrupt Register(R/W) - * @details \ref IR indicates the interrupt status. Each bit of \ref IR will be still until the bit will be written to by the host. - * If \ref IR is not equal to 0x0000 INTn PIN is asserted to low until it is 0x0000\n\n - * Each bit of \ref IR defined as follows. - * - * - * - * - * - *
15 14 13 12 11 10 9 8
IPCF DPUR PPPT FMTU Reserved Reserved Reserved Reserved
7 6 5 4 3 2 1 0
S7_INT S6_INT S5_INT S4_INT S3_INT S2_INT S1_INT S0_INT
- * - \ref IR_IPCF : IP conflict - * - \ref IR_DPUR : Destination Port Unreachable - * - \ref IR_PPPT : PPPoE Termination - * - \ref IR_FMTU : Fragmented MTU - * - \ref IR_SnINT(n) : Interrupted from SOCKETn - * - * @note : In W5300, IR is operated same as IR and SIR in other WIZCHIP(5100,5200,W5500) - */ -#define IR (_W5300_IO_BASE_ + 0x02) - -/** - * @ingroup Common_register_group_W5300 - * @brief Socket Interrupt Mask Register(R/W) - * @details Each bit of \ref _IMR_ corresponds to each bit of \ref IR. - * When a bit of _IMR_ is and the corresponding bit of \ref IR is Interrupt will be issued. - * In other words, if a bit of _IMR_, an interrupt will be not issued even if the corresponding bit of \ref IR is set - * @note : In W5300, _IMR_ is operated same as _IMR_ and SIMR in other WIZCHIP(5100,5200,W5500) - */ -#define _IMR_ (_W5300_IO_BASE_ + 0x04) - - -//#define ICFGR (_W5300_IO_BASE_ + 0x06) -//#define INTLEVEL ICFGR - -/** - * @ingroup Common_register_group_W5300 - * @brief Source MAC Register address(R/W) - * @details @ref SHAR configures the source hardware address. - */ -#define SHAR (_W5300_IO_BASE_ + 0x08) - - -/** - * @ingroup Common_register_group_W5300 - * @brief Gateway IP Register address(R/W) - * @details @ref GAR configures the default gateway address. - */ - #define GAR (_W5300_IO_BASE_ + 0x10) - -/** - * @ingroup Common_register_group_W5300 - * @brief Subnet mask Register address(R/W) - * @details @ref SUBR configures the subnet mask address. - */ -#define SUBR (_W5300_IO_BASE_ + 0x14) - -/** - * @ingroup Common_register_group_W5300 - * @brief Source IP Register address(R/W) - * @details @ref SIPR configures the source IP address. - */ -#define SIPR (_W5300_IO_BASE_ + 0x18) - -/** - * @ingroup Common_register_group_W5300 - * @brief Timeout register address( 1 is 100us )(R/W) - * @details @ref _RTR_ configures the retransmission timeout period. The unit of timeout period is 100us and the default of @ref _RTR_ is x07D0. - * And so the default timeout period is 200ms(100us X 2000). During the time configured by @ref _RTR_, W5300 waits for the peer response - * to the packet that is transmitted by \ref Sn_CR (CONNECT, DISCON, CLOSE, SEND, SEND_MAC, SEND_KEEP command). - * If the peer does not respond within the @ref _RTR_ time, W5300 retransmits the packet or issues timeout. - */ - #define _RTR_ (_W5300_IO_BASE_ + 0x1C) - -/** - * @ingroup Common_register_group_W5300 - * @brief Retry count register(R/W) - * @details @ref _RCR_ configures the number of time of retransmission. - * When retransmission occurs as many as ref _RCR_+1 Timeout interrupt is issued (@ref Sn_IR_TIMEOUT = '1'). - */ -#define _RCR_ (_W5300_IO_BASE_ + 0x1E) - -/** - * @ingroup Common_register_group_W5300 - * @brief TX memory size of \c SOCKET 0 & 1 - * @details TMS01R configures the TX buffer block size of \c SOCKET 0 & 1. The default value is configured with 8KB and can be configure from 0 to 64KB with unit 1KB. - * But the sum of all SOCKET TX buffer size should be multiple of 8 and the sum of all SOCKET TX and RX memory size can't exceed 128KB. - * When exceeded nor multiple of 8, the data transmittion is invalid. - */ -#define TMS01R (_W5300_IO_BASE_ + 0x20) - -/** - * @ingroup Common_register_group_W5300 - * @brief TX memory size of \c SOCKET 2 & 3 - * @details refer to \ref TMS01R - */ -#define TMS23R (TMS01R + 2) - -/** - * @ingroup Common_register_group_W5300 - * @brief TX memory size of \c SOCKET 4 & 5 - * @details refer to \ref TMS01R - */ -#define TMS45R (TMS01R + 4) - -/** - * @ingroup Common_register_group_W5300 - * @brief TX memory size of \c SOCKET 6 & 7 - * @details refer to \ref TMS01R - */ -#define TMS67R (TMS01R + 6) - -/** - * @ingroup Common_register_group_W5300 - * @brief TX memory size of \c SOCKET 0. - * @details refer to \ref TMS01R - */ -#define TMSR0 TMS01R - -/** - * @ingroup Common_register_group_W5300 - * @brief TX memory size of \c SOCKET 1. - * @details refer to \ref TMS01R - */ -#define TMSR1 (TMSR0 + 1) - -/** - * @ingroup Common_register_group_W5300 - * @brief TX memory size of \c SOCKET 2. - * @details refer to \ref TMS01R - */ -#define TMSR2 (TMSR0 + 2) - -/** - * @ingroup Common_register_group_W5300 - * @brief TX memory size of \c SOCKET 3. - * @details refer to \ref TMS01R - */ -#define TMSR3 (TMSR0 + 3) - -/** - * @ingroup Common_register_group_W5300 - * @brief TX memory size of \c SOCKET 4. - * @details refer to \ref TMS01R - */ -#define TMSR4 (TMSR0 + 4) - -/** - * @ingroup Common_register_group_W5300 - * @brief TX memory size of \c SOCKET 5. - * @details refer to \ref TMS01R - */ -#define TMSR5 (TMSR0 + 5) - -/** - * @ingroup Common_register_group_W5300 - * @brief TX memory size of \c SOCKET 6. - * @details refer to \ref TMS01R - */ -#define TMSR6 (TMSR0 + 6) - -/** - * @ingroup Common_register_group_W5300 - * @brief TX memory size of \c SOCKET 7. - * @details refer to \ref TMS01R - */ -#define TMSR7 (TMSR0 + 7) - - -/** - * @ingroup Common_register_group_W5300 - * @brief RX memory size of \c SOCKET 0 & 1 - * @details RMS01R configures the RX buffer block size of \c SOCKET 0 & 1. The default value is configured with 8KB and can be configure from 0 to 64KB with unit 1KB. - * But the sum of all SOCKET RX buffer size should be multiple of 8 and the sum of all SOCKET RX and TX memory size can't exceed 128KB. - * When exceeded nor multiple of 8, the data reception is invalid. - */ -#define RMS01R (_W5300_IO_BASE_ + 0x28) - -/** - * @ingroup Common_register_group_W5300 - * @brief RX memory size of \c SOCKET 2 & 3 - * @details Refer to \ref RMS01R - */ -#define RMS23R (RMS01R + 2) - -/** - * @ingroup Common_register_group_W5300 - * @brief RX memory size of \c SOCKET 4 & 5 - * @details Refer to \ref RMS01R - */ -#define RMS45R (RMS01R + 4) - -/** - * @ingroup Common_register_group_W5300 - * @brief RX memory size of \c SOCKET 6 & 7 - * @details Refer to \ref RMS01R - */ -#define RMS67R (RMS01R + 6) - -/** - * @ingroup Common_register_group_W5300 - * @brief RX memory size of \c SOCKET 0. - * @details refer to \ref RMS01R - */ -#define RMSR0 RMS01R - -/** - * @ingroup Common_register_group_W5300 - * @brief RX memory size of \c SOCKET 1. - * @details refer to \ref RMS01R - */ -#define RMSR1 (RMSR0 + 1) - -/** - * @ingroup Common_register_group_5300 - * @brief RX memory size of \c SOCKET 2. - * @details refer to \ref RMS01R - */ -#define RMSR2 (RMSR0 + 2) - -/** - * @ingroup Common_register_group_W5300 - * @brief RX memory size of \c SOCKET 3. - * @details refer to \ref RMS01R - */ -#define RMSR3 (RMSR0 + 3) - -/** - * @ingroup Common_register_group_W5300 - * @brief RX memory size of \c SOCKET 4. - * @details refer to \ref RMS01R - */ -#define RMSR4 (RMSR0 + 4) - -/** - * @ingroup Common_register_group_W5300 - * @brief RX memory size of \c SOCKET 5. - * @details refer to \ref RMS01R - */ -#define RMSR5 (RMSR0 + 5) - -/** - * @ingroup Common_register_group_W5300 - * @brief RX memory size of \c SOCKET 6. - * @details refer to \ref RMS01R - */ -#define RMSR6 (RMSR0 + 6) - -/** - * @ingroup Common_register_group_W5300 - * @brief RX memory size of \c SOCKET 7. - * @details refer to \ref RMS01R - */ -#define RMSR7 (RMSR0 + 7) - - - -/** - * @ingroup Common_register_group_W5300 - * @brief Memory Type Register - * @details W5300’s 128Kbytes data memory (Internal TX/RX memory) is composed of 16 memory blocks - * of 8Kbytes. MTYPER configures type of each 8KB memory block in order to select RX or TX memory. - * The type of 8KB memory block corresponds to each bit of MTYPER. When the bit is ‘1’, it is used as TX - * memory, and the bit is ‘0’, it is used as RX memory. MTYPER is configured as TX memory type - * from the lower bit. The rest of the bits not configured as TX memory, should be set as ‘0’. - */ -#define MTYPER (_W5300_IO_BASE_ + 0x30) - -/** - * @ingroup Common_register_group_W5300 - * @brief PPPoE Authentication Type register - * @details It notifies authentication method negotiated with PPPoE server. - * W5300 supports 2 types of authentication methods. - * - PAP : 0xC023 - * - CHAP : 0xC223 - */ -#define PATR (_W5300_IO_BASE_ + 0x32) - -//#define PPPALGOR (_W5300_IO_BASE_ + 0x34) - -/** - * @ingroup Common_register_group_W5300 - * @brief PPP Link Control Protocol Request Timer Register - * @details It configures transmitting timer of link control protocol (LCP) echo request. Value 1 is about 25ms. - */ -#define PTIMER (_W5300_IO_BASE_ + 0x36) - -/** - * @ingroup Common_register_group_W5300 - * @brief PPP LCP magic number register - * @details It configures byte value to be used for 4bytes “Magic Number” during LCP negotiation with PPPoE server. - */ -#define PMAGICR (_W5300_IO_BASE_ + 0x38) - -//#define PSTATER (_W5300_IO_BASE_ + 0x3A) - -/** - * @ingroup Common_register_group_W5300 - * @brief PPPoE session ID register - * @details It notifies PPP session ID to be used for communication with PPPoE server (acquired by PPPoE-process of W5300). - */ -#define PSIDR (_W5300_IO_BASE_ + 0x3C) - -/** - * @ingroup Common_register_group_W5300 - * @brief PPPoE destination hardware address register - * @details It notifies hardware address of PPPoE server (acquired by PPPoE-process of W5300). - */ -#define PDHAR (_W5300_IO_BASE_ + 0x40) - -/** - * @ingroup Common_register_group_W5300 - * @brief Unreachable IP address register - * @details When trying to transmit UDP data to destination port number which is not open, - * W5300 can receive ICMP (Destination port unreachable) packet. \n - * In this case, \ref IR_DPUR bit of \ref IR becomes '1'. - * And destination IP address and unreachable port number of ICMP packet can be acquired through UIPR and \ref UPORTR. - */ -#define UIPR (_W5300_IO_BASE_ + 0x48) - -/** - * @ingroup Common_register_group_W5300 - * @brief Unreachable port number register - * @details Refer to \ref UIPR. - */ -#define UPORTR (_W5300_IO_BASE_ + 0x4C) - -/** - * @ingroup Common_register_group_W5300 - * @brief Fragment MTU register - * @details When communicating with the peer having a different MTU, W5300 can receive an ICMP(Fragment MTU) packet. - * At this case, IR(FMTU) becomes ‘1’ and destination IP address and fragment MTU value of ICMP packet can be acquired through UIPR and FMTUR. - * In order to keep communicating with the peer having Fragment MTU, set the FMTUR first in Sn_MSSR of the SOCKETn, and try the next communication. - */ -#define FMTUR (_W5300_IO_BASE_ + 0x4E) - -//#define Sn_RTCR(n) (_W5300_IO_BASE_ + 0x50 + n*2) - -/** - * @ingroup Common_register_group_W5300 - * @brief PIN 'BRDYn' configure register - * @details It configures the PIN "BRDYn" which is monitoring TX/RX memory status of the specified SOCKET. - * If the free buffer size of TX memory is same or bigger than the buffer depth of \ref Pn_BDPTHR, - * or received buffer size of RX memory is same or bigger than the \ref Pn_BDPTHR, - * PIN "BRDYn" is signaled. - * - * - * - * - * - *
15 14 13 12 11 10 9 8
Reserved, Read as 0
7 6 5 4 3 2 1 0
PEN MT PPL Reserved SN
- * - * - \ref Pn_PEN Enable PIN 'BRDYn' (0 : Disable, 1 : Enable) - * - \ref Pn_MT Monitoring Memory type (0 : RX memory, 1 : TX Memory) - * - \ref Pn_PPL PIN Polarity bit of Pn_BRDYR. (0 : Low sensitive, 1 : High sensitive) - * - \ref Pn_SN(n) Monitoring SOCKET number of Pn_BRDYR - */ -#define Pn_BRDYR(n) (_W5300_IO_BASE_ + 0x60 + n*4) - -/** - * @ingroup Common_register_group_W5300 - * @brief PIN 'BRDYn' buffer depth Register - * @details It configures buffer depth of PIN "BRDYn". - * When monitoring TX memory and \ref Sn_TX_FSR is same or bigger than Pn_BDPTHR, the PIN "BRDYn" is signaled. - * When monitoring RX memory and if \ref Sn_RX_RSR is same or bigger than Pn_BDPTHR, PIN "BRDYn" is signaled. - * The value for Pn_BDPTHR can't exceed TX/RX memory size allocated by TMSR or RMSR such like as \ref TMS01R or \ref RMS01R. - */ -#define Pn_BDPTHR(n) (_W5300_IO_BASE_ + 0x60 + n*4 + 2) - -/** - * @ingroup Common_register_group_W5300 - * @brief W5300 identification register. - * @details Read Only. 0x5300. - */ -#define IDR (_W5300_IO_BASE_ + 0xFE) -#define VERSIONR IDR - - -//----------------------------- W5300 SOCKET Registers ----------------------------- - -/** - * @ingroup Socket_register_group_W5300 - * @brief Socket Mode register(R/W) - * @details @ref Sn_MR configures the option or protocol type of Socket n.\n\n - * Each bit of @ref Sn_MR defined as the following. - * - * - * - * - * - *
15 14 13 12 11 10 9 8
Reserved. Read as 0 ALIGN
7 6 5 4 3 2 1 0
MULTI MF ND/IGMPv Reserved PROTOCOL[3:0]
- * - @ref Sn_MR_ALIGN : Alignment bit of Sn_MR, Only valid in \ref Sn_MR_TCP. (C0 : Include TCP PACK_INFO, 1 : Not include TCP PACK_INFO) - * - @ref Sn_MR_MULTI : Support UDP Multicasting - * - @ref Sn_MR_MF : Enable MAC Filter (0 : Disable, 1 - Enable), When enabled, W5300 can receive only both own and broadcast packet. - * - @ref Sn_MR_ND : No Delayed Ack(TCP) flag - * - @ref Sn_MR_IGMPv : IGMP version used in UDP mulitcasting. (0 : Version 2, 1 : Version 2) - * - PROTOCOL[3:0] - * - * - * - * - * - * - * - * - *
Protocol[3] Protocol[2] Protocol[1] Protocol[0] @b Meaning
0 0 0 0 Closed
0 0 0 1 TCP
0 0 1 0 UDP
0 0 1 1 IPCRAW
0 1 0 0 MACRAW
0 1 0 1 PPPoE
- * - * - @ref Sn_MR_PPPoE : PPPoE - * - @ref Sn_MR_MACRAW : MAC LAYER RAW SOCK - * - @ref Sn_MR_IPRAW : IP LAYER RAW SOCK - * - @ref Sn_MR_UDP : UDP - * - @ref Sn_MR_TCP : TCP - * - @ref Sn_MR_CLOSE : Unused socket - * @note MACRAW mode should be only used in Socket 0. - */ -#define Sn_MR(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x00) - -/** - * @ingroup Socket_register_group_W5300 - * @brief Socket command register(R/W) - * @details This is used to set the command for Socket n such as OPEN, CLOSE, CONNECT, LISTEN, SEND, and RECEIVE.\n - * After W5500 accepts the command, the @ref Sn_CR register is automatically cleared to 0x00. - * Even though @ref Sn_CR is cleared to 0x00, the command is still being processed.\n - * To check whether the command is completed or not, please check the @ref Sn_IR or @ref Sn_SR. - * - @ref Sn_CR_OPEN : Initialize or open socket. - * - @ref Sn_CR_LISTEN : Wait connection request in TCP mode(Server mode) - * - @ref Sn_CR_CONNECT : Send connection request in TCP mode(Client mode) - * - @ref Sn_CR_DISCON : Send closing request in TCP mode. - * - @ref Sn_CR_CLOSE : Close socket. - * - @ref Sn_CR_SEND : Update TX buffer pointer and send data. - * - @ref Sn_CR_SEND_MAC : Send data with MAC address, so without ARP process. - * - @ref Sn_CR_SEND_KEEP : Send keep alive message. - * - @ref Sn_CR_RECV : Update RX buffer pointer and receive data. - * - @ref Sn_CR_PCON : PPPoE connection begins by transmitting PPPoE discovery packet. - * - @ref Sn_CR_PDISCON : Closes PPPoE connection. - * - @ref Sn_CR_PCR : In each phase, it transmits REQ message. - * - @ref Sn_CR_PCN : In each phase, it transmits NAK message. - * - @ref Sn_CR_PCJ : In each phase, it transmits REJECT message. - */ -#define Sn_CR(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x02) - -/** - * @ingroup Socket_register_group_W5300 - * @brief socket interrupt mask register(R) - * @details @ref Sn_IMR masks the interrupt of Socket n. - * Each bit corresponds to each bit of @ref Sn_IR. When a Socket n Interrupt is occurred and the corresponding bit of @ref Sn_IMR is - * the corresponding bit of @ref Sn_IR becomes When both the corresponding bit of @ref Sn_IMR and @ref Sn_IR are and the n-th bit of @ref IR is - * Host is interrupted by asserted INTn PIN to low. - */ -#define Sn_IMR(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x04) - -/** - * @ingroup Socket_register_group_W5300 - * @brief Socket interrupt register(R) - * @details @ref Sn_IR indicates the status of Socket Interrupt such as establishment, termination, receiving data, timeout).\n - * When an interrupt occurs and the corresponding bit of @ref Sn_IMR is the corresponding bit of @ref Sn_IR becomes \n - * In order to clear the @ref Sn_IR bit, the host should write the bit to \n - * - * - * - * - * - *
15 14 13 12 11 10 9 8
Reserved. Read as 0
7 6 5 4 3 2 1 0
PRECV PFAIL PNEXT SENDOK TIMEOUT RECV DISCON CON
- * - \ref Sn_IR_PRECV : PPP receive - * - \ref Sn_IR_PFAIL : PPP fail - * - \ref Sn_IR_PNEXT : PPP next phase - * - \ref Sn_IR_SENDOK : SENDOK - * - \ref Sn_IR_TIMEOUT : TIMEOUT - * - \ref Sn_IR_RECV : RECV - * - \ref Sn_IR_DISCON : DISCON - * - \ref Sn_IR_CON : CON - */ -#define Sn_IR(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x06) - -/** - * @ingroup Socket_register_group_W5300 - * @brief Socket status register(R) - * @details @ref Sn_SSR indicates the status of Socket n.\n - * The status of Socket n is changed by @ref Sn_CR or some special control packet as SYN, FIN packet in TCP. - * @par Normal status - * - @ref SOCK_CLOSED : Closed - * - @ref SOCK_INIT : Initiate state - * - @ref SOCK_LISTEN : Listen state - * - @ref SOCK_ESTABLISHED : Success to connect - * - @ref SOCK_CLOSE_WAIT : Closing state - * - @ref SOCK_UDP : UDP socket - * - @ref SOCK_IPRAW : IPRAW socket - * - @ref SOCK_MACRAW : MAC raw mode socket - * - @ref SOCK_PPPoE : PPPoE mode Socket - *@par Temporary status during changing the status of Socket n. - * - @ref SOCK_SYNSENT : This indicates Socket n sent the connect-request packet (SYN packet) to a peer. - * - @ref SOCK_SYNRECV : It indicates Socket n successfully received the connect-request packet (SYN packet) from a peer. - * - @ref SOCK_FIN_WAIT : Connection state - * - @ref SOCK_CLOSING : Closing state - * - @ref SOCK_TIME_WAIT : Closing state - * - @ref SOCK_LAST_ACK : Closing state - * - @ref SOCK_ARP : ARP request state - */ -#define Sn_SSR(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x08) -#define Sn_SR(n) Sn_SSR(n) ///< For Compatible ioLibrary. Refer to @ref Sn_SSR(n) - -/** - * @ingroup Socket_register_group_W5300 - * @brief source port register(R/W) - * @details @ref Sn_PORTR configures the source port number of Socket n. - * It is valid when Socket n is used in TCP/UPD mode. It should be set before OPEN command is ordered. - */ -#define Sn_PORTR(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x0A) -#define Sn_PORT(n) Sn_PORTR(n) ///< For compatible ioLibrary. Refer to @ref Sn_PORTR(n). - -/** - * @ingroup Socket_register_group_W5300 - * @brief Peer MAC register address(R/W) - * @details @ref Sn_DHAR configures the destination hardware address of Socket n when using SEND_MAC command in UDP mode or - * it indicates that it is acquired in ARP-process by CONNECT/SEND command. - */ -#define Sn_DHAR(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x0C) - -/** - * @ingroup Socket_register_group_W5300 - * @brief Peer port register address(R/W) - * @details @ref Sn_DPORTR configures or indicates the destination port number of Socket n. It is valid when Socket n is used in TCP/UDP mode. - * In TCP clientmode, it configures the listen port number of TCP serverbefore CONNECT command. - * In TCP Servermode, it indicates the port number of TCP client after successfully establishing connection. - * In UDP mode, it configures the port number of peer to be transmitted the UDP packet by SEND/SEND_MAC command. - */ -#define Sn_DPORTR(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x12) -#define Sn_DPORT(n) Sn_DPORTR(n) ///< For compatible ioLibrary. Refer to \ref Sn_DPORTR. - - -/** - * @ingroup Socket_register_group_W5300 - * @brief Peer IP register address(R/W) - * @details @ref Sn_DIPR configures or indicates the destination IP address of Socket n. It is valid when Socket n is used in TCP/UDP mode. - * In TCP client mode, it configures an IP address of TCP serverbefore CONNECT command. - * In TCP server mode, it indicates an IP address of TCP clientafter successfully establishing connection. - * In UDP mode, it configures an IP address of peer to be received the UDP packet by SEND or SEND_MAC command. - */ - #define Sn_DIPR(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x14) - -/** - * @ingroup Socket_register_group_W5300 - * @brief Maximum Segment Size(Sn_MSSR0) register address(R/W) - * @details @ref Sn_MSSR configures or indicates the MTU(Maximum Transfer Unit) of Socket n. - */ -#define Sn_MSSR(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x18) - -/** - * @ingroup Socket_register_group_W5300 - * @brief Keep Alive Timer register(R/W) - * @details @ref Sn_KPALVTR configures the transmitting timer of KEEP ALIVE(KA)packet of SOCKETn. It is valid only in TCP mode, - * and ignored in other modes. The time unit is 5s. - * KA packet is transmittable after @ref Sn_SR is changed to SOCK_ESTABLISHED and after the data is transmitted or received to/from a peer at least once. - * In case of '@ref Sn_KPALVTR > 0', W5500 automatically transmits KA packet after time-period for checking the TCP connection (Auto-keepalive-process). - * In case of '@ref Sn_KPALVTR = 0', Auto-keep-alive-process will not operate, - * and KA packet can be transmitted by SEND_KEEP command by the host (Manual-keep-alive-process). - * Manual-keep-alive-process is ignored in case of '@ref Sn_KPALVTR > 0'. - */ -#define Sn_KPALVTR(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x1A) - -/** - * @ingroup Socket_register_group_W5300 - * @brief IP Protocol(PROTO) Register(R/W) - * @details \ref Sn_PROTO that sets the protocol number field of the IP header at the IP layer. It is - * valid only in IPRAW mode, and ignored in other modes. - */ -#define Sn_PROTOR(n) Sn_KPALVTR(n) - - -/** - * @ingroup Socket_register_group_W5300 - * @brief IP Type of Service(TOS) Register(R/W) - * @details @ref Sn_TOSR configures the TOS(Type Of Service field in IP Header) of Socket n. - * It is set before OPEN command. - */ -#define Sn_TOSR(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x1C) -#define Sn_TOS(n) Sn_TOSR(n) ///< For compatible ioLibrary. Refer to Sn_TOSR - -/** - * @ingroup Socket_register_group_W5300 - * @brief IP Time to live(TTL) Register(R/W) - * @details @ref Sn_TTLR configures the TTL(Time To Live field in IP header) of Socket n. - * It is set before OPEN command. - */ -#define Sn_TTLR(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x1E) -#define Sn_TTL(n) Sn_TTLR(n) ///< For compatible ioLibrary. Refer to Sn_TTLR - -/** - * @ingroup Socket_register_group_W5300 - * @brief SOCKETn TX write size register(R/W) - * @details It sets the byte size of the data written in internal TX memory through @ref Sn_TX_FIFOR. - * It is set before SEND or SEND_MAC command, and can't be bigger than internal TX memory - * size set by TMSR such as @ref TMS01R, TMS23R and etc. - */ -#define Sn_TX_WRSR(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x20) - -/** - * @ingroup Socket_register_group_W5300 - * @brief Transmit free memory size register(R) - * @details Sn_TX_FSR indicates the free size of Socket n TX Buffer Block. It is initialized to the configured size by TMSR such as @ref TMS01SR. - * Data bigger than Sn_TX_FSR should not be saved in the Socket n TX Buffer because the bigger data overwrites the previous saved data not yet sent. - * Therefore, check before saving the data to the Socket n TX Buffer, and if data is equal or smaller than its checked size, - * transmit the data with SEND/SEND_MAC command after saving the data in Socket n TX buffer. But, if data is bigger than its checked size, - * transmit the data after dividing into the checked size and saving in the Socket n TX buffer. - */ -#define Sn_TX_FSR(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x0024) - -/** - * @ingroup Socket_register_group_w5300 - * @brief Received data size register(R) - * @details @ref Sn_RX_RSR indicates the data size received and saved in Socket n RX Buffer. - * @ref Sn_RX_RSR does not exceed the RMSR such as @ref RMS01SR and is calculated as the difference between - * ?Socket n RX Write Pointer (@ref Sn_RX_WR)and Socket n RX Read Pointer (@ref Sn_RX_RD) - */ -#define Sn_RX_RSR(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x0028) - -/** - * @ingroup Socket_register_group_W5300 - * @brief Fragment field value in IP header register(R/W) - * @details @ref Sn_FRAGR configures the FRAG(Fragment field in IP header). - */ -#define Sn_FRAGR(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x002C) -#define Sn_FRAG(n) Sn_FRAGR(n) - -/** - * @ingroup Socket_register_group_W5300 - * @brief SOCKET n TX FIFO regsiter - * @details It indirectly accesses internal TX memory of SOCKETn. - * The internal TX memory can't be accessed directly by the host, but can be accessed through Sn_TX_FIFOR. - * If @ref MR(MT) = '0', only the Host-Write of internal TX memory is allowed through Sn_TX_FIFOR. - * But if @ref MR(MT) is '1', both of Host-Read and Host-Write are allowed. - */ -#define Sn_TX_FIFOR(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x2E) - -/** - * @ingroup Socket_register_group_W5300 - * @brief SOCKET n RX FIFO register - * @details It indirectly accesses to internal RX memory of SOCKETn. - * The internal RX memory can't be directly accessed by the host, but can be accessed through Sn_RX_FIFOR. - * If MR(MT) = '0', only the Host-Read of internal RX memory is allowed through Sn_RX_FIFOR. - * But if MR(MT) is '1', both of Host-Read and Host-Write are allowed. - */ -#define Sn_RX_FIFOR(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x30) - -//#define Sn_TX_SADR(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x32) - -//#define Sn_RX_SADR(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x34) - -//#define Sn_TX_RD(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x36) - -//#define Sn_TX_WR(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x38) - -//#define Sn_TX_ACK(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x3A) - -//#define Sn_RX_RD(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x3C) - -//#define Sn_RX_WR(n) (_W5300_IO_BASE_ + WIZCHIP_SREG_BLOCK(n) + 0x3E) - - -/************************************/ -/* The bit of MR regsiter defintion */ -/************************************/ -#define MR_DBW (1 << 15) /**< Data bus width bit of \ref MR. Read Only. (0 : 8Bit, 1 : 16Bit)*/ -#define MR_MPF (1 << 14) /**< Mac layer pause frame bit of \ref MR. (0 : Disable, 1 : Enable)*/ -#define MR_WDF(X) ((X & 0x07) << 11) /**< Write data fetch time bit of \ref MR. Fetch Data from DATA bus after PLL_CLK * MR_WDF[2:0]*/ -#define MR_RDH (1 << 10) /**< Read data hold time bit of \ref MR. Hold Data on DATA bus during 2 * PLL_CLK after CS high*/ -#define MR_FS (1 << 8) /**< FIFO swap bit of \ref MR. Swap MSB & LSB of \ref Sn_TX_FIFOR & Sn_RX_FIFOR (0 : No swap, 1 : Swap) */ -#define MR_RST (1 << 7) /**< S/W reset bit of \ref MR. (0 : Normal Operation, 1 : Reset (automatically clear after reset))*/ -#define MR_MT (1 << 5) /**< Memory test bit of \ref MR. (0 : Normal, 1 : Internal Socket memory write & read Test)*/ -#define MR_PB (1 << 4) /**< Ping block bit of \ref MR. (0 : Unblock, 1 : Block)*/ -#define MR_PPPoE (1 << 3) /**< PPPoE bit of \ref MR. (0 : No use PPPoE, 1: Use PPPoE)*/ -#define MR_DBS (1 << 2) /**< Data bus swap of \ref MR. Valid only 16bit mode (0 : No swap, 1 : Swap)*/ -#define MR_IND (1 << 0) /**< Indirect mode bit of \ref MR. (0 : Direct mode, 1 : Indirect mode) */ - - -/************************************/ -/* The bit of IR regsiter definition */ -/************************************/ -#define IR_IPCF (1 << 7) /**< IP conflict 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 << 5) /**< PPPoE terminate bit of \ref 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*/ - -/*****************************************/ -/* The bit of Pn_BRDYR regsiter definition*/ -/*****************************************/ -#define Pn_PEN (1 << 7) /**< PIN 'BRDYn' enable bit of Pn_BRDYR. */ -#define Pn_MT (1 << 6) /**< PIN memory type bit of Pn_BRDYR. */ -#define Pn_PPL (1 << 5) /**< PIN Polarity bit of Pn_BRDYR. */ -#define Pn_SN(n) ((n & 0x07) << 0) /**< What socket to monitor. */ - - -/***************************************/ -/* The bit of Sn_MR regsiter definition */ -/***************************************/ -/** - * @brief Alignment bit of \ref Sn_MR. - * @details It is valid only in the TCP (\ref Sn_MR_TCP) with TCP communication, - * when every the received DATA packet size is of even number and set as '1', - * data receiving performance can be improved by removing PACKET-INFO(data size) that is attached to every the received DATA packet. - */ -#define Sn_MR_ALIGN (1 << 8) - -/** - * @brief Multicasting bit of \ref Sn_MR - * @details It is valid only in UDP (\ref Sn_MR_UDP). - * In order to implement multicasting, set the IP address and port number in @ref Sn_DIPR and @ref Sn_DPORTR respectively before "OPEN" command(@ref Sn_CR_OPEN).\n - * 0 : Disable, 1 : Enable - */ -#define Sn_MR_MULTI (1 << 7) - -/** - * @brief MAC filter bit of \ref Sn_MR - * @details It is valid in MACRAW(@ref Sn_MR_MACRAW). - * When this bit is set as ‘1’, W5300 can receive packet that is belong in itself or broadcasting. - * When this bit is set as ‘0’, W5300 can receive all packets on Ethernet. - * When using the hybrid TCP/IP stack, it is recommended to be set as ‘1’ for reducing the receiving overhead of host. \n - * 0 : Disable, 1 : Enable - */ -#define Sn_MR_MF (1 << 6) - -/** - * @brief IGMP version bit of \ref Sn_MR - * details It is valid in case of @ref Sn_MR_MULTI='1' and UDP(@ref Sn_MR_UDP). - * It configures IGMP version to send IGMP message such as Join/Leave/Report to multicast-group. \n - * 0 : IGMPv2, 1 : IGMPv1 - */ -#define Sn_MR_IGMPv (1 << 5) -#define Sn_MR_MC Sn_MR_IGMPv ///< For compatible ioLibrary - -/** - * @brief No delayed ack bit of \ref Sn_MR - * @details It is valid in TCP(@ref Sn_MR_TCP). - * In case that it is set as '1', ACK packet is transmitted right after receiving DATA packet from the peer. - * It is recommended to be set as '1' for TCP performance improvement. - * In case that it is set as '0', ACK packet is transmitted after the time set in @ref _RTR_ regardless of DATA packet receipt.\n - * 0 : No use, 1 : Use - */ -#define Sn_MR_ND (1 << 5) - -/** - * @brief No mode - * @details This configures the protocol mode of Socket n. - * @sa Sn_MR - */ -#define Sn_MR_CLOSE 0x00 - -/** - * @brief TCP mode - * @details This configures the protocol mode of Socket n. - * @sa Sn_MR - */ -#define Sn_MR_TCP 0x01 - -/** - * @brief UDP mode - * @details This configures the protocol mode of Socket n. - * @sa Sn_MR - */ -#define Sn_MR_UDP 0x02 /**< Protocol bits of \ref Sn_MR. */ - -/** - * @brief IP LAYER RAW mode - * @details This configures the protocol mode of Socket n. - * @sa Sn_MR - */ -#define Sn_MR_IPRAW 0x03 /**< Protocol bits of \ref Sn_MR. */ - -/** - * @brief MAC LAYER RAW mode - * @details This configures the protocol mode of Socket 0. - * @sa Sn_MR - * @note MACRAW mode should be only used in Socket 0. - */ -#define Sn_MR_MACRAW 0x04 - -/** - * @brief PPPoE mode - * @details This configures the protocol mode of Socket 0. - * @sa Sn_MR - * @note PPPoE mode should be only used in Socket 0. - */ -#define Sn_MR_PPPoE 0x05 /**< Protocol bits of \ref Sn_MR. */ - -#define SOCK_STREAM Sn_MR_TCP /**< For Berkeley Socket API, Refer to @ref Sn_MR_TCP */ -#define SOCK_DGRAM Sn_MR_UDP /**< For Berkeley Socket API, Refer to @ref Sn_MR_UDP */ - - - -/******************************/ -/* The values of CR definition */ -/******************************/ -/** - * @brief Initialize or open a socket - * @details Socket n is initialized and opened according to the protocol selected in Sn_MR(P3:P0). - * The table below shows the value of @ref Sn_SR corresponding to @ref Sn_MR.\n - * - * - * - * - * - * - * - * - *
\b Sn_MR (P[3:0]) \b Sn_SR
Sn_MR_CLOSE (000)
Sn_MR_TCP (001) SOCK_INIT (0x13)
Sn_MR_UDP (010) SOCK_UDP (0x22)
Sn_MR_IPRAW (010) SOCK_IPRAW (0x32)
Sn_MR_MACRAW (100) SOCK_MACRAW (0x42)
Sn_MR_PPPoE (101) SOCK_PPPoE (0x5F)
- */ -#define Sn_CR_OPEN 0x01 - -/** - * @brief Wait connection request in TCP mode(Server mode) - * @details This is valid only in TCP mode (\ref Sn_MR(P3:P0) = \ref Sn_MR_TCP). - * In this mode, Socket n operates as a TCP serverand waits for connection-request (SYN packet) from any TCP client - * The @ref Sn_SR changes the state from \ref SOCK_INIT to \ref SOCKET_LISTEN. - * When a TCP clientconnection request is successfully established, - * the @ref Sn_SR changes from SOCK_LISTEN to SOCK_ESTABLISHED and the @ref Sn_IR(0) becomes - * But when a TCP clientconnection request is failed, @ref Sn_IR(3) becomes and the status of @ref Sn_SR changes to SOCK_CLOSED. - */ -#define Sn_CR_LISTEN 0x02 - -/** - * @brief Send connection request in TCP mode(Client mode) - * @details To connect, a connect-request (SYN packet) is sent to TCP serverconfigured by @ref Sn_DIPR & Sn_DPORT(destination address & port). - * If the connect-request is successful, the @ref Sn_SR is changed to @ref SOCK_ESTABLISHED and the Sn_IR(0) becomes \n\n - * The connect-request fails in the following three cases.\n - * 1. When a @b ARPTO occurs (@ref Sn_IR[3] = '1') because destination hardware address is not acquired through the ARP-process.\n - * 2. When a @b SYN/ACK packet is not received and @b TCPTO (Sn_IR(3) = )\n - * 3. When a @b RST packet is received instead of a @b SYN/ACK packet. In these cases, @ref Sn_SR is changed to @ref SOCK_CLOSED. - * @note This is valid only in TCP mode and operates when Socket n acts as TCP client - */ -#define Sn_CR_CONNECT 0x04 - -/** - * @brief Send closing request in TCP mode - * @details Regardless of TCP serveror TCP client the DISCON command processes the disconnect-process (b>Active close
or Passive close.\n - * @par Active close - * it transmits disconnect-request(FIN packet) to the connected peer\n - * @par Passive close - * When FIN packet is received from peer, a FIN packet is replied back to the peer.\n - * @details When the disconnect-process is successful (that is, FIN/ACK packet is received successfully), @ref Sn_SR is changed to @ref SOCK_CLOSED.\n - * Otherwise, @b TCPTO occurs (\ref Sn_IR[3]='1') and then @ref Sn_SR is changed to @ref SOCK_CLOSED. - * @note Valid only in TCP mode. - */ -#define Sn_CR_DISCON 0x08 - -/** - * @brief Close socket - * @details @ref Sn_SR is changed to @ref SOCK_CLOSED. - */ -#define Sn_CR_CLOSE 0x10 - -/** - * @brief Update TX buffer pointer and send data - * @details SEND command transmits all the data in the Socket n TX buffer thru @ref Sn_TX_FIFOR.\n - * For more details, please refer to Socket n TX Free Size Register (@ref Sn_TX_FSR) and Socket TX Write Size register (@ref Sn_TX_WRSR). - */ -#define Sn_CR_SEND 0x20 - -/** - * @brief Send data with MAC address, so without ARP process - * @details The basic operation is same as SEND.\n - * Normally SEND command transmits data after destination hardware address is acquired by the automatic ARP-process(Address Resolution Protocol).\n - * But SEND_MAC command transmits data without the automatic ARP-process.\n - * In this case, the destination hardware address is acquired from @ref Sn_DHAR configured by host, instead of APR-process. - * @note Valid only in UDP mode. - */ -#define Sn_CR_SEND_MAC 0x21 - -/** - * @brief Send keep alive message - * @details It checks the connection status by sending 1byte keep-alive packet.\n - * If the peer can not respond to the keep-alive packet during timeout time, the connection is terminated and the timeout interrupt will occur. - * @note Valid only in TCP mode. - */ -#define Sn_CR_SEND_KEEP 0x22 - -/** - * @brief Update RX buffer pointer and receive data - * @details RECV completes the processing of the received data in Socket n RX Buffer thru @ref Sn_RX_FIFOR).\n - * For more details, refer to Socket n RX Received Size Register (@ref Sn_RX_RSR) & @ref Sn_RX_FIFOR. - */ -#define Sn_CR_RECV 0x40 /**< RECV command value of \ref Sn_CR */ - -#define Sn_CR_PCON 0x23 /**< PPPoE connection begins by transmitting PPPoE discovery packet. Refer to \ref Sn_CR */ -#define Sn_CR_PDISCON 0x24 /**< Closes PPPoE connection. Refer to \ref Sn_CR */ -#define Sn_CR_PCR 0x25 /**< In each phase, it transmits REQ message. Refer to \ref Sn_CR */ -#define Sn_CR_PCN 0x26 /**< In each phase, it transmits NAK message. Refer to \ref Sn_CR */ -#define Sn_CR_PCJ 0x27 /**< In each phase, it transmits REJECT message. Refer to \ref Sn_CR */ - - -/*********************************/ -/* 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_PFAIL 0x40 /**< It is set in the case that PAP authentication is failed. Refer to \ref Sn_IR */ -#define Sn_IR_PNEXT 0x20 /**< It is set in the case that the phase is changed during PPPoE connection process. \ref Sn_IR */ -#define Sn_IR_SENDOK 0x10 /**< It is set when SEND command is completed. Refer to \ref Sn_IR */ -#define Sn_IR_TIMEOUT 0x08 /**< It is set when ARPTO or TCPTO is occured. Refer to \ref Sn_IR */ -#define Sn_IR_RECV 0x04 /**< It is set whenever data is received from a peer. Refer to \ref Sn_IR */ -#define Sn_IR_DISCON 0x02 /**< It is set when FIN or FIN/ACK packet is received from a peer. Refer to \ref Sn_IR */ -#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 definition */ -/**********************************/ -/** - * @brief The state of SOCKET intialized or closed - * @details This indicates that Socket n is released.\n - * When DICON, CLOSE command is ordered, or when a timeout occurs, it is changed to @ref SOCK_CLOSED regardless of previous status. - */ -#define SOCK_CLOSED 0x00 - -/** - * @brief The state of ARP process - * @details It is temporary state for getting a peer MAC address when TCP connect or UDP Data Send\n - * When DICON, CLOSE command is ordered, or when a timeout occurs, it is changed to @ref SOCK_CLOSED regardless of previous status. - */ -#define SOCK_ARP 0x01 /**< ARP-request is transmitted in order to acquire destination hardware address. */ - -/** - * @brief Initiate state in TCP. - * @details This indicates Socket n is opened with TCP mode.\n - * It is changed to @ref SOCK_INIT when \ref Sn_MR(P[3:0]) = '001' and OPEN command(\ref Sn_CR_OPEN) is ordered.\n - * After SOCK_INIT, user can use LISTEN(@ref Sn_CR_LISTEN)/CONNECT(@ref Sn_CR_CONNET) command. - */ -#define SOCK_INIT 0x13 - -/** - * @brief Listen state - * @details This indicates Socket n is operating as TCP servermode and waiting for connection-request (SYN packet) from a peer TCP client.\n - * It will change to @ref SOCK_ESTALBLISHED when the connection-request is successfully accepted.\n - * Otherwise it will change to @ref SOCK_CLOSED after TCPTO (@ref Sn_IR_TIMEOUT = '1') is occurred. - */ -#define SOCK_LISTEN 0x14 - -/** - * @brief Connection state - * @details This indicates Socket n sent the connect-request packet (SYN packet) to a peer.\n - * It is temporarily shown when @ref Sn_SR is changed from @ref SOCK_INIT to @ref SOCK_ESTABLISHED by @ref Sn_CR_CONNECT command.\n - * If connect-accept(SYN/ACK packet) is received from the peer at SOCK_SYNSENT, it changes to @ref SOCK_ESTABLISHED.\n - * Otherwise, it changes to @ref SOCK_CLOSED after TCPTO (@ref Sn_IR_TIMEOUT = '1') is occurred. - */ -#define SOCK_SYNSENT 0x15 - -/** - * @brief Connection state - * @details It indicates Socket n successfully received the connect-request packet (SYN packet) from a peer.\n - * If socket n sends the response (SYN/ACK packet) to the peer successfully, it changes to @ref SOCK_ESTABLISHED. \n - * If not, it changes to @ref SOCK_CLOSED after timeout (@ref Sn_IR_TIMEOUT = '1') is occurred. - */ -#define SOCK_SYNRECV 0x16 - -/** - * @brief Success to connect - * @details This indicates the status of the connection of Socket n.\n - * It changes to @ref SOCK_ESTABLISHED when the TCP SERVERprocessed the SYN packet from the TCP CLIENTduring @ref SOCK_LISTEN, or - * when the @ref Sn_CR_CONNECT command is successful.\n - * During @ref SOCK_ESTABLISHED, DATA packet can be transferred using @ref Sn_CR_SEND or @ref Sn_CR_RECV command. - */ -#define SOCK_ESTABLISHED 0x17 - -/** - * @brief Closing state - * @details These indicate Socket n is closing.\n - * These are shown in disconnect-process such as active-close and passive-close.\n - * When Disconnect-process is successfully completed, or when timeout(@ref Sn_CR_TIMTEOUT = '1') is occurred, these change to @ref SOCK_CLOSED. - */ -#define SOCK_FIN_WAIT 0x18 - -/** - * @brief Closing state - * @details These indicate Socket n is closing.\n - * These are shown in disconnect-process such as active-close and passive-close.\n - * When Disconnect-process is successfully completed, or when timeout occurs, these change to @ref SOCK_CLOSED. - */ -#define SOCK_CLOSING 0x1A - -/** - * @brief Closing state - * @details These indicate Socket n is closing.\n - * These are shown in disconnect-process such as active-close and passive-close.\n - * When Disconnect-process is successfully completed, or when timeout occurs, these change to @ref SOCK_CLOSED. - */ -#define SOCK_TIME_WAIT 0x1B - -/** - * @brief Closing state - * @details This indicates Socket n received the disconnect-request (FIN packet) from the connected peer.\n - * This is half-closing status, and data can be transferred.\n - * For full-closing, @ref Sn_CR_DISCON command is used. But For just-closing, @ref Sn_CR_CLOSE command is used. - */ -#define SOCK_CLOSE_WAIT 0x1C - -/** - * @brief Closing state - * @details This indicates Socket n is waiting for the response (FIN/ACK packet) to the disconnect-request (FIN packet) by passive-close.\n - * It changes to @ref SOCK_CLOSED when Socket n received the response successfully, or when timeout (@ref Sn_IR_TIMEOUT = '1') is occurred. - */ -#define SOCK_LAST_ACK 0x1D - -/** - * @brief UDP socket - * @details This indicates Socket n is opened in UDP mode(@ref Sn_MR(P[3:0]) = '010').\n - * It changes to SOCK_UDP when @ref Sn_MR(P[3:0]) = '010' and @ref Sn_CR_OPEN command is ordered.\n - * Unlike TCP mode, data can be transfered without the connection-process. - */ -#define SOCK_UDP 0x22 - -/** - * @brief IP raw mode socket - * @details TThe socket is opened in IPRAW mode. The SOCKET status is change to SOCK_IPRAW when @ref Sn_MR (P3:P0) is - * Sn_MR_IPRAW and @ref Sn_CR_OPEN command is used.\n - * IP Packet can be transferred without a connection similar to the UDP mode. -*/ -#define SOCK_IPRAW 0x32 - -/** - * @brief MAC raw mode socket - * @details This indicates Socket 0 is opened in MACRAW mode (@ref Sn_MR(P[3:0]) = '100' and n = 0) and is valid only in Socket 0.\n - * It changes to SOCK_MACRAW when @ref Sn_MR(P[3:0] = 100)and @ ref Sn_CR_OPEN command is ordered.\n - * Like UDP mode socket, MACRAW mode Socket 0 can transfer a MAC packet (Ethernet frame) without the connection-process. - */ -#define SOCK_MACRAW 0x42 /**< SOCKET0 is open as MACRAW mode. */ - -/** - * @brief PPPoE mode socket - * @details It is the status that SOCKET0 is opened as PPPoE mode. - * It is changed to SOCK_PPPoE in case of @ref Sn_CR_OPEN command is ordered and @ref Sn_MR(P3:P0)= @ref Sn_MR_PPPoE\n - * It is temporarily used at the PPPoE connection. - */ -#define SOCK_PPPoE 0x5F /**< SOCKET0 is open as PPPoE mode. */ - -/* IP PROTOCOL */ -#define IPPROTO_IP 0 //< Dummy for IP -#define IPPROTO_ICMP 1 //< Control message protocol -#define IPPROTO_IGMP 2 //< Internet group management protocol -#define IPPROTO_GGP 3 //< Gateway^2 (deprecated) -#define IPPROTO_TCP 6 //< TCP -#define IPPROTO_PUP 12 //< PUP -#define IPPROTO_UDP 17 //< UDP -#define IPPROTO_IDP 22 //< XNS idp -#define IPPROTO_ND 77 //< UNOFFICIAL net disk protocol -#define IPPROTO_RAW 255 //< Raw IP packet - - -/** - * @brief Enter a critical section - * - * @details It is provided to protect your shared code which are executed without distribution. \n \n - * - * In non-OS environment, It can be just implemented by disabling whole interrupt.\n - * In OS environment, You can replace it to critical section api supported by OS. - * - * \sa WIZCHIP_READ(), WIZCHIP_WRITE() - * \sa WIZCHIP_CRITICAL_EXIT() - */ -#define WIZCHIP_CRITICAL_ENTER() WIZCHIP.CRIS._enter() - -#ifdef _exit -#undef _exit -#endif - -/** - * @brief Exit a critical section - * - * @details It is provided to protect your shared code which are executed without distribution. \n\n - * - * In non-OS environment, It can be just implemented by disabling whole interrupt. \n - * In OS environment, You can replace it to critical section api supported by OS. - * - * @sa WIZCHIP_READ(), WIZCHIP_WRITE() - * @sa WIZCHIP_CRITICAL_ENTER() - */ -#define WIZCHIP_CRITICAL_EXIT() WIZCHIP.CRIS._exit() - -//////////////////////// -// Basic I/O Function // -//////////////////////// - -/** - * @ingroup Basic_IO_function_W5300 - * @brief It reads 1 byte value from a register. - * @param AddrSel Register address - * @return The value of register - */ -uint16_t WIZCHIP_READ (uint32_t AddrSel); - -/** - * @ingroup Basic_IO_function_W5300 - * @brief It writes 1 byte value to a register. - * @param AddrSel Register address - * @param wb Write data - * @return void - */ -void WIZCHIP_WRITE(uint32_t AddrSel, uint16_t wb ); - -/*********************************** - * COMMON Register Access Function * - ***********************************/ - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set Mode Register - * @param (@ref iodata_t)mr The value to be set. - * @sa getMR() - */ -#if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_) - #if (_WIZCHIP_IO_BUS_WIDTH_ == 8) - #define setMR(mr) \ - (*((uint8_t*)MR) = (uint8_t)((mr) >> 8)); (*((uint8_t*)WIZCHIP_OFFSET_INC(MR,1)) = (uint8_t)((mr) & 0xFF)) - #elif (_WIZCHIP_IO_BUS_WIDTH_ == 16) - #define setMR(mr) (*((uint16_t*)MR) = (uint16_t)((mr) & 0xFFFF)) - #else - #error "Unknown _WIZCHIP_IO_BUS_WIDTH_. You should be define _WIZCHIP_IO_BUS_WIDTH as 8 or 16." - #endif -#else - #error "Unknown _WIZCHIP_IO_MODE_" -#endif - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref MR. - * @return @ref iodata_t. The value of Mode register. - * @sa setMR() - */ -#if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_) - #if (_WIZCHIP_IO_BUS_WIDTH_ == 8) - #define getMR() (((uint16_t)(*((uint8_t*)MR)) << 8) + (((uint16_t)(*((uint8_t*)WIZCHIP_OFFSET_INC(MR,1)))) & 0x00FF)) - #elif(_WIZCHIP_IO_BUS_WIDTH_ == 16) - #define getMR() (*((uint16_t*)MR)) - #else - #error "Unknown _WIZCHIP_IO_BUS_WIDTH_. You should be define _WIZCHIP_IO_BUS_WIDTH as 8 or 16." - #endif -#else - #error "Unknown _WIZCHIP_IO_MODE_" -#endif - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set \ref IR register - * @param (uint16_t)ir Value to set \ref IR register. - * @sa getIR() - */ -#define setIR(ir) \ - WIZCHIP_WRITE(IR, ir & 0xF0FF) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get \ref IR register - * @return uint8_t. Value of \ref IR register. - * @sa setIR() - */ -#define getIR() \ - (WIZCHIP_READ(IR) & 0xF0FF) - - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set \ref _IMR_ register - * @param (uint16_t)imr Value to set @ref _IMR_ register. - * @sa getIMR() - */ -#define setIMR(imr) \ - WIZCHIP_WRITE(_IMR_, imr & 0xF0FF) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get \ref _IMR_ register - * @return uint16_t. Value of \ref IR register. - * @sa setIMR() - */ -#define getIMR() \ - (WIZCHIP_READ(_IMR_) & 0xF0FF) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set local MAC address - * @param (uint8_t*)shar Pointer variable to set local MAC address. It should be allocated 6 bytes. - * @sa getSHAR() - */ -#define setSHAR(shar) { \ - WIZCHIP_WRITE(SHAR, (((uint16_t)((shar)[0])) << 8) + (((uint16_t)((shar)[1])) & 0x00FF)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(SHAR,2), (((uint16_t)((shar)[2])) << 8) + (((uint16_t)((shar)[3])) & 0x00FF)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(SHAR,4), (((uint16_t)((shar)[4])) << 8) + (((uint16_t)((shar)[5])) & 0x00FF)); \ - } - -/** - * @ingroup Common_register_access_function - * @brief Get local MAC address - * @param (uint8_t*)shar Pointer variable to get local MAC address. It should be allocated 6 bytes. - * @sa setSHAR() - */ -#define getSHAR(shar) { \ - (shar)[0] = (uint8_t)(WIZCHIP_READ(SHAR) >> 8); \ - (shar)[1] = (uint8_t)(WIZCHIP_READ(SHAR)); \ - (shar)[2] = (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(SHAR,2)) >> 8); \ - (shar)[3] = (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(SHAR,2))); \ - (shar)[4] = (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(SHAR,4)) >> 8); \ - (shar)[5] = (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(SHAR,4))); \ - } - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set gateway IP address - * @param (uint8_t*)gar Pointer variable to set gateway IP address. It should be allocated 4 bytes. - * @sa getGAR() - */ -#define setGAR(gar) { \ - WIZCHIP_WRITE(GAR, (((uint16_t)((gar)[0])) << 8) + (((uint16_t)((gar)[1])) & 0x00FF)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(GAR,2), (((uint16_t)((gar)[2])) << 8) + (((uint16_t)((gar)[3])) & 0x00FF)); \ - } - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get gateway IP address - * @param (uint8_t*)gar Pointer variable to get gateway IP address. It should be allocated 4 bytes. - * @sa setGAR() - */ -#define getGAR(gar) { \ - (gar)[0] = (uint8_t)(WIZCHIP_READ(GAR) >> 8); \ - (gar)[1] = (uint8_t)(WIZCHIP_READ(GAR)); \ - (gar)[2] = (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(GAR,2)) >> 8); \ - (gar)[3] = (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(GAR,2))); \ - } - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set subnet mask address - * @param (uint8_t*)subr Pointer variable to set subnet mask address. It should be allocated 4 bytes. - * @sa getSUBR() - */ -#define setSUBR(subr) { \ - WIZCHIP_WRITE(SUBR, (((uint16_t)((subr)[0])) << 8) + (((uint16_t)((subr)[1])) & 0x00FF)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(SUBR,2), (((uint16_t)((subr)[2])) << 8) + (((uint16_t)((subr)[3])) & 0x00FF)); \ - } - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get subnet mask address - * @param (uint8_t*)subr Pointer variable to get subnet mask address. It should be allocated 4 bytes. - * @sa setSUBR() - */ -#define getSUBR(subr) { \ - (subr)[0] = (uint8_t)(WIZCHIP_READ(SUBR) >> 8); \ - (subr)[1] = (uint8_t)(WIZCHIP_READ(SUBR)); \ - (subr)[2] = (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(SUBR,2)) >> 8); \ - (subr)[3] = (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(SUBR,2))); \ - } - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set local IP address - * @param (uint8_t*)sipr Pointer variable to set local IP address. It should be allocated 4 bytes. - * @sa getSIPR() - */ -#define setSIPR(sipr) { \ - WIZCHIP_WRITE(SIPR, (((uint16_t)((sipr)[0])) << 8) + (((uint16_t)((sipr)[1])) & 0x00FF)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(SIPR,2), (((uint16_t)((sipr)[2])) << 8) + (((uint16_t)((sipr)[3])) & 0x00FF)); \ - } - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get local IP address - * @param (uint8_t*)sipr Pointer variable to get local IP address. It should be allocated 4 bytes. - * @sa setSIPR() - */ -#define getSIPR(sipr) { \ - (sipr)[0] = (uint8_t)(WIZCHIP_READ(SIPR) >> 8); \ - (sipr)[1] = (uint8_t)(WIZCHIP_READ(SIPR)); \ - (sipr)[2] = (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(SIPR,2)) >> 8); \ - (sipr)[3] = (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(SIPR,2))); \ - } - - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set @ref _RTR_ register - * @param (uint16_t)rtr Value to set @ref _RTR_ register. - * @sa getRTR() - */ -#define setRTR(rtr) \ - WIZCHIP_WRITE(_RTR_, rtr) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref _RTR_ register - * @return uint16_t. Value of @ref _RTR_ register. - * @sa setRTR() - */ -#define getRTR() \ - WIZCHIP_READ(_RTR_) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set @ref _RCR_ register - * @param (uint8_t)rcr Value to set @ref _RCR_ register. - * @sa getRCR() - */ -#define setRCR(rcr) \ - WIZCHIP_WRITE(_RCR_, ((uint16_t)rcr)&0x00FF) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref _RCR_ register - * @return uint8_t. Value of @ref _RCR_ register. - * @sa setRCR() - */ -#define getRCR() \ - ((uint8_t)(WIZCHIP_READ(_RCR_) & 0x00FF)) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set @ref TMS01R register - * @param (uint16_t)tms01r Value to set @ref TMS01R register. The lower socket memory size is located at MSB of tms01r. - * @sa getTMS01R() - */ -#define setTMS01R(tms01r) \ - WIZCHIP_WRITE(TMS01R,tms01r) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref TMS01R register - * @return uint16_t. Value of @ref TMS01R register. - * @sa setTMS01R() - */ -#define getTMS01R() \ - WIZCHIP_READ(TMS01R) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set @ref TMS23R register - * @param (uint16_t)tms23r Value to set @ref TMS23R register. The lower socket memory size is located at MSB of tms01r. - * @sa getTMS23R() - */ -#define setTMS23R(tms23r) \ - WIZCHIP_WRITE(TMS23R,tms23r) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref TMS23R register - * @return uint16_t. Value of @ref TMS23R register. - * @sa setTMS23R() - */ -#define getTMS23R() \ - WIZCHIP_READ(TMS23R) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set @ref TMS45R register - * @param (uint16_t)tms45r Value to set @ref TMS45R register. The lower socket memory size is located at MSB of tms45r. - * @sa getTMS45R() - */ -#define setTMS45R(tms45r) \ - WIZCHIP_WRITE(TMS45R,tms45r) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref TMS45R register - * @return uint16_t. Value of @ref TMS45R register. - * @sa setTMS45R() - */ -#define getTMS45R() \ - WIZCHIP_READ(TMS45R) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set @ref TMS67R register - * @param (uint16_t)tms67r Value to set @ref TMS67R register. The lower socket memory size is located at MSB of tms67r. - * @sa getTMS67R() - */ -#define setTMS67R(tms67r) \ - WIZCHIP_WRITE(TMS67R,tms67r) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref TMS67R register - * @return uint16_t. Value of @ref TMS67R register. - * @sa setTMS67R() - */ -#define getTMS67R() \ - WIZCHIP_READ(TMS67R) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set @ref TMSR0 ~ @ref TMSR7 register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @param (uint8_t)tmsr Value to set @ref TMSR0 ~@ref TMSR7 register. - * @sa getTMSR() - */ -void setTMSR(uint8_t sn,uint8_t tmsr); -#define setSn_TXBUF_SIZE(sn, tmsr) setTMSR(sn, tmsr) ///< For compatible ioLibrary - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref TMSR0 ~ @ref TMSR7 register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @return uint8_t. Value of @ref TMSR0 ~ @ref TMSR7 - * @sa getTMSR() - */ -uint8_t getTMSR(uint8_t sn); -#define getSn_TXBUF_SIZE(sn) getTMSR(sn) ///< For compatible ioLibrary - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set @ref RMS01R register - * @param (uint16_t)rms01r Value to set @ref RMS01R register. The lower socket memory size is located at MSB of rms01r. - * @sa getRMS01R() - */ -#define setRMS01R(rms01r) \ - WIZCHIP_WRITE(RMS01R,rms01r) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref RMS01R register - * @return uint16_t. Value of @ref RMS01R register. - * @sa setRMS01R() - */ -#define getRMS01R() \ - WIZCHIP_READ(RMS01R) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set @ref RMS23R register - * @param (uint16_t)rms23r Value to set @ref RMS23R register. The lower socket memory size is located at MSB of rms01r. - * @sa getRMS23R() - */ -#define setRMS23R(rms23r) \ - WIZCHIP_WRITE(RMS23R,rms23r) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref RMS23R register - * @return uint16_t. Value of @ref RMS23R register. - * @sa setRMS23R() - */ -#define getRMS23R() \ - WIZCHIP_READ(RMS23R) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set @ref RMS45R register - * @param (uint16_t)rms45r Value to set @ref RMS45R register. The lower socket memory size is located at MSB of rms45r. - * @sa getRMS45R() - */ -#define setRMS45R(rms45r) \ - WIZCHIP_WRITE(RMS45R,rms45r) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref RMS45R register - * @return uint16_t. Value of @ref RMS45R register. - * @sa setRMS45R() - */ -#define getRMS45R() \ - WIZCHIP_READ(RMS45R) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set @ref RMS67R register - * @param (uint16_t)rms67r Value to set @ref RMS67R register. The lower socket memory size is located at MSB of rms67r. - * @sa getRMS67R() - */ -#define setRMS67R(rms67r) \ - WIZCHIP_WRITE(RMS67R,rms67r) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref RMS67R register - * @return uint16_t. Value of @ref RMS67R register. - * @sa setRMS67R() - */ -#define getRMS67R() \ - WIZCHIP_READ(RMS67R) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set @ref RMS01R ~ @ref RMS67R register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @param (uint8_t)rmsr Value to set @ref RMSR0 ~@ref RMSR7 register. - * @sa getTMSR() - */ -void setRMSR(uint8_t sn,uint8_t rmsr); -#define setSn_RXBUF_SIZE(sn,rmsr) setRMSR(sn, rmsr) ///< For compatible ioLibrary - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref RMS01R ~ @ref RMS67R register - * @param (uint8_t)sn Socket number. It shoudl be 0 ~ 7. - * @return uint8_t. Value of @ref RMSR0 ~ @ref RMSR7 register. - * @sa setRMSR() - */ -uint8_t getRMSR(uint8_t sn); -#define getSn_RXBUF_SIZE(sn) getRMSR(sn) ///< For compatible ioLibrary - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set @ref MTYPER register - * @param (uint16_t)mtyper Value to set @ref MTYPER register. - * @sa getMTYPER() - */ -#define setMTYPER(mtype) \ - WIZCHIP_WRITE(MTYPER, mtype) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref MTYPER register - * @return uint16_t. Value of @ref MTYPER register. - * @sa setMTYPER() - */ -#define getMTYPER() \ - WIZCHIP_READ(MTYPER) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref RATR register - * @return uint16_t. Value of @ref PATR register. - */ -#define getPATR() \ - WIZCHIP_READ(PATR) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set @ref PTIMER register - * @param (uint8_t)ptimer Value to set @ref PTIMER register. - * @sa getPTIMER() - */ -#define setPTIMER(ptimer) \ - WIZCHIP_WRITE(PTIMER, ((uint16_t)ptimer) & 0x00FF) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref PTIMER register - * @return uint8_t. Value of @ref PTIMER register. - * @sa setPTIMER() - */ -#define getPTIMER() \ - ((uint8_t)(WIZCHIP_READ(PTIMER) & 0x00FF)) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set @ref PMAGIC register - * @param (uint8_t)pmagic Value to set @ref PMAGIC register. - * @sa getPMAGIC() - */ -#define setPMAGIC(pmagic) \ - WIZCHIP_WRITE(PMAGIC, ((uint16_t)pmagic) & 0x00FF) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref PMAGIC register - * @return uint8_t. Value of @ref PMAGIC register. - * @sa setPMAGIC() - */ -#define getPMAGIC() \ - ((uint8_t)(WIZCHIP_READ(PMAGIC) & 0x00FF)) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref PSID register - * @return uint16_t. Value of @ref PSID register. - */ -#define getPSIDR() \ - WIZCHIP_READ(PSIDR) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref PDHAR register - * @param (uint8_t*)pdhar Pointer variable to PPP destination MAC register address. It should be allocated 6 bytes. - */ -#define getPDHAR(pdhar) { \ - (pdhar)[0] = (uint8_t)(WIZCHIP_READ(PDHAR) >> 8); \ - (pdhar)[1] = (uint8_t)(WIZCHIP_READ(PDHAR)); \ - (pdhar)[2] = (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(PDHAR,2)) >> 8); \ - (pdhar)[3] = (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(PDHAR,2))); \ - (pdhar)[4] = (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(PDHAR,4)) >> 8); \ - (pdhar)[5] = (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(PDHAR,4))); \ - } - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get unreachable IP address. @ref UIPR - * @param (uint8_t*)uipr Pointer variable to get unreachable IP address. It should be allocated 4 bytes. - */ -#define getUIPR(uipr) { \ - (uipr)[0] = (uint8_t)(WIZCHIP_READ(UIPR) >> 8); \ - (uipr)[1] = (uint8_t)(WIZCHIP_READ(UIPR)); \ - (uipr)[2] = (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(UIPR,2)) >> 8); \ - (uipr)[3] = (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(UIPR,2))); \ - } - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref UPORTR register - * @return uint16_t. Value of @ref UPORTR register. - */ -#define getUPORTR() \ - WIZCHIP_READ(UPORTR) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref FMTUR register - * @return uint16_t. Value of @ref FMTUR register. - */ -#define getFMTUR() \ - WIZCHIP_READ(FMTUR) - - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref Pn_BRDYR register - * @return uint8_t. Value of @ref Pn_BRDYR register. - */ -#define getPn_BRDYR(p) \ - ((uint8_t)(WIZCHIP_READ(Pn_BRDYR(p)) & 0x00FF)) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set @ref Pn_BRDYR register - * @param p Pin number (p = 0,1,2,3) - * @param brdyr Set a value @ref Pn_BRDYR(p). - */ -#define setPn_BRDYR(p, brdyr) \ - WIZCHIP_WRITE(Pn_BRDYR(p), brdyr & 0x00E7) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref Pn_BDPTHR register - * @param p Pin number (p = 0,1,2,3) - * @return uint16_t. Value of @ref Pn_BDPTHR register. - */ -#define getPn_BDPTHR(p) \ - WIZCHIP_READ(Pn_BDPTHR(p)) - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Set @ref Pn_BDPTHR register - * @param p Pin number (p = 0,1,2,3) - * @param bdpthr Value of @ref Pn_BDPTHR - */ -#define setPn_BDPTHR(p, bdpthr) \ - WIZCHIP_WRITE(Pn_BDPTHR(p),bdpthr) - - -/** - * @ingroup Common_register_access_function_W5300 - * @brief Get @ref IDR register - * @return uint16_t. Always 0x5300. - */ -#define getIDR() \ - WIZCHIP_READ(IDR) - - -/*********************************** - * SOCKET Register Access Function * - ***********************************/ - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Set @ref Sn_MR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @param (uint8_t)mr Value to set @ref Sn_MR - * @sa getSn_MR() - */ -#define setSn_MR(sn, mr) \ - WIZCHIP_WRITE(Sn_MR(sn),mr) - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Get @ref Sn_MR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @return uint8_t. Value of @ref Sn_MR. - * @sa setSn_MR() - */ -#define getSn_MR(sn) \ - WIZCHIP_READ(Sn_MR(sn)) - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Set @ref Sn_CR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @param (uint8_t)cr Value to set @ref Sn_CR - * @sa getSn_CR() - */ -#define setSn_CR(sn, cr) \ - WIZCHIP_WRITE(Sn_CR(sn), ((uint16_t)cr) & 0x00FF) - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Get @ref Sn_CR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @return uint8_t. Value of @ref Sn_CR. - * @sa setSn_CR() - */ -#define getSn_CR(sn) \ - ((uint8_t)WIZCHIP_READ(Sn_CR(sn))) - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Set @ref Sn_IMR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @param (uint8_t)imr Value to set @ref Sn_IMR - * @sa getSn_IMR() - */ -#define setSn_IMR(sn, imr) \ - WIZCHIP_WRITE(Sn_IMR(sn), ((uint16_t)imr) & 0x00FF) - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Get @ref Sn_IMR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @return uint8_t. Value of @ref Sn_IMR. - * @sa setSn_IMR() - */ -#define getSn_IMR(sn) \ - ((uint8_t)WIZCHIP_READ(Sn_IMR(sn))) - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Set @ref Sn_IR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @param (uint8_t)ir Value to set @ref Sn_IR - * @sa getSn_IR() - */ -#define setSn_IR(sn, ir) \ - WIZCHIP_WRITE(Sn_IR(sn), ((uint16_t)ir) & 0x00FF) - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Get @ref Sn_IR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @return uint8_t. Value of @ref Sn_IR. - * @sa setSn_IR() - */ -#define getSn_IR(sn) \ - ((uint8_t)WIZCHIP_READ(Sn_IR(sn))) - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Get @ref Sn_SR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @return uint8_t. Value of @ref Sn_SR. - */ -#define getSn_SSR(sn) \ - ((uint8_t)WIZCHIP_READ(Sn_SR(sn))) -#define getSn_SR(sn) getSn_SSR(sn) ///< For compatible ioLibrary. Refer to getSn_SSR(). - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Set @ref Sn_PORTR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @param (uint16_t)port Variable to set @ref Sn_PORTR. - * @sa getSn_PORTR() - */ -#define setSn_PORTR(sn, port) \ - WIZCHIP_WRITE(Sn_PORTR(sn), port) -#define setSn_PORT(sn, port) setSn_PORTR(sn, port) ///< For compatible ioLibrary - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Get @ref Sn_PORTR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @return uint16_t. Variable of @ref Sn_PORTR. - * @sa setSn_PORTR() - */ -#define getSn_PORTR(sn) \ - WIZCHIP_READ(Sn_PORTR(sn)) -#define getSn_PORT(sn) getSn_PORTR(sn) ///< For compatible ioLibrary - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Set @ref Sn_DHAR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @param (uint8_t*)dhar Pointer variable to set socket n destination hardware address. It should be allocated 6 bytes. - * @sa getSn_DHAR() - */ -#define setSn_DHAR(sn, dhar) { \ - WIZCHIP_WRITE(Sn_DHAR(sn), (((uint16_t)((dhar)[0])) << 8) + (((uint16_t)((dhar)[1])) & 0x00FF)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_DHAR(sn),2), (((uint16_t)((dhar)[0])) << 8) + (((uint16_t)((dhar)[1])) & 0x00FF)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_DHAR(sn),4), (((uint16_t)((dhar)[0])) << 8) + (((uint16_t)((dhar)[1])) & 0x00FF)); \ - } - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Get @ref Sn_MR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @param (uint8_t*)dhar Pointer variable to get socket n destination hardware address. It should be allocated 6 bytes. - * @sa setSn_DHAR() - */ -#define getSn_DHAR(sn, dhar) { \ - (dhar)[0] = (uint8_t)(WIZCHIP_READ(Sn_DHAR(sn)) >> 8); \ - (dhar)[1] = (uint8_t) WIZCHIP_READ(Sn_DHAR(sn)); \ - (dhar)[2] = (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_DHAR(sn),2)) >> 8); \ - (dhar)[3] = (uint8_t) WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_DHAR(sn),2)); \ - (dhar)[4] = (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_DHAR(sn),4)) >> 8); \ - (dhar)[5] = (uint8_t) WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_DHAR(sn),4)); \ - } - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Set @ref Sn_DPORT register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @param (uint16_t)dport Value to set @ref Sn_DPORT - * @sa getSn_DPORT() - */ -#define setSn_DPORTR(sn, dport) \ - WIZCHIP_WRITE(Sn_DPORTR(sn),dport) -#define setSn_DPORT(sn, dport) setSn_DPORTR(sn,dport) ///< For compatible ioLibrary. Refer to @ref Sn_DPORTR. - - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Get @ref Sn_DPORT register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @return uint16_t. Value of @ref Sn_DPORT. - * @sa setSn_DPORT() - * @note This function is not available because W5300 have a bug to read @ref Sn_DPORTR. \n - * Don't use this function. - */ -#define getSn_DPORTR(sn) \ - WIZCHIP_READ(Sn_DPORTR(sn)) -#define getSn_DPORT(sn) getSn_DPORTR(sn) ///< For compatible ioLibrary. Refer to @ref Sn_DPORTR. - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Set @ref Sn_DIPR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @param (uint8_t*)dipr Pointer variable to set socket n destination IP address. It should be allocated 4 bytes. - * @sa getSn_DIPR() - */ -#define setSn_DIPR(sn, dipr) { \ - WIZCHIP_WRITE(Sn_DIPR(sn), (((uint16_t)((dipr)[0])) << 8) + (((uint16_t)((dipr)[1])) & 0x00FF)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_DIPR(sn),2), (((uint16_t)((dipr)[2])) << 8) + (((uint16_t)((dipr)[3])) & 0x00FF)); \ - } - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Get @ref Sn_DIPR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @param (uint8_t*)dipr Pointer variable to get socket n destination IP address. It should be allocated 4 bytes. - * @sa setSn_DIPR() - */ -#define getSn_DIPR(sn, dipr) { \ - (dipr)[0] = (uint8_t)(WIZCHIP_READ(Sn_DIPR(sn)) >> 8); \ - (dipr)[1] = (uint8_t) WIZCHIP_READ(Sn_DIPR(sn)); \ - (dipr)[2] = (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_DIPR(sn),2)) >> 8); \ - (dipr)[3] = (uint8_t) WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_DIPR(sn),2)); \ - } - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Set @ref Sn_MSSR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @param (uint16_t)mss Value to set @ref Sn_MSSR - * @sa setSn_MSSR() - */ -#define setSn_MSSR(sn, mss) \ - WIZCHIP_WRITE(Sn_MSSR(sn), mss) - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Get @ref Sn_MSSR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @return uint16_t. Value of @ref Sn_MSSR. - * @sa setSn_MSSR() - */ -#define getSn_MSSR(sn) \ - WIZCHIP_READ(Sn_MSSR(sn)) - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Set @ref Sn_KPALVTR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @param (uint8_t)kpalvt Value to set @ref Sn_KPALVTR - * @sa getSn_KPALVTR() - */ -#define setSn_KPALVTR(sn, kpalvt) \ - WIZCHIP_WRITE(Sn_KPALVTR(sn), (WIZCHIP_READ(Sn_KPALVTR(sn)) & 0x00FF) | (((uint16_t)kpalvt)<<8)) - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Get @ref Sn_KPALVTR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @return uint8_t. Value of @ref Sn_KPALVTR. - * @sa setSn_KPALVTR() - */ -#define getSn_KPALVTR(sn) \ - ((uint8_t)(WIZCHIP_READ(Sn_KPALVTR(sn)) >> 8)) - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Set @ref Sn_PROTOR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t)proto Value to set \ref Sn_PROTOR - * @sa getSn_PROTOR() - */ -#define setSn_PROTOR(sn, proto) \ - 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 - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Get @ref Sn_PROTOR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @return uint8_t. Value of @ref Sn_PROTOR. - * @sa setSn_PROTOR() - */ -#define getSn_PROTOR(sn) \ - ((uint8_t)WIZCHIP_READ(Sn_PROTOR(sn))) -#define getSn_PROTO(sn) getSn_PROTOR(sn) ///< For compatible ioLibrary - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Set @ref Sn_TX_WRSR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @param (uint32_t)txwrs Value to set @ref Sn_KPALVTR (It should be <= 0x00010000) - * @sa getSn_TX_WRSR() - */ -#define setSn_TX_WRSR(sn, txwrs) { \ - WIZCHIP_WRITE(Sn_TX_WRSR(sn), (uint16_t)(((uint32_t)txwrs) >> 16)); \ - WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_TX_WRSR(sn),2), (uint16_t)txwrs); \ - } - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Get @ref Sn_TX_WRSR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @return uint32_t. Value of Sn_TX_WRSR. - * @sa setSn_TX_WRSR() - */ -#define getSn_TX_WRSR(sn) \ - ( (((uint32_t)WIZCHIP_READ(Sn_TX_WRSR(sn))) << 16) + (((uint32_t)WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_WRSR(sn),1))) & 0x0000FFFF) ) - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Get @ref Sn_TX_FSR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @return uint32_t. Value of @ref Sn_TX_FSR. - */ -uint32_t getSn_TX_FSR(uint8_t sn); - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Get @ref Sn_RX_RSR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @return uint32_t. Value of @ref Sn_RX_RSR. - */ -uint32_t getSn_RX_RSR(uint8_t sn); - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Set @ref Sn_TX_FIFOR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @param (uint16_t)txfifo. Value to set @ref Sn_TX_FIFOR. - */ -#define setSn_TX_FIFOR(sn, txfifo) \ - WIZCHIP_WRITE(Sn_TX_FIFOR(sn), txfifo); - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Get @ref Sn_RX_FIFOR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @return uint16_t. Value of @ref Sn_RX_FIFOR. - */ -#define getSn_RX_FIFOR(sn) \ - WIZCHIP_READ(Sn_RX_FIFOR(sn)); - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Set @ref Sn_TOSR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. - * @param (uint8_t)tos Value to set @ref Sn_TOSR - * @sa getSn_TOSR() - */ -#define setSn_TOSR(sn, tos) \ - WIZCHIP_WRITE(Sn_TOS(sn), ((uint16_t)tos) & 0x00FF) -#define setSn_TOS(sn,tos) setSn_TOSR(sn,tos) ///< For compatible ioLibrar - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Get @ref Sn_TOSR register - * @param (uint8_t)sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_ . - * @return uint8_t. Value of Sn_TOSR. - * @sa setSn_TOSR() - */ -#define getSn_TOSR(sn) \ - ((uint8_t)WIZCHIP_READ(Sn_TOSR(sn))) -#define getSn_TOS(sn) getSn_TOSR(sn) ///< For compatible ioLibrar - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Set @ref Sn_TTLR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @param (uint8_t)ttl Value to set @ref Sn_TTLR - * @sa getSn_TTLR() - */ -#define setSn_TTLR(sn, ttl) \ - WIZCHIP_WRITE(Sn_TTLR(sn), ((uint16_t)ttl) & 0x00FF) -#define setSn_TTL(sn,ttl) setSn_TTLR(sn,ttl) ///< For compatible ioLibrary - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Get @ref Sn_TTLR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @return uint8_t. Value of @ref Sn_TTLR. - * @sa setSn_TTLR() - */ -#define getSn_TTLR(sn) \ - ((uint8_t)WIZCHIP_READ(Sn_TTL(sn))) -#define getSn_TTL(sn) getSn_TTLR(sn) ///< For compatible ioLibrary - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Set @ref Sn_FRAGR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @param (uint16_t)frag Value to set @ref Sn_FRAGR - * @sa getSn_FRAGR() - */ -#define setSn_FRAGR(sn, frag) \ - WIZCHIP_WRITE(Sn_FRAGR(sn), ((uint16_t)frag) & 0x00FF) -#define setSn_FRAG(sn,frag) setSn_FRAGR(sn,flag) - -/** - * @ingroup Socket_register_access_function_W5300 - * @brief Get @ref Sn_FRAGR register - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @return uint16_t. Value of @ref Sn_FRAGR. - * @sa setSn_FRAGR() - */ -#define getSn_FRAGR(sn) \ - (WIZCHIP_READ(Sn_FRAG(sn))) -#define getSn_FRAG(sn) getSn_FRAGR(sn) - - -///////////////////////////////////// -// Sn_TXBUF & Sn_RXBUF IO function // -///////////////////////////////////// - -/** - * @brief Socket_register_access_function_W5300 - * @brief Gets the max buffer size of socket sn passed as parameter. - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @return uint32_t. Value of Socket n RX max buffer size. - */ -#define getSn_RxMAX(sn) \ - (((uint32_t)getSn_RXBUF_SIZE(sn)) << 10) - -/** - * @brief Socket_register_access_function_W5300 - * @brief Gets the max buffer size of socket sn passed as parameters. - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @return uint32_t. Value of Socket n TX max buffer size. - */ -#define getSn_TxMAX(sn) \ - (((uint32_t)getSn_TXBUF_SIZE(sn)) << 10) - -/** - * @ingroup Basic_IO_function_W5300 - * @brief It copies data to internal TX memory - * - * @details This function reads the Tx write pointer register and after that, - * it copies the wizdata(pointer buffer) of the length of len(variable) bytes to internal TX memory - * and updates the Tx write pointer register. - * This function is being called by send() and sendto() function also. - * - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @param wizdata Pointer buffer to write data - * @param len Data length - * @sa wiz_recv_data() - */ -void wiz_send_data(uint8_t sn, uint8_t *wizdata, uint32_t len); - -/** - * @ingroup Basic_IO_function_W5300 - * @brief It copies data to your buffer from internal RX memory - * - * @details This function read the Rx read pointer register and after that, - * it copies the received data from internal RX memory - * to wizdata(pointer variable) of the length of len(variable) bytes. - * This function is being called by recv() also. - * - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @param wizdata Pointer buffer to read data - * @param len Data length - * @sa wiz_send_data() - */ -void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint32_t len); - -/** - * @ingroup Basic_IO_function_W5300 - * @brief It discard the received data in RX memory. - * @details It discards the data of the length of len(variable) bytes in internal RX memory. - * @param (uint8_t)sn Socket number. It should be 0 ~ 7. - * @param len Data length - */ -void wiz_recv_ignore(uint8_t sn, uint32_t len); - -/// \cond DOXY_APPLY_CODE -#endif -/// \endcond - -#ifdef __cplusplus -} -#endif - -#endif // _W5300_H_ diff --git a/platformio.ini b/platformio.ini index f144bd0..37eaa96 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,8 +9,13 @@ ; https://docs.platformio.org/page/projectconf.html [env:genericCH32V203C8T6] -platform = ch32v +platform = https://git.hye.su/mira/platform-ch32v.git + +platform_packages = + toolchain-riscv @ https://git.hye.su/mira/toolchain-riscv-linux.git ; gcc 14.2.0 + framework-ch32v003fun @ https://github.com/cnlohr/ch32v003fun.git ; upstream cnlohr repo board = genericCH32V203C8T6 framework = ch32v003fun upload_protocol = wlink # isp, minichlink, wch-link, wlink - +build_unflags = -march=rv32imacxw +build_flags = -march=rv32imac diff --git a/src/main.c b/src/main.c index 714b672..d8c2dd9 100644 --- a/src/main.c +++ b/src/main.c @@ -179,10 +179,11 @@ int main(void) { int8_t res; uint8_t retries = 0; - while (retries < 10) { + while (retries < 2) { Delay_Ms(250); printf("Resolving domain name \"%s\"...\r\n", domain_name); + res = DNS_run(dns, (uint8_t *)domain_name, addr); if (res == 1) {