commit 441b6563d6f6ceec5a7e151e627a1c86b16fa08b Author: Zakhar Panteleev Date: Wed Dec 10 17:55:05 2025 +0300 up diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..412eeda --- /dev/null +++ b/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a505ec0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,1940 @@ +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# ========================= +# Operating System Files +# ========================= + +# OSX +# ========================= + +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear on external disk +.Spotlight-V100 +.Trashes + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk +man/man3/wizchip_conf.h.3 +man/man3/wizchip_conf.c.3 +man/man3/wiz_PhyConf_t.3 +man/man3/wiz_NetTimeout_t.3 +man/man3/wiz_NetInfo_t.3 +man/man3/w5500.jpg.3 +man/man3/w5500.h.3 +man/man3/w5500.c.3 +man/man3/w5300.h.3 +man/man3/w5300.c.3 +man/man3/w5200_w5500.jpg.3 +man/man3/w5200.h.3 +man/man3/ftpc.h.3 +man/man3/ftpc.c.3 +man/man3/ftpc.3 +man/man3/extra_functions.3 +man/man3/doxygen_log.txt.3 +man/man3/dns.h.3 +man/man3/dns.c.3 +man/man3/dhdr.3 +man/man3/dhcp.h.3 +man/man3/dhcp.c.3 +man/man3/dataEntryType.3 +man/man3/_un_l2cval.3 +man/man3/_st_http_socket.3 +man/man3/_st_http_request.3 +man/man3/_ntpformat.3 +man/man3/_httpServer_webContent.3 +man/man3/W5100.3 +man/man3/Timer.3 +man/man3/StackTrace.h.3 +man/man3/Special_function_W5100S.3 +man/man3/Socket_register_group_W5300.3 +man/man3/Socket_register_group_W5200.3 +man/man3/Socket_register_group_W5100S.3 +man/man3/Socket_register_group_W5100.3 +man/man3/Socket_register_group.3 +man/man3/Socket_register_access_function_W5300.3 +man/man3/Socket_register_access_function_W5200.3 +man/man3/Socket_register_access_function_W5100S.3 +man/man3/Socket_register_access_function_W5100.3 +man/man3/Socket_register_access_function.3 +man/man3/Readme.txt.3 +man/man3/RIP_MSG.3 +man/man3/README.md.3 +man/man3/Network.3 +man/man3/MessageData.3 +man/man3/Main_page.txt.3 +man/man3/MQTTUnsubscribeServer.c.3 +man/man3/MQTTUnsubscribeClient.c.3 +man/man3/MQTTUnsubscribe.h.3 +man/man3/MQTTTransport.3 +man/man3/MQTTSubscribeServer.c.3 +man/man3/MQTTSubscribeClient.c.3 +man/man3/MQTTSubscribe.h.3 +man/man3/MQTTString.3 +man/man3/MQTTSerializePublish.c.3 +man/man3/MQTTPublish.h.3 +man/man3/MQTTPacket_willOptions.3 +man/man3/MQTTPacket_connectData.3 +man/man3/MQTTPacket.h.3 +man/man3/MQTTPacket.c.3 +man/man3/MQTTMessage.3 +man/man3/MQTTLenString.3 +man/man3/MQTTHeader.3 +man/man3/MQTTFormat.h.3 +man/man3/MQTTFormat.c.3 +man/man3/MQTTDeserializePublish.c.3 +man/man3/MQTTConnectServer.c.3 +man/man3/MQTTConnectFlags.3 +man/man3/MQTTConnectClient.c.3 +man/man3/MQTTConnect.h.3 +man/man3/MQTTConnackFlags.3 +man/man3/MQTTClient_MessageHandlers.3 +man/man3/MQTTClient.h.3 +man/man3/MQTTClient.c.3 +man/man3/MQTTClient.3 +man/man3/D__workspace_CoIDE WorkSpace_ioLibrary_Driver_img_.3 +man/man3/D__workspace_CoIDE WorkSpace_ioLibrary_Driver_image_.3 +man/man3/D__workspace_CoIDE WorkSpace_ioLibrary_Driver_Internet_httpServer_.3 +man/man3/D__workspace_CoIDE WorkSpace_ioLibrary_Driver_Internet_TFTP_.3 +man/man3/D__workspace_CoIDE WorkSpace_ioLibrary_Driver_Internet_SNTP_.3 +man/man3/D__workspace_CoIDE WorkSpace_ioLibrary_Driver_Internet_SNMP_.3 +man/man3/D__workspace_CoIDE WorkSpace_ioLibrary_Driver_Internet_MQTT_MQTTPacket_src_.3 +man/man3/D__workspace_CoIDE WorkSpace_ioLibrary_Driver_Internet_MQTT_MQTTPacket_.3 +man/man3/D__workspace_CoIDE WorkSpace_ioLibrary_Driver_Internet_MQTT_.3 +man/man3/D__workspace_CoIDE WorkSpace_ioLibrary_Driver_Internet_FTPServer_.3 +man/man3/D__workspace_CoIDE WorkSpace_ioLibrary_Driver_Internet_FTPClient_.3 +man/man3/D__workspace_CoIDE WorkSpace_ioLibrary_Driver_Internet_DNS_.3 +man/man3/D__workspace_CoIDE WorkSpace_ioLibrary_Driver_Internet_DHCP_.3 +man/man3/D__workspace_CoIDE WorkSpace_ioLibrary_Driver_Internet_.3 +man/man3/D__workspace_CoIDE WorkSpace_ioLibrary_Driver_Ethernet_W5500_.3 +man/man3/D__workspace_CoIDE WorkSpace_ioLibrary_Driver_Ethernet_W5300_.3 +man/man3/D__workspace_CoIDE WorkSpace_ioLibrary_Driver_Ethernet_W5200_.3 +man/man3/D__workspace_CoIDE WorkSpace_ioLibrary_Driver_Ethernet_W5100_.3 +man/man3/D__workspace_CoIDE WorkSpace_ioLibrary_Driver_Ethernet_W5100S_.3 +man/man3/D__workspace_CoIDE WorkSpace_ioLibrary_Driver_Ethernet_.3 +man/man3/D__workspace_CoIDE WorkSpace_ioLibrary_Driver_Application_loopback_.3 +man/man3/D__workspace_CoIDE WorkSpace_ioLibrary_Driver_Application_.3 +man/man3/DATA_TYPE.3 +man/man3/Common_register_group_W5300.3 +man/man3/Common_register_group_W5200.3 +man/man3/Common_register_group_W5100S.3 +man/man3/Common_register_group_W5100.3 +man/man3/Common_register_group.3 +man/man3/Common_register_access_function_W5300.3 +man/man3/Common_register_access_function_W5200.3 +man/man3/Common_register_access_function_W5100S.3 +man/man3/Common_register_access_function_W5100.3 +man/man3/Common_register_access_function.3 +man/man3/Command.3 +man/man3/Berkeley_SOCKET.jpg.3 +man/man3/Basic_IO_function_W5300.3 +man/man3/Basic_IO_function_W5200.3 +man/man3/Basic_IO_function_W5100S.3 +man/man3/Basic_IO_function_W5100.3 +man/man3/Basic_IO_function.3 +latex/wizchip__conf_8h__incl.pdf +latex/wizchip__conf_8h__incl.md5 +latex/wizchip__conf_8h__dep__incl.pdf +latex/wizchip__conf_8h__dep__incl.md5 +latex/wizchip__conf_8h.tex +latex/wizchip__conf_8c__incl.pdf +latex/wizchip__conf_8c__incl.md5 +latex/wizchip__conf_8c.tex +latex/w5500_8jpg.tex +latex/w5500_8h__incl.pdf +latex/w5500_8h__incl.md5 +latex/w5500_8h__dep__incl.pdf +latex/w5500_8h__dep__incl.md5 +latex/w5500_8h.tex +latex/w5500_8c__incl.pdf +latex/w5500_8c__incl.md5 +latex/w5500_8c.tex +latex/w5300_8h__incl.pdf +latex/w5300_8h__incl.md5 +latex/w5300_8h.tex +latex/w5300_8c__incl.pdf +latex/w5300_8c__incl.md5 +latex/w5300_8c.tex +latex/w5200__w5500_8jpg.tex +latex/w5200_8h__incl.pdf +latex/w5200_8h__incl.md5 +latex/w5200_8h__dep__incl.pdf +latex/w5200_8h__dep__incl.md5 +latex/w5200_8h.tex +latex/w5200_8c__incl.pdf +latex/w5200_8c__incl.md5 +latex/w5200_8c.tex +latex/w5100s_8h__incl.pdf +latex/w5100s_8h__incl.md5 +latex/w5100s_8h__dep__incl.pdf +latex/w5100s_8h__dep__incl.md5 +latex/w5100s_8h.tex +latex/w5100s_8c__incl.pdf +latex/w5100s_8c__incl.md5 +latex/w5100s_8c.tex +latex/w5100_8h__incl.pdf +latex/w5100_8h__incl.md5 +latex/w5100_8h__dep__incl.pdf +latex/w5100_8h__dep__incl.md5 +latex/w5100_8h.tex +latex/w5100_8c__incl.pdf +latex/w5100_8c__incl.md5 +latex/w5100_8c.tex +latex/union_m_q_t_t_header.tex +latex/union_m_q_t_t_connect_flags.tex +latex/union_m_q_t_t_connack_flags.tex +latex/union__un__l2cval.tex +latex/union_____w_i_z_c_h_i_p_1_1___i_f.tex +latex/todo.tex +latex/tftp_8h__incl.pdf +latex/tftp_8h__incl.md5 +latex/tftp_8h__dep__incl.pdf +latex/tftp_8h__dep__incl.md5 +latex/tftp_8h.tex +latex/tftp_8c__incl.pdf +latex/tftp_8c__incl.md5 +latex/tftp_8c.tex +latex/structwiz___phy_conf__t.tex +latex/structwiz___net_timeout__t.tex +latex/structwiz___net_info__t.tex +latex/structtlv_struct_type.tex +latex/structtftp__option.tex +latex/structtftp__error.tex +latex/structtftp__data.tex +latex/structmessage_struct.tex +latex/structftpd.tex +latex/structftpc.tex +latex/structdhdr.tex +latex/structdata_entry_type.tex +latex/struct_timer.tex +latex/struct_r_i_p___m_s_g.tex +latex/struct_network.tex +latex/struct_message_data__coll__graph.pdf +latex/struct_message_data__coll__graph.md5 +latex/struct_message_data.tex +latex/struct_m_q_t_t_transport.tex +latex/struct_m_q_t_t_string__coll__graph.pdf +latex/struct_m_q_t_t_string__coll__graph.md5 +latex/struct_m_q_t_t_string.tex +latex/struct_m_q_t_t_packet__will_options__coll__graph.pdf +latex/struct_m_q_t_t_packet__will_options__coll__graph.md5 +latex/struct_m_q_t_t_packet__will_options.tex +latex/struct_m_q_t_t_packet__connect_data__coll__graph.pdf +latex/struct_m_q_t_t_packet__connect_data__coll__graph.md5 +latex/struct_m_q_t_t_packet__connect_data.tex +latex/struct_m_q_t_t_message.tex +latex/struct_m_q_t_t_len_string.tex +latex/struct_m_q_t_t_client__coll__graph.pdf +latex/struct_m_q_t_t_client__coll__graph.md5 +latex/struct_m_q_t_t_client_1_1_message_handlers.tex +latex/struct_m_q_t_t_client.tex +latex/struct_command.tex +latex/struct__st__http__socket.tex +latex/struct__st__http__request.tex +latex/struct__ntpformat.tex +latex/struct__http_server__web_content.tex +latex/struct__datetime.tex +latex/struct____file.tex +latex/struct_____w_i_z_c_h_i_p__coll__graph.pdf +latex/struct_____w_i_z_c_h_i_p__coll__graph.md5 +latex/struct_____w_i_z_c_h_i_p_1_1___c_s.tex +latex/struct_____w_i_z_c_h_i_p_1_1___c_r_i_s.tex +latex/struct_____w_i_z_c_h_i_p.tex +latex/socket_8h__incl.pdf +latex/socket_8h__incl.md5 +latex/socket_8h__dep__incl.pdf +latex/socket_8h__dep__incl.md5 +latex/socket_8h.tex +latex/socket_8c__incl.pdf +latex/socket_8c__incl.md5 +latex/socket_8c.tex +latex/sntp_8h__incl.pdf +latex/sntp_8h__incl.md5 +latex/sntp_8h__dep__incl.pdf +latex/sntp_8h__dep__incl.md5 +latex/sntp_8h.tex +latex/sntp_8c__incl.pdf +latex/sntp_8c__incl.md5 +latex/sntp_8c.tex +latex/snmp__custom_8h__incl.pdf +latex/snmp__custom_8h__incl.md5 +latex/snmp__custom_8h__dep__incl.pdf +latex/snmp__custom_8h__dep__incl.md5 +latex/snmp__custom_8h.tex +latex/snmp__custom_8c__incl.pdf +latex/snmp__custom_8c__incl.md5 +latex/snmp__custom_8c.tex +latex/snmp_8h__dep__incl.pdf +latex/snmp_8h__dep__incl.md5 +latex/snmp_8h.tex +latex/snmp_8c__incl.pdf +latex/snmp_8c__incl.md5 +latex/snmp_8c.tex +latex/refman.tex +latex/netutil_8h__incl.pdf +latex/netutil_8h__incl.md5 +latex/netutil_8h__dep__incl.pdf +latex/netutil_8h__dep__incl.md5 +latex/netutil_8h.tex +latex/netutil_8c__incl.pdf +latex/netutil_8c__incl.md5 +latex/netutil_8c.tex +latex/mqtt__interface_8h__dep__incl.pdf +latex/mqtt__interface_8h__dep__incl.md5 +latex/mqtt__interface_8h.tex +latex/mqtt__interface_8c__incl.pdf +latex/mqtt__interface_8c__incl.md5 +latex/mqtt__interface_8c.tex +latex/modules.tex +latex/md__r_e_a_d_m_e.tex +latex/make.bat +latex/loopback_8h__incl.pdf +latex/loopback_8h__incl.md5 +latex/loopback_8h__dep__incl.pdf +latex/loopback_8h__dep__incl.md5 +latex/loopback_8h.tex +latex/loopback_8c__incl.pdf +latex/loopback_8c__incl.md5 +latex/loopback_8c.tex.tmp +latex/loopback_8c.tex +latex/license_8txt.tex +latex/index.tex +latex/http_util_8h__incl.pdf +latex/http_util_8h__incl.md5 +latex/http_util_8h__dep__incl.pdf +latex/http_util_8h__dep__incl.md5 +latex/http_util_8h.tex +latex/http_util_8c__incl.pdf +latex/http_util_8c__incl.md5 +latex/http_util_8c.tex +latex/http_server_8h__incl.pdf +latex/http_server_8h__incl.md5 +latex/http_server_8h__dep__incl.pdf +latex/http_server_8h__dep__incl.md5 +latex/http_server_8h.tex +latex/http_server_8c__incl.pdf +latex/http_server_8c__incl.md5 +latex/http_server_8c.tex +latex/http_parser_8h__incl.pdf +latex/http_parser_8h__incl.md5 +latex/http_parser_8h__dep__incl.pdf +latex/http_parser_8h__dep__incl.md5 +latex/http_parser_8h.tex +latex/http_parser_8c__incl.pdf +latex/http_parser_8c__incl.md5 +latex/http_parser_8c.tex +latex/group__snmp__module.tex +latex/group__extra__functions.tex +latex/group___w_i_znet__socket___a_p_is.tex +latex/group___w_i_z_c_h_i_p__register___w5300.tex +latex/group___w_i_z_c_h_i_p__register___w5300.pdf +latex/group___w_i_z_c_h_i_p__register___w5300.md5 +latex/group___w_i_z_c_h_i_p__register___w5200.tex +latex/group___w_i_z_c_h_i_p__register___w5200.pdf +latex/group___w_i_z_c_h_i_p__register___w5200.md5 +latex/group___w_i_z_c_h_i_p__register___w5100_s.tex +latex/group___w_i_z_c_h_i_p__register___w5100_s.pdf +latex/group___w_i_z_c_h_i_p__register___w5100_s.md5 +latex/group___w_i_z_c_h_i_p__register___w5100.tex +latex/group___w_i_z_c_h_i_p__register___w5100.pdf +latex/group___w_i_z_c_h_i_p__register___w5100.md5 +latex/group___w_i_z_c_h_i_p__register.tex +latex/group___w_i_z_c_h_i_p__register.pdf +latex/group___w_i_z_c_h_i_p__register.md5 +latex/group___w_i_z_c_h_i_p___i_o___functions___w5300.tex +latex/group___w_i_z_c_h_i_p___i_o___functions___w5300.pdf +latex/group___w_i_z_c_h_i_p___i_o___functions___w5300.md5 +latex/group___w_i_z_c_h_i_p___i_o___functions___w5200.tex +latex/group___w_i_z_c_h_i_p___i_o___functions___w5200.pdf +latex/group___w_i_z_c_h_i_p___i_o___functions___w5200.md5 +latex/group___w_i_z_c_h_i_p___i_o___functions___w5100_s.tex +latex/group___w_i_z_c_h_i_p___i_o___functions___w5100_s.pdf +latex/group___w_i_z_c_h_i_p___i_o___functions___w5100_s.md5 +latex/group___w_i_z_c_h_i_p___i_o___functions___w5100.tex +latex/group___w_i_z_c_h_i_p___i_o___functions___w5100.pdf +latex/group___w_i_z_c_h_i_p___i_o___functions___w5100.md5 +latex/group___w_i_z_c_h_i_p___i_o___functions.tex +latex/group___w_i_z_c_h_i_p___i_o___functions.pdf +latex/group___w_i_z_c_h_i_p___i_o___functions.md5 +latex/group___w5500.tex +latex/group___w5500.pdf +latex/group___w5500.md5 +latex/group___w5300.tex +latex/group___w5300.pdf +latex/group___w5300.md5 +latex/group___w5200.tex +latex/group___w5200.pdf +latex/group___w5200.md5 +latex/group___w5100_s.tex +latex/group___w5100_s.pdf +latex/group___w5100_s.md5 +latex/group___w5100.tex +latex/group___w5100.pdf +latex/group___w5100.md5 +latex/group___special__function___w5100_s.tex +latex/group___special__function___w5100_s.pdf +latex/group___special__function___w5100_s.md5 +latex/group___socket__register__group___w5300.tex +latex/group___socket__register__group___w5300.pdf +latex/group___socket__register__group___w5300.md5 +latex/group___socket__register__group___w5200.tex +latex/group___socket__register__group___w5200.pdf +latex/group___socket__register__group___w5200.md5 +latex/group___socket__register__group___w5100_s.tex +latex/group___socket__register__group___w5100_s.pdf +latex/group___socket__register__group___w5100_s.md5 +latex/group___socket__register__group___w5100.tex +latex/group___socket__register__group___w5100.pdf +latex/group___socket__register__group___w5100.md5 +latex/group___socket__register__group.tex +latex/group___socket__register__group.pdf +latex/group___socket__register__group.md5 +latex/group___socket__register__access__function___w5300.tex +latex/group___socket__register__access__function___w5300.pdf +latex/group___socket__register__access__function___w5300.md5 +latex/group___socket__register__access__function___w5200.tex +latex/group___socket__register__access__function___w5200.pdf +latex/group___socket__register__access__function___w5200.md5 +latex/group___socket__register__access__function___w5100_s.tex +latex/group___socket__register__access__function___w5100_s.pdf +latex/group___socket__register__access__function___w5100_s.md5 +latex/group___socket__register__access__function___w5100.tex +latex/group___socket__register__access__function___w5100.pdf +latex/group___socket__register__access__function___w5100.md5 +latex/group___socket__register__access__function.tex +latex/group___socket__register__access__function.pdf +latex/group___socket__register__access__function.md5 +latex/group___d_a_t_a___t_y_p_e.tex +latex/group___common__register__group___w5300.tex +latex/group___common__register__group___w5300.pdf +latex/group___common__register__group___w5300.md5 +latex/group___common__register__group___w5200.tex +latex/group___common__register__group___w5200.pdf +latex/group___common__register__group___w5200.md5 +latex/group___common__register__group___w5100_s.tex +latex/group___common__register__group___w5100_s.pdf +latex/group___common__register__group___w5100_s.md5 +latex/group___common__register__group___w5100.tex +latex/group___common__register__group___w5100.pdf +latex/group___common__register__group___w5100.md5 +latex/group___common__register__group.tex +latex/group___common__register__group.pdf +latex/group___common__register__group.md5 +latex/group___common__register__access__function___w5300.tex +latex/group___common__register__access__function___w5300.pdf +latex/group___common__register__access__function___w5300.md5 +latex/group___common__register__access__function___w5200.tex +latex/group___common__register__access__function___w5200.pdf +latex/group___common__register__access__function___w5200.md5 +latex/group___common__register__access__function___w5100_s.tex +latex/group___common__register__access__function___w5100_s.pdf +latex/group___common__register__access__function___w5100_s.md5 +latex/group___common__register__access__function___w5100.tex +latex/group___common__register__access__function___w5100.pdf +latex/group___common__register__access__function___w5100.md5 +latex/group___common__register__access__function.tex +latex/group___common__register__access__function.pdf +latex/group___common__register__access__function.md5 +latex/group___basic___i_o__function___w5300.tex +latex/group___basic___i_o__function___w5300.pdf +latex/group___basic___i_o__function___w5300.md5 +latex/group___basic___i_o__function___w5200.tex +latex/group___basic___i_o__function___w5200.pdf +latex/group___basic___i_o__function___w5200.md5 +latex/group___basic___i_o__function___w5100_s.tex +latex/group___basic___i_o__function___w5100_s.pdf +latex/group___basic___i_o__function___w5100_s.md5 +latex/group___basic___i_o__function___w5100.tex +latex/group___basic___i_o__function___w5100.pdf +latex/group___basic___i_o__function___w5100.md5 +latex/group___basic___i_o__function.tex +latex/group___basic___i_o__function.pdf +latex/group___basic___i_o__function.md5 +latex/ftpd_8h__incl.pdf +latex/ftpd_8h__incl.md5 +latex/ftpd_8h__dep__incl.pdf +latex/ftpd_8h__dep__incl.md5 +latex/ftpd_8h.tex +latex/ftpd_8c__incl.pdf +latex/ftpd_8c__incl.md5 +latex/ftpd_8c.tex +latex/ftpc_8h__incl.pdf +latex/ftpc_8h__incl.md5 +latex/ftpc_8h__dep__incl.pdf +latex/ftpc_8h__dep__incl.md5 +latex/ftpc_8h.tex +latex/ftpc_8c__incl.pdf +latex/ftpc_8c__incl.md5 +latex/ftpc_8c.tex +latex/files.tex +latex/doxygen__log_8txt.tex +latex/doxygen.sty +latex/dns_8h__incl.pdf +latex/dns_8h__incl.md5 +latex/dns_8h__dep__incl.pdf +latex/dns_8h__dep__incl.md5 +latex/dns_8h.tex +latex/dns_8c__incl.pdf +latex/dns_8c__incl.md5 +latex/dns_8c.tex +latex/dir_fe682d1d76c251404f71241aa833642c_dep.pdf +latex/dir_fe682d1d76c251404f71241aa833642c_dep.md5 +latex/dir_fe682d1d76c251404f71241aa833642c.tex +latex/dir_fca0adf6655fb1759a15e5776097c124_dep.pdf +latex/dir_fca0adf6655fb1759a15e5776097c124_dep.md5 +latex/dir_fca0adf6655fb1759a15e5776097c124.tex +latex/dir_f841453af36a2df9a2123f87589fe4f8_dep.pdf +latex/dir_f841453af36a2df9a2123f87589fe4f8_dep.md5 +latex/dir_f841453af36a2df9a2123f87589fe4f8.tex +latex/dir_f10a527ab5b3936e2edf95a019a13ec7_dep.pdf +latex/dir_f10a527ab5b3936e2edf95a019a13ec7_dep.md5 +latex/dir_f10a527ab5b3936e2edf95a019a13ec7.tex +latex/dir_eb1463819d84903762eb6f59cc0c4383_dep.pdf +latex/dir_eb1463819d84903762eb6f59cc0c4383_dep.md5 +latex/dir_eb1463819d84903762eb6f59cc0c4383.tex +latex/dir_e5121bff4754a4ad570fa548a998f0c5_dep.pdf +latex/dir_e5121bff4754a4ad570fa548a998f0c5_dep.md5 +latex/dir_e5121bff4754a4ad570fa548a998f0c5.tex +latex/dir_b88037d6581d528000057b4eaec3e673_dep.pdf +latex/dir_b88037d6581d528000057b4eaec3e673_dep.md5 +latex/dir_b88037d6581d528000057b4eaec3e673.tex +latex/dir_a5a06f90a751e77147778694c516f622_dep.pdf +latex/dir_a5a06f90a751e77147778694c516f622_dep.md5 +latex/dir_a5a06f90a751e77147778694c516f622.tex +latex/dir_a483286db9c12f74c7364bdaa9e78c36_dep.pdf +latex/dir_a483286db9c12f74c7364bdaa9e78c36_dep.md5 +latex/dir_a483286db9c12f74c7364bdaa9e78c36.tex +latex/dir_a138ed074e64356ad02dbb8d94382c4f_dep.pdf +latex/dir_a138ed074e64356ad02dbb8d94382c4f_dep.md5 +latex/dir_a138ed074e64356ad02dbb8d94382c4f.tex +latex/dir_97b8cbb23222306012bd2d84398746c9_dep.pdf +latex/dir_97b8cbb23222306012bd2d84398746c9_dep.md5 +latex/dir_97b8cbb23222306012bd2d84398746c9.tex +latex/dir_6e6e4d5e89221ed61dd87b2954f72a78_dep.pdf +latex/dir_6e6e4d5e89221ed61dd87b2954f72a78_dep.md5 +latex/dir_6e6e4d5e89221ed61dd87b2954f72a78.tex +latex/dir_6de1940466803d61d2f9d1259cb01031.tex +latex/dir_5a912e51f6f9520965e8671f07512599_dep.pdf +latex/dir_5a912e51f6f9520965e8671f07512599_dep.md5 +latex/dir_5a912e51f6f9520965e8671f07512599.tex +latex/dir_4c7002aef9ece892c0aedd728ed93eff.tex +latex/dir_498fbcdef69ea105b96b8673d051b2e3_dep.pdf +latex/dir_498fbcdef69ea105b96b8673d051b2e3_dep.md5 +latex/dir_498fbcdef69ea105b96b8673d051b2e3.tex +latex/dir_46819ec1095f3903911c103f5ebbb29f_dep.pdf +latex/dir_46819ec1095f3903911c103f5ebbb29f_dep.md5 +latex/dir_46819ec1095f3903911c103f5ebbb29f.tex +latex/dir_4396dcc0e095a5bc10b1affe087807cf_dep.pdf +latex/dir_4396dcc0e095a5bc10b1affe087807cf_dep.md5 +latex/dir_4396dcc0e095a5bc10b1affe087807cf.tex +latex/dir_337e147d8ae2958ef29ccaa8e2f968db_dep.pdf +latex/dir_337e147d8ae2958ef29ccaa8e2f968db_dep.md5 +latex/dir_337e147d8ae2958ef29ccaa8e2f968db.tex +latex/dir_2c7bb40a7e5a6685f00216dd2909cd99_dep.pdf +latex/dir_2c7bb40a7e5a6685f00216dd2909cd99_dep.md5 +latex/dir_2c7bb40a7e5a6685f00216dd2909cd99.tex +latex/dir_2c1dd796c287ab9a5cf44281d8a3cbeb.tex +latex/dir_072fcb7a67163ce1d8f22ad4144c7e08.tex +latex/dhcp_8h__dep__incl.pdf +latex/dhcp_8h__dep__incl.md5 +latex/dhcp_8h.tex +latex/dhcp_8c__incl.pdf +latex/dhcp_8c__incl.md5 +latex/dhcp_8c.tex +latex/annotated.tex +latex/_w_i_znet___s_o_c_k_e_t_8jpg.tex +latex/_stack_trace_8h__incl.pdf +latex/_stack_trace_8h__incl.md5 +latex/_stack_trace_8h__dep__incl.pdf +latex/_stack_trace_8h__dep__incl.md5 +latex/_stack_trace_8h.tex +latex/_readme_8txt.tex +latex/_r_e_a_d_m_e_8md.tex +latex/_main__page_8txt.tex +latex/_m_q_t_t_unsubscribe_server_8c__incl.pdf +latex/_m_q_t_t_unsubscribe_server_8c__incl.md5 +latex/_m_q_t_t_unsubscribe_server_8c.tex +latex/_m_q_t_t_unsubscribe_client_8c__incl.pdf +latex/_m_q_t_t_unsubscribe_client_8c__incl.md5 +latex/_m_q_t_t_unsubscribe_client_8c.tex +latex/_m_q_t_t_unsubscribe_8h__dep__incl.pdf +latex/_m_q_t_t_unsubscribe_8h__dep__incl.md5 +latex/_m_q_t_t_unsubscribe_8h.tex +latex/_m_q_t_t_subscribe_server_8c__incl.pdf +latex/_m_q_t_t_subscribe_server_8c__incl.md5 +latex/_m_q_t_t_subscribe_server_8c.tex +latex/_m_q_t_t_subscribe_client_8c__incl.pdf +latex/_m_q_t_t_subscribe_client_8c__incl.md5 +latex/_m_q_t_t_subscribe_client_8c.tex +latex/_m_q_t_t_subscribe_8h__dep__incl.pdf +latex/_m_q_t_t_subscribe_8h__dep__incl.md5 +latex/_m_q_t_t_subscribe_8h.tex +latex/_m_q_t_t_serialize_publish_8c__incl.pdf +latex/_m_q_t_t_serialize_publish_8c__incl.md5 +latex/_m_q_t_t_serialize_publish_8c.tex +latex/_m_q_t_t_publish_8h__dep__incl.pdf +latex/_m_q_t_t_publish_8h__dep__incl.md5 +latex/_m_q_t_t_publish_8h.tex +latex/_m_q_t_t_packet_8h__incl.pdf +latex/_m_q_t_t_packet_8h__incl.md5 +latex/_m_q_t_t_packet_8h__dep__incl.pdf +latex/_m_q_t_t_packet_8h__dep__incl.md5 +latex/_m_q_t_t_packet_8h.tex +latex/_m_q_t_t_packet_8c__incl.pdf +latex/_m_q_t_t_packet_8c__incl.md5 +latex/_m_q_t_t_packet_8c.tex +latex/_m_q_t_t_format_8h__incl.pdf +latex/_m_q_t_t_format_8h__incl.md5 +latex/_m_q_t_t_format_8h__dep__incl.pdf +latex/_m_q_t_t_format_8h__dep__incl.md5 +latex/_m_q_t_t_format_8h.tex +latex/_m_q_t_t_format_8c__incl.pdf +latex/_m_q_t_t_format_8c__incl.md5 +latex/_m_q_t_t_format_8c.tex +latex/_m_q_t_t_deserialize_publish_8c__incl.pdf +latex/_m_q_t_t_deserialize_publish_8c__incl.md5 +latex/_m_q_t_t_deserialize_publish_8c.tex +latex/_m_q_t_t_connect_server_8c__incl.pdf +latex/_m_q_t_t_connect_server_8c__incl.md5 +latex/_m_q_t_t_connect_server_8c.tex +latex/_m_q_t_t_connect_client_8c__incl.pdf +latex/_m_q_t_t_connect_client_8c__incl.md5 +latex/_m_q_t_t_connect_client_8c.tex +latex/_m_q_t_t_connect_8h__dep__incl.pdf +latex/_m_q_t_t_connect_8h__dep__incl.md5 +latex/_m_q_t_t_connect_8h.tex +latex/_m_q_t_t_client_8h__incl.pdf +latex/_m_q_t_t_client_8h__incl.md5 +latex/_m_q_t_t_client_8h__dep__incl.pdf +latex/_m_q_t_t_client_8h__dep__incl.md5 +latex/_m_q_t_t_client_8h.tex +latex/_m_q_t_t_client_8c__incl.pdf +latex/_m_q_t_t_client_8c__incl.md5 +latex/_m_q_t_t_client_8c.tex +latex/_f_t_p_server_2stdio__private_8h__incl.pdf +latex/_f_t_p_server_2stdio__private_8h__incl.md5 +latex/_f_t_p_server_2stdio__private_8h__dep__incl.pdf +latex/_f_t_p_server_2stdio__private_8h__dep__incl.md5 +latex/_f_t_p_server_2stdio__private_8h.tex +latex/_f_t_p_client_2stdio__private_8h__incl.pdf +latex/_f_t_p_client_2stdio__private_8h__incl.md5 +latex/_f_t_p_client_2stdio__private_8h__dep__incl.pdf +latex/_f_t_p_client_2stdio__private_8h__dep__incl.md5 +latex/_f_t_p_client_2stdio__private_8h.tex +latex/_berkeley___s_o_c_k_e_t_8jpg.tex +latex/Makefile +image/w5500.jpg +image/w5200_w5500.jpg +image/WIZnet_SOCKET.jpg +image/Berkeley_SOCKET.jpg +html/wizchip__conf_8h_source.html +html/wizchip__conf_8h__incl.png +html/wizchip__conf_8h__incl.md5 +html/wizchip__conf_8h__incl.map +html/wizchip__conf_8h__dep__incl.png +html/wizchip__conf_8h__dep__incl.md5 +html/wizchip__conf_8h__dep__incl.map +html/wizchip__conf_8h.html +html/wizchip__conf_8c_source.html +html/wizchip__conf_8c__incl.png +html/wizchip__conf_8c__incl.md5 +html/wizchip__conf_8c__incl.map +html/wizchip__conf_8c.html +html/w5500_8jpg_source.html +html/w5500_8jpg.html +html/w5500_8h_source.html +html/w5500_8h__incl.png +html/w5500_8h__incl.md5 +html/w5500_8h__incl.map +html/w5500_8h__dep__incl.png +html/w5500_8h__dep__incl.md5 +html/w5500_8h__dep__incl.map +html/w5500_8h.html +html/w5500_8c_source.html +html/w5500_8c__incl.png +html/w5500_8c__incl.md5 +html/w5500_8c__incl.map +html/w5500_8c.html +html/w5300_8h_source.html +html/w5300_8h__incl.png +html/w5300_8h__incl.md5 +html/w5300_8h__incl.map +html/w5300_8h.html +html/w5300_8c_source.html +html/w5300_8c__incl.png +html/w5300_8c__incl.md5 +html/w5300_8c__incl.map +html/w5300_8c.html +html/w5200_w5500.jpg +html/w5200__w5500_8jpg_source.html +html/w5200__w5500_8jpg.html +html/w5200_8h_source.html +html/w5200_8h__incl.png +html/w5200_8h__incl.md5 +html/w5200_8h__incl.map +html/w5200_8h__dep__incl.png +html/w5200_8h__dep__incl.md5 +html/w5200_8h__dep__incl.map +html/w5200_8h.html +html/w5200_8c_source.html +html/w5200_8c__incl.png +html/w5200_8c__incl.md5 +html/w5200_8c__incl.map +html/w5200_8c.html +html/w5100s_8h_source.html +html/w5100s_8h__incl.png +html/w5100s_8h__incl.md5 +html/w5100s_8h__incl.map +html/w5100s_8h__dep__incl.png +html/w5100s_8h__dep__incl.md5 +html/w5100s_8h__dep__incl.map +html/w5100s_8h.html +html/w5100s_8c_source.html +html/w5100s_8c__incl.png +html/w5100s_8c__incl.md5 +html/w5100s_8c__incl.map +html/w5100s_8c.html +html/w5100_8h_source.html +html/w5100_8h__incl.png +html/w5100_8h__incl.md5 +html/w5100_8h__incl.map +html/w5100_8h__dep__incl.png +html/w5100_8h__dep__incl.md5 +html/w5100_8h__dep__incl.map +html/w5100_8h.html +html/w5100_8c_source.html +html/w5100_8c__incl.png +html/w5100_8c__incl.md5 +html/w5100_8c__incl.map +html/w5100_8c.html +html/union_m_q_t_t_header.html +html/union_m_q_t_t_connect_flags.html +html/union_m_q_t_t_connack_flags.html +html/union__un__l2cval.html +html/union_____w_i_z_c_h_i_p_1_1___i_f.html +html/todo.html +html/tftp_8h_source.html +html/tftp_8h__incl.png +html/tftp_8h__incl.md5 +html/tftp_8h__incl.map +html/tftp_8h__dep__incl.png +html/tftp_8h__dep__incl.md5 +html/tftp_8h__dep__incl.map +html/tftp_8h.html +html/tftp_8c_source.html +html/tftp_8c__incl.png +html/tftp_8c__incl.md5 +html/tftp_8c__incl.map +html/tftp_8c.html +html/tabs.css +html/tab_s.png +html/tab_h.png +html/tab_b.png +html/tab_a.png +html/sync_on.png +html/sync_off.png +html/structwiz___phy_conf__t.html +html/structwiz___net_timeout__t.html +html/structwiz___net_info__t.html +html/structtlv_struct_type.html +html/structtftp__option.html +html/structtftp__error.html +html/structtftp__data.html +html/structmessage_struct.html +html/structftpd.html +html/structftpc.html +html/structdhdr.html +html/structdata_entry_type.html +html/struct_timer.html +html/struct_r_i_p___m_s_g.html +html/struct_network.html +html/struct_message_data__coll__graph.png +html/struct_message_data__coll__graph.md5 +html/struct_message_data__coll__graph.map +html/struct_message_data.html +html/struct_m_q_t_t_transport.html +html/struct_m_q_t_t_string__coll__graph.png +html/struct_m_q_t_t_string__coll__graph.md5 +html/struct_m_q_t_t_string__coll__graph.map +html/struct_m_q_t_t_string.html +html/struct_m_q_t_t_packet__will_options__coll__graph.png +html/struct_m_q_t_t_packet__will_options__coll__graph.md5 +html/struct_m_q_t_t_packet__will_options__coll__graph.map +html/struct_m_q_t_t_packet__will_options.html +html/struct_m_q_t_t_packet__connect_data__coll__graph.png +html/struct_m_q_t_t_packet__connect_data__coll__graph.md5 +html/struct_m_q_t_t_packet__connect_data__coll__graph.map +html/struct_m_q_t_t_packet__connect_data.html +html/struct_m_q_t_t_message.html +html/struct_m_q_t_t_len_string.html +html/struct_m_q_t_t_client__coll__graph.png +html/struct_m_q_t_t_client__coll__graph.md5 +html/struct_m_q_t_t_client__coll__graph.map +html/struct_m_q_t_t_client_1_1_message_handlers.html +html/struct_m_q_t_t_client.html +html/struct_command.html +html/struct__st__http__socket.html +html/struct__st__http__request.html +html/struct__ntpformat.html +html/struct__http_server__web_content.html +html/struct__datetime.html +html/struct____file.html +html/struct_____w_i_z_c_h_i_p__coll__graph.png +html/struct_____w_i_z_c_h_i_p__coll__graph.md5 +html/struct_____w_i_z_c_h_i_p__coll__graph.map +html/struct_____w_i_z_c_h_i_p_1_1___c_s.html +html/struct_____w_i_z_c_h_i_p_1_1___c_r_i_s.html +html/struct_____w_i_z_c_h_i_p.html +html/splitbar.png +html/socket_8h_source.html +html/socket_8h__incl.png +html/socket_8h__incl.md5 +html/socket_8h__incl.map +html/socket_8h__dep__incl.png +html/socket_8h__dep__incl.md5 +html/socket_8h__dep__incl.map +html/socket_8h.html +html/socket_8c_source.html +html/socket_8c__incl.png +html/socket_8c__incl.md5 +html/socket_8c__incl.map +html/socket_8c.html +html/sntp_8h_source.html +html/sntp_8h__incl.png +html/sntp_8h__incl.md5 +html/sntp_8h__incl.map +html/sntp_8h__dep__incl.png +html/sntp_8h__dep__incl.md5 +html/sntp_8h__dep__incl.map +html/sntp_8h.html +html/sntp_8c_source.html +html/sntp_8c__incl.png +html/sntp_8c__incl.md5 +html/sntp_8c__incl.map +html/sntp_8c.html +html/snmp__custom_8h_source.html +html/snmp__custom_8h__incl.png +html/snmp__custom_8h__incl.md5 +html/snmp__custom_8h__incl.map +html/snmp__custom_8h__dep__incl.png +html/snmp__custom_8h__dep__incl.md5 +html/snmp__custom_8h__dep__incl.map +html/snmp__custom_8h.html +html/snmp__custom_8c_source.html +html/snmp__custom_8c__incl.png +html/snmp__custom_8c__incl.md5 +html/snmp__custom_8c__incl.map +html/snmp__custom_8c.html +html/snmp_8h_source.html +html/snmp_8h__dep__incl.png +html/snmp_8h__dep__incl.md5 +html/snmp_8h__dep__incl.map +html/snmp_8h.html +html/snmp_8c_source.html +html/snmp_8c__incl.png +html/snmp_8c__incl.md5 +html/snmp_8c__incl.map +html/snmp_8c.html +html/search/variables_f.js +html/search/variables_f.html +html/search/variables_e.js +html/search/variables_e.html +html/search/variables_d.js +html/search/variables_d.html +html/search/variables_c.js +html/search/variables_c.html +html/search/variables_b.js +html/search/variables_b.html +html/search/variables_a.js +html/search/variables_a.html +html/search/variables_9.js +html/search/variables_9.html +html/search/variables_8.js +html/search/variables_8.html +html/search/variables_7.js +html/search/variables_7.html +html/search/variables_6.js +html/search/variables_6.html +html/search/variables_5.js +html/search/variables_5.html +html/search/variables_4.js +html/search/variables_4.html +html/search/variables_3.js +html/search/variables_3.html +html/search/variables_2.js +html/search/variables_2.html +html/search/variables_18.js +html/search/variables_18.html +html/search/variables_17.js +html/search/variables_17.html +html/search/variables_16.js +html/search/variables_16.html +html/search/variables_15.js +html/search/variables_15.html +html/search/variables_14.js +html/search/variables_14.html +html/search/variables_13.js +html/search/variables_13.html +html/search/variables_12.js +html/search/variables_12.html +html/search/variables_11.js +html/search/variables_11.html +html/search/variables_10.js +html/search/variables_10.html +html/search/variables_1.js +html/search/variables_1.html +html/search/variables_0.js +html/search/variables_0.html +html/search/typedefs_9.js +html/search/typedefs_9.html +html/search/typedefs_8.js +html/search/typedefs_8.html +html/search/typedefs_7.js +html/search/typedefs_7.html +html/search/typedefs_6.js +html/search/typedefs_6.html +html/search/typedefs_5.js +html/search/typedefs_5.html +html/search/typedefs_4.js +html/search/typedefs_4.html +html/search/typedefs_3.js +html/search/typedefs_3.html +html/search/typedefs_2.js +html/search/typedefs_2.html +html/search/typedefs_1.js +html/search/typedefs_1.html +html/search/typedefs_0.js +html/search/typedefs_0.html +html/search/searchdata.js +html/search/search_r.png +html/search/search_m.png +html/search/search_l.png +html/search/search.js +html/search/search.css +html/search/pages_2.js +html/search/pages_2.html +html/search/pages_1.js +html/search/pages_1.html +html/search/pages_0.js +html/search/pages_0.html +html/search/nomatches.html +html/search/mag_sel.png +html/search/groups_6.js +html/search/groups_6.html +html/search/groups_5.js +html/search/groups_5.html +html/search/groups_4.js +html/search/groups_4.html +html/search/groups_3.js +html/search/groups_3.html +html/search/groups_2.js +html/search/groups_2.html +html/search/groups_1.js +html/search/groups_1.html +html/search/groups_0.js +html/search/groups_0.html +html/search/functions_f.js +html/search/functions_f.html +html/search/functions_e.js +html/search/functions_e.html +html/search/functions_d.js +html/search/functions_d.html +html/search/functions_c.js +html/search/functions_c.html +html/search/functions_b.js +html/search/functions_b.html +html/search/functions_a.js +html/search/functions_a.html +html/search/functions_9.js +html/search/functions_9.html +html/search/functions_8.js +html/search/functions_8.html +html/search/functions_7.js +html/search/functions_7.html +html/search/functions_6.js +html/search/functions_6.html +html/search/functions_5.js +html/search/functions_5.html +html/search/functions_4.js +html/search/functions_4.html +html/search/functions_3.js +html/search/functions_3.html +html/search/functions_2.js +html/search/functions_2.html +html/search/functions_11.js +html/search/functions_11.html +html/search/functions_10.js +html/search/functions_10.html +html/search/functions_1.js +html/search/functions_1.html +html/search/functions_0.js +html/search/functions_0.html +html/search/files_a.js +html/search/files_a.html +html/search/files_9.js +html/search/files_9.html +html/search/files_8.js +html/search/files_8.html +html/search/files_7.js +html/search/files_7.html +html/search/files_6.js +html/search/files_6.html +html/search/files_5.js +html/search/files_5.html +html/search/files_4.js +html/search/files_4.html +html/search/files_3.js +html/search/files_3.html +html/search/files_2.js +html/search/files_2.html +html/search/files_1.js +html/search/files_1.html +html/search/files_0.js +html/search/files_0.html +html/search/enumvalues_f.js +html/search/enumvalues_f.html +html/search/enumvalues_e.js +html/search/enumvalues_e.html +html/search/enumvalues_d.js +html/search/enumvalues_d.html +html/search/enumvalues_c.js +html/search/enumvalues_c.html +html/search/enumvalues_b.js +html/search/enumvalues_b.html +html/search/enumvalues_a.js +html/search/enumvalues_a.html +html/search/enumvalues_9.js +html/search/enumvalues_9.html +html/search/enumvalues_8.js +html/search/enumvalues_8.html +html/search/enumvalues_7.js +html/search/enumvalues_7.html +html/search/enumvalues_6.js +html/search/enumvalues_6.html +html/search/enumvalues_5.js +html/search/enumvalues_5.html +html/search/enumvalues_4.js +html/search/enumvalues_4.html +html/search/enumvalues_3.js +html/search/enumvalues_3.html +html/search/enumvalues_2.js +html/search/enumvalues_2.html +html/search/enumvalues_12.js +html/search/enumvalues_12.html +html/search/enumvalues_11.js +html/search/enumvalues_11.html +html/search/enumvalues_10.js +html/search/enumvalues_10.html +html/search/enumvalues_1.js +html/search/enumvalues_1.html +html/search/enumvalues_0.js +html/search/enumvalues_0.html +html/search/enums_9.js +html/search/enums_9.html +html/search/enums_8.js +html/search/enums_8.html +html/search/enums_7.js +html/search/enums_7.html +html/search/enums_6.js +html/search/enums_6.html +html/search/enums_5.js +html/search/enums_5.html +html/search/enums_4.js +html/search/enums_4.html +html/search/enums_3.js +html/search/enums_3.html +html/search/enums_2.js +html/search/enums_2.html +html/search/enums_1.js +html/search/enums_1.html +html/search/enums_0.js +html/search/enums_0.html +html/search/defines_f.js +html/search/defines_f.html +html/search/defines_e.js +html/search/defines_e.html +html/search/defines_d.js +html/search/defines_d.html +html/search/defines_c.js +html/search/defines_c.html +html/search/defines_b.js +html/search/defines_b.html +html/search/defines_a.js +html/search/defines_a.html +html/search/defines_9.js +html/search/defines_9.html +html/search/defines_8.js +html/search/defines_8.html +html/search/defines_7.js +html/search/defines_7.html +html/search/defines_6.js +html/search/defines_6.html +html/search/defines_5.js +html/search/defines_5.html +html/search/defines_4.js +html/search/defines_4.html +html/search/defines_3.js +html/search/defines_3.html +html/search/defines_2.js +html/search/defines_2.html +html/search/defines_15.js +html/search/defines_15.html +html/search/defines_14.js +html/search/defines_14.html +html/search/defines_13.js +html/search/defines_13.html +html/search/defines_12.js +html/search/defines_12.html +html/search/defines_11.js +html/search/defines_11.html +html/search/defines_10.js +html/search/defines_10.html +html/search/defines_1.js +html/search/defines_1.html +html/search/defines_0.js +html/search/defines_0.html +html/search/close.png +html/search/classes_8.js +html/search/classes_8.html +html/search/classes_7.js +html/search/classes_7.html +html/search/classes_6.js +html/search/classes_6.html +html/search/classes_5.js +html/search/classes_5.html +html/search/classes_4.js +html/search/classes_4.html +html/search/classes_3.js +html/search/classes_3.html +html/search/classes_2.js +html/search/classes_2.html +html/search/classes_1.js +html/search/classes_1.html +html/search/classes_0.js +html/search/classes_0.html +html/search/all_f.js +html/search/all_f.html +html/search/all_e.js +html/search/all_e.html +html/search/all_d.js +html/search/all_d.html +html/search/all_c.js +html/search/all_c.html +html/search/all_b.js +html/search/all_b.html +html/search/all_a.js +html/search/all_a.html +html/search/all_9.js +html/search/all_9.html +html/search/all_8.js +html/search/all_8.html +html/search/all_7.js +html/search/all_7.html +html/search/all_6.js +html/search/all_6.html +html/search/all_5.js +html/search/all_5.html +html/search/all_4.js +html/search/all_4.html +html/search/all_3.js +html/search/all_3.html +html/search/all_2.js +html/search/all_2.html +html/search/all_1a.js +html/search/all_1a.html +html/search/all_19.js +html/search/all_19.html +html/search/all_18.js +html/search/all_18.html +html/search/all_17.js +html/search/all_17.html +html/search/all_16.js +html/search/all_16.html +html/search/all_15.js +html/search/all_15.html +html/search/all_14.js +html/search/all_14.html +html/search/all_13.js +html/search/all_13.html +html/search/all_12.js +html/search/all_12.html +html/search/all_11.js +html/search/all_11.html +html/search/all_10.js +html/search/all_10.html +html/search/all_1.js +html/search/all_1.html +html/search/all_0.js +html/search/all_0.html +html/pages.html +html/open.png +html/netutil_8h_source.html +html/netutil_8h__incl.png +html/netutil_8h__incl.md5 +html/netutil_8h__incl.map +html/netutil_8h__dep__incl.png +html/netutil_8h__dep__incl.md5 +html/netutil_8h__dep__incl.map +html/netutil_8h.html +html/netutil_8c_source.html +html/netutil_8c__incl.png +html/netutil_8c__incl.md5 +html/netutil_8c__incl.map +html/netutil_8c.html +html/nav_h.png +html/nav_g.png +html/nav_f.png +html/mqtt__interface_8h_source.html +html/mqtt__interface_8h__dep__incl.png +html/mqtt__interface_8h__dep__incl.md5 +html/mqtt__interface_8h__dep__incl.map +html/mqtt__interface_8h.html +html/mqtt__interface_8c_source.html +html/mqtt__interface_8c__incl.png +html/mqtt__interface_8c__incl.md5 +html/mqtt__interface_8c__incl.map +html/mqtt__interface_8c.html +html/modules.html +html/menudata.js +html/menu.js +html/md__r_e_a_d_m_e.html +html/loopback_8h_source.html +html/loopback_8h__incl.png +html/loopback_8h__incl.md5 +html/loopback_8h__incl.map +html/loopback_8h__dep__incl.png +html/loopback_8h__dep__incl.md5 +html/loopback_8h__dep__incl.map +html/loopback_8h.html +html/loopback_8c_source.html +html/loopback_8c__incl.png +html/loopback_8c__incl.md5 +html/loopback_8c__incl.map +html/loopback_8c.html +html/license_8txt.html +html/jquery.js +html/index.html +html/http_util_8h_source.html +html/http_util_8h__incl.png +html/http_util_8h__incl.md5 +html/http_util_8h__incl.map +html/http_util_8h__dep__incl.png +html/http_util_8h__dep__incl.md5 +html/http_util_8h__dep__incl.map +html/http_util_8h.html +html/http_util_8c_source.html +html/http_util_8c__incl.png +html/http_util_8c__incl.md5 +html/http_util_8c__incl.map +html/http_util_8c.html +html/http_server_8h_source.html +html/http_server_8h__incl.png +html/http_server_8h__incl.md5 +html/http_server_8h__incl.map +html/http_server_8h__dep__incl.png +html/http_server_8h__dep__incl.md5 +html/http_server_8h__dep__incl.map +html/http_server_8h.html +html/http_server_8c_source.html +html/http_server_8c__incl.png +html/http_server_8c__incl.md5 +html/http_server_8c__incl.map +html/http_server_8c.html +html/http_parser_8h_source.html +html/http_parser_8h__incl.png +html/http_parser_8h__incl.md5 +html/http_parser_8h__incl.map +html/http_parser_8h__dep__incl.png +html/http_parser_8h__dep__incl.md5 +html/http_parser_8h__dep__incl.map +html/http_parser_8h.html +html/http_parser_8c_source.html +html/http_parser_8c__incl.png +html/http_parser_8c__incl.md5 +html/http_parser_8c__incl.map +html/http_parser_8c.html +html/group__snmp__module.html +html/group__extra__functions.html +html/group___w_i_znet__socket___a_p_is.html +html/group___w_i_z_c_h_i_p__register___w5300.png +html/group___w_i_z_c_h_i_p__register___w5300.md5 +html/group___w_i_z_c_h_i_p__register___w5300.map +html/group___w_i_z_c_h_i_p__register___w5300.html +html/group___w_i_z_c_h_i_p__register___w5200.png +html/group___w_i_z_c_h_i_p__register___w5200.md5 +html/group___w_i_z_c_h_i_p__register___w5200.map +html/group___w_i_z_c_h_i_p__register___w5200.html +html/group___w_i_z_c_h_i_p__register___w5100_s.png +html/group___w_i_z_c_h_i_p__register___w5100_s.md5 +html/group___w_i_z_c_h_i_p__register___w5100_s.map +html/group___w_i_z_c_h_i_p__register___w5100_s.html +html/group___w_i_z_c_h_i_p__register___w5100.png +html/group___w_i_z_c_h_i_p__register___w5100.md5 +html/group___w_i_z_c_h_i_p__register___w5100.map +html/group___w_i_z_c_h_i_p__register___w5100.html +html/group___w_i_z_c_h_i_p__register.png +html/group___w_i_z_c_h_i_p__register.md5 +html/group___w_i_z_c_h_i_p__register.map +html/group___w_i_z_c_h_i_p__register.html +html/group___w_i_z_c_h_i_p___i_o___functions___w5300.png +html/group___w_i_z_c_h_i_p___i_o___functions___w5300.md5 +html/group___w_i_z_c_h_i_p___i_o___functions___w5300.map +html/group___w_i_z_c_h_i_p___i_o___functions___w5300.html +html/group___w_i_z_c_h_i_p___i_o___functions___w5200.png +html/group___w_i_z_c_h_i_p___i_o___functions___w5200.md5 +html/group___w_i_z_c_h_i_p___i_o___functions___w5200.map +html/group___w_i_z_c_h_i_p___i_o___functions___w5200.html +html/group___w_i_z_c_h_i_p___i_o___functions___w5100_s.png +html/group___w_i_z_c_h_i_p___i_o___functions___w5100_s.md5 +html/group___w_i_z_c_h_i_p___i_o___functions___w5100_s.map +html/group___w_i_z_c_h_i_p___i_o___functions___w5100_s.html +html/group___w_i_z_c_h_i_p___i_o___functions___w5100.png +html/group___w_i_z_c_h_i_p___i_o___functions___w5100.md5 +html/group___w_i_z_c_h_i_p___i_o___functions___w5100.map +html/group___w_i_z_c_h_i_p___i_o___functions___w5100.html +html/group___w_i_z_c_h_i_p___i_o___functions.png +html/group___w_i_z_c_h_i_p___i_o___functions.md5 +html/group___w_i_z_c_h_i_p___i_o___functions.map +html/group___w_i_z_c_h_i_p___i_o___functions.html +html/group___w5500.png +html/group___w5500.md5 +html/group___w5500.map +html/group___w5500.html +html/group___w5300.png +html/group___w5300.md5 +html/group___w5300.map +html/group___w5300.html +html/group___w5200.png +html/group___w5200.md5 +html/group___w5200.map +html/group___w5200.html +html/group___w5100_s.png +html/group___w5100_s.md5 +html/group___w5100_s.map +html/group___w5100_s.html +html/group___w5100.png +html/group___w5100.md5 +html/group___w5100.map +html/group___w5100.html +html/group___special__function___w5100_s.png +html/group___special__function___w5100_s.md5 +html/group___special__function___w5100_s.map +html/group___special__function___w5100_s.html +html/group___socket__register__group___w5300.png +html/group___socket__register__group___w5300.md5 +html/group___socket__register__group___w5300.map +html/group___socket__register__group___w5300.html +html/group___socket__register__group___w5200.png +html/group___socket__register__group___w5200.md5 +html/group___socket__register__group___w5200.map +html/group___socket__register__group___w5200.html +html/group___socket__register__group___w5100_s.png +html/group___socket__register__group___w5100_s.md5 +html/group___socket__register__group___w5100_s.map +html/group___socket__register__group___w5100_s.html +html/group___socket__register__group___w5100.png +html/group___socket__register__group___w5100.md5 +html/group___socket__register__group___w5100.map +html/group___socket__register__group___w5100.html +html/group___socket__register__group.png +html/group___socket__register__group.md5 +html/group___socket__register__group.map +html/group___socket__register__group.html +html/group___socket__register__access__function___w5300.png +html/group___socket__register__access__function___w5300.md5 +html/group___socket__register__access__function___w5300.map +html/group___socket__register__access__function___w5300.html +html/group___socket__register__access__function___w5200.png +html/group___socket__register__access__function___w5200.md5 +html/group___socket__register__access__function___w5200.map +html/group___socket__register__access__function___w5200.html +html/group___socket__register__access__function___w5100_s.png +html/group___socket__register__access__function___w5100_s.md5 +html/group___socket__register__access__function___w5100_s.map +html/group___socket__register__access__function___w5100_s.html +html/group___socket__register__access__function___w5100.png +html/group___socket__register__access__function___w5100.md5 +html/group___socket__register__access__function___w5100.map +html/group___socket__register__access__function___w5100.html +html/group___socket__register__access__function.png +html/group___socket__register__access__function.md5 +html/group___socket__register__access__function.map +html/group___socket__register__access__function.html +html/group___d_a_t_a___t_y_p_e.html +html/group___common__register__group___w5300.png +html/group___common__register__group___w5300.md5 +html/group___common__register__group___w5300.map +html/group___common__register__group___w5300.html +html/group___common__register__group___w5200.png +html/group___common__register__group___w5200.md5 +html/group___common__register__group___w5200.map +html/group___common__register__group___w5200.html +html/group___common__register__group___w5100_s.png +html/group___common__register__group___w5100_s.md5 +html/group___common__register__group___w5100_s.map +html/group___common__register__group___w5100_s.html +html/group___common__register__group___w5100.png +html/group___common__register__group___w5100.md5 +html/group___common__register__group___w5100.map +html/group___common__register__group___w5100.html +html/group___common__register__group.png +html/group___common__register__group.md5 +html/group___common__register__group.map +html/group___common__register__group.html +html/group___common__register__access__function___w5300.png +html/group___common__register__access__function___w5300.md5 +html/group___common__register__access__function___w5300.map +html/group___common__register__access__function___w5300.html +html/group___common__register__access__function___w5200.png +html/group___common__register__access__function___w5200.md5 +html/group___common__register__access__function___w5200.map +html/group___common__register__access__function___w5200.html +html/group___common__register__access__function___w5100_s.png +html/group___common__register__access__function___w5100_s.md5 +html/group___common__register__access__function___w5100_s.map +html/group___common__register__access__function___w5100_s.html +html/group___common__register__access__function___w5100.png +html/group___common__register__access__function___w5100.md5 +html/group___common__register__access__function___w5100.map +html/group___common__register__access__function___w5100.html +html/group___common__register__access__function.png +html/group___common__register__access__function.md5 +html/group___common__register__access__function.map +html/group___common__register__access__function.html +html/group___basic___i_o__function___w5300.png +html/group___basic___i_o__function___w5300.md5 +html/group___basic___i_o__function___w5300.map +html/group___basic___i_o__function___w5300.html +html/group___basic___i_o__function___w5200.png +html/group___basic___i_o__function___w5200.md5 +html/group___basic___i_o__function___w5200.map +html/group___basic___i_o__function___w5200.html +html/group___basic___i_o__function___w5100_s.png +html/group___basic___i_o__function___w5100_s.md5 +html/group___basic___i_o__function___w5100_s.map +html/group___basic___i_o__function___w5100_s.html +html/group___basic___i_o__function___w5100.png +html/group___basic___i_o__function___w5100.md5 +html/group___basic___i_o__function___w5100.map +html/group___basic___i_o__function___w5100.html +html/group___basic___i_o__function.png +html/group___basic___i_o__function.md5 +html/group___basic___i_o__function.map +html/group___basic___i_o__function.html +html/graph_legend.png +html/graph_legend.md5 +html/graph_legend.html +html/globals_x.html +html/globals_w.html +html/globals_vars.html +html/globals_v.html +html/globals_u.html +html/globals_type.html +html/globals_t.html +html/globals_s.html +html/globals_r.html +html/globals_q.html +html/globals_p.html +html/globals_o.html +html/globals_n.html +html/globals_m.html +html/globals_l.html +html/globals_k.html +html/globals_i.html +html/globals_h.html +html/globals_g.html +html/globals_func_w.html +html/globals_func_u.html +html/globals_func_t.html +html/globals_func_s.html +html/globals_func_r.html +html/globals_func_p.html +html/globals_func_n.html +html/globals_func_m.html +html/globals_func_l.html +html/globals_func_k.html +html/globals_func_i.html +html/globals_func_h.html +html/globals_func_g.html +html/globals_func_f.html +html/globals_func_d.html +html/globals_func_c.html +html/globals_func_b.html +html/globals_func.html +html/globals_f.html +html/globals_eval_x.html +html/globals_eval_v.html +html/globals_eval_u.html +html/globals_eval_t.html +html/globals_eval_s.html +html/globals_eval_r.html +html/globals_eval_q.html +html/globals_eval_p.html +html/globals_eval_n.html +html/globals_eval_m.html +html/globals_eval_l.html +html/globals_eval_i.html +html/globals_eval_h.html +html/globals_eval_f.html +html/globals_eval_e.html +html/globals_eval_d.html +html/globals_eval_c.html +html/globals_eval_b.html +html/globals_eval.html +html/globals_enum.html +html/globals_e.html +html/globals_defs_w.html +html/globals_defs_v.html +html/globals_defs_u.html +html/globals_defs_t.html +html/globals_defs_s.html +html/globals_defs_r.html +html/globals_defs_q.html +html/globals_defs_p.html +html/globals_defs_o.html +html/globals_defs_n.html +html/globals_defs_m.html +html/globals_defs_l.html +html/globals_defs_i.html +html/globals_defs_h.html +html/globals_defs_g.html +html/globals_defs_f.html +html/globals_defs_e.html +html/globals_defs_d.html +html/globals_defs_c.html +html/globals_defs_b.html +html/globals_defs_a.html +html/globals_defs.html +html/globals_d.html +html/globals_c.html +html/globals_b.html +html/globals_a.html +html/globals.html +html/functions_y.html +html/functions_x.html +html/functions_w.html +html/functions_vars_y.html +html/functions_vars_x.html +html/functions_vars_w.html +html/functions_vars_v.html +html/functions_vars_u.html +html/functions_vars_t.html +html/functions_vars_s.html +html/functions_vars_r.html +html/functions_vars_q.html +html/functions_vars_p.html +html/functions_vars_o.html +html/functions_vars_n.html +html/functions_vars_m.html +html/functions_vars_l.html +html/functions_vars_k.html +html/functions_vars_i.html +html/functions_vars_h.html +html/functions_vars_g.html +html/functions_vars_f.html +html/functions_vars_e.html +html/functions_vars_d.html +html/functions_vars_c.html +html/functions_vars_b.html +html/functions_vars_a.html +html/functions_vars.html +html/functions_v.html +html/functions_u.html +html/functions_t.html +html/functions_s.html +html/functions_r.html +html/functions_q.html +html/functions_p.html +html/functions_o.html +html/functions_n.html +html/functions_m.html +html/functions_l.html +html/functions_k.html +html/functions_i.html +html/functions_h.html +html/functions_g.html +html/functions_f.html +html/functions_e.html +html/functions_d.html +html/functions_c.html +html/functions_b.html +html/functions_a.html +html/functions.html +html/ftpd_8h_source.html +html/ftpd_8h__incl.png +html/ftpd_8h__incl.md5 +html/ftpd_8h__incl.map +html/ftpd_8h__dep__incl.png +html/ftpd_8h__dep__incl.md5 +html/ftpd_8h__dep__incl.map +html/ftpd_8h.html +html/ftpd_8c_source.html +html/ftpd_8c__incl.png +html/ftpd_8c__incl.md5 +html/ftpd_8c__incl.map +html/ftpd_8c.html +html/ftpc_8h_source.html +html/ftpc_8h__incl.png +html/ftpc_8h__incl.md5 +html/ftpc_8h__incl.map +html/ftpc_8h__dep__incl.png +html/ftpc_8h__dep__incl.md5 +html/ftpc_8h__dep__incl.map +html/ftpc_8h.html +html/ftpc_8c_source.html +html/ftpc_8c__incl.png +html/ftpc_8c__incl.md5 +html/ftpc_8c__incl.map +html/ftpc_8c.html +html/folderopen.png +html/folderclosed.png +html/files.html +html/dynsections.js +html/doxygen__log_8txt.html +html/doxygen.png +html/doxygen.css +html/doc.png +html/dns_8h_source.html +html/dns_8h__incl.png +html/dns_8h__incl.md5 +html/dns_8h__incl.map +html/dns_8h__dep__incl.png +html/dns_8h__dep__incl.md5 +html/dns_8h__dep__incl.map +html/dns_8h.html +html/dns_8c_source.html +html/dns_8c__incl.png +html/dns_8c__incl.md5 +html/dns_8c__incl.map +html/dns_8c.html +html/dir_fe682d1d76c251404f71241aa833642c_dep.png +html/dir_fe682d1d76c251404f71241aa833642c_dep.md5 +html/dir_fe682d1d76c251404f71241aa833642c_dep.map +html/dir_fe682d1d76c251404f71241aa833642c.html +html/dir_fca0adf6655fb1759a15e5776097c124_dep.png +html/dir_fca0adf6655fb1759a15e5776097c124_dep.md5 +html/dir_fca0adf6655fb1759a15e5776097c124_dep.map +html/dir_fca0adf6655fb1759a15e5776097c124.html +html/dir_f841453af36a2df9a2123f87589fe4f8_dep.png +html/dir_f841453af36a2df9a2123f87589fe4f8_dep.md5 +html/dir_f841453af36a2df9a2123f87589fe4f8_dep.map +html/dir_f841453af36a2df9a2123f87589fe4f8.html +html/dir_f10a527ab5b3936e2edf95a019a13ec7_dep.png +html/dir_f10a527ab5b3936e2edf95a019a13ec7_dep.md5 +html/dir_f10a527ab5b3936e2edf95a019a13ec7_dep.map +html/dir_f10a527ab5b3936e2edf95a019a13ec7.html +html/dir_eb1463819d84903762eb6f59cc0c4383_dep.png +html/dir_eb1463819d84903762eb6f59cc0c4383_dep.md5 +html/dir_eb1463819d84903762eb6f59cc0c4383_dep.map +html/dir_eb1463819d84903762eb6f59cc0c4383.html +html/dir_e5121bff4754a4ad570fa548a998f0c5_dep.png +html/dir_e5121bff4754a4ad570fa548a998f0c5_dep.md5 +html/dir_e5121bff4754a4ad570fa548a998f0c5_dep.map +html/dir_e5121bff4754a4ad570fa548a998f0c5.html +html/dir_b88037d6581d528000057b4eaec3e673_dep.png +html/dir_b88037d6581d528000057b4eaec3e673_dep.md5 +html/dir_b88037d6581d528000057b4eaec3e673_dep.map +html/dir_b88037d6581d528000057b4eaec3e673.html +html/dir_a5a06f90a751e77147778694c516f622_dep.png +html/dir_a5a06f90a751e77147778694c516f622_dep.md5 +html/dir_a5a06f90a751e77147778694c516f622_dep.map +html/dir_a5a06f90a751e77147778694c516f622.html +html/dir_a483286db9c12f74c7364bdaa9e78c36_dep.png +html/dir_a483286db9c12f74c7364bdaa9e78c36_dep.md5 +html/dir_a483286db9c12f74c7364bdaa9e78c36_dep.map +html/dir_a483286db9c12f74c7364bdaa9e78c36.html +html/dir_a138ed074e64356ad02dbb8d94382c4f_dep.png +html/dir_a138ed074e64356ad02dbb8d94382c4f_dep.md5 +html/dir_a138ed074e64356ad02dbb8d94382c4f_dep.map +html/dir_a138ed074e64356ad02dbb8d94382c4f.html +html/dir_97b8cbb23222306012bd2d84398746c9_dep.png +html/dir_97b8cbb23222306012bd2d84398746c9_dep.md5 +html/dir_97b8cbb23222306012bd2d84398746c9_dep.map +html/dir_97b8cbb23222306012bd2d84398746c9.html +html/dir_6e6e4d5e89221ed61dd87b2954f72a78_dep.png +html/dir_6e6e4d5e89221ed61dd87b2954f72a78_dep.md5 +html/dir_6e6e4d5e89221ed61dd87b2954f72a78_dep.map +html/dir_6e6e4d5e89221ed61dd87b2954f72a78.html +html/dir_6de1940466803d61d2f9d1259cb01031.html +html/dir_5a912e51f6f9520965e8671f07512599_dep.png +html/dir_5a912e51f6f9520965e8671f07512599_dep.md5 +html/dir_5a912e51f6f9520965e8671f07512599_dep.map +html/dir_5a912e51f6f9520965e8671f07512599.html +html/dir_4c7002aef9ece892c0aedd728ed93eff.html +html/dir_498fbcdef69ea105b96b8673d051b2e3_dep.png +html/dir_498fbcdef69ea105b96b8673d051b2e3_dep.md5 +html/dir_498fbcdef69ea105b96b8673d051b2e3_dep.map +html/dir_498fbcdef69ea105b96b8673d051b2e3.html +html/dir_46819ec1095f3903911c103f5ebbb29f_dep.png +html/dir_46819ec1095f3903911c103f5ebbb29f_dep.md5 +html/dir_46819ec1095f3903911c103f5ebbb29f_dep.map +html/dir_46819ec1095f3903911c103f5ebbb29f.html +html/dir_4396dcc0e095a5bc10b1affe087807cf_dep.png +html/dir_4396dcc0e095a5bc10b1affe087807cf_dep.md5 +html/dir_4396dcc0e095a5bc10b1affe087807cf_dep.map +html/dir_4396dcc0e095a5bc10b1affe087807cf.html +html/dir_337e147d8ae2958ef29ccaa8e2f968db_dep.png +html/dir_337e147d8ae2958ef29ccaa8e2f968db_dep.md5 +html/dir_337e147d8ae2958ef29ccaa8e2f968db_dep.map +html/dir_337e147d8ae2958ef29ccaa8e2f968db.html +html/dir_2c7bb40a7e5a6685f00216dd2909cd99_dep.png +html/dir_2c7bb40a7e5a6685f00216dd2909cd99_dep.md5 +html/dir_2c7bb40a7e5a6685f00216dd2909cd99_dep.map +html/dir_2c7bb40a7e5a6685f00216dd2909cd99.html +html/dir_2c1dd796c287ab9a5cf44281d8a3cbeb.html +html/dir_072fcb7a67163ce1d8f22ad4144c7e08.html +html/dir_000020_000002.html +html/dir_000019_000002.html +html/dir_000018_000002.html +html/dir_000017_000002.html +html/dir_000015_000016.html +html/dir_000015_000002.html +html/dir_000014_000015.html +html/dir_000014_000002.html +html/dir_000013_000002.html +html/dir_000012_000002.html +html/dir_000011_000002.html +html/dir_000010_000002.html +html/dir_000009_000002.html +html/dir_000002_000007.html +html/dir_000002_000004.html +html/dir_000001_000002.html +html/dhcp_8h_source.html +html/dhcp_8h__dep__incl.png +html/dhcp_8h__dep__incl.md5 +html/dhcp_8h__dep__incl.map +html/dhcp_8h.html +html/dhcp_8c_source.html +html/dhcp_8c__incl.png +html/dhcp_8c__incl.md5 +html/dhcp_8c__incl.map +html/dhcp_8c.html +html/closed.png +html/classes.html +html/bdwn.png +html/bc_s.png +html/annotated.html +html/_w_i_znet___s_o_c_k_e_t_8jpg_source.html +html/_w_i_znet___s_o_c_k_e_t_8jpg.html +html/_stack_trace_8h_source.html +html/_stack_trace_8h__incl.png +html/_stack_trace_8h__incl.md5 +html/_stack_trace_8h__incl.map +html/_stack_trace_8h__dep__incl.png +html/_stack_trace_8h__dep__incl.md5 +html/_stack_trace_8h__dep__incl.map +html/_stack_trace_8h.html +html/_readme_8txt.html +html/_r_e_a_d_m_e_8md_source.html +html/_r_e_a_d_m_e_8md.html +html/_main__page_8txt.html +html/_m_q_t_t_unsubscribe_server_8c_source.html +html/_m_q_t_t_unsubscribe_server_8c__incl.png +html/_m_q_t_t_unsubscribe_server_8c__incl.md5 +html/_m_q_t_t_unsubscribe_server_8c__incl.map +html/_m_q_t_t_unsubscribe_server_8c.html +html/_m_q_t_t_unsubscribe_client_8c_source.html +html/_m_q_t_t_unsubscribe_client_8c__incl.png +html/_m_q_t_t_unsubscribe_client_8c__incl.md5 +html/_m_q_t_t_unsubscribe_client_8c__incl.map +html/_m_q_t_t_unsubscribe_client_8c.html +html/_m_q_t_t_unsubscribe_8h_source.html +html/_m_q_t_t_unsubscribe_8h__dep__incl.png +html/_m_q_t_t_unsubscribe_8h__dep__incl.md5 +html/_m_q_t_t_unsubscribe_8h__dep__incl.map +html/_m_q_t_t_unsubscribe_8h.html +html/_m_q_t_t_subscribe_server_8c_source.html +html/_m_q_t_t_subscribe_server_8c__incl.png +html/_m_q_t_t_subscribe_server_8c__incl.md5 +html/_m_q_t_t_subscribe_server_8c__incl.map +html/_m_q_t_t_subscribe_server_8c.html +html/_m_q_t_t_subscribe_client_8c_source.html +html/_m_q_t_t_subscribe_client_8c__incl.png +html/_m_q_t_t_subscribe_client_8c__incl.md5 +html/_m_q_t_t_subscribe_client_8c__incl.map +html/_m_q_t_t_subscribe_client_8c.html +html/_m_q_t_t_subscribe_8h_source.html +html/_m_q_t_t_subscribe_8h__dep__incl.png +html/_m_q_t_t_subscribe_8h__dep__incl.md5 +html/_m_q_t_t_subscribe_8h__dep__incl.map +html/_m_q_t_t_subscribe_8h.html +html/_m_q_t_t_serialize_publish_8c_source.html +html/_m_q_t_t_serialize_publish_8c__incl.png +html/_m_q_t_t_serialize_publish_8c__incl.md5 +html/_m_q_t_t_serialize_publish_8c__incl.map +html/_m_q_t_t_serialize_publish_8c.html +html/_m_q_t_t_publish_8h_source.html +html/_m_q_t_t_publish_8h__dep__incl.png +html/_m_q_t_t_publish_8h__dep__incl.md5 +html/_m_q_t_t_publish_8h__dep__incl.map +html/_m_q_t_t_publish_8h.html +html/_m_q_t_t_packet_8h_source.html +html/_m_q_t_t_packet_8h__incl.png +html/_m_q_t_t_packet_8h__incl.md5 +html/_m_q_t_t_packet_8h__incl.map +html/_m_q_t_t_packet_8h__dep__incl.png +html/_m_q_t_t_packet_8h__dep__incl.md5 +html/_m_q_t_t_packet_8h__dep__incl.map +html/_m_q_t_t_packet_8h.html +html/_m_q_t_t_packet_8c_source.html +html/_m_q_t_t_packet_8c__incl.png +html/_m_q_t_t_packet_8c__incl.md5 +html/_m_q_t_t_packet_8c__incl.map +html/_m_q_t_t_packet_8c.html +html/_m_q_t_t_format_8h_source.html +html/_m_q_t_t_format_8h__incl.png +html/_m_q_t_t_format_8h__incl.md5 +html/_m_q_t_t_format_8h__incl.map +html/_m_q_t_t_format_8h__dep__incl.png +html/_m_q_t_t_format_8h__dep__incl.md5 +html/_m_q_t_t_format_8h__dep__incl.map +html/_m_q_t_t_format_8h.html +html/_m_q_t_t_format_8c_source.html +html/_m_q_t_t_format_8c__incl.png +html/_m_q_t_t_format_8c__incl.md5 +html/_m_q_t_t_format_8c__incl.map +html/_m_q_t_t_format_8c.html +html/_m_q_t_t_deserialize_publish_8c_source.html +html/_m_q_t_t_deserialize_publish_8c__incl.png +html/_m_q_t_t_deserialize_publish_8c__incl.md5 +html/_m_q_t_t_deserialize_publish_8c__incl.map +html/_m_q_t_t_deserialize_publish_8c.html +html/_m_q_t_t_connect_server_8c_source.html +html/_m_q_t_t_connect_server_8c__incl.png +html/_m_q_t_t_connect_server_8c__incl.md5 +html/_m_q_t_t_connect_server_8c__incl.map +html/_m_q_t_t_connect_server_8c.html +html/_m_q_t_t_connect_client_8c_source.html +html/_m_q_t_t_connect_client_8c__incl.png +html/_m_q_t_t_connect_client_8c__incl.md5 +html/_m_q_t_t_connect_client_8c__incl.map +html/_m_q_t_t_connect_client_8c.html +html/_m_q_t_t_connect_8h_source.html +html/_m_q_t_t_connect_8h__dep__incl.png +html/_m_q_t_t_connect_8h__dep__incl.md5 +html/_m_q_t_t_connect_8h__dep__incl.map +html/_m_q_t_t_connect_8h.html +html/_m_q_t_t_client_8h_source.html +html/_m_q_t_t_client_8h__incl.png +html/_m_q_t_t_client_8h__incl.md5 +html/_m_q_t_t_client_8h__incl.map +html/_m_q_t_t_client_8h__dep__incl.png +html/_m_q_t_t_client_8h__dep__incl.md5 +html/_m_q_t_t_client_8h__dep__incl.map +html/_m_q_t_t_client_8h.html +html/_m_q_t_t_client_8c_source.html +html/_m_q_t_t_client_8c__incl.png +html/_m_q_t_t_client_8c__incl.md5 +html/_m_q_t_t_client_8c__incl.map +html/_m_q_t_t_client_8c.html +html/_f_t_p_server_2stdio__private_8h_source.html +html/_f_t_p_server_2stdio__private_8h__incl.png +html/_f_t_p_server_2stdio__private_8h__incl.md5 +html/_f_t_p_server_2stdio__private_8h__incl.map +html/_f_t_p_server_2stdio__private_8h__dep__incl.png +html/_f_t_p_server_2stdio__private_8h__dep__incl.md5 +html/_f_t_p_server_2stdio__private_8h__dep__incl.map +html/_f_t_p_server_2stdio__private_8h.html +html/_f_t_p_client_2stdio__private_8h_source.html +html/_f_t_p_client_2stdio__private_8h__incl.png +html/_f_t_p_client_2stdio__private_8h__incl.md5 +html/_f_t_p_client_2stdio__private_8h__incl.map +html/_f_t_p_client_2stdio__private_8h__dep__incl.png +html/_f_t_p_client_2stdio__private_8h__dep__incl.md5 +html/_f_t_p_client_2stdio__private_8h__dep__incl.map +html/_f_t_p_client_2stdio__private_8h.html +html/_berkeley___s_o_c_k_e_t_8jpg_source.html +html/_berkeley___s_o_c_k_e_t_8jpg.html +html/WIZnet_SOCKET.jpg +html/Berkeley_SOCKET.jpg +Main_page.txt +Doxyfile +man/man3/sntp.c.3 +man/man3/snmp_module.3 +man/man3/snmp_custom.h.3 +man/man3/snmp_custom.c.3 +man/man3/snmp.h.3 +man/man3/snmp.c.3 +man/man3/netutil.h.3 +man/man3/netutil.c.3 +man/man3/mqtt_interface.h.3 +man/man3/mqtt_interface.c.3 +man/man3/messageStruct.3 +man/man3/md__r_e_a_d_m_e.3 +man/man3/loopback.h.3 +man/man3/loopback.c.3 +man/man3/license.txt.3 +man/man3/httpUtil.h.3 +man/man3/_datetime.3 +man/man3/__file.3 +man/man3/__WIZCHIP__IF.3 +man/man3/__WIZCHIP__CS.3 +man/man3/__WIZCHIP__CRIS.3 +man/man3/__WIZCHIP.3 +man/man3/WIZnet_socket_APIs.3 +man/man3/WIZnet_SOCKET.jpg.3 +man/man3/WIZCHIP_register.3 +man/man3/WIZCHIP_IO_Functions_W5300.3 +man/man3/WIZCHIP_IO_Functions_W5200.3 +man/man3/WIZCHIP_IO_Functions_W5100S.3 +man/man3/W5500.3 +man/man3/W5300.3 +man/man3/W5100S.3 +man/man3/w5200.c.3 +man/man3/w5100s.h.3 +man/man3/w5100s.c.3 +man/man3/w5100.h.3 +man/man3/w5100.c.3 +man/man3/todo.3 +man/man3/tlvStructType.3 +man/man3/tftp_option.3 +man/man3/tftp_error.3 +man/man3/tftp_data.3 +man/man3/tftp.h.3 +man/man3/tftp.c.3 +man/man3/stdio_private.h.3 +man/man3/socket.h.3 +man/man3/socket.c.3 +man/man3/sntp.h.3 +man/man3/httpUtil.c.3 +man/man3/httpServer.h.3 +man/man3/httpServer.c.3 +man/man3/httpParser.h.3 +man/man3/httpParser.c.3 +man/man3/ftpd.h.3 +man/man3/ftpd.c.3 +man/man3/ftpd.3 +man/man3/WIZCHIP_register_W5300.3 +man/man3/WIZCHIP_register_W5200.3 +man/man3/WIZCHIP_register_W5100S.3 +man/man3/WIZCHIP_register_W5100.3 +man/man3/WIZCHIP_IO_Functions_W5100.3 +man/man3/WIZCHIP_IO_Functions.3 +man/man3/W5200.3 diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..e69de29 diff --git a/Application/Application.h b/Application/Application.h new file mode 100644 index 0000000..6053690 --- /dev/null +++ b/Application/Application.h @@ -0,0 +1,18 @@ +#ifndef _APPLICATION_H_ +#define _APPLICATION_H_ + +#include + + +#define SOCK_TCP4 (Sn_MR_TCP) +#define SOCK_TCP6 (Sn_MR_TCP6) +#define SOCK_TCPD (Sn_MR_TCPD) + +#define SOCK_UDP4 (Sn_MR_UDP4) +#define SOCK_UDP6 (Sn_MR_UDP6) +#define SOCK_UDPD (Sn_MR_UDPD) + +#define AS_IPV4 2 +#define AS_IPV6 23 +#define AS_IPDUAL 11 +#endif diff --git a/Application/loopback/loopback.c b/Application/loopback/loopback.c new file mode 100644 index 0000000..a199755 --- /dev/null +++ b/Application/loopback/loopback.c @@ -0,0 +1,1029 @@ +#include +#include "loopback.h" +#include "socket.h" +#include "wizchip_conf.h" + + +#if LOOPBACK_MODE == LOOPBACK_MAIN_NOBLCOK + + +static int8_t loopback_mode = 0 ; + + + + + +#if (_WIZCHIP_ == W5100 || _WIZCHIP_ == W5100S || _WIZCHIP_ == W5200 || _WIZCHIP_ == W5300 || _WIZCHIP_ == W5500) +int32_t loopback_tcps(uint8_t sn, uint8_t* buf, uint16_t port) { + int32_t ret; + uint16_t size = 0, sentsize = 0; + +#ifdef _LOOPBACK_DEBUG_ + uint8_t destip[4]; + uint16_t destport; +#endif + + switch (getSn_SR(sn)) { + case SOCK_ESTABLISHED : + if (getSn_IR(sn) & Sn_IR_CON) { +#ifdef _LOOPBACK_DEBUG_ + getSn_DIPR(sn, destip); + destport = getSn_DPORT(sn); + + printf("%d:Connected - %d.%d.%d.%d : %d\r\n", sn, destip[0], destip[1], destip[2], destip[3], destport); +#endif + setSn_IR(sn, Sn_IR_CON); + } + if ((size = getSn_RX_RSR(sn)) > 0) { // Don't need to check SOCKERR_BUSY because it doesn't not occur. + if (size > DATA_BUF_SIZE) { + size = DATA_BUF_SIZE; + } + ret = recv(sn, buf, size); + + if (ret <= 0) { + return ret; // check SOCKERR_BUSY & SOCKERR_XXX. For showing the occurrence of SOCKERR_BUSY. + } + size = (uint16_t) ret; + sentsize = 0; + + while (size != sentsize) { + ret = send(sn, buf + sentsize, size - sentsize); + if (ret < 0) { + close(sn); + return ret; + } + sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero. + } + } + break; + case SOCK_CLOSE_WAIT : +#ifdef _LOOPBACK_DEBUG_ + //printf("%d:CloseWait\r\n",sn); +#endif + if ((ret = disconnect(sn)) != SOCK_OK) { + return ret; + } +#ifdef _LOOPBACK_DEBUG_ + printf("%d:Socket Closed\r\n", sn); +#endif + break; + case SOCK_INIT : +#ifdef _LOOPBACK_DEBUG_ + printf("%d:Listen, TCP server loopback, port [%d]\r\n", sn, port); +#endif + if ((ret = listen(sn)) != SOCK_OK) { + return ret; + } + break; + case SOCK_CLOSED: +#ifdef _LOOPBACK_DEBUG_ + //printf("%d:TCP server loopback start\r\n",sn); +#endif + if ((ret = socket(sn, Sn_MR_TCP, port, 0x00)) != sn) { + return ret; + } +#ifdef _LOOPBACK_DEBUG_ + //printf("%d:Socket opened\r\n",sn); +#endif + break; + default: + break; + } + return 1; +} + + +int32_t loopback_tcpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destport) { + int32_t ret; // return value for SOCK_ERRORs + uint16_t size = 0, sentsize = 0; + + // Destination (TCP Server) IP info (will be connected) + // >> loopback_tcpc() function parameter + // >> Ex) + // uint8_t destip[4] = {192, 168, 0, 214}; + // uint16_t destport = 5000; + + // Port number for TCP client (will be increased) + static uint16_t any_port = 50000; + + // Socket Status Transitions + // Check the W5500 Socket n status register (Sn_SR, The 'Sn_SR' controlled by Sn_CR command or Packet send/recv status) + switch (getSn_SR(sn)) { + case SOCK_ESTABLISHED : + if (getSn_IR(sn) & Sn_IR_CON) { // Socket n interrupt register mask; TCP CON interrupt = connection with peer is successful +#ifdef _LOOPBACK_DEBUG_ + printf("%d:Connected to - %d.%d.%d.%d : %d\r\n", sn, destip[0], destip[1], destip[2], destip[3], destport); +#endif + setSn_IR(sn, Sn_IR_CON); // this interrupt should be write the bit cleared to '1' + } + + ////////////////////////////////////////////////////////////////////////////////////////////// + // Data Transaction Parts; Handle the [data receive and send] process + ////////////////////////////////////////////////////////////////////////////////////////////// + if ((size = getSn_RX_RSR(sn)) > 0) { // Sn_RX_RSR: Socket n Received Size Register, Receiving data length + if (size > DATA_BUF_SIZE) { + size = DATA_BUF_SIZE; // DATA_BUF_SIZE means user defined buffer size (array) + } + ret = recv(sn, buf, size); // Data Receive process (H/W Rx socket buffer -> User's buffer) + + if (ret <= 0) { + return ret; // If the received data length <= 0, receive failed and process end + } + size = (uint16_t) ret; + sentsize = 0; + + // Data sentsize control + while (size != sentsize) { + ret = send(sn, buf + sentsize, size - sentsize); // Data send process (User's buffer -> Destination through H/W Tx socket buffer) + if (ret < 0) { // Send Error occurred (sent data length < 0) + close(sn); // socket close + return ret; + } + sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero. + } + } + ////////////////////////////////////////////////////////////////////////////////////////////// + break; + + case SOCK_CLOSE_WAIT : +#ifdef _LOOPBACK_DEBUG_ + //printf("%d:CloseWait\r\n",sn); +#endif + if ((ret = disconnect(sn)) != SOCK_OK) { + return ret; + } +#ifdef _LOOPBACK_DEBUG_ + printf("%d:Socket Closed\r\n", sn); +#endif + break; + + case SOCK_INIT : +#ifdef _LOOPBACK_DEBUG_ + printf("%d:Try to connect to the %d.%d.%d.%d : %d\r\n", sn, destip[0], destip[1], destip[2], destip[3], destport); +#endif + if ((ret = connect(sn, destip, destport)) != SOCK_OK) { + return ret; // Try to TCP connect to the TCP server (destination) + } + break; + + case SOCK_CLOSED: + close(sn); + if ((ret = socket(sn, Sn_MR_TCP, any_port++, 0x00)) != sn) { + if (any_port == 0xffff) { + any_port = 50000; + } + return ret; // TCP socket open with 'any_port' port number + } +#ifdef _LOOPBACK_DEBUG_ + //printf("%d:TCP client loopback start\r\n",sn); + //printf("%d:Socket opened\r\n",sn); +#endif + break; + default: + break; + } + return 1; +} + + +int32_t loopback_udps(uint8_t sn, uint8_t* buf, uint16_t port) { + int32_t ret; + uint16_t size, sentsize; + uint8_t destip[4]; + uint16_t destport; + + switch (getSn_SR(sn)) { + case SOCK_UDP : + if ((size = getSn_RX_RSR(sn)) > 0) { + if (size > DATA_BUF_SIZE) { + size = DATA_BUF_SIZE; + } + ret = recvfrom(sn, buf, size, destip, (uint16_t*)&destport); + if (ret <= 0) { +#ifdef _LOOPBACK_DEBUG_ + printf("%d: recvfrom error. %ld\r\n", sn, ret); +#endif + return ret; + } + size = (uint16_t) ret; + sentsize = 0; + while (sentsize != size) { + ret = sendto(sn, buf + sentsize, size - sentsize, destip, destport); + if (ret < 0) { +#ifdef _LOOPBACK_DEBUG_ + printf("%d: sendto error. %ld\r\n", sn, ret); +#endif + return ret; + } + sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero. + } + } + break; + case SOCK_CLOSED: +#ifdef _LOOPBACK_DEBUG_ + //printf("%d:UDP loopback start\r\n",sn); +#endif + if ((ret = socket(sn, Sn_MR_UDP, port, 0x00)) != sn) { + return ret; + } +#ifdef _LOOPBACK_DEBUG_ + printf("%d:Opened, UDP loopback, port [%d]\r\n", sn, port); +#endif + break; + default : + break; + } + return 1; +} +int32_t loopback_udpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destport) { + int32_t ret; + uint16_t size = 0, sentsize = 0; + static uint16_t any_port = 50000; + // uint8_t* strtest = "\r\nhello world"; + // uint8_t flag = 0; + switch (getSn_SR(sn)) { + case SOCK_UDP : + // sendto(sn, strtest, strlen(strtest), destip, destport); + if ((size = getSn_RX_RSR(sn)) > 0) { + if (size > DATA_BUF_SIZE) { + size = DATA_BUF_SIZE; + } + ret = recvfrom(sn, buf, size, destip, (uint16_t*)&destport); + buf[ret] = 0x00; + printf("recv form[%d.%d.%d.%d][%d]: %s\n", destip[0], destip[1], destip[2], destip[3], destport, buf); + if (ret <= 0) { +#ifdef _LOOPBACK_DEBUG_ + printf("%d: recvfrom error. %ld\r\n", sn, ret); +#endif + return ret; + } + size = (uint16_t) ret; + sentsize = 0; + while (sentsize != size) { + ret = sendto(sn, buf + sentsize, size - sentsize, destip, destport); + if (ret < 0) { +#ifdef _LOOPBACK_DEBUG_ + printf("%d: sendto error. %ld\r\n", sn, ret); +#endif + return ret; + } + sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero. + } + } + break; + case SOCK_CLOSED: +#ifdef _LOOPBACK_DEBUG_ + // printf("%d:UDP loopback start\r\n",sn); +#endif + if ((ret = socket(sn, Sn_MR_UDP, any_port, 0x00)) != sn) { + return ret; + } +#ifdef _LOOPBACK_DEBUG_ + printf("%d:Opened, UDP loopback, port [%d]\r\n", sn, any_port); +#endif + break; + default : + break; + } + return 1; + +} + +//teddy 240122 + + + +#elif ((_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300)) + +int8_t set_loopback_mode_W6x00(uint8_t get_loopback_mode) { + loopback_mode = get_loopback_mode ; + return 0; +} + +int8_t check_loopback_mode_W6x00() { + if (loopback_mode != AS_IPV4 && loopback_mode != AS_IPV6 && loopback_mode != AS_IPDUAL) { + loopback_mode = AS_IPV4 ; + } + return loopback_mode; +} + +//static uint16_t j=0; +static uint16_t any_port = 50000; +static uint8_t curr_state[8] = {0,}; +static uint8_t sock_state[8] = {0,}; +uint8_t* msg_v4 = "IPv4 mode"; +uint8_t* msg_v6 = "IPv6 mode"; +uint8_t* msg_dual = "Dual IP mode"; + +int32_t loopback_tcps(uint8_t sn, uint8_t* buf, uint16_t port) { + // by Lihan 20241119 + check_loopback_mode_W6x00(); + int32_t ret; + uint16_t sentsize = 0; + int8_t status, inter; + uint8_t tmp = 0; + uint16_t received_size; + uint8_t arg_tmp8; + uint8_t* mode_msg; +#if 1 + // 20231018 taylor + uint8_t destip[16], sn_status; + uint16_t destport; +#endif + + if (loopback_mode == AS_IPV4) { + mode_msg = msg_v4; + } else if (loopback_mode == AS_IPV6) { + mode_msg = msg_v6; + } else { + mode_msg = msg_dual; + } +#ifdef _LOOPBACK_DEBUG_ + uint8_t dst_ip[16], ext_status; + uint16_t dst_port; +#endif + getsockopt(sn, SO_STATUS, &status); + switch (status) { + case SOCK_ESTABLISHED : + ctlsocket(sn, CS_GET_INTERRUPT, &inter); + if (inter & Sn_IR_CON) { +#ifdef _LOOPBACK_DEBUG_ + getsockopt(sn, SO_DESTIP, dst_ip); + getsockopt(sn, SO_EXTSTATUS, &ext_status); + if (ext_status & TCPSOCK_MODE) { + //IPv6 + printf("%d:Peer IP : %04X:%04X", sn, ((uint16_t)dst_ip[0] << 8) | ((uint16_t)dst_ip[1]), + ((uint16_t)dst_ip[2] << 8) | ((uint16_t)dst_ip[3])); + printf(":%04X:%04X", ((uint16_t)dst_ip[4] << 8) | ((uint16_t)dst_ip[5]), + ((uint16_t)dst_ip[6] << 8) | ((uint16_t)dst_ip[7])); + printf(":%04X:%04X", ((uint16_t)dst_ip[8] << 8) | ((uint16_t)dst_ip[9]), + ((uint16_t)dst_ip[10] << 8) | ((uint16_t)dst_ip[11])); + printf(":%04X:%04X, ", ((uint16_t)dst_ip[12] << 8) | ((uint16_t)dst_ip[13]), + ((uint16_t)dst_ip[14] << 8) | ((uint16_t)dst_ip[15])); + } else { + //IPv4 + //getSn_DIPR(sn,dst_ip); + printf("%d:Peer IP : %.3d.%.3d.%.3d.%.3d, ", + sn, dst_ip[0], dst_ip[1], dst_ip[2], dst_ip[3]); + } + getsockopt(sn, SO_DESTPORT, &dst_port); + printf("Peer Port : %d\r\n", dst_port); +#endif + arg_tmp8 = Sn_IR_CON; + ctlsocket(sn, CS_CLR_INTERRUPT, &arg_tmp8); + } + getsockopt(sn, SO_RECVBUF, &received_size); + + if (received_size > 0) { + if (received_size > DATA_BUF_SIZE) { + received_size = DATA_BUF_SIZE; + } + ret = recv(sn, buf, received_size); + +#if 1 + // 20231018 taylor +#ifdef _LOOPBACK_DEBUG_ + getsockopt(sn, SO_DESTIP, destip); + getsockopt(sn, SO_DESTPORT, &destport); + getsockopt(sn, SO_EXTSTATUS, &sn_status); + if (sn_status & TCPSOCK_MODE) { + printf("Socket %d Received %d bytes from %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x port %d : \r\n", + sn, received_size, + destip[0], destip[1], destip[2], destip[3], + destip[4], destip[5], destip[6], destip[7], + destip[8], destip[9], destip[10], destip[11], + destip[12], destip[13], destip[14], destip[15], + destport); + } else { + printf("Socket %d Received %d bytes from %d.%d.%d.%d port %d : \r\n", sn, received_size, destip[0], destip[1], destip[2], destip[3], destport); + } + + int i; + for (i = 0; i < received_size; i++) { + printf("%c", buf[i]); + } + printf("\r\n"); +#endif +#endif + if (ret <= 0) { + return ret; // check SOCKERR_BUSY & SOCKERR_XXX. For showing the occurrence of SOCKERR_BUSY. + } + received_size = (uint16_t) ret; + sentsize = 0; + + while (received_size != sentsize) { + ret = send(sn, buf + sentsize, received_size - sentsize); + if (ret < 0) { + close(sn); + return ret; + } + sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero. + } +#if 1 + // 20231018 taylor +#ifdef _LOOPBACK_DEBUG_ + if (sn_status & TCPSOCK_MODE) { + printf("Socket %d Sent back %d bytes from %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x port %d : \r\n", + sn, sentsize, + destip[0], destip[1], destip[2], destip[3], + destip[4], destip[5], destip[6], destip[7], + destip[8], destip[9], destip[10], destip[11], + destip[12], destip[13], destip[14], destip[15], + destport); + } else { + printf("Socket %d Sent back %d bytes from %d.%d.%d.%d port %d : \r\n", sn, sentsize, destip[0], destip[1], destip[2], destip[3], destport); + } + + int j; + for (j = 0; j < sentsize; j++) { + printf("%c", buf[j]); + } + printf("\r\n"); +#endif +#endif + } + break; + case SOCK_CLOSE_WAIT : +#ifdef _LOOPBACK_DEBUG_ + printf("%d:CloseWait\r\n", sn); +#endif + getsockopt(sn, SO_RECVBUF, &received_size); + if (received_size > 0) { // Don't need to check SOCKERR_BUSY because it doesn't not occur. + if (received_size > DATA_BUF_SIZE) { + received_size = DATA_BUF_SIZE; + } + ret = recv(sn, buf, received_size); + + if (ret <= 0) { + return ret; // check SOCKERR_BUSY & SOCKERR_XXX. For showing the occurrence of SOCKERR_BUSY. + } + received_size = (uint16_t) ret; + sentsize = 0; + +#if 1 + // 20231018 taylor +#ifdef _LOOPBACK_DEBUG_ + getsockopt(sn, SO_DESTIP, destip); + getsockopt(sn, SO_DESTPORT, &destport); + getsockopt(sn, SO_EXTSTATUS, &sn_status); + if (sn_status & TCPSOCK_MODE) { + printf("Socket %d Received %d bytes from %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x port %d : \r\n", + sn, received_size, + destip[0], destip[1], destip[2], destip[3], + destip[4], destip[5], destip[6], destip[7], + destip[8], destip[9], destip[10], destip[11], + destip[12], destip[13], destip[14], destip[15], + destport); + } else { + printf("Socket %d Received %d bytes from %d.%d.%d.%d port %d : \r\n", sn, received_size, destip[0], destip[1], destip[2], destip[3], destport); + } + + int i; + for (i = 0; i < received_size; i++) { + printf("%c", buf[i]); + } + printf("\r\n"); +#endif +#endif + + while (received_size != sentsize) { + ret = send(sn, buf + sentsize, received_size - sentsize); + if (ret < 0) { + close(sn); + return ret; + } + sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero. + } +#if 1 + // 20231018 taylor +#ifdef _LOOPBACK_DEBUG_ + if (sn_status & TCPSOCK_MODE) { + printf("Socket %d Sent back %d bytes from %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x port %d : \r\n", + sn, sentsize, + destip[0], destip[1], destip[2], destip[3], + destip[4], destip[5], destip[6], destip[7], + destip[8], destip[9], destip[10], destip[11], + destip[12], destip[13], destip[14], destip[15], + destport); + } else { + printf("Socket %d Sent back %d bytes from %d.%d.%d.%d port %d : \r\n", sn, sentsize, destip[0], destip[1], destip[2], destip[3], destport); + } + + int j; + for (j = 0; j < sentsize; j++) { + printf("%c", buf[j]); + } + printf("\r\n"); +#endif +#endif + } + + if ((ret = disconnect(sn)) != SOCK_OK) { + return ret; + } +#ifdef _LOOPBACK_DEBUG_ + printf("%d:Socket Closed\r\n", sn); +#endif + break; + case SOCK_INIT : + if ((ret = listen(sn)) != SOCK_OK) { + return ret; + } +#if 1 + // 20231018 taylor +#if 0 +#endif +#else +#ifdef _LOOPBACK_DEBUG_ + printf("%d:Listen, TCP server loopback, port [%d] as %s\r\n", sn, port, mode_msg); +#endif +#endif + printf("%d:Listen, TCP server loopback, port [%d] as %s\r\n", sn, port, mode_msg); + break; + case SOCK_CLOSED: +#ifdef _LOOPBACK_DEBUG_ + printf("%d:TCP server loopback start\r\n", sn); +#endif + switch (loopback_mode) { + case AS_IPV4: + tmp = socket(sn, Sn_MR_TCP4, port, SOCK_IO_NONBLOCK); + break; + case AS_IPV6: + tmp = socket(sn, Sn_MR_TCP6, port, SOCK_IO_NONBLOCK); + break; + case AS_IPDUAL: + tmp = socket(sn, Sn_MR_TCPD, port, SOCK_IO_NONBLOCK); + break; + default: + break; + } + if (tmp != sn) { /* reinitialize the socket */ +#ifdef _LOOPBACK_DEBUG_ + printf("%d : Fail to create socket.\r\n", sn); +#endif + return SOCKERR_SOCKNUM; + } +#ifdef _LOOPBACK_DEBUG_ + printf("%d:Socket opened[%d]\r\n", sn, getSn_SR(sn)); + sock_state[sn] = 1; +#endif + break; + default: + break; + } + return 1; +} + +int32_t loopback_tcpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destport) { + check_loopback_mode_W6x00(); + int32_t ret; // return value for SOCK_ERRORs + uint16_t sentsize = 0; + uint8_t status, inter, addr_len; + uint16_t received_size; + uint8_t tmp = 0; + uint8_t arg_tmp8; + wiz_IPAddress destinfo; +#if 1 + // 20231018 taylor + uint8_t sn_status; +#endif + + + // Socket Status Transitions + // Check the W6100 Socket n status register (Sn_SR, The 'Sn_SR' controlled by Sn_CR command or Packet send/recv status) + getsockopt(sn, SO_STATUS, &status); + switch (status) { + case SOCK_ESTABLISHED : + ctlsocket(sn, CS_GET_INTERRUPT, &inter); + if (inter & Sn_IR_CON) { // Socket n interrupt register mask; TCP CON interrupt = connection with peer is successful +#ifdef _LOOPBACK_DEBUG_ +#if 1 + // 20231018 taylor + getsockopt(sn, SO_EXTSTATUS, &sn_status); + if (sn_status & TCPSOCK_MODE) { + printf("%d:Connected to - %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x : %d\r\n", sn, + destip[0], destip[1], destip[2], destip[3], + destip[4], destip[5], destip[6], destip[7], + destip[8], destip[9], destip[10], destip[11], + destip[12], destip[13], destip[14], destip[15], + destport); + } else { + printf("%d:Connected to - %d.%d.%d.%d : %d\r\n", sn, destip[0], destip[1], destip[2], destip[3], destport); + } +#else + printf("%d:Connected to - %d.%d.%d.%d : %d\r\n", sn, destip[0], destip[1], destip[2], destip[3], destport); +#endif +#endif + arg_tmp8 = Sn_IR_CON; + ctlsocket(sn, CS_CLR_INTERRUPT, &arg_tmp8); // this interrupt should be write the bit cleared to '1' + } + + ////////////////////////////////////////////////////////////////////////////////////////////// + // Data Transaction Parts; Handle the [data receive and send] process + ////////////////////////////////////////////////////////////////////////////////////////////// + getsockopt(sn, SO_RECVBUF, &received_size); + + if (received_size > 0) { // Sn_RX_RSR: Socket n Received Size Register, Receiving data length + if (received_size > DATA_BUF_SIZE) { + received_size = DATA_BUF_SIZE; // DATA_BUF_SIZE means user defined buffer size (array) + } + ret = recv(sn, buf, received_size); // Data Receive process (H/W Rx socket buffer -> User's buffer) + + if (ret <= 0) { + return ret; // If the received data length <= 0, receive failed and process end + } + received_size = (uint16_t) ret; + sentsize = 0; + +#if 1 + // 20231018 taylor +#ifdef _LOOPBACK_DEBUG_ + getsockopt(sn, SO_EXTSTATUS, &sn_status); + if (sn_status & TCPSOCK_MODE) { + printf("Socket %d Received %d bytes from %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x port %d : \r\n", + sn, received_size, + destip[0], destip[1], destip[2], destip[3], + destip[4], destip[5], destip[6], destip[7], + destip[8], destip[9], destip[10], destip[11], + destip[12], destip[13], destip[14], destip[15], + destport); + } else { + printf("Socket %d Received %d bytes from %d.%d.%d.%d port %d : \r\n", sn, received_size, destip[0], destip[1], destip[2], destip[3], destport); + } + + int i; + for (i = 0; i < received_size; i++) { + printf("%c", buf[i]); + } + printf("\r\n"); +#endif +#endif + + // Data sentsize control + while (received_size != sentsize) { + ret = send(sn, buf + sentsize, received_size - sentsize); // Data send process (User's buffer -> Destination through H/W Tx socket buffer) + if (ret < 0) { // Send Error occurred (sent data length < 0) + close(sn); // socket close + return ret; + } + sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero. + } +#if 1 + // 20231018 taylor +#ifdef _LOOPBACK_DEBUG_ + if (sn_status & TCPSOCK_MODE) { + printf("Socket %d Sent back %d bytes from %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x port %d : \r\n", + sn, sentsize, + destip[0], destip[1], destip[2], destip[3], + destip[4], destip[5], destip[6], destip[7], + destip[8], destip[9], destip[10], destip[11], + destip[12], destip[13], destip[14], destip[15], + destport); + } else { + printf("Socket %d Sent back %d bytes from %d.%d.%d.%d port %d : \r\n", sn, sentsize, destip[0], destip[1], destip[2], destip[3], destport); + } + + int j; + for (j = 0; j < sentsize; j++) { + printf("%c", buf[j]); + } + printf("\r\n"); +#endif +#endif + } + ////////////////////////////////////////////////////////////////////////////////////////////// + break; + + case SOCK_CLOSE_WAIT : +#ifdef _LOOPBACK_DEBUG_ + printf("%d:CloseWait\r\n", sn); +#endif + getsockopt(sn, SO_RECVBUF, &received_size); + + if ((received_size = getSn_RX_RSR(sn)) > 0) { // Sn_RX_RSR: Socket n Received Size Register, Receiving data length + if (received_size > DATA_BUF_SIZE) { + received_size = DATA_BUF_SIZE; // DATA_BUF_SIZE means user defined buffer size (array) + } + ret = recv(sn, buf, received_size); // Data Receive process (H/W Rx socket buffer -> User's buffer) + + if (ret <= 0) { + return ret; // If the received data length <= 0, receive failed and process end + } + received_size = (uint16_t) ret; + sentsize = 0; +#if 1 + // 20231018 taylor +#ifdef _LOOPBACK_DEBUG_ + getsockopt(sn, SO_EXTSTATUS, &sn_status); + if (sn_status & TCPSOCK_MODE) { + printf("Socket %d Received %d bytes from %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x port %d : \r\n", + sn, received_size, + destip[0], destip[1], destip[2], destip[3], + destip[4], destip[5], destip[6], destip[7], + destip[8], destip[9], destip[10], destip[11], + destip[12], destip[13], destip[14], destip[15], + destport); + } else { + printf("Socket %d Received %d bytes from %d.%d.%d.%d port %d : \r\n", sn, received_size, destip[0], destip[1], destip[2], destip[3], destport); + } + + int i; + for (i = 0; i < received_size; i++) { + printf("%c", buf[i]); + } + printf("\r\n"); +#endif +#endif + + // Data sentsize control + while (received_size != sentsize) { + ret = send(sn, buf + sentsize, received_size - sentsize); // Data send process (User's buffer -> Destination through H/W Tx socket buffer) + if (ret < 0) { // Send Error occurred (sent data length < 0) + close(sn); // socket close + return ret; + } + sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero. + } +#if 1 + // 20231018 taylor +#ifdef _LOOPBACK_DEBUG_ + if (sn_status & TCPSOCK_MODE) { + printf("Socket %d Sent back %d bytes from %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x port %d : \r\n", + sn, sentsize, + destip[0], destip[1], destip[2], destip[3], + destip[4], destip[5], destip[6], destip[7], + destip[8], destip[9], destip[10], destip[11], + destip[12], destip[13], destip[14], destip[15], + destport); + } else { + printf("Socket %d Sent back %d bytes from %d.%d.%d.%d port %d : \r\n", sn, sentsize, destip[0], destip[1], destip[2], destip[3], destport); + } + + int j; + for (j = 0; j < sentsize; j++) { + printf("%c", buf[j]); + } + printf("\r\n"); +#endif +#endif + } + if ((ret = disconnect(sn)) != SOCK_OK) { + return ret; + } +#ifdef _LOOPBACK_DEBUG_ + printf("%d:Socket Closed\r\n", sn); +#endif + break; + + case SOCK_INIT : +#ifdef _LOOPBACK_DEBUG_ + if (loopback_mode == AS_IPV4) { + printf("%d:Try to connect to the %d.%d.%d.%d, %d\r\n", sn, destip[0], destip[1], destip[2], destip[3], destport); + } else if (loopback_mode == AS_IPV6) { + printf("%d:Try to connect to the %04X:%04X", sn, ((uint16_t)destip[0] << 8) | ((uint16_t)destip[1]), + ((uint16_t)destip[2] << 8) | ((uint16_t)destip[3])); + printf(":%04X:%04X", ((uint16_t)destip[4] << 8) | ((uint16_t)destip[5]), + ((uint16_t)destip[6] << 8) | ((uint16_t)destip[7])); + printf(":%04X:%04X", ((uint16_t)destip[8] << 8) | ((uint16_t)destip[9]), + ((uint16_t)destip[10] << 8) | ((uint16_t)destip[11])); + printf(":%04X:%04X,", ((uint16_t)destip[12] << 8) | ((uint16_t)destip[13]), + ((uint16_t)destip[14] << 8) | ((uint16_t)destip[15])); + printf("%d\r\n", destport); + } +#endif + + if (loopback_mode == AS_IPV4) { + ret = connect(sn, destip, destport, 4); /* Try to connect to TCP server(Socket, DestIP, DestPort) */ + } else if (loopback_mode == AS_IPV6) { + ret = connect(sn, destip, destport, 16); /* Try to connect to TCP server(Socket, DestIP, DestPort) */ + } + + printf("SOCK Status: %d\r\n", ret); + + if (ret != SOCK_OK) { + return ret; // Try to TCP connect to the TCP server (destination) + } + break; + + case SOCK_CLOSED: + switch (loopback_mode) { + case AS_IPV4: + tmp = socket(sn, Sn_MR_TCP4, any_port++, SOCK_IO_NONBLOCK); + break; + case AS_IPV6: + tmp = socket(sn, Sn_MR_TCP6, any_port++, SOCK_IO_NONBLOCK); + break; + case AS_IPDUAL: + tmp = socket(sn, Sn_MR_TCPD, any_port++, SOCK_IO_NONBLOCK); + break; + default: + break; + } + + if (tmp != sn) { /* reinitialize the socket */ +#ifdef _LOOPBACK_DEBUG_ + printf("%d : Fail to create socket.\r\n", sn); +#endif + return SOCKERR_SOCKNUM; + } + printf("%d:Socket opened[%d]\r\n", sn, getSn_SR(sn)); + sock_state[sn] = 1; + + break; + default: + break; + } + return 1; +} + +int32_t loopback_udps(uint8_t sn, uint8_t* buf, uint16_t port) { + check_loopback_mode_W6x00(); + uint8_t status; + static uint8_t destip[16] = {0,}; + static uint16_t destport; + uint8_t pack_info; + uint8_t addr_len; + uint16_t ret; + uint16_t received_size; + uint16_t size, sentsize; + uint8_t* mode_msg; + + if (loopback_mode == AS_IPV4) { + mode_msg = msg_v4; + } else if (loopback_mode == AS_IPV6) { + mode_msg = msg_v6; + } else { + mode_msg = msg_dual; + } + + getsockopt(sn, SO_STATUS, &status); + switch (status) { + case SOCK_UDP: + getsockopt(sn, SO_RECVBUF, &received_size); + if (received_size > DATA_BUF_SIZE) { + received_size = DATA_BUF_SIZE; + } + if (received_size > 0) { + ret = recvfrom(sn, buf, received_size, (uint8_t*)&destip, (uint16_t*)&destport, &addr_len); + + if (ret <= 0) { + return ret; + } + received_size = (uint16_t) ret; +#if 1 + // 20231018 taylor +#ifdef _LOOPBACK_DEBUG_ + if (addr_len == 4) { + printf("Socket %d Received %d bytes from %d.%d.%d.%d port %d : \r\n", sn, received_size, destip[0], destip[1], destip[2], destip[3], destport); + } else { + printf("Socket %d Received %d bytes from %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x port %d : \r\n", + sn, received_size, + destip[0], destip[1], destip[2], destip[3], + destip[4], destip[5], destip[6], destip[7], + destip[8], destip[9], destip[10], destip[11], + destip[12], destip[13], destip[14], destip[15], + destport); + } + + int i; + for (i = 0; i < received_size; i++) { + printf("%c", buf[i]); + } + printf("\r\n"); +#endif +#endif + sentsize = 0; + while (sentsize != received_size) { + ret = sendto(sn, buf + sentsize, received_size - sentsize, destip, destport, addr_len); + + if (ret < 0) { + return ret; + } + + sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero. + } +#if 1 + // 20231018 taylor +#ifdef _LOOPBACK_DEBUG_ + int j; + if (addr_len == 4) { + printf("Socket %d Sent back %d bytes from %d.%d.%d.%d port %d : \r\n", sn, sentsize, destip[0], destip[1], destip[2], destip[3], destport); + } else { + printf("Socket %d Sent back %d bytes from %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x port %d : \r\n", + sn, sentsize, + destip[0], destip[1], destip[2], destip[3], + destip[4], destip[5], destip[6], destip[7], + destip[8], destip[9], destip[10], destip[11], + destip[12], destip[13], destip[14], destip[15], + destport); + } + for (j = 0; j < sentsize; j++) { + printf("%c", buf[j]); + } + printf("\r\n"); +#endif +#endif + } + break; + case SOCK_CLOSED: + + switch (loopback_mode) { + case AS_IPV4: + socket(sn, Sn_MR_UDP4, port, SOCK_IO_NONBLOCK); + break; + case AS_IPV6: + socket(sn, Sn_MR_UDP6, port, SOCK_IO_NONBLOCK); + break; + case AS_IPDUAL: + socket(sn, Sn_MR_UDPD, port, SOCK_IO_NONBLOCK); + break; + } + printf("%d:Opened, UDP loopback, port [%d] as %s\r\n", sn, port, mode_msg); + + } + + return 0; +} + + + +int32_t loopback_udpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destport) { + check_loopback_mode_W6x00(); + int32_t ret; + uint16_t size = 0, sentsize = 0; + static uint16_t any_port = 50000; + uint8_t addr_len; + + + uint8_t* mode_msg; + if (loopback_mode == AS_IPV4) { + mode_msg = msg_v4; + } else if (loopback_mode == AS_IPV6) { + mode_msg = msg_v6; + } else { + mode_msg = msg_dual; + } + + // uint8_t* strtest = "\r\nhello world"; + // uint8_t flag = 0; + switch (getSn_SR(sn)) { + case SOCK_UDP : + // sendto(sn, strtest, strlen(strtest), destip, destport); + if ((size = getSn_RX_RSR(sn)) > 0) { + if (size > DATA_BUF_SIZE) { + size = DATA_BUF_SIZE; + } + ret = recvfrom(sn, buf, size, destip, (uint16_t*)&destport, &addr_len); + buf[ret] = 0x00; + printf("recv form[%d.%d.%d.%d][%d]: %s\n", destip[0], destip[1], destip[2], destip[3], destport, buf); + if (ret <= 0) { +#ifdef _LOOPBACK_DEBUG_ + printf("%d: recvfrom error. %ld\r\n", sn, ret); +#endif + return ret; + } + size = (uint16_t) ret; + sentsize = 0; + while (sentsize != size) { + ret = sendto(sn, buf + sentsize, size - sentsize, destip, destport, addr_len); + if (ret < 0) { +#ifdef _LOOPBACK_DEBUG_ + printf("%d: sendto error. %ld\r\n", sn, ret); +#endif + return ret; + } + sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero. + } + } + break; + case SOCK_CLOSED: +#ifdef _LOOPBACK_DEBUG_ + // printf("%d:UDP loopback start\r\n",sn); +#endif + + switch (loopback_mode) { + case AS_IPV4: + socket(sn, Sn_MR_UDP4, destport, SOCK_IO_NONBLOCK); + break; + case AS_IPV6: + socket(sn, Sn_MR_UDP6, destport, SOCK_IO_NONBLOCK); + break; + case AS_IPDUAL: + socket(sn, Sn_MR_UDPD, destport, SOCK_IO_NONBLOCK); + break; + } + printf("%d:Opened, UDP loopback, port [%d] as %s\r\n", sn, destport, mode_msg); +#ifdef _LOOPBACK_DEBUG_ + printf("%d:Opened, UDP loopback, port [%d]\r\n", sn, any_port); +#endif + break; + default : + break; + } + return 1; + +} + +#endif + +#endif diff --git a/Application/loopback/loopback.h b/Application/loopback/loopback.h new file mode 100644 index 0000000..6be2ce8 --- /dev/null +++ b/Application/loopback/loopback.h @@ -0,0 +1,50 @@ +#ifndef _LOOPBACK_H_ +#define _LOOPBACK_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "wizchip_conf.h" + +/* Loopback test debug message printout enable */ +#if 0 +#define _LOOPBACK_DEBUG_ +#endif + +/* DATA_BUF_SIZE define for Loopback example */ +#ifndef DATA_BUF_SIZE +#define DATA_BUF_SIZE 2048 +#endif + +/************************/ +/* Select LOOPBACK_MODE */ +/************************/ +#define LOOPBACK_MAIN_NOBLOCK 0 +#define LOOPBACK_MODE LOOPBACK_MAIN_NOBLOCK + +#if ((_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300)) +int8_t set_loopback_mode_W6x00(uint8_t get_loopback_mode) ; +int8_t check_loopback_mode_W6x00(); +#endif + +/* TCP server Loopback test example */ +int32_t loopback_tcps(uint8_t sn, uint8_t* buf, uint16_t port); + +/* TCP client Loopback test example */ +int32_t loopback_tcpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destport); + +/* UDP Loopback test example */ +int32_t loopback_udps(uint8_t sn, uint8_t* buf, uint16_t port); + +/* UDP Client Loopback test example */ +int32_t loopback_udpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destport); + +//teddy 240122 + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Application/multicast/multicast.c b/Application/multicast/multicast.c new file mode 100644 index 0000000..d159972 --- /dev/null +++ b/Application/multicast/multicast.c @@ -0,0 +1,145 @@ +#include "multicast.h" +#include +#include "socket.h" +#include "wizchip_conf.h" + + +int32_t multicast_loopback(uint8_t sn, uint8_t* buf, uint8_t* multicast_ip, uint16_t multicast_port) { + int32_t ret; + uint16_t size, sentsize; + uint8_t destip[4]; + uint16_t destport, port = 3000; +#if 1 + // 20231019 taylor + uint8_t addr_len; +#endif + + switch (getSn_SR(sn)) { + case SOCK_UDP : + if ((size = getSn_RX_RSR(sn)) > 0) { + if (size > DATA_BUF_SIZE) { + size = DATA_BUF_SIZE; + } +#if 1 + // 20231019 taylor//teddy 240122 +#if ((_WIZCHIP_ == 6100)|| (_WIZCHIP_ == 6300)) + ret = recvfrom(sn, buf, size, destip, (uint16_t*)&destport, &addr_len); +#else + ret = recvfrom(sn, buf, size, destip, (uint16_t*)&destport); +#endif +#else + ret = recvfrom(sn, buf, size, destip, (uint16_t*)&destport); +#endif + if (ret <= 0) { +#ifdef _MULTICAST_DEBUG_ + printf("%d: recvfrom error. %ld\r\n", sn, ret); +#endif + return ret; + } + size = (uint16_t) ret; + sentsize = 0; + while (sentsize != size) { +#if 1 + // 20231016 taylor//teddy 240122 +#if ((_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300)) + ret = sendto(sn, buf + sentsize, size - sentsize, destip, destport, 4); +#else + ret = sendto(sn, buf + sentsize, size - sentsize, destip, destport); +#endif +#else + ret = sendto(sn, buf + sentsize, size - sentsize, destip, destport); +#endif + if (ret < 0) { +#ifdef _MULTICAST_DEBUG_ + printf("%d: sendto error. %ld\r\n", sn, ret); +#endif + return ret; + } + sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero. + } + } + + break; + case SOCK_CLOSED: +#ifdef _MULTICAST_DEBUG_ + printf("%d:Multicast Loopback start\r\n", sn); +#endif + setSn_DIPR(0, multicast_ip); + setSn_DPORT(0, multicast_port); + if ((ret = socket(sn, Sn_MR_UDP, port, Sn_MR_MULTI)) != sn) { + return ret; + } +#ifdef _MULTICAST_DEBUG_ + printf("%d:Opened, UDP Multicast Socket\r\n", sn); + printf("%d:Multicast Group IP - %d.%d.%d.%d\r\n", sn, multicast_ip[0], multicast_ip[1], multicast_ip[2], multicast_ip[3]); + printf("%d:Multicast Group Port - %d\r\n", sn, multicast_port); +#endif + break; + default : + break; + } + return 1; +} + +int32_t multicast_recv(uint8_t sn, uint8_t* buf, uint8_t* multicast_ip, uint16_t multicast_port) { + int32_t ret; + uint16_t size, port = 3000; + uint8_t destip[4]; + uint16_t destport; +#if 1 + // 20231019 taylor + uint8_t addr_len; +#endif + + switch (getSn_SR(sn)) { + case SOCK_UDP : + if ((size = getSn_RX_RSR(sn)) > 0) { + if (size > DATA_BUF_SIZE) { + size = DATA_BUF_SIZE; + } +#if 1 + // 20231019 taylor//teddy 240122 +#if ((_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300)) + ret = recvfrom(sn, buf, size, destip, (uint16_t*)&destport, &addr_len); +#else + ret = recvfrom(sn, buf, size, destip, (uint16_t*)&destport); +#endif +#else + ret = recvfrom(sn, buf, size, destip, (uint16_t*)&destport); +#endif + if (ret <= 0) { +#ifdef _MULTICAST_DEBUG_ + printf("%d: recvfrom error. %ld\r\n", sn, ret); +#endif + return ret; + } + size = (uint16_t) ret; +#ifdef _MULTICAST_DEBUG_ + printf("\r\nrecv size : %d\r\n", size); + for (int i = 0; i < size; i++) { + printf("%c", buf[i]); + } + printf("\r\n"); +#endif + } + break; + case SOCK_CLOSED: +#ifdef _MULTICAST_DEBUG_ + printf("%d:Multicast Recv start\r\n", sn); +#endif + setSn_DIPR(sn, multicast_ip); + setSn_DPORT(sn, multicast_port); + if ((ret = socket(sn, Sn_MR_UDP, port, Sn_MR_MULTI)) != sn) { + return ret; + } +#ifdef _MULTICAST_DEBUG_ + printf("%d:Opened, UDP Multicast Socket\r\n", sn); + printf("%d:Multicast Group IP - %d.%d.%d.%d\r\n", sn, multicast_ip[0], multicast_ip[1], multicast_ip[2], multicast_ip[3]); + printf("%d:Multicast Group Port - %d\r\n", sn, multicast_port); +#endif + break; + default : + break; + } + return 1; +} diff --git a/Application/multicast/multicast.h b/Application/multicast/multicast.h new file mode 100644 index 0000000..ab4e9aa --- /dev/null +++ b/Application/multicast/multicast.h @@ -0,0 +1,28 @@ +#ifndef _MULTICAST_H_ +#define _MULTICAST_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/* Multicast test debug message printout enable */ +#define _MULTICAST_DEBUG_ + +#ifndef DATA_BUF_SIZE +#define DATA_BUF_SIZE 2048 +#endif + +/* UDP Multicast Loopback test example */ +int32_t multicast_loopback(uint8_t sn, uint8_t* buf, uint8_t* multicast_ip, uint16_t multicast_port); + +/* UDP Multicast Recv test example */ +int32_t multicast_recv(uint8_t sn, uint8_t* buf, uint8_t* multicast_ip, uint16_t multicast_port); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Ethernet/Socket_APIs_V3.0.3.chm b/Ethernet/Socket_APIs_V3.0.3.chm new file mode 100644 index 0000000..35ed512 Binary files /dev/null and b/Ethernet/Socket_APIs_V3.0.3.chm differ diff --git a/Ethernet/W5100/w5100.c b/Ethernet/W5100/w5100.c new file mode 100644 index 0000000..2863ed4 --- /dev/null +++ b/Ethernet/W5100/w5100.c @@ -0,0 +1,371 @@ +//***************************************************************************** +// +//! \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/Ethernet/W5100/w5100.h b/Ethernet/W5100/w5100.h new file mode 100644 index 0000000..898f557 --- /dev/null +++ b/Ethernet/W5100/w5100.h @@ -0,0 +1,1875 @@ +//* **************************************************************************** +//! \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); \ + } + +#define setSn_PORTR setSn_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); \ + } +#define setSn_DPORTR(sn, dport) setSn_DPORT(sn,dport) + +#define Sn_IMR(sn) (_W5100_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x002C)) +#define setSn_IMR(sn, imr) \ + WIZCHIP_WRITE(Sn_IMR(sn), (imr & 0x1F)) + +#define getSn_IMR(sn) \ + (WIZCHIP_READ(Sn_IMR(sn)) & 0x1F) + +/** + @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))) +#define getSn_DPORTR(sn) getSn_DPORT(sn) +/** + @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/Ethernet/W5100S/w5100s.c b/Ethernet/W5100S/w5100s.c new file mode 100644 index 0000000..6e65405 --- /dev/null +++ b/Ethernet/W5100S/w5100s.c @@ -0,0 +1,499 @@ +//***************************************************************************** +// +//! \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); +#if 1 + // 20231108 taylor + + uint8_t tAD[2]; + tAD[0] = (uint8_t)((AddrSel & 0x0000FF00) >> 8); + tAD[1] = (uint8_t)(AddrSel & 0x000000FF); + + WIZCHIP.IF.BUS._write_data_buf(IDM_AR0, tAD, 2, 1); + +#else + WIZCHIP.IF.BUS._write_data(IDM_AR0, (AddrSel & 0xFF00) >> 8); + WIZCHIP.IF.BUS._write_data(IDM_AR1, (AddrSel & 0x00FF)); +#endif + +#if 1 + // 20231108 taylor + WIZCHIP.IF.BUS._write_data_buf(IDM_DR, pBuf, len, 0); +#else + for (i = 0 ; i < len; i++) { + WIZCHIP.IF.BUS._write_data(IDM_DR, pBuf[i]); + } +#endif + 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); +#if 1 + // 20231108 taylor + + uint8_t tAD[2]; + tAD[0] = (uint8_t)((AddrSel & 0x0000FF00) >> 8); + tAD[1] = (uint8_t)(AddrSel & 0x000000FF); + + WIZCHIP.IF.BUS._write_data_buf(IDM_AR0, tAD, 2, 1); + +#else + WIZCHIP.IF.BUS._write_data(IDM_AR0, (AddrSel & 0xFF00) >> 8); + WIZCHIP.IF.BUS._write_data(IDM_AR1, (AddrSel & 0x00FF)); +#endif + +#if 1 + // 20231108 taylor + WIZCHIP.IF.BUS._read_data_buf(IDM_DR, pBuf, len, 0); +#else + for (i = 0 ; i < len; i++) { + pBuf[i] = WIZCHIP.IF.BUS._read_data(IDM_DR); + } +#endif + 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/Ethernet/W5100S/w5100s.h b/Ethernet/W5100S/w5100s.h new file mode 100644 index 0000000..3d0d296 --- /dev/null +++ b/Ethernet/W5100S/w5100s.h @@ -0,0 +1,3322 @@ +//* **************************************************************************** +//! \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); \ + } +#define setSn_PORTR setSn_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); \ + } +#define setSn_DPORTR(sn, dport) setSn_DPORT(sn,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))) +#define getSn_DPORTR(sn) getSn_DPORT(sn) +/** + @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/Ethernet/W5200/w5200.c b/Ethernet/W5200/w5200.c new file mode 100644 index 0000000..c487a1e --- /dev/null +++ b/Ethernet/W5200/w5200.c @@ -0,0 +1,338 @@ +//***************************************************************************** +// +//! \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/Ethernet/W5200/w5200.h b/Ethernet/W5200/w5200.h new file mode 100644 index 0000000..eedf1c9 --- /dev/null +++ b/Ethernet/W5200/w5200.h @@ -0,0 +1,2118 @@ +//* **************************************************************************** +//! \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); \ + } +#define setSn_PORTR setSn_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); \ + } +#define setSn_DPORTR setSn_DPORT + + +#define Sn_KPALVTR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0030)) +#define getSn_KPALVTR(sn) \ + WIZCHIP_READ(Sn_KPALVTR(sn)) +/** + /** + @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))) + +#define getSn_DPORTR(sn) getSn_DPORT(sn) +/** + @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/Ethernet/W5300/w5300.c b/Ethernet/W5300/w5300.c new file mode 100644 index 0000000..e57e019 --- /dev/null +++ b/Ethernet/W5300/w5300.c @@ -0,0 +1,229 @@ +//***************************************************************************** +// +//! \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/Ethernet/W5300/w5300.h b/Ethernet/W5300/w5300.h new file mode 100644 index 0000000..136aba0 --- /dev/null +++ b/Ethernet/W5300/w5300.h @@ -0,0 +1,2336 @@ +#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/Ethernet/W5500/w5500.c b/Ethernet/W5500/w5500.c new file mode 100644 index 0000000..8913610 --- /dev/null +++ b/Ethernet/W5500/w5500.c @@ -0,0 +1,248 @@ +//***************************************************************************** +// +//! \file w5500.c +//! \brief W5500 HAL Interface. +//! \version 1.0.2 +//! \date 2013/10/21 +//! \par Revision history +//! <2015/02/05> Notice +//! The version history is not updated after this point. +//! Download the latest version directly from GitHub. Please visit the our GitHub repository for ioLibrary. +//! >> https://github.com/Wiznet/ioLibrary_Driver +//! <2014/05/01> V1.0.2 +//! 1. Implicit type casting -> Explicit type casting. Refer to M20140501 +//! Fixed the problem on porting into under 32bit MCU +//! Issued by Mathias ClauBen, wizwiki forum ID Think01 and bobh +//! Thank for your interesting and serious advices. +//! <2013/12/20> V1.0.1 +//! 1. Remove warning +//! 2. WIZCHIP_READ_BUF WIZCHIP_WRITE_BUF in case _WIZCHIP_IO_MODE_SPI_FDM_ +//! for loop optimized(removed). refer to M20131220 +//! <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. +// +//***************************************************************************** +//#include +#include "w5500.h" + +#define _W5500_SPI_VDM_OP_ 0x00 +#define _W5500_SPI_FDM_OP_LEN1_ 0x01 +#define _W5500_SPI_FDM_OP_LEN2_ 0x02 +#define _W5500_SPI_FDM_OP_LEN4_ 0x03 + +#if (_WIZCHIP_ == 5500) +//////////////////////////////////////////////////// + +uint8_t WIZCHIP_READ(uint32_t AddrSel) { + uint8_t ret; + uint8_t spi_data[3]; + + WIZCHIP_CRITICAL_ENTER(); + WIZCHIP.CS._select(); + + AddrSel |= (_W5500_SPI_READ_ | _W5500_SPI_VDM_OP_); + + if (!WIZCHIP.IF.SPI._read_burst || !WIZCHIP.IF.SPI._write_burst) { // byte operation + WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16); + WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8); + WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0); + } else { // burst operation + spi_data[0] = (AddrSel & 0x00FF0000) >> 16; + spi_data[1] = (AddrSel & 0x0000FF00) >> 8; + spi_data[2] = (AddrSel & 0x000000FF) >> 0; + WIZCHIP.IF.SPI._write_burst(spi_data, 3); + } + ret = WIZCHIP.IF.SPI._read_byte(); + + WIZCHIP.CS._deselect(); + WIZCHIP_CRITICAL_EXIT(); + return ret; +} + +void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb) { + uint8_t spi_data[4]; + + WIZCHIP_CRITICAL_ENTER(); + WIZCHIP.CS._select(); + + AddrSel |= (_W5500_SPI_WRITE_ | _W5500_SPI_VDM_OP_); + + //if(!WIZCHIP.IF.SPI._read_burst || !WIZCHIP.IF.SPI._write_burst) // byte operation + if (!WIZCHIP.IF.SPI._write_burst) { // byte operation + WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16); + WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8); + WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0); + WIZCHIP.IF.SPI._write_byte(wb); + } else { // burst operation + spi_data[0] = (AddrSel & 0x00FF0000) >> 16; + spi_data[1] = (AddrSel & 0x0000FF00) >> 8; + spi_data[2] = (AddrSel & 0x000000FF) >> 0; + spi_data[3] = wb; + WIZCHIP.IF.SPI._write_burst(spi_data, 4); + } + + WIZCHIP.CS._deselect(); + WIZCHIP_CRITICAL_EXIT(); +} + +void WIZCHIP_READ_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len) { + uint8_t spi_data[3]; + uint16_t i; + + WIZCHIP_CRITICAL_ENTER(); + WIZCHIP.CS._select(); + + AddrSel |= (_W5500_SPI_READ_ | _W5500_SPI_VDM_OP_); + + if (!WIZCHIP.IF.SPI._read_burst || !WIZCHIP.IF.SPI._write_burst) { // byte operation + WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16); + WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8); + WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0); + for (i = 0; i < len; i++) { + pBuf[i] = WIZCHIP.IF.SPI._read_byte(); + } + } else { // burst operation + spi_data[0] = (AddrSel & 0x00FF0000) >> 16; + spi_data[1] = (AddrSel & 0x0000FF00) >> 8; + spi_data[2] = (AddrSel & 0x000000FF) >> 0; + WIZCHIP.IF.SPI._write_burst(spi_data, 3); + WIZCHIP.IF.SPI._read_burst(pBuf, len); + } + + WIZCHIP.CS._deselect(); + WIZCHIP_CRITICAL_EXIT(); +} + +void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len) { + uint8_t spi_data[3]; + uint16_t i; + + WIZCHIP_CRITICAL_ENTER(); + WIZCHIP.CS._select(); + + AddrSel |= (_W5500_SPI_WRITE_ | _W5500_SPI_VDM_OP_); + + if (!WIZCHIP.IF.SPI._write_burst) { // byte operation + WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16); + WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8); + WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0); + for (i = 0; i < len; i++) { + WIZCHIP.IF.SPI._write_byte(pBuf[i]); + } + } else { // burst operation + spi_data[0] = (AddrSel & 0x00FF0000) >> 16; + spi_data[1] = (AddrSel & 0x0000FF00) >> 8; + spi_data[2] = (AddrSel & 0x000000FF) >> 0; + WIZCHIP.IF.SPI._write_burst(spi_data, 3); + WIZCHIP.IF.SPI._write_burst(pBuf, len); + } + + WIZCHIP.CS._deselect(); + WIZCHIP_CRITICAL_EXIT(); +} + + +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; +} + +void wiz_send_data(uint8_t sn, uint8_t *wizdata, uint16_t len) { + uint16_t ptr = 0; + uint32_t addrsel = 0; + + if (len == 0) { + return; + } + ptr = getSn_TX_WR(sn); + //M20140501 : implict type casting -> explict type casting + //addrsel = (ptr << 8) + (WIZCHIP_TXBUF_BLOCK(sn) << 3); + addrsel = ((uint32_t)ptr << 8) + (WIZCHIP_TXBUF_BLOCK(sn) << 3); + // + WIZCHIP_WRITE_BUF(addrsel, wizdata, len); + + ptr += len; + setSn_TX_WR(sn, ptr); +} + +void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint16_t len) { + uint16_t ptr = 0; + uint32_t addrsel = 0; + + if (len == 0) { + return; + } + ptr = getSn_RX_RD(sn); + //M20140501 : implict type casting -> explict type casting + //addrsel = ((ptr << 8) + (WIZCHIP_RXBUF_BLOCK(sn) << 3); + addrsel = ((uint32_t)ptr << 8) + (WIZCHIP_RXBUF_BLOCK(sn) << 3); + // + WIZCHIP_READ_BUF(addrsel, wizdata, len); + ptr += len; + + setSn_RX_RD(sn, ptr); +} + + +void wiz_recv_ignore(uint8_t sn, uint16_t len) { + uint16_t ptr = 0; + + ptr = getSn_RX_RD(sn); + ptr += len; + setSn_RX_RD(sn, ptr); +} + +#endif diff --git a/Ethernet/W5500/w5500.h b/Ethernet/W5500/w5500.h new file mode 100644 index 0000000..d120dd6 --- /dev/null +++ b/Ethernet/W5500/w5500.h @@ -0,0 +1,2164 @@ +//***************************************************************************** +// +//! \file w5500.h +//! \brief W5500 HAL Header File. +//! \version 1.0.0 +//! \date 2013/10/21 +//! \par Revision history +//! <2015/02/05> Notice +//! The version history is not updated after this point. +//! Download the latest version directly from GitHub. Please visit the our GitHub repository for ioLibrary. +//! >> https://github.com/Wiznet/ioLibrary_Driver +//! <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 _W5500_H_ +#define _W5500_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "wizchip_conf.h" + +/// @cond DOXY_APPLY_CODE +#if (_WIZCHIP_ == 5500) +/// @endcond + +#define _W5500_IO_BASE_ 0x00000000 + +#define _W5500_SPI_READ_ (0x00 << 2) //< SPI interface Read operation in Control Phase +#define _W5500_SPI_WRITE_ (0x01 << 2) //< SPI interface Write operation in Control Phase + +#define WIZCHIP_CREG_BLOCK 0x00 //< Common register block +#define WIZCHIP_SREG_BLOCK(N) (1+4*N) //< Socket N register block +#define WIZCHIP_TXBUF_BLOCK(N) (2+4*N) //< Socket N Tx buffer address block +#define WIZCHIP_RXBUF_BLOCK(N) (3+4*N) //< Socket N Rx buffer address block + +#define WIZCHIP_OFFSET_INC(ADDR, N) (ADDR + (N<<8)) //< Increase offset address + + +/////////////////////////////////////// +// 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 W5500 W5500 + + @brief WHIZCHIP register defines and I/O functions of @b W5500. + + - @ref WIZCHIP_register : @ref Common_register_group and @ref Socket_register_group + - @ref WIZCHIP_IO_Functions : @ref Basic_IO_function, @ref Common_register_access_function and @ref Socket_register_access_function +*/ + + +/** + @defgroup WIZCHIP_register WIZCHIP register + @ingroup W5500 + + @brief WHIZCHIP register defines register group of @b W5500. + + - @ref Common_register_group : Common register group + - @ref Socket_register_group : \c SOCKET n register group +*/ + + +/** + @defgroup WIZCHIP_IO_Functions WIZCHIP I/O functions + @ingroup W5500 + + @brief This supports the basic I/O functions for @ref WIZCHIP_register. + + - Basic I/O function \n + WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF() \n\n + + - @ref Common_register_group access functions \n + -# @b Mode \n + getMR(), setMR() + -# @b Interrupt \n + getIR(), setIR(), getIMR(), setIMR(), getSIR(), setSIR(), getSIMR(), setSIMR(), 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(), getPSID(), setPSID(), getPHAR(), setPHAR(), getPMRU(), setPMRU() + -# ICMP packet \n + getUIPR(), getUPORTR() + -# @b etc. \n + getPHYCFGR(), setPHYCFGR(), getVERSIONR() \n\n + + - \ref Socket_register_group 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 Common register + @ingroup WIZCHIP_register + + @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, SIR, SIMR : Interrupt. + @sa _RTR_, _RCR_ : Data retransmission. + @sa PTIMER, PMAGIC, PHAR, PSID, PMRU : PPPoE. + @sa UIPR, UPORTR : ICMP message. + @sa PHYCFGR, VERSIONR : etc. +*/ + + + +/** + @defgroup Socket_register_group Socket register + @ingroup WIZCHIP_register + + @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_RXBUF_SIZE, Sn_TXBUF_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 Basic I/O function + @ingroup WIZCHIP_IO_Functions + @brief These are basic input/output functions to read values from register or write values to register. +*/ + +/** + @defgroup Common_register_access_function Common register access functions + @ingroup WIZCHIP_IO_Functions + @brief These are functions to access common registers. +*/ + +/** + @defgroup Socket_register_access_function Socket register access functions + @ingroup WIZCHIP_IO_Functions + @brief These are functions to access socket registers. +*/ + +//------------------------------- defgroup end -------------------------------------------- +//----------------------------- W5500 Common Registers IOMAP ----------------------------- +/** + @ingroup Common_register_group + @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 FARP Reserved
+ - \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 (_W5500_IO_BASE_ + (0x0000 << 8) + (WIZCHIP_CREG_BLOCK << 3)) + +/** + @ingroup Common_register_group + @brief Gateway IP Register address(R/W) + @details @ref GAR configures the default gateway address. +*/ +#define GAR (_W5500_IO_BASE_ + (0x0001 << 8) + (WIZCHIP_CREG_BLOCK << 3)) + +/** + @ingroup Common_register_group + @brief Subnet mask Register address(R/W) + @details @ref SUBR configures the subnet mask address. +*/ +#define SUBR (_W5500_IO_BASE_ + (0x0005 << 8) + (WIZCHIP_CREG_BLOCK << 3)) + +/** + @ingroup Common_register_group + @brief Source MAC Register address(R/W) + @details @ref SHAR configures the source hardware address. +*/ +#define SHAR (_W5500_IO_BASE_ + (0x0009 << 8) + (WIZCHIP_CREG_BLOCK << 3)) + +/** + @ingroup Common_register_group + @brief Source IP Register address(R/W) + @details @ref SIPR configures the source IP address. +*/ +#define SIPR (_W5500_IO_BASE_ + (0x000F << 8) + (WIZCHIP_CREG_BLOCK << 3)) + +/** + @ingroup Common_register_group + @brief Set Interrupt low level timer register address(R/W) + @details @ref INTLEVEL configures the Interrupt Assert Time. +*/ +#define INTLEVEL (_W5500_IO_BASE_ + (0x0013 << 8) + (WIZCHIP_CREG_BLOCK << 3)) + +/** + @ingroup Common_register_group + @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 MP Reserved Reserved Reserved Reserved
+ - \ref IR_CONFLICT : IP conflict + - \ref IR_UNREACH : Destination unreachable + - \ref IR_PPPoE : PPPoE connection close + - \ref IR_MP : Magic packet +*/ +#define IR (_W5500_IO_BASE_ + (0x0015 << 8) + (WIZCHIP_CREG_BLOCK << 3)) + +/** + @ingroup Common_register_group + @brief Interrupt mask register(R/W) + @details @ref _IMR_ is used to mask interrupts. 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 an interrupt will be issued. In other words, + if a bit of @ref _IMR_ is an interrupt will not be issued even if the corresponding bit of @ref IR is \n\n + Each bit of @ref _IMR_ defined as the following. + + + +
7 6 5 4 3 2 1 0
IM_IR7 IM_IR6 IM_IR5 IM_IR4 Reserved Reserved Reserved Reserved
+ - \ref IM_IR7 : IP Conflict Interrupt Mask + - \ref IM_IR6 : Destination unreachable Interrupt Mask + - \ref IM_IR5 : PPPoE Close Interrupt Mask + - \ref IM_IR4 : Magic Packet Interrupt Mask +*/ +//M20150401 : Rename SYMBOE ( Re-define error in a compile) +//#define IMR (_W5500_IO_BASE_ + (0x0016 << 8) + (WIZCHIP_CREG_BLOCK << 3)) +#define _IMR_ (_W5500_IO_BASE_ + (0x0016 << 8) + (WIZCHIP_CREG_BLOCK << 3)) + +/** + @ingroup Common_register_group + @brief Socket Interrupt Register(R/W) + @details @ref SIR indicates the interrupt status of Socket.\n + Each bit of @ref SIR 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 SIR is and INTn PIN is asserted until @ref SIR is x00 */ +#define SIR (_W5500_IO_BASE_ + (0x0017 << 8) + (WIZCHIP_CREG_BLOCK << 3)) + +/** + @ingroup Common_register_group + @brief Socket Interrupt Mask Register(R/W) + @details Each bit of @ref SIMR corresponds to each bit of @ref SIR. + When a bit of @ref SIMR is and the corresponding bit of @ref SIR is Interrupt will be issued. + In other words, if a bit of @ref SIMR is an interrupt will be not issued even if the corresponding bit of @ref SIR is +*/ +#define SIMR (_W5500_IO_BASE_ + (0x0018 << 8) + (WIZCHIP_CREG_BLOCK << 3)) + +/** + @ingroup Common_register_group + @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_, W5500 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, W5500 retransmits the packet or issues timeout. +*/ +//M20150401 : Rename SYMBOE ( Re-define error in a compile) +//#define RTR (_W5500_IO_BASE_ + (0x0019 << 8) + (WIZCHIP_CREG_BLOCK << 3)) +#define _RTR_ (_W5500_IO_BASE_ + (0x0019 << 8) + (WIZCHIP_CREG_BLOCK << 3)) + +/** + @ingroup Common_register_group + @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'). +*/ +//M20150401 : Rename SYMBOE ( Re-define error in a compile) +//#define RCR (_W5500_IO_BASE_ + (0x001B << 8) + (WIZCHIP_CREG_BLOCK << 3)) +#define _RCR_ (_W5500_IO_BASE_ + (0x001B << 8) + (WIZCHIP_CREG_BLOCK << 3)) + +/** + @ingroup Common_register_group + @brief PPP LCP Request Timer register in PPPoE mode(R/W) + @details @ref PTIMER configures the time for sending LCP echo request. The unit of time is 25ms. +*/ +#define PTIMER (_W5500_IO_BASE_ + (0x001C << 8) + (WIZCHIP_CREG_BLOCK << 3)) + +/** + @ingroup Common_register_group + @brief PPP LCP Magic number register in PPPoE mode(R/W) + @details @ref PMAGIC configures the 4bytes magic number to be used in LCP negotiation. +*/ +#define PMAGIC (_W5500_IO_BASE_ + (0x001D << 8) + (WIZCHIP_CREG_BLOCK << 3)) + +/** + @ingroup Common_register_group + @brief PPP Destination MAC Register address(R/W) + @details @ref PHAR configures the PPPoE server hardware address that is acquired during PPPoE connection process. +*/ +#define PHAR (_W5500_IO_BASE_ + (0x001E << 8) + (WIZCHIP_CREG_BLOCK << 3)) + +/** + @ingroup Common_register_group + @brief PPP Session Identification Register(R/W) + @details @ref PSID configures the PPPoE sever session ID acquired during PPPoE connection process. +*/ +#define PSID (_W5500_IO_BASE_ + (0x0024 << 8) + (WIZCHIP_CREG_BLOCK << 3)) + +/** + @ingroup Common_register_group + @brief PPP Maximum Segment Size(MSS) register(R/W) + @details @ref PMRU configures the maximum receive unit of PPPoE. +*/ +#define PMRU (_W5500_IO_BASE_ + (0x0026 << 8) + (WIZCHIP_CREG_BLOCK << 3)) + +/** + @ingroup Common_register_group + @brief Unreachable IP register address in UDP mode(R) + @details W5500 receives an ICMP packet(Destination port unreachable) when data is sent to a port number + which socket is not open and @ref IR_UNREACH bit of @ref IR becomes and @ref UIPR & @ref UPORTR indicates + the destination IP address & port number respectively. +*/ +#define UIPR (_W5500_IO_BASE_ + (0x0028 << 8) + (WIZCHIP_CREG_BLOCK << 3)) + +/** + @ingroup Common_register_group + @brief Unreachable Port register address in UDP mode(R) + @details W5500 receives an ICMP packet(Destination port unreachable) when data is sent to a port number + which socket is not open and @ref IR_UNREACH bit of @ref IR becomes and @ref UIPR & @ref UPORTR + indicates the destination IP address & port number respectively. +*/ +#define UPORTR (_W5500_IO_BASE_ + (0x002C << 8) + (WIZCHIP_CREG_BLOCK << 3)) + +/** + @ingroup Common_register_group + @brief PHY Status Register(R/W) + @details @ref PHYCFGR configures PHY operation mode and resets PHY. In addition, @ref PHYCFGR indicates the status of PHY such as duplex, Speed, Link. +*/ +#define PHYCFGR (_W5500_IO_BASE_ + (0x002E << 8) + (WIZCHIP_CREG_BLOCK << 3)) + +// Reserved (_W5500_IO_BASE_ + (0x002F << 8) + (WIZCHIP_CREG_BLOCK << 3)) +// Reserved (_W5500_IO_BASE_ + (0x0030 << 8) + (WIZCHIP_CREG_BLOCK << 3)) +// Reserved (_W5500_IO_BASE_ + (0x0031 << 8) + (WIZCHIP_CREG_BLOCK << 3)) +// Reserved (_W5500_IO_BASE_ + (0x0032 << 8) + (WIZCHIP_CREG_BLOCK << 3)) +// Reserved (_W5500_IO_BASE_ + (0x0033 << 8) + (WIZCHIP_CREG_BLOCK << 3)) +// Reserved (_W5500_IO_BASE_ + (0x0034 << 8) + (WIZCHIP_CREG_BLOCK << 3)) +// Reserved (_W5500_IO_BASE_ + (0x0035 << 8) + (WIZCHIP_CREG_BLOCK << 3)) +// Reserved (_W5500_IO_BASE_ + (0x0036 << 8) + (WIZCHIP_CREG_BLOCK << 3)) +// Reserved (_W5500_IO_BASE_ + (0x0037 << 8) + (WIZCHIP_CREG_BLOCK << 3)) +// Reserved (_W5500_IO_BASE_ + (0x0038 << 8) + (WIZCHIP_CREG_BLOCK << 3)) + +/** + @ingroup Common_register_group + @brief chip version register address(R) + @details @ref VERSIONR always indicates the W5500 version as @b 0x04. +*/ +#define VERSIONR (_W5500_IO_BASE_ + (0x0039 << 8) + (WIZCHIP_CREG_BLOCK << 3)) + + +//----------------------------- W5500 Socket Registers IOMAP ----------------------------- +/** + @ingroup Socket_register_group + @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/MFEN BCASTB ND/MC/MMB UCASTB/MIP6B Protocol[3] Protocol[2] Protocol[1] Protocol[0]
+ - @ref Sn_MR_MULTI : Support UDP Multicasting + - @ref Sn_MR_BCASTB : Broadcast block in UDP Multicasting + - @ref Sn_MR_ND : No Delayed Ack(TCP) flag + - @ref Sn_MR_MC : IGMP version used in UDP mulitcasting + - @ref Sn_MR_MMB : Multicast Blocking in @ref Sn_MR_MACRAW mode + - @ref Sn_MR_UCASTB : Unicast Block in UDP Multicating + - @ref Sn_MR_MIP6B : IPv6 packet Blocking in @ref Sn_MR_MACRAW mode + - 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
+ - @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(N) (_W5500_IO_BASE_ + (0x0000 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) + +/** + @ingroup Socket_register_group + @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. +*/ +#define Sn_CR(N) (_W5500_IO_BASE_ + (0x0001 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) + +/** + @ingroup Socket_register_group + @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
Reserved Reserved Reserved SEND_OK TIMEOUT RECV DISCON CON
+ - \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(N) (_W5500_IO_BASE_ + (0x0002 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) + +/** + @ingroup Socket_register_group + @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(N) (_W5500_IO_BASE_ + (0x0003 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) + +/** + @ingroup Socket_register_group + @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(N) (_W5500_IO_BASE_ + (0x0004 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) + +/** + @ingroup Socket_register_group + @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) (_W5500_IO_BASE_ + (0x0006 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) + +/** + @ingroup Socket_register_group + @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) (_W5500_IO_BASE_ + (0x000C << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) + +/** + @ingroup Socket_register_group + @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 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_DPORT(N) (_W5500_IO_BASE_ + (0x0010 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) + +/** + @ingroup Socket_register_group + @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) (_W5500_IO_BASE_ + (0x0012 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) + +// Reserved (_W5500_IO_BASE_ + (0x0014 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) + +/** + @ingroup Socket_register_group + @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(N) (_W5500_IO_BASE_ + (0x0015 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) +/** + @ingroup Socket_register_group + @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(N) (_W5500_IO_BASE_ + (0x0016 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) +// Reserved (_W5500_IO_BASE_ + (0x0017 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) +// Reserved (_W5500_IO_BASE_ + (0x0018 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) +// Reserved (_W5500_IO_BASE_ + (0x0019 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) +// Reserved (_W5500_IO_BASE_ + (0x001A << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) +// Reserved (_W5500_IO_BASE_ + (0x001B << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) +// Reserved (_W5500_IO_BASE_ + (0x001C << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) +// Reserved (_W5500_IO_BASE_ + (0x001D << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) + +/** + @ingroup Socket_register_group + @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,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_RXBUF_SIZE. The total sum of @ref Sn_RXBUF_SIZE can not be exceed 16Kbytes. + When exceeded, the data reception error is occurred. +*/ +#define Sn_RXBUF_SIZE(N) (_W5500_IO_BASE_ + (0x001E << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) + +/** + @ingroup Socket_register_group + @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,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_TXBUF_SIZE. The total sum of @ref Sn_TXBUF_SIZE can not be exceed 16Kbytes. + When exceeded, the data transmission error is occurred. +*/ +#define Sn_TXBUF_SIZE(N) (_W5500_IO_BASE_ + (0x001F << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) + +/** + @ingroup Socket_register_group + @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_TXBUF_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(N) (_W5500_IO_BASE_ + (0x0020 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) + +/** + @ingroup Socket_register_group + @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(N) (_W5500_IO_BASE_ + (0x0022 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) + +/** + @ingroup Socket_register_group + @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(N) (_W5500_IO_BASE_ + (0x0024 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) + +/** + @ingroup Socket_register_group + @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_RXBUF_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(N) (_W5500_IO_BASE_ + (0x0026 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) + +/** + @ingroup Socket_register_group + @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 W5500. +*/ +#define Sn_RX_RD(N) (_W5500_IO_BASE_ + (0x0028 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) + +/** + @ingroup Socket_register_group + @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(N) (_W5500_IO_BASE_ + (0x002A << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) + +/** + @ingroup Socket_register_group + @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) (_W5500_IO_BASE_ + (0x002C << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) + +/** + @ingroup Socket_register_group + @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(N) (_W5500_IO_BASE_ + (0x002D << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) + +/** + @ingroup Socket_register_group + @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) (_W5500_IO_BASE_ + (0x002F << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) + +//#define Sn_TSR(N) (_W5500_IO_BASE_ + (0x0030 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3)) + + +//----------------------------- W5500 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 + +/** + @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 W5500 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 + +/** + @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 + +/** + @brief Enable PPPoE + @details 0 : DisablePPPoE mode\n + 1 : EnablePPPoE mode\n + If you use ADSL, this bit should be +*/ +#define MR_PPPOE 0x08 + +/** + @brief Enable UDP_FORCE_ARP CHECHK + @details 0 : Disable Force ARP mode\n + 1 : Enable Force ARP mode\n + In Force ARP mode, It forces on sending ARP Request whenever data is sent. +*/ +#define MR_FARP 0x02 + +/* 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 + +/** + @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 + +/** + @brief Get the PPPoE close message. + @details When PPPoE is disconnected during PPPoE mode, this bit is set. +*/ +#define IR_PPPoE 0x20 + +/** + @brief Get the magic packet interrupt. + @details When WOL mode is enabled and receives the magic packet over UDP, this bit is set. +*/ +#define IR_MP 0x10 + + +/* PHYCFGR register value */ +#define PHYCFGR_RST ~(1<<7) //< For PHY reset, must operate AND mask. +#define PHYCFGR_OPMD (1<<6) // Configre PHY with OPMDC value +#define PHYCFGR_OPMDC_ALLA (7<<3) +#define PHYCFGR_OPMDC_PDOWN (6<<3) +#define PHYCFGR_OPMDC_NA (5<<3) +#define PHYCFGR_OPMDC_100FA (4<<3) +#define PHYCFGR_OPMDC_100F (3<<3) +#define PHYCFGR_OPMDC_100H (2<<3) +#define PHYCFGR_OPMDC_10F (1<<3) +#define PHYCFGR_OPMDC_10H (0<<3) +#define PHYCFGR_DPX_FULL (1<<2) +#define PHYCFGR_DPX_HALF (0<<2) +#define PHYCFGR_SPD_100 (1<<1) +#define PHYCFGR_SPD_10 (0<<1) +#define PHYCFGR_LNK_ON (1<<0) +#define PHYCFGR_LNK_OFF (0<<0) + +/* IMR register values */ +/** + @brief IP Conflict Interrupt Mask. + @details 0: Disable IP Conflict Interrupt\n + 1: Enable IP Conflict Interrupt +*/ +#define IM_IR7 0x80 + +/** + @brief Destination unreachable Interrupt Mask. + @details 0: Disable Destination unreachable Interrupt\n + 1: Enable Destination unreachable Interrupt +*/ +#define IM_IR6 0x40 + +/** + @brief PPPoE Close Interrupt Mask. + @details 0: Disable PPPoE Close Interrupt\n + 1: Enable PPPoE Close Interrupt +*/ +#define IM_IR5 0x20 + +/** + @brief Magic Packet Interrupt Mask. + @details 0: Disable Magic Packet Interrupt\n + 1: Enable Magic Packet Interrupt +*/ +#define IM_IR4 0x10 + +/* 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 + +/** + @brief Broadcast block in UDP Multicasting. + @details 0 : disable Broadcast Blocking\n + 1 : enable Broadcast Blocking\n + This bit blocks to receive broadcasting packet during UDP mode(P[3:0] = 010.\m + In addition, This bit does when MACRAW mode(P[3:0] = 100 +*/ +#define Sn_MR_BCASTB 0x40 + +/** + @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 + +/** + @brief Unicast Block in UDP Multicasting + @details 0 : disable Unicast Blocking\n + 1 : enable Unicast Blocking\n + This bit blocks receiving the unicast packet during UDP mode(P[3:0] = 010 and MULTI = +*/ +#define Sn_MR_UCASTB 0x10 + +/** + @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 + +#define Sn_MR_IPRAW 0x03 /**< IP LAYER RAW SOCK */ + +/** + @brief UDP + @details This configures the protocol mode of Socket n. +*/ +#define Sn_MR_UDP 0x02 + +/** + @brief TCP + @details This configures the protocol mode of Socket n. +*/ +#define Sn_MR_TCP 0x01 + +/** + @brief Unused socket + @details This configures the protocol mode of Socket n. +*/ +#define Sn_MR_CLOSE 0x00 + +/* Sn_MR values used with Sn_MR_MACRAW */ +/** + @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 W5500 can only receive broadcasting packet or packet sent to itself. + When this bit is W5500 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_MFEN Sn_MR_MULTI + +/** + @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 = + It configures the version for IGMP messages (Join/Leave/Report). +*/ +#define Sn_MR_MMB Sn_MR_ND + +/** + @brief IPv6 packet Blocking in @ref Sn_MR_MACRAW mode + @details 0 : disable IPv6 Blocking\n + 1 : enable IPv6 Blocking\n + This bit is applied only during MACRAW mode (P[3:0] = 100. It blocks to receiving the IPv6 packet. +*/ +#define Sn_MR_MIP6B Sn_MR_UCASTB + +/* Sn_MR value used with Sn_MR_UDP & Sn_MR_MULTI */ +/** + @brief IGMP version used in UDP mulitcasting + @details 0 : disable Multicast Blocking\n + 1 : enable Multicast Blocking\n + This bit is applied only when MACRAW mode(P[3:0] = 100. It blocks to receive the packet with multicast MAC address. +*/ +#define Sn_MR_MC Sn_MR_ND + +/* Sn_MR alternate values */ +/** + @brief For Berkeley Socket API +*/ +#define SOCK_STREAM Sn_MR_TCP + +/** + @brief For Berkeley Socket API +*/ +#define SOCK_DGRAM Sn_MR_UDP + + +/* 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_MACRAW (100) SOCK_MACRAW (0x02)
+*/ +#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] = ) 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, 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 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 + +/* Sn_IR values */ +/** + @brief SEND_OK Interrupt + @details This is issued when SEND command is completed. +*/ +#define Sn_IR_SENDOK 0x10 + +/** + @brief TIMEOUT Interrupt + @details This is issued when ARPTO or TCPTO occurs. +*/ +#define Sn_IR_TIMEOUT 0x08 + +/** + @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 + +/** + @brief Initiate state + @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 is ordered.\n + After @ref SOCK_INIT, user can use LISTEN /CONNECT 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 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 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(@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 + +#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] = 100and 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 + +//#define SOCK_PPPOE 0x5F + +/* 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(), 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 + @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 + @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 + @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 + @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 I/O function // +///////////////////////////////// +/** + @ingroup Common_register_access_function + @brief Set Mode Register + @param (uint8_t)mr The value to be set. + @sa getMR() +*/ +#define setMR(mr) \ + WIZCHIP_WRITE(MR,mr) + + +/** + @ingroup Common_register_access_function + @brief Get Mode Register + @return uint8_t. The value of Mode register. + @sa setMR() +*/ +#define getMR() \ + WIZCHIP_READ(MR) + +/** + @ingroup Common_register_access_function + @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_BUF(GAR,gar,4) + +/** + @ingroup Common_register_access_function + @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) \ + WIZCHIP_READ_BUF(GAR,gar,4) + +/** + @ingroup Common_register_access_function + @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_BUF(SUBR, subr,4) + + +/** + @ingroup Common_register_access_function + @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) \ + WIZCHIP_READ_BUF(SUBR, subr, 4) + +/** + @ingroup Common_register_access_function + @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_BUF(SHAR, shar, 6) + +/** + @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) \ + WIZCHIP_READ_BUF(SHAR, shar, 6) + +/** + @ingroup Common_register_access_function + @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_BUF(SIPR, sipr, 4) + +/** + @ingroup Common_register_access_function + @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) \ + WIZCHIP_READ_BUF(SIPR, sipr, 4) + +/** + @ingroup Common_register_access_function + @brief Set 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 + @brief Get INTLEVEL register + @return uint16_t. Value of @ref INTLEVEL register. + @sa setINTLEVEL() +*/ +//M20150401 : Type explict declaration +/* + #define getINTLEVEL() \ + ((WIZCHIP_READ(INTLEVEL) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(INTLEVEL,1))) +*/ +#define getINTLEVEL() \ + (((uint16_t)WIZCHIP_READ(INTLEVEL) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(INTLEVEL,1))) + +/** + @ingroup Common_register_access_function + @brief Set @ref IR register + @param (uint8_t)ir Value to set @ref IR register. + @sa getIR() +*/ +#define setIR(ir) \ + WIZCHIP_WRITE(IR, (ir & 0xF0)) + +/** + @ingroup Common_register_access_function + @brief Get @ref IR register + @return uint8_t. Value of @ref IR register. + @sa setIR() +*/ +#define getIR() \ + (WIZCHIP_READ(IR) & 0xF0) +/** + @ingroup Common_register_access_function + @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 + @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 + @brief Set @ref SIR register + @param (uint8_t)sir Value to set @ref SIR register. + @sa getSIR() +*/ +#define setSIR(sir) \ + WIZCHIP_WRITE(SIR, sir) + +/** + @ingroup Common_register_access_function + @brief Get @ref SIR register + @return uint8_t. Value of @ref SIR register. + @sa setSIR() +*/ +#define getSIR() \ + WIZCHIP_READ(SIR) +/** + @ingroup Common_register_access_function + @brief Set @ref SIMR register + @param (uint8_t)simr Value to set @ref SIMR register. + @sa getSIMR() +*/ +#define setSIMR(simr) \ + WIZCHIP_WRITE(SIMR, simr) + +/** + @ingroup Common_register_access_function + @brief Get @ref SIMR register + @return uint8_t. Value of @ref SIMR register. + @sa setSIMR() +*/ +#define getSIMR() \ + WIZCHIP_READ(SIMR) + +/** + @ingroup Common_register_access_function + @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 + @brief Get @ref _RTR_ register + @return uint16_t. Value of @ref _RTR_ register. + @sa setRTR() +*/ +//M20150401 : Type explict declaration +/* + #define getRTR() \ + ((WIZCHIP_READ(_RTR_) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_RTR_,1))) +*/ +#define getRTR() \ + (((uint16_t)WIZCHIP_READ(_RTR_) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_RTR_,1))) + + +/** + @ingroup Common_register_access_function + @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 + @brief Get @ref _RCR_ register + @return uint8_t. Value of @ref _RCR_ register. + @sa setRCR() +*/ +#define getRCR() \ + WIZCHIP_READ(_RCR_) + +//================================================== test done =========================================================== + +/** + @ingroup Common_register_access_function + @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 + @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 + @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 + @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 + @brief Set @ref PHAR address + @param (uint8_t*)phar Pointer variable to set PPP destination MAC register address. It should be allocated 6 bytes. + @sa getPHAR() +*/ +#define setPHAR(phar) \ + WIZCHIP_WRITE_BUF(PHAR, phar, 6) + +/** + @ingroup Common_register_access_function + @brief Get @ref PHAR address + @param (uint8_t*)phar Pointer variable to PPP destination MAC register address. It should be allocated 6 bytes. + @sa setPHAR() +*/ +#define getPHAR(phar) \ + WIZCHIP_READ_BUF(PHAR, phar, 6) + +/** + @ingroup Common_register_access_function + @brief Set @ref PSID register + @param (uint16_t)psid Value to set @ref PSID register. + @sa getPSID() +*/ +#define setPSID(psid) {\ + WIZCHIP_WRITE(PSID, (uint8_t)(psid >> 8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(PSID,1), (uint8_t) psid); \ + } + +/** + @ingroup Common_register_access_function + @brief Get @ref PSID register + @return uint16_t. Value of @ref PSID register. + @sa setPSID() +*/ +//uint16_t getPSID(void); +//M20150401 : Type explict declaration +/* + #define getPSID() \ + ((WIZCHIP_READ(PSID) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(PSID,1))) +*/ +#define getPSID() \ + (((uint16_t)WIZCHIP_READ(PSID) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(PSID,1))) + +/** + @ingroup Common_register_access_function + @brief Set @ref PMRU register + @param (uint16_t)pmru Value to set @ref PMRU register. + @sa getPMRU() +*/ +#define setPMRU(pmru) { \ + WIZCHIP_WRITE(PMRU, (uint8_t)(pmru>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(PMRU,1), (uint8_t) pmru); \ + } + +/** + @ingroup Common_register_access_function + @brief Get @ref PMRU register + @return uint16_t. Value of @ref PMRU register. + @sa setPMRU() +*/ +//M20150401 : Type explict declaration +/* + #define getPMRU() \ + ((WIZCHIP_READ(PMRU) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(PMRU,1))) +*/ +#define getPMRU() \ + (((uint16_t)WIZCHIP_READ(PMRU) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(PMRU,1))) + +/** + @ingroup Common_register_access_function + @brief Get unreachable IP address + @param (uint8_t*)uipr Pointer variable to get unreachable IP address. It should be allocated 4 bytes. +*/ +//M20150401 : Size Error of UIPR (6 -> 4) +/* + #define getUIPR(uipr) \ + WIZCHIP_READ_BUF(UIPR,uipr,6) +*/ +#define getUIPR(uipr) \ + WIZCHIP_READ_BUF(UIPR,uipr,4) + +/** + @ingroup Common_register_access_function + @brief Get @ref UPORTR register + @return uint16_t. Value of @ref UPORTR register. +*/ +//M20150401 : Type explict declaration +/* + #define getUPORTR() \ + ((WIZCHIP_READ(UPORTR) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(UPORTR,1))) +*/ +#define getUPORTR() \ + (((uint16_t)WIZCHIP_READ(UPORTR) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(UPORTR,1))) + +/** + @ingroup Common_register_access_function + @brief Set @ref PHYCFGR register + @param (uint8_t)phycfgr Value to set @ref PHYCFGR register. + @sa getPHYCFGR() +*/ +#define setPHYCFGR(phycfgr) \ + WIZCHIP_WRITE(PHYCFGR, phycfgr) + +/** + @ingroup Common_register_access_function + @brief Get @ref PHYCFGR register + @return uint8_t. Value of @ref PHYCFGR register. + @sa setPHYCFGR() +*/ +#define getPHYCFGR() \ + WIZCHIP_READ(PHYCFGR) + +/** + @ingroup Common_register_access_function + @brief Get @ref VERSIONR register + @return uint8_t. Value of @ref VERSIONR register. +*/ +#define getVERSIONR() \ + WIZCHIP_READ(VERSIONR) + +///////////////////////////////////// + +/////////////////////////////////// +// Socket N register I/O function // +/////////////////////////////////// +/** + @ingroup Socket_register_access_function + @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 + @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 + @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), cr) + +/** + @ingroup Socket_register_access_function + @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) \ + WIZCHIP_READ(Sn_CR(sn)) + +/** + @ingroup Socket_register_access_function + @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), (ir & 0x1F)) + +/** + @ingroup Socket_register_access_function + @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) \ + (WIZCHIP_READ(Sn_IR(sn)) & 0x1F) + +/** + @ingroup Socket_register_access_function + @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), (imr & 0x1F)) + +/** + @ingroup Socket_register_access_function + @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) \ + (WIZCHIP_READ(Sn_IMR(sn)) & 0x1F) + +/** + @ingroup Socket_register_access_function + @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_SR(sn) \ + WIZCHIP_READ(Sn_SR(sn)) + +/** + @ingroup Socket_register_access_function + @brief Set @ref Sn_PORT register + @param (uint8_t)sn Socket number. It should be 0 ~ 7. + @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); \ + } +#define setSn_PORTR setSn_PORT +/** + @ingroup Socket_register_access_function + @brief Get @ref Sn_PORT register + @param (uint8_t)sn Socket number. It should be 0 ~ 7. + @return uint16_t. Value of @ref Sn_PORT. + @sa setSn_PORT() +*/ +//M20150401 : Type explict declaration +/* + #define getSn_PORT(sn) \ + ((WIZCHIP_READ(Sn_PORT(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_PORT(sn),1))) +*/ +#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 + @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_BUF(Sn_DHAR(sn), dhar, 6) + +/** + @ingroup Socket_register_access_function + @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) \ + WIZCHIP_READ_BUF(Sn_DHAR(sn), dhar, 6) + +/** + @ingroup Socket_register_access_function + @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_BUF(Sn_DIPR(sn), dipr, 4) + +/** + @ingroup Socket_register_access_function + @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) \ + WIZCHIP_READ_BUF(Sn_DIPR(sn), dipr, 4) + +/** + @ingroup Socket_register_access_function + @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_DPORT(sn, dport) { \ + WIZCHIP_WRITE(Sn_DPORT(sn), (uint8_t) (dport>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_DPORT(sn),1), (uint8_t) dport); \ + } +#define setSn_DPORTR(sn, dport) setSn_DPORT(sn,dport) ///< For compatible ioLibrary. Refer to @ref Sn_DPORTR. + +/** + @ingroup Socket_register_access_function + @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() +*/ +//M20150401 : Type explict declaration +/* + #define getSn_DPORT(sn) \ + ((WIZCHIP_READ(Sn_DPORT(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_DPORT(sn),1))) +*/ +#define getSn_DPORT(sn) \ + (((uint16_t)WIZCHIP_READ(Sn_DPORT(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_DPORT(sn),1))) +#define getSn_DPORTR(sn) getSn_DPORT(sn) +/** + @ingroup Socket_register_access_function + @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), (uint8_t)(mss>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_MSSR(sn),1), (uint8_t) mss); \ + } + +/** + @ingroup Socket_register_access_function + @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() +*/ +//M20150401 : Type explict declaration +/* + #define getSn_MSSR(sn) \ + ((WIZCHIP_READ(Sn_MSSR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_MSSR(sn),1))) +*/ +#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 + @brief Set @ref Sn_TOS register + @param (uint8_t)sn Socket number. It should be 0 ~ 7. + @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 + @brief Get @ref Sn_TOS register + @param (uint8_t)sn Socket number. It should be 0 ~ 7. + @return uint8_t. Value of Sn_TOS. + @sa setSn_TOS() +*/ +#define getSn_TOS(sn) \ + WIZCHIP_READ(Sn_TOS(sn)) + +/** + @ingroup Socket_register_access_function + @brief Set @ref Sn_TTL register + @param (uint8_t)sn Socket number. It should be 0 ~ 7. + @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 + @brief Get @ref Sn_TTL register + @param (uint8_t)sn Socket number. It should be 0 ~ 7. + @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 + @brief Set @ref Sn_RXBUF_SIZE register + @param (uint8_t)sn Socket number. It should be 0 ~ 7. + @param (uint8_t)rxbufsize Value to set @ref Sn_RXBUF_SIZE + @sa getSn_RXBUF_SIZE() +*/ +#define setSn_RXBUF_SIZE(sn, rxbufsize) \ + WIZCHIP_WRITE(Sn_RXBUF_SIZE(sn),rxbufsize) + + +/** + @ingroup Socket_register_access_function + @brief Get @ref Sn_RXBUF_SIZE register + @param (uint8_t)sn Socket number. It should be 0 ~ 7. + @return uint8_t. Value of @ref Sn_RXBUF_SIZE. + @sa setSn_RXBUF_SIZE() +*/ +#define getSn_RXBUF_SIZE(sn) \ + WIZCHIP_READ(Sn_RXBUF_SIZE(sn)) + +/** + @ingroup Socket_register_access_function + @brief Set @ref Sn_TXBUF_SIZE register + @param (uint8_t)sn Socket number. It should be 0 ~ 7. + @param (uint8_t)txbufsize Value to set @ref Sn_TXBUF_SIZE + @sa getSn_TXBUF_SIZE() +*/ +#define setSn_TXBUF_SIZE(sn, txbufsize) \ + WIZCHIP_WRITE(Sn_TXBUF_SIZE(sn), txbufsize) + +/** + @ingroup Socket_register_access_function + @brief Get @ref Sn_TXBUF_SIZE register + @param (uint8_t)sn Socket number. It should be 0 ~ 7. + @return uint8_t. Value of @ref Sn_TXBUF_SIZE. + @sa setSn_TXBUF_SIZE() +*/ +#define getSn_TXBUF_SIZE(sn) \ + WIZCHIP_READ(Sn_TXBUF_SIZE(sn)) + +/** + @ingroup Socket_register_access_function + @brief Get @ref Sn_TX_FSR register + @param (uint8_t)sn Socket number. It should be 0 ~ 7. + @return uint16_t. Value of @ref Sn_TX_FSR. +*/ +uint16_t getSn_TX_FSR(uint8_t sn); + +/** + @ingroup Socket_register_access_function + @brief Get @ref Sn_TX_RD register + @param (uint8_t)sn Socket number. It should be 0 ~ 7. + @return uint16_t. Value of @ref Sn_TX_RD. +*/ +//M20150401 : Type explict declaration +/* + #define getSn_TX_RD(sn) \ + ((WIZCHIP_READ(Sn_TX_RD(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_RD(sn),1))) +*/ +#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 + @brief Set @ref Sn_TX_WR register + @param (uint8_t)sn Socket number. It should be 0 ~ 7. + @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 + @brief Get @ref Sn_TX_WR register + @param (uint8_t)sn Socket number. It should be 0 ~ 7. + @return uint16_t. Value of @ref Sn_TX_WR. + @sa setSn_TX_WR() +*/ +//M20150401 : Type explict declaration +/* + #define getSn_TX_WR(sn) \ + ((WIZCHIP_READ(Sn_TX_WR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_WR(sn),1))) +*/ +#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 + @brief Get @ref Sn_RX_RSR register + @param (uint8_t)sn Socket number. It should be 0 ~ 7. + @return uint16_t. Value of @ref Sn_RX_RSR. +*/ +uint16_t getSn_RX_RSR(uint8_t sn); + + +/** + @ingroup Socket_register_access_function + @brief Set @ref Sn_RX_RD register + @param (uint8_t)sn Socket number. It should be 0 ~ 7. + @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 + @brief Get @ref Sn_RX_RD register + @param (uint8_t)sn Socket number. It should be 0 ~ 7. + @return uint16_t. Value of @ref Sn_RX_RD. + @sa setSn_RX_RD() +*/ +//M20150401 : Type explict declaration +/* + #define getSn_RX_RD(sn) \ + ((WIZCHIP_READ(Sn_RX_RD(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RD(sn),1))) +*/ +#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 + @brief Get @ref Sn_RX_WR register + @param (uint8_t)sn Socket number. It should be 0 ~ 7. + @return uint16_t. Value of @ref Sn_RX_WR. +*/ +//M20150401 : Type explict declaration +/* + #define getSn_RX_WR(sn) \ + ((WIZCHIP_READ(Sn_RX_WR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_WR(sn),1))) +*/ +#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 + @brief Set @ref Sn_FRAG register + @param (uint8_t)sn Socket number. It should be 0 ~ 7. + @param (uint16_t)frag Value to set @ref Sn_FRAG + @sa getSn_FRAD() +*/ +#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 + @brief Get @ref Sn_FRAG register + @param (uint8_t)sn Socket number. It should be 0 ~ 7. + @return uint16_t. Value of @ref Sn_FRAG. + @sa setSn_FRAG() +*/ +//M20150401 : Type explict declaration +/* + #define getSn_FRAG(sn) \ + ((WIZCHIP_READ(Sn_FRAG(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_FRAG(sn),1))) +*/ +#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 + @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), kpalvt) + +/** + @ingroup Socket_register_access_function + @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) \ + WIZCHIP_READ(Sn_KPALVTR(sn)) + +////////////////////////////////////// + +///////////////////////////////////// +// Sn_TXBUF & Sn_RXBUF IO function // +///////////////////////////////////// +/** + @brief Socket_register_access_function + @brief Gets the max buffer size of socket sn passed as parameter. + @param (uint8_t)sn Socket number. It should be 0 ~ 7. + @return uint16_t. Value of Socket n RX max buffer size. +*/ +//M20150401 : Type explict declaration +/* + #define getSn_RxMAX(sn) \ + (getSn_RXBUF_SIZE(sn) << 10) +*/ +#define getSn_RxMAX(sn) \ + (((uint16_t)getSn_RXBUF_SIZE(sn)) << 10) + +/** + @brief Socket_register_access_function + @brief Gets the max buffer size of socket sn passed as parameters. + @param (uint8_t)sn Socket number. It should be 0 ~ 7. + @return uint16_t. Value of Socket n TX max buffer size. +*/ +//M20150401 : Type explict declaration +/* + #define getSn_TxMAX(sn) \ + (getSn_TXBUF_SIZE(sn) << 10) +*/ +#define getSn_TxMAX(sn) \ + (((uint16_t)getSn_TXBUF_SIZE(sn)) << 10) + +/** + @ingroup Basic_IO_function + @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, uint16_t len); + +/** + @ingroup Basic_IO_function + @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, uint16_t len); + +/** + @ingroup Basic_IO_function + @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, uint16_t len); + +/// @cond DOXY_APPLY_CODE +#endif +/// @endcond + +#ifdef __cplusplus +} +#endif + +#endif // _W5500_H_ diff --git a/Ethernet/W6100/w6100.c b/Ethernet/W6100/w6100.c new file mode 100644 index 0000000..4cc19e2 --- /dev/null +++ b/Ethernet/W6100/w6100.c @@ -0,0 +1,272 @@ +//***************************************************************************** +// +//! \file w6100.c +//! \brief W6100 HAL Implements file. +//! \version 1.0.0 +//! \date 2019/01/01 +//! \par Revision history +//! <2019/01/01> 1st Release +//! \author MidnightCow +//! \copyright +//! +//! Copyright (c) 2019, WIZnet Co., LTD. +//! +//! Permission is hereby granted, free of charge, to any person obtaining a copy +//! of this software and associated documentation files (the "Software"), to deal +//! in the Software without restriction, including without limitation the rights +//! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +//! copies of the Software, and to permit persons to whom the Software is +//! furnished to do so, subject to the following conditions: +//! +//! The above copyright notice and this permission notice shall be included in +//! all copies or substantial portions of the Software. +//! +//! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +//! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +//! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +//! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +//! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +//! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +//! SOFTWARE. +//! +//***************************************************************************** + +#include "w6100.h" + + + +#define _WIZCHIP_SPI_VDM_OP_ 0x00 +#define _WIZCHIP_SPI_FDM_LEN1_ 0x01 +#define _WIZCHIP_SPI_FDM_LEN2_ 0x02 +#define _WIZCHIP_SPI_FDM_LEN4_ 0x03 +// +// If you want to use SPI FDM mode, Feel free contact to WIZnet. +// http://forum.wiznet.io +// + +#if _WIZCHIP_ == 6100 +//////////////////////////////////////////////////////////////////////////////////////// + + +#define _W6100_SPI_OP_ _WIZCHIP_SPI_VDM_OP_ + +////////////////////////////////////////////////// +void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb) { + uint8_t tAD[4]; + tAD[0] = (uint8_t)((AddrSel & 0x00FF0000) >> 16); + tAD[1] = (uint8_t)((AddrSel & 0x0000FF00) >> 8); + tAD[2] = (uint8_t)(AddrSel & 0x000000ff); + tAD[3] = wb; + + WIZCHIP_CRITICAL_ENTER(); + WIZCHIP.CS._select(); + +#if( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_VDM_)) + tAD[2] |= (_W6100_SPI_WRITE_ | _W6100_SPI_OP_); + if (!WIZCHIP.IF.SPI._write_burst) { // byte operation + WIZCHIP.IF.SPI._write_byte(tAD[0]); + WIZCHIP.IF.SPI._write_byte(tAD[1]); + WIZCHIP.IF.SPI._write_byte(tAD[2]); + WIZCHIP.IF.SPI._write_byte(tAD[3]); + } else { + WIZCHIP.IF.SPI._write_burst(tAD, 4); + } +#elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) ) +#if 1 + // 20231103 taylor + WIZCHIP.IF.BUS._write_data_buf(IDM_AR0, tAD, 4, 1); +#else + WIZCHIP.IF.BUS._write_data(IDM_AR0, tAD, 4, 1); +#endif +#else +#error "Unknown _WIZCHIP_IO_MODE_ in W6100. !!!" +#endif + + WIZCHIP.CS._deselect(); + WIZCHIP_CRITICAL_EXIT(); +} + +uint8_t WIZCHIP_READ(uint32_t AddrSel) { + uint8_t ret; + uint8_t tAD[3]; + tAD[0] = (uint8_t)((AddrSel & 0x00FF0000) >> 16); + tAD[1] = (uint8_t)((AddrSel & 0x0000FF00) >> 8); + tAD[2] = (uint8_t)(AddrSel & 0x000000ff); + + WIZCHIP_CRITICAL_ENTER(); + WIZCHIP.CS._select(); + +#if( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_VDM_)) + tAD[2] |= (_W6100_SPI_READ_ | _W6100_SPI_OP_); + if (!WIZCHIP.IF.SPI._read_burst || !WIZCHIP.IF.SPI._write_burst) { // byte operation + WIZCHIP.IF.SPI._write_byte(tAD[0]); + WIZCHIP.IF.SPI._write_byte(tAD[1]); + WIZCHIP.IF.SPI._write_byte(tAD[2]); + } else { + WIZCHIP.IF.SPI._write_burst(tAD, 3); + } + ret = WIZCHIP.IF.SPI._read_byte(); +#elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) ) + WIZCHIP.IF.BUS._write_data_buf(IDM_AR0, tAD, 3, 1); + ret = WIZCHIP.IF.BUS._read_data(IDM_DR); +#else +#error "Unknown _WIZCHIP_IO_MODE_ in W6100. !!!" +#endif + + WIZCHIP.CS._deselect(); + WIZCHIP_CRITICAL_EXIT(); + return ret; +} + +void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len) { + uint8_t tAD[3]; + uint16_t i = 0; + + tAD[0] = (uint8_t)((AddrSel & 0x00FF0000) >> 16); + tAD[1] = (uint8_t)((AddrSel & 0x0000FF00) >> 8); + tAD[2] = (uint8_t)(AddrSel & 0x000000ff); + + WIZCHIP_CRITICAL_ENTER(); + WIZCHIP.CS._select(); + +#if((_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_VDM_)) + tAD[2] |= (_W6100_SPI_WRITE_ | _W6100_SPI_OP_); + if (!WIZCHIP.IF.SPI._write_burst) { // byte operation + WIZCHIP.IF.SPI._write_byte(tAD[0]); + WIZCHIP.IF.SPI._write_byte(tAD[1]); + WIZCHIP.IF.SPI._write_byte(tAD[2]); + for (i = 0; i < len; i++) { + WIZCHIP.IF.SPI._write_byte(pBuf[i]); + } + } else { + WIZCHIP.IF.SPI._write_burst(tAD, 3); + WIZCHIP.IF.SPI._write_burst(pBuf, len); + } +#elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) ) + WIZCHIP.IF.BUS._write_data_buf(IDM_AR0, tAD, 3, 1); + WIZCHIP.IF.BUS._write_data_buf(IDM_DR, pBuf, len, 0); +#else +#error "Unknown _WIZCHIP_IO_MODE_ in W6100. !!!!" +#endif + + WIZCHIP.CS._deselect(); + WIZCHIP_CRITICAL_EXIT(); +} + +void WIZCHIP_READ_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len) { + uint8_t tAD[3]; + uint16_t i; + tAD[0] = (uint8_t)((AddrSel & 0x00FF0000) >> 16); + tAD[1] = (uint8_t)((AddrSel & 0x0000FF00) >> 8); + tAD[2] = (uint8_t)(AddrSel & 0x000000ff); + + WIZCHIP_CRITICAL_ENTER(); + WIZCHIP.CS._select(); + +#if((_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_VDM_)) + tAD[2] |= (_W6100_SPI_READ_ | _W6100_SPI_OP_); + if (!WIZCHIP.IF.SPI._read_burst || !WIZCHIP.IF.SPI._write_burst) { // byte operation + WIZCHIP.IF.SPI._write_byte(tAD[0]); + WIZCHIP.IF.SPI._write_byte(tAD[1]); + WIZCHIP.IF.SPI._write_byte(tAD[2]); + for (i = 0; i < len; len++) { + pBuf[i] = WIZCHIP.IF.SPI._read_byte(); + } + } else { + WIZCHIP.IF.SPI._write_burst(tAD, 3); + WIZCHIP.IF.SPI._read_burst(pBuf, len); + } + +#elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) ) + WIZCHIP.IF.BUS._write_data_buf(IDM_AR0, tAD, 3, 1); + WIZCHIP.IF.BUS._read_data_buf(IDM_DR, pBuf, len, 0); +#else +#error "Unknown _WIZCHIP_IO_MODE_ in W6100. !!!!" +#endif + WIZCHIP.CS._deselect(); + WIZCHIP_CRITICAL_EXIT(); +} + +uint16_t getSn_TX_FSR(uint8_t sn) { + uint16_t prev_val = -1, val = 0; + do { + prev_val = val; + val = WIZCHIP_READ(_Sn_TX_FSR_(sn)); + val = (val << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_Sn_TX_FSR_(sn), 1)); + } while (val != prev_val); + return val; +} + +uint16_t getSn_RX_RSR(uint8_t sn) { + uint16_t prev_val = -1, val = 0; + do { + prev_val = val; + val = WIZCHIP_READ(_Sn_RX_RSR_(sn)); + val = (val << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_Sn_RX_RSR_(sn), 1)); + } while (val != prev_val); + return val; +} + +void wiz_send_data(uint8_t sn, uint8_t *wizdata, uint16_t len) { + uint16_t ptr = 0; + uint32_t addrsel = 0; + ptr = getSn_TX_WR(sn); + addrsel = ((uint32_t)ptr << 8) + WIZCHIP_TXBUF_BLOCK(sn); + WIZCHIP_WRITE_BUF(addrsel, wizdata, len); + ptr += len; + setSn_TX_WR(sn, ptr); +} + +void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint16_t len) { + uint16_t ptr = 0; + uint32_t addrsel = 0; + if (len == 0) { + return; + } + ptr = getSn_RX_RD(sn); + addrsel = ((uint32_t)ptr << 8) + WIZCHIP_RXBUF_BLOCK(sn); + WIZCHIP_READ_BUF(addrsel, wizdata, len); + ptr += len; + setSn_RX_RD(sn, ptr); +} + +void wiz_recv_ignore(uint8_t sn, uint16_t len) { + setSn_RX_RD(sn, getSn_RX_RD(sn) + len); +} + +#if 1 +// 20231019 taylor +void wiz_delay_ms(uint32_t milliseconds) { + uint32_t i; + for (i = 0 ; i < milliseconds ; i++) { + //Write any values to clear the TCNTCLKR register + setTCNTRCLR(0xff); + + // Wait until counter register value reaches 10.(10 = 1ms : TCNTR is 100us tick counter register) + while (getTCNTR() < 0x0a) {} + } +} +#endif + +/// @cond DOXY_APPLY_CODE +#if (_PHY_IO_MODE_ == _PHY_IO_MODE_MII_) +/// @endcond +void wiz_mdio_write(uint8_t phyregaddr, uint16_t var) { + setPHYRAR(phyregaddr); + setPHYDIR(var); + setPHYACR(PHYACR_WRITE); + while (getPHYACR()); //wait for command complete +} + +uint16_t wiz_mdio_read(uint8_t phyregaddr) { + setPHYRAR(phyregaddr); + setPHYACR(PHYACR_READ); + while (getPHYACR()); //wait for command complete + return getPHYDOR(); +} +/// @cond DOXY_APPLY_CODE +#endif +/// @endcond + +//////////////////////////////////////////////////////////////////////////////////////// +#endif diff --git a/Ethernet/W6100/w6100.h b/Ethernet/W6100/w6100.h new file mode 100644 index 0000000..16ea8c9 --- /dev/null +++ b/Ethernet/W6100/w6100.h @@ -0,0 +1,4086 @@ +//* **************************************************************************** +//! \file w6100.h +//! \brief W6100 HAL Header File. +//! \version 1.0.0 +//! \date 2019/01/01 +//! \par Revision history +//! <2019/01/01> 1st Release +//! \author MidnightCow +//! \copyright +//! +//! Copyright (c) 2019, WIZnet Co., LTD. +//! +//! Permission is hereby granted, free of charge, to any person obtaining a copy +//! of this software and associated documentation files (the "Software"), to deal +//! in the Software without restriction, including without limitation the rights +//! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +//! copies of the Software, and to permit persons to whom the Software is +//! furnished to do so, subject to the following conditions: +//! +//! The above copyright notice and this permission notice shall be included in +//! all copies or substantial portions of the Software. +//! +//! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +//! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +//! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +//! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +//! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +//! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +//! SOFTWARE. +//! +//***************************************************************************** + + +#ifndef _W6100_H_ +#define _W6100_H_ + +#include +#include "wizchip_conf.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +/// @cond DOXY_APPLY_CODE +#if (_WIZCHIP_ == W6100) +/// @endcond + +#define _W6100_SPI_READ_ (0x00 << 2) ///< SPI interface Read operation in Control Phase +#define _W6100_SPI_WRITE_ (0x01 << 2) ///< SPI interface Write operation in Control Phase + +#define WIZCHIP_CREG_BLOCK (0x00 <<3) ///< Common register block +#define WIZCHIP_SREG_BLOCK(N) ((1+4*N)<<3) ///< SOCKETn register block +#define WIZCHIP_TXBUF_BLOCK(N) ((2+4*N)<<3) ///< SOCKETn Tx buffer address block +#define WIZCHIP_RXBUF_BLOCK(N) ((3+4*N)<<3) ///< SOCKETn Rx buffer address block + +#define WIZCHIP_OFFSET_INC(ADDR, N) (ADDR + (N<<8)) ///< Increase offset address + +#if (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) +#define IDM_AR0 ((_WIZCHIP_IO_BASE_ + 0x0000)) ///< Indirect High Address Register +#define IDM_AR1 ((_WIZCHIP_IO_BASE_ + 0x0001)) ///< Indirect Low Address Register +#define IDM_BSR ((_WIZCHIP_IO_BASE_ + 0x0002)) ///< Block Select Register +#define IDM_DR ((_WIZCHIP_IO_BASE_ + 0x0003)) ///< Indirect Data Register +#define _W6100_IO_BASE_ _WIZCHIP_IO_BASE_ +#elif (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_) +#define _W6100_IO_BASE_ 0x00000000 +#endif + + +//----------- defgroup -------------------------------- + +/** + @defgroup W6100 W6100 + @brief @ref _WIZCHIP_ register defines and I/O functions + @details + - @ref WIZCHIP_register_W6100 : @ref Common_register_group_W6100, @ref Socket_register_group_W6100 + - @ref WIZCHIP_IO_Functions_W6100 : @ref Basic_IO_function_W6100, @ref Common_register_access_function_W6100, @ref Socket_register_access_function_W6100 +*/ + +/** + @defgroup WIZCHIP_register_W6100 WIZCHIP register + @ingroup W6100 + @brief @ref WIZCHIP_register_W6100 defines register group of @b W6100. + @details + - @ref Common_register_group_W6100 : Common register group W6100 + - @ref Socket_register_group_W6100 : SOCKET n register group W6100 +*/ + +/** + @defgroup Basic_IO_function_W6100 Basic I/O function + @ingroup WIZCHIP_IO_Functions_W6100 + @brief These are basic input/output functions to read values from register or write values to register. +*/ + +/** + @defgroup Common_register_access_function_W6100 Common register access functions + @ingroup WIZCHIP_IO_Functions_W6100 + @brief These are functions to access @ref Common_register_group_W6100. +*/ + +/** + @defgroup Socket_register_access_function_W6100 Socket register access functions + @ingroup WIZCHIP_IO_Functions_W6100 + @brief These are functions to access @ref Socket_register_group_W6100. +*/ + +/** + @defgroup WIZCHIP_IO_Functions_W6100 WIZCHIP I/O functions + @ingroup W6100 + @brief @ref WIZCHIP_IO_Functions_W6100 supports the basic I/O functions for @ref WIZCHIP_register_W6100. + @details + - @ref WIZCHIP_IO_Functions_W6100 \n + WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF() + - @ref Common_register_access_function_W6100 \n + - @ref _WIZCHIP_ Mode \n + getCIDR(), getVER() \n + getSYSR() \n + setCHPLCKR(), setNETLCKR(), setPHYLCKR() \n + setSYCR0(), getSYCR1(), setSYCR1() + - Network Mode \n + getNET4MR(), setNET4MR(), getNET6MR(), setNET6MR(), getNETMR(), setNETMR(), getNETMR2(), setNETMR2() + - Interrupt \n + getIR(), setIRCLR(), getIMR(), setIMR() \n + getSIR(), getSIMR(), setSIMR() \n + getSLIR(), setSLIRCLR(), getSLIMR(), setSLIMR() \n + getINTPTMR(), setINTPTMR() + - Network Information \n + NETLOCK(), NETUNLOCK() \n + getSHAR(), setSHAR(), getGAR(), setGAR(), getSUBR(), setSUBR(), getSIPR(), setSIPR() \n + getLLAR(), setLLAR(), getGUAR(), setGUAR(), getGA6R(), setGA6R(), getSUB6R(), setSUB6R() \n + getPLR(), getPFR(), getVLTR(), getPLTR(), getPAR() \n + - SOCKET-less Commands for PING, ARP and IPv6 Auto-Configuration \n + getSLCR(), setSLCR() \n + getPINGIDR(), setPINGIDR(), getPINGSEQR(), setPINGSEQR() \n + getSLDHAR(), getSLDIPR(), setSLDIPR(), getSLDIP4R(), setSLDIP4R(), getSLDIP6R(), setSLDIP6R(), getSLHOPR(), setSLHOPR() \n + - Retransmission \n + getRCR(), setRCR() \n + getSLRCR(), setSLRCR(), getSLRTR(), setSLRTR() \n + - ICMP \n + getUIPR(), getUIP6R(), getUPORTR(), getUPORT6R() \n + getICMP6BLKR(), setICMP6BLKR() \n + - PPPoE \n + getPTMR(), setPTMR(), getPMNR(), getPMNR() \n + getPHAR(), setPHAR(), getPSIDR(), setPSIDR(), getPMRUR(), setPMRUR() + - PHY Configuration \n + getPHYSR(), setPHYLCKR(), PHYLOCK(), PHYUNLOCK() \n + setPHYCR0(), getPHYCR1(), setPHYCR1() \n + getPHYRAR(), setPHYRAR(), setPHYDIR(), getPHYDOR(), getPHYACR(), setPHYACR(), getPHYDIVR(), setPHYDIVR() + - etc \n + getTCNTR(), setTCNTRCLR() + - @ref Socket_register_access_function_W6100 \n + - SOCKET control \n + getSn_MR(), setSn_MR(), getSn_MR2(), setSn_MR2(), getSn_PSR(), setSn_PSR(), getSn_CR(), setSn_CR() \n + getSn_IR(), setSn_IRCLR(), getSn_IMR(), setSn_IMR() \n + getSn_RTR(), setSn_RTR(), getSn_RCR(), setSn_RCR(), getSn_KPALVTR(), setSn_KPALVTR() + - SOCKET information \n + getSn_SR(), getSn_ESR() \n + getSn_DHAR(), setSn_DHAR(), getSn_PORTR(), setSn_PORTR(), getSn_DPORTR(), setSn_DPORTR() \n + getSn_DIPR(), setSn_DIPR(), getSn_DIP6R(), setSn_DIP6R() \n + getSn_MSSR(), setSn_MSSR() + - SOCKET communication \n + getSn_RX_BSR(), setSn_RX_BSR(), getSn_TX_BSR(), setSn_TX_BSR() \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_FRGR(), setSn_FRGR(), getSn_TOSR(), setSn_TOSR() \n + getSn_TTLR(), setSn_TTLR() +*/ + +/** + @defgroup Common_register_group_W6100 Common register + @ingroup WIZCHIP_register_W6100 + @brief Common register group \n + @details It set the general configuration such as interrupt, network information, ICMP, and etc. + @sa + + + + + + + + + + + + +
@ref _WIZCHIP_ Information : _CIDR_, _VER_
@ref _WIZCHIP_ Mode : _SYSR_, _SYCR0_, _SYCR1_, _CHPLCKR_, _NETLCKR_, _PHYLCKR_
Network Mode : _NET4MR_, _NET6MR_, _NETMR_, _NETMR2_
Network Information : _GAR_, _SUBR_, _SHAR_, _SIPR_, _GA6R_, _LLAR_, _GUAR_, _SUB6R_
Interrupt : _IR_, _IRCLR_, _IMR_, _SIR_, _SIMR_, _SLIR_, _SLIMR_, _SLIRCLR_, _INTPTMR_
Data retransmission : _RTR_, _RCR_, _SLRTR_, _SLRCR_, _SLHOPR_
PPPoE : _PHAR_, _PSIDR_, _PMRUR_, _PTMR_, _PMNR_
SOCKET-less command : _SLCR_, _SLIR_, _SLDIPR_, _SLDIP4R_, _SLDIP6R_, _SLDHAR_, _PINGIDR_, _PINGSEQR_
ICMP v4 & v6 : _UIPR_, _UPORTR_, _UIP6R_, _UPORT6R_, _ICMP6BLKR_
IPv6 Auto-configuration : _PLR_, _PFR_, _VLTR_, _PAR_
PHY Configuration : _PHYSR_, _PHYCR0_, _PHYCR1_, _PHYRAR_, _PHYDIR_, _PHYDOR_, _PHYACR_, _PHYDIVR_
+*/ + + +/** + @defgroup Socket_register_group_W6100 Socket register + @ingroup WIZCHIP_register_W6100 + @brief Socket register group\n + @details + SOCKETn registers configure and control SOCKETn which is necessary to data communication. + @sa + + + + + + +
SOCKETn Control : _Sn_MR_, _Sn_MR2_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_IMR_, _Sn_PSR_
SOCKETn Information : _Sn_SR_, _Sn_ESR_, _Sn_PORTR_, _Sn_DHAR_, _Sn_DIPR_, _Sn_DIP6R_, _Sn_DPORTR_
SOCKETn Retransmission : _Sn_RTR_, _Sn_RCR_
Internet protocol : _Sn_MSSR_, _Sn_TOSR_, _Sn_TTLR_, _Sn_FRGR_
Data communication : _Sn_RX_BSR_, _Sn_TX_BSR_, _Sn_TX_FSR_, _Sn_TX_RD_, _Sn_TX_WR_, _Sn_RX_RSR_, _Sn_RX_RD_, _Sn_RX_WR_
+*/ + +//----------------------------------------------------------------------------------- + +//----------------------------- W6100 Common Registers IOMAP ----------------------------- + +/** + @addtogroup Common_register_group_W6100 + @{ +*/ + +/** + @brief Chip Identification Register address [RO] [0x6100] + @sa getCIDR() +*/ +#define _CIDR_ (_W6100_IO_BASE_ + (0x0000 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Chip Version Register address [RO] [0x4661] + @sa getVER() +*/ +#define _VER_ (_W6100_IO_BASE_ + (0x0002 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief System Status Register address [RO] [0xEU] + @details @ref _SYSR_ shows the information such as CHIP, NET, PHY Locking and Host I/F + + + +
7 6 5 4 ~ 2 1 0
CHPL NETL PHYL Reserved IND SPI
+ - @ref SYSR_CHPL + - @ref SYSR_NETL + - @ref SYSR_PHYL + - @ref SYSR_IND : HOST use Parallel BUS Interface(Indirect Bus Mode) + - @ref SYSR_SPI : HOST use SPI Interface + + @sa _CHPLCKR_, _NETLCKR_, _PHYLCKR_, + @sa getSYSR(), setCHPLCKR(), getCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), setNETLCKR(), getNETLCKR(), NETLOCK(), NETUNLOCK() \n + setPHYLCKR(), getPHYLCKR(), PHYLOCK(), PHYUNLOCK() +*/ +#define _SYSR_ (_W6100_IO_BASE_ + (0x2000 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief System Config Register 0 address [WO][0x80] + @details @ref _SYCR0_ softly reset to _WIZCHIP_. + + + +
7 6 ~ 0
RST Reserved
+ - @ref SYCR0_RST : Software Reset. + + @note It can be accessed only when @ref SYSR_CHPL = 1. + @sa _CHPLCKR_, _SYSR_, SYSR_CHPL + @sa setSYCR0(), setCHPLCKR(), getCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _SYCR0_ (_W6100_IO_BASE_ + (0x2004 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief System Config Register 1 address [R=W][0x80] + @details @ref _SYCR1_ controls the global interrupt enable, and selects the system clock. + + + +
7 6 ~ 1 0
IEN Reserved CLKSEL
+ - @ref SYCR1_IEN + - @ref SYCR1_CLKSEL + + @note SYCR1_CLKSEL bit can be accessed only when @ref SYSR_CHPL = 1. + @sa _CHPLCKR_, _SYSR_, SYSR_CHPL + @sa getSYCR1(), setSYCR1(), setCHPLCKR(), getCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _SYCR1_ (WIZCHIP_OFFSET_INC(_SYCR0_,1)) + +/** + @brief Ticker Counter Register address [RO][0x0000] + @details @ref _TCNTR_ increase by 1 every 100us after _WIZCHIP_ reset. + @sa _TCNTRCLR_ + @sa getTCNTR(), setTCNTRCLR() +*/ +#define _TCNTR_ (_W6100_IO_BASE_ + (0x2016 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Ticker Counter Clear Register address [RO][0x00] + @details @ref _TCNTRCLR_ clear @ref _TCNTR_. + @sa setTCNTRCLR(), getTCNTR() +*/ +#define _TCNTRCLR_ (_W6100_IO_BASE_ + (0x2020 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Interrupt Register address [RO][0x00] + @details @ref _IR_ indicates the interrupt status. + If @ref _IR_ is not equal to x00 INTn PIN is asserted to low until it is x00. + + + + +
7 6 ~ 5 4 3 2 1 0
WOL Reserved UNR6 Reserved IPCONF UNR4 PTERM
+ - @ref IR_WOL : Wake On LAN + - @ref IR_UNR6 : Destination Port Unreachable for IPv6 + - @ref IR_IPCONF : @ref _SIPR_ is Conflict + - @ref IR_UNR4 : Destination Port Unreachable for IPv4 + - @ref IR_PTERM : PPPoE Terminated + + @sa _IMR_, _IRCLR_, SYCR1_IEN, _CHIPLCKR_, _SYSR_, SYSR_CHPL + @sa getIR(), setIRCLR(), getSYCR1(), setSYCR1(), getCHPLCKR(), setCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _IR_ (_W6100_IO_BASE_ + (0x2100 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET Interrupt Register address [RO][0x00] + @details @ref _SIR_ indicates whether a socket interrupt is occurred or not.\n + Each bit of @ref _SIR_ be still until @ref _Sn_IR_ is cleared by @ref _Sn_IRCLR_ + @sa _SIMR_, _Sn_IR_, _Sn_IRCLR_, _Sn_IMR_, SYCR1_IEN , _CHIPLCKR_, _SYSR_, SYSR_CHPL + @sa getSIR(), getSn_IR(), setSn_IRCLR(), getSIMR(), setSIMR(), getSn_IMR(), setSn_IMR(), getSYCR1(), setSYCR1(), \n + getSYCR1(), setSYCR1(), getCHPLCKR(), setCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _SIR_ (_W6100_IO_BASE_ + (0x2101 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less Interrupt Register address [RO][0x00] + @details @ref _SLIR_ indicates the completion of @ref _SLCR_ or timeout. + + + +
7 6 5 4 3 2 1 0
TOUT ARP4 PING4 ARP6 PING6 NS RS RA
+ - @ref SLIR_TOUT : The timeout occurrence after @ref _SLCR_ is performed + - @ref SLIR_ARP4 : The completion of @ref SLCR_ARP4 + - @ref SLIR_PING4 : The completion of @ref SLCR_PING4 + - @ref SLIR_ARP6 : The completion f @ref SLCR_ARP6 + - @ref SLIR_PING6 : The completion of @ref SLCR_PING6 + - @ref SLIR_NS : The completion of @ref SLCR_NS + - @ref SLIR_RS : The completion of @ref SLIR_RS + - @ref SLIR_RA : The reception from Router Advertisement + + @sa _SLIRCLR_, _SLIMR_, SYCR1_IEN, _CHPLCKR_, _SYSR_, SYSR_CHPL + @sa getSLIR(), setSLIRCLR(), getSLIR(), getSLIMR(), setSLIMR(), \n + getSYCR1(), setSYCR1(), getCHPLCKR(), setCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _SLIR_ (_W6100_IO_BASE_ + (0x2102 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Interrupt Mask Register address [R=W][0x00] + @details @ref _IMR_ is used to mask interrupts of @ref _IR_.\n + When a bit of @ref _IMR_ and the corresponding bit of @ref _IR_ is set, an interrupt will be issued. + @sa _IR_, SYCR1_IEN, _CHPLCKR_, _SYSR_, SYSR_CHPL + @sa getIMR(), setIMR(), getIR(), setIRCLR(), \n + getSYCR1(), setSYCR1(), getCHPLCKR(), setCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _IMR_ (_W6100_IO_BASE_ + (0x2104 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief @ref _IR_ Clear Register address [WO][0x00] + @details @ref _IRCLR_ clears @ref _IR_ + @sa _IR_, _IMR_, SYCR1_IEN, _CHPLCKR_, _SYSR_, SYSR_CHPL + @sa setIRCLR(), getIR(), getIMR(), getSYCR1(), setSYCR1(), getCHPLCKR(), setCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _IRCLR_ (_W6100_IO_BASE_ + (0x2108 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET Interrupt Mask Register address [R=W]][0x00] + @details @ref _SIMR_ is used to mask interrupts of @ref _SIR_.\n + When a bit of @ref _SIMR_ and the corresponding bit of @ref _SIR_ is set, an interrupt will be issued.\n + when @ref _Sn_IR_ is not 0, The N-th bit of @ref _SIR_ is set. Otherwise, this bit is automatically clear.\n + @sa _SIR_, _Sn_IR_, _Sn_IRCLR_, _Sn_IMR_, SYCR1_IEN, _CHPLCKR_, _SYSR_, SYSR_CHPL + @sa getSIMR(), setSIMR(), getSIR(), setSn_IRCLR(), getSn_IMR(), setSn_IMR(), \n + getSYCR1(), setSYCR1(), getCHPLCKR(), setCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _SIMR_ (_W6100_IO_BASE_ + (0x2114 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less Interrupt Mask Register address [R=W][0x00] + @details @ref _SLIMR_ is used to mask interrupts of @ref _SLIR_\n + When a bit of @ref _SLIMR_ and the corresponding bit of @ref _SLIR_ is set, an interrupt will be issued. + @sa _SLIR_, _SLIRCLR_, SYCR1_IEN, _CHPLCKR_, _SYSR_, SYSR_CHPL + @sa getSLIMR(), setSLIMR(), getSLIR(), setSLIRCLR(), \n + getSYCR1(), setSYCR1(), getCHPLCKR(), setCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _SLIMR_ (_W6100_IO_BASE_ + (0x2124 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less Interrupt Clear Register address [WO][0x00] + @details @ref _SLIRCLR_ clears @ref _SLIR_ + @sa _SLIR_, _SLIRCLR_, _SLIMR_, SYCR1_IEN, _CHPLCKR_, _SYSR_, SYSR_CHPL + @sa getSLIR(), setSLIRCLR(), getSLIMR(), setSLIMR(), \n + getSYCR1(), setSYCR1(), getCHPLCKR(), setCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _SLIRCLR_ (_W6100_IO_BASE_ + (0x2128 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less Prefer Source IPv6 Address Register address [R=W][0x00] + @details @ref _SLPSR_ select the Source IPv6 Address to transmit a packet by @ref _SLCR_. + - @ref PSR_AUTO + - @ref PSR_LLA + - @ref PSR_GUA + @sa _SLCR_, _Sn_PSR_ + @sa getSLPSR(), setSLPSR(), getSLCR(), setSLCR(), getSn_PSR(), setSn_PSR() +*/ +#define _SLPSR_ (_W6100_IO_BASE_ + (0x212C << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less Command Register address [RW,AC][0x00] + @details @ref _SLCR_ can be request a message such like as ARP, PING, and ICMPv6 without SOCKET. + + + +
7 6 5 4 3 2 1 0
Reserved ARP4 PING4 ARP6 PING6 NS RS UNA
+ - @ref SLCR_ARP4 + - @ref SLCR_PING4 + - @ref SLCR_ARP6 + - @ref SLCR_PING6 + - @ref SLCR_NS + - @ref SLCR_RS + - @ref SLCR_UNA + + @sa _SLIR_, _SLIMR_, _SLDIPR_, _SLDIP4R_, _SLDIP6R_, _SLDHAR_, SYCR1_IEN, _CHPLCKR_, _SYSR_, SYSR_CHPL + @sa getSLCR(), setSLCR(), getSLIR(), setSLIRCLR(), getSLIMR(), setSLIMR(), getSLDIPR(),setSLDIPR(), getSLDIP4R(),setSLDIP4R(), + getSLDIP6R(), setSLDIP6R(), getSLDHAR(), getSYCR1(), setSYCR1(), getCHPLCKR(), setCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _SLCR_ (_W6100_IO_BASE_ + (0x2130 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PHY Status Register address [RO][0x00] + @details @ref _PHYSR_ shows the operation mode of PHY, the link status and etc. + - @ref PHYSR_CAB : @ref PHYSR_CAB_OFF, @ref PHYSR_CAB_ON + - @ref PHYSR_MODE : @ref PHYSR_MODE_AUTO, @ref PHYSR_MODE_100F, @ref PHYSR_MODE_100H, @ref PHYSR_MODE_10F, @ref PHYSR_MODE_10H + - @ref PHYSR_DPX : @ref PHYSR_DPX_FULL, @ref PHYSR_DPX_HALF + - @ref PHYSR_SPD : @ref PHYSR_SPD_100M, @ref PHYSR_SPD_10M + - @ref PHYSR_LNK : @ref PHYSR_LNK_UP, @ref PHYSR_LNK_DOWN + + @sa _PHYCR0_, _PHYLCKR_, _SYSR_, SYSR_PHYL + @sa getPHYSR(), setPHYCR0(), setPHYLCKR(), getPHYLCKR(), PHYLOCK(), PHYUNLOCK(), getSYSR() +*/ +#define _PHYSR_ (_W6100_IO_BASE_ + (0x3000 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PHY Internal Register Address Register address(R/W) + @details @ref _PHYRAR_ specifies the address of register in the Ethernet PHY. + - @ref PHYRAR_BMCR + - @ref PHYRAR_BMSR + @sa _PHYACR_, _PHYDOR_, _PHYDIR_, _PHYDIVR_ + @sa getPHYACR(), setPHYACR(), getPHYDOR(), setPHYDIR(), getPHYDIVR(), setPHYDIVR() +*/ +#define _PHYRAR_ (_W6100_IO_BASE_ + (0x3008 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PHY Data Input Register address [R=W][0x00] + @details @ref _PHYDIR_ specifies the value to write to the register in PHY + @sa _PHYRAR_, _PHYACR_, _PHYDOR_, _PHYDIVR_ + @sa setPHYDIR(), getPHYRAR(), setPHYRAR(), getPHYACR(), setPHYACR(), getPHYDOR(), setPHYDIR(), getPHYDIVR(), setPHYDIVR() +*/ +#define _PHYDIR_ (_W6100_IO_BASE_ + (0x300C << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PHY Data Output Register address [WO][0x00] + @details @ref _PHYDOR_ read the value from the register in PHY + @sa _PHYRAR_, _PHYACR_, _PHYDIR_, _PHYDIVR_ + @sa getPHYDOR(), getPHYRAR(), setPHYRAR(), getPHYACR(), setPHYACR(), setPHYDIR(), getPHYDIVR(), setPHYDIVR() +*/ +#define _PHYDOR_ (_W6100_IO_BASE_ + (0x3010 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PHY Access Register address [RW,AC][0x00] + @details @ref _PHYACR_ write(read) to(from) the value of register in the Ethernet PHY + - @ref PHYACR_READ + - @ref PHYACR_WRITE + @sa _PHYRAR_, _PHYDOR_, _PHYDIR_, _PHYDIVR_ + @sa getPHYACR(), setPHYACR(), getPHYDOR(), getPHYRAR(), setPHYRAR(), setPHYDIR(), getPHYDIVR(), setPHYDIVR() +*/ +#define _PHYACR_ (_W6100_IO_BASE_ + (0x3014 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PHY's MDC Clock Division Register address [R=W][0x01] + @details @ref _PHYDIVR_ divides the system clock for the MDC clock of Ethernet PHY' + - @ref PHYDIVR_32 + - @ref PHYDIVR_64 + - @ref PHYDIVR_128 + @sa _PHYRAR_, _PHYACR_, _PHYDOR_, _PHYDIR_, _PHYDIVR_ + @sa getPHYDIVR(), setPHYDIVR(), getPHYRAR(), setPHYRAR(), getPHYACR(), setPHYACR(), getPHYDOR(), setPHYDIR() +*/ +#define _PHYDIVR_ (_W6100_IO_BASE_ + (0x3018 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PHY Control Register address [WO][0x00] + @details @ref _PHYCR0_ controls the operation mode of PHY. + The result will be checked by @ref _PHYSR_ after PHY HW reset by @ref PHYCR1_RST. + - @ref PHYCR0_AUTO + - @ref PHYCR0_100F + - @ref PHYCR0_100H + - @ref PHYCR0_10F + - @ref PHYCR0_10H + + @note It can be only accessed when @ref SYSR_PHYL is unlock. + @sa _SYSR_, _PHYCR1_ + @sa setPHYCR0(), getSYSR(), getPHYCR1(), setPHYCR1() +*/ +#define _PHYCR0_ (_W6100_IO_BASE_ + (0x301C << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PHY Control Register address [R=W][0x40] + @details @ref _PHYCR1_ controls the Ethernet PHY function such as HW reset, Power down and etc. + + + +
7 6 5 4 3 2 ~ 1 0
Reserved Always 1 PWDN Reseved TE Reserved RST
+ - @ref PHYCR1_PWDN + - @ref PHYCR1_TE + - @ref PHYCR1_RST + + @note It can be only accessed when @ref SYSR_PHYL is unlock. + @sa _SYSR_, _PHYCR0_ + @sa getPHYCR1(), setPHYCR1(), setPHYCR0(), getSYSR() +*/ +#define _PHYCR1_ WIZCHIP_OFFSET_INC(_PHYCR0_,1) + +/** + @brief Network IPv4 Mode Register address [R=W][0x00] + @details @ref _NET4MR_ can block the transmission such like as unreachable message, TCP reset, and ping relay.\n + It can ARP request before ping relpy. + + + + +
7 ~ 4 3 2 1 0
Reserved UNRB PARP RSTB PB
+ - @ref NETxMR_UNRB + - @ref NETxMR_PARP + - @ref NETxMR_RSTB + - @ref NETxMR_PB + @sa _NET6MR_ + @sa getNET4MR(), setNET4MR(), getNET6MR(), setNET6MR() +*/ +#define _NET4MR_ (_W6100_IO_BASE_ + (0x4000 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Network IPv6 Mode Register address [R=W][0x00] + @details @ref _NET6MR_ can block the transmission such like as unreachable message, TCP reset, and ping relay.\n + It can ARP request before ping reply. + + + + +
7 ~ 4 3 2 1 0
Reserved UNRB PARP RSTB PB
+ - @ref NETxMR_UNRB + - @ref NETxMR_PARP + - @ref NETxMR_RSTB + - @ref NETxMR_PB + @sa _NET4MR_ + @sa getNET6MR(), setNET6MR(), getNET4MR(), setNET4MR() +*/ +#define _NET6MR_ (_W6100_IO_BASE_ + (0x4004 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Network Mode Register address [R=W][0x00] + @details @ref _NETMR_ set WOL(Wake On Lan) mode.\n + It also can block a packet such as \n + IPv6 PING request from an all-node broadcasting, \n + IPv6 PING request from a solicited mulitcasting address,\n + IPv4 packets, \n + and IPv6 packets. + + + + +
7 ~ 6 5 4 3 2 1 0
Reserved ANB M6B Always 0 WOL IP6B IP4B
+ - @ref NETMR_ANB + - @ref NETMR_M6B + - @ref NETMR_WOL + - @ref NETMR_IP6B + - @ref NETMR_IP4B + @sa getNETMR(), setNETMR() + +*/ +#define _NETMR_ (_W6100_IO_BASE_ + (0x4008 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Network Mode Register 2 address [R=W][0x00] + @details @ref _NETMR2_ set PPPoE mode.\n + It also can select the destination hardware address to either Ethernet frame MAC or target MAC in the ARP-reply message + + + +
7 6 ~ 1 0
DHAS 6 ~ 1 PPPoE
+ - @ref NETMR2_DHAS : @ref NETMR2_DHAS_ARP, @ref NETMR2_DHAS_ETH + - @ref NETMR2_PPPoE + @sa getNETMR2(), setNETMR2() +*/ +#define _NETMR2_ (_W6100_IO_BASE_ + (0x4009 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PPP LCP request Timer Register address [R=W][0x28] + @details @ref _PTMR_ sets the time for sending LCP echo request.\n + The unit of time is 25ms. + @sa _PMNR_, _PHAR_, _PSIDR_, _PMRUR_, NETMR2_PPPoE + @sa getPTMR(), setPTMR(), getPMNR(), setPMNR(), getPHAR(), setPHAR(), getPSIDR(), setPSIDR(), getPMRUR(), setPMRUR(), getNETMR2(), setNETMR2() +*/ +#define _PTMR_ (_W6100_IO_BASE_ + (0x4100 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PPP LCP Magic Number Register address [R=W][0x00] + @details @ref _PMNR_ sets the 4bytes magic number to be used in LCP negotiation. + @sa _PTMR_, _PHAR_, _PSIDR_, _PMRUR_, NETMR2_PPPoE + @sa getPMNR(), setPMNR(), getPTMR(), setPTMR(), getPHAR(), setPHAR(), getPSIDR(), setPSIDR(), getPMRUR(), setPMRUR(), getNETMR2(), setNETMR2() +*/ +#define _PMNR_ (_W6100_IO_BASE_ + (0x4104 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PPPoE Hardware Address Register address [R=W][0x00] + @details @ref _PHAR_ sets the PPPoE server hardware address that is acquired during PPPoE connection process. + @sa _PTMR_, _PMNR_, _PSIDR_, _PMRUR_, NETMR2_PPPoE + @sa getPHAR(), setPHAR(), getPTMR(), setPTMR(), getPMNR(), setPMNR(), getPSIDR(), setPSIDR(), getPMRUR(), setPMRUR(), getNETMR2(), setNETMR2() +*/ +#define _PHAR_ (_W6100_IO_BASE_ + (0x4108 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PPP Session ID Register address [R=W][0X0000] + @details @ref _PSIDR_ sets the PPPoE sever session ID acquired during PPPoE connection process. + @sa _PTMR_, _PMNR_, _PHAR_, _PMRUR_, NETMR2_PPPoE + @sa getPSIDR(), setPSIDR(), getPTMR(), setPTMR(), getPMNR(), setPMNR(), getPHAR(), setPHAR(), getPMRUR(), setPMRUR(), getNETMR2(), setNETMR2() +*/ +#define _PSIDR_ (_W6100_IO_BASE_ + (0x4110 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PPP Maximum Receive Unit Register address [R=W][0xFFFF] + @details @ref _PMRUR_ sets the maximum receive unit of PPPoE. + @sa _PTMR_, _PMNR_, _PHAR_, _PSIDR_, NETMR2_PPPoE + @sa getPMRUR(), setPMRUR(), getPTMR(), setPTMR(), getPMNR(), setPMNR(), getPHAR(), setPHAR(), getPSIDR(), setPSIDR(), getNETMR2(), setNETMR2() +*/ +#define _PMRUR_ (_W6100_IO_BASE_ + (0x4114 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Source Hardware Address Register address [R=W][00:00:00:00:00:00] + @details @ref _SHAR_ sets the source hardware address. + @note It can be accessed only when @ref SYSR_NETL is unlock. + @sa SYSR_NETL, _NETLCKR_ + @sa getSHAR(), setSHAR(), getSYSR(), setNETLCKR(), getNETLCKR(), NETLOCK(), NETUNLOCK() +*/ +#define _SHAR_ (_W6100_IO_BASE_ + (0x4120 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief IPv4 Gateway Address Register address [R=W][0.0.0.0] + @details @ref _GAR_ sets the default gateway IPv4 address. + @note It can be accessed only when @ref SYSR_NETL is unlock. + @sa SYSR_NETL, _NETLCKR_, _GA6R_ + @sa getGAR(), setGAR(), getSYSR(), setNETLCKR(), getNETLCKR(), NETLOCK(), NETUNLOCK(), getGA6R(), setGA6R() +*/ +#define _GAR_ (_W6100_IO_BASE_ + (0x4130 << 8) + WIZCHIP_CREG_BLOCK) +#define _GA4R_ (_GAR_) ///< Refer to @ref _GAR_ +/** + @brief IPv4 Subnet Mask Register address [R=W][0.0.0.0] + @details @ref _SUBR_ sets the default subnet mask address of IPv4. + @note It can be accessed only when @ref SYSR_NETL is unlock. + @sa SYSR_NETL, _NETLCKR_, _SUB6R_ + @sa getSUBR(), setSUBR(), getSYSR(), setNETLCKR(), getNETLCKR(), NETLOCK(), NETUNLOCK(), getSUB6R(), setSUB6R() +*/ +#define _SUBR_ (_W6100_IO_BASE_ + (0x4134 << 8) + WIZCHIP_CREG_BLOCK) +#define _SUB4R_ (_SUBR_) ///< Refer to @ref _SUBR_ + +/** + @brief IPv4 Source IP Register address [R=W][0.0.0.0] + @details @ref _SIPR_ sets the source IPv4 address. + @note It can be accessed only when @ref SYSR_NETL is unlock. + @sa SYSR_NETL, _NETLCKR_, _LLAR_, _GUAR_ + @sa getSIPR(), setSIPR(), getSYSR(), setNETLCKR(), getNETLCKR(), NETLOCK(), NETUNLOCK(), getLLAR(), setLLAR(), getGUAR(),setGUAR() +*/ +#define _SIPR_ (_W6100_IO_BASE_ + (0x4138 << 8) + WIZCHIP_CREG_BLOCK) +#define _SIP4R_ (_SIPR_) ///< Refer to @ref _SIPR_. + +/** + @brief IPv6 LLA(Link Local Address) Register address [R=W][::] + @details @ref _LLAR_ sets the LLA address of IPv6. + @note It can be accessed only when @ref SYSR_NETL is unlock. + @sa SYSR_NETL, _NETLCKR_, _GUAR_, _SIPR_ + @sa getLLAR(), setLLAR(), getSYSR(), setNETLCKR(), getNETLCKR(), NETLOCK(), NETUNLOCK(), getGUAR(),setGUAR(), getSIPR(), setSIPR() +*/ +#define _LLAR_ (_W6100_IO_BASE_ + (0x4140 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief IPv6 GUA(Global Unicast Address) Register address [R=W][::] + @details @ref _GUAR_ sets the GUA address of IPv6. + @note It can be accessed only when @ref SYSR_NETL is unlock. + @sa SYSR_NETL, _NETLCKR_, _LLAR_, _SIPR_ + @sa getGUAR(), setGUAR(), getSYSR(), setNETLCKR(), getNETLCKR(), NETLOCK(), NETUNLOCK(), getLLAR(),setLLAR(), getSIPR(), setSIPR() +*/ +#define _GUAR_ (_W6100_IO_BASE_ + (0x4150 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief IPv6 Subnet Mask Register address [R=W][] + @details @ref _SUB6R_ sets the default subnet mask address of IPv6. + @note It can be accessed only when @ref SYSR_NETL is unlock. + @sa SYSR_NETL, _NETLCKR_, _SUBR_ + @sa getSUB6R(), setSUB6R(), getSYSR(), setNETLCKR(), getNETLCKR(), NETLOCK(), NETUNLOCK(), getSUBR(), setSUBR() +*/ +#define _SUB6R_ (_W6100_IO_BASE_ + (0x4160 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief IPv6 Gateway Address Register address [R/W][::] + @details @ref _GA6R_ sets the default gateway IPv6 address. + @sa _GAR_ + @sa getGA6R(), setGA6R(), getGAR(), setGAR() +*/ +#define _GA6R_ (_W6100_IO_BASE_ + (0x4170 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less Peer IPv6 Register address [R=W][::] + @details @ref _SLDIP6R_ sets the destination IP address of @ref _SLCR_. + @sa _SLDIP6R_, _SLCR_, _SLIR_, _SLIRCLR_, _SLIMR_, _SLDHAR_, _SLDIPR_, _SLDIP4R_ + @sa getSLDIP6R(), setSLDIP6R(), getSLCR(), setSLCR(), getSLIR(), setSLIRCLR(), getSLIMR(), setSLIMR(), getSLDHAR(), + getSLDIPR(), setSLDIPR(), getSLDIP4R(), setSLDIP4R() +*/ +#define _SLDIP6R_ (_W6100_IO_BASE_ + (0x4180 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less Peer IPv6 Register address [R=W][0.0.0.0] + @details @ref _SLDIPR_(= @ref _SLDIP4R_) sets the destination IPv4 address of @ref _SLCR_. + @sa _SLDIP4R_, _SLCR_, _SLIR_, _SLIRCLR_, _SLIMR_, _SLDHAR_, _SLDIP6R_ + @sa getSLDIPR(), setSLDIPR(), getSLDIP4R(), setSLDIP4R(), getSLCR(), setSLCR(), getSLIR(), setSLIRCLR(), getSLIMR(), setSLIMR(), getSLDHAR(), + getSLDIP6R(), setSLDIP6R() +*/ +#define _SLDIPR_ (_W6100_IO_BASE_ + (0x418C << 8) + WIZCHIP_CREG_BLOCK) +#define _SLDIP4R_ (_SLDIPR_) ///< Refer to @ref _SLDIPR_. + + +/** + @brief SOCKET-less Peer Hardware Address Register address [RO][00:00:00:00:00:00] + @details @ref _SLDHAR_ gets the destination hardware address acquired by of @ref SLCR_ARP4, SLCR_ARP6, SLCR_PING4, and SLCR_PING6. + @sa _SLDIP4R_, _SLDIP6R_, _SLCR_, _SLIR_, _SLIRCLR_, _SLIMR_ + @sa getSLDHAR(), getSLDIP4R(), setSLDIP4R(), getSLDIP6R(), setSLDIP6R(), getSLCR(), setSLCR(), \n + getSLIR(), setSLIRCLR(), getSLIMR(), setSLIMR() +*/ +#define _SLDHAR_ (_W6100_IO_BASE_ + (0x4190 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less Ping ID Register address [R=W][0x00] + @details @ref _PINGIDR_ sets the PING-request ID to be sent by @ref SLCR_PING4 or @ref SLCR_PING6. + @sa _SLCR_, _PINGSEQR_, _SLDIPR_, _SLDIP4R_, _SLDIP6R_, _SLDHAR_, _SLIR_, _SLIRCLR_, _SLIMR_ + @sa getPINGIDR(), setPINGIDR(), getSLCR(), setSLCR(), getPINGSEQR(), setPINGSEQR(), getSLDIPR(), setSLDIPR(), + getSLDIP4R(), setSLDIP4R(), getSLDIP6R(), setSLDIP6R(), getSLDHAR(), getSLIR(), setSLIRCLR(), getSLIMR(), setSLIMR() +*/ +#define _PINGIDR_ (_W6100_IO_BASE_ + (0x4198 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less ping Sequence number Register address [R=W][0x0000] + @details @ref _PINGIDR_ sets the PING-request sequence number to be sent by @ref SLCR_PING4 or @ref SLCR_PING6. + @sa _SLCR_, _PINGIDR_, _SLDIPR_, _SLDIP4R_, _SLDIP6R_, _SLDHAR_, _SLIR_, _SLIRCLR_, _SLIMR_ + @sa getPINGSEQR(), setPINGSEQR(), getSLCR(), setSLCR(), getPINGIDR(), setPINGIDR(), getSLDIPR(), setSLDIPR(), getSLDIP4R(), setSLDIP4R(), + getSLDIP6R(), setSLDIP6R(), getSLDHAR(), getSLIR(), setSLIRCLR(), getSLIMR(), setSLIMR() +*/ +#define _PINGSEQR_ (_W6100_IO_BASE_ + (0x419C << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief IPv4 Unreachable Address Register address [RO][0.0.0.0] + @details @ref _UIPR_ is set when a unreachable ICMPv4 message is received. + @sa _UPORTR_, _UIP6R_, _UPORT6R_ + @sa getUIPR(), setUIPR(), getUPORTR(), setUPORTR(), getUIPR6(), setUIPR6(), getUPORT6R(), setUPORT6R() +*/ +#define _UIPR_ (_W6100_IO_BASE_ + (0x41A0 << 8) + WIZCHIP_CREG_BLOCK) +#define _UIP4R_ (_UIPR_) ///< Refer to @ref _UPORTR_ + +/** + @brief IPv4 Unreachable Port number Register address [RO][0x0000] + @details @ref _UPORTR_ is set when a unreachable ICMPv4 message is received. + @sa _UIPR_, _UIP6R_, _UPORT6R_ + @sa getUPORTR(), setUPORTR(), getUIPR(), setUIPR(), getUIPR6(), setUIPR6(), getUPORT6R(), setUPORT6R() +*/ +#define _UPORTR_ (_W6100_IO_BASE_ + (0x41A4 << 8) + WIZCHIP_CREG_BLOCK) +#define _UPORT4R_ (_UPORTR_) ///< Refer to @ref _UPORTR_ +/** + @brief IPv6 Unreachable IP Address Register address [RO][::] + @details @ref _UIP6R_ is set when a unreachable ICMPv6 message is received. + @sa _UIPR_, _UPORTR_, _UIP6R_, _UPORT6R_ + @sa getUIPR6(), setUIPR6(), getUIPR(), setUIPR(), getUPORTR(), setUPORTR(), getUPORT6R(), setUPORT6R() +*/ +#define _UIP6R_ (_W6100_IO_BASE_ + (0x41B0 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief IPv6 Unreachable Port number Register address [RO][0x0000] + @details @ref _UIP6R_ is set when a unreachable ICMPv6 message is received. + @sa _UIPR_, _UPORTR_, _UIP6R_, _UPORT6R_ + @sa getUIPR6(), setUIPR6(), getUIPR(), setUIPR(), getUPORTR(), setUPORTR(), getUPORT6R(), setUPORT6R() +*/ +#define _UPORT6R_ (_W6100_IO_BASE_ + (0x41C0 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Interrupt Pending Time Register address [R=w][0x0000] + @details @ref _INTPTMR_ pends the next interrupt issued by the INTn pin of @ref _WIZCHIP_.\n + It is decreased 1 every 4 SYS_CLK. \n + If it is zero and some interrupt is still remained, the INTn pin is issued. + @sa _IR_, _IRCLR_, _IMR_, _SIR_, _Sn_IRCLR_, _SIMR_, _SLIR_, _SLIRCLR_, _SLIMR_, SYCR_IEN + @sa getINTPTMR(), setINTPTMR(), getIR(), setIRCLR(), getIMR(), setIMR(), getSIR(), setSn_IRCLR(), getSIMR(), setSIMR(), \n + getSLIR(), setSLIRCLR(), getSLIMR(), setSLIMR(), getSYCR1(), setSYCR1() +*/ +#define _INTPTMR_ (_W6100_IO_BASE_ + (0x41C5 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief RA Prefix Length Register address [RO][0x00] + @details @ref _PLR_ is set when RA packet is received from a router. + @sa SLIR_RA, _SLIRCLR_, _PFR_, _VLTR_, _PLTR_, _PAR_ + @sa getPLR(), getSLIR(), setSLIRCLR(), getPFR(), getVLTR(), getPLTR(), getPAR() +*/ +#define _PLR_ (_W6100_IO_BASE_ + (0x41D0 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief RA Prefix Flag Register address [RO][0x00] + @details @ref _PFR_ is set when RA packet is received from a router. + @sa SLIR_RA, _SLIRCLR_, _PLR_, _VLTR_, _PLTR_, _PAR_ + @sa getPFR(), getSLIR(), setSLIRCLR(), getPLR(), getVLTR(), getPLTR(), getPAR() +*/ +#define _PFR_ (_W6100_IO_BASE_ + (0x41D4 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief RA Valid Life Time Register address [RO][0x00000000] + @details @ref _VLTR_ is set when RA packet is received from a router. + @sa SLIR_RA, _SLIRCLR_, _PLR_, _PFR_, _PLTR_, _PAR_ + @sa getVLTR(), getSLIR(), setSLIRCLR(), getPLR(), getPFR(), getPLTR(), getPAR() +*/ +#define _VLTR_ (_W6100_IO_BASE_ + (0x41D8 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief RA Prefered Life Time Register address [RO][0x00000000] + @details @ref _PLTR_ is set when RA packet is received from a router. + @sa SLIR_RA, _SLIRCLR_, _PLR_, _PFR_, _PLTR_, _PAR_ + @sa getPLTR(), getSLIR(), setSLIRCLR(), getPLR(), getPFR(), getVLTR(), getPAR() +*/ +#define _PLTR_ (_W6100_IO_BASE_ + (0x41DC << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief RA Prefix Address Register address[RO][::] + @details @ref _PAR_ is set when RA packet is received from a router. + @sa SLIR_RA, _SLIRCLR_, _PLR_, _PFR_, _VLTR_, _PLTR_, _PAR_ + @sa getPAR(), getPLTR(), getSLIR(), setSLIRCLR(), getPLR(), getPFR(), getVLTR() +*/ +#define _PAR_ (_W6100_IO_BASE_ + (0x41E0 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief ICMPv6 Block Register address [R=W][0x00] + @details @ref _ICMP6BLKR_ can block ICMPv6 message such like as PING, MLD, RA, NS and NA.\n + In this blocked case, @ref Sn_MR_IPRAW6 SOCKET can receive it. + + + +
7 ~ 5 4 3 2 1 0
7 ~ 5 PING6 MLD RA NA NS
+ - @ref ICMP6BLKR_PING6 : The same as @ref NETxMR_PB + - @ref ICMP6BLKR_MLD + - @ref ICMP6BLKR_RA + - @ref ICMP6BLKR_NA + - @ref ICMP6BLKR_NS + + @note The blocked message can be accepted by SOCKETn opened with @ref Sn_MR_IPRAW6. + @sa NETxMR_PB + @sa getICMP6BLKR(), setICMP6BLKR(), getNET6MR(), setNET6MR() +*/ +#define _ICMP6BLKR_ (_W6100_IO_BASE_ + (0x41F0 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Chip configuration Lock Register address [WO][0x00] + @details @ref _CHPLCKR_ can lock or unlock to access @ref _SYCR0_ and @ref _SYCR1_.\n + The lock state can be checked from @ref SYSR_CHPL. + @sa _SYCR0_, _SYCR1_, _SYSR_, SYSR_CHPL + @sa getCHPLCKR(), setCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _CHPLCKR_ (_W6100_IO_BASE_ + (0x41F4 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Network configuration Lock Register address [WO][0x00] + @details @ref _NETLCKR_ can lock or unlock to access the network information register such as @ref _SIPR_, @ref _LLAR_, and etc.\n + The lock state can be checked from @ SYSR_NETL. + @sa _SHAR_, _SIPR_, _SUBR_, _GAR_, _LLAR_, _GUAR_, _SUB6R_, _SYSR_, SYSR_NETL + @sa getNETLCKR(), setNETLCKR(), NETLOCK(), NETUNLOCK(), getSHAR(), setSHAR(), getSIPR(), getSIPR(), getSUBR(), setSUBR(), \n + getGAR(), setGAR(), getLLAR(), setLLAR(), getGUAR(), setGUAR(), getSUB6R(), setSUB6R(), getSYSR() +*/ +#define _NETLCKR_ (_W6100_IO_BASE_ + (0x41F5 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PHY configuration Lock Register address [WO][0x00] + @details @ref _PHYLCKR_ can lock or unlock to access @ref _PHYCR0_ and @ref _PHYCR1_.\n + The lock state can be checked from @ref SYSR_PHYL. + @sa _PHYCR0_, _PHYCR1_, _SYSR_, SYSR_PHYL. + @sa getPHYLCKR(), setPHYLCKR(), PHYLOCK(), PHYUNLOCK(), setPHYCR0(), getPHYCR1(), setPHYCR1(), getSYSR() +*/ +#define _PHYLCKR_ (_W6100_IO_BASE_ + (0x41F6 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Retransmission Time Register address [R=W][0x07D0] + @details @ref _RTR_ sets the default timeout value of @ref _Sn_RTR_.\n + When @ref _Sn_RTR_ is 0, @ref _Sn_RTR_ is reset to @ref _RTR_ after @ref Sn_CR_OPEN. + @sa _Sn_RTR_, _RCR_, _Sn_RCR_, _Sn_CR_, Sn_CR_OPEN, _Sn_IR_, _Sn_IRCLR_, Sn_IR_TIMEOUT + @sa getRTR(), setRTR(), getSn_RTR(), setSn_RTR(), getRCR(), setRCR(), getSn_RCR(), setSn_RCR(), \n + getSn_CR(), getSn_CR(), getSn_IR(), setSn_IRCLR() +*/ +#define _RTR_ (_W6100_IO_BASE_ + (0x4200 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Retransmission Counter Register address [R=W][0x08] + @details @ref _RCR_ sets the default retransmission count of @ref _Sn_RCR_.\n + When @ref _Sn_RCR_ is 0, @ref _Sn_RCR_ is initialized as @ref _Sn_RTR_ after @ref Sn_CR_OPEN. + @sa _Sn_RCR_, _RTR_, _Sn_RTR_, _Sn_CR_, Sn_CR_OPEN, _Sn_IR_, _Sn_IRCLR_, Sn_IR_TIMEOUT + @sa getRCR(), setRCR(), getSn_RCR(), setSn_RCR(), getRTR(), setRTR(), getSn_RTR(), setSn_RTR(), \n + getSn_CR(), getSn_CR(), getSn_IR(), setSn_IRCLR() +*/ +#define _RCR_ (_W6100_IO_BASE_ + (0x4204 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less Retransmission Time Register address [R=W][0x07D0] + @details @ref _SLRTR_ sets the timeout value of packet to be retransmitted by @ref _SLCR_. + @sa _SLRCR_, _SLIR_, _SLIRCLR_, SLIR_TOUT + @sa getSLRTR(), setSLRTR(), getSLRCR(), setSLRCR(), getSLIR(), setSLIRCLR() +*/ +#define _SLRTR_ (_W6100_IO_BASE_ + (0x4208 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less Retransmission Count Register address [R=W][0x00] + @details @ref _SLRCR_ sets the retry counter of packet to be retransmitted by @ref _SLCR_. + @sa _SLRTR_, _SLIR_, _SLIRCLR_, SLIR_TOUT + @sa getSLRCR(), setSLRCR(), getSLRTR(), setSLRTR(), setSLIRCLR(), getSLIR(), setSLIRCLR(), +*/ +#define _SLRCR_ (_W6100_IO_BASE_ + (0x420C << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less Hop Limit Register address [R=W][0x80] + @details @ref _SLHOPR_ sets the hop limit value of packet to be transmitted by @ref _SLCR_. + @sa _SLCR_ + @sa getSLHOPR(), setSLHOPR(), getSLCR(), setSLCR() +*/ +#define _SLHOPR_ (_W6100_IO_BASE_ + (0x420F << 8) + WIZCHIP_CREG_BLOCK) + +/** + @} +*/ + +//----------------------------- W6100 Socket Registers ----------------------------- +/** + @addtogroup Socket_register_group_W6100 + @{ +*/ +/** + @brief Socket Mode Register Address [R=W][0x00] + @details @ref _Sn_MR_ sets the option or protocol type of SOCKETn before @ref Sn_CR_OPEN is performed.\n\n + Each bit of @ref _Sn_MR_ is defined as the following. + + + +
7 6 5 4 3 ~ 0
MULTI/MF BRDB/FPSH ND/MC/SMB/MMB UNIB/MMB6 P[3:0]
+ - @ref Sn_MR_MULTI : Support UDP Multicasting + - @ref Sn_MR_MF : Support MAC Filter Enable + - @ref Sn_MR_BRDB : Broadcast Block + - @ref Sn_MR_FPSH : Force PSH flag + - @ref Sn_MR_ND : No Delay ACK flag + - @ref Sn_MR_MC : IGMP ver2, ver1 + - @ref Sn_MR_SMB : Solicited Multicast Block + - @ref Sn_MR_MMB : IPv4 Multicast block + - @ref Sn_MR_UNIB : Unicast Block + - @ref Sn_MR_MMB6 : IPv6 UDP Multicast Block + - P[3:0] + + + + + + + + + + + + +
P[3:0] Protocol Mode
0000 SOCKET Closed
0001 TCP4
0010 UDP4
0011 IPRAW4
0100
MACRAW
1001 TCP6
1010 UDP6
1100 IPRAW6
1101 TCP Dual(TCPD)
1110 UDP Dual (UDPD)
+ - @ref Sn_MR_CLOSE : SOCKET Closed + - @ref Sn_MR_TCP4(= @ref Sn_MR_TCP) : TCP4 mode + - @ref Sn_MR_UDP4(= @ref Sn_MR_UDP) : UDP4 mode + - @ref Sn_MR_IPRAW4(= @ref Sn_MR_IPRAW) : IPRAW4 mode + - @ref Sn_MR_MACRAW : MACRAW mode + - @ref Sn_MR_TCP6 : TCP6 mode + - @ref Sn_MR_UDP6 : UDP6 mode + - @ref Sn_MR_IPRAW6 : IPRAW6 mode + - @ref Sn_MR_TCPD : TCP Dual (TCPD) mode + - @ref Sn_MR_UDPD : UDP Dual (UDPD) mode + + @note MACRAW mode should be only used in Socket 0. + @sa _Sn_CR_, Sn_CR_OPEN, _Sn_SR_, _Sn_MR2_ + @sa getSn_MR(), setSn_MR(), getSn_CR(), setSn_CR(), getSn_SR(), getSn_MR2(), setSn_MR2() +*/ +#define _Sn_MR_(N) (_W6100_IO_BASE_ + (0x0000 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKET n Prefer Source IPv6 Address Register Address [R=W][0x00] + @details @ref _Sn_PSR_ select the Source IPv6 Address to transmit a packet by @ref _Sn_CR_. + This function is same as @ref _SLPSR_. + - @ref PSR_AUTO + - @ref PSR_LLA + - @ref PSR_GUA + @sa _Sn_CR_, _Sn_PSR_, _SLPSR_ + @sa getSn_PSR(), setSn_PSR(), getSLCR(), setSLCR(), getSLPSR(), setSLPSR(), +*/ +#define _Sn_PSR_(N) (_W6100_IO_BASE_ + (0x0004 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief Socket Command Register Address [RW,AC][0x00] + @details @ref _Sn_CR_ is used to set the command for SOCKET n such as OPEN, CLOSE, CONNECT, LISTEN, SEND, and RECEIVE.\n + It is automatically cleared to 0x00 after the command is recognized by @ref _WIZCHIP_.\n + 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 on TCP4/TCP6/TCPD mode(Server mode) + - @ref Sn_CR_CONNECT : Send connection request on TCP4/TCPD mode(Client mode) + - @ref Sn_CR_CONNECT6 : Send connection request on TCP6/TCPD mode(Client mode):nohl + - @ref Sn_CR_DISCON : Send closing request on TCP/TCP6/TCPD mode. + - @ref Sn_CR_CLOSE : Close socket. + - @ref Sn_CR_SEND : Update TX buffer pointer and send data in IPv4 socket. + - @ref Sn_CR_SEND6 : Update TX buffer pointer and send data in IPv6 socket. + - @ref Sn_CR_SEND_KEEP : Send keep alive message. + - @ref Sn_CR_RECV : Update RX buffer pointer and receive data. + + @note These commands should be exclusive executed.\n That is, the other command can not executed when one command is not cleared yet. + @sa _Sn_IR_, _Sn_IRCLR_, Sn_IMR_, _SIR_, _Sn_SR_ + @sa getSn_CR(), setSn_CR(), getSn_IR(), setSn_IRCLR(), getSn_IMR(), setSn_IMR(), getSIR(), getSn_SR() +*/ +#define _Sn_CR_(N) (_W6100_IO_BASE_ + (0x0010 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Interrupt Register Address [RO][0x00] + @details @ref _Sn_IR_ gets the status of SOCKETn interrupt such as establishment, termination, receiving data, timeout.\n + If SOCKETn interrupt occurs and the n-th bit of @ref _SIMR_ is set, then @ref SIR_INT(n) is set.\n + In order to clear the @ref _Sn_IR_ bit, Set the corresponding bit of _Sn_IRCLR_ to 1.\n + If all @ref _Sn_IR_ bits are cleared, the @ref SIR_INT(n) is automatically cleared. + + + +
7 ~ 5 4 3 2 1 0
Reserved SENDOK TIMEOUT RECV DISCON CON
+ - @ref Sn_IR_SENDOK + - @ref Sn_IR_TIMEOUT + - @ref Sn_IR_RECV + - @ref Sn_IR_DISCON + - @ref Sn_IR_CON + + @sa _Sn_IRCLR_, _Sn_IMR_, _SIR_, _SIMR_ + @sa getSn_IR(), setSn_IRCLR(), getSn_IMR(), setSn_IMR(), getSIR(), getSIMR(), setSIMR() +*/ +#define _Sn_IR_(N) (_W6100_IO_BASE_ + (0x0020 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Interrupt Mask Register Address [R=W][0xFF] + @details @ref _Sn_IMR_ is used to mask interrupts of @ref _Sn_IR_. + @sa _Sn_IR_, _Sn_IRCR_, _SIR_, _SIMR_ + @sa getSn_IMR(), setSn_IMR(), getSn_IR(), setSn_IRCLR(), getSIR(), getSIMR(), setSIMR() +*/ +#define _Sn_IMR_(N) (_W6100_IO_BASE_ + (0x0024 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Interrupt Clear Register Address [WO][0x00] + @details @ref _Sn_IRCLR_ clears @ref _Sn_IR_ + @sa _Sn_IR_, _SIR_, _SIMR_ + @sa setSn_IRCLR(), getSn_IR(), getSIR(), getSIMR(), setSIMR() +*/ +#define _Sn_IRCLR_(N) (_W6100_IO_BASE_ + (0x0028 << 8) + WIZCHIP_SREG_BLOCK(N)) + + + +/** + @brief SOCKETn Status Register Address [RO][0x00] + @details @ref _Sn_SR_ indicates the status of SOCKETn.\n + The status of SOCKETn can be changed by @ref _Sn_CR_, some TCP packets such as SYN, FIN, RST packet, or @ref Sn_IR_TIMEOUT. + - 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_IPRAW6 : IPv6 IPRAW socket + - @ref SOCK_MACRAW : MAC raw mode socket + - Temporary status during changing the status of SOCKETn . + - @ref SOCK_SYNSENT : This indicates SOCKETn sent the connect-request packet (SYN packet) to a peer. + - @ref SOCK_SYNRECV : It indicates SOCKETn successfully received the connect-request packet (SYN packet) from a peer. + - @ref SOCK_FIN_WAIT : Connection state + - @ref SOCK_TIME_WAIT : Closing state + - @ref SOCK_LAST_ACK : Closing state + + @sa _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, Sn_IR_TIMEOUT + @sa getSn_SR(), getSn_CR(), setSn_CR(), getSn_IR(), setSn_IRCLR() + + + +
@image html SocketStatus.png ""
+ +*/ +#define _Sn_SR_(N) (_W6100_IO_BASE_ + (0x0030 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Extension Status Register Address [RO][0x00] + @details @ref _Sn_ESR_ indicates the connected client IP address information such as IP version, IPv6 address type(LLA or GUA), \n + and TCP operation mode such as TCP SERVER and TCP CLIENT + + + +
7 ~ 3 2 1 0
Reserved TCPM TCPOP IP6T
+ - @ref Sn_ESR_TCPM : @ref Sn_ESR_TCPM_IPV4, @ref Sn_ESR_TCPM_IPV6 + - @ref Sn_ESR_TCPOP : @ref Sn_ESR_TCPOP_SVR, @ref Sn_ESR_TCPOP_CLT + - @ref Sn_ESR_IP6T : @ref Sn_ESR_IP6T_LLA, @ref Sn_ESR_IP6T_GUA + + @note It is valid only on TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_MR_, _Sn_PSR_ + @sa getSn_ESR(), getSn_MR(), setSn_MR(), getSn_PSR(), setSn_PSR() +*/ +#define _Sn_ESR_(N) (_W6100_IO_BASE_ + (0x0031 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn IP Protocol Number(PN) Register Address [R/W][0x0000] + @details \ref _Sn_PNR_ that sets the protocol number/next header field of the IPv4/IPv6 header at the IP layer. + @note It is valid only in IPRAW mode such as @ref Sn_MR_IPRAW4 and @ref Sn_MR_IPRAW6. + @note It is set before @ref Sn_CR_OPEN is performed. + @sa _Sn_NHR_, _Sn_MR_, Sn_CR_OPEN + @sa getSn_PNR(), setSn_PNR(), getSn_NHR(), setSn_NHR(), getSn_MR(), setSn_MR(), getSn_CR(), setSn_CR() +*/ +#define _Sn_PNR_(N) (_W6100_IO_BASE_ + (0x0100 << 8) + WIZCHIP_SREG_BLOCK(N)) +#define _Sn_NHR_(N) (_Sn_PNR_(N)) ///< Refer to @ref _Sn_PNR_. + +/** + @brief SOCKETn IPv4 Type of Service(TOS) Register Address [R=W][0x00] + @details @ref _Sn_TOSR_ sets the TOS(Type Of Service) field in IPv4 Header. + @sa getSn_TOSR(), setSn_TOSR() +*/ +#define _Sn_TOSR_(N) (_W6100_IO_BASE_ + (0x0104 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn IP Time to live(TTL) Register Address [R=W][0x80] + @details @ref _Sn_TTLR_ sets the TTL(Time To Live)/HOP(Hop Limit) field in IPv4/IPv6 header at the IP layer. + @sa _Sn_HOPR_ + @sa getSn_TTLR(), setSn_TTLR(), getSn_HOPR(), setSn_HOPR() +*/ +#define _Sn_TTLR_(N) (_W6100_IO_BASE_ + (0x0108 << 8) + WIZCHIP_SREG_BLOCK(N)) +#define _Sn_HOPR_(N) (_Sn_TTLR_(N)) ///< Refer to @ref _Sn_TTLR_. + +/** + @brief SOCKETn Fragment Register Address [R=W][0x4000] + @details @ref _Sn_FRGR_ sets the fragment flag & offset in IPv4 header. + @note @ref _WIZCHIP_ can not support IP fragment & re-assembly.\n So It is not recommended to set @ref _Sn_FRGR_ to any other value. + @sa getSn_FRGR(), setSn_FRGR() +*/ +#define _Sn_FRGR_(N) (_W6100_IO_BASE_ + (0x010C << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Maximum Segment Size(MSS) Register Address [RW][0x0000] + @details @ref _Sn_MSSR_ sets or gets the MTU(Maximum Transfer Unit) of SOCKETn. \n + The MTU of each protocol is as following. + + + + + + + + + +
@ref _Sn_MR_[3:0] @ref NETMR2_PPPoE = 0 @ref NETMR2_PPPoE = '1'
@ref Sn_MR_TCP4 1 ~ 1460 1 ~ 1452
@ref Sn_MR_TCP6 1 ~ 1440 1 ~ 1432
@ref Sn_MR_UDP4 1 ~ 1472 1 ~ 1464
@ref Sn_MR_UDP6 1 ~ 1452 1 ~ 1444
@ref Sn_MR_IPRAW4 1 ~ 1480 1 ~ 1472
@ref Sn_MR_IPRAW6 1 ~ 1460 1 ~ 1452
@ref Sn_MR_MACRAW 1 ~ 1514
+ + @note It is not set exceeding the MTU for each protocol of SOCKETn even if _Sn_MSSR_ is set over the MTU. + @sa _Sn_MR_, NETMR2_PPPoE + @sa getSn_MSSR(), setSn_MSSR(), getSn_MR(), setSn_MR(), getNETMR2(), setNETMR2() +*/ +#define _Sn_MSSR_(N) (_W6100_IO_BASE_ + (0x0110 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Source Port Register Address [R=W][0x0000] + @details @ref _Sn_PORTR_ sets the source port number of SOCKETn . + @note It is valid in TCP(@ref Sn_MR_TCP4, @ref Sn_MR_TCP6, @ref Sn_MR_TCPD) and UDP(@ref Sn_MR_UDP4, @ref Sn_MR_UDP6, @ref Sn_MR_UDPD) mode. + @note It should be set before @ref Sn_CR_OPEN is performed. + @sa _Sn_MR_, Sn_CR_OPEN + @sa getSn_PORTR(), getSn_PORTR(), getSn_MR(), setSn_MR(), getSn_CR(), setSn_CR() +*/ +#define _Sn_PORTR_(N) (_W6100_IO_BASE_ + (0x0114 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Destination Hardware Address Register Address [RW][00:00:00:00:00:00] + @details @ref _Sn_DHAR_ sets or gets the destination hardware address of SOCKETn.\n + - When @ref Sn_MR2_DHAM = 1 and @ref _Sn_MR_[3:0] != @ref Sn_MR_MACRAW + The destination hardware address is set by @ref _Sn_DHAR_ without ARP processed by @ref Sn_CR_CONNECT, @ref Sn_CR_CONNECT6, @ref Sn_CR_SEND, and @ref Sn_CR_SEND6.\n + Also, when SOCKETn is opened with @ref Sn_MR_UDP4 or @ref Sn_MR_UDP6 and @ref Sn_MR_MULTI is set, @ref _Sn_DHAR_ sets the Multicast Group Hardware address. + - Others + In TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD, \n + @ref _Sn_DHAR_ gets the destination hardware address when @ref _Sn_SR_ is @ref SOCK_ESTABLISHED. + @sa _Sn_MR_, _Sn_MR2_, _Sn_CR_, _Sn_SR_ + @sa getSn_DHAR(), setSn_DHAR(), getSn_MR(), setSn_MR(), getSn_MR2(), setSn_MR2(), getSn_CR(), setSn_CR(), getSn_SR() +*/ +#define _Sn_DHAR_(N) (_W6100_IO_BASE_ + (0x0118 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Destination IPv4 Address Register Address [RW][0.0.0.0] + @details @ref _Sn_DIPR_(= @ref _Sn_DIP4R_) sets or gets the destination IPv4 address of SOCKETn. \n + - In TCP mode such as @ref Sn_MR_TCP4, and @ref Sn_MR_TCPD + - TCP CLIENT mode : It sets the IPv4 address of TCP SERVER before @ref Sn_CR_CONNECT is performed. + - TCP SERVER mode : It gets the IPv4 address of TCP CLIENT when @ref _Sn_SR_ is @ref SOCK_ESTABLISHED. + - In UDP(@ref Sn_MR_UDP4, @ref Sn_MR_UDPD) mode & IPRAW4(@ref Sn_MR_IPRAW4) mode + It sets the destination IPv4 address before @ref Sn_CR_SEND is performed. \n + When Sn_MR_MULTI = 1, It sets the multicast group IPv4 address. + @sa _Sn_DIP4R_, _Sn_MR_, _Sn_CR_, _Sn_SR_ + @sa getSn_DIPR(), getSn_DIPR(), getSn_DIP4R(), getSn_DIP4R(), getSn_MR(), setSn_MR(), getSn_CR(), setSn_CR(), getSn_SR() +*/ +#define _Sn_DIPR_(N) (_W6100_IO_BASE_ + (0x0120 << 8) + WIZCHIP_SREG_BLOCK(N)) +#define _Sn_DIP4R_(N) (_Sn_DIPR_(N)) ///< Refer to @ref _Sn_DIPR_. + +/** + @brief SOCKETn Destination IPv6 Address Register Address [RW][::] + @details @ref _Sn_DIP6R_ sets or gets the destination IPv6 address of SOCKETn. + - In TCP mode such as @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD + - TCP CLIENT mode : It sets the IPv6 address of TCP SERVER before @ref Sn_CR_CONNECT6 is performed. + - TCP SERVER mode : It gets the IPv6 address of TCP CLIENT when @ref _Sn_SR_ is @ref SOCK_ESTABLISHED. + - In UDP(@ref Sn_MR_UDP6, @ref Sn_MR_UDPD) mode & IPRAW4(@ref Sn_MR_IPRAW6) mode + It sets the destination IPv6 address before @ref Sn_CR_SEND6 is performed.\n + When Sn_MR_MULTI = 1, It sets the multicast group IPv6 address. + @sa _Sn_MR_, _Sn_CR_, _Sn_SR_ + @sa getSn_DIP6R(), setSn_DIP6R(), getSn_MR(), setSn_MR(), getSn_CR(), setSn_CR(), getSn_SR() +*/ +#define _Sn_DIP6R_(N) (_W6100_IO_BASE_ + (0x0130 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Destination Port Register Address [RW][0x0000] + @details @ref _Sn_DPORTR_ sets or gets the destination port number of SOCKETn. + - In TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD + - TCP CLIENT mode : It sets the port number of TCP SERVER before @ref Sn_CR_CONNECT is performed. + - TCP SERVER mode : It gets the port number of TCP CLIENT when @ref _Sn_SR_ is @ref SOCK_ESTABLISHED. + - In UDP mode such as @ref Sn_MR_UDP4, @ref Sn_MR_UDP6, and @ref Sn_MR_UDPD + It sets the destination port number before @ref Sn_CR_SEND is performed. \n + When Sn_MR_MULTI = 1, It sets the multicast group group port number. + + @note It is valid SOCKETn is opened with @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, @ref Sn_MR_TCPD, @ref Sn_MR_UDP4, @ref Sn_MR_UDP4, and @ref Sn_MR_UDPD. + @note It should be set before OPEN command is ordered. + @sa _Sn_MR_, _Sn_CR_, _Sn_SR_ + @sa getSn_DPORTR(), getSn_DPORTR(), getSn_MR(), setSn_MR(), getSn_CR(), setSn_CR(), getSn_SR() +*/ +#define _Sn_DPORTR_(N) (_W6100_IO_BASE_ + (0x0140 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Mode Register 2 Address [R=W][0x00] + @details @ref _Sn_MR2_ sets the option of SOCKETn with @ref _Sn_MR_, before @ref Sn_CR_OPEN is performed.\n + Each bit of @ref _Sn_MR2_ is defined as the following. + + + +
7 ~ 2 1 0
Reserved DHAM FARP
+ - @ref Sn_MR2_DHAM : @ref Sn_MR2_DHAM_AUTO, @ref Sn_MR2_DHAM_MANUAL + - @ref Sn_MR2_FARP + @sa _Sn_MR_, _Sn_CR_ + @sa getSn_MR2(), setSn_MR2(), getSn_MR(), getSn_MR(), getSn_CR() +*/ +#define _Sn_MR2_(N) (_W6100_IO_BASE_ + (0x0144 << 8) + WIZCHIP_SREG_BLOCK(N)) + + +/** + @brief SOCKETn Retransmission Time Register Address [R=W][0x0000] + @details @ref _Sn_RTR_ sets the timeout value of packet to be retransmitted by @ref _SLCR_.\n + @note It should be set before @ref Sn_CR_OPEN is performed.\n + It is initialized as @ref _RTR_ if you do not set it to none-zero value. + @sa _RTR_, _Sn_CR_ + @sa getSn_RTR(), setSn_RTR(), getSn_CR(), setSn_CR() +*/ +#define _Sn_RTR_(N) (_W6100_IO_BASE_ + (0x0180 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Retransmission Count Register Address [R=W][0x00] + @details @ref _Sn_RCR_ sets the retry count value of packet to be retransmitted by @ref _SLCR_.\n + @note It should be set before @ref Sn_CR_OPEN is performed.\n + It is initialized as @ref _RTR_ if you do not set it to any none-zero value. + @sa _RTR_, _Sn_CR_ + @sa getSn_RTR(), setSn_RTR(), getSn_CR(), setSn_CR() +*/ +#define _Sn_RCR_(N) (_W6100_IO_BASE_ + (0x0184 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Keep Alive Time Register Address [R=W][0x00] + @details @ref _Sn_KPALVTR_ sets the auto-retransmission time of KA(Keep Alive) packet. \n + If the destination can not respond to the KA packet during the time set by @ref _Sn_KPALVTR_,\n + the connection is terminated, @ref Sn_IR_TIMEOUT is set and then @ref _Sn_SR_ is changed @ref SOCK_CLOSED.\n + Before the time is expierd, if the destination sends a KA/ACK packet or any packet, the connection is still valid,\n + @ref _Sn_SR_ remained at @ref SOCK_ESTABLISHED. + @note It is valid only after sending data over 1 byte in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @note If it is set to 0, KA packet can be sent by @ref Sn_CR_SEND_KEEP. + @sa Sn_CR_SEND_KEEP, Sn_IR_TIMEOUT, Sn_IRCLR, Sn_SR, Sn_MR + @sa getSn_KPALVTR(), setSn_KPALVTR(), getSn_IR(), setSn_IRCLR(), getSn_SR(), getSn_MR(), setSn_MR() +*/ +#define _Sn_KPALVTR_(N) (_W6100_IO_BASE_ + (0x0188 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn TX Buffer Size Register Address [R=W][0x02] + @details @ref _Sn_TX_BSR_ sets the TX buffer size of SOCKETn in the 16KB TX memory.\n + It can be set only with 0,1,2,4,8, and 16K bytes. + @note The 16KB TX memory is allocated as many as @ref _Sn_TX_BSR_ sequentially from SOCKET0 to SOCKETn(Here, 0 <= n <= @ref _WIZCHIP_SOCK_NUM_ - 1).\n + The total sum of Sn_TX_BSR can not be exceed 16KB of TX memory. \n + If the total size is exceeded, SOCKETn can't be normally sent data to a destination. + @sa _Sn_RX_BSR_ + @sa getSn_TX_BSR(), setSn_TX_BSR(), getSn_TXBUF_SIZE(), setSn_TXBUF_SIZE(), getSn_TxMAX(), setSn_TX_BSR(), getSn_RX_BSR(), setSn_RX_BSR() +*/ +#define _Sn_TX_BSR_(N) (_W6100_IO_BASE_ + (0x0200 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn TX Free Buffer Size Register Address [RO][0x0800] + @details @ref _Sn_TX_FSR_ gets the transmittable free size of SOCKETn TX buffer. + @note Data should not be saved bigger than it because the data overwrites the previous saved data not to be sent yet.\n + Therefore, Check it before saving the data to the SOCKETn TX buffer. \n + If the data size is equal or smaller than it, transmit the data with @ref Sn_CR_SEND / @ref Sn_CR_SEND6 after saving the data in SOCKETn TX buffer.\n + If the data size is greater than it, transmit the data after dividing into it and saving in the SOCKETn TX buffer. + @note \n + - In TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6 and @ref Sn_MR_TCPD, \n + It is automatically increased by the absolute difference between @ref _Sn_TX_WR_ and interanl TX ACK pointer. + - In other mode \n + It is automatically increased by the absolute difference between @ref _Sn_TX_WR_ and @ref _Sn_TX_RD_. + @sa _Sn_RX_RSR_, _Sn_TX_WR_, _Sn_TX_RD_, _Sn_CR_ + @sa getSn_TX_FSR(), getSn_TX_WR(), getSn_TX_WR(), getSn_TX_RD(), getSn_CR(), setSn_CR() +*/ +#define _Sn_TX_FSR_(N) (_W6100_IO_BASE_ + (0x0204 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKET TX Memory Read Pointer Register Address[R][0x0000] + @details @ref _Sn_TX_RD_ gets the start pointer of data to be sent by @ref Sn_CR_SEND. \n + @ref Sn_CR_SEND / @ref Sn_CR_SEND6 starts to transmit the saved data from @ref _Sn_TX_RD_ to @ref _Sn_TX_WR_ in the SOCKETn TX Buffer,\n + and when @ref Sn_IR_SENDOK is set, It is automatically increased to equal @ref _Sn_TX_WR_. + @note It is initialized by @ref Sn_CR_OPEN, But, In TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD,\n + it is re-initialized when the TCP connection is completed. + @note If it exceeds the maximum value 0xFFFF, (that is, it is greater than 0x10000 and the carry bit occurs),\n + then the carry bit is ignored and it automatically is updated with its the lower 16bits value. + @sa _Sn_TX_WR_, _Sn_TX_FSR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_ + @sa getSn_TX_RD(), getSn_TX_WR(), setSn_TX_WR(), getSn_TX_FSR(), getSn_CR(), setSn_CR(), getSn_IR(), setSn_IRCLR(), getSn_MR(), setSn_MR() +*/ +#define _Sn_TX_RD_(N) (_W6100_IO_BASE_ + (0x0208 << 8) + WIZCHIP_SREG_BLOCK(N)) + + +/** + @brief SOCKETn TX Memory Write Pointer Register Address [RW][0x0000] + @details @ref _Sn_TX_WR_ gets the start pointer of data to be saved in the SOCKETn TX buffer, \n + or sets the end pointer of data to be sent by @ref Sn_CR_SEND. \n + If you have completed to save the data to be sent in the SOCKETn TX buffer, + increase it as many as the saved size of data before @ref Sn_CR_SEND is performed.\n + @ref Sn_CR_SEND starts to transmit the saved data from @ref _Sn_TX_RD_ to @ref _Sn_TX_WR_ in the SOCKETn TX Buffer, \n + and when @ref Sn_IR_SENDOK is set, @ref _Sn_TX_RD_ is automatically increased to equal it. + @note It is initialized by @ref Sn_CR_OPEN.\n + But, In TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD,\n + it is re-initialized when the TCP connection is completed. + @note The size of data to be saved can't exceed @ref _Sn_TX_FSR_. + @note If it exceeds the maximum value 0xFFFF(that is, it is greater than 0x10000 and the carry bit occurs),\n + then ignore the carry bit and update it with its lower 16bits value. + @sa _Sn_TX_RD_, _Sn_TX_FSR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_ + @sa getSn_TX_WR(), setSn_TX_WR(), getSn_TX_RD(), getSn_TX_FSR(), getSn_CR(), setSn_CR(), getSn_IR(), setSn_IRCLR(), getSn_MR(), setSn_MR() +*/ +#define _Sn_TX_WR_(N) (_W6100_IO_BASE_ + (0x020C << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn RX Buffer Size Register Address [R=W][0x02] + @details @ref _Sn_RX_BSR_ sets the RX buffer size of SOCKETn in the 16KB RX memory.\n + It can be set only with 0,1,2,4,8, and 16K bytes. + @note The 16KB RX memory is allocated as many as @ref _Sn_RX_BSR_ sequentially from SOCKET0 to SOCKETn(Here, 0 <= n <= @ref _WIZCHIP_SOCK_NUM_ - 1).\n + The total sum of @ref _Sn_RX_BSR_ can not be exceed 16KB of RX memory. \n + If the total size is exceeded, SOCKETn can't be normally received data from a destination. + @sa _Sn_RX_BSR_ + @sa getSn_TX_BSR(), setSn_TX_BSR(), getSn_RXBUF_SIZE(), setSn_RXBUF_SIZE(), getSn_RxMAX(), getSn_RX_BSR(), setSn_RX_BSR() +*/ +#define _Sn_RX_BSR_(N) (_W6100_IO_BASE_ + (0x0220 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn RX Received Size Register Address [RO][0x0000] + @details @ref _Sn_RX_RSR_ gets the received data size of SOCKETn RX buffer. + @note The real received data size maybe smaller than it, \n + because it maybe included the size of 'PACKET NFO' such like as \n + the destination IP address, destination port number and data size of the received DATA PACKET. + @note Do not read bigger data than @ref _Sn_RX_RSR_. + @note It is automatically increased by the absolute difference between @ref _Sn_RX_WR_ and @ref _Sn_RX_RD_ \n + after @ref Sn_CR_RECV is performed. + @sa _Sn_RX_RSR_, _Sn_TX_WR_, _Sn_TX_RD_, _Sn_CR_, _Sn_TX_FSR_ + @sa getSn_RX_RSR(), getSn_TX_WR(), getSn_TX_WR(), getSn_CR(), setSn_CR(), getSn_TX_FSR() +*/ +#define _Sn_RX_RSR_(N) (_W6100_IO_BASE_ + (0x0224 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKET RX Memory Read Pointer Register Address[R][0x0000] + @details @ref _Sn_RX_RD_ gets the start pointer of the received data in the SOCKETn RX buffer,\n + or sets the end data pointer of the read completed data by @ref Sn_CR_RECV. \n + You can read the received data from it to @ref _Sn_RX_WR_ in the SOCKET RX buffer.\n + After completing to read data, you should increase it as many as the read size before @ref Sn_CR_RECV is performed. + @note It is initialized by @ref Sn_CR_OPEN, But, In TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD,\n + it is re-initialized when the TCP connection is completed. + @note If it exceeds the maximum value 0xFFFF, (that is, it is greater than 0x10000 and the carry bit occurs),\n + Ignore the carry bit and update with its the lower 16bits value. + @sa _Sn_RX_WR_, _Sn_RX_RSR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_ + @sa getSn_RX_WR(), setSn_RX_RD(), getSn_RX_WR(), getSn_TX_FSR(), getSn_CR(), setSn_CR(), getSn_IR(), setSn_IRCLR(), getSn_MR(), setSn_MR() +*/ +#define _Sn_RX_RD_(N) (_W6100_IO_BASE_ + (0x0228 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn TX Memory Write Pointer Register Address [RW][0x0000] + @details @ref _Sn_TX_WR_ gets the end pointer of the data that has been completely received in the SOCKETn RX buffer. \n + Whenever a data has been completely received from a destination, \n + It is automatically increased as many as the sum size of the received data and the 'PACKET INFO'. \n + You can read the recevied data from @ref _Sn_RX_RD_ to it in the SOCKET RX buffer. + @note It is initialized by @ref Sn_CR_OPEN. But, In TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD,\n + it is re-initialized when the TCP connection is completed. + @note If it exceeds the maximum value 0xFFFF(that is, it is greater than 0x10000 and the carry bit occurs),\n + then ignore the carry bit and update it with its lower 16bits value. + @sa _Sn_TX_RD_, _Sn_TX_FSR_, _Sn_CR_, _Sn_IR_, Sn_IRCLR_, _Sn_MR_ + @sa getSn_TX_WR(), setSn_TX_WR(), getSn_TX_RD(), getSn_TX_FSR(), getSn_CR(), setSn_CR(), getSn_IR(), setSn_IRCLR(), getSn_MR(), setSn_MR() +*/ +#define _Sn_RX_WR_(N) (_W6100_IO_BASE_ + (0x022C << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @} +*/ + +/*----------------------------- W6100 Register values -----------------------------*/ + +/* System Status Register Bit Definition */ +/** + @brief CHIP Lock staus bit of @ref _SYSR_. + @details @ref SYSR_CHPL indicates the lock status of @ref _SYCR0_ and @ref _SYCR1_.\n + 1 : Lock \n + 0 : unlock + @note It is set by only @ref _CHPLCKR_. + @sa _SYSR_, _CHPLCKR_, _SYCR0_, _SYCR1_ + @sa getSYSR(), getCHPLCKR(), setCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), setSYCR0(), setSYCR1() +*/ +#define SYSR_CHPL (1 << 7) + +/** + @brief NET Lock status bit of @ref _SYSR_. + @details @ref SYSR_NETL indicates the lock of network information registers such as + @ref _SHAR_, @ref _GAR_, @ref _SUBR_, @ref _SIPR_, @ref _LLAR_, @ref _GUAR_, and @ref _SUB6R_. \n + 1 : Lock \n + 0 : unlock + @note It is set by only @ref _NETLCKR_. + @note @ref _GA6R_ can be accessed regardless of @ref SYSR_NETL. + @sa _SYSR_, _NETLCKR_, _SHAR_, _GAR_, _SUBR_, _SIPR_, _LLAR_, _GUAR_, _SUB6R_ + @sa getSYSR(), getNETLCKR(), setNETLCKR(), NETLOCK(), NETUNLOCK(),\n + getSHAR(), setSHAR(), getGAR(), setGAR(), getSUBR(), getSIR(), setSIPR(), \n + getLLAR(), setLLAR(), getGUAR(),setGUAR(), getSUB6R(), setSUB6R() +*/ +#define SYSR_NETL (1 << 6) + +/** + @brief PHY Lock status bit of @ref _SYSR_. Refer to @ref _PHYLCKR_. + @details @ref SYSR_PHYL indicates the lock status of @ref _PHYCR0_ and _PHYCR1_.\n + 1 : Lock \n + 0 : unlock + @note It is set by only @ref _PHYLCKR_. + @sa _SYSR_, _PHYCLKR_, _PHYCR0_, _PHYCR1_ + @sa getSYSR(), getPHYLCKR(), setPHYLCKR(), setPHYCR0(), getPHYCR1(), setPHYCR1() +*/ +#define SYSR_PHYL (1 << 5) + +/** + @brief Parallel Bus Mode bit of @ref _SYSR_ + @details @ref SYSR_IND is set when @ref _WIZCHIP_ PIN MODE[3:0] == "010X". + It indicates to use the parallel BUS mode. + @sa _SYSR_, _WIZCHIP_IO_MODE_BUS_ + @sa getSYSR() +*/ +#define SYSR_IND (1 << 5) + +/** + @brief SPI I/F Mode bit of @ref _SYSR_. + @details @ref SYSR_SPI is set when @ref _WIZCHIP_ PIN MODE[3:0] == "000X". + It indicates to use the SPI mode. + @sa _SYSR_, _WIZCHIP_IO_MODE_SPI_ + @sa getSYSR() +*/ +#define SYSR_SPI (1 << 0) + + +/* System Config Register Bit Definition */ +/** + @brief RST bit of @ref _SYCR0_ + @details @ref SYCR0_RST resets to @ref _WIZCHIP_ softly. \n + 0 : Soft reset \n + 1 : Normal operation + @note It can be set only when @ref SYSR_CHPL = 1. + @sa _SYSR0_, _CHPLCKR_, _SYSR_, SYSR_CHPL + @sa setSYCR0(), setCHPLCKR(), getCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define SYCR0_RST (0x00) + +/** + @brief IEN bit of @ref _SYCR1_. + @details @ref SYCR1_IEN is globally enable or disable the interrupt of @ref _WIZCHIP_,\n + regardless of the related interrupt mask registers such as @ref _IMR_, @ref _SIMR_, @ref _SLIMR_, and @ref _Sn_IMR_.\n + 1 : Enable \n + 0 : Disable + @sa _SYCR1_, _IR_, _SIR_, _SLIR_, _Sn_IR_, _IRCLR_, _SLIRCLR_, _Sn_IRCLR_ + @sa getSYCR1(), setSYCR1(), getIR(), getSIR(), getSLIR(), getSn_IR(), setIRCLR(), setSLIRCLR(), setSn_IRCLR() +*/ +#define SYCR1_IEN (1 << 7) + +/** + @brief System Clock select mask bit of @ref _SYCR1_. + @details @ref SYCR1_CLKSEL selects a system clock to 100MHz or 25MHz. \n + The masked bit values are as following. + - @ref SYCR1_CLKSEL_25M + - @ref SYCR1_CLKSEL_100M + @note It can be set only when @ref SYSR_CHPL = 1. + @note The system clock is automatically changed to 25MHz while the reset of @ref _WIZCHIP_ H/W reset, the Ethernet PHY H/W reset and power down. \n + On the other hand, the system clock is set by @ref SYCR1_CLKSEL during normal operating. + @sa _SYCR1_, _SYSR_, _CHPLCKR_, SYSL_CHPL, PHYCR1_RST, PHYCR1_PWDN + @sa getSYCR1(), setSYCR1(), getSYSR(), getCHPLCKR(), setCHIPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getPHYCR1(), setPHYCR1() +*/ +#define SYCR1_CLKSEL (1 << 0) + +/** + @brief System Clock - 25MHz + @details @ref SYCR1_CLKSEL_25M selects a system clock to 25MHz. + @note It can be set only when @ref SYSR_CHPL = 1. + @sa _SYCR1_, SYCR1_CLKSEL, SYCR1_CLKSEL_100M + @sa getSYCR1(), setSYCR1(), getSYSR(), getCHPLCKR(), setCHIPLCKR(), CHIPLOCK(), CHIPUNLOCK() +*/ +#define SYCR1_CLKSEL_25M 1 + +/** + @brief System Clock - 100MHz + @details @ref SYCR1_CLKSEL_100M selects a system clock to 100MHz. + @note It can be set only when @ref SYSR_CHPL = 1. + @sa _SYCR1_, SYCR1_CLKSEL, SYCR1_CLKSEL_25M + @sa getSYCR1(), setSYCR1(), getSYSR(), getCHPLCKR(), setCHIPLCKR(), CHIPLOCK(), CHIPUNLOCK() +*/ +#define SYCR1_CLKSEL_100M 0 + + +/* Interrupt Register Bit Definition */ +/** + @brief WOL bit of @ref _IR_ + @details @ref IR_WOL is set when @ref _WIZCHIP_ receives a magic packet of WOL. + @sa _IR_, _IRCLR_, _IMR_ + @sa getIR(), setIRCLR(), getIMR(), setIMR() +*/ +#define IR_WOL (1<<7) + +/** + @brief UNR6 bit of @ref _IR_ + @details @ref IR_UNR6 is set when @ref _WIZCHIP_ receives the unreachable message of ICMPv6. + @sa _IR_, _IRCLR_, _IMR_ + @sa getIR(), setIRCLR(), getIMR(), setIMR() +*/ +#define IR_UNR6 (1<<4) + +/** + @brief IPCONF bit of @ref _IR_ + @details @ref IR_IPCONF is set when @ref _WIZCHIP_ receives a ARP reply with the same IPv4 address as @ref _SIPR_. + @sa _IR_, _IRCLR_, _IMR_ + @sa getIR(), setIRCLR(), getIMR(), setIMR() +*/ +#define IR_IPCONF (1<<2) + +/** + @brief UNR4 bit of @ref _IR_ + @details @ref IR_UNR4 is set when @ref _WIZCHIP_ receives the unreachable message of ICMPv4. + @sa _IR_, _IRCLR_, _IMR_ + @sa getIR(), setIRCLR(), getIMR(), setIMR() +*/ +#define IR_UNR4 (1<<1) + +/** + @brief PTERM bit of @ref _IR_ + @details @ref IR_PTERM is set when @ref _WIZCHIP_ receives the PPP termination packet + @sa _IR_, _IRCLR_, _IMR_ + @sa getIR(), setIRCLR(), getIMR(), setIMR() +*/ +#define IR_PTERM (1<<0) + + +/* SOCKET Interrupt Register Bit Definition */ +/** + @brief N-th INT bit of @@ref _SIR_ + @details @ref SIR_INT(N) is set when @ref _Sn_IR_(N) is not equal to zero. + @sa _SIR_, _Sn_IRCLR_, _SIMR_ + @sa getSIR(), setSn_IRCLR(), getSIMR() +*/ +#define SIR_INT(N) (1<TCP SERVER mode + If the connection request client have a IPv4 address, \n + TCP dual SOCKETn is changed to TCP4 mode and a destination IP address can be checked thru @ref _Sn_DIPR_, \n + else if the client have a IPv6 address, \n + TCP dual SOCKETn is changed to IPv6 mode and destination IP address can be checked by thru @ref _Sn_DIP6R_. + - In SOCKETn is operated as TCP CLIENT mode, + If the IP address type of destination to connect is IPv4, \n + the destination IP address should be set to @ref _Sn_DIPR_ and try to connect by @ref Sn_CR_CONNECT, \n + else if the type is IPv6, \n + the destination IP address should be set to @ref _Sn_DIP6R_ and try to connect by @ref Sn_CR_CONNECT6. \n + + @note In TCP SERVER mode, You can check the IP type of the client with @ref Sn_ESR_TCPM. + @note If the connected client have a IPv6 address, You can check whether the address is LLA or GAU, thru @ref Sn_ESR_IP6T + @sa _Sn_MR_, _Sn_CR_, _Sn_SR_, _Sn_ESR_TCPM_, Sn_MR_TCP4, Sn_MR_TCP6 + @sa getSn_MR(), setSn_MR(), getSn_CR(), setSn_CR(), getSn_SR(), getSn_ESR() +*/ +#define Sn_MR_TCPD (0x0D) + +/** + @brief UDP Dual mode + @details @ref Sn_MR_UDPD sets SOCKETn to both UDP4 & UDP6 mode. \n + It should be set before @ref Sn_CR_OPEN is performed. \n + After @ref Sn_CR_OPEN, SOCKETn is opened as UDP dual mode \n + and @ref _Sn_SR_ is changed from @ref SOCK_CLOSED to @ref SOCK_UDP. + @note In order to send data, \n + You can use both @ref Sn_CR_SEND and @ref Sn_CR_SEND6 as command and both @ref _Sn_DIPR_ and @ref _Sn_DIP6R_ as destination. + @note You can know the destination IP address type is whether IPv6 or IPv4 thru @ref getsockopt() with @ref SO_PACKINFO. + @sa _Sn_MR_, _Sn_CR_, _Sn_SR_, Sn_MR_UDP6, Sn_MR_UDP4 + @sa getSn_MR(), setSn_MR(), getSn_CR(), setSn_CR(), getSn_SR() +*/ +#define Sn_MR_UDPD (0x0E) + +/* SOCKETn Command Register BIt Definition */ +/** + @brief Initialize or Open SOCKETn. + @details SOCKETn is initialized and opened according to the protocol mode selected by @ref _Sn_MR_ and with a source port set by @ref _Sn_PORTR_. \n + The table shows @ref _Sn_SR_ is changed according to @ref _Sn_MR_.\n + + + + + + + + +
@ref _Sn_MR_ (P[3:0]) @ref _Sn_SR_
@ref Sn_MR_CLOSE @ref SOCK_CLOSED
@ref Sn_MR_TCP4, @ref Sn_MR_TCP6, @ref Sn_MR_TCPD @ref SOCK_INIT
@ref Sn_MR_UDP, @ref Sn_MR_UDP6, @ref Sn_MR_UDPD @ref SOCK_UDP
@ref Sn_MR_IPRAW4 @ref SOCK_IPRAW4
@ref Sn_MR_IPRAW6 @ref SOCK_IPRAW6
@ref Sn_MR_MACRAW @ref SOCK_MACRAW
+ + @note If you want to use a SOCKETn option such as Sn_MR_MF, Sn_MR_ND, Sn_MR_MUTIL and etc, \n + these options should be set before @ref Sn_CR_OPEN is performed. + @note If you want to open a multicast UDP mode SOCKETn, \n + You should set the multicast group with @ref _Sn_DIPR_ or @ref _Sn_DIP6R_ and @ref _Sn_DPORTR_ before @ref Sn_CR_OPEN is performed. + @sa _Sn_CR_, _Sn_MR_, _Sn_SR_, _Sn_PORTR_, _Sn_DIPR_, _Sn_DIP6R_, _Sn_DPORTR_, + @sa getSn_CR(), setSn_CR(), getSn_MR(), setSn_MR(), getSn_SR(), getSn_PORTR(), setSn_PORTR(), getSn_DIPR(), setSn_DIPR(), + getSn_DIP6R(), setSn_DIP6R(), getSn_DPORTR(), setSn_DPORTR() +*/ +#define Sn_CR_OPEN (0x01) + +/** + @brief Wait a connection request in TCP SERVER mode + @details SOCKETn operates as a TCP SERVER and waits for a connection-request (SYN packet) \n + with corresponding @ref _Sn_PORTR_ port number from any TCP CLIENT \n + The @ref _Sn_SR_ is changed from @ref SOCK_INIT to @ref SOCK_LISTEN. \n + When a TCP CLIENT connection request is successfully accepted,\n + the @ref _Sn_SR_ is changed from @ref SOCK_LISTEN to @ref SOCK_ESTABLISHED \n + and the @ref Sn_IR_CON is set.\n + But when a TCP CLIENT connection request is failed, \n + @ref Sn_IR_TIMEOUT is set and @ref _Sn_SR_ is changed to SOCK_CLOSED. + @note This is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_CR_, _Sn_MR_, _Sn_SR_, _Sn_PORTR_ + @sa getSn_CR(), setSn_CR(), getSn_MR(), setSn_MR(), getSn_SR(), getSn_PORTR(), setSn_PORTR() +*/ +#define Sn_CR_LISTEN (0x02) + +/** + @brief Send a connection request in TCP CLIENT mode + @details To establish a connection, a connect-request (SYN packet) is sent to TCP SERVER set by @ref _Sn_DIPR_ & @ref _Sn_DPORTR_.\n + If the connect-request is successful accepted by a TCP SERVER, \n + the @ref _Sn_SR_ is changed to @ref SOCK_ESTABLISHED and the @ref Sn_IR_CON is set. \n + The connect-request fails in the following three cases, \n + and @ref _Sn_SR_ is changed to @ref SOCK_CLOSED.\n\n + 1. Until a ARP timeout is occurred (@ref Sn_IR_TIMEOUT = 1), a destination hardware address can not be acquired through the ARP-process.\n + 2. Until a TCP tmeout occurred (@ref Sn_IR_TIMEOUT = 1), a SYN/ACK packet is not received from the server\n + 3. When a RST packet is received instead of a SYN/ACK packet \n + + @note This is valid only in TCP mode such as @ref Sn_MR_TCP4 and @ref Sn_MR_TCPD. + @sa _Sn_CR_, _Sn_MR_, _Sn_SR_, _Sn_DIPR_, _Sn_DPORTR_, Sn_CR_CONNECT6, _Sn_IR_, _Sn_IRCLR_ + @sa getSn_CR(), setSn_CR(), getSn_MR(), setSn_MR(), getSn_SR(), getSn_DIPR(), setSn_DIPR(), getSn_DPORTR(), setSn_DPORTR(), getSn_IR(), setSn_IRCLR() +*/ +#define Sn_CR_CONNECT (0x04) + +/** + @brief Send connection request in TCP CLIENT mode + @details To establish a connection, a connect-request (SYN packet) is sent to TCP SERVER set by @ref _Sn_DIP6R_ & @ref _Sn_DPORTR_.\n + If the connect-request is successful accepted by a TCP SERVER, \n + the @ref _Sn_SR_ is changed to @ref SOCK_ESTABLISHED and the @ref Sn_IR_CON is set. \n + The connect-request fails in the following three cases, and @ref _Sn_SR_ is changed @ref SOCK_CLOSED.\n + 1. Until a ARP timeout is occurred (@ref Sn_IR_TIMEOUT = 1), a destination hardware address can not be acquired through the ARP-process.\n + 2. Until a TCP tmeout occurred (@ref Sn_IR_TIMEOUT = 1), a @b SYN/ACK packet is not received from the server\n + 3. When a RST packet is received instead of a @b SYN/ACK packet \n + + @note This is valid only in TCP mode such as @ref Sn_MR_TCP6 and @ref Sn_MR_TCPD. + @sa _Sn_CR_, _Sn_MR_, _Sn_SR_, _Sn_DIP6R_, _Sn_DPORTR_, Sn_CR_CONNECT, _Sn_IR_, _Sn_IRCLR_ + @sa getSn_CR(), setSn_CR(), getSn_MR(), setSn_MR(), getSn_SR(), getSn_DIP6R(), setSn_DIP6R(), getSn_DPORTR(), setSn_DPORTR(), getSn_IR(), setSn_IRCLR() +*/ +#define Sn_CR_CONNECT6 (0x84) + +/** + @brief Send a disconnect request in TCP mode + @details Regardless of TCP SERVER or TCP CLIENT, \n + @ref Sn_CR_DISCON processes the disconnect-process (Active or Passive close).\n + When the disconnect-process is successful (that is, FIN/ACK packet is received successfully from/to each other),\n + @ref _Sn_SR_ is changed to @ref SOCK_CLOSED.\n + Otherwise, @ref Sn_IR_TIMEOUT is set and then @ref _Sn_SR_ is changed to @ref SOCK_CLOSED. + - Active close + It transmits first a disconnect-request(FIN packet) to the connected peer, and waits to receive two FIN/ACK and FIN packet from the peer. \n + If two FIN/ACK and FIN packet is received successfully, @ref Sn_IR_DISCON is set and @ref _Sn_SR_ is changed @ref SOCK_CLOSED. + - Passive close + When a FIN packet is first received from the peer, the FIN/ACK packet is replied back to the peer and @ref Sn_IR_DISCON is set.\n + And then, a FIN packet is sent by @ref Sn_CR_DISCON to the peer, and waits to receive the FIN/ACK packet from the peer. \n + If the FIN/ACK packet is received successfully from the peer, @ref _Sn_SR_ is changed to @ref SOCK_CLOSED. + + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_CR_, _Sn_MR_, _Sn_SR_, _Sn_IR_, _Sn_IRCLR_, Sn_IR_DISCON, Sn_IR_TIMEOUT + @sa getSn_CR(), setSn_CR(), getSn_MR(), setSn_MR(), getSn_SR(), getSn_IR(), setSn_IRCLR() +*/ +#define Sn_CR_DISCON (0x08) + +/** + @brief Release or Close SOCKETn + @details In TCP mode, @ref Sn_CR_CLOSE force to close a SOCKETn without the disconnect-process.\n + In other SOCKETn mode, @ref Sn_CR_CLOSE just closes a SOCKET.\n + @note @ref _Sn_SR_ can be changed from any status to @ref SOCK_CLOSED by @ref Sn_CR_CLOSE. + @sa _Sn_CR_, _Sn_MR_, _Sn_SR_, Sn_CR_DISCON + @sa getSn_CR(), setSn_CR(), getSn_MR(), setSn_MR(), getSn_SR() +*/ +#define Sn_CR_CLOSE (0x10) + +/** + @brief Send Data + @details @ref Sn_CR_SEND send the saved data from @ref _Sn_TX_RD_ to @ref _Sn_TX_WR_ in the SOCKETn TX buffer \n + to the destination specified by @ref _Sn_DIPR_ or @ref _Sn_DIP6R_, and @ref _Sn_DPORTR_.\n + - TCP mode(@ref Sn_MR_TCP4, @ref Sn_MR_TCP6, @ref Sn_MR_TCPD) + If it starts to be sent the data by @ref Sn_CR_SEND, @ref Sn_IR_SENDOK is set. \n + And after sending the data, if the ACK to the sent data can not be received during @ref _Sn_RTR_, \n + the sent data can be retransmitted as many as @ref _Sn_RCR_. \n + During the retransmission, \n + If the ACK is received, @ref _Sn_TX_FSR_ is increased as many as the sent data size, \n + Otherwise, @ref Sn_IR_TIMEOUT is set and @ref _Sn_SR_ is changed to @ref SOCK_CLOSED. + - UDP mode(@ref Sn_MR_UDP4, @ref Sn_MR_UDPD) & IPRAW mode(@ref Sn_MR_IPRAW4) + It first sends a ARP-request to a destination specified with @ref _Sn_DIPR_ before it starts to be sent data by @ref Sn_CR_SEND. \n + If the ARP-reply can not be received during @ref _Sn_RTR_, the ARP-request can be retransmitted as many as @ref _Sn_RCR_. \n + During the retransmission, \n + If the ARP-reply is received and @ref Sn_IR_SENDOK is set, it starts to send data and then @ref _Sn_TX_FSR_ is increased as many as the sent data size. \n + Otherwise, @ref Sn_IR_TIMEOUT is set but @ref _Sn_SR_ is not changed. + - MACRAW mode(@ref Sn_MR_MACRAW) + It just start to send data and @ref Sn_IR_SENDOK is set. + + @note Data size to be sent is calculated by the absolute difference between @ref _Sn_TX_WR_ and @ref _Sn_TX_RD_. \n + In TCP or UDP mode, It can not be sent bigger data than @ref _Sn_TX_FSR_.\n + In IPRAW or Macraw case, it can not be sent bigger data than MTU(Maximum Transmit Unit). + @note In TCP or MACRAW mode, It can send data to a destination address whether IPv4 or IPv6. \n + In UDP or IPRAW mode, It can send data only to a destination IPv4 address. \n + For Sending to IPv6 address, It can be used with @ref Sn_CR_SEND6. + @sa _Sn_CR_, _Sn_MR_, _Sn_DIPR_, _Sn_DIP6R_, _Sn_DPORTR_, _Sn_IR_, _Sn_IRCLR_, _Sn_TX_FSR_, _Sn_TX_WR_, _Sn_TX_RD_ + @sa getSn_CR(), setSn_CR(), getSn_MR(), setSn_MR(), getSn_SR(), getSn_DIPR(), setSn_DIPR(), getSn_DIP6R(), setSn_DIP6R(), \n + getSn_DPORTR(), setSn_DPORTR(), getSn_IR(), setSn_IRCLR(), getSn_TX_FSR(), getSn_TX_WR(), setSn_TX_WR(), getSn_TX_RD() +*/ +#define Sn_CR_SEND (0x20) + +/** + @brief Send Data + @details @ref Sn_CR_SEND6 sends the saved data from @ref _Sn_TX_RD_ to @ref _Sn_TX_WR_ in the SOCKETn TX buffer \n + to the destination specified by @ref _Sn_DIP6R_, and @ref _Sn_DPORTR_.\n + - TCP mode(@ref Sn_MR_TCP4, @ref Sn_MR_TCP6, @ref Sn_MR_TCPD) & MACRAW mode(@ref Sn_MR_MACRAW) + @ref Sn_CR_SEND6 is not recommended. In this case, Use @ref Sn_CR_SEND. + - UDP mode(@ref Sn_MR_UDP6, @ref Sn_MR_UDPD) & IPRAW mode(@ref Sn_MR_IPRAW6) + It first send a neighbor solicitation NS) of ICMPv6 to a destination specified with @ref _Sn_DIP6R_ \n + before it starts to be sent data by @ref Sn_CR_SEND. \n + If the neighbor advertisement(NA) of ICMPv6 can not be received during @ref _Sn_RTR_, \n + the NS can be retransmitted as many as @ref _Sn_RCR_. \n + During the retransmission, \n + If the NA is received and @ref Sn_IR_SENDOK is set, \n + it starts to send data and then @ref _Sn_TX_FSR_ is increased as many as the sent data size. \n + Otherwise, @ref Sn_IR_TIMEOUT is set but @ref _Sn_SR_ is not changed. + + @note Data size to be sent is calculated by the absolute difference between @ref _Sn_TX_WR_ and @ref _Sn_TX_RD_. \n + In TCP or UDP mode, It can not be sent bigger data than @ref _Sn_TX_FSR_.\n + In IPRAW or Macraw case, it can not be sent bigger data than MTU(Maximum Transmit Unit). + @note In UDP or IPRAW mode, It can send data only to a destination IPv6 address. \n + For Sending to IPv4 address, It can be sent by @ref Sn_CR_SEND. + @sa _Sn_CR_, _Sn_MR_, _Sn_DIP6R_, _Sn_DPORTR_, _Sn_IR_, _Sn_IRCLR_, _Sn_TX_FSR_, _Sn_TX_WR_, _Sn_TX_RD_ + @sa getSn_CR(), setSn_CR(), getSn_MR(), setSn_MR(), getSn_SR(), getSn_DIP6R(), setSn_DIP6R(), getSn_DPORTR(), setSn_DPORTR(), \n + getSn_IR(), setSn_IRCLR(), getSn_TX_FSR(), getSn_TX_WR(), setSn_TX_WR(), getSn_TX_RD() +*/ +#define Sn_CR_SEND6 (0xA0) + +/** + @brief Send keep alive message + @details @ref Sn_CR_SEND_KEEP checks whether the connection is established or not by sending 1 byte KA(Keep Alive) packet.\n + If the destination can not respond to the KA packet during the time set by @ref _Sn_RTR_ and @ref _Sn_RCR_, \n + the connection is terminated, @ref Sn_IR_TIMEOUT is set and then @ref _Sn_SR_ is changed @ref SOCK_CLOSED. + @note It is valid only after sending data over 1 byte in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_CR_, _Sn_MR_, _Sn_SR_, _Sn_IR_, _Sn_IRCLR_, _Sn_RTR_, _Sn_RCR_, _Sn_KPALVTR_ + @sa getSn_CR(), setSn_CR(), getSn_MR(), setSn_MR(), getSn_SR(), getSn_IR(), setSn_IRCLR(), \n + getSn_RTR(), setSn_RTR(), getSn_RCR(), setSn_RCR(), getSn_KPALVTR(), getSn_KPALVTR() +*/ +#define Sn_CR_SEND_KEEP (0x22) + +/** + @brief Receive data + @details @ref Sn_CR_RECV reads the saved from @ref _Sn_RX_RD_ to @ref _Sn_RX_WR_ data in SOCKETn RX buffer.\n + When a data is saved in the SOCKETn RX buffer, \n + @ref Sn_IR_RECV is set and @ref _Sn_RX_RSR_ is increased as many as the saved data size.\n + The total size of saved data is calculated by the absolute difference between @ref _Sn_RX_WR_ and @ref _Sn_RX_RD_,\n + and it can be checked thru @ref _Sn_RX_RSR_.\n + After reading data, @ref _Sn_RX_RD_ should be increased as many as the read size before @ref Sn_CR_RECV is performed.\n + After @ref Sn_CR_RECV, @ref _Sn_RX_RSR_ is decreased as many as the read size.\n + If @ref _Sn_RX_RSR_ is remained still at none-zero, @ref Sn_IR_RECV is set again. + @sa _Sn_CR_, _Sn_MR_, _Sn_IR_, _Sn_IRCLR_, _Sn_RX_RD_, _Sn_RX_WR_, _Sn_RX_RSR_ + @sa getSn_CR(), setSn_CR(), getSn_MR(), setSn_MR(), getSn_IR(), getSn_IRCLR(), \n + getSn_RX_RD(), setSn_RX_RD(), getSn_RX_TX(), getSn_RX_RSR() +*/ +#define Sn_CR_RECV (0x40) + + +/* Sn_IR values */ +/** + @brief SEND OK Interrupt + @details @ref Sn_IR_SENDOK is set when it is started to be sent data by @ref Sn_CR_SEND. + @note Even though @ref Sn_IR_SENDOK is set, it does not means that the destination receives data successfully.\n + - In TCP mode, The sent data maybe still transmitting or retransmitting. \n + - In other modes, The sent data maybe lost by media collision or an other reason such as network traffic. + @sa _Sn_IR_, _Sn_IRCLR_, Sn_CR_SEND + @sa getSn_IR(), setSn_IRCLR(), getSn_CR(), setSn_CR() +*/ +#define Sn_IR_SENDOK (0x10) + +/** + @brief TIMEOUT Interrupt + @details @ref Sn_IR_TIMEOUT is set when a timeout occurs in ARP and ND process or TCP retransmission. + @note In TCP mode, If it is set, @ref _Sn_SR_ is changed to @ref SOCK_CLOSED. \n + In other modes, _Sn_SR_ is still remained at the previous status. + @sa _Sn_IR_, _Sn_IRCLR_, Sn_CR_CONNECT, Sn_CR_CONNECT6, Sn_CR_SEND + @sa getSn_IR(), setSn_IRCLR(), getSn_CR(), setSn_CR() +*/ +#define Sn_IR_TIMEOUT (0x08) + +/** + @brief RECV Interrupt + @details @ref Sn_IR_RECV is set whenever data is received from a peer, \n + or if @ref _Sn_RX_RSR_ is still at none-zero whenever @ref Sn_CR_RECV is performed. + @sa _Sn_IR_, _Sn_IRCLR_, Sn_CR_RECV + @sa getSn_IR(), setSn_IRCLR(), getSn_CR(), setSn_CR() +*/ +#define Sn_IR_RECV (0x04) + +/** + @brief DISCON Interrupt + @details @ref Sn_IR_DISCON is set when a FIN or FIN/ACK packet is received from the connected peer. + @note When first a FIN packet is received from the connected peer and @ref _Sn_SR_ is changed to SOCK_CLOSE_WAIT, \n + you should perform @ref Sn_CR_DISCON for a successful disconnect. \n + If the disconnect-process is completed or failed, @ref _Sn_SR_ is changed to @ref SOCK_CLOSED. + @note It is valild only in TCP mode such as @ref Sn_MR_TCP4, @ ref Sn_MR_TCP6 and @ref Sn_MR_TCPD. + @sa _Sn_IR_, _Sn_IRCLR_, Sn_IR_DISCON, _Sn_SR_ + @sa getSn_IR(), setSn_IRCLR(), getSn_CR(), setSn_CR(), getSn_SR() +*/ +#define Sn_IR_DISCON (0x02) + +/** + @brief CONNECT Interrupt + @details @ref Sn_IR_CON is set once the connection with a peer is established and @ref _Sn_SR_ is changed to @ref SOCK_ESTABLISHED. + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ ref Sn_MR_TCP6 adn @ref Sn_MR_TCPD. + @sa _Sn_IR_, _Sn_IRCLR_, _Sn_SR_ + @sa getSn_IR(), setSn_IRCLR(), getSn_SR() +*/ +#define Sn_IR_CON (0x01) + +/* Sn_SR values */ +/** + @brief SOCKETn Closed status + @details @ref SOCK_CLOSED indicates that SOCKETn is closed and released.\n + It is set when @ref Sn_CR_DISCON , @ref Sn_CR_CLOSE is performed, or when @ref Sn_IR_TIMEOUT is set.\n + It can be changed to @ref SOCK_CLOSED regardless of previous status. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, Sn_IR_TIMEOUT + @sa getSn_SR(), getSn_CR(), setSn_CR(), getSn_IR(), setSn_IRCLR() +*/ +#define SOCK_CLOSED (0x00) + +/** + @brief TCP SOCKETn initialized status + @details @ref SOCK_INIT indicates SOCKETn is opened with TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCP6.\n + @ref _Sn_SR_ is changed from @ref SOCK_CLOSED to @ref SOCK_INIT when @ref Sn_CR_OPEN is performed in TCP mode.\n + In @ref SOCK_INIT status, @ref Sn_CR_LISTEN for operating a TCP SERVER \n + or @ref Sn_CR_CONNECT / @ref Sn_CR_CONNECT6 for operating a TCP CLIENT can be performed. + @note It is valid only in TCP mode. + @sa _Sn_SR_, _Sn_CR_, _Sn_MR_ + @sa getSn_SR, getSn_CR(), setSn_CR(), getSn_MR(), setSn_MR() +*/ +#define SOCK_INIT (0x13) + +/** + @brief TCP SOCKETn Listen status + @details @ref SOCK_LISTEN indicates SOCKETn is operating as TCP SERVER mode \n + and waiting for connection-request (SYN packet) from a peer (TCP CLIENT).\n + @ref _Sn_SR_ is changed to @ref SOCK_SYNRECV when the connection-request(SYN packet) is successfully accepted \n + and It is changed from @ref SOCK_SYNRECV to @ref SOCK_ESTABLISHED \n + when the SYN/ACK packet is sent successfully to the peer and then the ACK packet of SYN/ACK is received successfully.\n + Otherwise, it is changed to @ref SOCK_CLOSED and @ref Sn_IR_TIMEOUT is set. + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCP6.. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_ + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR() +*/ +#define SOCK_LISTEN (0x14) + +/** + @brief TCP Connection Request status + @details @ref SOCK_SYNSENT indicates TCP SOCKETn sent the connect-request packet(SYN packet)\n + to the peer specified by @ref _Sn_DIPR_ / @ref _Sn_DIP6R_ and @ref _Sn_DPORTR_.\n + It is temporarily shown when @ref _Sn_SR_ is changing from @ref SOCK_INIT to @ref SOCK_ESTABLISHED by @ref Sn_CR_CONNECT or @ref Sn_CR_CONNECT6.\n + When the connect-accept packet (SYN/ACK packet) is received from the peer at @ref SOCK_SYNSENT and the ACK packet of SYN/ACK is sent successfully, \n + @ref _Sn_SR_ is changed to @ref SOCK_ESTABLISHED.\n + Otherwise, it is changed to @ref SOCK_CLOSED and @ref Sn_IR_TIMEOUT is set. + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCP6.. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_ + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR() +*/ +#define SOCK_SYNSENT (0x15) + +/** + @brief TCP Connection Accept status + @details @ref SOCK_SYNRECV indicates TCP SOCKETn is successfully received the connect-request packet (SYN packet) from a peer.\n + It is temporarily shown when @ref _Sn_SR_ is changing from @ref SOCK_LISTEN to @ref SOCK_ESTABLISHED by the SYN packet\n + If SOCKETn sends the response (SYN/ACK packet) to the peer successfully and the ACK packet of SYS/ACK is received successfully,\n + @ref _Sn_SR_ is changed to @ref SOCK_ESTABLISHED. \n + Otherwise, @ref _Sn_SR_ is changed to @ref SOCK_CLOSED and @ref Sn_IR_TIMEOUT is set. + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCP6.. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_ + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR() +*/ +#define SOCK_SYNRECV (0x16) + +/** + @brief TCP SOCKETn Established status + @details @ref SOCK_ESTABLISHED indicates TCP SOCKETn is connected successfully with a peer.\n + when the TCP SERVER processes the SYN packet from the TCP CLIENT during @ref SOCK_LISTEN or \n + when the TCP CLIENT performs successfully @ref Sn_CR_CONNECT or @ref Sn_CR_CONNECT6,\n + @ref _Sn_SR_ is changed to @ref SOCK_ESTABLISHED and @ref Sn_IR_CON is set. \n + During @ref SOCK_ESTABLISHED, a DATA packet can be sent to or received from the peer by @ref Sn_CR_SEND or @ref Sn_CR_RECV. \n + If the DATA/ACK packet is not received from the peer during data re-transmission, @ref Sn_IR_TIMEOUT is set and @ref _Sn_SR_ is changed to @ref SOCK_CLOSED.\n + Otherwise, @ref _Sn_SR_ is still at @ref SOCK_ESTABLISHED. + @note In TCP SERVER, \n + You can check the IPv4/IPv6 address and port number of connected peer thru @ref _Sn_DIPR_, @ref _Sn_DIP6R_, and @ref _Sn_DPORTR_ respectively. + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCP6. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_, _Sn_DIPR_, _Sn_DIP6R_, _Sn_DPORTR_ + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR(), + getSn_DIPR(), setSn_DIPR(), getSn_DIP6R(), setSn_DIP6R(), getSn_DPORTR(), setSn_DPORTR(). +*/ +#define SOCK_ESTABLISHED (0x17) + +/** + @brief TCP SOCKETn Closing status + @details @ref SOCK_FIN_WAIT indicates TCP mode SOCKETn waits until the disconnect-process is completed. \n + It is temporarily shown in disconnect-process such as active-close. \n + When the disconnect-process is successfully completed or when @ref Sn_IR_TIMEOUT is set,\n + @ref _Sn_SR_ is changed to @ref SOCK_CLOSED. + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_, SOCK_TIME_WAIT, SOCK_LAST_ACK + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR() + +*/ +#define SOCK_FIN_WAIT (0x18) + +/** + @brief TCP SOCKETn Closing status + @details @ref SOCK_TIME_WAIT indicates TCP SOCKETn waits until the disconnect-process is completed.\n + It is temporarily shown in disconnect-process such as active-close. \n + When the disconnect-process is successfully completed or when @ref Sn_IR_TIMEOUT is set,\n + @ref _Sn_SR_ is changed to @ref SOCK_CLOSED. + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_, SOCK_FIN_WAIT, SOCK_LAST_ACK + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR() +*/ +#define SOCK_TIME_WAIT (0x1B) + +/** + @brief TCP SOCKETn Half Closing staus + @details @ref SOCK_CLOSE_WAIT indicates TCP SOCKETn receives the disconnect-request (FIN packet) from the connected peer.\n + It is a half-closing status, and a DATA packet can be still sent or received by @ref Sn_CR_SEND or @ref Sn_CR_RECV.\n + If you do not have any more need to send or received a DATA packet, You can perform @ref Sn_CR_DISCON for a full-closing. + @note If you have no need the successful closing, You maybe perform @ref Sn_CR_CLOSE. + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_ + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR() +*/ +#define SOCK_CLOSE_WAIT (0x1C) + +/** + @brief TCP SOCKETn Closing status + @details @ref SOCK_LAST_ACK indicates TCP SOCKETn waits until the disconnect-process is completed.\n + It is temporarily shown in disconnect-process such as active-close and passive-close.\n + When the disconnect-process is successfully completed or when @ref Sn_IR_TIMEOUT is set,\n + @ref _Sn_SR_ is changed to @ref SOCK_CLOSED. + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_, SOCK_FIN_WAIT, SOCK_TIME_WAIT + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR() +*/ +#define SOCK_LAST_ACK (0x1D) + +/** + @brief UDP SOCKETn status + @details @ref SOCK_UDP indicates SOCKETn is opened in UDP mode such as @ref Sn_MR_UDP4, @ref Sn_MR_UDP6, and @ref Sn_MR_UDPD.\n + @ref _Sn_SR_ is changed from @ref SOCK_CLOSED to @ref SOCK_INIT when @ref Sn_CR_OPEN is performed in UDP mode.\n + Unlike TCP mode, during @ref SOCK_UDP, \n + a DATA packet can be sent to or received from a peer by @ref Sn_CR_SEND / @ref Sn_CR_SEND6 or @ref Sn_CR_RECV without a connect-process.\n + Before a DATA packet is sent by @ref Sn_CR_SEND / @ref Sn_CR_SEND6,\n + the ARP is requested to the peer specified by @ref _Sn_DIPR_ / @ref _Sn_DIP6R_.\n + In ARP processing, @ref _Sn_SR_ is stll at @ref SOCK_UDP even if @ref Sn_IR_TIMEOUT is set.\n + If you do not have any more need to send or received a DATA packet, \n + You can perform @ref Sn_CR_CLOSE and @ref _Sn_SR_ is changed to @ref SOCK_CLOSED. + @note It is valid only in UDP mode such as @ref Sn_MR_UDP4, @ref Sn_MR_UDP6, and @ref Sn_MR_UDPD. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_, _Sn_DIPR_, _Sn_DIP6R_ + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR(), + getSn_DIPR(), setSn_DIPR(), getSn_DIP6R(), setSn_DIP6R() +*/ +#define SOCK_UDP (0x22) + +/** + @brief IPRAW4 SOCKETn mode + @details @ref SOCK_IPRAW4(= @ref SOCK_IPRAW) SOCKETn indicates SOCKETn is opened as IPv4 RAW mode.\n + @ref _Sn_SR_ is changed from @ref SOCK_CLOSED to @ref SOCK_IPRAW4 when @ref Sn_CR_OPEN is performed with @ref Sn_MR_IPRAW4. \n + A DATA packet can be send to or received from a peer without a connection like as @ref SOCK_UDP. \n + Before a DATA packet is sent by @ref Sn_CR_SEND, \n + the ARP is requested to the peer specified by @ref _Sn_DIPR_.\n + In ARP processing, @ref _Sn_SR_ is still at @ref SOCK_IPRAW4 even if @ref Sn_IR_TIMEOUT is set.\n + IPRAW4 SOCKETn can receive only the packet specified by @ref _Sn_PNR_, and it discards the others packets.\n + If you do not have any more need to send or received a DATA packet, \n + You can perform @ref Sn_CR_CLOSE and @ref _Sn_SR_ is changed to @ref SOCK_CLOSED. + @note It is valid only in IPRAW4 mode such as @ref Sn_MR_IPRAW4. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_, _Sn_DIPR_, _Sn_PNR_ + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR(), + getSn_DIPR(), setSn_DIPR(), getSn_PNR(), setSn_PNR() +*/ +#define SOCK_IPRAW4 (0x32) +#define SOCK_IPRAW (SOCK_IPRAW4) ///< Refer to @ref SOCK_IPRAW4. + +/** + @brief IPRAW6 SOCKETn mode + @details @ref SOCK_IPRAW6 SOCKETn indicates SOCKETn is opened as IPv6 RAW mode.\n + @ref _Sn_SR_ is changed from @ref SOCK_CLOSED to @ref SOCK_IPRAW6 when @ref Sn_CR_OPEN is performed with @ref Sn_MR_IPRAW6. \n + A DATA packet can be send to or received from a peer without a connection like as @ref SOCK_UDP.\n + Before a DATA packet is sent by @ref Sn_CR_SEND6, \n + the ICMPv6 NS is requested to the peer specified by @ref _Sn_DIPR_ or @ref _Sn_DIP6R_.\n + In ND(Neighbor Discovery) is processing,\n + @ref _Sn_SR_ is still at @ref SOCK_IPRAW6 even if @ref Sn_IR_TIMEOUT is set.\n + IPRAW6 SOCKETn can receive only the packet specified by @ref _Sn_PNR_, and it discards the others packets.\n + If you do not have any more need to send or received a DATA packet, \n + You can perform @ref Sn_CR_CLOSE and @ref _Sn_SR_ is changed to @ref SOCK_CLOSED. + @note It is valid only in IPRAW6 mode such as @ref Sn_MR_IPRAW6. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_, _Sn_DIP6R_, _Sn_PNR_ + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR(), + getSn_DIP6R(), setSn_DIP6R(), getSn_PNR(), setSn_PNR() +*/ +#define SOCK_IPRAW6 (0x33) + +/** + @brief MACRAW SOCKETn mode + @details @ref SOCK_MACRAW indicates SOCKET0 is opened as MACRAW mode.\n + @ref _Sn_SR_ is changed from @ref SOCK_CLOSED to @ref SOCK_MACRAW when @ref Sn_CR_OPEN command is ordered with @ref Sn_MR_MACRAW.\n + MACRAW SOCKET0 can be sent or received a pure Ethernet frame packet to/from any peer. + @note It is valid only in SOCKET0. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_ + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR(), +*/ +#define SOCK_MACRAW (0x42) + +/* Sn_ESR values */ +/** + @brief SOCKETn Extended Status : TCP Mode + @details @ref Sn_ESR_TCPM masks the TCPM bit of @ref _Sn_ESR_. \n + The masked bit values are as following. \n + - @ref Sn_ESR_TCPM_IPV4 + - @ref Sn_ESR_TCPM_IPV6 + @note It is useful to know the destination IP version when TCPD(@ref Sn_MR_TCPD) mode SOCKETn is operated as TCP SERVER. + @sa _Sn_ESR_ + @sa getSn_ESR() +*/ +#define Sn_ESR_TCPM (1<<2) + +/** + @brief TCP SOCKETn IP version - IPv4 + @details @ref Sn_ESR_TCPM_IPV4 indicates TCP SOCKETn is operated on IPv4 . + @sa _Sn_ESR_, Sn_ESR_TCPM_IPV6 + @sa getSn_ESR() +*/ +#define Sn_ESR_TCPM_IPV4 (0<<2) + +/** + @brief TCP SOCKETn IP version - IPv6 + @details @ref Sn_ESR_TCPM_IPV6 indicates TCP SOCKETn is operated on IPv6 . + @sa _Sn_ESR_, Sn_ESR_TCPM_IPV4 + @sa getSn_ESR() +*/ +#define Sn_ESR_TCPM_IPV6 (1<<2) + +/** + @brief SOCKETn Extended Status : TCP Operation Mode + @details @ref Sn_ESR_TCPOP masks the TCPOP bit of @ref _Sn_ESR_. The masked bit values are as following. \n + - @ref Sn_ESR_TCPOP_SVR + - @ref Sn_ESR_TCPOP_CLT + @note It is useful to check TCP mode SOCKETn is operated as whether TCP SERVER or TCP CLIENT. + @sa _Sn_ESR_ + @sa getSn_ESR() +*/ +#define Sn_ESR_TCPOP (1<<1) + +/** + @brief TCP SOCKETn Operation Mode - TCP SERVER + @details @ref Sn_ESR_TCPOP_SVR indicates TCP mode SOCKET n is operated as TCP SERVER + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_ESR_, Sn_ESR_TCPOP_CLT + @sa getSn_ESR() +*/ +#define Sn_ESR_TCPOP_SVR (0<<1) + +/** + @brief TCP SOCKETn Operation Mode - TCP CLIENT + @details @ref Sn_ESR_TCPOP_SVR indicates TCP mode SOCKET n is operated as TCP CLIENT + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_ESR_, Sn_ESR_TCPOP_SVR + @sa getSn_ESR() +*/ +#define Sn_ESR_TCPOP_CLT (1<<1) + +/** + @brief SOCKETn Extended Status : Source IPv6 Address Type + @details @ref Sn_ESR_IP6T masks the IP6T bit of @ref _Sn_ESR_. \n + The masked bit values are as following. \n + - @ref Sn_ESR_IP6T_LLA + - @ref Sn_ESR_IP6T_GUA + @note It is useful to check whether the connected peer IP address is LLA or GUA. + @note It is valid only in TCP mode such as @ref Sn_MR_TCP6 and @ref Sn_MR_TCPD. + @sa _Sn_ESR_ + @sa getSn_ESR() +*/ +#define Sn_ESR_IP6T (1<<0) + +/** + @brief Source IPv6 Address Type - LLA + @details @ref Sn_ESR_IP6T_LLA indicates the source IPv6 Address is used as @ref _LLAR_ + @note It is valid only in TCP mode such as @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_ESR_, Sn_ESR_IP6T_GUA, _LLAR_ + @sa getSn_ESR(), getLLAR(), setLLAR() +*/ +#define Sn_ESR_IP6T_LLA (0<<0) + +/** + @brief Source IPv6 Address Type - LLA + @details @ref Sn_ESR_IP6T_GUA indicates the source IPv6 Address is used as @ref _GUAR_ + @note It is valid only in TCP mode such as @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_ESR_, Sn_ESR_IP6T_LLA, _GUAR_ + @sa getSn_ESR(), getGUAR(), setGUAR() +*/ +#define Sn_ESR_IP6T_GUA (1<<0) + +/* Sn_MR2 values */ +/** + @brief Destination Hardware Address Mode + @details @ref Sn_MR2_DHAM masks the DHAM bit of @ref _Sn_MR2_.\n + The masked bit values are as following. + - @ref Sn_MR2_DHAM_AUTO + - @ref Sn_MR2_DHAM_MANUAL + @sa _Sn_MR2_ + @sa getSn_MR2(), setSn_MR2() +*/ +#define Sn_MR2_DHAM (1<<1) + +/** + @brief Destination Hardware Address Mode - AUTO + @details @ref Sn_MR2_DHAM_AUTO sets the destination hardware address as the address acquired by ARP-process. + @sa _Sn_MR2_, Sn_MR_DHAM_MANUAL, NETMR_DHAS + @sa getSn_MR2(), setSn_MR2(), getNETMR(), setNETMR() +*/ +#define Sn_MR2_DHAM_AUTO (0<<1) + +/** + @brief Destination Hardware Address Mode - MANUAL + @details @ref Sn_MR2_DHAM_MANUAL sets the destination hardware address as @ref _Sn_DHAR_. + @sa _Sn_MR2_, Sn_MR_DHAM_MANUAL, NETMR_DHAS + @sa getSn_MR2(), setSn_MR2(), getNETMR(), setNETMR() +*/ +#define Sn_MR2_DHAM_MANUAL (1<<1) + +/** + @brief Force ARP + @details @ref Sn_MR2_FARP force to perform the ARP-process for acquiring the destination hardware address, before data communication\n + 0 : Normal \n + 1 : Force ARP + - In TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD + If SOCKETn is operated as TCP SERVER, It sets the destination hardware address as the address + acquired by the forced ARP-process before sending SYN/ACK packet. + - In UDP mode such as @ref Sn_MR_UDP4, @ref Sn_MR_UDP6, and @ref Sn_MR_UDPD + It sets the destination hardware address as the address acquired by the forced ARP-process whenever @ref Sn_CR_SEND or @ref Sn_CR_SEND6. + @note When @ref Sn_MR2_DHAM_MANUAL and @ref Sn_MR2_FARP = '1', It sets the destination hardware address as @ref _Sn_DHAR_ even if the ARP-process is forced. +*/ +#define Sn_MR2_FARP (1<<0) + + +/*----------------------------For PHY Control-------------------------------*/ + +/** + @ingroup Common_register_group_W6100 + @brief Basic Mode Control Register of Ethernet PHY [RW][0x3100] + @details @ref PHYRAR_BMCR can be controlled by MDC/MDIO controller of @ref _WIZCHIP_. \n + Each bit of @ref PHYRAR_BMCR is defined as the following. + + + +
15 14 13 12 11 10 9 8 7 6 ~ 0
RST LB SPD ANE PWDN ISOL RAN DPX COLT Reserved
+ - @ref BMCR_RST + - @ref BMCR_LB + - @ref BMCR_SPD + - @ref BMCR_ANE + - @ref BMCR_PWDN + - @ref BMCR_ISOL : Not supported. + - @ref BMCR_REAN + - @ref BMCR_DPX + - @ref BMCR_COLT + + @note Its some bits have the same function as @ref _PHYCR0_ and @ref _PHYCR1_.\n + It can control the Ethernet PHY with software, while @ref _PHYCR0_ \n + and @ref _PHYCR1_ can control the Ethernet PHY with hardware. + + @sa PHYRAR_BMSR, _PHYRAR_, _PHYDIR_, _PHYDOR_, _PHYACR_, _PHYCR0_, _PHYCR1_ + @sa getPHYRAR(), setPHYRAR(), wiz_mdio_read(), wiz_mdio_write() +*/ +#define PHYRAR_BMCR (0x00) + +//Basic mode status register, basic register +/** + @ingroup Common_register_group_W6100 + @brief Basic Mode Status Register of Ethernet PHY [RO][0x7809] + @details @ref PHYRAR_BMSR gets the status of Ethernet PHY through MDC/MDIO controller of @ref _WIZCHIP_. \n + Each bit of @ref PHYRAR_BMSR is defined as the following. + + + + + +
15 14 13 12 11 10~76 5 4 3 2 1 0
100_T4 100_FDX 100_HDX 10_FDX 10_HDX Reserved MF_SUPANG_COMP REMOTE_FAULT ANG_ABILITY LINK_STATUS JABBER_DETECT EXT_CAPA
+ - @ref BMSR_100_T4 : Not supported. Always 0 + - @ref BMSR_100_FDX + - @ref BMSR_100_HDX + - @ref BMSR_10_FDX + - @ref BMSR_10_HDX + - @ref BMSR_MF_SUP : Not supported. Always 0. + - @ref BMSR_AN_COMP + - @ref BMSR_REMOTE_FAULT : Not supported. Always 0. + - @ref BMSR_AN_ABILITY + - @ref BMSR_LINK_STATUS + - @ref BMSR_JABBER_DETECT + - @ref BMSR_EXT_CAPA : Always 1. If you need a extended register information, send e-mail to support@wiznet.io + + @note Its some bits have the same function as @ref _PHYSR_. + @sa PHYRAR_BMCR, _PHYRAR_, _PHYDIR_, _PHYDOR_, _PHYACR_, _PHYCR0_, _PHYCR1_ + @sa getPHYRAR(), setPHYRAR(), wiz_mdio_read(), wiz_mdio_write() +*/ +#define PHYRAR_BMSR (0x01) + + +/********************/ +/* BMCR & BMSR Bit definitions */ +/********************/ + +/*For BMCR register*/ +/** + @brief Ethernet PHY S/W Reset. + @details 0 - Normal operation \n + 1 - Software reset + @sa PHYRAR_BMCR, PHYCR1_RST + @sa getPHYRAR_BMCR(), setPHYRAR_BMCR() +*/ +#define BMCR_RST (1<<15) + +/** + @brief Ethernet PHY Loopback. + @details 0 - Normal Operation \n + 1 - Loopback Enable + @sa PHYRAR_BMCR + @sa getPHYRAR_BMCR(), setPHYRAR_BMCR() +*/ +#define BMCR_LB (1<<14) ///< Loopback. 0 - Noraml operation, 1 - Loopback enabled + +/** + @brief Ethernet PHY Speed + @details 0 - 10 Mbps \n + 1 - 100 Mbps + @sa PHYCR_BMCR, PHYCR0_100F, PHYCR0_100H, PHYCR0_10F, PHYCR0_10H + @sa getPHYRAR_BMCR(), setPHYRAR_BMCR(), setPHYCR0() +*/ +#define BMCR_SPD (1<<13) + +/** + @brief Ethernet PHY Auto-Negotiation + @details 0 - Disable \n + 1 - Enable + @note When it is set, @ref BMCR_SPD and @ref BMCR_DPX is ignored + @sa PHYCR_BMCR, PHYCR0_AUTO + @sa getPHYRAR_BMCR(), setPHYRAR_BMCR(), setPHYCR0() +*/ +#define BMCR_ANE (1<<12) + +/** + @brief Ethernet PHY Power Down Mode + @details 0 - Normal Operation \n + 1 - Power Down mode + @sa PHYCR_BMCR, PHYCR0_PWDN + @sa getPHYRAR_BMCR(), setPHYRAR_BMCR(), setPHYCR0() +*/ +#define BMCR_PWDN (1<<11) ///< Power-down mode + +/** + @brief Ethernet PHY Isolation Mode + @details 0 - Normal Operation \n + 1 - Isolation Mode + @ Don't set it to '1'. It is not supported. + @sa PHYCR_BMCR + @sa getPHYRAR_BMCR(), setPHYRAR_BMCR() +*/ +#define BMCR_ISOL (1<<10) + +/** + @brief Ethernet PHY Restart Auto-Negotiation + @details 0 - Normal Operation \n + 1 - Restart Auto-Negotiation + @sa PHYCR_BMCR + @sa getPHYRAR_BMCR(), setPHYRAR_BMCR() +*/ +#define BMCR_REAN (1<<9) + +/** + @brief Ethernet PHY Duplex + @details 0 - Half-Duplex \n + 1 - Full-Duplex + @sa PHYCR_BMCR, PHYCR0_100F, PHYCR0_100H, PHYCR0_10F, PHYCR0_10H + @sa getPHYRAR_BMCR(), setPHYRAR_BMCR(), setPHYCR0() +*/ +#define BMCR_DPX (1<<8) + +/** + @brief Ethernet PHY Collision Test + @details 0 - Normal Operation \n + 1 - Collision Test + @sa PHYCR_BMCR + @sa getPHYRAR_BMCR(), setPHYRAR_BMCR() +*/ +#define BMCR_COLT (1<<7) + +/*For BMSR register*/ + +/** + @brief Ethernet PHY 100 Base-T4 capable + @details @ref BMSR_100_T4 is always 0. + @note It is not supported. + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_100_T4 (1<<15) + +/** + @brief Ethernet PHY 100 Base-TX Full-Duplex capable + @details @ref BMSR_100_FDX is always 1. + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_100_FDX (1<<14) + +/** + @brief Ethernet PHY 100 Base-TX Half-Duplex capable + @details @ref BMSR_100_HDX is always 1. + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_100_HDX (1<<13) + +/** + @brief Ethernet PHY 10 Base-T Full-Duplex capable + @details @ref BMSR_10_FDX is always 1. + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_10_FDX (1<<12) + +/** + @brief Ethernet PHY 10 Base-T Half-Duplex capable + @details @ref BMSR_10_HDX is always 1. + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_10_HDX (1<<11) + +/** + @brief Ethernet PHY Management Frame preamble suppression + @details @ref BMSR_MF_SUP is always 0. + @note It is not supported + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_MF_SUP (1<<6) + +/** + @brief Ethernet PHY Auto-Negotiation Complete + @details @ref BMSR_MF_SUP indicates the status of auto-negotiation. \n + 0 - Auto-negotiation process is not completed \n + 1 - Auto-negotiation process is completed + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_AN_COMP (1<<5) + +/** + @brief Ethernet PHY Remote Fault + @details @ref BMSR_REMOTE_FAULT is always 0. + @note It is not supported + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_REMOTE_FAULT (1<<4) + +/** + @brief Ethernet PHY Auto-Negotiation Ability + @details @ref BMSR_AN_ABILITY is always 1. + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_AN_ABILITY (1<<3) + +/** + @brief Ethernet PHY Link Status + @details @ref BMSR_LINK_STATUS indicates the status of link. \n + 0 - Link is not established + 1 - Valid link is established + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_LINK_STATUS (1<<2) + +/** + @brief Ethernet PHY Jabber Detect + @details @ref BMSR_JABBER_DETECT indicates the status of auto-negotiation. \n + 0 - Jabber condition is not detected\n + 1 - Jabber condition is detected + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_JABBER_DETECT (1<<1) + +/** + @brief Ethernet PHY Extended capability + @details @ref BMSR_EXT_CAPA indicates the extended register capability. \n + 0 - Only basic registers are capable\n + 1 - Extended registers are capable + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_EXT_CAPA (1<<0) + + +/** + @brief Enter a critical section + @details It is provided to protect your shared code and hardware resources against interference. \n + - Non-OS environment + It can be just implemented by disabling whole interrupt. + - OS environment + You can replace it to critical section API supported by OS. + + @note It is callback function that can be replaced it with your code, by calling @ref reg_wizchip_cris_cbfunc(). + @sa WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF() + @sa WIZCHIP_CRITICAL_EXIT(), reg_wizchip_cris_cbfunc() +*/ +#define WIZCHIP_CRITICAL_ENTER() WIZCHIP.CRIS._enter() + + +/** + @brief Enter a critical section + @details It exits the protected code and hardware resources against interference. \n + - Non-OS environment + It can be just implemented by enabling whole interrupt.\n + - OS environment + You can replace it to critical section API supported by OS. + + @note It is callback function that can be replaced it with your code, by calling @ref reg_wizchip_cris_cbfunc(). + @sa WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF() + @sa WIZCHIP_CRITICAL_EXIT(), reg_wizchip_cris_cbfunc() +*/ +#define WIZCHIP_CRITICAL_EXIT() WIZCHIP.CRIS._exit() + + + +//////////////////////// +// Basic I/O Function // +//////////////////////// +// +// +/** + @ingroup Basic_IO_function_W6100 + @brief It reads 1 byte value from a register. + @param AddrSel Register address + @return The value of register + @sa WIZCHIP_READ_BUF(), reg_wizchip_bus_cbfunc(), reg_wizchip_spi_cbfunc(), WIZCHIP_WRITE() +*/ +uint8_t WIZCHIP_READ(uint32_t AddrSel); + +/** + @ingroup Basic_IO_function_W6100 + @brief It writes 1 byte value to a register. + @param AddrSel Register address + @param wb Write data + @return void + @sa WIZCHIP_WRITE_BUF(), reg_wizchip_bus_cbfunc(), reg_wizchip_spi_cbfunc(), WIZCHIP_READ() +*/ +void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb); + +/** + @ingroup Basic_IO_function_W6100 + @brief It reads sequentail data from registers. + @param AddrSel Register address + @param pBuf Pointer buffer to read data + @param len Data length + @return void + @sa WIZCHIP_WRITE_BUF(), reg_wizchip_bus_cbfunc(), reg_wizchip_spi_cbfunc(), WIZCHIP_READ() +*/ +void WIZCHIP_READ_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len); + +/** + @ingroup Basic_IO_function_W6100 + @brief It writes sequential data to registers. + @param AddrSel Register address + @param pBuf Pointer buffer to write data + @param len Data length + @return void + @sa WIZCHIP_READ_BUF(), reg_wizchip_bus_cbfunc(), reg_wizchip_spi_cbfunc(), WIZCHIP_WRITE() +*/ +void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len); + + + +///////////////////////////////// +// Common Register IO function // +///////////////////////////////// +/** + @addtogroup Common_register_access_function_W6100 + @{ +*/ +#define getCIDR() \ + ((((uint16_t)WIZCHIP_READ(_CIDR_)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_CIDR_,1))) + +#define getVER() \ + ((((uint16_t)WIZCHIP_READ(_VER_)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_VER_,1))) + +#define getSYSR() \ + WIZCHIP_READ(_SYSR_) + +#define getSYCR0() \ + WIZCHIP_READ(_SYCR0_) + +#define setSYCR0(sycr0) \ + WIZCHIP_WRITE(_SYCR0_, (sycr0)) + +#define getSYCR1() \ + WIZCHIP_READ(_SYCR1_) + +#define setSYCR1(sycr1) \ + WIZCHIP_WRITE(_SYCR1_, (sycr1)) + +#define getTCNTR() \ + ((((uint16_t)WIZCHIP_READ(_TCNTR_)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_TCNTR_,1))) + +#define setTCNTRCLR(tcntrclr) \ + WIZCHIP_WRITE(_TCNTRCLR_,(tcntrclr)) + +#define getIR() \ + WIZCHIP_READ(_IR_) + +#define getSIR() \ + WIZCHIP_READ(_SIR_) + +#define getSLIR() \ + WIZCHIP_READ(_SLIR_) + +#define setIMR(imr) \ + WIZCHIP_WRITE(_IMR_,(imr)) + +#define getIMR() \ + WIZCHIP_READ(_IMR_) + +#define setIRCLR(irclr) \ + WIZCHIP_WRITE(_IRCLR_,(irclr)) +#define setIR(ir) setIRCLR(ir) + +#define setSIMR(simr) \ + WIZCHIP_WRITE(_SIMR_,(simr)) + +#define getSIMR() \ + WIZCHIP_READ(_SIMR_) + +#define setSLIMR(slimr) \ + WIZCHIP_WRITE(_SLIMR_,(slimr)) + +#define getSLIMR() \ + WIZCHIP_READ(_SLIMR_) + +#define setSLIRCLR(slirclr) \ + WIZCHIP_WRITE(_SLIRCLR_,(slirclr)) +#define setSLIR(slir) setSLIRCLR(slir) + +#define setSLPSR(slpsr) \ + WIZCHIP_WRITE(_SLPSR_,(slpsr)) + +#define getSLPSR() \ + WIZCHIP_READ(_SLPSR_) + +#define setSLCR(slcr) \ + WIZCHIP_WRITE(_SLCR_,(slcr)) + +#define getSLCR() \ + WIZCHIP_READ(_SLCR_) + +#define getPHYSR() \ + WIZCHIP_READ(_PHYSR_) + +#define setPHYRAR(phyrar) \ + WIZCHIP_WRITE(_PHYRAR_,(phyrar)) + +#define getPHYRAR() \ + WIZCHIP_READ(_PHYRAR_) + +#define setPHYDIR(phydir) \ + do{ \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_PHYDIR_,1), (uint8_t)((phydir)>>8)); \ + WIZCHIP_WRITE(_PHYDIR_, (uint8_t)(phydir)); \ + }while(0); + +#define getPHYDOR() \ + ((((uint16_t)WIZCHIP_READ(WIZCHIP_OFFSET_INC(_PHYDOR_,1))) << 8) + WIZCHIP_READ(_PHYDOR_)) + +#define setPHYACR(phyacr) \ + WIZCHIP_WRITE(_PHYACR_,(phyacr)) + +#define getPHYACR() \ + WIZCHIP_READ(_PHYACR_) + +#define setPHYDIVR(phydivr) \ + WIZCHIP_WRITE(_PHYDIVR_,(phydivr)) + +#define getPHYDIVR() \ + WIZCHIP_READ(_PHYDIVR_) + +#define setPHYCR0(phycr0) \ + WIZCHIP_WRITE(_PHYCR0_,(phycr0)) + +#define setPHYCR1(phycr1) \ + WIZCHIP_WRITE(_PHYCR1_,(phycr1)) + +#define getPHYCR1() \ + WIZCHIP_READ(_PHYCR1_) + +#define setNET4MR(net4mr) \ + WIZCHIP_WRITE(_NET4MR_,(net4mr)) + +#define setNET6MR(net6mr) \ + WIZCHIP_WRITE(_NET6MR_,(net6mr)) + +#define setNETMR(netmr) \ + WIZCHIP_WRITE(_NETMR_,(netmr)) + +#define setNETMR2(netmr2) \ + WIZCHIP_WRITE(_NETMR2_,(netmr2)) + +#define getNET4MR() \ + WIZCHIP_READ(_NET4MR_) + +#define getNET6MR() \ + WIZCHIP_READ(_NET6MR_) + +#define getNETMR() \ + WIZCHIP_READ(_NETMR_) + +#define getNETMR2() \ + WIZCHIP_READ(_NETMR2_) + +#define setPTMR(ptmr) \ + WIZCHIP_WRITE(_PTMR_, (ptmr)) + +#define getPTMR() \ + WIZCHIP_READ(_PTMR_) + +#define setPMNR(pmnr) \ + WIZCHIP_WRITE(_PMNR_, (pmnr)) + +#define getPMNR() \ + WIZCHIP_READ(_PMNR_) + +#define setPHAR(phar) \ + WIZCHIP_WRITE_BUF(_PHAR_,(phar),6) + +#define getPHAR(phar) \ + WIZCHIP_READ_BUF(_PHAR_,(phar),6) + +#define setPSIDR(psidr) \ + do{ \ + WIZCHIP_WRITE(_PSIDR_,(uint8_t)((psidr) >> 8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_PSIDR_,1),(uint8_t)(psidr)); \ + }while(0); + +#define getPSIDR() \ + ((((uint16_t)WIZCHIP_READ(_PSIDR_)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_PSIDR_,1))) + +#define setPMRUR(pmrur) \ + do{ \ + WIZCHIP_WRITE(_PMRUR_,(uint8_t)((pmrur) >> 8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_PMRUR_,1),(uint8_t)(pmrur)); \ + }while(0); + +#define getPMRUR() \ + ((((uint16_t)WIZCHIP_READ(_PMRUR_)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_PMRUR_,1))) + +#define setSHAR(shar) \ + WIZCHIP_WRITE_BUF(_SHAR_,(shar),6) + +#define getSHAR(shar) \ + WIZCHIP_READ_BUF(_SHAR_,(shar),6) + +#define setGAR(gar) \ + WIZCHIP_WRITE_BUF(_GAR_,(gar),4) + +#define getGAR(gar) \ + WIZCHIP_READ_BUF(_GAR_,(gar),4) + +#define setGA4R(ga4r) setGAR(ga4r) +#define getGA4R(ga4r) getGAR(ga4r) + +#define setSUBR(subr) \ + WIZCHIP_WRITE_BUF(_SUBR_,(subr),4) + +#define getSUBR(subr) \ + WIZCHIP_READ_BUF(_SUBR_,(subr),4) + +#define setSUB4R(sub4r) setSUBR(sub4r) +#define getSUB4R(sub4r) getSUBR(sub4r) + +#define setSIPR(sipr) \ + WIZCHIP_WRITE_BUF(_SIPR_,(sipr),4) + +#define getSIPR(sipr) \ + WIZCHIP_READ_BUF(_SIPR_,(sipr),4) + +#define setLLAR(llar) \ + WIZCHIP_WRITE_BUF(_LLAR_,(llar),16) + +#define getLLAR(llar) \ + WIZCHIP_READ_BUF(_LLAR_,(llar),16) + +#define setGUAR(guar) \ + WIZCHIP_WRITE_BUF(_GUAR_,(guar),16) + +#define getGUAR(guar) \ + WIZCHIP_READ_BUF(_GUAR_,(guar),16) + +#define setSUB6R(sub6r) \ + WIZCHIP_WRITE_BUF(_SUB6R_,(sub6r),16) + +#define getSUB6R(sub6r) \ + WIZCHIP_READ_BUF(_SUB6R_,(sub6r),16) + +#define setGA6R(ga6r) \ + WIZCHIP_WRITE_BUF(_GA6R_,(ga6r),16) + +#define getGA6R(ga6r) \ + WIZCHIP_READ_BUF(_GA6R_,(ga6r),16) + +#define setSLDIPR(sldipr) \ + WIZCHIP_WRITE_BUF(_SLDIPR_,(sldipr),4) +#define setSLDIP4R(sldip4r) setSLDIPR((sldip4r)) + +#define getSLDIPR(sldipr) \ + WIZCHIP_READ_BUF(_SLDIPR_,(sldipr),4) +#define getSLDIP4R(sldip4r) getSLDIPR((sldip4r)) + +#define setSLDIP6R(sldip6r) \ + WIZCHIP_WRITE_BUF(_SLDIP6R_, (sldip6r),16) + +#define getSLDIP6R(sldip6r) \ + WIZCHIP_READ_BUF(_SLDIP6R_,(sldip6r),16) + +#define getSLDHAR(sldhar) \ + WIZCHIP_READ_BUF(_SLDHAR_,(sldhar),6) + +#define setPINGIDR(pingidr) \ + do{ \ + WIZCHIP_WRITE(_PINGIDR_,(uint8_t)((pingidr)>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_PINGIDR_,1),(uint8_t)(pingidr)); \ + }while(0); + +#define getPINGIDR() \ + (((int16_t)(WIZCHIP_READ(_PINGIDR_) << 8)) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_PINGIDR_,1))) + +#define setPINGSEQR(pingseqr) \ + do{ \ + WIZCHIP_WRITE(_PINGSEQR_,(uint8_t)((pingseqr)>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_PINGSEQR_,1),(uint8_t)(pingseqr)); \ + }while(0); + +#define getPINGSEQR() \ + (((int16_t)(WIZCHIP_READ(_PINGSEQR_) << 8)) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_PINGSEQR_,1))) + +#define getUIPR(uipr) \ + WIZCHIP_READ_BUF(_UIPR_, (uipr), 4) + +#define getUIP4R(uip4r) getUIPR(uip4r) + +#define getUPORTR() \ + ((((uint16_t)WIZCHIP_READ(_UPORTR_)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_UPORTR_,1))) + +#define getUPORT4R() getUPORTR() + +#define getUIP6R(uip6r) \ + WIZCHIP_READ_BUF(_UIP6R_,(uip6r),16) + +#define getUPORT6R(uport6r) \ + ((((uint16_t)WIZCHIP_READ(_UPORT6R_)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_UPORT6R_,1))) + +#define setINTPTMR(intptmr) \ + do{ \ + WIZCHIP_WRITE(_INTPTMR_,(uint8_t)((intptmr) >> 8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_INTPTMR_,1),(uint8_t)(intptmr)); \ + }while(0); + +#define getINTPTMR() \ + ((((uint16_t)WIZCHIP_READ(_INTPTMR_)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_INTPTMR_,1))) + +#define getPLR() \ + WIZCHIP_READ(_PLR_) + +#define getPFR() \ + WIZCHIP_READ(_PFR_) + +#define getVLTR() \ + ( (((uint32_t)WIZCHIP_READ(_VLTR_)) << 24) + \ + (((uint32_t)WIZCHIP_READ(WIZCHIP_OFFSET_INC(_VLTR_,1))) << 16) + \ + (((uint32_t)WIZCHIP_READ(WIZCHIP_OFFSET_INC(_VLTR_,2))) << 16) + \ + (((uint32_t)WIZCHIP_READ(WIZCHIP_OFFSET_INC(_VLTR_,3))) << 16) ) + +#define getPLTR() \ + ( (((uint32_t)WIZCHIP_READ(_PLTR_)) << 24) + \ + (((uint32_t)WIZCHIP_READ(WIZCHIP_OFFSET_INC(_PLTR_,1))) << 16) + \ + (((uint32_t)WIZCHIP_READ(WIZCHIP_OFFSET_INC(_PLTR_,2))) << 16) + \ + (((uint32_t)WIZCHIP_READ(WIZCHIP_OFFSET_INC(_PLTR_,3))) << 16) ) + +#define getPAR(par) \ + WIZCHIP_READ_BUF(_PAR_, (par), 16) + +#define setICMP6BLKR(icmp6blkr) \ + WIZCHIP_WRITE(_ICMP6BLKR_,(icmp6blkr)) + +#define getICMP6BLKR() \ + WIZCHIP_READ(_ICMP6BLKR_) + +#define setCHPLCKR(chplckr) \ + WIZCHIP_WRITE(_CHPLCKR_, (chplckr)) + +#define getCHPLCKR() \ + ((getSYSR() & SYSR_CHPL) >> 7) + +#define CHIPLOCK() setCHPLCKR(0xFF) +#define CHIPUNLOCK() setCHPLCKR(0xCE) + +#define setNETLCKR(netlckr) \ + WIZCHIP_WRITE(_NETLCKR_, (netlckr)) + +#define getNETLCKR() \ + ((getSYSR() & SYSR_NETL) >> 6) + +#define NETLOCK() setNETLCKR(0xC5) +#define NETUNLOCK() setNETLCKR(0x3A) + +#define setPHYLCKR(phylckr) \ + WIZCHIP_WRITE(_PHYLCKR_,(phylckr)) + +#define getPHYLCKR() \ + ((getSYSR() & SYSR_PHYL) >> 5) + +#define PHYLOCK() setPHYLCKR(0xFF) +#define PHYUNLOCK() setPHYLCKR(0x53) + +#define setRTR(rtr) \ + do{ \ + WIZCHIP_WRITE(_RTR_,(uint8_t)((rtr)>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_RTR_,1),(uint8_t)(rtr)); \ + }while(0); + +#define getRTR() \ + ((((uint16_t)WIZCHIP_READ(_RTR_)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_RTR_,1))) + +#define setRCR(rcr) \ + WIZCHIP_WRITE(_RCR_,(rcr)) + +#define getRCR() \ + WIZCHIP_READ(_RCR_) + +#define setSLRTR(slrtr) \ + do{ \ + WIZCHIP_WRITE(_SLRTR_,(uint8_t)((slrtr)>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_SLRTR_,1),(uint8_t)(slrtr)); \ + }while(0); + +#define getSLRTR() \ + ((((uint16_t)WIZCHIP_READ(_SLRTR_)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_SLRTR_,1))) + +#define setSLRCR(slrcr) \ + WIZCHIP_WRITE(_SLRCR_,(slrcr)) + +#define getSLRCR() \ + WIZCHIP_READ(_SLRCR_) + +#define setSLHOPR(slhopr) \ + WIZCHIP_WRITE(_SLHOPR_,(slhopr)) + +#define getSLHOPR() \ + WIZCHIP_READ(_SLHOPR_) +/** + @} +*/ + + +//////////////////////////////////// +// SOCKETn register I/O function // +//////////////////////////////////// +/** + @addtogroup Socket_register_access_function_W6100 + @{ +*/ +#define setSn_MR(sn,mr) \ + WIZCHIP_WRITE(_Sn_MR_(sn),(mr)) +#define getSn_MR(sn) \ + WIZCHIP_READ(_Sn_MR_(sn)) + +#define setSn_PSR(sn,psr) \ + WIZCHIP_WRITE(_Sn_PSR_(sn),(psr)) +#define getSn_PSR(sn) \ + WIZCHIP_READ(_Sn_PSR_(sn)) + +#define setSn_CR(sn,cr) \ + WIZCHIP_WRITE(_Sn_CR_(sn),(cr)) +#define getSn_CR(sn) \ + WIZCHIP_READ(_Sn_CR_(sn)) + +#define getSn_IR(sn) \ + WIZCHIP_READ(_Sn_IR_(sn)) + +#define setSn_IMR(sn,imr) \ + WIZCHIP_WRITE(_Sn_IMR_(sn),(imr)) +#define getSn_IMR(sn) \ + WIZCHIP_READ(_Sn_IMR_(sn)) + +#define setSn_IRCLR(sn,irclr) \ + WIZCHIP_WRITE(_Sn_IRCLR_(sn),(irclr)) +#define setSn_IR(sn,ir) setSn_IRCLR(sn,(ir)) + +#define getSn_SR(sn) \ + WIZCHIP_READ(_Sn_SR_(sn)) + +#define getSn_ESR(sn) \ + WIZCHIP_READ(_Sn_ESR_(sn)) + +#define setSn_PNR(sn,pnr) \ + WIZCHIP_WRITE(_Sn_PNR_(sn),(pnr)) +#define setSn_NHR(sn,nhr) setSn_PNR(_Sn_PNR_(sn),(nhr)) + +#define getSn_PNR(sn) \ + WIZCHIP_READ(_Sn_PNR_(sn)) +#define getSn_NHR(sn) getSn_PNR(sn) + +#define setSn_TOSR(sn,tosr) \ + WIZCHIP_WRITE(_Sn_TOSR_(sn),(tosr)) +#define getSn_TOSR(sn) \ + WIZCHIP_READ(_Sn_TOSR_(sn)) +#define getSn_TOS(sn) getSn_TOSR(sn) ///< For compatible ioLibrar +#define setSn_TOS(sn,tos) setSn_TOSR(sn,tos) ///< For compatible ioLibrar + + +#define setSn_TTLR(sn,ttlr) \ + WIZCHIP_WRITE(_Sn_TTLR_(sn),(ttlr)) +#define setSn_TTL(sn,ttl) setSn_TTLR(sn,ttl) ///< For compatible ioLibrary + +#define getSn_TTLR(sn) \ + WIZCHIP_READ(_Sn_TTLR_(sn)) +#define getSn_TTL(sn) getSn_TTLR(sn) ///< For compatible ioLibrary + + +#define setSn_HOPR(sn,hopr) setSn_TTLR(sn),(ttlr)) +#define getSn_HOPR(sn) getSn_TTLR(sn) + +#define setSn_FRGR(sn,frgr) \ + do{ \ + WIZCHIP_WRITE(_Sn_FRGR_(sn),(uint8_t)((frgr)>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_Sn_FRGR_(sn),1),(uint8_t)(frgr)); \ + }while(0); +#define getSn_FRGR(sn,frgr) \ + ((((uint16_t)WIZCHIP_READ(_Sn_FRGR_(sn))) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_Sn_FRGR_(sn),1))) + +#define setSn_MSSR(sn,mssr) \ + do{ \ + WIZCHIP_WRITE(_Sn_MSSR_(sn),(uint8_t)((mssr)>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_Sn_MSSR_(sn),1),(uint8_t)(mssr)); \ + }while(0); +#define getSn_MSSR(sn) \ + ((((uint16_t)WIZCHIP_READ(_Sn_MSSR_(sn))) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_Sn_MSSR_(sn),1))) + +#define setSn_PORTR(sn,portr) \ + do{ \ + WIZCHIP_WRITE(_Sn_PORTR_(sn),(uint8_t)((portr)>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_Sn_PORTR_(sn),1),(uint8_t)(portr)); \ + }while(0); +#define getSn_PORTR(sn) \ + ((((uint16_t)WIZCHIP_READ(_Sn_PORTR_(sn))) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_Sn_PORTR_(sn),1))) + +#define setSn_DHAR(sn,dhar) \ + WIZCHIP_WRITE_BUF(_Sn_DHAR_(sn),(dhar),6) +#define getSn_DHAR(sn,dhar) \ + WIZCHIP_READ_BUF(_Sn_DHAR_(sn),(dhar),6) + +#define setSn_DIPR(sn,dipr) \ + WIZCHIP_WRITE_BUF(_Sn_DIPR_(sn),(dipr),4) +#define getSn_DIPR(sn,dipr) \ + WIZCHIP_READ_BUF(_Sn_DIPR_(sn),(dipr),4) + +#define setSn_DIP4R(sn,dipr) setSn_DIPR(sn,(dipr)) +#define getSn_DIP4R(sn,dipr) getSn_DIPR(sn,(dipr)) + +#define setSn_DIP6R(sn,dip6r) \ + WIZCHIP_WRITE_BUF(_Sn_DIP6R_(sn),(dip6r),16) +#define getSn_DIP6R(sn,dip6r) \ + WIZCHIP_READ_BUF(_Sn_DIP6R_(sn),(dip6r),16) + +#define setSn_DPORTR(sn,dportr) \ + do{ \ + WIZCHIP_WRITE(_Sn_DPORTR_(sn),(uint8_t)((dportr)>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_Sn_DPORTR_(sn),1),(uint8_t)(dportr)); \ + }while(0); +#define getSn_DPORTR(sn) \ + ((((uint16_t)WIZCHIP_READ(_Sn_DPORTR_(sn))) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_Sn_DPORTR_(sn),1))) +#define getSn_DPORT(sn) getSn_DPORTR(sn) +#define setSn_DPORT(sn,dportr) setSn_DPORTR(sn,dportr) + +#define setSn_MR2(sn,mr2) \ + WIZCHIP_WRITE(_Sn_MR2_(sn),(mr2)) +#define getSn_MR2(sn) \ + WIZCHIP_READ(_Sn_MR2_(sn)) + +#define setSn_RTR(sn,rtr) \ + do{ \ + WIZCHIP_WRITE(_Sn_RTR_(sn),(uint8_t)((rtr)>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_Sn_RTR_(sn),1),(uint8_t)(rtr)); \ + }while(0); +#define getSn_RTR(sn) \ + ((((uint16_t)WIZCHIP_READ(_Sn_RTR_(sn))) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_Sn_RTR_(sn),1))) + +#define setSn_RCR(sn,rcr) \ + WIZCHIP_WRITE(_Sn_RCR_(sn),(rcr)) +#define getSn_RCR(sn) \ + WIZCHIP_READ(_Sn_RCR_(sn)) + +#define setSn_KPALVTR(sn,kpalvtr) \ + WIZCHIP_WRITE(_Sn_KPALVTR_(sn),(kpalvtr)) +#define getSn_KPALVTR(sn) \ + WIZCHIP_READ(_Sn_KPALVTR_(sn)) + +#define setSn_TX_BSR(sn, tmsr) \ + WIZCHIP_WRITE(_Sn_TX_BSR_(sn),(tmsr)) +#define setSn_TXBUF_SIZE(sn, tmsr) setSn_TX_BSR(sn,(tmsr)) + +#define getSn_TX_BSR(sn) \ + WIZCHIP_READ(_Sn_TX_BSR_(sn)) +#define getSn_TXBUF_SIZE(sn) getSn_TX_BSR(sn) + +#define getSn_TxMAX(sn) \ + (getSn_TX_BSR(sn) << 10) + +uint16_t getSn_TX_FSR(uint8_t sn); + +#define getSn_TX_RD(sn) \ + ((((uint16_t)WIZCHIP_READ(_Sn_TX_RD_(sn))) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_Sn_TX_RD_(sn),1))) + +#define setSn_TX_WR(sn,txwr) \ + do{ \ + WIZCHIP_WRITE(_Sn_TX_WR_(sn), (uint8_t)((txwr)>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_Sn_TX_WR_(sn),1), (uint8_t)(txwr)); \ + }while(0); +#define getSn_TX_WR(sn) \ + (((uint16_t)WIZCHIP_READ(_Sn_TX_WR_(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_Sn_TX_WR_(sn),1))) + +#define setSn_RX_BSR(sn,rmsr) \ + WIZCHIP_WRITE(_Sn_RX_BSR_(sn),(rmsr)) +#define setSn_RXBUF_SIZE(sn,rmsr) setSn_RX_BSR(sn,(rmsr)) + +#define getSn_RX_BSR(sn) \ + WIZCHIP_READ(_Sn_RX_BSR_(sn)) +#define getSn_RXBUF_SIZE(sn) getSn_RX_BSR(sn) + +#define getSn_RxMAX(sn) \ + (getSn_RX_BSR(sn) <<10) + +uint16_t getSn_RX_RSR(uint8_t s); + +#define setSn_RX_RD(sn,rxrd) \ + do{ \ + WIZCHIP_WRITE(_Sn_RX_RD_(sn), (uint8_t)((rxrd)>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_Sn_RX_RD_(sn),1), (uint8_t)(rxrd)) ; \ + }while(0); + +#define getSn_RX_RD(sn) \ + (((uint16_t)WIZCHIP_READ(_Sn_RX_RD_(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_Sn_RX_RD_(sn),1))) + +#define getSn_RX_WR(sn) \ + (((uint16_t)WIZCHIP_READ(_Sn_RX_WR_(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_Sn_RX_WR_(sn),1))) +/** + @} +*/ + + +///////////////////////////////////// +// Sn_TXBUF & Sn_RXBUF IO function // +///////////////////////////////////// +/** + @ingroup Basic_IO_function_W6100 + @brief It saves data to be sent in the SOCKETn TX buffer. + @details This function reads first @ref _Sn_TX_WR_ \n + and starts to copy wizdata from @ref _Sn_TX_WR_ address of SOCKETn TX buffer as many as len.\n + After it is completed to copy , \n + It increases @ref _Sn_TX_WR_ as many as len. + @param sn SOCKETn. 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_W6100 + @brief It reads the received data from the SOCKETn RX buffer and copies the data to your system memory specified by wizdata. + @details This function reads first @ref _Sn_RX_RD_ \n + and starts to copy the received data to wizdata as many as len.\n + After it is completed to copy the received data, \n + It increases @ref _Sn_RX_RD_ as many as len. + @param sn SOCKETn. 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_W6100 + @brief It discards the received data in the SOCKETn RX buffer. + @details This function discards the received data by increasing @ref _Sn_RX_RD_ as manay as len without coping the data. + @param sn SOCKETn. It should be 0 ~ @ref _WIZCHIP_SOCK_NUM_. + @param len Data length +*/ +void wiz_recv_ignore(uint8_t sn, uint16_t len); + +#if 1 +// 20231019 taylor +/** + @ingroup Special_function_W6100 + @brief Delay function + @details Delay function using internal 100us timer of the W6100 + @param (uint32_t)ms Time to delay in milliseconds. +*/ +void wiz_delay_ms(uint32_t ms); +#endif + +/// @cond DOXY_APPLY_CODE +#if (_PHY_IO_MODE_ == _PHY_IO_MODE_MII_) +/// @endcond +/** + @ingroup Special_function_W6100 + @brief Write data to the PHY via MDC/MDIO interface. + @details Write command data to the PHY via MDC/MDIO interface. + @param phyregaddr Address of the PHY register. It should be @ref PHYRAR_BMCR, @ref PHYRAR_BMSR, and etc. + @param var Data to write to the PHY register. Please refer to the bit definitions of the BMCR and BMSR register. + @note In order to use it, You should define @ref _PHY_IO_MODE_ to @ref _PHY_IO_MODE_MII_. +*/ +void wiz_mdio_write(uint8_t phyregaddr, uint16_t var); + +/** + @ingroup Special_function_W6100 + @brief Read data from the PHY via MDC/MDIO interface. + @details Read command or status data from the PHY via MDC/MDIO interface. + @param phyregaddr Address of the PHY register. It should be @ref PHYRAR_BMCR, @ref PHYRAR_BMSR, and etc. + @return The value of the PHY register + @note In order to use it, You should define @ref _PHY_IO_MODE_ to @ref _PHY_IO_MODE_MII_. +*/ +uint16_t wiz_mdio_read(uint8_t phyregaddr); +/// @cond DOXY_APPLY_CODE +#endif +/// @endcond + +/// @cond DOXY_APPLY_CODE +#endif // _WIZCHIP_ == 6100 +/// @endcond + + +#ifdef __cplusplus +} +#endif + + +#endif //_W6100_H_ diff --git a/Ethernet/W6300/w6300.c b/Ethernet/W6300/w6300.c new file mode 100644 index 0000000..1c8192a --- /dev/null +++ b/Ethernet/W6300/w6300.c @@ -0,0 +1,273 @@ +//***************************************************************************** +// +//! \file W6300.c +//! \brief W6300 HAL Implements file. +//! \version 1.0.0 +//! \date 2019/01/01 +//! \par Revision history +//! <2019/01/01> 1st Release +//! \author MidnightCow +//! \copyright +//! +//! Copyright (c) 2019, WIZnet Co., LTD. +//! +//! Permission is hereby granted, free of charge, to any person obtaining a copy +//! of this software and associated documentation files (the "Software"), to deal +//! in the Software without restriction, including without limitation the rights +//! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +//! copies of the Software, and to permit persons to whom the Software is +//! furnished to do so, subject to the following conditions: +//! +//! The above copyright notice and this permission notice shall be included in +//! all copies or substantial portions of the Software. +//! +//! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +//! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +//! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +//! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +//! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +//! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +//! SOFTWARE. +//! +//***************************************************************************** + +#include "w6300.h" + + +#if 0 +#define _WIZCHIP_SPI_VDM_OP_ 0x00 +#define _WIZCHIP_SPI_FDM_LEN1_ 0x01 +#define _WIZCHIP_SPI_FDM_LEN2_ 0x02 +#define _WIZCHIP_SPI_FDM_LEN4_ 0x03 +#endif +// +// If you want to use SPI FDM mode, Feel free contact to WIZnet. +// http://forum.wiznet.io +// + +#if _WIZCHIP_ == 6300 +//////////////////////////////////////////////////////////////////////////////////////// + + +#define _W6300_SPI_OP_ _WIZCHIP_SPI_VDM_OP_ +#define _W6300_SPI_READ_ (0x00 << 5) ///< SPI interface Read operation in Control Phase +#define _W6300_SPI_WRITE_ (0x01 << 5) ///< SPI interface Write operation in Control Phase + +////////////////////////////////////////////////// +void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb) { + + uint8_t opcode = 0; + uint16_t ADDR = 0; + + WIZCHIP_CRITICAL_ENTER(); + WIZCHIP.CS._select(); + +#if (_WIZCHIP_IO_MODE_ & 0xff00) & _WIZCHIP_IO_MODE_BUS_ + uint8_t tAD[4]; + tAD[0] = (uint8_t)((AddrSel & 0x00FF0000) >> 16); + tAD[1] = (uint8_t)((AddrSel & 0x0000FF00) >> 8); + tAD[2] = (uint8_t)(AddrSel & 0x000000ff); + tAD[3] = wb; + WIZCHIP.IF.BUS._write_data_buf(IDM_AR0, tAD, 4, 1); +#else //w6300 QSPI MODE + opcode = (uint8_t)((AddrSel & 0x000000FF) | (_W6300_SPI_WRITE_) | (_WIZCHIP_QSPI_MODE_)); + ADDR = (uint16_t)((AddrSel & 0x00ffff00) >> 8); + WIZCHIP.IF.QSPI._write_qspi(opcode, ADDR, &wb, 1); +#endif + + WIZCHIP.CS._deselect(); + WIZCHIP_CRITICAL_EXIT(); +} + +uint8_t WIZCHIP_READ(uint32_t AddrSel) { + //uint8_t ret; + uint8_t ret[2] = {0,}; + uint8_t opcode = 0; + uint16_t ADDR = 0; + + WIZCHIP_CRITICAL_ENTER(); + WIZCHIP.CS._select(); + +#if (_WIZCHIP_IO_MODE_ & 0xff00) & _WIZCHIP_IO_MODE_BUS_ + uint8_t tAD[3]; + tAD[0] = (uint8_t)((AddrSel & 0x00FF0000) >> 16); + tAD[1] = (uint8_t)((AddrSel & 0x0000FF00) >> 8); + tAD[2] = (uint8_t)(AddrSel & 0x000000ff); + WIZCHIP.IF.BUS._write_data_buf(IDM_AR0, tAD, 3, 1); + ret[0] = WIZCHIP.IF.BUS._read_data(IDM_DR); +#else + opcode = (uint8_t)((AddrSel & 0x000000FF) | (_W6300_SPI_READ_) | (_WIZCHIP_QSPI_MODE_)); + ADDR = (uint16_t)((AddrSel & 0x00ffff00) >> 8); + WIZCHIP.IF.QSPI._read_qspi(opcode, ADDR, ret, 1); +#endif + WIZCHIP.CS._deselect(); + WIZCHIP_CRITICAL_EXIT(); + return ret[0]; +} + + +void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, datasize_t len) { + + uint8_t opcode = 0; + uint16_t ADDR = 0; + + WIZCHIP_CRITICAL_ENTER(); + WIZCHIP.CS._select(); + +#if (_WIZCHIP_IO_MODE_ & 0xff00) & _WIZCHIP_IO_MODE_BUS_ + uint8_t tAD[3]; + tAD[0] = (uint8_t)((AddrSel & 0x00FF0000) >> 16); + tAD[1] = (uint8_t)((AddrSel & 0x0000FF00) >> 8); + tAD[2] = (uint8_t)(AddrSel & 0x000000ff); + WIZCHIP.IF.BUS._write_data_buf(IDM_AR0, tAD, 3, 1); + WIZCHIP.IF.BUS._write_data_buf(IDM_DR, pBuf, len, 0); +#else + opcode = (uint8_t)((AddrSel & 0x000000FF) | (_W6300_SPI_WRITE_) | (_WIZCHIP_QSPI_MODE_)); + ADDR = (uint16_t)((AddrSel & 0x00ffff00) >> 8); + WIZCHIP.IF.QSPI._write_qspi(opcode, ADDR, pBuf, len);//by_lihan + //qspi_write_buf(opcode, ADDR, pBuf, len); + WIZCHIP.CS._deselect(); + WIZCHIP_CRITICAL_EXIT(); +#endif +} + +void WIZCHIP_READ_BUF(uint32_t AddrSel, uint8_t* pBuf, datasize_t len) { + + uint8_t ret; + uint8_t opcode = 0; + uint16_t ADDR = 0; + + WIZCHIP_CRITICAL_ENTER(); + WIZCHIP.CS._select(); + +#if _WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_ + uint8_t tAD[3]; + tAD[0] = (uint8_t)((AddrSel & 0x00FF0000) >> 16); + tAD[1] = (uint8_t)((AddrSel & 0x0000FF00) >> 8); + tAD[2] = (uint8_t)(AddrSel & 0x000000ff); + WIZCHIP.IF.BUS._write_data_buf(IDM_AR0, tAD, 3, 1); + WIZCHIP.IF.BUS._read_data_buf(IDM_DR, pBuf, len, 0); +#else + opcode = (uint8_t)((AddrSel & 0x000000FF) | (_W6300_SPI_READ_) | (_WIZCHIP_QSPI_MODE_)); + ADDR = (uint16_t)((AddrSel & 0x00ffff00) >> 8); + WIZCHIP.IF.QSPI._read_qspi(opcode, ADDR, pBuf, len);//by_lihan + //qspi_read_buf(opcode, ADDR, pBuf, len); + WIZCHIP.CS._deselect(); + WIZCHIP_CRITICAL_EXIT(); +#endif +} + +uint16_t getSn_TX_FSR(uint8_t sn) { + uint16_t prev_val = -1, val = 0; + do { + prev_val = val; + val = WIZCHIP_READ(_Sn_TX_FSR_(sn)); + val = (val << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_Sn_TX_FSR_(sn), 1)); + } while (val != prev_val); + return val; +} + +uint16_t getSn_RX_RSR(uint8_t sn) { + uint16_t prev_val = -1, val = 0; + do { + prev_val = val; + val = WIZCHIP_READ(_Sn_RX_RSR_(sn)); + val = (val << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_Sn_RX_RSR_(sn), 1)); + } while (val != prev_val); + return val; +} + +void wiz_send_data(uint8_t sn, uint8_t *wizdata, uint16_t len) { + uint16_t ptr = 0; + uint32_t addrsel = 0; + ptr = getSn_TX_WR(sn); + addrsel = ((uint32_t)ptr << 8) + WIZCHIP_TXBUF_BLOCK(sn); + WIZCHIP_WRITE_BUF(addrsel, wizdata, len); + ptr += len; + setSn_TX_WR(sn, ptr); +} + +#if 0 +#define ETHERNET_BUF_MAX_SIZE_TEMP (1024 * 32 ) +void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint16_t len) { + uint16_t ptr = 0; + uint32_t addrsel = 0; + if (len == 0) { + return; + } + ptr = getSn_RX_RD(sn); + + if (ptr + len > 0xFFFF) { + addrsel = ((uint32_t)ptr << 8) + WIZCHIP_RXBUF_BLOCK(sn); + uint16_t size = 0xFFFF - ptr; + WIZCHIP_READ_BUF(addrsel, wizdata, size); + wizdata += size; + size = len - size; + addrsel = WIZCHIP_RXBUF_BLOCK(sn); + WIZCHIP_READ_BUF(addrsel, wizdata, size); + } else { + addrsel = ((uint32_t)ptr << 8) + WIZCHIP_RXBUF_BLOCK(sn); + WIZCHIP_READ_BUF(addrsel, wizdata, len); + } + + ptr += len; + ptr %= 0xFFFF ; + + setSn_RX_RD(sn, ptr); +} + + +#else +void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint16_t len) { + uint16_t ptr = 0; + uint32_t addrsel = 0; + if (len == 0) { + return; + } + ptr = getSn_RX_RD(sn); + addrsel = ((uint32_t)ptr << 8) + WIZCHIP_RXBUF_BLOCK(sn); + WIZCHIP_READ_BUF(addrsel, wizdata, len); + ptr += len; + setSn_RX_RD(sn, ptr); +} +#endif +void wiz_recv_ignore(uint8_t sn, uint16_t len) { + setSn_RX_RD(sn, getSn_RX_RD(sn) + len); +} + +#if 1 +// 20231019 taylor +void wiz_delay_ms(uint32_t milliseconds) { + uint32_t i; + for (i = 0 ; i < milliseconds ; i++) { + //Write any values to clear the TCNTCLKR register + setTCNTRCLR(0xff); + + // Wait until counter register value reaches 10.(10 = 1ms : TCNTR is 100us tick counter register) + while (getTCNTR() < 0x0a) {} + } +} +#endif + +/// @cond DOXY_APPLY_CODE +#if (_PHY_IO_MODE_ == _PHY_IO_MODE_MII_) +/// @endcond +void wiz_mdio_write(uint8_t phyregaddr, uint16_t var) { + setPHYRAR(phyregaddr); + setPHYDIR(var); + setPHYACR(PHYACR_WRITE); + while (getPHYACR()); //wait for command complete +} + +uint16_t wiz_mdio_read(uint8_t phyregaddr) { + setPHYRAR(phyregaddr); + setPHYACR(PHYACR_READ); + while (getPHYACR()); //wait for command complete + return getPHYDOR(); +} +/// @cond DOXY_APPLY_CODE +#endif +/// @endcond + +//////////////////////////////////////////////////////////////////////////////////////// +#endif diff --git a/Ethernet/W6300/w6300.h b/Ethernet/W6300/w6300.h new file mode 100644 index 0000000..240c7aa --- /dev/null +++ b/Ethernet/W6300/w6300.h @@ -0,0 +1,4103 @@ +//* **************************************************************************** +//! \file W6300.h +//! \brief W6300 HAL Header File. +//! \version 1.0.0 +//! \date 2019/01/01 +//! \par Revision history +//! <2019/01/01> 1st Release +//! \author MidnightCow +//! \copyright +//! +//! Copyright (c) 2019, WIZnet Co., LTD. +//! +//! Permission is hereby granted, free of charge, to any person obtaining a copy +//! of this software and associated documentation files (the "Software"), to deal +//! in the Software without restriction, including without limitation the rights +//! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +//! copies of the Software, and to permit persons to whom the Software is +//! furnished to do so, subject to the following conditions: +//! +//! The above copyright notice and this permission notice shall be included in +//! all copies or substantial portions of the Software. +//! +//! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +//! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +//! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +//! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +//! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +//! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +//! SOFTWARE. +//! +//***************************************************************************** + + +#ifndef _W6300_H_ +#define _W6300_H_ + +#include +#include "wizchip_conf.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +/// @cond DOXY_APPLY_CODE +#if (_WIZCHIP_ == W6300) +/// @endcond + +#define _W6300_SPI_READ_ (0x00 << 5) ///< SPI interface Read operation in Control Phase +#define _W6300_SPI_WRITE_ (0x01 << 5) ///< SPI interface Write operation in Control Phase + +#define WIZCHIP_CREG_BLOCK (0x00 ) ///< Common register block +#define WIZCHIP_SREG_BLOCK(N) ((1+4*N)) ///< SOCKETn register block +#define WIZCHIP_TXBUF_BLOCK(N) ((2+4*N)) ///< SOCKETn Tx buffer address block +#define WIZCHIP_RXBUF_BLOCK(N) ((3+4*N)) ///< SOCKETn Rx buffer address block + +#define WIZCHIP_OFFSET_INC(ADDR, N) (ADDR + (N<<8)) ///< Increase offset address + +#if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_) +#define IDM_AR0 ((_WIZCHIP_IO_BASE_ + 0x0000)) ///< Indirect High Address Register +#define IDM_AR1 ((_WIZCHIP_IO_BASE_ + 0x0001)) ///< Indirect Low Address Register +#define IDM_BSR ((_WIZCHIP_IO_BASE_ + 0x0002)) ///< Block Select Register +#define IDM_DR ((_WIZCHIP_IO_BASE_ + 0x0003)) ///< Indirect Data Register +#define _W6300_IO_BASE_ _WIZCHIP_IO_BASE_ +#elif (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_) +#define IDM_AR0 ((_WIZCHIP_IO_BASE_ + 0x0000)) ///< Indirect High Address Register +#define IDM_AR1 ((_WIZCHIP_IO_BASE_ + 0x0001)) ///< Indirect Low Address Register +#define IDM_BSR ((_WIZCHIP_IO_BASE_ + 0x0002)) ///< Block Select Register +#define IDM_DR ((_WIZCHIP_IO_BASE_ + 0x0003)) ///< Indirect Data Register +#define _W6300_IO_BASE_ 0x00000000 +#define _W6100_IO_BASE_ 0x00000000 +#endif + + +//----------- defgroup -------------------------------- + +/** + @defgroup W6300 W6300 + @brief @ref _WIZCHIP_ register defines and I/O functions + @details + - @ref WIZCHIP_register_W6300 : @ref Common_register_group_W6300, @ref Socket_register_group_W6300 + - @ref WIZCHIP_IO_Functions_W6300 : @ref Basic_IO_function_W6300, @ref Common_register_access_function_W6300, @ref Socket_register_access_function_W6300 +*/ + +/** + @defgroup WIZCHIP_register_W6300 WIZCHIP register + @ingroup W6300 + @brief @ref WIZCHIP_register_W6300 defines register group of @b W6300. + @details + - @ref Common_register_group_W6300 : Common register group W6300 + - @ref Socket_register_group_W6300 : SOCKET n register group W6300 +*/ + +/** + @defgroup Basic_IO_function_W6300 Basic I/O function + @ingroup WIZCHIP_IO_Functions_W6300 + @brief These are basic input/output functions to read values from register or write values to register. +*/ + +/** + @defgroup Common_register_access_function_W6300 Common register access functions + @ingroup WIZCHIP_IO_Functions_W6300 + @brief These are functions to access @ref Common_register_group_W6300. +*/ + +/** + @defgroup Socket_register_access_function_W6300 Socket register access functions + @ingroup WIZCHIP_IO_Functions_W6300 + @brief These are functions to access @ref Socket_register_group_W6300. +*/ + +/** + @defgroup WIZCHIP_IO_Functions_W6300 WIZCHIP I/O functions + @ingroup W6300 + @brief @ref WIZCHIP_IO_Functions_W6300 supports the basic I/O functions for @ref WIZCHIP_register_W6300. + @details + - @ref WIZCHIP_IO_Functions_W6300 \n + WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF() + - @ref Common_register_access_function_W6300 \n + - @ref _WIZCHIP_ Mode \n + getCIDR(), getVER() \n + getSYSR() \n + setCHPLCKR(), setNETLCKR(), setPHYLCKR() \n + setSYCR0(), getSYCR1(), setSYCR1() + - Network Mode \n + getNET4MR(), setNET4MR(), getNET6MR(), setNET6MR(), getNETMR(), setNETMR(), getNETMR2(), setNETMR2() + - Interrupt \n + getIR(), setIRCLR(), getIMR(), setIMR() \n + getSIR(), getSIMR(), setSIMR() \n + getSLIR(), setSLIRCLR(), getSLIMR(), setSLIMR() \n + getINTPTMR(), setINTPTMR() + - Network Information \n + NETLOCK(), NETUNLOCK() \n + getSHAR(), setSHAR(), getGAR(), setGAR(), getSUBR(), setSUBR(), getSIPR(), setSIPR() \n + getLLAR(), setLLAR(), getGUAR(), setGUAR(), getGA6R(), setGA6R(), getSUB6R(), setSUB6R() \n + getPLR(), getPFR(), getVLTR(), getPLTR(), getPAR() \n + - SOCKET-less Commands for PING, ARP and IPv6 Auto-Configuration \n + getSLCR(), setSLCR() \n + getPINGIDR(), setPINGIDR(), getPINGSEQR(), setPINGSEQR() \n + getSLDHAR(), getSLDIPR(), setSLDIPR(), getSLDIP4R(), setSLDIP4R(), getSLDIP6R(), setSLDIP6R(), getSLHOPR(), setSLHOPR() \n + - Retransmission \n + getRCR(), setRCR() \n + getSLRCR(), setSLRCR(), getSLRTR(), setSLRTR() \n + - ICMP \n + getUIPR(), getUIP6R(), getUPORTR(), getUPORT6R() \n + getICMP6BLKR(), setICMP6BLKR() \n + - PPPoE \n + getPTMR(), setPTMR(), getPMNR(), getPMNR() \n + getPHAR(), setPHAR(), getPSIDR(), setPSIDR(), getPMRUR(), setPMRUR() + - PHY Configuration \n + getPHYSR(), setPHYLCKR(), PHYLOCK(), PHYUNLOCK() \n + setPHYCR0(), getPHYCR1(), setPHYCR1() \n + getPHYRAR(), setPHYRAR(), setPHYDIR(), getPHYDOR(), getPHYACR(), setPHYACR(), getPHYDIVR(), setPHYDIVR() + - etc \n + getTCNTR(), setTCNTRCLR() + - @ref Socket_register_access_function_W6300 \n + - SOCKET control \n + getSn_MR(), setSn_MR(), getSn_MR2(), setSn_MR2(), getSn_PSR(), setSn_PSR(), getSn_CR(), setSn_CR() \n + getSn_IR(), setSn_IRCLR(), getSn_IMR(), setSn_IMR() \n + getSn_RTR(), setSn_RTR(), getSn_RCR(), setSn_RCR(), getSn_KPALVTR(), setSn_KPALVTR() + - SOCKET information \n + getSn_SR(), getSn_ESR() \n + getSn_DHAR(), setSn_DHAR(), getSn_PORTR(), setSn_PORTR(), getSn_DPORTR(), setSn_DPORTR() \n + getSn_DIPR(), setSn_DIPR(), getSn_DIP6R(), setSn_DIP6R() \n + getSn_MSSR(), setSn_MSSR() + - SOCKET communication \n + getSn_RX_BSR(), setSn_RX_BSR(), getSn_TX_BSR(), setSn_TX_BSR() \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_FRGR(), setSn_FRGR(), getSn_TOSR(), setSn_TOSR() \n + getSn_TTLR(), setSn_TTLR() +*/ + +/** + @defgroup Common_register_group_W6300 Common register + @ingroup WIZCHIP_register_W6300 + @brief Common register group \n + @details It set the general configuration such as interrupt, network information, ICMP, and etc. + @sa + + + + + + + + + + + + +
@ref _WIZCHIP_ Information : _CIDR_, _VER_
@ref _WIZCHIP_ Mode : _SYSR_, _SYCR0_, _SYCR1_, _CHPLCKR_, _NETLCKR_, _PHYLCKR_
Network Mode : _NET4MR_, _NET6MR_, _NETMR_, _NETMR2_
Network Information : _GAR_, _SUBR_, _SHAR_, _SIPR_, _GA6R_, _LLAR_, _GUAR_, _SUB6R_
Interrupt : _IR_, _IRCLR_, _IMR_, _SIR_, _SIMR_, _SLIR_, _SLIMR_, _SLIRCLR_, _INTPTMR_
Data retransmission : _RTR_, _RCR_, _SLRTR_, _SLRCR_, _SLHOPR_
PPPoE : _PHAR_, _PSIDR_, _PMRUR_, _PTMR_, _PMNR_
SOCKET-less command : _SLCR_, _SLIR_, _SLDIPR_, _SLDIP4R_, _SLDIP6R_, _SLDHAR_, _PINGIDR_, _PINGSEQR_
ICMP v4 & v6 : _UIPR_, _UPORTR_, _UIP6R_, _UPORT6R_, _ICMP6BLKR_
IPv6 Auto-configuration : _PLR_, _PFR_, _VLTR_, _PAR_
PHY Configuration : _PHYSR_, _PHYCR0_, _PHYCR1_, _PHYRAR_, _PHYDIR_, _PHYDOR_, _PHYACR_, _PHYDIVR_
+*/ + + +/** + @defgroup Socket_register_group_W6300 Socket register + @ingroup WIZCHIP_register_W6300 + @brief Socket register group\n + @details + SOCKETn registers configure and control SOCKETn which is necessary to data communication. + @sa + + + + + + +
SOCKETn Control : _Sn_MR_, _Sn_MR2_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_IMR_, _Sn_PSR_
SOCKETn Information : _Sn_SR_, _Sn_ESR_, _Sn_PORTR_, _Sn_DHAR_, _Sn_DIPR_, _Sn_DIP6R_, _Sn_DPORTR_
SOCKETn Retransmission : _Sn_RTR_, _Sn_RCR_
Internet protocol : _Sn_MSSR_, _Sn_TOSR_, _Sn_TTLR_, _Sn_FRGR_
Data communication : _Sn_RX_BSR_, _Sn_TX_BSR_, _Sn_TX_FSR_, _Sn_TX_RD_, _Sn_TX_WR_, _Sn_RX_RSR_, _Sn_RX_RD_, _Sn_RX_WR_
+*/ + +//----------------------------------------------------------------------------------- + +//----------------------------- W6300 Common Registers IOMAP ----------------------------- + +/** + @addtogroup Common_register_group_W6300 + @{ +*/ + +/** + @brief Chip Identification Register address [RO] [0x6100] + @sa getCIDR() +*/ +#define _CIDR_ (_W6300_IO_BASE_ + (0x0000 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Chip Identification Register address [RO] [0x11] + @sa getRTL() +*/ +#define _RTL_ (_W6300_IO_BASE_ + (0x0004 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Chip Version Register address [RO] [0x4661] + @sa getVER() +*/ +#define _VER_ (_W6300_IO_BASE_ + (0x0002 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief System Status Register address [RO] [0xEU] + @details @ref _SYSR_ shows the information such as CHIP, NET, PHY Locking and Host I/F + + + +
7 6 5 4 ~ 2 1 0
CHPL NETL PHYL Reserved IND SPI
+ - @ref SYSR_CHPL + - @ref SYSR_NETL + - @ref SYSR_PHYL + - @ref SYSR_IND : HOST use Parallel BUS Interface(Indirect Bus Mode) + - @ref SYSR_SPI : HOST use SPI Interface + + @sa _CHPLCKR_, _NETLCKR_, _PHYLCKR_, + @sa getSYSR(), setCHPLCKR(), getCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), setNETLCKR(), getNETLCKR(), NETLOCK(), NETUNLOCK() \n + setPHYLCKR(), getPHYLCKR(), PHYLOCK(), PHYUNLOCK() +*/ +#define _SYSR_ (_W6300_IO_BASE_ + (0x2000 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief System Config Register 0 address [WO][0x80] + @details @ref _SYCR0_ softly reset to _WIZCHIP_. + + + +
7 6 ~ 0
RST Reserved
+ - @ref SYCR0_RST : Software Reset. + + @note It can be accessed only when @ref SYSR_CHPL = 1. + @sa _CHPLCKR_, _SYSR_, SYSR_CHPL + @sa setSYCR0(), setCHPLCKR(), getCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _SYCR0_ (_W6300_IO_BASE_ + (0x2004 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief System Config Register 1 address [R=W][0x80] + @details @ref _SYCR1_ controls the global interrupt enable, and selects the system clock. + + + +
7 6 ~ 1 0
IEN Reserved CLKSEL
+ - @ref SYCR1_IEN + - @ref SYCR1_CLKSEL + + @note SYCR1_CLKSEL bit can be accessed only when @ref SYSR_CHPL = 1. + @sa _CHPLCKR_, _SYSR_, SYSR_CHPL + @sa getSYCR1(), setSYCR1(), setCHPLCKR(), getCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _SYCR1_ (WIZCHIP_OFFSET_INC(_SYCR0_,1)) + +/** + @brief Ticker Counter Register address [RO][0x0000] + @details @ref _TCNTR_ increase by 1 every 100us after _WIZCHIP_ reset. + @sa _TCNTRCLR_ + @sa getTCNTR(), setTCNTRCLR() +*/ +#define _TCNTR_ (_W6300_IO_BASE_ + (0x2016 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Ticker Counter Clear Register address [RO][0x00] + @details @ref _TCNTRCLR_ clear @ref _TCNTR_. + @sa setTCNTRCLR(), getTCNTR() +*/ +#define _TCNTRCLR_ (_W6300_IO_BASE_ + (0x2020 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Interrupt Register address [RO][0x00] + @details @ref _IR_ indicates the interrupt status. + If @ref _IR_ is not equal to x00 INTn PIN is asserted to low until it is x00. + + + + +
7 6 ~ 5 4 3 2 1 0
WOL Reserved UNR6 Reserved IPCONF UNR4 PTERM
+ - @ref IR_WOL : Wake On LAN + - @ref IR_UNR6 : Destination Port Unreachable for IPv6 + - @ref IR_IPCONF : @ref _SIPR_ is Conflict + - @ref IR_UNR4 : Destination Port Unreachable for IPv4 + - @ref IR_PTERM : PPPoE Terminated + + @sa _IMR_, _IRCLR_, SYCR1_IEN, _CHIPLCKR_, _SYSR_, SYSR_CHPL + @sa getIR(), setIRCLR(), getSYCR1(), setSYCR1(), getCHPLCKR(), setCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _IR_ (_W6300_IO_BASE_ + (0x2100 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET Interrupt Register address [RO][0x00] + @details @ref _SIR_ indicates whether a socket interrupt is occurred or not.\n + Each bit of @ref _SIR_ be still until @ref _Sn_IR_ is cleared by @ref _Sn_IRCLR_ + @sa _SIMR_, _Sn_IR_, _Sn_IRCLR_, _Sn_IMR_, SYCR1_IEN , _CHIPLCKR_, _SYSR_, SYSR_CHPL + @sa getSIR(), getSn_IR(), setSn_IRCLR(), getSIMR(), setSIMR(), getSn_IMR(), setSn_IMR(), getSYCR1(), setSYCR1(), \n + getSYCR1(), setSYCR1(), getCHPLCKR(), setCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _SIR_ (_W6300_IO_BASE_ + (0x2101 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less Interrupt Register address [RO][0x00] + @details @ref _SLIR_ indicates the completion of @ref _SLCR_ or timeout. + + + +
7 6 5 4 3 2 1 0
TOUT ARP4 PING4 ARP6 PING6 NS RS RA
+ - @ref SLIR_TOUT : The timeout occurrence after @ref _SLCR_ is performed + - @ref SLIR_ARP4 : The completion of @ref SLCR_ARP4 + - @ref SLIR_PING4 : The completion of @ref SLCR_PING4 + - @ref SLIR_ARP6 : The completion f @ref SLCR_ARP6 + - @ref SLIR_PING6 : The completion of @ref SLCR_PING6 + - @ref SLIR_NS : The completion of @ref SLCR_NS + - @ref SLIR_RS : The completion of @ref SLIR_RS + - @ref SLIR_RA : The reception from Router Advertisement + + @sa _SLIRCLR_, _SLIMR_, SYCR1_IEN, _CHPLCKR_, _SYSR_, SYSR_CHPL + @sa getSLIR(), setSLIRCLR(), getSLIR(), getSLIMR(), setSLIMR(), \n + getSYCR1(), setSYCR1(), getCHPLCKR(), setCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _SLIR_ (_W6300_IO_BASE_ + (0x2102 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Interrupt Mask Register address [R=W][0x00] + @details @ref _IMR_ is used to mask interrupts of @ref _IR_.\n + When a bit of @ref _IMR_ and the corresponding bit of @ref _IR_ is set, an interrupt will be issued. + @sa _IR_, SYCR1_IEN, _CHPLCKR_, _SYSR_, SYSR_CHPL + @sa getIMR(), setIMR(), getIR(), setIRCLR(), \n + getSYCR1(), setSYCR1(), getCHPLCKR(), setCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _IMR_ (_W6300_IO_BASE_ + (0x2104 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief @ref _IR_ Clear Register address [WO][0x00] + @details @ref _IRCLR_ clears @ref _IR_ + @sa _IR_, _IMR_, SYCR1_IEN, _CHPLCKR_, _SYSR_, SYSR_CHPL + @sa setIRCLR(), getIR(), getIMR(), getSYCR1(), setSYCR1(), getCHPLCKR(), setCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _IRCLR_ (_W6300_IO_BASE_ + (0x2108 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET Interrupt Mask Register address [R=W]][0x00] + @details @ref _SIMR_ is used to mask interrupts of @ref _SIR_.\n + When a bit of @ref _SIMR_ and the corresponding bit of @ref _SIR_ is set, an interrupt will be issued.\n + when @ref _Sn_IR_ is not 0, The N-th bit of @ref _SIR_ is set. Otherwise, this bit is automatically clear.\n + @sa _SIR_, _Sn_IR_, _Sn_IRCLR_, _Sn_IMR_, SYCR1_IEN, _CHPLCKR_, _SYSR_, SYSR_CHPL + @sa getSIMR(), setSIMR(), getSIR(), setSn_IRCLR(), getSn_IMR(), setSn_IMR(), \n + getSYCR1(), setSYCR1(), getCHPLCKR(), setCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _SIMR_ (_W6300_IO_BASE_ + (0x2114 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less Interrupt Mask Register address [R=W][0x00] + @details @ref _SLIMR_ is used to mask interrupts of @ref _SLIR_\n + When a bit of @ref _SLIMR_ and the corresponding bit of @ref _SLIR_ is set, an interrupt will be issued. + @sa _SLIR_, _SLIRCLR_, SYCR1_IEN, _CHPLCKR_, _SYSR_, SYSR_CHPL + @sa getSLIMR(), setSLIMR(), getSLIR(), setSLIRCLR(), \n + getSYCR1(), setSYCR1(), getCHPLCKR(), setCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _SLIMR_ (_W6300_IO_BASE_ + (0x2124 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less Interrupt Clear Register address [WO][0x00] + @details @ref _SLIRCLR_ clears @ref _SLIR_ + @sa _SLIR_, _SLIRCLR_, _SLIMR_, SYCR1_IEN, _CHPLCKR_, _SYSR_, SYSR_CHPL + @sa getSLIR(), setSLIRCLR(), getSLIMR(), setSLIMR(), \n + getSYCR1(), setSYCR1(), getCHPLCKR(), setCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _SLIRCLR_ (_W6300_IO_BASE_ + (0x2128 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less Prefer Source IPv6 Address Register address [R=W][0x00] + @details @ref _SLPSR_ select the Source IPv6 Address to transmit a packet by @ref _SLCR_. + - @ref PSR_AUTO + - @ref PSR_LLA + - @ref PSR_GUA + @sa _SLCR_, _Sn_PSR_ + @sa getSLPSR(), setSLPSR(), getSLCR(), setSLCR(), getSn_PSR(), setSn_PSR() +*/ +#define _SLPSR_ (_W6300_IO_BASE_ + (0x212C << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less Command Register address [RW,AC][0x00] + @details @ref _SLCR_ can be request a message such like as ARP, PING, and ICMPv6 without SOCKET. + + + +
7 6 5 4 3 2 1 0
Reserved ARP4 PING4 ARP6 PING6 NS RS UNA
+ - @ref SLCR_ARP4 + - @ref SLCR_PING4 + - @ref SLCR_ARP6 + - @ref SLCR_PING6 + - @ref SLCR_NS + - @ref SLCR_RS + - @ref SLCR_UNA + + @sa _SLIR_, _SLIMR_, _SLDIPR_, _SLDIP4R_, _SLDIP6R_, _SLDHAR_, SYCR1_IEN, _CHPLCKR_, _SYSR_, SYSR_CHPL + @sa getSLCR(), setSLCR(), getSLIR(), setSLIRCLR(), getSLIMR(), setSLIMR(), getSLDIPR(),setSLDIPR(), getSLDIP4R(),setSLDIP4R(), + getSLDIP6R(), setSLDIP6R(), getSLDHAR(), getSYCR1(), setSYCR1(), getCHPLCKR(), setCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _SLCR_ (_W6300_IO_BASE_ + (0x2130 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PHY Status Register address [RO][0x00] + @details @ref _PHYSR_ shows the operation mode of PHY, the link status and etc. + - @ref PHYSR_CAB : @ref PHYSR_CAB_OFF, @ref PHYSR_CAB_ON + - @ref PHYSR_MODE : @ref PHYSR_MODE_AUTO, @ref PHYSR_MODE_100F, @ref PHYSR_MODE_100H, @ref PHYSR_MODE_10F, @ref PHYSR_MODE_10H + - @ref PHYSR_DPX : @ref PHYSR_DPX_FULL, @ref PHYSR_DPX_HALF + - @ref PHYSR_SPD : @ref PHYSR_SPD_100M, @ref PHYSR_SPD_10M + - @ref PHYSR_LNK : @ref PHYSR_LNK_UP, @ref PHYSR_LNK_DOWN + + @sa _PHYCR0_, _PHYLCKR_, _SYSR_, SYSR_PHYL + @sa getPHYSR(), setPHYCR0(), setPHYLCKR(), getPHYLCKR(), PHYLOCK(), PHYUNLOCK(), getSYSR() +*/ +#define _PHYSR_ (_W6300_IO_BASE_ + (0x3000 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PHY Internal Register Address Register address(R/W) + @details @ref _PHYRAR_ specifies the address of register in the Ethernet PHY. + - @ref PHYRAR_BMCR + - @ref PHYRAR_BMSR + @sa _PHYACR_, _PHYDOR_, _PHYDIR_, _PHYDIVR_ + @sa getPHYACR(), setPHYACR(), getPHYDOR(), setPHYDIR(), getPHYDIVR(), setPHYDIVR() +*/ +#define _PHYRAR_ (_W6300_IO_BASE_ + (0x3008 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PHY Data Input Register address [R=W][0x00] + @details @ref _PHYDIR_ specifies the value to write to the register in PHY + @sa _PHYRAR_, _PHYACR_, _PHYDOR_, _PHYDIVR_ + @sa setPHYDIR(), getPHYRAR(), setPHYRAR(), getPHYACR(), setPHYACR(), getPHYDOR(), setPHYDIR(), getPHYDIVR(), setPHYDIVR() +*/ +#define _PHYDIR_ (_W6300_IO_BASE_ + (0x300C << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PHY Data Output Register address [WO][0x00] + @details @ref _PHYDOR_ read the value from the register in PHY + @sa _PHYRAR_, _PHYACR_, _PHYDIR_, _PHYDIVR_ + @sa getPHYDOR(), getPHYRAR(), setPHYRAR(), getPHYACR(), setPHYACR(), setPHYDIR(), getPHYDIVR(), setPHYDIVR() +*/ +#define _PHYDOR_ (_W6300_IO_BASE_ + (0x3010 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PHY Access Register address [RW,AC][0x00] + @details @ref _PHYACR_ write(read) to(from) the value of register in the Ethernet PHY + - @ref PHYACR_READ + - @ref PHYACR_WRITE + @sa _PHYRAR_, _PHYDOR_, _PHYDIR_, _PHYDIVR_ + @sa getPHYACR(), setPHYACR(), getPHYDOR(), getPHYRAR(), setPHYRAR(), setPHYDIR(), getPHYDIVR(), setPHYDIVR() +*/ +#define _PHYACR_ (_W6300_IO_BASE_ + (0x3014 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PHY's MDC Clock Division Register address [R=W][0x01] + @details @ref _PHYDIVR_ divides the system clock for the MDC clock of Ethernet PHY' + - @ref PHYDIVR_32 + - @ref PHYDIVR_64 + - @ref PHYDIVR_128 + @sa _PHYRAR_, _PHYACR_, _PHYDOR_, _PHYDIR_, _PHYDIVR_ + @sa getPHYDIVR(), setPHYDIVR(), getPHYRAR(), setPHYRAR(), getPHYACR(), setPHYACR(), getPHYDOR(), setPHYDIR() +*/ +#define _PHYDIVR_ (_W6300_IO_BASE_ + (0x3018 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PHY Control Register address [WO][0x00] + @details @ref _PHYCR0_ controls the operation mode of PHY. + The result will be checked by @ref _PHYSR_ after PHY HW reset by @ref PHYCR1_RST. + - @ref PHYCR0_AUTO + - @ref PHYCR0_100F + - @ref PHYCR0_100H + - @ref PHYCR0_10F + - @ref PHYCR0_10H + + @note It can be only accessed when @ref SYSR_PHYL is unlock. + @sa _SYSR_, _PHYCR1_ + @sa setPHYCR0(), getSYSR(), getPHYCR1(), setPHYCR1() +*/ +#define _PHYCR0_ (_W6300_IO_BASE_ + (0x301C << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PHY Control Register address [R=W][0x40] + @details @ref _PHYCR1_ controls the Ethernet PHY function such as HW reset, Power down and etc. + + + +
7 6 5 4 3 2 ~ 1 0
Reserved Always 1 PWDN Reseved TE Reserved RST
+ - @ref PHYCR1_PWDN + - @ref PHYCR1_TE + - @ref PHYCR1_RST + + @note It can be only accessed when @ref SYSR_PHYL is unlock. + @sa _SYSR_, _PHYCR0_ + @sa getPHYCR1(), setPHYCR1(), setPHYCR0(), getSYSR() +*/ +#define _PHYCR1_ WIZCHIP_OFFSET_INC(_PHYCR0_,1) + +/** + @brief Network IPv4 Mode Register address [R=W][0x00] + @details @ref _NET4MR_ can block the transmission such like as unreachable message, TCP reset, and ping relay.\n + It can ARP request before ping relpy. + + + + +
7 ~ 4 3 2 1 0
Reserved UNRB PARP RSTB PB
+ - @ref NETxMR_UNRB + - @ref NETxMR_PARP + - @ref NETxMR_RSTB + - @ref NETxMR_PB + @sa _NET6MR_ + @sa getNET4MR(), setNET4MR(), getNET6MR(), setNET6MR() +*/ +#define _NET4MR_ (_W6300_IO_BASE_ + (0x4000 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Network IPv6 Mode Register address [R=W][0x00] + @details @ref _NET6MR_ can block the transmission such like as unreachable message, TCP reset, and ping relay.\n + It can ARP request before ping reply. + + + + +
7 ~ 4 3 2 1 0
Reserved UNRB PARP RSTB PB
+ - @ref NETxMR_UNRB + - @ref NETxMR_PARP + - @ref NETxMR_RSTB + - @ref NETxMR_PB + @sa _NET4MR_ + @sa getNET6MR(), setNET6MR(), getNET4MR(), setNET4MR() +*/ +#define _NET6MR_ (_W6300_IO_BASE_ + (0x4004 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Network Mode Register address [R=W][0x00] + @details @ref _NETMR_ set WOL(Wake On Lan) mode.\n + It also can block a packet such as \n + IPv6 PING request from an all-node broadcasting, \n + IPv6 PING request from a solicited mulitcasting address,\n + IPv4 packets, \n + and IPv6 packets. + + + + +
7 ~ 6 5 4 3 2 1 0
Reserved ANB M6B Always 0 WOL IP6B IP4B
+ - @ref NETMR_ANB + - @ref NETMR_M6B + - @ref NETMR_WOL + - @ref NETMR_IP6B + - @ref NETMR_IP4B + @sa getNETMR(), setNETMR() + +*/ +#define _NETMR_ (_W6300_IO_BASE_ + (0x4008 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Network Mode Register 2 address [R=W][0x00] + @details @ref _NETMR2_ set PPPoE mode.\n + It also can select the destination hardware address to either Ethernet frame MAC or target MAC in the ARP-reply message + + + +
7 6 ~ 1 0
DHAS 6 ~ 1 PPPoE
+ - @ref NETMR2_DHAS : @ref NETMR2_DHAS_ARP, @ref NETMR2_DHAS_ETH + - @ref NETMR2_PPPoE + @sa getNETMR2(), setNETMR2() +*/ +#define _NETMR2_ (_W6300_IO_BASE_ + (0x4009 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PPP LCP request Timer Register address [R=W][0x28] + @details @ref _PTMR_ sets the time for sending LCP echo request.\n + The unit of time is 25ms. + @sa _PMNR_, _PHAR_, _PSIDR_, _PMRUR_, NETMR2_PPPoE + @sa getPTMR(), setPTMR(), getPMNR(), setPMNR(), getPHAR(), setPHAR(), getPSIDR(), setPSIDR(), getPMRUR(), setPMRUR(), getNETMR2(), setNETMR2() +*/ +#define _PTMR_ (_W6300_IO_BASE_ + (0x4100 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PPP LCP Magic Number Register address [R=W][0x00] + @details @ref _PMNR_ sets the 4bytes magic number to be used in LCP negotiation. + @sa _PTMR_, _PHAR_, _PSIDR_, _PMRUR_, NETMR2_PPPoE + @sa getPMNR(), setPMNR(), getPTMR(), setPTMR(), getPHAR(), setPHAR(), getPSIDR(), setPSIDR(), getPMRUR(), setPMRUR(), getNETMR2(), setNETMR2() +*/ +#define _PMNR_ (_W6300_IO_BASE_ + (0x4104 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PPPoE Hardware Address Register address [R=W][0x00] + @details @ref _PHAR_ sets the PPPoE server hardware address that is acquired during PPPoE connection process. + @sa _PTMR_, _PMNR_, _PSIDR_, _PMRUR_, NETMR2_PPPoE + @sa getPHAR(), setPHAR(), getPTMR(), setPTMR(), getPMNR(), setPMNR(), getPSIDR(), setPSIDR(), getPMRUR(), setPMRUR(), getNETMR2(), setNETMR2() +*/ +#define _PHAR_ (_W6300_IO_BASE_ + (0x4108 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PPP Session ID Register address [R=W][0X0000] + @details @ref _PSIDR_ sets the PPPoE sever session ID acquired during PPPoE connection process. + @sa _PTMR_, _PMNR_, _PHAR_, _PMRUR_, NETMR2_PPPoE + @sa getPSIDR(), setPSIDR(), getPTMR(), setPTMR(), getPMNR(), setPMNR(), getPHAR(), setPHAR(), getPMRUR(), setPMRUR(), getNETMR2(), setNETMR2() +*/ +#define _PSIDR_ (_W6300_IO_BASE_ + (0x4110 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PPP Maximum Receive Unit Register address [R=W][0xFFFF] + @details @ref _PMRUR_ sets the maximum receive unit of PPPoE. + @sa _PTMR_, _PMNR_, _PHAR_, _PSIDR_, NETMR2_PPPoE + @sa getPMRUR(), setPMRUR(), getPTMR(), setPTMR(), getPMNR(), setPMNR(), getPHAR(), setPHAR(), getPSIDR(), setPSIDR(), getNETMR2(), setNETMR2() +*/ +#define _PMRUR_ (_W6300_IO_BASE_ + (0x4114 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Source Hardware Address Register address [R=W][00:00:00:00:00:00] + @details @ref _SHAR_ sets the source hardware address. + @note It can be accessed only when @ref SYSR_NETL is unlock. + @sa SYSR_NETL, _NETLCKR_ + @sa getSHAR(), setSHAR(), getSYSR(), setNETLCKR(), getNETLCKR(), NETLOCK(), NETUNLOCK() +*/ +#define _SHAR_ (_W6300_IO_BASE_ + (0x4120 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief IPv4 Gateway Address Register address [R=W][0.0.0.0] + @details @ref _GAR_ sets the default gateway IPv4 address. + @note It can be accessed only when @ref SYSR_NETL is unlock. + @sa SYSR_NETL, _NETLCKR_, _GA6R_ + @sa getGAR(), setGAR(), getSYSR(), setNETLCKR(), getNETLCKR(), NETLOCK(), NETUNLOCK(), getGA6R(), setGA6R() +*/ +#define _GAR_ (_W6300_IO_BASE_ + (0x4130 << 8) + WIZCHIP_CREG_BLOCK) +#define _GA4R_ (_GAR_) ///< Refer to @ref _GAR_ +/** + @brief IPv4 Subnet Mask Register address [R=W][0.0.0.0] + @details @ref _SUBR_ sets the default subnet mask address of IPv4. + @note It can be accessed only when @ref SYSR_NETL is unlock. + @sa SYSR_NETL, _NETLCKR_, _SUB6R_ + @sa getSUBR(), setSUBR(), getSYSR(), setNETLCKR(), getNETLCKR(), NETLOCK(), NETUNLOCK(), getSUB6R(), setSUB6R() +*/ +#define _SUBR_ (_W6300_IO_BASE_ + (0x4134 << 8) + WIZCHIP_CREG_BLOCK) +#define _SUB4R_ (_SUBR_) ///< Refer to @ref _SUBR_ + +/** + @brief IPv4 Source IP Register address [R=W][0.0.0.0] + @details @ref _SIPR_ sets the source IPv4 address. + @note It can be accessed only when @ref SYSR_NETL is unlock. + @sa SYSR_NETL, _NETLCKR_, _LLAR_, _GUAR_ + @sa getSIPR(), setSIPR(), getSYSR(), setNETLCKR(), getNETLCKR(), NETLOCK(), NETUNLOCK(), getLLAR(), setLLAR(), getGUAR(),setGUAR() +*/ +#define _SIPR_ (_W6300_IO_BASE_ + (0x4138 << 8) + WIZCHIP_CREG_BLOCK) +#define _SIP4R_ (_SIPR_) ///< Refer to @ref _SIPR_. + +/** + @brief IPv6 LLA(Link Local Address) Register address [R=W][::] + @details @ref _LLAR_ sets the LLA address of IPv6. + @note It can be accessed only when @ref SYSR_NETL is unlock. + @sa SYSR_NETL, _NETLCKR_, _GUAR_, _SIPR_ + @sa getLLAR(), setLLAR(), getSYSR(), setNETLCKR(), getNETLCKR(), NETLOCK(), NETUNLOCK(), getGUAR(),setGUAR(), getSIPR(), setSIPR() +*/ +#define _LLAR_ (_W6300_IO_BASE_ + (0x4140 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief IPv6 GUA(Global Unicast Address) Register address [R=W][::] + @details @ref _GUAR_ sets the GUA address of IPv6. + @note It can be accessed only when @ref SYSR_NETL is unlock. + @sa SYSR_NETL, _NETLCKR_, _LLAR_, _SIPR_ + @sa getGUAR(), setGUAR(), getSYSR(), setNETLCKR(), getNETLCKR(), NETLOCK(), NETUNLOCK(), getLLAR(),setLLAR(), getSIPR(), setSIPR() +*/ +#define _GUAR_ (_W6300_IO_BASE_ + (0x4150 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief IPv6 Subnet Mask Register address [R=W][] + @details @ref _SUB6R_ sets the default subnet mask address of IPv6. + @note It can be accessed only when @ref SYSR_NETL is unlock. + @sa SYSR_NETL, _NETLCKR_, _SUBR_ + @sa getSUB6R(), setSUB6R(), getSYSR(), setNETLCKR(), getNETLCKR(), NETLOCK(), NETUNLOCK(), getSUBR(), setSUBR() +*/ +#define _SUB6R_ (_W6300_IO_BASE_ + (0x4160 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief IPv6 Gateway Address Register address [R/W][::] + @details @ref _GA6R_ sets the default gateway IPv6 address. + @sa _GAR_ + @sa getGA6R(), setGA6R(), getGAR(), setGAR() +*/ +#define _GA6R_ (_W6300_IO_BASE_ + (0x4170 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less Peer IPv6 Register address [R=W][::] + @details @ref _SLDIP6R_ sets the destination IP address of @ref _SLCR_. + @sa _SLDIP6R_, _SLCR_, _SLIR_, _SLIRCLR_, _SLIMR_, _SLDHAR_, _SLDIPR_, _SLDIP4R_ + @sa getSLDIP6R(), setSLDIP6R(), getSLCR(), setSLCR(), getSLIR(), setSLIRCLR(), getSLIMR(), setSLIMR(), getSLDHAR(), + getSLDIPR(), setSLDIPR(), getSLDIP4R(), setSLDIP4R() +*/ +#define _SLDIP6R_ (_W6300_IO_BASE_ + (0x4180 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less Peer IPv6 Register address [R=W][0.0.0.0] + @details @ref _SLDIPR_(= @ref _SLDIP4R_) sets the destination IPv4 address of @ref _SLCR_. + @sa _SLDIP4R_, _SLCR_, _SLIR_, _SLIRCLR_, _SLIMR_, _SLDHAR_, _SLDIP6R_ + @sa getSLDIPR(), setSLDIPR(), getSLDIP4R(), setSLDIP4R(), getSLCR(), setSLCR(), getSLIR(), setSLIRCLR(), getSLIMR(), setSLIMR(), getSLDHAR(), + getSLDIP6R(), setSLDIP6R() +*/ +#define _SLDIPR_ (_W6300_IO_BASE_ + (0x418C << 8) + WIZCHIP_CREG_BLOCK) +#define _SLDIP4R_ (_SLDIPR_) ///< Refer to @ref _SLDIPR_. + + +/** + @brief SOCKET-less Peer Hardware Address Register address [RO][00:00:00:00:00:00] + @details @ref _SLDHAR_ gets the destination hardware address acquired by of @ref SLCR_ARP4, SLCR_ARP6, SLCR_PING4, and SLCR_PING6. + @sa _SLDIP4R_, _SLDIP6R_, _SLCR_, _SLIR_, _SLIRCLR_, _SLIMR_ + @sa getSLDHAR(), getSLDIP4R(), setSLDIP4R(), getSLDIP6R(), setSLDIP6R(), getSLCR(), setSLCR(), \n + getSLIR(), setSLIRCLR(), getSLIMR(), setSLIMR() +*/ +#define _SLDHAR_ (_W6300_IO_BASE_ + (0x4190 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less Ping ID Register address [R=W][0x00] + @details @ref _PINGIDR_ sets the PING-request ID to be sent by @ref SLCR_PING4 or @ref SLCR_PING6. + @sa _SLCR_, _PINGSEQR_, _SLDIPR_, _SLDIP4R_, _SLDIP6R_, _SLDHAR_, _SLIR_, _SLIRCLR_, _SLIMR_ + @sa getPINGIDR(), setPINGIDR(), getSLCR(), setSLCR(), getPINGSEQR(), setPINGSEQR(), getSLDIPR(), setSLDIPR(), + getSLDIP4R(), setSLDIP4R(), getSLDIP6R(), setSLDIP6R(), getSLDHAR(), getSLIR(), setSLIRCLR(), getSLIMR(), setSLIMR() +*/ +#define _PINGIDR_ (_W6300_IO_BASE_ + (0x4198 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less ping Sequence number Register address [R=W][0x0000] + @details @ref _PINGIDR_ sets the PING-request sequence number to be sent by @ref SLCR_PING4 or @ref SLCR_PING6. + @sa _SLCR_, _PINGIDR_, _SLDIPR_, _SLDIP4R_, _SLDIP6R_, _SLDHAR_, _SLIR_, _SLIRCLR_, _SLIMR_ + @sa getPINGSEQR(), setPINGSEQR(), getSLCR(), setSLCR(), getPINGIDR(), setPINGIDR(), getSLDIPR(), setSLDIPR(), getSLDIP4R(), setSLDIP4R(), + getSLDIP6R(), setSLDIP6R(), getSLDHAR(), getSLIR(), setSLIRCLR(), getSLIMR(), setSLIMR() +*/ +#define _PINGSEQR_ (_W6300_IO_BASE_ + (0x419C << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief IPv4 Unreachable Address Register address [RO][0.0.0.0] + @details @ref _UIPR_ is set when a unreachable ICMPv4 message is received. + @sa _UPORTR_, _UIP6R_, _UPORT6R_ + @sa getUIPR(), setUIPR(), getUPORTR(), setUPORTR(), getUIPR6(), setUIPR6(), getUPORT6R(), setUPORT6R() +*/ +#define _UIPR_ (_W6300_IO_BASE_ + (0x41A0 << 8) + WIZCHIP_CREG_BLOCK) +#define _UIP4R_ (_UIPR_) ///< Refer to @ref _UPORTR_ + +/** + @brief IPv4 Unreachable Port number Register address [RO][0x0000] + @details @ref _UPORTR_ is set when a unreachable ICMPv4 message is received. + @sa _UIPR_, _UIP6R_, _UPORT6R_ + @sa getUPORTR(), setUPORTR(), getUIPR(), setUIPR(), getUIPR6(), setUIPR6(), getUPORT6R(), setUPORT6R() +*/ +#define _UPORTR_ (_W6300_IO_BASE_ + (0x41A4 << 8) + WIZCHIP_CREG_BLOCK) +#define _UPORT4R_ (_UPORTR_) ///< Refer to @ref _UPORTR_ +/** + @brief IPv6 Unreachable IP Address Register address [RO][::] + @details @ref _UIP6R_ is set when a unreachable ICMPv6 message is received. + @sa _UIPR_, _UPORTR_, _UIP6R_, _UPORT6R_ + @sa getUIPR6(), setUIPR6(), getUIPR(), setUIPR(), getUPORTR(), setUPORTR(), getUPORT6R(), setUPORT6R() +*/ +#define _UIP6R_ (_W6300_IO_BASE_ + (0x41B0 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief IPv6 Unreachable Port number Register address [RO][0x0000] + @details @ref _UIP6R_ is set when a unreachable ICMPv6 message is received. + @sa _UIPR_, _UPORTR_, _UIP6R_, _UPORT6R_ + @sa getUIPR6(), setUIPR6(), getUIPR(), setUIPR(), getUPORTR(), setUPORTR(), getUPORT6R(), setUPORT6R() +*/ +#define _UPORT6R_ (_W6300_IO_BASE_ + (0x41C0 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Interrupt Pending Time Register address [R=w][0x0000] + @details @ref _INTPTMR_ pends the next interrupt issued by the INTn pin of @ref _WIZCHIP_.\n + It is decreased 1 every 4 SYS_CLK. \n + If it is zero and some interrupt is still remained, the INTn pin is issued. + @sa _IR_, _IRCLR_, _IMR_, _SIR_, _Sn_IRCLR_, _SIMR_, _SLIR_, _SLIRCLR_, _SLIMR_, SYCR_IEN + @sa getINTPTMR(), setINTPTMR(), getIR(), setIRCLR(), getIMR(), setIMR(), getSIR(), setSn_IRCLR(), getSIMR(), setSIMR(), \n + getSLIR(), setSLIRCLR(), getSLIMR(), setSLIMR(), getSYCR1(), setSYCR1() +*/ +#define _INTPTMR_ (_W6300_IO_BASE_ + (0x41C5 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief RA Prefix Length Register address [RO][0x00] + @details @ref _PLR_ is set when RA packet is received from a router. + @sa SLIR_RA, _SLIRCLR_, _PFR_, _VLTR_, _PLTR_, _PAR_ + @sa getPLR(), getSLIR(), setSLIRCLR(), getPFR(), getVLTR(), getPLTR(), getPAR() +*/ +#define _PLR_ (_W6300_IO_BASE_ + (0x41D0 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief RA Prefix Flag Register address [RO][0x00] + @details @ref _PFR_ is set when RA packet is received from a router. + @sa SLIR_RA, _SLIRCLR_, _PLR_, _VLTR_, _PLTR_, _PAR_ + @sa getPFR(), getSLIR(), setSLIRCLR(), getPLR(), getVLTR(), getPLTR(), getPAR() +*/ +#define _PFR_ (_W6300_IO_BASE_ + (0x41D4 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief RA Valid Life Time Register address [RO][0x00000000] + @details @ref _VLTR_ is set when RA packet is received from a router. + @sa SLIR_RA, _SLIRCLR_, _PLR_, _PFR_, _PLTR_, _PAR_ + @sa getVLTR(), getSLIR(), setSLIRCLR(), getPLR(), getPFR(), getPLTR(), getPAR() +*/ +#define _VLTR_ (_W6300_IO_BASE_ + (0x41D8 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief RA Prefered Life Time Register address [RO][0x00000000] + @details @ref _PLTR_ is set when RA packet is received from a router. + @sa SLIR_RA, _SLIRCLR_, _PLR_, _PFR_, _PLTR_, _PAR_ + @sa getPLTR(), getSLIR(), setSLIRCLR(), getPLR(), getPFR(), getVLTR(), getPAR() +*/ +#define _PLTR_ (_W6300_IO_BASE_ + (0x41DC << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief RA Prefix Address Register address[RO][::] + @details @ref _PAR_ is set when RA packet is received from a router. + @sa SLIR_RA, _SLIRCLR_, _PLR_, _PFR_, _VLTR_, _PLTR_, _PAR_ + @sa getPAR(), getPLTR(), getSLIR(), setSLIRCLR(), getPLR(), getPFR(), getVLTR() +*/ +#define _PAR_ (_W6300_IO_BASE_ + (0x41E0 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief ICMPv6 Block Register address [R=W][0x00] + @details @ref _ICMP6BLKR_ can block ICMPv6 message such like as PING, MLD, RA, NS and NA.\n + In this blocked case, @ref Sn_MR_IPRAW6 SOCKET can receive it. + + + +
7 ~ 5 4 3 2 1 0
7 ~ 5 PING6 MLD RA NA NS
+ - @ref ICMP6BLKR_PING6 : The same as @ref NETxMR_PB + - @ref ICMP6BLKR_MLD + - @ref ICMP6BLKR_RA + - @ref ICMP6BLKR_NA + - @ref ICMP6BLKR_NS + + @note The blocked message can be accepted by SOCKETn opened with @ref Sn_MR_IPRAW6. + @sa NETxMR_PB + @sa getICMP6BLKR(), setICMP6BLKR(), getNET6MR(), setNET6MR() +*/ +#define _ICMP6BLKR_ (_W6300_IO_BASE_ + (0x41F0 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Chip configuration Lock Register address [WO][0x00] + @details @ref _CHPLCKR_ can lock or unlock to access @ref _SYCR0_ and @ref _SYCR1_.\n + The lock state can be checked from @ref SYSR_CHPL. + @sa _SYCR0_, _SYCR1_, _SYSR_, SYSR_CHPL + @sa getCHPLCKR(), setCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define _CHPLCKR_ (_W6300_IO_BASE_ + (0x41F4 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Network configuration Lock Register address [WO][0x00] + @details @ref _NETLCKR_ can lock or unlock to access the network information register such as @ref _SIPR_, @ref _LLAR_, and etc.\n + The lock state can be checked from @ SYSR_NETL. + @sa _SHAR_, _SIPR_, _SUBR_, _GAR_, _LLAR_, _GUAR_, _SUB6R_, _SYSR_, SYSR_NETL + @sa getNETLCKR(), setNETLCKR(), NETLOCK(), NETUNLOCK(), getSHAR(), setSHAR(), getSIPR(), getSIPR(), getSUBR(), setSUBR(), \n + getGAR(), setGAR(), getLLAR(), setLLAR(), getGUAR(), setGUAR(), getSUB6R(), setSUB6R(), getSYSR() +*/ +#define _NETLCKR_ (_W6300_IO_BASE_ + (0x41F5 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief PHY configuration Lock Register address [WO][0x00] + @details @ref _PHYLCKR_ can lock or unlock to access @ref _PHYCR0_ and @ref _PHYCR1_.\n + The lock state can be checked from @ref SYSR_PHYL. + @sa _PHYCR0_, _PHYCR1_, _SYSR_, SYSR_PHYL. + @sa getPHYLCKR(), setPHYLCKR(), PHYLOCK(), PHYUNLOCK(), setPHYCR0(), getPHYCR1(), setPHYCR1(), getSYSR() +*/ +#define _PHYLCKR_ (_W6300_IO_BASE_ + (0x41F6 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Retransmission Time Register address [R=W][0x07D0] + @details @ref _RTR_ sets the default timeout value of @ref _Sn_RTR_.\n + When @ref _Sn_RTR_ is 0, @ref _Sn_RTR_ is reset to @ref _RTR_ after @ref Sn_CR_OPEN. + @sa _Sn_RTR_, _RCR_, _Sn_RCR_, _Sn_CR_, Sn_CR_OPEN, _Sn_IR_, _Sn_IRCLR_, Sn_IR_TIMEOUT + @sa getRTR(), setRTR(), getSn_RTR(), setSn_RTR(), getRCR(), setRCR(), getSn_RCR(), setSn_RCR(), \n + getSn_CR(), getSn_CR(), getSn_IR(), setSn_IRCLR() +*/ +#define _RTR_ (_W6300_IO_BASE_ + (0x4200 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief Retransmission Counter Register address [R=W][0x08] + @details @ref _RCR_ sets the default retransmission count of @ref _Sn_RCR_.\n + When @ref _Sn_RCR_ is 0, @ref _Sn_RCR_ is initialized as @ref _Sn_RTR_ after @ref Sn_CR_OPEN. + @sa _Sn_RCR_, _RTR_, _Sn_RTR_, _Sn_CR_, Sn_CR_OPEN, _Sn_IR_, _Sn_IRCLR_, Sn_IR_TIMEOUT + @sa getRCR(), setRCR(), getSn_RCR(), setSn_RCR(), getRTR(), setRTR(), getSn_RTR(), setSn_RTR(), \n + getSn_CR(), getSn_CR(), getSn_IR(), setSn_IRCLR() +*/ +#define _RCR_ (_W6300_IO_BASE_ + (0x4204 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less Retransmission Time Register address [R=W][0x07D0] + @details @ref _SLRTR_ sets the timeout value of packet to be retransmitted by @ref _SLCR_. + @sa _SLRCR_, _SLIR_, _SLIRCLR_, SLIR_TOUT + @sa getSLRTR(), setSLRTR(), getSLRCR(), setSLRCR(), getSLIR(), setSLIRCLR() +*/ +#define _SLRTR_ (_W6300_IO_BASE_ + (0x4208 << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less Retransmission Count Register address [R=W][0x00] + @details @ref _SLRCR_ sets the retry counter of packet to be retransmitted by @ref _SLCR_. + @sa _SLRTR_, _SLIR_, _SLIRCLR_, SLIR_TOUT + @sa getSLRCR(), setSLRCR(), getSLRTR(), setSLRTR(), setSLIRCLR(), getSLIR(), setSLIRCLR(), +*/ +#define _SLRCR_ (_W6300_IO_BASE_ + (0x420C << 8) + WIZCHIP_CREG_BLOCK) + +/** + @brief SOCKET-less Hop Limit Register address [R=W][0x80] + @details @ref _SLHOPR_ sets the hop limit value of packet to be transmitted by @ref _SLCR_. + @sa _SLCR_ + @sa getSLHOPR(), setSLHOPR(), getSLCR(), setSLCR() +*/ +#define _SLHOPR_ (_W6300_IO_BASE_ + (0x420F << 8) + WIZCHIP_CREG_BLOCK) + +/** + @} +*/ + +//----------------------------- W6300 Socket Registers ----------------------------- +/** + @addtogroup Socket_register_group_W6300 + @{ +*/ +/** + @brief Socket Mode Register Address [R=W][0x00] + @details @ref _Sn_MR_ sets the option or protocol type of SOCKETn before @ref Sn_CR_OPEN is performed.\n\n + Each bit of @ref _Sn_MR_ is defined as the following. + + + +
7 6 5 4 3 ~ 0
MULTI/MF BRDB/FPSH ND/MC/SMB/MMB UNIB/MMB6 P[3:0]
+ - @ref Sn_MR_MULTI : Support UDP Multicasting + - @ref Sn_MR_MF : Support MAC Filter Enable + - @ref Sn_MR_BRDB : Broadcast Block + - @ref Sn_MR_FPSH : Force PSH flag + - @ref Sn_MR_ND : No Delay ACK flag + - @ref Sn_MR_MC : IGMP ver2, ver1 + - @ref Sn_MR_SMB : Solicited Multicast Block + - @ref Sn_MR_MMB : IPv4 Multicast block + - @ref Sn_MR_UNIB : Unicast Block + - @ref Sn_MR_MMB6 : IPv6 UDP Multicast Block + - P[3:0] + + + + + + + + + + + + +
P[3:0] Protocol Mode
0000 SOCKET Closed
0001 TCP4
0010 UDP4
0011 IPRAW4
0100
MACRAW
1001 TCP6
1010 UDP6
1100 IPRAW6
1101 TCP Dual(TCPD)
1110 UDP Dual (UDPD)
+ - @ref Sn_MR_CLOSE : SOCKET Closed + - @ref Sn_MR_TCP4(= @ref Sn_MR_TCP) : TCP4 mode + - @ref Sn_MR_UDP4(= @ref Sn_MR_UDP) : UDP4 mode + - @ref Sn_MR_IPRAW4(= @ref Sn_MR_IPRAW) : IPRAW4 mode + - @ref Sn_MR_MACRAW : MACRAW mode + - @ref Sn_MR_TCP6 : TCP6 mode + - @ref Sn_MR_UDP6 : UDP6 mode + - @ref Sn_MR_IPRAW6 : IPRAW6 mode + - @ref Sn_MR_TCPD : TCP Dual (TCPD) mode + - @ref Sn_MR_UDPD : UDP Dual (UDPD) mode + + @note MACRAW mode should be only used in Socket 0. + @sa _Sn_CR_, Sn_CR_OPEN, _Sn_SR_, _Sn_MR2_ + @sa getSn_MR(), setSn_MR(), getSn_CR(), setSn_CR(), getSn_SR(), getSn_MR2(), setSn_MR2() +*/ +#define _Sn_MR_(N) (_W6300_IO_BASE_ + (0x0000 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKET n Prefer Source IPv6 Address Register Address [R=W][0x00] + @details @ref _Sn_PSR_ select the Source IPv6 Address to transmit a packet by @ref _Sn_CR_. + This function is same as @ref _SLPSR_. + - @ref PSR_AUTO + - @ref PSR_LLA + - @ref PSR_GUA + @sa _Sn_CR_, _Sn_PSR_, _SLPSR_ + @sa getSn_PSR(), setSn_PSR(), getSLCR(), setSLCR(), getSLPSR(), setSLPSR(), +*/ +#define _Sn_PSR_(N) (_W6300_IO_BASE_ + (0x0004 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief Socket Command Register Address [RW,AC][0x00] + @details @ref _Sn_CR_ is used to set the command for SOCKET n such as OPEN, CLOSE, CONNECT, LISTEN, SEND, and RECEIVE.\n + It is automatically cleared to 0x00 after the command is recognized by @ref _WIZCHIP_.\n + 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 on TCP4/TCP6/TCPD mode(Server mode) + - @ref Sn_CR_CONNECT : Send connection request on TCP4/TCPD mode(Client mode) + - @ref Sn_CR_CONNECT6 : Send connection request on TCP6/TCPD mode(Client mode):nohl + - @ref Sn_CR_DISCON : Send closing request on TCP/TCP6/TCPD mode. + - @ref Sn_CR_CLOSE : Close socket. + - @ref Sn_CR_SEND : Update TX buffer pointer and send data in IPv4 socket. + - @ref Sn_CR_SEND6 : Update TX buffer pointer and send data in IPv6 socket. + - @ref Sn_CR_SEND_KEEP : Send keep alive message. + - @ref Sn_CR_RECV : Update RX buffer pointer and receive data. + + @note These commands should be exclusive executed.\n That is, the other command can not executed when one command is not cleared yet. + @sa _Sn_IR_, _Sn_IRCLR_, Sn_IMR_, _SIR_, _Sn_SR_ + @sa getSn_CR(), setSn_CR(), getSn_IR(), setSn_IRCLR(), getSn_IMR(), setSn_IMR(), getSIR(), getSn_SR() +*/ +#define _Sn_CR_(N) (_W6300_IO_BASE_ + (0x0010 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Interrupt Register Address [RO][0x00] + @details @ref _Sn_IR_ gets the status of SOCKETn interrupt such as establishment, termination, receiving data, timeout.\n + If SOCKETn interrupt occurs and the n-th bit of @ref _SIMR_ is set, then @ref SIR_INT(n) is set.\n + In order to clear the @ref _Sn_IR_ bit, Set the corresponding bit of _Sn_IRCLR_ to 1.\n + If all @ref _Sn_IR_ bits are cleared, the @ref SIR_INT(n) is automatically cleared. + + + +
7 ~ 5 4 3 2 1 0
Reserved SENDOK TIMEOUT RECV DISCON CON
+ - @ref Sn_IR_SENDOK + - @ref Sn_IR_TIMEOUT + - @ref Sn_IR_RECV + - @ref Sn_IR_DISCON + - @ref Sn_IR_CON + + @sa _Sn_IRCLR_, _Sn_IMR_, _SIR_, _SIMR_ + @sa getSn_IR(), setSn_IRCLR(), getSn_IMR(), setSn_IMR(), getSIR(), getSIMR(), setSIMR() +*/ +#define _Sn_IR_(N) (_W6300_IO_BASE_ + (0x0020 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Interrupt Mask Register Address [R=W][0xFF] + @details @ref _Sn_IMR_ is used to mask interrupts of @ref _Sn_IR_. + @sa _Sn_IR_, _Sn_IRCR_, _SIR_, _SIMR_ + @sa getSn_IMR(), setSn_IMR(), getSn_IR(), setSn_IRCLR(), getSIR(), getSIMR(), setSIMR() +*/ +#define _Sn_IMR_(N) (_W6300_IO_BASE_ + (0x0024 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Interrupt Clear Register Address [WO][0x00] + @details @ref _Sn_IRCLR_ clears @ref _Sn_IR_ + @sa _Sn_IR_, _SIR_, _SIMR_ + @sa setSn_IRCLR(), getSn_IR(), getSIR(), getSIMR(), setSIMR() +*/ +#define _Sn_IRCLR_(N) (_W6300_IO_BASE_ + (0x0028 << 8) + WIZCHIP_SREG_BLOCK(N)) + + + +/** + @brief SOCKETn Status Register Address [RO][0x00] + @details @ref _Sn_SR_ indicates the status of SOCKETn.\n + The status of SOCKETn can be changed by @ref _Sn_CR_, some TCP packets such as SYN, FIN, RST packet, or @ref Sn_IR_TIMEOUT. + - 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_IPRAW6 : IPv6 IPRAW socket + - @ref SOCK_MACRAW : MAC raw mode socket + - Temporary status during changing the status of SOCKETn . + - @ref SOCK_SYNSENT : This indicates SOCKETn sent the connect-request packet (SYN packet) to a peer. + - @ref SOCK_SYNRECV : It indicates SOCKETn successfully received the connect-request packet (SYN packet) from a peer. + - @ref SOCK_FIN_WAIT : Connection state + - @ref SOCK_TIME_WAIT : Closing state + - @ref SOCK_LAST_ACK : Closing state + + @sa _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, Sn_IR_TIMEOUT + @sa getSn_SR(), getSn_CR(), setSn_CR(), getSn_IR(), setSn_IRCLR() + + + +
@image html SocketStatus.png ""
+ +*/ +#define _Sn_SR_(N) (_W6300_IO_BASE_ + (0x0030 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Extension Status Register Address [RO][0x00] + @details @ref _Sn_ESR_ indicates the connected client IP address information such as IP version, IPv6 address type(LLA or GUA), \n + and TCP operation mode such as TCP SERVER and TCP CLIENT + + + +
7 ~ 3 2 1 0
Reserved TCPM TCPOP IP6T
+ - @ref Sn_ESR_TCPM : @ref Sn_ESR_TCPM_IPV4, @ref Sn_ESR_TCPM_IPV6 + - @ref Sn_ESR_TCPOP : @ref Sn_ESR_TCPOP_SVR, @ref Sn_ESR_TCPOP_CLT + - @ref Sn_ESR_IP6T : @ref Sn_ESR_IP6T_LLA, @ref Sn_ESR_IP6T_GUA + + @note It is valid only on TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_MR_, _Sn_PSR_ + @sa getSn_ESR(), getSn_MR(), setSn_MR(), getSn_PSR(), setSn_PSR() +*/ +#define _Sn_ESR_(N) (_W6300_IO_BASE_ + (0x0031 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn IP Protocol Number(PN) Register Address [R/W][0x0000] + @details \ref _Sn_PNR_ that sets the protocol number/next header field of the IPv4/IPv6 header at the IP layer. + @note It is valid only in IPRAW mode such as @ref Sn_MR_IPRAW4 and @ref Sn_MR_IPRAW6. + @note It is set before @ref Sn_CR_OPEN is performed. + @sa _Sn_NHR_, _Sn_MR_, Sn_CR_OPEN + @sa getSn_PNR(), setSn_PNR(), getSn_NHR(), setSn_NHR(), getSn_MR(), setSn_MR(), getSn_CR(), setSn_CR() +*/ +#define _Sn_PNR_(N) (_W6300_IO_BASE_ + (0x0100 << 8) + WIZCHIP_SREG_BLOCK(N)) +#define _Sn_NHR_(N) (_Sn_PNR_(N)) ///< Refer to @ref _Sn_PNR_. + +/** + @brief SOCKETn IPv4 Type of Service(TOS) Register Address [R=W][0x00] + @details @ref _Sn_TOSR_ sets the TOS(Type Of Service) field in IPv4 Header. + @sa getSn_TOSR(), setSn_TOSR() +*/ +#define _Sn_TOSR_(N) (_W6300_IO_BASE_ + (0x0104 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn IP Time to live(TTL) Register Address [R=W][0x80] + @details @ref _Sn_TTLR_ sets the TTL(Time To Live)/HOP(Hop Limit) field in IPv4/IPv6 header at the IP layer. + @sa _Sn_HOPR_ + @sa getSn_TTLR(), setSn_TTLR(), getSn_HOPR(), setSn_HOPR() +*/ +#define _Sn_TTLR_(N) (_W6300_IO_BASE_ + (0x0108 << 8) + WIZCHIP_SREG_BLOCK(N)) +#define _Sn_HOPR_(N) (_Sn_TTLR_(N)) ///< Refer to @ref _Sn_TTLR_. + +/** + @brief SOCKETn Fragment Register Address [R=W][0x4000] + @details @ref _Sn_FRGR_ sets the fragment flag & offset in IPv4 header. + @note @ref _WIZCHIP_ can not support IP fragment & re-assembly.\n So It is not recommended to set @ref _Sn_FRGR_ to any other value. + @sa getSn_FRGR(), setSn_FRGR() +*/ +#define _Sn_FRGR_(N) (_W6300_IO_BASE_ + (0x010C << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Maximum Segment Size(MSS) Register Address [RW][0x0000] + @details @ref _Sn_MSSR_ sets or gets the MTU(Maximum Transfer Unit) of SOCKETn. \n + The MTU of each protocol is as following. + + + + + + + + + +
@ref _Sn_MR_[3:0] @ref NETMR2_PPPoE = 0 @ref NETMR2_PPPoE = '1'
@ref Sn_MR_TCP4 1 ~ 1460 1 ~ 1452
@ref Sn_MR_TCP6 1 ~ 1440 1 ~ 1432
@ref Sn_MR_UDP4 1 ~ 1472 1 ~ 1464
@ref Sn_MR_UDP6 1 ~ 1452 1 ~ 1444
@ref Sn_MR_IPRAW4 1 ~ 1480 1 ~ 1472
@ref Sn_MR_IPRAW6 1 ~ 1460 1 ~ 1452
@ref Sn_MR_MACRAW 1 ~ 1514
+ + @note It is not set exceeding the MTU for each protocol of SOCKETn even if _Sn_MSSR_ is set over the MTU. + @sa _Sn_MR_, NETMR2_PPPoE + @sa getSn_MSSR(), setSn_MSSR(), getSn_MR(), setSn_MR(), getNETMR2(), setNETMR2() +*/ +#define _Sn_MSSR_(N) (_W6300_IO_BASE_ + (0x0110 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Source Port Register Address [R=W][0x0000] + @details @ref _Sn_PORTR_ sets the source port number of SOCKETn . + @note It is valid in TCP(@ref Sn_MR_TCP4, @ref Sn_MR_TCP6, @ref Sn_MR_TCPD) and UDP(@ref Sn_MR_UDP4, @ref Sn_MR_UDP6, @ref Sn_MR_UDPD) mode. + @note It should be set before @ref Sn_CR_OPEN is performed. + @sa _Sn_MR_, Sn_CR_OPEN + @sa getSn_PORTR(), getSn_PORTR(), getSn_MR(), setSn_MR(), getSn_CR(), setSn_CR() +*/ +#define _Sn_PORTR_(N) (_W6300_IO_BASE_ + (0x0114 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Destination Hardware Address Register Address [RW][00:00:00:00:00:00] + @details @ref _Sn_DHAR_ sets or gets the destination hardware address of SOCKETn.\n + - When @ref Sn_MR2_DHAM = 1 and @ref _Sn_MR_[3:0] != @ref Sn_MR_MACRAW + The destination hardware address is set by @ref _Sn_DHAR_ without ARP processed by @ref Sn_CR_CONNECT, @ref Sn_CR_CONNECT6, @ref Sn_CR_SEND, and @ref Sn_CR_SEND6.\n + Also, when SOCKETn is opened with @ref Sn_MR_UDP4 or @ref Sn_MR_UDP6 and @ref Sn_MR_MULTI is set, @ref _Sn_DHAR_ sets the Multicast Group Hardware address. + - Others + In TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD, \n + @ref _Sn_DHAR_ gets the destination hardware address when @ref _Sn_SR_ is @ref SOCK_ESTABLISHED. + @sa _Sn_MR_, _Sn_MR2_, _Sn_CR_, _Sn_SR_ + @sa getSn_DHAR(), setSn_DHAR(), getSn_MR(), setSn_MR(), getSn_MR2(), setSn_MR2(), getSn_CR(), setSn_CR(), getSn_SR() +*/ +#define _Sn_DHAR_(N) (_W6300_IO_BASE_ + (0x0118 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Destination IPv4 Address Register Address [RW][0.0.0.0] + @details @ref _Sn_DIPR_(= @ref _Sn_DIP4R_) sets or gets the destination IPv4 address of SOCKETn. \n + - In TCP mode such as @ref Sn_MR_TCP4, and @ref Sn_MR_TCPD + - TCP CLIENT mode : It sets the IPv4 address of TCP SERVER before @ref Sn_CR_CONNECT is performed. + - TCP SERVER mode : It gets the IPv4 address of TCP CLIENT when @ref _Sn_SR_ is @ref SOCK_ESTABLISHED. + - In UDP(@ref Sn_MR_UDP4, @ref Sn_MR_UDPD) mode & IPRAW4(@ref Sn_MR_IPRAW4) mode + It sets the destination IPv4 address before @ref Sn_CR_SEND is performed. \n + When Sn_MR_MULTI = 1, It sets the multicast group IPv4 address. + @sa _Sn_DIP4R_, _Sn_MR_, _Sn_CR_, _Sn_SR_ + @sa getSn_DIPR(), getSn_DIPR(), getSn_DIP4R(), getSn_DIP4R(), getSn_MR(), setSn_MR(), getSn_CR(), setSn_CR(), getSn_SR() +*/ +#define _Sn_DIPR_(N) (_W6300_IO_BASE_ + (0x0120 << 8) + WIZCHIP_SREG_BLOCK(N)) +#define _Sn_DIP4R_(N) (_Sn_DIPR_(N)) ///< Refer to @ref _Sn_DIPR_. + +/** + @brief SOCKETn Destination IPv6 Address Register Address [RW][::] + @details @ref _Sn_DIP6R_ sets or gets the destination IPv6 address of SOCKETn. + - In TCP mode such as @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD + - TCP CLIENT mode : It sets the IPv6 address of TCP SERVER before @ref Sn_CR_CONNECT6 is performed. + - TCP SERVER mode : It gets the IPv6 address of TCP CLIENT when @ref _Sn_SR_ is @ref SOCK_ESTABLISHED. + - In UDP(@ref Sn_MR_UDP6, @ref Sn_MR_UDPD) mode & IPRAW4(@ref Sn_MR_IPRAW6) mode + It sets the destination IPv6 address before @ref Sn_CR_SEND6 is performed.\n + When Sn_MR_MULTI = 1, It sets the multicast group IPv6 address. + @sa _Sn_MR_, _Sn_CR_, _Sn_SR_ + @sa getSn_DIP6R(), setSn_DIP6R(), getSn_MR(), setSn_MR(), getSn_CR(), setSn_CR(), getSn_SR() +*/ +#define _Sn_DIP6R_(N) (_W6300_IO_BASE_ + (0x0130 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Destination Port Register Address [RW][0x0000] + @details @ref _Sn_DPORTR_ sets or gets the destination port number of SOCKETn. + - In TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD + - TCP CLIENT mode : It sets the port number of TCP SERVER before @ref Sn_CR_CONNECT is performed. + - TCP SERVER mode : It gets the port number of TCP CLIENT when @ref _Sn_SR_ is @ref SOCK_ESTABLISHED. + - In UDP mode such as @ref Sn_MR_UDP4, @ref Sn_MR_UDP6, and @ref Sn_MR_UDPD + It sets the destination port number before @ref Sn_CR_SEND is performed. \n + When Sn_MR_MULTI = 1, It sets the multicast group group port number. + + @note It is valid SOCKETn is opened with @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, @ref Sn_MR_TCPD, @ref Sn_MR_UDP4, @ref Sn_MR_UDP4, and @ref Sn_MR_UDPD. + @note It should be set before OPEN command is ordered. + @sa _Sn_MR_, _Sn_CR_, _Sn_SR_ + @sa getSn_DPORTR(), getSn_DPORTR(), getSn_MR(), setSn_MR(), getSn_CR(), setSn_CR(), getSn_SR() +*/ +#define _Sn_DPORTR_(N) (_W6300_IO_BASE_ + (0x0140 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Mode Register 2 Address [R=W][0x00] + @details @ref _Sn_MR2_ sets the option of SOCKETn with @ref _Sn_MR_, before @ref Sn_CR_OPEN is performed.\n + Each bit of @ref _Sn_MR2_ is defined as the following. + + + +
7 ~ 2 1 0
Reserved DHAM FARP
+ - @ref Sn_MR2_DHAM : @ref Sn_MR2_DHAM_AUTO, @ref Sn_MR2_DHAM_MANUAL + - @ref Sn_MR2_FARP + @sa _Sn_MR_, _Sn_CR_ + @sa getSn_MR2(), setSn_MR2(), getSn_MR(), getSn_MR(), getSn_CR() +*/ +#define _Sn_MR2_(N) (_W6300_IO_BASE_ + (0x0144 << 8) + WIZCHIP_SREG_BLOCK(N)) + + +/** + @brief SOCKETn Retransmission Time Register Address [R=W][0x0000] + @details @ref _Sn_RTR_ sets the timeout value of packet to be retransmitted by @ref _SLCR_.\n + @note It should be set before @ref Sn_CR_OPEN is performed.\n + It is initialized as @ref _RTR_ if you do not set it to none-zero value. + @sa _RTR_, _Sn_CR_ + @sa getSn_RTR(), setSn_RTR(), getSn_CR(), setSn_CR() +*/ +#define _Sn_RTR_(N) (_W6300_IO_BASE_ + (0x0180 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Retransmission Count Register Address [R=W][0x00] + @details @ref _Sn_RCR_ sets the retry count value of packet to be retransmitted by @ref _SLCR_.\n + @note It should be set before @ref Sn_CR_OPEN is performed.\n + It is initialized as @ref _RTR_ if you do not set it to any none-zero value. + @sa _RTR_, _Sn_CR_ + @sa getSn_RTR(), setSn_RTR(), getSn_CR(), setSn_CR() +*/ +#define _Sn_RCR_(N) (_W6300_IO_BASE_ + (0x0184 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn Keep Alive Time Register Address [R=W][0x00] + @details @ref _Sn_KPALVTR_ sets the auto-retransmission time of KA(Keep Alive) packet. \n + If the destination can not respond to the KA packet during the time set by @ref _Sn_KPALVTR_,\n + the connection is terminated, @ref Sn_IR_TIMEOUT is set and then @ref _Sn_SR_ is changed @ref SOCK_CLOSED.\n + Before the time is expierd, if the destination sends a KA/ACK packet or any packet, the connection is still valid,\n + @ref _Sn_SR_ remained at @ref SOCK_ESTABLISHED. + @note It is valid only after sending data over 1 byte in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @note If it is set to 0, KA packet can be sent by @ref Sn_CR_SEND_KEEP. + @sa Sn_CR_SEND_KEEP, Sn_IR_TIMEOUT, Sn_IRCLR, Sn_SR, Sn_MR + @sa getSn_KPALVTR(), setSn_KPALVTR(), getSn_IR(), setSn_IRCLR(), getSn_SR(), getSn_MR(), setSn_MR() +*/ +#define _Sn_KPALVTR_(N) (_W6300_IO_BASE_ + (0x0188 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn TX Buffer Size Register Address [R=W][0x02] + @details @ref _Sn_TX_BSR_ sets the TX buffer size of SOCKETn in the 16KB TX memory.\n + It can be set only with 0,1,2,4,8, and 16K bytes. + @note The 16KB TX memory is allocated as many as @ref _Sn_TX_BSR_ sequentially from SOCKET0 to SOCKETn(Here, 0 <= n <= @ref _WIZCHIP_SOCK_NUM_ - 1).\n + The total sum of Sn_TX_BSR can not be exceed 16KB of TX memory. \n + If the total size is exceeded, SOCKETn can't be normally sent data to a destination. + @sa _Sn_RX_BSR_ + @sa getSn_TX_BSR(), setSn_TX_BSR(), getSn_TXBUF_SIZE(), setSn_TXBUF_SIZE(), getSn_TxMAX(), setSn_TX_BSR(), getSn_RX_BSR(), setSn_RX_BSR() +*/ +#define _Sn_TX_BSR_(N) (_W6300_IO_BASE_ + (0x0200 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn TX Free Buffer Size Register Address [RO][0x0800] + @details @ref _Sn_TX_FSR_ gets the transmittable free size of SOCKETn TX buffer. + @note Data should not be saved bigger than it because the data overwrites the previous saved data not to be sent yet.\n + Therefore, Check it before saving the data to the SOCKETn TX buffer. \n + If the data size is equal or smaller than it, transmit the data with @ref Sn_CR_SEND / @ref Sn_CR_SEND6 after saving the data in SOCKETn TX buffer.\n + If the data size is greater than it, transmit the data after dividing into it and saving in the SOCKETn TX buffer. + @note \n + - In TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6 and @ref Sn_MR_TCPD, \n + It is automatically increased by the absolute difference between @ref _Sn_TX_WR_ and interanl TX ACK pointer. + - In other mode \n + It is automatically increased by the absolute difference between @ref _Sn_TX_WR_ and @ref _Sn_TX_RD_. + @sa _Sn_RX_RSR_, _Sn_TX_WR_, _Sn_TX_RD_, _Sn_CR_ + @sa getSn_TX_FSR(), getSn_TX_WR(), getSn_TX_WR(), getSn_TX_RD(), getSn_CR(), setSn_CR() +*/ +#define _Sn_TX_FSR_(N) (_W6300_IO_BASE_ + (0x0204 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKET TX Memory Read Pointer Register Address[R][0x0000] + @details @ref _Sn_TX_RD_ gets the start pointer of data to be sent by @ref Sn_CR_SEND. \n + @ref Sn_CR_SEND / @ref Sn_CR_SEND6 starts to transmit the saved data from @ref _Sn_TX_RD_ to @ref _Sn_TX_WR_ in the SOCKETn TX Buffer,\n + and when @ref Sn_IR_SENDOK is set, It is automatically increased to equal @ref _Sn_TX_WR_. + @note It is initialized by @ref Sn_CR_OPEN, But, In TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD,\n + it is re-initialized when the TCP connection is completed. + @note If it exceeds the maximum value 0xFFFF, (that is, it is greater than 0x10000 and the carry bit occurs),\n + then the carry bit is ignored and it automatically is updated with its the lower 16bits value. + @sa _Sn_TX_WR_, _Sn_TX_FSR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_ + @sa getSn_TX_RD(), getSn_TX_WR(), setSn_TX_WR(), getSn_TX_FSR(), getSn_CR(), setSn_CR(), getSn_IR(), setSn_IRCLR(), getSn_MR(), setSn_MR() +*/ +#define _Sn_TX_RD_(N) (_W6300_IO_BASE_ + (0x0208 << 8) + WIZCHIP_SREG_BLOCK(N)) + + +/** + @brief SOCKETn TX Memory Write Pointer Register Address [RW][0x0000] + @details @ref _Sn_TX_WR_ gets the start pointer of data to be saved in the SOCKETn TX buffer, \n + or sets the end pointer of data to be sent by @ref Sn_CR_SEND. \n + If you have completed to save the data to be sent in the SOCKETn TX buffer, + increase it as many as the saved size of data before @ref Sn_CR_SEND is performed.\n + @ref Sn_CR_SEND starts to transmit the saved data from @ref _Sn_TX_RD_ to @ref _Sn_TX_WR_ in the SOCKETn TX Buffer, \n + and when @ref Sn_IR_SENDOK is set, @ref _Sn_TX_RD_ is automatically increased to equal it. + @note It is initialized by @ref Sn_CR_OPEN.\n + But, In TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD,\n + it is re-initialized when the TCP connection is completed. + @note The size of data to be saved can't exceed @ref _Sn_TX_FSR_. + @note If it exceeds the maximum value 0xFFFF(that is, it is greater than 0x10000 and the carry bit occurs),\n + then ignore the carry bit and update it with its lower 16bits value. + @sa _Sn_TX_RD_, _Sn_TX_FSR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_ + @sa getSn_TX_WR(), setSn_TX_WR(), getSn_TX_RD(), getSn_TX_FSR(), getSn_CR(), setSn_CR(), getSn_IR(), setSn_IRCLR(), getSn_MR(), setSn_MR() +*/ +#define _Sn_TX_WR_(N) (_W6300_IO_BASE_ + (0x020C << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn RX Buffer Size Register Address [R=W][0x02] + @details @ref _Sn_RX_BSR_ sets the RX buffer size of SOCKETn in the 16KB RX memory.\n + It can be set only with 0,1,2,4,8, and 16K bytes. + @note The 16KB RX memory is allocated as many as @ref _Sn_RX_BSR_ sequentially from SOCKET0 to SOCKETn(Here, 0 <= n <= @ref _WIZCHIP_SOCK_NUM_ - 1).\n + The total sum of @ref _Sn_RX_BSR_ can not be exceed 16KB of RX memory. \n + If the total size is exceeded, SOCKETn can't be normally received data from a destination. + @sa _Sn_RX_BSR_ + @sa getSn_TX_BSR(), setSn_TX_BSR(), getSn_RXBUF_SIZE(), setSn_RXBUF_SIZE(), getSn_RxMAX(), getSn_RX_BSR(), setSn_RX_BSR() +*/ +#define _Sn_RX_BSR_(N) (_W6300_IO_BASE_ + (0x0220 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn RX Received Size Register Address [RO][0x0000] + @details @ref _Sn_RX_RSR_ gets the received data size of SOCKETn RX buffer. + @note The real received data size maybe smaller than it, \n + because it maybe included the size of 'PACKET NFO' such like as \n + the destination IP address, destination port number and data size of the received DATA PACKET. + @note Do not read bigger data than @ref _Sn_RX_RSR_. + @note It is automatically increased by the absolute difference between @ref _Sn_RX_WR_ and @ref _Sn_RX_RD_ \n + after @ref Sn_CR_RECV is performed. + @sa _Sn_RX_RSR_, _Sn_TX_WR_, _Sn_TX_RD_, _Sn_CR_, _Sn_TX_FSR_ + @sa getSn_RX_RSR(), getSn_TX_WR(), getSn_TX_WR(), getSn_CR(), setSn_CR(), getSn_TX_FSR() +*/ +#define _Sn_RX_RSR_(N) (_W6300_IO_BASE_ + (0x0224 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKET RX Memory Read Pointer Register Address[R][0x0000] + @details @ref _Sn_RX_RD_ gets the start pointer of the received data in the SOCKETn RX buffer,\n + or sets the end data pointer of the read completed data by @ref Sn_CR_RECV. \n + You can read the received data from it to @ref _Sn_RX_WR_ in the SOCKET RX buffer.\n + After completing to read data, you should increase it as many as the read size before @ref Sn_CR_RECV is performed. + @note It is initialized by @ref Sn_CR_OPEN, But, In TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD,\n + it is re-initialized when the TCP connection is completed. + @note If it exceeds the maximum value 0xFFFF, (that is, it is greater than 0x10000 and the carry bit occurs),\n + Ignore the carry bit and update with its the lower 16bits value. + @sa _Sn_RX_WR_, _Sn_RX_RSR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_ + @sa getSn_RX_WR(), setSn_RX_RD(), getSn_RX_WR(), getSn_TX_FSR(), getSn_CR(), setSn_CR(), getSn_IR(), setSn_IRCLR(), getSn_MR(), setSn_MR() +*/ +#define _Sn_RX_RD_(N) (_W6300_IO_BASE_ + (0x0228 << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @brief SOCKETn TX Memory Write Pointer Register Address [RW][0x0000] + @details @ref _Sn_TX_WR_ gets the end pointer of the data that has been completely received in the SOCKETn RX buffer. \n + Whenever a data has been completely received from a destination, \n + It is automatically increased as many as the sum size of the received data and the 'PACKET INFO'. \n + You can read the recevied data from @ref _Sn_RX_RD_ to it in the SOCKET RX buffer. + @note It is initialized by @ref Sn_CR_OPEN. But, In TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD,\n + it is re-initialized when the TCP connection is completed. + @note If it exceeds the maximum value 0xFFFF(that is, it is greater than 0x10000 and the carry bit occurs),\n + then ignore the carry bit and update it with its lower 16bits value. + @sa _Sn_TX_RD_, _Sn_TX_FSR_, _Sn_CR_, _Sn_IR_, Sn_IRCLR_, _Sn_MR_ + @sa getSn_TX_WR(), setSn_TX_WR(), getSn_TX_RD(), getSn_TX_FSR(), getSn_CR(), setSn_CR(), getSn_IR(), setSn_IRCLR(), getSn_MR(), setSn_MR() +*/ +#define _Sn_RX_WR_(N) (_W6300_IO_BASE_ + (0x022C << 8) + WIZCHIP_SREG_BLOCK(N)) + +/** + @} +*/ + +/*----------------------------- W6300 Register values -----------------------------*/ + +/* System Status Register Bit Definition */ +/** + @brief CHIP Lock staus bit of @ref _SYSR_. + @details @ref SYSR_CHPL indicates the lock status of @ref _SYCR0_ and @ref _SYCR1_.\n + 1 : Lock \n + 0 : unlock + @note It is set by only @ref _CHPLCKR_. + @sa _SYSR_, _CHPLCKR_, _SYCR0_, _SYCR1_ + @sa getSYSR(), getCHPLCKR(), setCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), setSYCR0(), setSYCR1() +*/ +#define SYSR_CHPL (1 << 7) + +/** + @brief NET Lock status bit of @ref _SYSR_. + @details @ref SYSR_NETL indicates the lock of network information registers such as + @ref _SHAR_, @ref _GAR_, @ref _SUBR_, @ref _SIPR_, @ref _LLAR_, @ref _GUAR_, and @ref _SUB6R_. \n + 1 : Lock \n + 0 : unlock + @note It is set by only @ref _NETLCKR_. + @note @ref _GA6R_ can be accessed regardless of @ref SYSR_NETL. + @sa _SYSR_, _NETLCKR_, _SHAR_, _GAR_, _SUBR_, _SIPR_, _LLAR_, _GUAR_, _SUB6R_ + @sa getSYSR(), getNETLCKR(), setNETLCKR(), NETLOCK(), NETUNLOCK(),\n + getSHAR(), setSHAR(), getGAR(), setGAR(), getSUBR(), getSIR(), setSIPR(), \n + getLLAR(), setLLAR(), getGUAR(),setGUAR(), getSUB6R(), setSUB6R() +*/ +#define SYSR_NETL (1 << 6) + +/** + @brief PHY Lock status bit of @ref _SYSR_. Refer to @ref _PHYLCKR_. + @details @ref SYSR_PHYL indicates the lock status of @ref _PHYCR0_ and _PHYCR1_.\n + 1 : Lock \n + 0 : unlock + @note It is set by only @ref _PHYLCKR_. + @sa _SYSR_, _PHYCLKR_, _PHYCR0_, _PHYCR1_ + @sa getSYSR(), getPHYLCKR(), setPHYLCKR(), setPHYCR0(), getPHYCR1(), setPHYCR1() +*/ +#define SYSR_PHYL (1 << 5) + +/** + @brief Parallel Bus Mode bit of @ref _SYSR_ + @details @ref SYSR_IND is set when @ref _WIZCHIP_ PIN MODE[3:0] == "010X". + It indicates to use the parallel BUS mode. + @sa _SYSR_, _WIZCHIP_IO_MODE_BUS_ + @sa getSYSR() +*/ +#define SYSR_IND (1 << 5) + +/** + @brief SPI I/F Mode bit of @ref _SYSR_. + @details @ref SYSR_SPI is set when @ref _WIZCHIP_ PIN MODE[3:0] == "000X". + It indicates to use the SPI mode. + @sa _SYSR_, _WIZCHIP_IO_MODE_SPI_ + @sa getSYSR() +*/ +#define SYSR_SPI (1 << 0) + + +/* System Config Register Bit Definition */ +/** + @brief RST bit of @ref _SYCR0_ + @details @ref SYCR0_RST resets to @ref _WIZCHIP_ softly. \n + 0 : Soft reset \n + 1 : Normal operation + @note It can be set only when @ref SYSR_CHPL = 1. + @sa _SYSR0_, _CHPLCKR_, _SYSR_, SYSR_CHPL + @sa setSYCR0(), setCHPLCKR(), getCHPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getSYSR() +*/ +#define SYCR0_RST (0x00) + +/** + @brief IEN bit of @ref _SYCR1_. + @details @ref SYCR1_IEN is globally enable or disable the interrupt of @ref _WIZCHIP_,\n + regardless of the related interrupt mask registers such as @ref _IMR_, @ref _SIMR_, @ref _SLIMR_, and @ref _Sn_IMR_.\n + 1 : Enable \n + 0 : Disable + @sa _SYCR1_, _IR_, _SIR_, _SLIR_, _Sn_IR_, _IRCLR_, _SLIRCLR_, _Sn_IRCLR_ + @sa getSYCR1(), setSYCR1(), getIR(), getSIR(), getSLIR(), getSn_IR(), setIRCLR(), setSLIRCLR(), setSn_IRCLR() +*/ +#define SYCR1_IEN (1 << 7) + +/** + @brief System Clock select mask bit of @ref _SYCR1_. + @details @ref SYCR1_CLKSEL selects a system clock to 100MHz or 25MHz. \n + The masked bit values are as following. + - @ref SYCR1_CLKSEL_25M + - @ref SYCR1_CLKSEL_100M + @note It can be set only when @ref SYSR_CHPL = 1. + @note The system clock is automatically changed to 25MHz while the reset of @ref _WIZCHIP_ H/W reset, the Ethernet PHY H/W reset and power down. \n + On the other hand, the system clock is set by @ref SYCR1_CLKSEL during normal operating. + @sa _SYCR1_, _SYSR_, _CHPLCKR_, SYSL_CHPL, PHYCR1_RST, PHYCR1_PWDN + @sa getSYCR1(), setSYCR1(), getSYSR(), getCHPLCKR(), setCHIPLCKR(), CHIPLOCK(), CHIPUNLOCK(), getPHYCR1(), setPHYCR1() +*/ +#define SYCR1_CLKSEL (1 << 0) + +/** + @brief System Clock - 25MHz + @details @ref SYCR1_CLKSEL_25M selects a system clock to 25MHz. + @note It can be set only when @ref SYSR_CHPL = 1. + @sa _SYCR1_, SYCR1_CLKSEL, SYCR1_CLKSEL_100M + @sa getSYCR1(), setSYCR1(), getSYSR(), getCHPLCKR(), setCHIPLCKR(), CHIPLOCK(), CHIPUNLOCK() +*/ +#define SYCR1_CLKSEL_25M 1 + +/** + @brief System Clock - 100MHz + @details @ref SYCR1_CLKSEL_100M selects a system clock to 100MHz. + @note It can be set only when @ref SYSR_CHPL = 1. + @sa _SYCR1_, SYCR1_CLKSEL, SYCR1_CLKSEL_25M + @sa getSYCR1(), setSYCR1(), getSYSR(), getCHPLCKR(), setCHIPLCKR(), CHIPLOCK(), CHIPUNLOCK() +*/ +#define SYCR1_CLKSEL_100M 0 + + +/* Interrupt Register Bit Definition */ +/** + @brief WOL bit of @ref _IR_ + @details @ref IR_WOL is set when @ref _WIZCHIP_ receives a magic packet of WOL. + @sa _IR_, _IRCLR_, _IMR_ + @sa getIR(), setIRCLR(), getIMR(), setIMR() +*/ +#define IR_WOL (1<<7) + +/** + @brief UNR6 bit of @ref _IR_ + @details @ref IR_UNR6 is set when @ref _WIZCHIP_ receives the unreachable message of ICMPv6. + @sa _IR_, _IRCLR_, _IMR_ + @sa getIR(), setIRCLR(), getIMR(), setIMR() +*/ +#define IR_UNR6 (1<<4) + +/** + @brief IPCONF bit of @ref _IR_ + @details @ref IR_IPCONF is set when @ref _WIZCHIP_ receives a ARP reply with the same IPv4 address as @ref _SIPR_. + @sa _IR_, _IRCLR_, _IMR_ + @sa getIR(), setIRCLR(), getIMR(), setIMR() +*/ +#define IR_IPCONF (1<<2) + +/** + @brief UNR4 bit of @ref _IR_ + @details @ref IR_UNR4 is set when @ref _WIZCHIP_ receives the unreachable message of ICMPv4. + @sa _IR_, _IRCLR_, _IMR_ + @sa getIR(), setIRCLR(), getIMR(), setIMR() +*/ +#define IR_UNR4 (1<<1) + +/** + @brief PTERM bit of @ref _IR_ + @details @ref IR_PTERM is set when @ref _WIZCHIP_ receives the PPP termination packet + @sa _IR_, _IRCLR_, _IMR_ + @sa getIR(), setIRCLR(), getIMR(), setIMR() +*/ +#define IR_PTERM (1<<0) + + +/* SOCKET Interrupt Register Bit Definition */ +/** + @brief N-th INT bit of @@ref _SIR_ + @details @ref SIR_INT(N) is set when @ref _Sn_IR_(N) is not equal to zero. + @sa _SIR_, _Sn_IRCLR_, _SIMR_ + @sa getSIR(), setSn_IRCLR(), getSIMR() +*/ +#define SIR_INT(N) (1<TCP SERVER mode + If the connection request client have a IPv4 address, \n + TCP dual SOCKETn is changed to TCP4 mode and a destination IP address can be checked thru @ref _Sn_DIPR_, \n + else if the client have a IPv6 address, \n + TCP dual SOCKETn is changed to IPv6 mode and destination IP address can be checked by thru @ref _Sn_DIP6R_. + - In SOCKETn is operated as TCP CLIENT mode, + If the IP address type of destination to connect is IPv4, \n + the destination IP address should be set to @ref _Sn_DIPR_ and try to connect by @ref Sn_CR_CONNECT, \n + else if the type is IPv6, \n + the destination IP address should be set to @ref _Sn_DIP6R_ and try to connect by @ref Sn_CR_CONNECT6. \n + + @note In TCP SERVER mode, You can check the IP type of the client with @ref Sn_ESR_TCPM. + @note If the connected client have a IPv6 address, You can check whether the address is LLA or GAU, thru @ref Sn_ESR_IP6T + @sa _Sn_MR_, _Sn_CR_, _Sn_SR_, _Sn_ESR_TCPM_, Sn_MR_TCP4, Sn_MR_TCP6 + @sa getSn_MR(), setSn_MR(), getSn_CR(), setSn_CR(), getSn_SR(), getSn_ESR() +*/ +#define Sn_MR_TCPD (0x0D) + +/** + @brief UDP Dual mode + @details @ref Sn_MR_UDPD sets SOCKETn to both UDP4 & UDP6 mode. \n + It should be set before @ref Sn_CR_OPEN is performed. \n + After @ref Sn_CR_OPEN, SOCKETn is opened as UDP dual mode \n + and @ref _Sn_SR_ is changed from @ref SOCK_CLOSED to @ref SOCK_UDP. + @note In order to send data, \n + You can use both @ref Sn_CR_SEND and @ref Sn_CR_SEND6 as command and both @ref _Sn_DIPR_ and @ref _Sn_DIP6R_ as destination. + @note You can know the destination IP address type is whether IPv6 or IPv4 thru @ref getsockopt() with @ref SO_PACKINFO. + @sa _Sn_MR_, _Sn_CR_, _Sn_SR_, Sn_MR_UDP6, Sn_MR_UDP4 + @sa getSn_MR(), setSn_MR(), getSn_CR(), setSn_CR(), getSn_SR() +*/ +#define Sn_MR_UDPD (0x0E) + +/* SOCKETn Command Register BIt Definition */ +/** + @brief Initialize or Open SOCKETn. + @details SOCKETn is initialized and opened according to the protocol mode selected by @ref _Sn_MR_ and with a source port set by @ref _Sn_PORTR_. \n + The table shows @ref _Sn_SR_ is changed according to @ref _Sn_MR_.\n + + + + + + + + +
@ref _Sn_MR_ (P[3:0]) @ref _Sn_SR_
@ref Sn_MR_CLOSE @ref SOCK_CLOSED
@ref Sn_MR_TCP4, @ref Sn_MR_TCP6, @ref Sn_MR_TCPD @ref SOCK_INIT
@ref Sn_MR_UDP, @ref Sn_MR_UDP6, @ref Sn_MR_UDPD @ref SOCK_UDP
@ref Sn_MR_IPRAW4 @ref SOCK_IPRAW4
@ref Sn_MR_IPRAW6 @ref SOCK_IPRAW6
@ref Sn_MR_MACRAW @ref SOCK_MACRAW
+ + @note If you want to use a SOCKETn option such as Sn_MR_MF, Sn_MR_ND, Sn_MR_MUTIL and etc, \n + these options should be set before @ref Sn_CR_OPEN is performed. + @note If you want to open a multicast UDP mode SOCKETn, \n + You should set the multicast group with @ref _Sn_DIPR_ or @ref _Sn_DIP6R_ and @ref _Sn_DPORTR_ before @ref Sn_CR_OPEN is performed. + @sa _Sn_CR_, _Sn_MR_, _Sn_SR_, _Sn_PORTR_, _Sn_DIPR_, _Sn_DIP6R_, _Sn_DPORTR_, + @sa getSn_CR(), setSn_CR(), getSn_MR(), setSn_MR(), getSn_SR(), getSn_PORTR(), setSn_PORTR(), getSn_DIPR(), setSn_DIPR(), + getSn_DIP6R(), setSn_DIP6R(), getSn_DPORTR(), setSn_DPORTR() +*/ +#define Sn_CR_OPEN (0x01) + +/** + @brief Wait a connection request in TCP SERVER mode + @details SOCKETn operates as a TCP SERVER and waits for a connection-request (SYN packet) \n + with corresponding @ref _Sn_PORTR_ port number from any TCP CLIENT \n + The @ref _Sn_SR_ is changed from @ref SOCK_INIT to @ref SOCK_LISTEN. \n + When a TCP CLIENT connection request is successfully accepted,\n + the @ref _Sn_SR_ is changed from @ref SOCK_LISTEN to @ref SOCK_ESTABLISHED \n + and the @ref Sn_IR_CON is set.\n + But when a TCP CLIENT connection request is failed, \n + @ref Sn_IR_TIMEOUT is set and @ref _Sn_SR_ is changed to SOCK_CLOSED. + @note This is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_CR_, _Sn_MR_, _Sn_SR_, _Sn_PORTR_ + @sa getSn_CR(), setSn_CR(), getSn_MR(), setSn_MR(), getSn_SR(), getSn_PORTR(), setSn_PORTR() +*/ +#define Sn_CR_LISTEN (0x02) + +/** + @brief Send a connection request in TCP CLIENT mode + @details To establish a connection, a connect-request (SYN packet) is sent to TCP SERVER set by @ref _Sn_DIPR_ & @ref _Sn_DPORTR_.\n + If the connect-request is successful accepted by a TCP SERVER, \n + the @ref _Sn_SR_ is changed to @ref SOCK_ESTABLISHED and the @ref Sn_IR_CON is set. \n + The connect-request fails in the following three cases, \n + and @ref _Sn_SR_ is changed to @ref SOCK_CLOSED.\n\n + 1. Until a ARP timeout is occurred (@ref Sn_IR_TIMEOUT = 1), a destination hardware address can not be acquired through the ARP-process.\n + 2. Until a TCP tmeout occurred (@ref Sn_IR_TIMEOUT = 1), a SYN/ACK packet is not received from the server\n + 3. When a RST packet is received instead of a SYN/ACK packet \n + + @note This is valid only in TCP mode such as @ref Sn_MR_TCP4 and @ref Sn_MR_TCPD. + @sa _Sn_CR_, _Sn_MR_, _Sn_SR_, _Sn_DIPR_, _Sn_DPORTR_, Sn_CR_CONNECT6, _Sn_IR_, _Sn_IRCLR_ + @sa getSn_CR(), setSn_CR(), getSn_MR(), setSn_MR(), getSn_SR(), getSn_DIPR(), setSn_DIPR(), getSn_DPORTR(), setSn_DPORTR(), getSn_IR(), setSn_IRCLR() +*/ +#define Sn_CR_CONNECT (0x04) + +/** + @brief Send connection request in TCP CLIENT mode + @details To establish a connection, a connect-request (SYN packet) is sent to TCP SERVER set by @ref _Sn_DIP6R_ & @ref _Sn_DPORTR_.\n + If the connect-request is successful accepted by a TCP SERVER, \n + the @ref _Sn_SR_ is changed to @ref SOCK_ESTABLISHED and the @ref Sn_IR_CON is set. \n + The connect-request fails in the following three cases, and @ref _Sn_SR_ is changed @ref SOCK_CLOSED.\n + 1. Until a ARP timeout is occurred (@ref Sn_IR_TIMEOUT = 1), a destination hardware address can not be acquired through the ARP-process.\n + 2. Until a TCP tmeout occurred (@ref Sn_IR_TIMEOUT = 1), a @b SYN/ACK packet is not received from the server\n + 3. When a RST packet is received instead of a @b SYN/ACK packet \n + + @note This is valid only in TCP mode such as @ref Sn_MR_TCP6 and @ref Sn_MR_TCPD. + @sa _Sn_CR_, _Sn_MR_, _Sn_SR_, _Sn_DIP6R_, _Sn_DPORTR_, Sn_CR_CONNECT, _Sn_IR_, _Sn_IRCLR_ + @sa getSn_CR(), setSn_CR(), getSn_MR(), setSn_MR(), getSn_SR(), getSn_DIP6R(), setSn_DIP6R(), getSn_DPORTR(), setSn_DPORTR(), getSn_IR(), setSn_IRCLR() +*/ +#define Sn_CR_CONNECT6 (0x84) + +/** + @brief Send a disconnect request in TCP mode + @details Regardless of TCP SERVER or TCP CLIENT, \n + @ref Sn_CR_DISCON processes the disconnect-process (Active or Passive close).\n + When the disconnect-process is successful (that is, FIN/ACK packet is received successfully from/to each other),\n + @ref _Sn_SR_ is changed to @ref SOCK_CLOSED.\n + Otherwise, @ref Sn_IR_TIMEOUT is set and then @ref _Sn_SR_ is changed to @ref SOCK_CLOSED. + - Active close + It transmits first a disconnect-request(FIN packet) to the connected peer, and waits to receive two FIN/ACK and FIN packet from the peer. \n + If two FIN/ACK and FIN packet is received successfully, @ref Sn_IR_DISCON is set and @ref _Sn_SR_ is changed @ref SOCK_CLOSED. + - Passive close + When a FIN packet is first received from the peer, the FIN/ACK packet is replied back to the peer and @ref Sn_IR_DISCON is set.\n + And then, a FIN packet is sent by @ref Sn_CR_DISCON to the peer, and waits to receive the FIN/ACK packet from the peer. \n + If the FIN/ACK packet is received successfully from the peer, @ref _Sn_SR_ is changed to @ref SOCK_CLOSED. + + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_CR_, _Sn_MR_, _Sn_SR_, _Sn_IR_, _Sn_IRCLR_, Sn_IR_DISCON, Sn_IR_TIMEOUT + @sa getSn_CR(), setSn_CR(), getSn_MR(), setSn_MR(), getSn_SR(), getSn_IR(), setSn_IRCLR() +*/ +#define Sn_CR_DISCON (0x08) + +/** + @brief Release or Close SOCKETn + @details In TCP mode, @ref Sn_CR_CLOSE force to close a SOCKETn without the disconnect-process.\n + In other SOCKETn mode, @ref Sn_CR_CLOSE just closes a SOCKET.\n + @note @ref _Sn_SR_ can be changed from any status to @ref SOCK_CLOSED by @ref Sn_CR_CLOSE. + @sa _Sn_CR_, _Sn_MR_, _Sn_SR_, Sn_CR_DISCON + @sa getSn_CR(), setSn_CR(), getSn_MR(), setSn_MR(), getSn_SR() +*/ +#define Sn_CR_CLOSE (0x10) + +/** + @brief Send Data + @details @ref Sn_CR_SEND send the saved data from @ref _Sn_TX_RD_ to @ref _Sn_TX_WR_ in the SOCKETn TX buffer \n + to the destination specified by @ref _Sn_DIPR_ or @ref _Sn_DIP6R_, and @ref _Sn_DPORTR_.\n + - TCP mode(@ref Sn_MR_TCP4, @ref Sn_MR_TCP6, @ref Sn_MR_TCPD) + If it starts to be sent the data by @ref Sn_CR_SEND, @ref Sn_IR_SENDOK is set. \n + And after sending the data, if the ACK to the sent data can not be received during @ref _Sn_RTR_, \n + the sent data can be retransmitted as many as @ref _Sn_RCR_. \n + During the retransmission, \n + If the ACK is received, @ref _Sn_TX_FSR_ is increased as many as the sent data size, \n + Otherwise, @ref Sn_IR_TIMEOUT is set and @ref _Sn_SR_ is changed to @ref SOCK_CLOSED. + - UDP mode(@ref Sn_MR_UDP4, @ref Sn_MR_UDPD) & IPRAW mode(@ref Sn_MR_IPRAW4) + It first sends a ARP-request to a destination specified with @ref _Sn_DIPR_ before it starts to be sent data by @ref Sn_CR_SEND. \n + If the ARP-reply can not be received during @ref _Sn_RTR_, the ARP-request can be retransmitted as many as @ref _Sn_RCR_. \n + During the retransmission, \n + If the ARP-reply is received and @ref Sn_IR_SENDOK is set, it starts to send data and then @ref _Sn_TX_FSR_ is increased as many as the sent data size. \n + Otherwise, @ref Sn_IR_TIMEOUT is set but @ref _Sn_SR_ is not changed. + - MACRAW mode(@ref Sn_MR_MACRAW) + It just start to send data and @ref Sn_IR_SENDOK is set. + + @note Data size to be sent is calculated by the absolute difference between @ref _Sn_TX_WR_ and @ref _Sn_TX_RD_. \n + In TCP or UDP mode, It can not be sent bigger data than @ref _Sn_TX_FSR_.\n + In IPRAW or Macraw case, it can not be sent bigger data than MTU(Maximum Transmit Unit). + @note In TCP or MACRAW mode, It can send data to a destination address whether IPv4 or IPv6. \n + In UDP or IPRAW mode, It can send data only to a destination IPv4 address. \n + For Sending to IPv6 address, It can be used with @ref Sn_CR_SEND6. + @sa _Sn_CR_, _Sn_MR_, _Sn_DIPR_, _Sn_DIP6R_, _Sn_DPORTR_, _Sn_IR_, _Sn_IRCLR_, _Sn_TX_FSR_, _Sn_TX_WR_, _Sn_TX_RD_ + @sa getSn_CR(), setSn_CR(), getSn_MR(), setSn_MR(), getSn_SR(), getSn_DIPR(), setSn_DIPR(), getSn_DIP6R(), setSn_DIP6R(), \n + getSn_DPORTR(), setSn_DPORTR(), getSn_IR(), setSn_IRCLR(), getSn_TX_FSR(), getSn_TX_WR(), setSn_TX_WR(), getSn_TX_RD() +*/ +#define Sn_CR_SEND (0x20) + +/** + @brief Send Data + @details @ref Sn_CR_SEND6 sends the saved data from @ref _Sn_TX_RD_ to @ref _Sn_TX_WR_ in the SOCKETn TX buffer \n + to the destination specified by @ref _Sn_DIP6R_, and @ref _Sn_DPORTR_.\n + - TCP mode(@ref Sn_MR_TCP4, @ref Sn_MR_TCP6, @ref Sn_MR_TCPD) & MACRAW mode(@ref Sn_MR_MACRAW) + @ref Sn_CR_SEND6 is not recommended. In this case, Use @ref Sn_CR_SEND. + - UDP mode(@ref Sn_MR_UDP6, @ref Sn_MR_UDPD) & IPRAW mode(@ref Sn_MR_IPRAW6) + It first send a neighbor solicitation NS) of ICMPv6 to a destination specified with @ref _Sn_DIP6R_ \n + before it starts to be sent data by @ref Sn_CR_SEND. \n + If the neighbor advertisement(NA) of ICMPv6 can not be received during @ref _Sn_RTR_, \n + the NS can be retransmitted as many as @ref _Sn_RCR_. \n + During the retransmission, \n + If the NA is received and @ref Sn_IR_SENDOK is set, \n + it starts to send data and then @ref _Sn_TX_FSR_ is increased as many as the sent data size. \n + Otherwise, @ref Sn_IR_TIMEOUT is set but @ref _Sn_SR_ is not changed. + + @note Data size to be sent is calculated by the absolute difference between @ref _Sn_TX_WR_ and @ref _Sn_TX_RD_. \n + In TCP or UDP mode, It can not be sent bigger data than @ref _Sn_TX_FSR_.\n + In IPRAW or Macraw case, it can not be sent bigger data than MTU(Maximum Transmit Unit). + @note In UDP or IPRAW mode, It can send data only to a destination IPv6 address. \n + For Sending to IPv4 address, It can be sent by @ref Sn_CR_SEND. + @sa _Sn_CR_, _Sn_MR_, _Sn_DIP6R_, _Sn_DPORTR_, _Sn_IR_, _Sn_IRCLR_, _Sn_TX_FSR_, _Sn_TX_WR_, _Sn_TX_RD_ + @sa getSn_CR(), setSn_CR(), getSn_MR(), setSn_MR(), getSn_SR(), getSn_DIP6R(), setSn_DIP6R(), getSn_DPORTR(), setSn_DPORTR(), \n + getSn_IR(), setSn_IRCLR(), getSn_TX_FSR(), getSn_TX_WR(), setSn_TX_WR(), getSn_TX_RD() +*/ +#define Sn_CR_SEND6 (0xA0) + +/** + @brief Send keep alive message + @details @ref Sn_CR_SEND_KEEP checks whether the connection is established or not by sending 1 byte KA(Keep Alive) packet.\n + If the destination can not respond to the KA packet during the time set by @ref _Sn_RTR_ and @ref _Sn_RCR_, \n + the connection is terminated, @ref Sn_IR_TIMEOUT is set and then @ref _Sn_SR_ is changed @ref SOCK_CLOSED. + @note It is valid only after sending data over 1 byte in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_CR_, _Sn_MR_, _Sn_SR_, _Sn_IR_, _Sn_IRCLR_, _Sn_RTR_, _Sn_RCR_, _Sn_KPALVTR_ + @sa getSn_CR(), setSn_CR(), getSn_MR(), setSn_MR(), getSn_SR(), getSn_IR(), setSn_IRCLR(), \n + getSn_RTR(), setSn_RTR(), getSn_RCR(), setSn_RCR(), getSn_KPALVTR(), getSn_KPALVTR() +*/ +#define Sn_CR_SEND_KEEP (0x22) + +/** + @brief Receive data + @details @ref Sn_CR_RECV reads the saved from @ref _Sn_RX_RD_ to @ref _Sn_RX_WR_ data in SOCKETn RX buffer.\n + When a data is saved in the SOCKETn RX buffer, \n + @ref Sn_IR_RECV is set and @ref _Sn_RX_RSR_ is increased as many as the saved data size.\n + The total size of saved data is calculated by the absolute difference between @ref _Sn_RX_WR_ and @ref _Sn_RX_RD_,\n + and it can be checked thru @ref _Sn_RX_RSR_.\n + After reading data, @ref _Sn_RX_RD_ should be increased as many as the read size before @ref Sn_CR_RECV is performed.\n + After @ref Sn_CR_RECV, @ref _Sn_RX_RSR_ is decreased as many as the read size.\n + If @ref _Sn_RX_RSR_ is remained still at none-zero, @ref Sn_IR_RECV is set again. + @sa _Sn_CR_, _Sn_MR_, _Sn_IR_, _Sn_IRCLR_, _Sn_RX_RD_, _Sn_RX_WR_, _Sn_RX_RSR_ + @sa getSn_CR(), setSn_CR(), getSn_MR(), setSn_MR(), getSn_IR(), getSn_IRCLR(), \n + getSn_RX_RD(), setSn_RX_RD(), getSn_RX_TX(), getSn_RX_RSR() +*/ +#define Sn_CR_RECV (0x40) + + +/* Sn_IR values */ +/** + @brief SEND OK Interrupt + @details @ref Sn_IR_SENDOK is set when it is started to be sent data by @ref Sn_CR_SEND. + @note Even though @ref Sn_IR_SENDOK is set, it does not means that the destination receives data successfully.\n + - In TCP mode, The sent data maybe still transmitting or retransmitting. \n + - In other modes, The sent data maybe lost by media collision or an other reason such as network traffic. + @sa _Sn_IR_, _Sn_IRCLR_, Sn_CR_SEND + @sa getSn_IR(), setSn_IRCLR(), getSn_CR(), setSn_CR() +*/ +#define Sn_IR_SENDOK (0x10) + +/** + @brief TIMEOUT Interrupt + @details @ref Sn_IR_TIMEOUT is set when a timeout occurs in ARP and ND process or TCP retransmission. + @note In TCP mode, If it is set, @ref _Sn_SR_ is changed to @ref SOCK_CLOSED. \n + In other modes, _Sn_SR_ is still remained at the previous status. + @sa _Sn_IR_, _Sn_IRCLR_, Sn_CR_CONNECT, Sn_CR_CONNECT6, Sn_CR_SEND + @sa getSn_IR(), setSn_IRCLR(), getSn_CR(), setSn_CR() +*/ +#define Sn_IR_TIMEOUT (0x08) + +/** + @brief RECV Interrupt + @details @ref Sn_IR_RECV is set whenever data is received from a peer, \n + or if @ref _Sn_RX_RSR_ is still at none-zero whenever @ref Sn_CR_RECV is performed. + @sa _Sn_IR_, _Sn_IRCLR_, Sn_CR_RECV + @sa getSn_IR(), setSn_IRCLR(), getSn_CR(), setSn_CR() +*/ +#define Sn_IR_RECV (0x04) + +/** + @brief DISCON Interrupt + @details @ref Sn_IR_DISCON is set when a FIN or FIN/ACK packet is received from the connected peer. + @note When first a FIN packet is received from the connected peer and @ref _Sn_SR_ is changed to SOCK_CLOSE_WAIT, \n + you should perform @ref Sn_CR_DISCON for a successful disconnect. \n + If the disconnect-process is completed or failed, @ref _Sn_SR_ is changed to @ref SOCK_CLOSED. + @note It is valild only in TCP mode such as @ref Sn_MR_TCP4, @ ref Sn_MR_TCP6 and @ref Sn_MR_TCPD. + @sa _Sn_IR_, _Sn_IRCLR_, Sn_IR_DISCON, _Sn_SR_ + @sa getSn_IR(), setSn_IRCLR(), getSn_CR(), setSn_CR(), getSn_SR() +*/ +#define Sn_IR_DISCON (0x02) + +/** + @brief CONNECT Interrupt + @details @ref Sn_IR_CON is set once the connection with a peer is established and @ref _Sn_SR_ is changed to @ref SOCK_ESTABLISHED. + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ ref Sn_MR_TCP6 adn @ref Sn_MR_TCPD. + @sa _Sn_IR_, _Sn_IRCLR_, _Sn_SR_ + @sa getSn_IR(), setSn_IRCLR(), getSn_SR() +*/ +#define Sn_IR_CON (0x01) + +/* Sn_SR values */ +/** + @brief SOCKETn Closed status + @details @ref SOCK_CLOSED indicates that SOCKETn is closed and released.\n + It is set when @ref Sn_CR_DISCON , @ref Sn_CR_CLOSE is performed, or when @ref Sn_IR_TIMEOUT is set.\n + It can be changed to @ref SOCK_CLOSED regardless of previous status. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, Sn_IR_TIMEOUT + @sa getSn_SR(), getSn_CR(), setSn_CR(), getSn_IR(), setSn_IRCLR() +*/ +#define SOCK_CLOSED (0x00) + +/** + @brief TCP SOCKETn initialized status + @details @ref SOCK_INIT indicates SOCKETn is opened with TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCP6.\n + @ref _Sn_SR_ is changed from @ref SOCK_CLOSED to @ref SOCK_INIT when @ref Sn_CR_OPEN is performed in TCP mode.\n + In @ref SOCK_INIT status, @ref Sn_CR_LISTEN for operating a TCP SERVER \n + or @ref Sn_CR_CONNECT / @ref Sn_CR_CONNECT6 for operating a TCP CLIENT can be performed. + @note It is valid only in TCP mode. + @sa _Sn_SR_, _Sn_CR_, _Sn_MR_ + @sa getSn_SR, getSn_CR(), setSn_CR(), getSn_MR(), setSn_MR() +*/ +#define SOCK_INIT (0x13) + +/** + @brief TCP SOCKETn Listen status + @details @ref SOCK_LISTEN indicates SOCKETn is operating as TCP SERVER mode \n + and waiting for connection-request (SYN packet) from a peer (TCP CLIENT).\n + @ref _Sn_SR_ is changed to @ref SOCK_SYNRECV when the connection-request(SYN packet) is successfully accepted \n + and It is changed from @ref SOCK_SYNRECV to @ref SOCK_ESTABLISHED \n + when the SYN/ACK packet is sent successfully to the peer and then the ACK packet of SYN/ACK is received successfully.\n + Otherwise, it is changed to @ref SOCK_CLOSED and @ref Sn_IR_TIMEOUT is set. + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCP6.. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_ + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR() +*/ +#define SOCK_LISTEN (0x14) + +/** + @brief TCP Connection Request status + @details @ref SOCK_SYNSENT indicates TCP SOCKETn sent the connect-request packet(SYN packet)\n + to the peer specified by @ref _Sn_DIPR_ / @ref _Sn_DIP6R_ and @ref _Sn_DPORTR_.\n + It is temporarily shown when @ref _Sn_SR_ is changing from @ref SOCK_INIT to @ref SOCK_ESTABLISHED by @ref Sn_CR_CONNECT or @ref Sn_CR_CONNECT6.\n + When the connect-accept packet (SYN/ACK packet) is received from the peer at @ref SOCK_SYNSENT and the ACK packet of SYN/ACK is sent successfully, \n + @ref _Sn_SR_ is changed to @ref SOCK_ESTABLISHED.\n + Otherwise, it is changed to @ref SOCK_CLOSED and @ref Sn_IR_TIMEOUT is set. + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCP6.. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_ + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR() +*/ +#define SOCK_SYNSENT (0x15) + +/** + @brief TCP Connection Accept status + @details @ref SOCK_SYNRECV indicates TCP SOCKETn is successfully received the connect-request packet (SYN packet) from a peer.\n + It is temporarily shown when @ref _Sn_SR_ is changing from @ref SOCK_LISTEN to @ref SOCK_ESTABLISHED by the SYN packet\n + If SOCKETn sends the response (SYN/ACK packet) to the peer successfully and the ACK packet of SYS/ACK is received successfully,\n + @ref _Sn_SR_ is changed to @ref SOCK_ESTABLISHED. \n + Otherwise, @ref _Sn_SR_ is changed to @ref SOCK_CLOSED and @ref Sn_IR_TIMEOUT is set. + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCP6.. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_ + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR() +*/ +#define SOCK_SYNRECV (0x16) + +/** + @brief TCP SOCKETn Established status + @details @ref SOCK_ESTABLISHED indicates TCP SOCKETn is connected successfully with a peer.\n + when the TCP SERVER processes the SYN packet from the TCP CLIENT during @ref SOCK_LISTEN or \n + when the TCP CLIENT performs successfully @ref Sn_CR_CONNECT or @ref Sn_CR_CONNECT6,\n + @ref _Sn_SR_ is changed to @ref SOCK_ESTABLISHED and @ref Sn_IR_CON is set. \n + During @ref SOCK_ESTABLISHED, a DATA packet can be sent to or received from the peer by @ref Sn_CR_SEND or @ref Sn_CR_RECV. \n + If the DATA/ACK packet is not received from the peer during data re-transmission, @ref Sn_IR_TIMEOUT is set and @ref _Sn_SR_ is changed to @ref SOCK_CLOSED.\n + Otherwise, @ref _Sn_SR_ is still at @ref SOCK_ESTABLISHED. + @note In TCP SERVER, \n + You can check the IPv4/IPv6 address and port number of connected peer thru @ref _Sn_DIPR_, @ref _Sn_DIP6R_, and @ref _Sn_DPORTR_ respectively. + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCP6. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_, _Sn_DIPR_, _Sn_DIP6R_, _Sn_DPORTR_ + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR(), + getSn_DIPR(), setSn_DIPR(), getSn_DIP6R(), setSn_DIP6R(), getSn_DPORTR(), setSn_DPORTR(). +*/ +#define SOCK_ESTABLISHED (0x17) + +/** + @brief TCP SOCKETn Closing status + @details @ref SOCK_FIN_WAIT indicates TCP mode SOCKETn waits until the disconnect-process is completed. \n + It is temporarily shown in disconnect-process such as active-close. \n + When the disconnect-process is successfully completed or when @ref Sn_IR_TIMEOUT is set,\n + @ref _Sn_SR_ is changed to @ref SOCK_CLOSED. + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_, SOCK_TIME_WAIT, SOCK_LAST_ACK + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR() + +*/ +#define SOCK_FIN_WAIT (0x18) + +/** + @brief TCP SOCKETn Closing status + @details @ref SOCK_TIME_WAIT indicates TCP SOCKETn waits until the disconnect-process is completed.\n + It is temporarily shown in disconnect-process such as active-close. \n + When the disconnect-process is successfully completed or when @ref Sn_IR_TIMEOUT is set,\n + @ref _Sn_SR_ is changed to @ref SOCK_CLOSED. + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_, SOCK_FIN_WAIT, SOCK_LAST_ACK + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR() +*/ +#define SOCK_TIME_WAIT (0x1B) + +/** + @brief TCP SOCKETn Half Closing staus + @details @ref SOCK_CLOSE_WAIT indicates TCP SOCKETn receives the disconnect-request (FIN packet) from the connected peer.\n + It is a half-closing status, and a DATA packet can be still sent or received by @ref Sn_CR_SEND or @ref Sn_CR_RECV.\n + If you do not have any more need to send or received a DATA packet, You can perform @ref Sn_CR_DISCON for a full-closing. + @note If you have no need the successful closing, You maybe perform @ref Sn_CR_CLOSE. + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_ + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR() +*/ +#define SOCK_CLOSE_WAIT (0x1C) + +/** + @brief TCP SOCKETn Closing status + @details @ref SOCK_LAST_ACK indicates TCP SOCKETn waits until the disconnect-process is completed.\n + It is temporarily shown in disconnect-process such as active-close and passive-close.\n + When the disconnect-process is successfully completed or when @ref Sn_IR_TIMEOUT is set,\n + @ref _Sn_SR_ is changed to @ref SOCK_CLOSED. + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_, SOCK_FIN_WAIT, SOCK_TIME_WAIT + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR() +*/ +#define SOCK_LAST_ACK (0x1D) + +/** + @brief UDP SOCKETn status + @details @ref SOCK_UDP indicates SOCKETn is opened in UDP mode such as @ref Sn_MR_UDP4, @ref Sn_MR_UDP6, and @ref Sn_MR_UDPD.\n + @ref _Sn_SR_ is changed from @ref SOCK_CLOSED to @ref SOCK_INIT when @ref Sn_CR_OPEN is performed in UDP mode.\n + Unlike TCP mode, during @ref SOCK_UDP, \n + a DATA packet can be sent to or received from a peer by @ref Sn_CR_SEND / @ref Sn_CR_SEND6 or @ref Sn_CR_RECV without a connect-process.\n + Before a DATA packet is sent by @ref Sn_CR_SEND / @ref Sn_CR_SEND6,\n + the ARP is requested to the peer specified by @ref _Sn_DIPR_ / @ref _Sn_DIP6R_.\n + In ARP processing, @ref _Sn_SR_ is stll at @ref SOCK_UDP even if @ref Sn_IR_TIMEOUT is set.\n + If you do not have any more need to send or received a DATA packet, \n + You can perform @ref Sn_CR_CLOSE and @ref _Sn_SR_ is changed to @ref SOCK_CLOSED. + @note It is valid only in UDP mode such as @ref Sn_MR_UDP4, @ref Sn_MR_UDP6, and @ref Sn_MR_UDPD. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_, _Sn_DIPR_, _Sn_DIP6R_ + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR(), + getSn_DIPR(), setSn_DIPR(), getSn_DIP6R(), setSn_DIP6R() +*/ +#define SOCK_UDP (0x22) + +/** + @brief IPRAW4 SOCKETn mode + @details @ref SOCK_IPRAW4(= @ref SOCK_IPRAW) SOCKETn indicates SOCKETn is opened as IPv4 RAW mode.\n + @ref _Sn_SR_ is changed from @ref SOCK_CLOSED to @ref SOCK_IPRAW4 when @ref Sn_CR_OPEN is performed with @ref Sn_MR_IPRAW4. \n + A DATA packet can be send to or received from a peer without a connection like as @ref SOCK_UDP. \n + Before a DATA packet is sent by @ref Sn_CR_SEND, \n + the ARP is requested to the peer specified by @ref _Sn_DIPR_.\n + In ARP processing, @ref _Sn_SR_ is still at @ref SOCK_IPRAW4 even if @ref Sn_IR_TIMEOUT is set.\n + IPRAW4 SOCKETn can receive only the packet specified by @ref _Sn_PNR_, and it discards the others packets.\n + If you do not have any more need to send or received a DATA packet, \n + You can perform @ref Sn_CR_CLOSE and @ref _Sn_SR_ is changed to @ref SOCK_CLOSED. + @note It is valid only in IPRAW4 mode such as @ref Sn_MR_IPRAW4. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_, _Sn_DIPR_, _Sn_PNR_ + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR(), + getSn_DIPR(), setSn_DIPR(), getSn_PNR(), setSn_PNR() +*/ +#define SOCK_IPRAW4 (0x32) +#define SOCK_IPRAW (SOCK_IPRAW4) ///< Refer to @ref SOCK_IPRAW4. + +/** + @brief IPRAW6 SOCKETn mode + @details @ref SOCK_IPRAW6 SOCKETn indicates SOCKETn is opened as IPv6 RAW mode.\n + @ref _Sn_SR_ is changed from @ref SOCK_CLOSED to @ref SOCK_IPRAW6 when @ref Sn_CR_OPEN is performed with @ref Sn_MR_IPRAW6. \n + A DATA packet can be send to or received from a peer without a connection like as @ref SOCK_UDP.\n + Before a DATA packet is sent by @ref Sn_CR_SEND6, \n + the ICMPv6 NS is requested to the peer specified by @ref _Sn_DIPR_ or @ref _Sn_DIP6R_.\n + In ND(Neighbor Discovery) is processing,\n + @ref _Sn_SR_ is still at @ref SOCK_IPRAW6 even if @ref Sn_IR_TIMEOUT is set.\n + IPRAW6 SOCKETn can receive only the packet specified by @ref _Sn_PNR_, and it discards the others packets.\n + If you do not have any more need to send or received a DATA packet, \n + You can perform @ref Sn_CR_CLOSE and @ref _Sn_SR_ is changed to @ref SOCK_CLOSED. + @note It is valid only in IPRAW6 mode such as @ref Sn_MR_IPRAW6. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_, _Sn_DIP6R_, _Sn_PNR_ + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR(), + getSn_DIP6R(), setSn_DIP6R(), getSn_PNR(), setSn_PNR() +*/ +#define SOCK_IPRAW6 (0x33) + +/** + @brief MACRAW SOCKETn mode + @details @ref SOCK_MACRAW indicates SOCKET0 is opened as MACRAW mode.\n + @ref _Sn_SR_ is changed from @ref SOCK_CLOSED to @ref SOCK_MACRAW when @ref Sn_CR_OPEN command is ordered with @ref Sn_MR_MACRAW.\n + MACRAW SOCKET0 can be sent or received a pure Ethernet frame packet to/from any peer. + @note It is valid only in SOCKET0. + @sa _Sn_SR_, _Sn_CR_, _Sn_IR_, _Sn_IRCLR_, _Sn_MR_ + @sa getSn_SR, getSn_CR(), getSn_IR(), setSn_IRCLR(), setSn_CR(), getSn_MR(), setSn_MR(), +*/ +#define SOCK_MACRAW (0x42) + +/* Sn_ESR values */ +/** + @brief SOCKETn Extended Status : TCP Mode + @details @ref Sn_ESR_TCPM masks the TCPM bit of @ref _Sn_ESR_. \n + The masked bit values are as following. \n + - @ref Sn_ESR_TCPM_IPV4 + - @ref Sn_ESR_TCPM_IPV6 + @note It is useful to know the destination IP version when TCPD(@ref Sn_MR_TCPD) mode SOCKETn is operated as TCP SERVER. + @sa _Sn_ESR_ + @sa getSn_ESR() +*/ +#define Sn_ESR_TCPM (1<<2) + +/** + @brief TCP SOCKETn IP version - IPv4 + @details @ref Sn_ESR_TCPM_IPV4 indicates TCP SOCKETn is operated on IPv4 . + @sa _Sn_ESR_, Sn_ESR_TCPM_IPV6 + @sa getSn_ESR() +*/ +#define Sn_ESR_TCPM_IPV4 (0<<2) + +/** + @brief TCP SOCKETn IP version - IPv6 + @details @ref Sn_ESR_TCPM_IPV6 indicates TCP SOCKETn is operated on IPv6 . + @sa _Sn_ESR_, Sn_ESR_TCPM_IPV4 + @sa getSn_ESR() +*/ +#define Sn_ESR_TCPM_IPV6 (1<<2) + +/** + @brief SOCKETn Extended Status : TCP Operation Mode + @details @ref Sn_ESR_TCPOP masks the TCPOP bit of @ref _Sn_ESR_. The masked bit values are as following. \n + - @ref Sn_ESR_TCPOP_SVR + - @ref Sn_ESR_TCPOP_CLT + @note It is useful to check TCP mode SOCKETn is operated as whether TCP SERVER or TCP CLIENT. + @sa _Sn_ESR_ + @sa getSn_ESR() +*/ +#define Sn_ESR_TCPOP (1<<1) + +/** + @brief TCP SOCKETn Operation Mode - TCP SERVER + @details @ref Sn_ESR_TCPOP_SVR indicates TCP mode SOCKET n is operated as TCP SERVER + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_ESR_, Sn_ESR_TCPOP_CLT + @sa getSn_ESR() +*/ +#define Sn_ESR_TCPOP_SVR (0<<1) + +/** + @brief TCP SOCKETn Operation Mode - TCP CLIENT + @details @ref Sn_ESR_TCPOP_SVR indicates TCP mode SOCKET n is operated as TCP CLIENT + @note It is valid only in TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_ESR_, Sn_ESR_TCPOP_SVR + @sa getSn_ESR() +*/ +#define Sn_ESR_TCPOP_CLT (1<<1) + +/** + @brief SOCKETn Extended Status : Source IPv6 Address Type + @details @ref Sn_ESR_IP6T masks the IP6T bit of @ref _Sn_ESR_. \n + The masked bit values are as following. \n + - @ref Sn_ESR_IP6T_LLA + - @ref Sn_ESR_IP6T_GUA + @note It is useful to check whether the connected peer IP address is LLA or GUA. + @note It is valid only in TCP mode such as @ref Sn_MR_TCP6 and @ref Sn_MR_TCPD. + @sa _Sn_ESR_ + @sa getSn_ESR() +*/ +#define Sn_ESR_IP6T (1<<0) + +/** + @brief Source IPv6 Address Type - LLA + @details @ref Sn_ESR_IP6T_LLA indicates the source IPv6 Address is used as @ref _LLAR_ + @note It is valid only in TCP mode such as @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_ESR_, Sn_ESR_IP6T_GUA, _LLAR_ + @sa getSn_ESR(), getLLAR(), setLLAR() +*/ +#define Sn_ESR_IP6T_LLA (0<<0) + +/** + @brief Source IPv6 Address Type - LLA + @details @ref Sn_ESR_IP6T_GUA indicates the source IPv6 Address is used as @ref _GUAR_ + @note It is valid only in TCP mode such as @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD. + @sa _Sn_ESR_, Sn_ESR_IP6T_LLA, _GUAR_ + @sa getSn_ESR(), getGUAR(), setGUAR() +*/ +#define Sn_ESR_IP6T_GUA (1<<0) + +/* Sn_MR2 values */ +/** + @brief Destination Hardware Address Mode + @details @ref Sn_MR2_DHAM masks the DHAM bit of @ref _Sn_MR2_.\n + The masked bit values are as following. + - @ref Sn_MR2_DHAM_AUTO + - @ref Sn_MR2_DHAM_MANUAL + @sa _Sn_MR2_ + @sa getSn_MR2(), setSn_MR2() +*/ +#define Sn_MR2_DHAM (1<<1) + +/** + @brief Destination Hardware Address Mode - AUTO + @details @ref Sn_MR2_DHAM_AUTO sets the destination hardware address as the address acquired by ARP-process. + @sa _Sn_MR2_, Sn_MR_DHAM_MANUAL, NETMR_DHAS + @sa getSn_MR2(), setSn_MR2(), getNETMR(), setNETMR() +*/ +#define Sn_MR2_DHAM_AUTO (0<<1) + +/** + @brief Destination Hardware Address Mode - MANUAL + @details @ref Sn_MR2_DHAM_MANUAL sets the destination hardware address as @ref _Sn_DHAR_. + @sa _Sn_MR2_, Sn_MR_DHAM_MANUAL, NETMR_DHAS + @sa getSn_MR2(), setSn_MR2(), getNETMR(), setNETMR() +*/ +#define Sn_MR2_DHAM_MANUAL (1<<1) + +/** + @brief Force ARP + @details @ref Sn_MR2_FARP force to perform the ARP-process for acquiring the destination hardware address, before data communication\n + 0 : Normal \n + 1 : Force ARP + - In TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD + If SOCKETn is operated as TCP SERVER, It sets the destination hardware address as the address + acquired by the forced ARP-process before sending SYN/ACK packet. + - In UDP mode such as @ref Sn_MR_UDP4, @ref Sn_MR_UDP6, and @ref Sn_MR_UDPD + It sets the destination hardware address as the address acquired by the forced ARP-process whenever @ref Sn_CR_SEND or @ref Sn_CR_SEND6. + @note When @ref Sn_MR2_DHAM_MANUAL and @ref Sn_MR2_FARP = '1', It sets the destination hardware address as @ref _Sn_DHAR_ even if the ARP-process is forced. +*/ +#define Sn_MR2_FARP (1<<0) + + +/*----------------------------For PHY Control-------------------------------*/ + +/** + @ingroup Common_register_group_W6300 + @brief Basic Mode Control Register of Ethernet PHY [RW][0x3100] + @details @ref PHYRAR_BMCR can be controlled by MDC/MDIO controller of @ref _WIZCHIP_. \n + Each bit of @ref PHYRAR_BMCR is defined as the following. + + + +
15 14 13 12 11 10 9 8 7 6 ~ 0
RST LB SPD ANE PWDN ISOL RAN DPX COLT Reserved
+ - @ref BMCR_RST + - @ref BMCR_LB + - @ref BMCR_SPD + - @ref BMCR_ANE + - @ref BMCR_PWDN + - @ref BMCR_ISOL : Not supported. + - @ref BMCR_REAN + - @ref BMCR_DPX + - @ref BMCR_COLT + + @note Its some bits have the same function as @ref _PHYCR0_ and @ref _PHYCR1_.\n + It can control the Ethernet PHY with software, while @ref _PHYCR0_ \n + and @ref _PHYCR1_ can control the Ethernet PHY with hardware. + + @sa PHYRAR_BMSR, _PHYRAR_, _PHYDIR_, _PHYDOR_, _PHYACR_, _PHYCR0_, _PHYCR1_ + @sa getPHYRAR(), setPHYRAR(), wiz_mdio_read(), wiz_mdio_write() +*/ +#define PHYRAR_BMCR (0x00) + +//Basic mode status register, basic register +/** + @ingroup Common_register_group_W6300 + @brief Basic Mode Status Register of Ethernet PHY [RO][0x7809] + @details @ref PHYRAR_BMSR gets the status of Ethernet PHY through MDC/MDIO controller of @ref _WIZCHIP_. \n + Each bit of @ref PHYRAR_BMSR is defined as the following. + + + + + +
15 14 13 12 11 10~76 5 4 3 2 1 0
100_T4 100_FDX 100_HDX 10_FDX 10_HDX Reserved MF_SUPANG_COMP REMOTE_FAULT ANG_ABILITY LINK_STATUS JABBER_DETECT EXT_CAPA
+ - @ref BMSR_100_T4 : Not supported. Always 0 + - @ref BMSR_100_FDX + - @ref BMSR_100_HDX + - @ref BMSR_10_FDX + - @ref BMSR_10_HDX + - @ref BMSR_MF_SUP : Not supported. Always 0. + - @ref BMSR_AN_COMP + - @ref BMSR_REMOTE_FAULT : Not supported. Always 0. + - @ref BMSR_AN_ABILITY + - @ref BMSR_LINK_STATUS + - @ref BMSR_JABBER_DETECT + - @ref BMSR_EXT_CAPA : Always 1. If you need a extended register information, send e-mail to support@wiznet.io + + @note Its some bits have the same function as @ref _PHYSR_. + @sa PHYRAR_BMCR, _PHYRAR_, _PHYDIR_, _PHYDOR_, _PHYACR_, _PHYCR0_, _PHYCR1_ + @sa getPHYRAR(), setPHYRAR(), wiz_mdio_read(), wiz_mdio_write() +*/ +#define PHYRAR_BMSR (0x01) + + +/********************/ +/* BMCR & BMSR Bit definitions */ +/********************/ + +/*For BMCR register*/ +/** + @brief Ethernet PHY S/W Reset. + @details 0 - Normal operation \n + 1 - Software reset + @sa PHYRAR_BMCR, PHYCR1_RST + @sa getPHYRAR_BMCR(), setPHYRAR_BMCR() +*/ +#define BMCR_RST (1<<15) + +/** + @brief Ethernet PHY Loopback. + @details 0 - Normal Operation \n + 1 - Loopback Enable + @sa PHYRAR_BMCR + @sa getPHYRAR_BMCR(), setPHYRAR_BMCR() +*/ +#define BMCR_LB (1<<14) ///< Loopback. 0 - Noraml operation, 1 - Loopback enabled + +/** + @brief Ethernet PHY Speed + @details 0 - 10 Mbps \n + 1 - 100 Mbps + @sa PHYCR_BMCR, PHYCR0_100F, PHYCR0_100H, PHYCR0_10F, PHYCR0_10H + @sa getPHYRAR_BMCR(), setPHYRAR_BMCR(), setPHYCR0() +*/ +#define BMCR_SPD (1<<13) + +/** + @brief Ethernet PHY Auto-Negotiation + @details 0 - Disable \n + 1 - Enable + @note When it is set, @ref BMCR_SPD and @ref BMCR_DPX is ignored + @sa PHYCR_BMCR, PHYCR0_AUTO + @sa getPHYRAR_BMCR(), setPHYRAR_BMCR(), setPHYCR0() +*/ +#define BMCR_ANE (1<<12) + +/** + @brief Ethernet PHY Power Down Mode + @details 0 - Normal Operation \n + 1 - Power Down mode + @sa PHYCR_BMCR, PHYCR0_PWDN + @sa getPHYRAR_BMCR(), setPHYRAR_BMCR(), setPHYCR0() +*/ +#define BMCR_PWDN (1<<11) ///< Power-down mode + +/** + @brief Ethernet PHY Isolation Mode + @details 0 - Normal Operation \n + 1 - Isolation Mode + @ Don't set it to '1'. It is not supported. + @sa PHYCR_BMCR + @sa getPHYRAR_BMCR(), setPHYRAR_BMCR() +*/ +#define BMCR_ISOL (1<<10) + +/** + @brief Ethernet PHY Restart Auto-Negotiation + @details 0 - Normal Operation \n + 1 - Restart Auto-Negotiation + @sa PHYCR_BMCR + @sa getPHYRAR_BMCR(), setPHYRAR_BMCR() +*/ +#define BMCR_REAN (1<<9) + +/** + @brief Ethernet PHY Duplex + @details 0 - Half-Duplex \n + 1 - Full-Duplex + @sa PHYCR_BMCR, PHYCR0_100F, PHYCR0_100H, PHYCR0_10F, PHYCR0_10H + @sa getPHYRAR_BMCR(), setPHYRAR_BMCR(), setPHYCR0() +*/ +#define BMCR_DPX (1<<8) + +/** + @brief Ethernet PHY Collision Test + @details 0 - Normal Operation \n + 1 - Collision Test + @sa PHYCR_BMCR + @sa getPHYRAR_BMCR(), setPHYRAR_BMCR() +*/ +#define BMCR_COLT (1<<7) + +/*For BMSR register*/ + +/** + @brief Ethernet PHY 100 Base-T4 capable + @details @ref BMSR_100_T4 is always 0. + @note It is not supported. + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_100_T4 (1<<15) + +/** + @brief Ethernet PHY 100 Base-TX Full-Duplex capable + @details @ref BMSR_100_FDX is always 1. + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_100_FDX (1<<14) + +/** + @brief Ethernet PHY 100 Base-TX Half-Duplex capable + @details @ref BMSR_100_HDX is always 1. + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_100_HDX (1<<13) + +/** + @brief Ethernet PHY 10 Base-T Full-Duplex capable + @details @ref BMSR_10_FDX is always 1. + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_10_FDX (1<<12) + +/** + @brief Ethernet PHY 10 Base-T Half-Duplex capable + @details @ref BMSR_10_HDX is always 1. + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_10_HDX (1<<11) + +/** + @brief Ethernet PHY Management Frame preamble suppression + @details @ref BMSR_MF_SUP is always 0. + @note It is not supported + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_MF_SUP (1<<6) + +/** + @brief Ethernet PHY Auto-Negotiation Complete + @details @ref BMSR_MF_SUP indicates the status of auto-negotiation. \n + 0 - Auto-negotiation process is not completed \n + 1 - Auto-negotiation process is completed + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_AN_COMP (1<<5) + +/** + @brief Ethernet PHY Remote Fault + @details @ref BMSR_REMOTE_FAULT is always 0. + @note It is not supported + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_REMOTE_FAULT (1<<4) + +/** + @brief Ethernet PHY Auto-Negotiation Ability + @details @ref BMSR_AN_ABILITY is always 1. + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_AN_ABILITY (1<<3) + +/** + @brief Ethernet PHY Link Status + @details @ref BMSR_LINK_STATUS indicates the status of link. \n + 0 - Link is not established + 1 - Valid link is established + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_LINK_STATUS (1<<2) + +/** + @brief Ethernet PHY Jabber Detect + @details @ref BMSR_JABBER_DETECT indicates the status of auto-negotiation. \n + 0 - Jabber condition is not detected\n + 1 - Jabber condition is detected + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_JABBER_DETECT (1<<1) + +/** + @brief Ethernet PHY Extended capability + @details @ref BMSR_EXT_CAPA indicates the extended register capability. \n + 0 - Only basic registers are capable\n + 1 - Extended registers are capable + @sa PHYCR_BMSR + @sa getPHYRAR_BMSR() +*/ +#define BMSR_EXT_CAPA (1<<0) + + +/** + @brief Enter a critical section + @details It is provided to protect your shared code and hardware resources against interference. \n + - Non-OS environment + It can be just implemented by disabling whole interrupt. + - OS environment + You can replace it to critical section API supported by OS. + + @note It is callback function that can be replaced it with your code, by calling @ref reg_wizchip_cris_cbfunc(). + @sa WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF() + @sa WIZCHIP_CRITICAL_EXIT(), reg_wizchip_cris_cbfunc() +*/ +#define WIZCHIP_CRITICAL_ENTER() WIZCHIP.CRIS._enter() + + +/** + @brief Enter a critical section + @details It exits the protected code and hardware resources against interference. \n + - Non-OS environment + It can be just implemented by enabling whole interrupt.\n + - OS environment + You can replace it to critical section API supported by OS. + + @note It is callback function that can be replaced it with your code, by calling @ref reg_wizchip_cris_cbfunc(). + @sa WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF() + @sa WIZCHIP_CRITICAL_EXIT(), reg_wizchip_cris_cbfunc() +*/ +#define WIZCHIP_CRITICAL_EXIT() WIZCHIP.CRIS._exit() + + + +//////////////////////// +// Basic I/O Function // +//////////////////////// +// +// +/** + @ingroup Basic_IO_function_W6300 + @brief It reads 1 byte value from a register. + @param AddrSel Register address + @return The value of register + @sa WIZCHIP_READ_BUF(), reg_wizchip_bus_cbfunc(), reg_wizchip_spi_cbfunc(), WIZCHIP_WRITE() +*/ +uint8_t WIZCHIP_READ(uint32_t AddrSel); + +/** + @ingroup Basic_IO_function_W6300 + @brief It writes 1 byte value to a register. + @param AddrSel Register address + @param wb Write data + @return void + @sa WIZCHIP_WRITE_BUF(), reg_wizchip_bus_cbfunc(), reg_wizchip_spi_cbfunc(), WIZCHIP_READ() +*/ +void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb); + +/** + @ingroup Basic_IO_function_W6300 + @brief It reads sequentail data from registers. + @param AddrSel Register address + @param pBuf Pointer buffer to read data + @param len Data length + @return void + @sa WIZCHIP_WRITE_BUF(), reg_wizchip_bus_cbfunc(), reg_wizchip_spi_cbfunc(), WIZCHIP_READ() +*/ +void WIZCHIP_READ_BUF(uint32_t AddrSel, uint8_t* pBuf, datasize_t len); + +/** + @ingroup Basic_IO_function_W6300 + @brief It writes sequential data to registers. + @param AddrSel Register address + @param pBuf Pointer buffer to write data + @param len Data length + @return void + @sa WIZCHIP_READ_BUF(), reg_wizchip_bus_cbfunc(), reg_wizchip_spi_cbfunc(), WIZCHIP_WRITE() +*/ +void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, datasize_t len); + + + +///////////////////////////////// +// Common Register IO function // +///////////////////////////////// +/** + @addtogroup Common_register_access_function_W6300 + @{ +*/ + +#define getRTL() \ + WIZCHIP_READ(_RTL_) + +#define getCIDR() \ + ((((uint16_t)WIZCHIP_READ(_CIDR_)| (((WIZCHIP_READ(_RTL_))&0x0F) << 1)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_CIDR_,1))) + +#define getVER() \ + ((((uint16_t)WIZCHIP_READ(_VER_)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_VER_,1))) + +#define getSYSR() \ + WIZCHIP_READ(_SYSR_) + +#define getSYCR0() \ + WIZCHIP_READ(_SYCR0_) + +#define setSYCR0(sycr0) \ + WIZCHIP_WRITE(_SYCR0_, (sycr0)) + +#define getSYCR1() \ + WIZCHIP_READ(_SYCR1_) + +#define setSYCR1(sycr1) \ + WIZCHIP_WRITE(_SYCR1_, (sycr1)) + +#define getTCNTR() \ + ((((uint16_t)WIZCHIP_READ(_TCNTR_)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_TCNTR_,1))) + +#define setTCNTRCLR(tcntrclr) \ + WIZCHIP_WRITE(_TCNTRCLR_,(tcntrclr)) + +#define getIR() \ + WIZCHIP_READ(_IR_) + +#define getSIR() \ + WIZCHIP_READ(_SIR_) + +#define getSLIR() \ + WIZCHIP_READ(_SLIR_) + +#define setIMR(imr) \ + WIZCHIP_WRITE(_IMR_,(imr)) + +#define getIMR() \ + WIZCHIP_READ(_IMR_) + +#define setIRCLR(irclr) \ + WIZCHIP_WRITE(_IRCLR_,(irclr)) +#define setIR(ir) setIRCLR(ir) + +#define setSIMR(simr) \ + WIZCHIP_WRITE(_SIMR_,(simr)) + +#define getSIMR() \ + WIZCHIP_READ(_SIMR_) + +#define setSLIMR(slimr) \ + WIZCHIP_WRITE(_SLIMR_,(slimr)) + +#define getSLIMR() \ + WIZCHIP_READ(_SLIMR_) + +#define setSLIRCLR(slirclr) \ + WIZCHIP_WRITE(_SLIRCLR_,(slirclr)) +#define setSLIR(slir) setSLIRCLR(slir) + +#define setSLPSR(slpsr) \ + WIZCHIP_WRITE(_SLPSR_,(slpsr)) + +#define getSLPSR() \ + WIZCHIP_READ(_SLPSR_) + +#define setSLCR(slcr) \ + WIZCHIP_WRITE(_SLCR_,(slcr)) + +#define getSLCR() \ + WIZCHIP_READ(_SLCR_) + +#define getPHYSR() \ + WIZCHIP_READ(_PHYSR_) + +#define setPHYRAR(phyrar) \ + WIZCHIP_WRITE(_PHYRAR_,(phyrar)) + +#define getPHYRAR() \ + WIZCHIP_READ(_PHYRAR_) + +#define setPHYDIR(phydir) \ + do{ \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_PHYDIR_,1), (uint8_t)((phydir)>>8)); \ + WIZCHIP_WRITE(_PHYDIR_, (uint8_t)(phydir)); \ + }while(0); + +#define getPHYDOR() \ + ((((uint16_t)WIZCHIP_READ(WIZCHIP_OFFSET_INC(_PHYDOR_,1))) << 8) + WIZCHIP_READ(_PHYDOR_)) + +#define setPHYACR(phyacr) \ + WIZCHIP_WRITE(_PHYACR_,(phyacr)) + +#define getPHYACR() \ + WIZCHIP_READ(_PHYACR_) + +#define setPHYDIVR(phydivr) \ + WIZCHIP_WRITE(_PHYDIVR_,(phydivr)) + +#define getPHYDIVR() \ + WIZCHIP_READ(_PHYDIVR_) + +#define setPHYCR0(phycr0) \ + WIZCHIP_WRITE(_PHYCR0_,(phycr0)) + +#define setPHYCR1(phycr1) \ + WIZCHIP_WRITE(_PHYCR1_,(phycr1)) + +#define getPHYCR1() \ + WIZCHIP_READ(_PHYCR1_) + +#define setNET4MR(net4mr) \ + WIZCHIP_WRITE(_NET4MR_,(net4mr)) + +#define setNET6MR(net6mr) \ + WIZCHIP_WRITE(_NET6MR_,(net6mr)) + +#define setNETMR(netmr) \ + WIZCHIP_WRITE(_NETMR_,(netmr)) + +#define setNETMR2(netmr2) \ + WIZCHIP_WRITE(_NETMR2_,(netmr2)) + +#define getNET4MR() \ + WIZCHIP_READ(_NET4MR_) + +#define getNET6MR() \ + WIZCHIP_READ(_NET6MR_) + +#define getNETMR() \ + WIZCHIP_READ(_NETMR_) + +#define getNETMR2() \ + WIZCHIP_READ(_NETMR2_) + +#define setPTMR(ptmr) \ + WIZCHIP_WRITE(_PTMR_, (ptmr)) + +#define getPTMR() \ + WIZCHIP_READ(_PTMR_) + +#define setPMNR(pmnr) \ + WIZCHIP_WRITE(_PMNR_, (pmnr)) + +#define getPMNR() \ + WIZCHIP_READ(_PMNR_) + +#define setPHAR(phar) \ + WIZCHIP_WRITE_BUF(_PHAR_,(phar),6) + +#define getPHAR(phar) \ + WIZCHIP_READ_BUF(_PHAR_,(phar),6) + +#define setPSIDR(psidr) \ + do{ \ + WIZCHIP_WRITE(_PSIDR_,(uint8_t)((psidr) >> 8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_PSIDR_,1),(uint8_t)(psidr)); \ + }while(0); + +#define getPSIDR() \ + ((((uint16_t)WIZCHIP_READ(_PSIDR_)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_PSIDR_,1))) + +#define setPMRUR(pmrur) \ + do{ \ + WIZCHIP_WRITE(_PMRUR_,(uint8_t)((pmrur) >> 8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_PMRUR_,1),(uint8_t)(pmrur)); \ + }while(0); + +#define getPMRUR() \ + ((((uint16_t)WIZCHIP_READ(_PMRUR_)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_PMRUR_,1))) + +#define setSHAR(shar) \ + WIZCHIP_WRITE_BUF(_SHAR_,(shar),6) + +#define getSHAR(shar) \ + WIZCHIP_READ_BUF(_SHAR_,(shar),6) + +#define setGAR(gar) \ + WIZCHIP_WRITE_BUF(_GAR_,(gar),4) + +#define getGAR(gar) \ + WIZCHIP_READ_BUF(_GAR_,(gar),4) + +#define setGA4R(ga4r) setGAR(ga4r) +#define getGA4R(ga4r) getGAR(ga4r) + +#define setSUBR(subr) \ + WIZCHIP_WRITE_BUF(_SUBR_,(subr),4) + +#define getSUBR(subr) \ + WIZCHIP_READ_BUF(_SUBR_,(subr),4) + +#define setSUB4R(sub4r) setSUBR(sub4r) +#define getSUB4R(sub4r) getSUBR(sub4r) + +#define setSIPR(sipr) \ + WIZCHIP_WRITE_BUF(_SIPR_,(sipr),4) + +#define getSIPR(sipr) \ + WIZCHIP_READ_BUF(_SIPR_,(sipr),4) + +#define setLLAR(llar) \ + WIZCHIP_WRITE_BUF(_LLAR_,(llar),16) + +#define getLLAR(llar) \ + WIZCHIP_READ_BUF(_LLAR_,(llar),16) + +#define setGUAR(guar) \ + WIZCHIP_WRITE_BUF(_GUAR_,(guar),16) + +#define getGUAR(guar) \ + WIZCHIP_READ_BUF(_GUAR_,(guar),16) + +#define setSUB6R(sub6r) \ + WIZCHIP_WRITE_BUF(_SUB6R_,(sub6r),16) + +#define getSUB6R(sub6r) \ + WIZCHIP_READ_BUF(_SUB6R_,(sub6r),16) + +#define setGA6R(ga6r) \ + WIZCHIP_WRITE_BUF(_GA6R_,(ga6r),16) + +#define getGA6R(ga6r) \ + WIZCHIP_READ_BUF(_GA6R_,(ga6r),16) + +#define setSLDIPR(sldipr) \ + WIZCHIP_WRITE_BUF(_SLDIPR_,(sldipr),4) +#define setSLDIP4R(sldip4r) setSLDIPR((sldip4r)) + +#define getSLDIPR(sldipr) \ + WIZCHIP_READ_BUF(_SLDIPR_,(sldipr),4) +#define getSLDIP4R(sldip4r) getSLDIPR((sldip4r)) + +#define setSLDIP6R(sldip6r) \ + WIZCHIP_WRITE_BUF(_SLDIP6R_, (sldip6r),16) + +#define getSLDIP6R(sldip6r) \ + WIZCHIP_READ_BUF(_SLDIP6R_,(sldip6r),16) + +#define getSLDHAR(sldhar) \ + WIZCHIP_READ_BUF(_SLDHAR_,(sldhar),6) + +#define setPINGIDR(pingidr) \ + do{ \ + WIZCHIP_WRITE(_PINGIDR_,(uint8_t)((pingidr)>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_PINGIDR_,1),(uint8_t)(pingidr)); \ + }while(0); + +#define getPINGIDR() \ + (((int16_t)(WIZCHIP_READ(_PINGIDR_) << 8)) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_PINGIDR_,1))) + +#define setPINGSEQR(pingseqr) \ + do{ \ + WIZCHIP_WRITE(_PINGSEQR_,(uint8_t)((pingseqr)>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_PINGSEQR_,1),(uint8_t)(pingseqr)); \ + }while(0); + +#define getPINGSEQR() \ + (((int16_t)(WIZCHIP_READ(_PINGSEQR_) << 8)) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_PINGSEQR_,1))) + +#define getUIPR(uipr) \ + WIZCHIP_READ_BUF(_UIPR_, (uipr), 4) + +#define getUIP4R(uip4r) getUIPR(uip4r) + +#define getUPORTR() \ + ((((uint16_t)WIZCHIP_READ(_UPORTR_)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_UPORTR_,1))) + +#define getUPORT4R() getUPORTR() + +#define getUIP6R(uip6r) \ + WIZCHIP_READ_BUF(_UIP6R_,(uip6r),16) + +#define getUPORT6R(uport6r) \ + ((((uint16_t)WIZCHIP_READ(_UPORT6R_)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_UPORT6R_,1))) + +#define setINTPTMR(intptmr) \ + do{ \ + WIZCHIP_WRITE(_INTPTMR_,(uint8_t)((intptmr) >> 8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_INTPTMR_,1),(uint8_t)(intptmr)); \ + }while(0); + +#define getINTPTMR() \ + ((((uint16_t)WIZCHIP_READ(_INTPTMR_)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_INTPTMR_,1))) + +#define getPLR() \ + WIZCHIP_READ(_PLR_) + +#define getPFR() \ + WIZCHIP_READ(_PFR_) + +#define getVLTR() \ + ( (((uint32_t)WIZCHIP_READ(_VLTR_)) << 24) + \ + (((uint32_t)WIZCHIP_READ(WIZCHIP_OFFSET_INC(_VLTR_,1))) << 16) + \ + (((uint32_t)WIZCHIP_READ(WIZCHIP_OFFSET_INC(_VLTR_,2))) << 16) + \ + (((uint32_t)WIZCHIP_READ(WIZCHIP_OFFSET_INC(_VLTR_,3))) << 16) ) + +#define getPLTR() \ + ( (((uint32_t)WIZCHIP_READ(_PLTR_)) << 24) + \ + (((uint32_t)WIZCHIP_READ(WIZCHIP_OFFSET_INC(_PLTR_,1))) << 16) + \ + (((uint32_t)WIZCHIP_READ(WIZCHIP_OFFSET_INC(_PLTR_,2))) << 16) + \ + (((uint32_t)WIZCHIP_READ(WIZCHIP_OFFSET_INC(_PLTR_,3))) << 16) ) + +#define getPAR(par) \ + WIZCHIP_READ_BUF(_PAR_, (par), 16) + +#define setICMP6BLKR(icmp6blkr) \ + WIZCHIP_WRITE(_ICMP6BLKR_,(icmp6blkr)) + +#define getICMP6BLKR() \ + WIZCHIP_READ(_ICMP6BLKR_) + +#define setCHPLCKR(chplckr) \ + WIZCHIP_WRITE(_CHPLCKR_, (chplckr)) + +#define getCHPLCKR() \ + ((getSYSR() & SYSR_CHPL) >> 7) + +#define CHIPLOCK() setCHPLCKR(0xFF) +#define CHIPUNLOCK() setCHPLCKR(0xCE) + +#define setNETLCKR(netlckr) \ + WIZCHIP_WRITE(_NETLCKR_, (netlckr)) + +#define getNETLCKR() \ + ((getSYSR() & SYSR_NETL) >> 6) + +#define NETLOCK() setNETLCKR(0xC5) +#define NETUNLOCK() setNETLCKR(0x3A) + +#define setPHYLCKR(phylckr) \ + WIZCHIP_WRITE(_PHYLCKR_,(phylckr)) + +#define getPHYLCKR() \ + ((getSYSR() & SYSR_PHYL) >> 5) + +#define PHYLOCK() setPHYLCKR(0xFF) +#define PHYUNLOCK() setPHYLCKR(0x53) + +#define setRTR(rtr) \ + do{ \ + WIZCHIP_WRITE(_RTR_,(uint8_t)((rtr)>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_RTR_,1),(uint8_t)(rtr)); \ + }while(0); + +#define getRTR() \ + ((((uint16_t)WIZCHIP_READ(_RTR_)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_RTR_,1))) + +#define setRCR(rcr) \ + WIZCHIP_WRITE(_RCR_,(rcr)) + +#define getRCR() \ + WIZCHIP_READ(_RCR_) + +#define setSLRTR(slrtr) \ + do{ \ + WIZCHIP_WRITE(_SLRTR_,(uint8_t)((slrtr)>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_SLRTR_,1),(uint8_t)(slrtr)); \ + }while(0); + +#define getSLRTR() \ + ((((uint16_t)WIZCHIP_READ(_SLRTR_)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_SLRTR_,1))) + +#define setSLRCR(slrcr) \ + WIZCHIP_WRITE(_SLRCR_,(slrcr)) + +#define getSLRCR() \ + WIZCHIP_READ(_SLRCR_) + +#define setSLHOPR(slhopr) \ + WIZCHIP_WRITE(_SLHOPR_,(slhopr)) + +#define getSLHOPR() \ + WIZCHIP_READ(_SLHOPR_) +/** + @} +*/ + + +//////////////////////////////////// +// SOCKETn register I/O function // +//////////////////////////////////// +/** + @addtogroup Socket_register_access_function_W6300 + @{ +*/ +#define setSn_MR(sn,mr) \ + WIZCHIP_WRITE(_Sn_MR_(sn),(mr)) +#define getSn_MR(sn) \ + WIZCHIP_READ(_Sn_MR_(sn)) + +#define setSn_PSR(sn,psr) \ + WIZCHIP_WRITE(_Sn_PSR_(sn),(psr)) +#define getSn_PSR(sn) \ + WIZCHIP_READ(_Sn_PSR_(sn)) + +#define setSn_CR(sn,cr) \ + WIZCHIP_WRITE(_Sn_CR_(sn),(cr)) +#define getSn_CR(sn) \ + WIZCHIP_READ(_Sn_CR_(sn)) + +#define getSn_IR(sn) \ + WIZCHIP_READ(_Sn_IR_(sn)) + +#define setSn_IMR(sn,imr) \ + WIZCHIP_WRITE(_Sn_IMR_(sn),(imr)) +#define getSn_IMR(sn) \ + WIZCHIP_READ(_Sn_IMR_(sn)) + +#define setSn_IRCLR(sn,irclr) \ + WIZCHIP_WRITE(_Sn_IRCLR_(sn),(irclr)) +#define setSn_IR(sn,ir) setSn_IRCLR(sn,(ir)) + +#define getSn_SR(sn) \ + WIZCHIP_READ(_Sn_SR_(sn)) + +#define getSn_ESR(sn) \ + WIZCHIP_READ(_Sn_ESR_(sn)) + +#define setSn_PNR(sn,pnr) \ + WIZCHIP_WRITE(_Sn_PNR_(sn),(pnr)) +#define setSn_NHR(sn,nhr) setSn_PNR(_Sn_PNR_(sn),(nhr)) + +#define getSn_PNR(sn) \ + WIZCHIP_READ(_Sn_PNR_(sn)) +#define getSn_NHR(sn) getSn_PNR(sn) + +#define setSn_TOSR(sn,tosr) \ + WIZCHIP_WRITE(_Sn_TOSR_(sn),(tosr)) +#define getSn_TOSR(sn) \ + WIZCHIP_READ(_Sn_TOSR_(sn)) +#define getSn_TOS(sn) getSn_TOSR(sn) ///< For compatible ioLibrar +#define setSn_TOS(sn,tos) setSn_TOSR(sn,tos) ///< For compatible ioLibrar + + +#define setSn_TTLR(sn,ttlr) \ + WIZCHIP_WRITE(_Sn_TTLR_(sn),(ttlr)) +#define getSn_TTLR(sn) \ + WIZCHIP_READ(_Sn_TTLR_(sn)) +#define setSn_TTL(sn,ttl) setSn_TTLR(sn,ttl) ///< For compatible ioLibrary +#define getSn_TTL(sn) getSn_TTLR(sn) ///< For compatible ioLibrary + +#define setSn_HOPR(sn,hopr) setSn_TTLR(sn),(ttlr)) +#define getSn_HOPR(sn) getSn_TTLR(sn) + +#define setSn_FRGR(sn,frgr) \ + do{ \ + WIZCHIP_WRITE(_Sn_FRGR_(sn),(uint8_t)((frgr)>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_Sn_FRGR_(sn),1),(uint8_t)(frgr)); \ + }while(0); +#define getSn_FRGR(sn,frgr) \ + ((((uint16_t)WIZCHIP_READ(_Sn_FRGR_(sn))) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_Sn_FRGR_(sn),1))) + +#define setSn_MSSR(sn,mssr) \ + do{ \ + WIZCHIP_WRITE(_Sn_MSSR_(sn),(uint8_t)((mssr)>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_Sn_MSSR_(sn),1),(uint8_t)(mssr)); \ + }while(0); +#define getSn_MSSR(sn) \ + ((((uint16_t)WIZCHIP_READ(_Sn_MSSR_(sn))) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_Sn_MSSR_(sn),1))) + +#define setSn_PORTR(sn,portr) \ + do{ \ + WIZCHIP_WRITE(_Sn_PORTR_(sn),(uint8_t)((portr)>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_Sn_PORTR_(sn),1),(uint8_t)(portr)); \ + }while(0); +#define getSn_PORTR(sn) \ + ((((uint16_t)WIZCHIP_READ(_Sn_PORTR_(sn))) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_Sn_PORTR_(sn),1))) + +#define setSn_DHAR(sn,dhar) \ + WIZCHIP_WRITE_BUF(_Sn_DHAR_(sn),(dhar),6) +#define getSn_DHAR(sn,dhar) \ + WIZCHIP_READ_BUF(_Sn_DHAR_(sn),(dhar),6) + +#define setSn_DIPR(sn,dipr) \ + WIZCHIP_WRITE_BUF(_Sn_DIPR_(sn),(dipr),4) +#define getSn_DIPR(sn,dipr) \ + WIZCHIP_READ_BUF(_Sn_DIPR_(sn),(dipr),4) + +#define setSn_DIP4R(sn,dipr) setSn_DIPR(sn,(dipr)) +#define getSn_DIP4R(sn,dipr) getSn_DIPR(sn,(dipr)) + +#define setSn_DIP6R(sn,dip6r) \ + WIZCHIP_WRITE_BUF(_Sn_DIP6R_(sn),(dip6r),16) +#define getSn_DIP6R(sn,dip6r) \ + WIZCHIP_READ_BUF(_Sn_DIP6R_(sn),(dip6r),16) + +#define setSn_DPORTR(sn,dportr) \ + do{ \ + WIZCHIP_WRITE(_Sn_DPORTR_(sn),(uint8_t)((dportr)>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_Sn_DPORTR_(sn),1),(uint8_t)(dportr)); \ + }while(0); + + +#define getSn_DPORTR(sn) \ + ((((uint16_t)WIZCHIP_READ(_Sn_DPORTR_(sn))) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_Sn_DPORTR_(sn),1))) + +#define getSn_DPORT(sn) getSn_DPORTR(sn) +#define setSn_DPORT(sn,dportr) setSn_DPORTR(sn,dportr) + + +#define setSn_MR2(sn,mr2) \ + WIZCHIP_WRITE(_Sn_MR2_(sn),(mr2)) +#define getSn_MR2(sn) \ + WIZCHIP_READ(_Sn_MR2_(sn)) + +#define setSn_RTR(sn,rtr) \ + do{ \ + WIZCHIP_WRITE(_Sn_RTR_(sn),(uint8_t)((rtr)>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_Sn_RTR_(sn),1),(uint8_t)(rtr)); \ + }while(0); +#define getSn_RTR(sn) \ + ((((uint16_t)WIZCHIP_READ(_Sn_RTR_(sn))) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_Sn_RTR_(sn),1))) + +#define setSn_RCR(sn,rcr) \ + WIZCHIP_WRITE(_Sn_RCR_(sn),(rcr)) +#define getSn_RCR(sn) \ + WIZCHIP_READ(_Sn_RCR_(sn)) + +#define setSn_KPALVTR(sn,kpalvtr) \ + WIZCHIP_WRITE(_Sn_KPALVTR_(sn),(kpalvtr)) +#define getSn_KPALVTR(sn) \ + WIZCHIP_READ(_Sn_KPALVTR_(sn)) + +#define setSn_TX_BSR(sn, tmsr) \ + WIZCHIP_WRITE(_Sn_TX_BSR_(sn),(tmsr)) +#define setSn_TXBUF_SIZE(sn, tmsr) setSn_TX_BSR(sn,(tmsr)) + +#define getSn_TX_BSR(sn) \ + WIZCHIP_READ(_Sn_TX_BSR_(sn)) +#define getSn_TXBUF_SIZE(sn) getSn_TX_BSR(sn) + +#define getSn_TxMAX(sn) \ + (getSn_TX_BSR(sn) << 10) + +uint16_t getSn_TX_FSR(uint8_t sn); + +#define getSn_TX_RD(sn) \ + ((((uint16_t)WIZCHIP_READ(_Sn_TX_RD_(sn))) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_Sn_TX_RD_(sn),1))) + +#define setSn_TX_WR(sn,txwr) \ + do{ \ + WIZCHIP_WRITE(_Sn_TX_WR_(sn), (uint8_t)((txwr)>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_Sn_TX_WR_(sn),1), (uint8_t)(txwr)); \ + }while(0); +#define getSn_TX_WR(sn) \ + (((uint16_t)WIZCHIP_READ(_Sn_TX_WR_(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_Sn_TX_WR_(sn),1))) + +#define setSn_RX_BSR(sn,rmsr) \ + WIZCHIP_WRITE(_Sn_RX_BSR_(sn),(rmsr)) +#define setSn_RXBUF_SIZE(sn,rmsr) setSn_RX_BSR(sn,(rmsr)) + +#define getSn_RX_BSR(sn) \ + WIZCHIP_READ(_Sn_RX_BSR_(sn)) +#define getSn_RXBUF_SIZE(sn) getSn_RX_BSR(sn) + +#define getSn_RxMAX(sn) \ + (getSn_RX_BSR(sn) <<10) + +uint16_t getSn_RX_RSR(uint8_t s); + +#define setSn_RX_RD(sn,rxrd) \ + do{ \ + WIZCHIP_WRITE(_Sn_RX_RD_(sn), (uint8_t)((rxrd)>>8)); \ + WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_Sn_RX_RD_(sn),1), (uint8_t)(rxrd)) ; \ + }while(0); + +#define getSn_RX_RD(sn) \ + (((uint16_t)WIZCHIP_READ(_Sn_RX_RD_(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_Sn_RX_RD_(sn),1))) + +#define getSn_RX_WR(sn) \ + (((uint16_t)WIZCHIP_READ(_Sn_RX_WR_(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_Sn_RX_WR_(sn),1))) +/** + @} +*/ + + +///////////////////////////////////// +// Sn_TXBUF & Sn_RXBUF IO function // +///////////////////////////////////// +/** + @ingroup Basic_IO_function_W6300 + @brief It saves data to be sent in the SOCKETn TX buffer. + @details This function reads first @ref _Sn_TX_WR_ \n + and starts to copy wizdata from @ref _Sn_TX_WR_ address of SOCKETn TX buffer as many as len.\n + After it is completed to copy , \n + It increases @ref _Sn_TX_WR_ as many as len. + @param sn SOCKETn. 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_W6300 + @brief It reads the received data from the SOCKETn RX buffer and copies the data to your system memory specified by wizdata. + @details This function reads first @ref _Sn_RX_RD_ \n + and starts to copy the received data to wizdata as many as len.\n + After it is completed to copy the received data, \n + It increases @ref _Sn_RX_RD_ as many as len. + @param sn SOCKETn. 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_W6300 + @brief It discards the received data in the SOCKETn RX buffer. + @details This function discards the received data by increasing @ref _Sn_RX_RD_ as manay as len without coping the data. + @param sn SOCKETn. It should be 0 ~ @ref _WIZCHIP_SOCK_NUM_. + @param len Data length +*/ +void wiz_recv_ignore(uint8_t sn, uint16_t len); + +#if 1 +// 20231019 taylor +/** + @ingroup Special_function_W6300 + @brief Delay function + @details Delay function using internal 100us timer of the W6300 + @param (uint32_t)ms Time to delay in milliseconds. +*/ +void wiz_delay_ms(uint32_t ms); +#endif + +/// @cond DOXY_APPLY_CODE +#if (_PHY_IO_MODE_ == _PHY_IO_MODE_MII_) +/// @endcond +/** + @ingroup Special_function_W6300 + @brief Write data to the PHY via MDC/MDIO interface. + @details Write command data to the PHY via MDC/MDIO interface. + @param phyregaddr Address of the PHY register. It should be @ref PHYRAR_BMCR, @ref PHYRAR_BMSR, and etc. + @param var Data to write to the PHY register. Please refer to the bit definitions of the BMCR and BMSR register. + @note In order to use it, You should define @ref _PHY_IO_MODE_ to @ref _PHY_IO_MODE_MII_. +*/ +void wiz_mdio_write(uint8_t phyregaddr, uint16_t var); + +/** + @ingroup Special_function_W6300 + @brief Read data from the PHY via MDC/MDIO interface. + @details Read command or status data from the PHY via MDC/MDIO interface. + @param phyregaddr Address of the PHY register. It should be @ref PHYRAR_BMCR, @ref PHYRAR_BMSR, and etc. + @return The value of the PHY register + @note In order to use it, You should define @ref _PHY_IO_MODE_ to @ref _PHY_IO_MODE_MII_. +*/ +uint16_t wiz_mdio_read(uint8_t phyregaddr); +/// @cond DOXY_APPLY_CODE +#endif +/// @endcond + +/// @cond DOXY_APPLY_CODE +#endif // _WIZCHIP_ == 6100 +/// @endcond + + +#ifdef __cplusplus +} +#endif + + +#endif //_W6300_H_ \ No newline at end of file diff --git a/Ethernet/socket.c b/Ethernet/socket.c new file mode 100644 index 0000000..4f6ee50 --- /dev/null +++ b/Ethernet/socket.c @@ -0,0 +1,1473 @@ +//***************************************************************************** +// +//! \file socket.c +//! \brief SOCKET APIs Implements file. +//! \details SOCKET APIs like as Berkeley Socket APIs. +//! \version 1.0.3 +//! \date 2013/10/21 +//! \par Revision history +//! <2015/02/05> Notice +//! The version history is not updated after this point. +//! Download the latest version directly from GitHub. Please visit the our GitHub repository for ioLibrary. +//! >> https://github.com/Wiznet/ioLibrary_Driver +//! <2014/05/01> V1.0.3. Refer to M20140501 +//! 1. Implicit type casting -> Explicit type casting. +//! 2. replace 0x01 with PACK_REMAINED in recvfrom() +//! 3. Validation a destination ip in connect() & sendto(): +//! It occurs a fatal error on converting unint32 address if uint8* addr parameter is not aligned by 4byte address. +//! Copy 4 byte addr value into temporary uint32 variable and then compares it. +//! <2013/12/20> V1.0.2 Refer to M20131220 +//! Remove Warning. +//! <2013/11/04> V1.0.1 2nd Release. Refer to "20131104". +//! In sendto(), Add to clear timeout interrupt status (Sn_IR_TIMEOUT) +//! <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. +// +//***************************************************************************** +#include "socket.h" + +//M20150401 : Typing Error +//#define SOCK_ANY_PORT_NUM 0xC000; +#define SOCK_ANY_PORT_NUM 0xC000 + +static uint16_t sock_any_port = SOCK_ANY_PORT_NUM; +static uint16_t sock_io_mode = 0; +static uint16_t sock_is_sending = 0; + +static uint16_t sock_remained_size[_WIZCHIP_SOCK_NUM_] = {0, 0,}; + +//M20150601 : For extern decleation +//static uint8_t sock_pack_info[_WIZCHIP_SOCK_NUM_] = {0,}; +uint8_t sock_pack_info[_WIZCHIP_SOCK_NUM_] = {0,}; +// + +#if _WIZCHIP_ == 5200 +static uint16_t sock_next_rd[_WIZCHIP_SOCK_NUM_] = {0,}; +#endif + +//A20150601 : For integrating with W5300 +#if _WIZCHIP_ == 5300 +uint8_t sock_remained_byte[_WIZCHIP_SOCK_NUM_] = {0,}; // set by wiz_recv_data() +#endif + + +#define CHECK_SOCKNUM() \ + do{ \ + if(sn >= _WIZCHIP_SOCK_NUM_) return SOCKERR_SOCKNUM; \ + }while(0); \ + +#define CHECK_SOCKMODE(mode) \ + do{ \ + if((getSn_MR(sn) & 0x0F) != mode) return SOCKERR_SOCKMODE; \ + }while(0); \ + +#define CHECK_TCPMODE() \ + do{ \ + if((getSn_MR(sn) & 0x03) != 0x01) return SOCKERR_SOCKMODE; \ + }while(0); + +#define CHECK_SOCKINIT() \ + do{ \ + if((getSn_SR(sn) != SOCK_INIT)) return SOCKERR_SOCKINIT; \ + }while(0); \ + +#define CHECK_SOCKDATA() \ + do{ \ + if(len == 0) return SOCKERR_DATALEN; \ + }while(0); \ +//teddy 240122 +#if _WIZCHIP_ == W6100 || _WIZCHIP_ == W6300 +#define CHECK_TCPMODE() \ + do{ \ + if((getSn_MR(sn) & 0x03) != 0x01) return SOCKERR_SOCKMODE; \ + }while(0); + +#define CHECK_UDPMODE() \ + do{ \ + if((getSn_MR(sn) & 0x03) != 0x02) return SOCKERR_SOCKMODE; \ + }while(0); + +#define CHECK_IPMODE() \ + do{ \ + if((getSn_MR(sn) & 0x07) != 0x03) return SOCKERR_SOCKMODE; \ + }while(0); + +#define CHECK_DGRAMMODE() \ + do{ \ + if(getSn_MR(sn) == Sn_MR_CLOSED) return SOCKERR_SOCKMODE; \ + if((getSn_MR(sn) & 0x03) == 0x01) return SOCKERR_SOCKMODE; \ + }while(0); + +#define CHECK_IPZERO(addr, addrlen) \ + do{ \ + uint16_t ipzero= 0; \ + for(uint8_t i=0; i W5500) +#define IPV6_AVAILABLE +#endif + +#if 1 + + +#define Sn_MR_TCP4 (Sn_MR_TCP) ///< Refer to @ref Sn_MR_TCP. +#define Sn_MR_UDP4 (Sn_MR_UDP) ///< Refer to @ref Sn_MR_UDP +#define Sn_MR_IPRAW4 (Sn_MR_IPRAW) ///< Refer to @ref Sn_MR_IPRAW. +#define Sn_MR_TCP6 (0x09) +#define Sn_MR_UDP6 (0x0A) //0x1010 +#define Sn_MR_IPRAW6 (0x0B) //0x1011 +#define Sn_MR_TCPD (0x0D) +#define Sn_MR_UDPD (0x0E) + + + +#endif + + +#if 0 // By lihan +static uint8_t addrlenTEST = -1 ; + +void setAddrlen_W6x00(uint8_t num) { + addrlenTEST = num; +} + +uint8_t checkAddrlen_W6x00() { + //if (addrlenTEST < 0 ) + if ((addrlenTEST != 4) && (addrlenTEST != 16)) { + perror("Error: addrlen is not initialized"); + } else { + printf("addrlenTEST %d \r\n", addrlenTEST) ; + } + return addrlenTEST; +} + +inline void inline_setAddrlen_W6x00(uint8_t num) { +#if (_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300) + setAddrlen_W6x00(num); +#endif +} + +inline uint8_t inline_CheckAddrlen_W6x00(void) { +#if (_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300) + return checkAddrlen_W6x00(); +#else + return 4; +#endif +} +#endif + + + + +int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag) { + + uint8_t taddr[16]; + uint16_t local_port = 0; + CHECK_SOCKNUM(); + switch (protocol & 0x0F) { +#ifdef IPV6_AVAILABLE + case Sn_MR_TCP4 : + getSIPR(taddr); + CHECK_IPZERO(taddr, 4); + break; + case Sn_MR_TCP6 : + getLLAR(taddr); + CHECK_IPZERO(taddr, 16); + //getGUAR(taddr); + //CHECK_IPZERO(taddr, 16); + break; + case Sn_MR_TCPD : + getSIPR(taddr); + CHECK_IPZERO(taddr, 4); + getLLAR(taddr); + CHECK_IPZERO(taddr, 16); + //getGUAR(taddr); + //CHECK_IPZERO(taddr, 16); + break; +#else + case Sn_MR_TCP : { + //M20150601 : Fixed the warning - taddr will never be NULL + /* + uint8_t taddr[4]; + getSIPR(taddr); + */ + uint32_t taddr; + getSIPR((uint8_t*)&taddr); + if (taddr == 0) { + return SOCKERR_SOCKINIT; + } + break; + } +#endif + case Sn_MR_UDP : + case Sn_MR_UDP6 : + case Sn_MR_UDPD : + case Sn_MR_MACRAW : + case Sn_MR_IPRAW4 : + case Sn_MR_IPRAW6 : + break; +#if ( _WIZCHIP_ < 5200 ) + case Sn_MR_PPPoE : + break; +#endif + default : + return SOCKERR_SOCKMODE; + } + //M20150601 : For SF_TCP_ALIGN & W5300 + //if((flag & 0x06) != 0) return SOCKERR_SOCKFLAG; + if ((flag & 0x04) != 0) { + return SOCKERR_SOCKFLAG; + } +#if _WIZCHIP_ == 5200 + if (flag & 0x10) { + return SOCKERR_SOCKFLAG; + } +#endif + + if (flag != 0) { + switch (protocol) { + +#ifdef IPV6_AVAILABLE + case Sn_MR_MACRAW: + if ((flag & (SF_DHA_MANUAL | SF_FORCE_ARP)) != 0) { + return SOCKERR_SOCKFLAG; + } + break; + case Sn_MR_TCP4: + case Sn_MR_TCP6: + case Sn_MR_TCPD: + if ((flag & (SF_MULTI_ENABLE | SF_UNI_BLOCK)) != 0) { + return SOCKERR_SOCKFLAG; + } + break; + case Sn_MR_IPRAW4: + case Sn_MR_IPRAW6: + if (flag != 0) { + return SOCKERR_SOCKFLAG; + } + break; +#else + case Sn_MR_TCP: + //M20150601 : For SF_TCP_ALIGN & W5300 +#if _WIZCHIP_ == 5300 + if ((flag & (SF_TCP_NODELAY | SF_IO_NONBLOCK | SF_TCP_ALIGN)) == 0) { + return SOCKERR_SOCKFLAG; + } +#else + if ((flag & (SF_TCP_NODELAY | SF_IO_NONBLOCK)) == 0) { + return SOCKERR_SOCKFLAG; + } +#endif + + break; + case Sn_MR_UDP: + if (flag & SF_IGMP_VER2) { + if ((flag & SF_MULTI_ENABLE) == 0) { + return SOCKERR_SOCKFLAG; + } + } +#if _WIZCHIP_ == 5500 + if (flag & SF_UNI_BLOCK) { + if ((flag & SF_MULTI_ENABLE) == 0) { + return SOCKERR_SOCKFLAG; + } + } +#endif + break; + +#endif + + default: + break; + } + } + close(sn); + //M20150601 +#if _WIZCHIP_ == 5300 + setSn_MR(sn, ((uint16_t)(protocol | (flag & 0xF0))) | (((uint16_t)(flag & 0x02)) << 7)); +#else + setSn_MR(sn, (protocol | (flag & 0xF0))); +#endif +#ifdef IPV6_AVAILABLE + setSn_MR2(sn, flag & 0x03); +#endif + if (!port) { + port = sock_any_port++; + if (sock_any_port == 0xFFF0) { + sock_any_port = SOCK_ANY_PORT_NUM; + } + } + setSn_PORTR(sn, port); + setSn_CR(sn, Sn_CR_OPEN); + while (getSn_CR(sn)); + //A20150401 : For release the previous sock_io_mode + sock_io_mode &= ~(1 << sn); + // +#ifndef IPV6_AVAILABLE + sock_io_mode |= ((flag & SF_IO_NONBLOCK) << sn); +#else + sock_io_mode |= ((flag & (SF_IO_NONBLOCK >> 3)) << sn); +#endif + sock_is_sending &= ~(1 << sn); + sock_remained_size[sn] = 0; + //M20150601 : repalce 0 with PACK_COMPLETED + //sock_pack_info[sn] = 0; + sock_pack_info[sn] = PACK_COMPLETED;//PACK_COMPLETED //TODO::need verify:LINAN 20250421 + // + while (getSn_SR(sn) == SOCK_CLOSED); + return (int8_t)sn; +} + +int8_t close(uint8_t sn) { + CHECK_SOCKNUM(); + //A20160426 : Applied the erratum 1 of W5300 +#if (_WIZCHIP_ == 5300) + //M20160503 : Wrong socket parameter. s -> sn + //if( ((getSn_MR(s)& 0x0F) == Sn_MR_TCP) && (getSn_TX_FSR(s) != getSn_TxMAX(s)) ) + if (((getSn_MR(sn) & 0x0F) == Sn_MR_TCP) && (getSn_TX_FSR(sn) != getSn_TxMAX(sn))) { + uint8_t destip[4] = {0, 0, 0, 1}; + // TODO + // You can wait for completing to sending data; + // wait about 1 second; + // if you have completed to send data, skip the code of erratum 1 + // ex> wait_1s(); + // if (getSn_TX_FSR(s) == getSn_TxMAX(s)) continue; + // + //M20160503 : The socket() of close() calls close() itself again. It occures a infinite loop - close()->socket()->close()->socket()-> ~ + //socket(s,Sn_MR_UDP,0x3000,0); + //sendto(s,destip,1,destip,0x3000); // send the dummy data to an unknown destination(0.0.0.1). + setSn_MR(sn, Sn_MR_UDP); + setSn_PORTR(sn, 0x3000); + setSn_CR(sn, Sn_CR_OPEN); + while (getSn_CR(sn) != 0); + while (getSn_SR(sn) != SOCK_UDP); + sendto(sn, destip, 1, destip, 0x3000); // send the dummy data to an unknown destination(0.0.0.1). + }; +#endif + setSn_CR(sn, Sn_CR_CLOSE); + /* wait to process the command... */ + while (getSn_CR(sn)); + /* clear all interrupt of SOCKETn. */ + setSn_IR(sn, 0xFF); + //A20150401 : Release the sock_io_mode of socket n. + sock_io_mode &= ~(1 << sn); + // + sock_is_sending &= ~(1 << sn); + sock_remained_size[sn] = 0; + sock_pack_info[sn] = PACK_NONE; + while (getSn_SR(sn) != SOCK_CLOSED); + return SOCK_OK; +} + +int8_t listen(uint8_t sn) { + CHECK_SOCKNUM(); + CHECK_TCPMODE(); + CHECK_SOCKINIT(); + setSn_CR(sn, Sn_CR_LISTEN); + while (getSn_CR(sn)); + while (getSn_SR(sn) != SOCK_LISTEN) { + close(sn); + return SOCKERR_SOCKCLOSED; + } + return SOCK_OK; +} +//int8_t connect (uint8_t sn, uint8_t * addr, uint16_t port ) +int8_t connect_W5x00(uint8_t sn, uint8_t * addr, uint16_t port) { + // printf(" W5x00 - connect - addrlen = %d \r\n" , 4 ); + // #ifdef IPV6_AVAILABLE + // TODO :define how to work, when IPV6_AVAILABLE is defined + // #endif + return connect_IO_6(sn, addr, port, 4); +} + +int8_t connect_W6x00(uint8_t sn, uint8_t * addr, uint16_t port, uint8_t addrlen) { + // printf(" W6x00 - connect - addrlen = %d \r\n" , addrlen ); + // #ifdef IPV6_AVAILABLE + // TODO :define how to work, when IPV6_AVAILABLE is defined + // #endif + return connect_IO_6(sn, addr, port, addrlen); +} + +static int8_t connect_IO_6(uint8_t sn, uint8_t * addr, uint16_t port, uint8_t addrlen) { + + // printf(" connect - addrlen = %d \r\n" , addrlen ); + + CHECK_SOCKNUM(); + CHECK_TCPMODE(); // same macro " CHECK_SOCKMODE(Sn_MR_TCP);" + CHECK_SOCKINIT(); + +#ifdef IPV6_AVAILABLE + CHECK_IPZERO(addr, addrlen); +#else + //M20140501 : For avoiding fatal error on memory align mismatched + //if( *((uint32_t*)addr) == 0xFFFFFFFF || *((uint32_t*)addr) == 0) return SOCKERR_IPINVALID; + { + uint32_t taddr; + taddr = ((uint32_t)addr[0] & 0x000000FF); + taddr = (taddr << 8) + ((uint32_t)addr[1] & 0x000000FF); + taddr = (taddr << 8) + ((uint32_t)addr[2] & 0x000000FF); + taddr = (taddr << 8) + ((uint32_t)addr[3] & 0x000000FF); + if (taddr == 0xFFFFFFFF || taddr == 0) { + return SOCKERR_IPINVALID; + } + } +#endif + + if (port == 0) { + return SOCKERR_PORTZERO; + } + + setSn_DPORTR(sn, port); + + if (addrlen == 16) { // addrlen=16, Sn_MR_TCP6(1001), Sn_MR_TCPD(1101)) +#ifdef IPV6_AVAILABLE + if (getSn_MR(sn) & 0x08) { + setSn_DIP6R(sn, addr); + setSn_CR(sn, Sn_CR_CONNECT6); + } else +#endif + return SOCKERR_SOCKMODE; + } else { // addrlen=4, Sn_MR_TCP4(0001), Sn_MR_TCPD(1101) + if (getSn_MR(sn) == Sn_MR_TCP6) { + return SOCKERR_SOCKMODE; + } + setSn_DIPR(sn, addr); + //setSn_DPORT(sn,port); //TODO::need verify:LINAN 20250421 + setSn_CR(sn, Sn_CR_CONNECT); + } + while (getSn_CR(sn)); + if (sock_io_mode & (1 << sn)) { + return SOCK_BUSY; + } + while (getSn_SR(sn) != SOCK_ESTABLISHED) { + if (getSn_IR(sn) & Sn_IR_TIMEOUT) { + setSn_IR(sn, Sn_IR_TIMEOUT); + return SOCKERR_TIMEOUT; + } + + if (getSn_SR(sn) == SOCK_CLOSED) { + return SOCKERR_SOCKCLOSED; + } + } + + return SOCK_OK; +} + +int8_t disconnect(uint8_t sn) { + CHECK_SOCKNUM(); + CHECK_TCPMODE(); + if (getSn_SR(sn) != SOCK_CLOSED) { + setSn_CR(sn, Sn_CR_DISCON); + /* wait to process the command... */ + while (getSn_CR(sn)); + sock_is_sending &= ~(1 << sn); + if (sock_io_mode & (1 << sn)) { + return SOCK_BUSY; + } + while (getSn_SR(sn) != SOCK_CLOSED) { + if (getSn_IR(sn) & Sn_IR_TIMEOUT) { + close(sn); + return SOCKERR_TIMEOUT; + } + } + } + return SOCK_OK; +} + + +#if 1 +int32_t send(uint8_t sn, uint8_t * buf, uint16_t len) { + uint8_t tmp = 0; + uint16_t freesize = 0; + /* + The below codes can be omitted for optmization of speed + */ + //CHECK_SOCKNUM(); + //CHECK_TCPMODE(Sn_MR_TCP4); + /************/ +#ifndef IPV6_AVAILABLE + CHECK_SOCKNUM(); + CHECK_SOCKMODE(Sn_MR_TCP); + CHECK_SOCKDATA(); + tmp = getSn_SR(sn); + if (tmp != SOCK_ESTABLISHED && tmp != SOCK_CLOSE_WAIT) { + return SOCKERR_SOCKSTATUS; + } + if (sock_is_sending & (1 << sn)) { + tmp = getSn_IR(sn); + if (tmp & Sn_IR_SENDOK) { + setSn_IR(sn, Sn_IR_SENDOK); + //M20150401 : Typing Error + //#if _WZICHIP_ == 5200 +#if _WIZCHIP_ == 5200 + if (getSn_TX_RD(sn) != sock_next_rd[sn]) { + setSn_CR(sn, Sn_CR_SEND); + while (getSn_CR(sn)); + return SOCK_BUSY; + } +#endif + sock_is_sending &= ~(1 << sn); + } else if (tmp & Sn_IR_TIMEOUT) { + close(sn); + return SOCKERR_TIMEOUT; + } else { + return SOCK_BUSY; + } + } +#endif + freesize = getSn_TxMAX(sn); + if (len > freesize) { + len = freesize; // check size not to exceed MAX size. + } + while (1) { + freesize = (uint16_t)getSn_TX_FSR(sn); + tmp = getSn_SR(sn); + if ((tmp != SOCK_ESTABLISHED) && (tmp != SOCK_CLOSE_WAIT)) { + if (tmp == SOCK_CLOSED) { + close(sn); + } + return SOCKERR_SOCKSTATUS; + } + if ((sock_io_mode & (1 << sn)) && (len > freesize)) { + return SOCK_BUSY; //TODO::need verify:LINAN 20250421 + } + // if( sock_io_mode & (1< 4096) len = 4096; // check size not to exceed MAX size.// + //if (len > 8192) len = 8192; // check size not to exceed MAX siz + //if (len > 16384) len = 16384; // check size not to exceed MAX size. + //if (len > 32768) len = 32768; // check size not to exceed MAX size. +#define __FREESIZE__(i) 1024 * i +#define __FREESIZE__Value 8 + if (len > __FREESIZE__(__FREESIZE__Value)) { + len = __FREESIZE__(__FREESIZE__Value); // check size not to exceed MAX size.//tse + } + + while (1) { + freesize = (uint16_t)getSn_TX_FSR(sn); + if (len <= freesize) { + break; + } + } + wiz_send_data(sn, buf, len); + setSn_CR(sn, Sn_CR_SEND); + + while (getSn_CR(sn)); // wait to process the command... + sock_is_sending |= (1 << sn); + + return len; +} +#endif +int32_t recv(uint8_t sn, uint8_t * buf, uint16_t len) { //lihan + uint8_t tmp = 0; + uint16_t recvsize = 0; + /* + The below codes can be omitted for optmization of speed + */ + //A20150601 : For integarating with W5300 +#if _WIZCHIP_ == 5300 + uint8_t head[2]; + uint16_t mr; +#endif + // + CHECK_SOCKNUM(); + CHECK_SOCKMODE(Sn_MR_TCP); + CHECK_SOCKDATA(); + + recvsize = getSn_RxMAX(sn); + if (recvsize < len) { + len = recvsize; + } + + //A20150601 : For Integrating with W5300 +#if _WIZCHIP_ == 5300 + //sock_pack_info[sn] = PACK_COMPLETED; // for clear + if (sock_remained_size[sn] == 0) { +#endif + // + while (1) { + recvsize = (uint16_t)getSn_RX_RSR(sn); + tmp = getSn_SR(sn); + if (tmp != SOCK_ESTABLISHED) { + if (tmp == SOCK_CLOSE_WAIT) { + if (recvsize != 0) { + break; + } else if (getSn_TX_FSR(sn) == getSn_TxMAX(sn)) { + close(sn); + return SOCKERR_SOCKSTATUS; + } + } else { + close(sn); + return SOCKERR_SOCKSTATUS; + } + } +#ifdef IPV6_AVAILABLE + if (recvsize != 0) { + break; + } + if (sock_io_mode & (1 << sn)) { + return SOCK_BUSY; + } +#else + if (sock_io_mode & (1 << sn)) { + return SOCK_BUSY; + } + if (recvsize != 0) { + break; + } +#endif + }; +#if _WIZCHIP_ == 5300 + } +#endif + + //A20150601 : For integrating with W5300 +#if _WIZCHIP_ == 5300 + if ((sock_remained_size[sn] == 0) || (getSn_MR(sn) & Sn_MR_ALIGN)) { + mr = getMR(); + if ((getSn_MR(sn) & Sn_MR_ALIGN) == 0) { + wiz_recv_data(sn, head, 2); + if (mr & MR_FS) { + recvsize = (((uint16_t)head[1]) << 8) | ((uint16_t)head[0]); + } else { + recvsize = (((uint16_t)head[0]) << 8) | ((uint16_t)head[1]); + } + sock_pack_info[sn] = PACK_FIRST; + } + sock_remained_size[sn] = recvsize; + } + if (len > sock_remained_size[sn]) { + len = sock_remained_size[sn]; + } + recvsize = len; + if (sock_pack_info[sn] & PACK_FIFOBYTE) { + *buf = sock_remained_byte[sn]; + buf++; + sock_pack_info[sn] &= ~(PACK_FIFOBYTE); + recvsize -= 1; + sock_remained_size[sn] -= 1; + } + if (recvsize != 0) { + wiz_recv_data(sn, buf, recvsize); + setSn_CR(sn, Sn_CR_RECV); + while (getSn_CR(sn)); + } + sock_remained_size[sn] -= recvsize; + if (sock_remained_size[sn] != 0) { + sock_pack_info[sn] |= PACK_REMAINED; + if (recvsize & 0x1) { + sock_pack_info[sn] |= PACK_FIFOBYTE; + } + } else { + sock_pack_info[sn] = PACK_COMPLETED; + } + if (getSn_MR(sn) & Sn_MR_ALIGN) { + sock_remained_size[sn] = 0; + } + //len = recvsize; +#else + if (recvsize < len) { + len = recvsize; + } + wiz_recv_data(sn, buf, len); + setSn_CR(sn, Sn_CR_RECV); + while (getSn_CR(sn)); +#endif + + //M20150409 : Explicit Type Casting + //return len; + return (int32_t)len; +} + + +int32_t sendto_W5x00(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port) { + //static int32_t sendto_IO_6(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port) + // printf("sendto_W5x00\r\n" ) ; + return sendto_IO_6(sn, buf, len, addr, port, 4); +} + +int32_t sendto_W6x00(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port, uint8_t addrlen) { + // printf("sendto_W6x00\r\n" ) ; + //static int32_t sendto_IO_6(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port) + return sendto_IO_6(sn, buf, len, addr, port, addrlen); +} + +static int32_t sendto_IO_6(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port, uint8_t addrlen) { + uint8_t tmp = 0; + uint8_t tcmd = Sn_CR_SEND; + uint16_t freesize = 0; + uint32_t taddr; + + /* + The below codes can be omitted for optmization of speed + */ + CHECK_SOCKNUM(); + //CHECK_DGRAMMODE(); + /************/ + switch (getSn_MR(sn) & 0x0F) { + case Sn_MR_UDP: + case Sn_MR_MACRAW: + // break; + // #if ( _WIZCHIP_ < 5200 ) + case Sn_MR_IPRAW: + case Sn_MR_IPRAW6: + break; + // #endif + default: + return SOCKERR_SOCKMODE; + } + tmp = getSn_MR(sn); + if (tmp != Sn_MR_MACRAW) { + if (addrlen == 16) { // addrlen=16, Sn_MR_UDP6(1010), Sn_MR_UDPD(1110)), IPRAW6(1011) +#ifdef IPV6_AVAILABLE + if (tmp & 0x08) { + setSn_DIP6R(sn, addr); + tcmd = Sn_CR_SEND6; + } else +#endif + return SOCKERR_SOCKMODE; + } else if (addrlen == 4) { // addrlen=4, Sn_MR_UDP4(0010), Sn_MR_UDPD(1110), IPRAW4(0011) + if (tmp == Sn_MR_UDP6 || tmp == Sn_MR_IPRAW6) { + return SOCKERR_SOCKMODE; + } + setSn_DIPR(sn, addr); + tcmd = Sn_CR_SEND; + } else { + return SOCKERR_IPINVALID; + } + } + if ((tmp & 0x03) == 0x02) { // Sn_MR_UPD4(0010), Sn_MR_UDP6(1010), Sn_MR_UDPD(1110) + if (port) { + setSn_DPORTR(sn, port); + } else { + return SOCKERR_PORTZERO; + } + } +#ifndef IPV6_AVAILABLE + CHECK_SOCKDATA(); + //M20140501 : For avoiding fatal error on memory align mismatched + //if(*((uint32_t*)addr) == 0) return SOCKERR_IPINVALID; + //{ + //uint32_t taddr; + taddr = ((uint32_t)addr[0]) & 0x000000FF; + taddr = (taddr << 8) + ((uint32_t)addr[1] & 0x000000FF); + taddr = (taddr << 8) + ((uint32_t)addr[2] & 0x000000FF); + taddr = (taddr << 8) + ((uint32_t)addr[3] & 0x000000FF); + //} + // + //if(*((uint32_t*)addr) == 0) return SOCKERR_IPINVALID; + if ((taddr == 0) && ((getSn_MR(sn)&Sn_MR_MACRAW) != Sn_MR_MACRAW)) { + return SOCKERR_IPINVALID; + } + if ((port == 0) && ((getSn_MR(sn)&Sn_MR_MACRAW) != Sn_MR_MACRAW)) { + return SOCKERR_PORTZERO; + } + tmp = getSn_SR(sn); + //#if ( _WIZCHIP_ < 5200 ) + if ((tmp != SOCK_MACRAW) && (tmp != SOCK_UDP) && (tmp != SOCK_IPRAW)) { + return SOCKERR_SOCKSTATUS; + } + //#else + // if(tmp != SOCK_MACRAW && tmp != SOCK_UDP) return SOCKERR_SOCKSTATUS; + //#endif + + setSn_DIPR(sn, addr); + setSn_DPORT(sn, port); +#endif + + freesize = getSn_TxMAX(sn); + if (len > freesize) { + len = freesize; // check size not to exceed MAX size. + } + + while (1) { + freesize = getSn_TX_FSR(sn); + if (getSn_SR(sn) == SOCK_CLOSED) { + return SOCKERR_SOCKCLOSED; + } + if ((sock_io_mode & (1 << sn)) && (len > freesize)) { + return SOCK_BUSY; + } + if (len <= freesize) { + break; + } + }; + wiz_send_data(sn, buf, len); + +#if _WIZCHIP_ < 5500 //M20150401 : for WIZCHIP Errata #4, #5 (ARP errata) + getSIPR((uint8_t *)&taddr); + if (taddr == 0) { + getSUBR((uint8_t*)&taddr); + setSUBR((uint8_t*)"\x00\x00\x00\x00"); + } else { + taddr = 0; + } +#endif + +#ifdef IPV6_AVAILABLE + setSn_CR(sn, tcmd); +#else + //A20150601 : For W5300 +#if _WIZCHIP_ == 5300 + setSn_TX_WRSR(sn, len); +#endif + // + setSn_CR(sn, Sn_CR_SEND); +#endif + /* wait to process the command... */ + while (getSn_CR(sn)); + while (1) { + tmp = getSn_IR(sn); + if (tmp & Sn_IR_SENDOK) { + setSn_IR(sn, Sn_IR_SENDOK); + break; + } + //M:20131104 + //else if(tmp & Sn_IR_TIMEOUT) return SOCKERR_TIMEOUT; + else if (tmp & Sn_IR_TIMEOUT) { + setSn_IR(sn, Sn_IR_TIMEOUT); + //M20150409 : Fixed the lost of sign bits by type casting. + //len = (uint16_t)SOCKERR_TIMEOUT; + //break; +#if _WIZCHIP_ < 5500 //M20150401 : for WIZCHIP Errata #4, #5 (ARP errata) + if (taddr) { + setSUBR((uint8_t*)&taddr); + } +#endif + return SOCKERR_TIMEOUT; + } + //////////// + } +#if _WIZCHIP_ < 5500 //M20150401 : for WIZCHIP Errata #4, #5 (ARP errata) + if (taddr) { + setSUBR((uint8_t*)&taddr); + } +#endif + //M20150409 : Explicit Type Casting + //return len; + return (int32_t)len; +} + + + +int32_t recvfrom_W5x00(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port) { + //int32_t recvfrom_IO_6(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port) + // printf("recvfrom_W5x00\r\n" ) ; + uint8_t addrlen = 4; //M20150601 : For W5300 + uint8_t *dummy = &addrlen; + return recvfrom_IO_6(sn, buf, len, addr, port, dummy); +} + +int32_t recvfrom_W6x00(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port, uint8_t *addrlen) { + // printf("recvfrom_W6x00\r\n" ) ; + //int32_t recvfrom_IO_6(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port) + return recvfrom_IO_6(sn, buf, len, addr, port, addrlen); +} +static int32_t recvfrom_IO_6(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port, uint8_t *addrlen) { //TODO : WILL BE IMPROVED + //M20150601 : For W5300 +#if _WIZCHIP_ == 5300 + uint16_t mr; + uint16_t mr1; +#else + uint8_t mr; +#endif + // + uint8_t head[8]; + uint16_t pack_len = 0; + + /* + The below codes can be omitted for optmization of speed + */ + CHECK_SOCKNUM(); + //CHECK_DGRAMMODE(); + //CHECK_SOCKDATA(); + /************/ + //CHECK_SOCKMODE(Sn_MR_UDP); + //A20150601 +#if _WIZCHIP_ == 5300 + mr1 = getMR(); +#endif + + switch ((mr = getSn_MR(sn)) & 0x0F) { + case Sn_MR_UDP: + case Sn_MR_IPRAW: + case Sn_MR_IPRAW6: + case Sn_MR_MACRAW: + break; +#if ( _WIZCHIP_ < 5200 ) + case Sn_MR_PPPoE: + break; +#endif + default: + return SOCKERR_SOCKMODE; + } + CHECK_SOCKDATA(); + if (sock_remained_size[sn] == 0) { + while (1) { + pack_len = getSn_RX_RSR(sn); + if (getSn_SR(sn) == SOCK_CLOSED) { + return SOCKERR_SOCKCLOSED; + } +#ifndef IPV6_AVAILABLE + if ((sock_io_mode & (1 << sn)) && (pack_len == 0)) { + return SOCK_BUSY; + } + if (pack_len != 0) { + break; + } +#else + if (pack_len != 0) { + sock_pack_info[sn] = PACK_NONE; + break; + } + if (sock_io_mode & (1 << sn)) { + return SOCK_BUSY; + } +#endif + }; + } +#ifdef IPV6_AVAILABLE + /* First read 2 bytes of PACKET INFO in SOCKETn RX buffer*/ + wiz_recv_data(sn, head, 2); + setSn_CR(sn, Sn_CR_RECV); + while (getSn_CR(sn)); + pack_len = head[0] & 0x07; + pack_len = (pack_len << 8) + head[1]; +#endif + //D20150601 : Move it to bottom + // sock_pack_info[sn] = PACK_COMPLETED; + switch (mr & 0x07) { + case Sn_MR_UDP4 : + case Sn_MR_UDP6: + case Sn_MR_UDPD: +#ifdef IPV6_AVAILABLE + if (addr == 0) { + return SOCKERR_ARG; + } + + sock_pack_info[sn] = head[0] & 0xF8; + + if (sock_pack_info[sn] & PACK_IPv6) { + *addrlen = 16 ; + } else { + *addrlen = 4 ; + } + wiz_recv_data(sn, addr, *addrlen); + setSn_CR(sn, Sn_CR_RECV); + + while (getSn_CR(sn)); + +#else + if (sock_remained_size[sn] == 0) { + wiz_recv_data(sn, head, 8); + setSn_CR(sn, Sn_CR_RECV); + while (getSn_CR(sn)); + // read peer's IP address, port number & packet length + //A20150601 : For W5300 +#if _WIZCHIP_ == 5300 + if (mr1 & MR_FS) { + addr[0] = head[1]; + addr[1] = head[0]; + addr[2] = head[3]; + addr[3] = head[2]; + *port = head[5]; + *port = (*port << 8) + head[4]; + sock_remained_size[sn] = head[7]; + sock_remained_size[sn] = (sock_remained_size[sn] << 8) + head[6]; + } else { +#endif + addr[0] = head[0]; + addr[1] = head[1]; + addr[2] = head[2]; + addr[3] = head[3]; + *port = head[4]; + *port = (*port << 8) + head[5]; + sock_remained_size[sn] = head[6]; + sock_remained_size[sn] = (sock_remained_size[sn] << 8) + head[7]; +#if _WIZCHIP_ == 5300 + } +#endif + sock_pack_info[sn] = PACK_FIRST; + } + if (len < sock_remained_size[sn]) { + pack_len = len; + } else { + pack_len = sock_remained_size[sn]; + } + //A20150601 : For W5300 + len = pack_len; +#if _WIZCHIP_ == 5300 + if (sock_pack_info[sn] & PACK_FIFOBYTE) { + *buf++ = sock_remained_byte[sn]; + pack_len -= 1; + sock_remained_size[sn] -= 1; + sock_pack_info[sn] &= ~PACK_FIFOBYTE; + } +#endif + // + // Need to packet length check (default 1472) + // + wiz_recv_data(sn, buf, pack_len); // data copy. +#endif + break; + case Sn_MR_MACRAW : + if (sock_remained_size[sn] == 0) { +#ifndef IPV6_AVAILABLE + wiz_recv_data(sn, head, 2); + setSn_CR(sn, Sn_CR_RECV); + while (getSn_CR(sn)); +#endif + // read peer's IP address, port number & packet length + sock_remained_size[sn] = head[0]; + sock_remained_size[sn] = (sock_remained_size[sn] << 8) + head[1] - 2; +#if _WIZCHIP_ == W5300 + if (sock_remained_size[sn] & 0x01) { + sock_remained_size[sn] = sock_remained_size[sn] + 1 - 4; + } else { + sock_remained_size[sn] -= 4; + } +#endif + if (sock_remained_size[sn] > 1514) { + close(sn); + return SOCKFATAL_PACKLEN; + } + sock_pack_info[sn] = PACK_FIRST; + } + if (len < sock_remained_size[sn]) { + pack_len = len; + } else { + pack_len = sock_remained_size[sn]; + } + wiz_recv_data(sn, buf, pack_len); + break; + //#if ( _WIZCHIP_ < 5200 ) + case Sn_MR_IPRAW6: + case Sn_MR_IPRAW4 : + if (sock_remained_size[sn] == 0) { +#ifndef IPV6_AVAILABLE + wiz_recv_data(sn, head, 6); + setSn_CR(sn, Sn_CR_RECV); + while (getSn_CR(sn)); + addr[0] = head[0]; + addr[1] = head[1]; + addr[2] = head[2]; + addr[3] = head[3]; + sock_remained_size[sn] = head[4]; + //M20150401 : For Typing Error + //sock_remaiend_size[sn] = (sock_remained_size[sn] << 8) + head[5]; + sock_remained_size[sn] = (sock_remained_size[sn] << 8) + head[5]; + sock_pack_info[sn] = PACK_FIRST; + // + // Need to packet length check + // + if (len < sock_remained_size[sn]) { + pack_len = len; + } else { + pack_len = sock_remained_size[sn]; + } + wiz_recv_data(sn, buf, pack_len); // data copy. +#else + if (*addr == 0) { + return SOCKERR_ARG; + } + sock_pack_info[sn] = head[0] & 0xF8; + if (sock_pack_info[sn] & PACK_IPv6) { + *addrlen = 16; + } else { + *addrlen = 4; + } + wiz_recv_data(sn, addr, *addrlen); + setSn_CR(sn, Sn_CR_RECV); + while (getSn_CR(sn)); + +#endif + } + break; + default: + wiz_recv_ignore(sn, pack_len); // data copy. + sock_remained_size[sn] = pack_len; + break; + } +#ifdef IPV6_AVAILABLE + sock_remained_size[sn] = pack_len; + sock_pack_info[sn] |= PACK_FIRST; + if ((getSn_MR(sn) & 0x03) == 0x02) { // Sn_MR_UDP4(0010), Sn_MR_UDP6(1010), Sn_MR_UDPD(1110) + /* Read port number of PACKET INFO in SOCKETn RX buffer */ + if (port == 0) { + return SOCKERR_ARG; + } + wiz_recv_data(sn, head, 2); + *port = (((((uint16_t)head[0])) << 8) + head[1]); + setSn_CR(sn, Sn_CR_RECV); + while (getSn_CR(sn)); + } + + if (len < sock_remained_size[sn]) { + pack_len = len; + } else { + pack_len = sock_remained_size[sn]; + } + wiz_recv_data(sn, buf, pack_len); + setSn_CR(sn, Sn_CR_RECV); + /* wait to process the command... */ + while (getSn_CR(sn)) ; + + sock_remained_size[sn] -= pack_len; + if (sock_remained_size[sn] != 0) { + sock_pack_info[sn] |= PACK_REMAINED; + } else { + sock_pack_info[sn] |= PACK_COMPLETED; + } + +#else + setSn_CR(sn, Sn_CR_RECV); + /* wait to process the command... */ + while (getSn_CR(sn)) ; + sock_remained_size[sn] -= pack_len; + //M20150601 : + //if(sock_remained_size[sn] != 0) sock_pack_info[sn] |= 0x01; + if (sock_remained_size[sn] != 0) { + sock_pack_info[sn] |= PACK_REMAINED; +#if _WIZCHIP_ == 5300 + if (pack_len & 0x01) { + sock_pack_info[sn] |= PACK_FIFOBYTE; + } +#endif + } else { + sock_pack_info[sn] = PACK_COMPLETED; + } +#if _WIZCHIP_ == 5300 + pack_len = len; +#endif + // + //M20150409 : Explicit Type Casting + //return pack_len; +#endif + return (int32_t)pack_len; +} + + +int8_t ctlsocket(uint8_t sn, ctlsock_type cstype, void* arg) { + uint8_t tmp = 0; + CHECK_SOCKNUM(); + tmp = *((uint8_t*)arg); + switch (cstype) { + case CS_SET_IOMODE: + if (tmp == SOCK_IO_NONBLOCK) { + sock_io_mode |= (1 << sn); + } else if (tmp == SOCK_IO_BLOCK) { + sock_io_mode &= ~(1 << sn); + } else { + return SOCKERR_ARG; + } + break; + case CS_GET_IOMODE: + //M20140501 : implict type casting -> explict type casting + //*((uint8_t*)arg) = (sock_io_mode >> sn) & 0x0001; + *((uint8_t*)arg) = (uint8_t)((sock_io_mode >> sn) & 0x0001); + // + break; + case CS_GET_MAXTXBUF: + *((uint16_t*)arg) = getSn_TxMAX(sn); + break; + case CS_GET_MAXRXBUF: + *((uint16_t*)arg) = getSn_RxMAX(sn); + break; + case CS_CLR_INTERRUPT: + if (tmp > SIK_ALL) { + return SOCKERR_ARG; + } + setSn_IR(sn, tmp); + break; + case CS_GET_INTERRUPT: + *((uint8_t*)arg) = getSn_IR(sn); + break; +#if _WIZCHIP_ != 5100 + case CS_SET_INTMASK: + if (tmp > SIK_ALL) { + return SOCKERR_ARG; + } + setSn_IMR(sn, tmp); + break; + case CS_GET_INTMASK: + *((uint8_t*)arg) = getSn_IMR(sn); + break; +#endif +#ifdef IPV6_AVAILABLE + case CS_SET_PREFER: + if ((tmp & 0x03) == 0x01) { + return SOCKERR_ARG; + } + setSn_PSR(sn, tmp); + break; + case CS_GET_PREFER: + *(uint8_t*) arg = getSn_PSR(sn); + break; +#endif + default: + return SOCKERR_ARG; + } + return SOCK_OK; +} + +int8_t setsockopt(uint8_t sn, sockopt_type sotype, void* arg) { + // M20131220 : Remove warning + //uint8_t tmp; + CHECK_SOCKNUM(); + switch (sotype) { + case SO_TTL: + setSn_TTL(sn, *(uint8_t*)arg); + break; + case SO_TOS: + setSn_TOS(sn, *(uint8_t*)arg); + break; + case SO_MSS: + setSn_MSSR(sn, *(uint16_t*)arg); + break; + case SO_DESTIP: +#ifdef IPV6_AVAILABLE + if (((wiz_IPAddress *)arg)->len == 16) { + setSn_DIP6R(sn, ((wiz_IPAddress*)arg)->ip); + } else +#endif + setSn_DIPR(sn, (uint8_t*)arg); + break; + case SO_DESTPORT: + setSn_DPORTR(sn, *(uint16_t*)arg); + break; +#if _WIZCHIP_ != 5100 + case SO_KEEPALIVESEND: + CHECK_TCPMODE(); +#if _WIZCHIP_ > 5200 + if (getSn_KPALVTR(sn) != 0) { + return SOCKERR_SOCKOPT; + } +#endif + setSn_CR(sn, Sn_CR_SEND_KEEP); + while (getSn_CR(sn) != 0) { + // M20131220 + //if ((tmp = getSn_IR(sn)) & Sn_IR_TIMEOUT) + if (getSn_IR(sn) & Sn_IR_TIMEOUT) { + setSn_IR(sn, Sn_IR_TIMEOUT); + return SOCKERR_TIMEOUT; + } + } + break; +#if _WIZCHIP_ > 5200 + case SO_KEEPALIVEAUTO: + CHECK_TCPMODE(); + setSn_KPALVTR(sn, *(uint8_t*)arg); + break; +#endif +#endif + default: + return SOCKERR_ARG; + } + return SOCK_OK; +} + +int8_t getsockopt(uint8_t sn, sockopt_type sotype, void* arg) { + CHECK_SOCKNUM(); + switch (sotype) { + case SO_FLAG: +#ifdef IPV6_AVAILABLE + *(uint8_t*)arg = (getSn_MR(sn) & 0xF0) | (getSn_MR2(sn)) | ((uint8_t)(((sock_io_mode >> sn) & 0x0001) << 3)); +#endif + *(uint8_t*)arg = getSn_MR(sn) & 0xF0; + break; + case SO_TTL: + *(uint8_t*) arg = getSn_TTL(sn); + break; + case SO_TOS: + *(uint8_t*) arg = getSn_TOS(sn); + break; + case SO_MSS: + *(uint16_t*) arg = getSn_MSSR(sn); + break; + case SO_DESTIP: +#ifdef IPV6_AVAILABLE + CHECK_TCPMODE(); + if (getSn_ESR(sn) & TCPSOCK_MODE) { //IPv6 ? + getSn_DIP6R(sn, ((wiz_IPAddress*)arg)->ip); + ((wiz_IPAddress*)arg)->len = 16; + } else { + getSn_DIPR(sn, ((wiz_IPAddress*)arg)->ip); + ((wiz_IPAddress*)arg)->len = 4; + } + break; +#else + getSn_DIPR(sn, (uint8_t*)arg); + break; +#endif + case SO_DESTPORT: + *(uint16_t*) arg = getSn_DPORTR(sn); + break; +#if _WIZCHIP_ > 5200 + case SO_KEEPALIVEAUTO: + CHECK_TCPMODE(); + *(uint16_t*) arg = getSn_KPALVTR(sn); + break; +#endif + case SO_SENDBUF: + *(uint16_t*) arg = getSn_TX_FSR(sn); + break; + case SO_RECVBUF: + *(uint16_t*) arg = getSn_RX_RSR(sn); + break; + case SO_STATUS: + *(uint8_t*) arg = getSn_SR(sn); + break; +#ifdef IPV6_AVAILABLE + case SO_EXTSTATUS: + CHECK_TCPMODE(); + *(uint8_t*) arg = getSn_ESR(sn) & 0x07; + break; + case SO_REMAINSIZE: + if (getSn_MR(sn) == SOCK_CLOSED) { + return SOCKERR_SOCKSTATUS; + } + if (getSn_MR(sn) & 0x01) { + *(uint16_t*)arg = getSn_RX_RSR(sn); + } else { + *(uint16_t*)arg = sock_remained_size[sn]; + } + break; + case SO_PACKINFO: + if (getSn_MR(sn) == SOCK_CLOSED) { + return SOCKERR_SOCKSTATUS; + } + if (getSn_MR(sn) & 0x01) { + return SOCKERR_SOCKMODE; + } else { + *(uint8_t*)arg = sock_pack_info[sn]; + } + break; + case SO_MODE: + *(uint8_t*) arg = 0x0F & getSn_MR(sn); + break; +#else + case SO_REMAINSIZE: + if (getSn_MR(sn) & Sn_MR_TCP) { + *(uint16_t*)arg = getSn_RX_RSR(sn); + } else { + *(uint16_t*)arg = sock_remained_size[sn]; + } + break; + case SO_PACKINFO : + //CHECK_SOCKMODE(Sn_MR_TCP); +#if _WIZCHIP_ != 5300 + if ((getSn_MR(sn) == Sn_MR_TCP)) { + return SOCKERR_SOCKMODE; + } +#endif + *(uint8_t*)arg = sock_pack_info[sn]; + break; + +#endif + default: + return SOCKERR_SOCKOPT; + } + return SOCK_OK; +} + +#ifdef IPV6_AVAILABLE +int16_t peeksockmsg(uint8_t sn, uint8_t* submsg, uint16_t subsize) { + uint32_t rx_ptr = 0; + uint16_t i = 0, sub_idx = 0; + + if ((getSn_RX_RSR(sn) > 0) && (subsize > 0)) { + rx_ptr = ((uint32_t)getSn_RX_RD(sn) << 8) + WIZCHIP_RXBUF_BLOCK(sn); + sub_idx = 0; + for (i = 0; i < getSn_RX_RSR(sn) ; i++) { + if (WIZCHIP_READ(rx_ptr) == submsg[sub_idx]) { + sub_idx++; + if (sub_idx == subsize) { + return (i + 1 - sub_idx); + } + } else { + sub_idx = 0; + } + rx_ptr = WIZCHIP_OFFSET_INC(rx_ptr, 1); + } + } + return -1; +} + + +#endif + diff --git a/Ethernet/socket.h b/Ethernet/socket.h new file mode 100644 index 0000000..292844c --- /dev/null +++ b/Ethernet/socket.h @@ -0,0 +1,736 @@ +//***************************************************************************** +// +//! \file socket.h +//! \brief SOCKET APIs Header file. +//! \details SOCKET APIs like as berkeley socket api. +//! \version 1.0.2 +//! \date 2013/10/21 +//! \par Revision history +//! <2015/02/05> Notice +//! The version history is not updated after this point. +//! Download the latest version directly from GitHub. Please visit the our GitHub repository for ioLibrary. +//! >> https://github.com/Wiznet/ioLibrary_Driver +//! <2014/05/01> V1.0.2. Refer to M20140501 +//! 1. Modify the comment : SO_REMAINED -> PACK_REMAINED +//! 2. Add the comment as zero byte udp data reception in getsockopt(). +//! <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. +// +//***************************************************************************** +/** + @defgroup WIZnet_socket_APIs 1. WIZnet socket APIs + @brief WIZnet socket APIs are based on Berkeley socket APIs, thus it has much similar name and interface. + But there is a little bit of difference. + @details + Comparison between WIZnet and Berkeley SOCKET APIs + + + + + + + + + + + + +
API WIZnet Berkeley
socket() O O
bind() X O
listen() O O
connect() O O
accept() X O
recv() O O
send() O O
recvfrom() O O
sendto() O O
closesocket() O
close() & disconnect()
O
+ There are @b bind() and @b accept() functions in @b Berkeley SOCKET API but, + not in @b WIZnet SOCKET API. Because socket() of WIZnet is not only creating a SOCKET but also binding a local port number, + and listen() of WIZnet is not only listening to connection request from client but also accepting the connection request. \n + When you program "TCP SERVER" with Berkeley SOCKET API, you can use only one listen port. + When the listen SOCKET accepts a connection request from a client, it keeps listening. + After accepting the connection request, a new SOCKET is created and the new SOCKET is used in communication with the client. \n + Following figure shows network flow diagram by Berkeley SOCKET API. + @image html Berkeley_SOCKET.jpg "" + But, When you program "TCP SERVER" with WIZnet SOCKET API, you can use as many as 8 listen SOCKET with same port number. \n + Because there's no accept() in WIZnet SOCKET APIs, when the listen SOCKET accepts a connection request from a client, + it is changed in order to communicate with the client. + And the changed SOCKET is not listening any more and is dedicated for communicating with the client. \n + If there're many listen SOCKET with same listen port number and a client requests a connection, + the SOCKET which has the smallest SOCKET number accepts the request and is changed as communication SOCKET. \n + Following figure shows network flow diagram by WIZnet SOCKET API. + @image html WIZnet_SOCKET.jpg "" +*/ +#ifndef _SOCKET_H_ +#define _SOCKET_H_ +#ifdef __cplusplus +extern "C" { +#endif + +#include "wizchip_conf.h" + +#define SOCKET uint8_t ///< SOCKET type define for legacy driver + +#define SOCK_OK 1 ///< Result is OK about socket process. +#define SOCK_BUSY 0 ///< Socket is busy on processing the operation. Valid only Non-block IO Mode. +#define SOCK_FATAL -1000 ///< Result is fatal error about socket process. + +#define SOCK_ERROR 0 +#define SOCKERR_SOCKNUM (SOCK_ERROR - 1) ///< Invalid socket number +#define SOCKERR_SOCKOPT (SOCK_ERROR - 2) ///< Invalid socket option +#define SOCKERR_SOCKINIT (SOCK_ERROR - 3) ///< Socket is not initialized or SIPR is Zero IP address when Sn_MR_TCP +#define SOCKERR_SOCKCLOSED (SOCK_ERROR - 4) ///< Socket unexpectedly closed. +#define SOCKERR_SOCKMODE (SOCK_ERROR - 5) ///< Invalid socket mode for socket operation. +#define SOCKERR_SOCKFLAG (SOCK_ERROR - 6) ///< Invalid socket flag +#define SOCKERR_SOCKSTATUS (SOCK_ERROR - 7) ///< Invalid socket status for socket operation. +#define SOCKERR_ARG (SOCK_ERROR - 10) ///< Invalid argument. +#define SOCKERR_PORTZERO (SOCK_ERROR - 11) ///< Port number is zero +#define SOCKERR_IPINVALID (SOCK_ERROR - 12) ///< Invalid IP address +#define SOCKERR_TIMEOUT (SOCK_ERROR - 13) ///< Timeout occurred +#define SOCKERR_DATALEN (SOCK_ERROR - 14) ///< Data length is zero or greater than buffer max size. +#define SOCKERR_BUFFER (SOCK_ERROR - 15) ///< Socket buffer is not enough for data communication. + +#define SOCKFATAL_PACKLEN (SOCK_FATAL - 1) ///< Invalid packet length. Fatal Error. + +#if (_WIZCHIP_ == W5100 || _WIZCHIP_ == W5100S || _WIZCHIP_ == W5200 || _WIZCHIP_ == W5300 || _WIZCHIP_ == W5500) +/* + SOCKET FLAG +*/ +#define SF_ETHER_OWN (Sn_MR_MFEN) ///< In @ref Sn_MR_MACRAW, Receive only the packet as broadcast, multicast and own packet +#define SF_IGMP_VER2 (Sn_MR_MC) ///< In @ref Sn_MR_UDP with \ref SF_MULTI_ENABLE, Select IGMP version 2. +#define SF_TCP_NODELAY (Sn_MR_ND) ///< In @ref Sn_MR_TCP, Use to nodelayed ack. +#define SF_MULTI_ENABLE (Sn_MR_MULTI) ///< In @ref Sn_MR_UDP, Enable multicast mode. + +#define Sn_MR2_DHAM (1<<1) +#define SF_DHA_MANUAL (Sn_MR2_DHAM) +#define Sn_MR2_FARP (1<<0) +#define SF_FORCE_ARP (Sn_MR2_FARP) + + +#if _WIZCHIP_ == 5500 +#define SF_BROAD_BLOCK (Sn_MR_BCASTB) ///< In @ref Sn_MR_UDP or @ref Sn_MR_MACRAW, Block broadcast packet. Valid only in W5500 +#define SF_MULTI_BLOCK (Sn_MR_MMB) ///< In @ref Sn_MR_MACRAW, Block multicast packet. Valid only in W5500 +#define SF_IPv6_BLOCK (Sn_MR_MIP6B) ///< In @ref Sn_MR_MACRAW, Block IPv6 packet. Valid only in W5500 +#define SF_UNI_BLOCK (Sn_MR_UCASTB) ///< In @ref Sn_MR_UDP with \ref SF_MULTI_ENABLE. Valid only in W5500 +#endif + +//A201505 : For W5300 +#if _WIZCHIP_ == 5300 +#define SF_TCP_ALIGN 0x02 ///< Valid only \ref Sn_MR_TCP and W5300, refer to \ref Sn_MR_ALIGN +#endif + +#define SF_IO_NONBLOCK 0x01 ///< Socket nonblock io mode. It used parameter in \ref socket(). + +/* + UDP & MACRAW Packet Infomation +*/ +#define PACK_FIRST 0x80 ///< In Non-TCP packet, It indicates to start receiving a packet. (When W5300, This flag can be applied) +#define PACK_REMAINED 0x01 ///< In Non-TCP packet, It indicates to remain a packet to be received. (When W5300, This flag can be applied) +#define PACK_COMPLETED 0x00 ///< In Non-TCP packet, It indicates to complete to receive a packet. (When W5300, This flag can be applied) +//A20150601 : For Integrating with W5300 +#define PACK_FIFOBYTE 0x02 ///< Valid only W5300, It indicate to have read already the Sn_RX_FIFOR. +// +//teddy 240122 + +#define PACK_IPv6 (1<<7) ///< It indicates the destination IP address of the received packet is IPv6 or IPv4. +#define PACK_IPV6_ALLNODE (PACK_IPv6 | (1<<6)) ///< It indicates the destination IP address of the received packet is allnode multicast(broadcast) address or not. +#define PACK_IPV6_MULTI (PACK_IPv6 | (1<<5)) ///< It indicates the destination IP address of the received packet is multicast address or not. +#define PACK_IPV6_LLA (PACK_IPv6 | (1<<4)) ///< It indicates the destination IP address of the received packet is lla or gua. +#define PACK_NONE (0x00) ///< It indicates no information of a packet + +#elif ((_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300)) + +/* + - @ref Sn_MR_MULTI : Support UDP Multicasting + - @ref Sn_MR_MF : Support MAC Filter Enable + - @ref Sn_MR_BRDB : Broadcast Block + - @ref Sn_MR_FPSH : Force PSH flag + - @ref Sn_MR_ND : No Delay ACK flag + - @ref Sn_MR_MC : IGMP ver2, ver1 + - @ref Sn_MR_SMB : Solicited Multicast Block + - @ref Sn_MR_MMB : IPv4 Multicast block + - @ref Sn_MR_UNIB : Unicast Block + - @ref Sn_MR_MMB6 : IPv6 UDP Multicast Block + + - @ref Sn_MR2_DHAM : @ref Sn_MR2_DHAM_AUTO, @ref Sn_MR2_DHAM_MANUAL + - @ref Sn_MR_FARP +*/ + +/* + SOCKET FLAG +*/ +/** + @brief In UDP mode such as @ref Sn_MR_UDP4 and @ref Sn_MR_UDP6, @ref Sn_MR_UDP6, Enable multicast mode. When @ref Sn_MR_UDP6, Enable only IPv6 Multicating. +*/ +#define SF_MULTI_ENABLE (Sn_MR_MULTI) +#define SF_ETHER_OWN (Sn_MR_MF) ///< In MACRAW mode such as @ref Sn_MR_MACRAW, Receive only the packet as broadcast, multicast and own packet + +/** + @brief In UDP mode such as @ref Sn_MR_UDP4, @ref Sn_MR_UDP6 and @ref Sn_MR_UDPD, or In MACRAW mode sucha as @ref Sn_MR_MACRAW, Block a broadcast packet. +*/ +#define SF_BROAD_BLOCK (Sn_MR_BRDB) +#define SF_TCP_FPSH (Sn_MR_FPSH) ///< In TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6 and @ref Sn_MR_TCPD, Use to forced push flag. + +#define SF_TCP_NODELAY (Sn_MR_ND) ///< In TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6 and @ref Sn_MR_TCPD, Use to nodelayed ack. +#define SF_IGMP_VER2 (Sn_MR_MC) ///< In UDP mode such as @ref Sn_MR_UDP4 with @ref SF_MULTI_ENABLE, Select IGMP version 2. +#define SF_SOLICIT_BLOCK (Sn_MR_SMB) ///< In UDP mode such as @ref Sn_MR_UDP6 and @ref Sn_MR_UDPD, Block a solicited mutlicast packet. +#define SF_ETHER_MULTI4B (Sn_MR_MMB4) ///< In MACRAW mode such as @ref Sn_MR_MACRAW with @ref SF_MULTI_ENABLE, Block a IPv4 multicast packet. + +#define SF_UNI_BLOCK (Sn_MR_UNIB) ///< In UDP mdoe such as @ref Sn_MR_UDP4, @ref Sn_MR_UDP6 and @ref Sn_MR_UDPD with @ref SF_MULTI_ENABLE, Block a unicast packet. +#define SF_ETHER_MULIT6B (Sn_MR_MMB6) ///< In MACRAW mode such as @ref Sn_MR_MACRAW with @ref SF_MULTI_ENABLE, Block a IPv6 multicast packet. + +/** + @brief Force to APR. + @details In datagram mode such as @ref Sn_MR_IPRAW4, @ref Sn_MR_IPRAW6, @ref Sn_MR_UDP4, @ref Sn_MR_UDP6, and @ref Sn_MR_UDPD, + Force to request ARP before a packet is sent to a destination.\n + In TCP mode such as @ref Sn_MR_TCP4, @ref Sn_MR_TCP6, and @ref Sn_MR_TCPD and TCP SERVER operation mode, + Force to request ARP before SYN/ACK packet is sent to a TCP CLIENT. \n + When @ref SF_DHA_MANUAL is set, the ARP is process but the destination hardware address is fixed by user. +*/ +#define SF_FORCE_ARP (Sn_MR2_FARP) + +/** + @brief The destination hardware address of packet to be transmitted is set by user through @ref _Sn_DHAR_. It is invalid in MACRAW mode such as @ref Sn_MR_MACRAW. +*/ +#define SF_DHA_MANUAL (Sn_MR2_DHAM) + +#define SF_IO_NONBLOCK (0x01 << 3) ///< Socket nonblock io mode. It used parameter in @ref socket(). + +/* + UDP, IPRAW, MACRAW Packet Infomation +*/ +#define PACK_IPv6 (1<<7) ///< It indicates the destination IP address of the received packet is IPv6 or IPv4. +#define PACK_IPV6_ALLNODE (PACK_IPv6 | (1<<6)) ///< It indicates the destination IP address of the received packet is allnode multicast(broadcast) address or not. +#define PACK_IPV6_MULTI (PACK_IPv6 | (1<<5)) ///< It indicates the destination IP address of the received packet is multicast address or not. +#define PACK_IPV6_LLA (PACK_IPv6 | (1<<4)) ///< It indicates the destination IP address of the received packet is lla or gua. +#define PACK_COMPLETED (1<<3) ///< It indicates the read data is last in the received packet. +#define PACK_REMAINED (1<<2) ///< It indicates to remain data in the received packet +#define PACK_FIRST (1<<1) ///< It indicates the read data is first in the received packet. +#define PACK_NONE (0x00) ///< It indicates no information of a packet + +#define SRCV6_PREFER_AUTO (PSR_AUTO) ///< Soruce IPv6 address is preferred to auto-selection. Refer to @ref _Sn_PSR_ +#define SRCV6_PREFER_LLA (PSR_LLA) ///< Soruce IPv6 address is preferred to link local address. Refer to @ref _Sn_PSR_ +#define SRCV6_PREFER_GUA (PSR_GUA) ///< Soruce IPv6 address is preferred to global unique address. Refer to @ref _Sn_PSR_ + +#define TCPSOCK_MODE (Sn_ESR_TCPM) ///< It indicates the IP version when SOCKETn is opened as TCP6 or TCPD mode.(0 - IPv4 , 1 - IPv6) +#define TCPSOCK_OP (Sn_ESR_TCPOP) ///< It indicates the operation mode when SOCKETn is connected.(0 - TCP CLIENT , 1 - TCP SERVER) +#define TCPSOCK_SIP (Sn_ESR_IP6T) ///< It indicates the source ip address type when SOCKET is connected. (0 - Link Local, 1 - Global Unique) + +///////////////////////////// +// SOCKET CONTROL & OPTION // +///////////////////////////// +#define SOCK_IO_BLOCK 0 ///< Socket Block IO Mode in @ref setsockopt(). +#define SOCK_IO_NONBLOCK 1 ///< Socket Non-block IO Mode in @ref setsockopt(). +#endif + +/** + @ingroup WIZnet_socket_APIs + @brief Open a socket. + @details Initializes the socket with 'sn' passed as parameter and open. + + @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. + @param protocol Protocol type to operate such as TCP, UDP and MACRAW. + @param port Port number to be bined. + @param flag Socket flags as \ref SF_ETHER_OWN, \ref SF_IGMP_VER2, \ref SF_TCP_NODELAY, \ref SF_MULTI_ENABLE, \ref SF_IO_NONBLOCK and so on.\n + Valid flags only in W5500 : @ref SF_BROAD_BLOCK, @ref SF_MULTI_BLOCK, @ref SF_IPv6_BLOCK, and @ref SF_UNI_BLOCK. + @sa Sn_MR + + @return @b Success : The socket number @b 'sn' passed as parameter\n + @b Fail :\n @ref SOCKERR_SOCKNUM - Invalid socket number\n + @ref SOCKERR_SOCKMODE - Not support socket mode as TCP, UDP, and so on. \n + @ref SOCKERR_SOCKFLAG - Invaild socket flag. +*/ +int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag); + +/** + @ingroup WIZnet_socket_APIs + @brief Close a socket. + @details It closes the socket with @b'sn' passed as parameter. + + @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. + + @return @b Success : @ref SOCK_OK \n + @b Fail : @ref SOCKERR_SOCKNUM - Invalid socket number +*/ +int8_t close(uint8_t sn); + +/** + @ingroup WIZnet_socket_APIs + @brief Listen to a connection request from a client. + @details It is listening to a connection request from a client. + If connection request is accepted successfully, the connection is established. Socket sn is used in passive(server) mode. + + @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. + @return @b Success : @ref SOCK_OK \n + @b Fail :\n @ref SOCKERR_SOCKINIT - Socket is not initialized \n + @ref SOCKERR_SOCKCLOSED - Socket closed unexpectedly. +*/ +int8_t listen(uint8_t sn); + +//teddy 240122 +/** + @ingroup WIZnet_socket_APIs + @brief Try to connect to a TCP SERVER. + @details It sends a connection-reqeust message to the server with destination IP address and port number passed as parameter.\n + SOCKET sn is used as active(TCP CLIENT) mode. + @param sn SOCKET number. It should be 0 ~ @ref _WIZCHIP_SOCK_NUM_. + @param addr Pointer variable of destination IPv6 or IPv4 address. + @param port Destination port number. + @param addrlen the length of addr. \n <- removed + If addr is IPv6 address it should be 16,else if addr is IPv4 address it should be 4. Otherwize, return @ref SOCKERR_IPINVALID. + @return Success : @ref SOCK_OK \n + Fail :\n @ref SOCKERR_SOCKNUM - Invalid socket number\n + @ref SOCKERR_SOCKMODE - Invalid socket mode\n + @ref SOCKERR_SOCKINIT - Socket is not initialized\n + @ref SOCKERR_IPINVALID - Wrong server IP address\n + @ref SOCKERR_PORTZERO - Server port zero\n + @ref SOCKERR_TIMEOUT - Timeout occurred during request connection\n + @ref SOCK_BUSY - In non-block io mode, it returns immediately\n + @note It is valid only in TCP client mode. \n + In block io mode, it does not return until connection is completed. \n + In Non-block io mode(@ref SF_IO_NONBLOCK), it returns @ref SOCK_BUSY immediately. +*/ +static int8_t connect_IO_6(uint8_t sn, uint8_t * addr, uint16_t port, uint8_t addrlen); +//int8_t connect(uint8_t sn, uint8_t * addr, uint16_t port, uint8_t addrlen); + +/** + @ingroup WIZnet_socket_APIs + @brief Try to disconnect a connection socket. + @details It sends request message to disconnect the TCP socket 'sn' passed as parameter to the server or client. + @note It is valid only in TCP server or client mode. \n + In block io mode, it does not return until disconnection is completed. \n + In Non-block io mode, it return @ref SOCK_BUSY immediately. \n + + @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. + @return @b Success : @ref SOCK_OK \n + @b Fail :\n @ref SOCKERR_SOCKNUM - Invalid socket number \n + @ref SOCKERR_SOCKMODE - Invalid operation in the socket \n + @ref SOCKERR_TIMEOUT - Timeout occurred \n + @ref SOCK_BUSY - Socket is busy. +*/ +int8_t disconnect(uint8_t sn); + +/** + @ingroup WIZnet_socket_APIs + @brief Send data to the connected peer in TCP socket. + @details It is used to send outgoing data to the connected socket. + @note It is valid only in TCP server or client mode. It can't send data greater than socket buffer size. \n + In block io mode, It doesn't return until data send is completed - socket buffer size is greater than data. \n + In non-block io mode, It return @ref SOCK_BUSY immediately when socket buffer is not enough. \n + @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. + @param buf Pointer buffer containing data to be sent. + @param len The byte length of data in buf. + @return @b Success : The sent data size \n + @b Fail : \n @ref SOCKERR_SOCKSTATUS - Invalid socket status for socket operation \n + @ref SOCKERR_TIMEOUT - Timeout occurred \n + @ref SOCKERR_SOCKMODE - Invalid operation in the socket \n + @ref SOCKERR_SOCKNUM - Invalid socket number \n + @ref SOCKERR_DATALEN - zero data length \n + @ref SOCK_BUSY - Socket is busy. +*/ +int32_t send(uint8_t sn, uint8_t * buf, uint16_t len); + +/** + @ingroup WIZnet_socket_APIs + @brief Receive data from the connected peer. + @details It is used to read incoming data from the connected socket.\n + It waits for data as much as the application wants to receive. + @note It is valid only in TCP server or client mode. It can't receive data greater than socket buffer size. \n + In block io mode, it doesn't return until data reception is completed - data is filled as len in socket buffer. \n + In non-block io mode, it return @ref SOCK_BUSY immediately when len is greater than data size in socket buffer. \n + + @param sn Socket number. It should be 0 ~ @ref \_WIZCHIP_SOCK_NUM_. + @param buf Pointer buffer to read incoming data. + @param len The max data length of data in buf. + @return @b Success : The real received data size \n + @b Fail :\n + @ref SOCKERR_SOCKSTATUS - Invalid socket status for socket operation \n + @ref SOCKERR_SOCKMODE - Invalid operation in the socket \n + @ref SOCKERR_SOCKNUM - Invalid socket number \n + @ref SOCKERR_DATALEN - zero data length \n + @ref SOCK_BUSY - Socket is busy. +*/ +int32_t recv(uint8_t sn, uint8_t * buf, uint16_t len); + +/** + @ingroup WIZnet_socket_APIs + @brief Send datagram to the peer specifed by destination IP address and port number passed as parameter. + @details It sends datagram data by using UDP,IPRAW, or MACRAW mode SOCKET. + @param sn SOCKET number. It should be 0 ~ @ref _WIZCHIP_SOCK_NUM_. + @param buf Pointer of data buffer to be sent. + @param len The byte length of data in buf. + @param addr Pointer variable of destination IPv6 or IPv4 address. + @param port Destination port number. + @param addrlen the length of addr. \n + If addr is IPv6 address it should be 16,else if addr is IPv4 address it should be 4. Otherwize, return @ref SOCKERR_IPINVALID. + @return Success : The real sent data size. It may be equal to len or small.\n + Fail :\n @ref SOCKERR_SOCKNUM - Invalid SOCKET number \n + @ref SOCKERR_SOCKMODE - Invalid operation in the SOCKET \n + @ref SOCKERR_SOCKSTATUS - Invalid SOCKET status for SOCKET operation \n + @ref SOCKERR_IPINVALID - Invalid IP address\n + @ref SOCKERR_PORTZERO - Destination port number is zero\n + @ref SOCKERR_DATALEN - Invalid data length \n + @ref SOCKERR_SOCKCLOSED - SOCKET unexpectedly closed \n + @ref SOCKERR_TIMEOUT - Timeout occurred \n + @ref SOCK_BUSY - SOCKET is busy. + @note It is valid only in @ref Sn_MR_UDP4, @ref Sn_MR_UDP6, @ref Sn_MR_UDPD, @ref Sn_MR_IPRAW4, @ref Sn_MR_IPRAW6, and @ref Sn_MR_MACRAW. \n + In UDP mode, It can send data as many as SOCKET RX buffer size if data is greater than SOCKET TX buffer size. \n + In IPRAW and MACRAW mode, It should send data as many as MTU(maxium transmission unit) if data is greater than MTU. That is, len can't exceed to MTU. + In block io mode, It doesn't return until data send is completed. + In non-block io mode(@ref SF_IO_NONBLOCK), It return @ref SOCK_BUSY immediately when SOCKET transimttable buffer size is not enough. +*/ +//int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port, uint8_t addrlen); +static int32_t sendto_IO_6(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port, uint8_t addrlen); + +/** + @ingroup WIZnet_socket_APIs + @brief Receive datagram from a peer + @details It can read a data received from a peer by using UDP, IPRAW, or MACRAW mode SOCKET. + @param sn SOCKET number. It should be 0 ~ @ref _WIZCHIP_SOCK_NUM_. + @param buf Pointer buffer to be saved the received data. + @param len The max read data length. \n + When the received packet size <= len, it can read data as many as the packet size. \n + When others, it can read data as many as len and remain to the rest data of the packet. + @param addr Pointer variable of destination IP address.\n + It is valid only when @ref recvfrom() is first called for receiving the datagram packet. + You can check it valid or not through @ref PACK_FIRST. You can get it through @ref getsockopt(sn, @ref SO_PACKINFO, &packinfo).\n + In UDP4, IPRAW mode SOCKET, it should be allocated over 4bytes. \n + In UDP6, UDPD mode SOCKET, it should be allocated over 16bytes. + @param port Pointer variable of destination port number. \n + It is valid only when @ref recvfrom() is first called for receiving the datagram packet, same as port case. + @param addrlen The byte length of destination IP address. \n + It is valid only when @ref recvfrom() is first called for receiving the datagram packet, same as port case.\n + When the destination has a IPv4 address, it is set to 4. \n + when the destination has a IPv6 address, it is set to 16. + @return Success : The real received data size. It may be equal to len or small.\n + Fail : @ref SOCKERR_SOCKMODE - Invalid operation in the socket \n + @ref SOCKERR_SOCKNUM - Invalid socket number \n + @ref SOCKERR_ARG - Invalid parameter such as addr, port + @ref SOCK_BUSY - SOCKET is busy. + @note It is valid only in @ref Sn_MR_UDP4, @ref Sn_MR_UDP6, @ref Sn_MR_UDPD, @ref Sn_MR_IPRAW4, @ref Sn_MR_IPRAW6, and @ref Sn_MR_MACRAW. \n + When SOCKET is opened with @ref Sn_MR_MACRAW or When it reads the the remained data of the previous datagram packet, + the parameters such as addr, port, addrlen is ignored. \n + Also, It can read data as many as the received datagram packet size if len is greater than the datagram packet size. \n + In block io mode, it doesn't return until data reception is completed. that is, it waits until any datagram packet is received in SOCKET RX buffer. \n + In non-block io mode(@ref SF_IO_NONBLOCK), it return @ref SOCK_BUSY immediately when SOCKET RX buffer is empty. \n +*/ +//int32_t recvfrom(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port, uint8_t *addrlen); +static int32_t recvfrom_IO_6(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port, uint8_t *addrlen); + + +///////////////////////////// +// SOCKET CONTROL & OPTION // +///////////////////////////// +#define SOCK_IO_BLOCK 0 ///< Socket Block IO Mode in @ref setsockopt(). +#define SOCK_IO_NONBLOCK 1 ///< Socket Non-block IO Mode in @ref setsockopt(). + +/** + @defgroup DATA_TYPE DATA TYPE +*/ + +/** + @ingroup DATA_TYPE + @brief The kind of Socket Interrupt. + @sa Sn_IR, Sn_IMR, setSn_IR(), getSn_IR(), setSn_IMR(), getSn_IMR() +*/ +typedef enum { + SIK_CONNECTED = (1 << 0), ///< connected + SIK_DISCONNECTED = (1 << 1), ///< disconnected + SIK_RECEIVED = (1 << 2), ///< data received + SIK_TIMEOUT = (1 << 3), ///< timeout occurred + SIK_SENT = (1 << 4), ///< send ok + //M20150410 : Remove the comma of last member + //SIK_ALL = 0x1F, ///< all interrupt + SIK_ALL = 0x1F ///< all interrupt +} sockint_kind; + +/** + @ingroup DATA_TYPE + @brief The type of @ref ctlsocket(). +*/ +typedef enum { + CS_SET_IOMODE, ///< set socket IO mode with @ref SOCK_IO_BLOCK or @ref SOCK_IO_NONBLOCK + CS_GET_IOMODE, ///< get socket IO mode + CS_GET_MAXTXBUF, ///< get the size of socket buffer allocated in TX memory + CS_GET_MAXRXBUF, ///< get the size of socket buffer allocated in RX memory + CS_CLR_INTERRUPT, ///< clear the interrupt of socket with @ref sockint_kind + CS_GET_INTERRUPT, ///< get the socket interrupt. refer to @ref sockint_kind + + //teddy 240122 + //#if _WIZCHIP_ == W6100 || _WIZCHIP_ == W6300 + CS_SET_PREFER, ///< set the preferred source IPv6 address of transmission packet.\n Refer to @ref SRCV6_PREFER_AUTO, @ref SRCV6_PREFER_LLA and @ref SRCV6_PREFER_GUA. + CS_GET_PREFER, ///< get the preferred source IPv6 address of transmission packet.\n Refer to @ref SRCV6_PREFER_AUTO, @ref SRCV6_PREFER_LLA and @ref SRCV6_PREFER_GUA. + //#endif +#if _WIZCHIP_ >= 5100 + CS_SET_INTMASK, ///< set the interrupt mask of socket with @ref sockint_kind, Not supported in W5100 + CS_GET_INTMASK ///< get the masked interrupt of socket. refer to @ref sockint_kind, Not supported in W5100 +#endif +} ctlsock_type; + + +/** + @ingroup DATA_TYPE + @brief The type of socket option in @ref setsockopt() or @ref getsockopt() +*/ +typedef enum { + SO_FLAG, ///< Valid only in getsockopt(), For set flag of socket refer to flag in @ref socket(). + SO_TTL, ///< Set TTL. @ref Sn_TTL ( @ref setSn_TTL(), @ref getSn_TTL() ) + SO_TOS, ///< Set TOS. @ref Sn_TOS ( @ref setSn_TOS(), @ref getSn_TOS() ) + SO_MSS, ///< Set MSS. @ref Sn_MSSR ( @ref setSn_MSSR(), @ref getSn_MSSR() ) + SO_DESTIP, ///< Set the destination IP address. @ref Sn_DIPR ( @ref setSn_DIPR(), @ref getSn_DIPR() ) + SO_DESTPORT, ///< Set the destination Port number. @ref Sn_DPORT ( @ref setSn_DPORT(), @ref getSn_DPORT() ) +#if _WIZCHIP_ != 5100 + SO_KEEPALIVESEND, ///< Valid only in setsockopt. Manually send keep-alive packet in TCP mode, Not supported in W5100 +#if !( (_WIZCHIP_ == 5100) || (_WIZCHIP_ == 5200) ) + SO_KEEPALIVEAUTO, ///< Set/Get keep-alive auto transmission timer in TCP mode, Not supported in W5100, W5200 +#endif +#endif + SO_SENDBUF, ///< Valid only in getsockopt. Get the free data size of Socekt TX buffer. @ref Sn_TX_FSR, @ref getSn_TX_FSR() + SO_RECVBUF, ///< Valid only in getsockopt. Get the received data size in socket RX buffer. @ref Sn_RX_RSR, @ref getSn_RX_RSR() + SO_STATUS, ///< Valid only in getsockopt. Get the socket status. @ref Sn_SR, @ref getSn_SR() + + //teddy 240122 + //#if _WIZCHIP_ == W6100 || _WIZCHIP_ == W6300 + SO_EXTSTATUS, ///< Valid only in @ref getsockopt(). Get the extended TCP SOCKETn status. @ref getSn_ESR() + SO_MODE, + //#endif + SO_REMAINSIZE, ///< Valid only in getsockopt. Get the remained packet size in other then TCP mode. + SO_PACKINFO ///< Valid only in getsockopt. Get the packet information as @ref PACK_FIRST, @ref PACK_REMAINED, and @ref PACK_COMPLETED in other then TCP mode. +} sockopt_type; + +/** + @ingroup WIZnet_socket_APIs + @brief Control socket. + @details Control IO mode, Interrupt & Mask of socket and get the socket buffer information. + Refer to @ref ctlsock_type. + @param sn socket number + @param cstype type of control socket. refer to @ref ctlsock_type. + @param arg Data type and value is determined according to @ref ctlsock_type. \n + + + + + +
@b cstype @b data type@b value
@ref CS_SET_IOMODE \n @ref CS_GET_IOMODE uint8_t @ref SOCK_IO_BLOCK @ref SOCK_IO_NONBLOCK
@ref CS_GET_MAXTXBUF \n @ref CS_GET_MAXRXBUF uint16_t 0 ~ 16K
@ref CS_CLR_INTERRUPT \n @ref CS_GET_INTERRUPT \n @ref CS_SET_INTMASK \n @ref CS_GET_INTMASK @ref sockint_kind @ref SIK_CONNECTED, etc.
+ @return @b Success @ref SOCK_OK \n + @b fail @ref SOCKERR_ARG - Invalid argument\n +*/ +int8_t ctlsocket(uint8_t sn, ctlsock_type cstype, void* arg); + +/** + @ingroup WIZnet_socket_APIs + @brief set socket options + @details Set socket option like as TTL, MSS, TOS, and so on. Refer to @ref sockopt_type. + + @param sn socket number + @param sotype socket option type. refer to @ref sockopt_type + @param arg Data type and value is determined according to sotype. \n + + + + + + + + + +
@b sotype @b data type@b value
@ref SO_TTL uint8_t 0 ~ 255
@ref SO_TOS uint8_t 0 ~ 255
@ref SO_MSS uint16_t 0 ~ 65535
@ref SO_DESTIP uint8_t[4]
@ref SO_DESTPORT uint16_t 0 ~ 65535
@ref SO_KEEPALIVESEND null null
@ref SO_KEEPALIVEAUTO uint8_t 0 ~ 255
+ @return + - @b Success : @ref SOCK_OK \n + - @b Fail + - @ref SOCKERR_SOCKNUM - Invalid Socket number \n + - @ref SOCKERR_SOCKMODE - Invalid socket mode \n + - @ref SOCKERR_SOCKOPT - Invalid socket option or its value \n + - @ref SOCKERR_TIMEOUT - Timeout occurred when sending keep-alive packet \n +*/ +int8_t setsockopt(uint8_t sn, sockopt_type sotype, void* arg); + +/** + @ingroup WIZnet_socket_APIs + @brief get socket options + @details Get socket option like as FLAG, TTL, MSS, and so on. Refer to @ref sockopt_type + @param sn socket number + @param sotype socket option type. refer to @ref sockopt_type + @param arg Data type and value is determined according to sotype. \n + + + + + + + + + + + + + +
@b sotype @b data type@b value
@ref SO_FLAG uint8_t @ref SF_ETHER_OWN, etc...
@ref SO_TOS uint8_t 0 ~ 255
@ref SO_MSS uint16_t 0 ~ 65535
@ref SO_DESTIP uint8_t[4]
@ref SO_DESTPORT uint16_t
@ref SO_KEEPALIVEAUTO uint8_t 0 ~ 255
@ref SO_SENDBUF uint16_t 0 ~ 65535
@ref SO_RECVBUF uint16_t 0 ~ 65535
@ref SO_STATUS uint8_t @ref SOCK_ESTABLISHED, etc..
@ref SO_REMAINSIZE uint16_t 0~ 65535
@ref SO_PACKINFO uint8_t @ref PACK_FIRST, etc...
+ @return + - @b Success : @ref SOCK_OK \n + - @b Fail + - @ref SOCKERR_SOCKNUM - Invalid Socket number \n + - @ref SOCKERR_SOCKOPT - Invalid socket option or its value \n + - @ref SOCKERR_SOCKMODE - Invalid socket mode \n + @note + The option as PACK_REMAINED and SO_PACKINFO is valid only in NON-TCP mode and after call @ref recvfrom(). \n + When SO_PACKINFO value is PACK_FIRST and the return value of recvfrom() is zero, + This means the zero byte UDP data(UDP Header only) received. +*/ +int8_t getsockopt(uint8_t sn, sockopt_type sotype, void* arg); + +//teddy 240122 +#if _WIZCHIP_ == W6100 || _WIZCHIP_ == W6300 +/** + @ingroup WIZnet_socket_APIs + @brief Peeks a sub-message in SOCKETn RX buffer + @details It peeks the incoming message of SOCKETn RX buffer. \n + It can find the specified sub-message in the incoming message and + return the length of incoming message before the sub-message. \n + It is useful when you need to read each messages from multiple message in SOCKET RX buffer. + @param sn SOCKET number + @param submsg sub-message pointer to find + @param subsize the length of submsg + @return + - Success : the length of incoming message length before the submsg \n + - Fail : -1 + @note + It is just return the length of incoming message before the found sub-message. It does not receive the message.\n + So, after calling peeksockmsg, @ref _Sn_RX_RD_ is not changed. +*/ +int16_t peeksockmsg(uint8_t sn, uint8_t* submsg, uint16_t subsize); + +#endif + +// void setAddrlen_W6x00( uint8_t num) ; +// uint8_t checkAddrlen_W6x00() ; + +// void inline_setAddrlen_W6x00( uint8_t num); +// uint8_t inline_CheckAddrlen_W6x00( void ); + + +#if 1 // by_Lihan + +/** + @ingroup WIZnet_socket_APIs + @brief by_Lihan_W5x00 +*/ +int8_t connect_W5x00(uint8_t sn, uint8_t * addr, uint16_t port); +/** + @ingroup WIZnet_socket_APIs + @brief by_Lihan_Wx00 +*/ +int8_t connect_W6x00(uint8_t sn, uint8_t * addr, uint16_t port, uint8_t addrlen); + + + + + +#define GET_MACRO_connect(_1, _2, _3, _4, NAME, ...) NAME +#define CHOOSE_TESTCODE_MACRO(...) GET_MACRO_connect(__VA_ARGS__, connect_4, connect_3) + +/** + // by_LIhan for overroading + // NOTE_LIHAN: Some sections of this code are not yet fully defined. + @note + In case of get 3 arguments - int8_t connect_W5x00(uint8_t sn, uint8_t * addr, uint16_t port );\n + In case of get 4 arguments - int8_t connect_W6x00(uint8_t sn, uint8_t * addr, uint16_t port, uint8_t addrlen ); +*/ + +#define connect(...) CHOOSE_TESTCODE_MACRO(__VA_ARGS__)(__VA_ARGS__) + +// In case of get 3 arguments +#define connect_3(sn , addr , port ) connect_W5x00(sn , addr , port) + +// In case of get 4 arguments +#define connect_4(sn , addr , port, addrlen ) connect_W6x00(sn , addr , port,addrlen) + + + + +/** + @ingroup WIZnet_socket_APIs + @brief by_Lihan +*/ +int32_t sendto_W5x00(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port); +/** + @ingroup WIZnet_socket_APIs + @brief by_Lihan +*/ +int32_t sendto_W6x00(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port, uint8_t addrlen); + + +#define GET_MACRO_sendto(_1, _2, _3, _4, _5 , _6, NAME, ...) NAME +#define CHOOSE_sendto_MACRO(...) GET_MACRO_sendto(__VA_ARGS__, sendto_6, sendto_5) + +// by_LIhan for overroading +// NOTE_LIHAN: Some sections of this code are not yet fully defined. +// In case of get 3 arguments - int8_t sendto_W5x00(uint8_t sn, uint8_t * addr, uint16_t port ); +// In case of get 4 arguments - int8_t sendto_W6x00(uint8_t sn, uint8_t * addr, uint16_t port,uint8_t addrlen ); +#define sendto(...) CHOOSE_sendto_MACRO(__VA_ARGS__)(__VA_ARGS__) + +// In case of get 3 arguments +#define sendto_5( sn, buf, len, addr, port ) sendto_W5x00( sn, buf, len, addr, port) + +// In case of get 4 arguments +#define sendto_6( sn, buf, len, addr, port, addrlen ) sendto_W6x00( sn, buf, len, addr, port, addrlen) + +/** + @ingroup WIZnet_socket_APIs + @brief byLihan_W5x00 +*/ +int32_t recvfrom_W5x00(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port); +/** + @ingroup WIZnet_socket_APIs + @brief byLihan_Wx00 +*/ +int32_t recvfrom_W6x00(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port, uint8_t *addrlen); + + +#define GET_MACRO_recvfrom(_1, _2, _3, _4, _5, _6 ,NAME, ...) NAME +#define CHOOSE_recvfrom_MACRO(...) GET_MACRO_recvfrom(__VA_ARGS__, recvfrom_6, recvfrom_5) + +// by_LIhanfor overroading +// In case of get 3 arguments - int8_t recvfrom_W5x00(uint8_t sn, uint8_t * addr, uint16_t port ); +// In case of get 4 arguments - int8_t recvfrom_W6x00(uint8_t sn, uint8_t * addr, uint16_t port,uint8_t addrlen ); +#define recvfrom(...) CHOOSE_recvfrom_MACRO(__VA_ARGS__)(__VA_ARGS__) + +// In case of get 3 arguments +#define recvfrom_5(sn, buf, len, addr, port ) recvfrom_W5x00(sn, buf, len, addr, port) + +// In case of get 4 arguments +#define recvfrom_6(sn, buf, len, addr, port, addrlen ) recvfrom_W6x00(sn, buf, len, addr, port, addrlen ) + + +#endif + + + +#ifdef __cplusplus +} +#endif + +#endif // _SOCKET_H_ + + diff --git a/Ethernet/wizchip_conf.c b/Ethernet/wizchip_conf.c new file mode 100644 index 0000000..9409b60 --- /dev/null +++ b/Ethernet/wizchip_conf.c @@ -0,0 +1,1515 @@ +//****************************************************************************/ +//! +//! \file wizchip_conf.c +//! \brief WIZCHIP Config Header File. +//! \version 1.0.1 +//! \date 2013/10/21 +//! \par Revision history +//! <2015/02/05> Notice +//! The version history is not updated after this point. +//! Download the latest version directly from GitHub. Please visit the our GitHub repository for ioLibrary. +//! >> https://github.com/Wiznet/ioLibrary_Driver +//! <2014/05/01> V1.0.1 Refer to M20140501 +//! 1. Explicit type casting in wizchip_bus_readdata() & wizchip_bus_writedata() +// Issued by Mathias ClauBen. +//! uint32_t type converts into ptrdiff_t first. And then recoverting it into uint8_t* +//! For remove the warning when pointer type size is not 32bit. +//! If ptrdiff_t doesn't support in your complier, You should must replace ptrdiff_t into your suitable pointer type. +//! <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. +// +//*****************************************************************************/ +//A20140501 : for use the type - ptrdiff_t +#include +// + +#include "wizchip_conf.h" + +///////////// +//M20150401 : Remove ; in the default callback function such as wizchip_cris_enter(), wizchip_cs_select() and etc. +///////////// + +/** + @brief Default function to enable interrupt. + @note This function help not to access wrong address. If you do not describe this function or register any functions, + null function is called. +*/ +//void wizchip_cris_enter(void) {}; +void wizchip_cris_enter(void) {} + +/** + @brief Default function to disable interrupt. + @note This function help not to access wrong address. If you do not describe this function or register any functions, + null function is called. +*/ +//void wizchip_cris_exit(void) {}; +void wizchip_cris_exit(void) {} + +/** + @brief Default function to select chip. + @note This function help not to access wrong address. If you do not describe this function or register any functions, + null function is called. +*/ +//void wizchip_cs_select(void) {}; +void wizchip_cs_select(void) {} + +/** + @brief Default function to deselect chip. + @note This function help not to access wrong address. If you do not describe this function or register any functions, + null function is called. +*/ +//void wizchip_cs_deselect(void) {}; +void wizchip_cs_deselect(void) {} + +/** + @brief Default function to read in direct or indirect interface. + @note This function help not to access wrong address. If you do not describe this function or register any functions, + null function is called. +*/ +//M20150601 : Rename the function for integrating with W5300 +//uint8_t wizchip_bus_readbyte(uint32_t AddrSel) { return * ((volatile uint8_t *)((ptrdiff_t) AddrSel)); } +iodata_t wizchip_bus_readdata(uint32_t AddrSel) { + return * ((volatile iodata_t *)((ptrdiff_t) AddrSel)); +} + +/** + @brief Default function to write in direct or indirect interface. + @note This function help not to access wrong address. If you do not describe this function or register any functions, + null function is called. +*/ +//M20150601 : Rename the function for integrating with W5300 +//void wizchip_bus_writebyte(uint32_t AddrSel, uint8_t wb) { *((volatile uint8_t*)((ptrdiff_t)AddrSel)) = wb; } +void wizchip_bus_writedata(uint32_t AddrSel, iodata_t wb) { + *((volatile iodata_t*)((ptrdiff_t)AddrSel)) = wb; +} +#if 1 +// 20231103 taylor +/** + @brief Default function to read @ref iodata_t buffer by using BUS interface + @details @ref wizchip_bus_read_buf() provides the default read @ref iodata_t data as many as len from BUS of @ref _WIZCHIP_. + @param AddrSel It specifies the address of register to be read. + @param buf It specifies your buffer pointer to be saved the read data from @ref _WIZCHIP_. + @param len It specifies the data length to be read from @ref _WIZCHIP_. + @param addrinc It specifies whether the address is increased by every read operation or not.\n + 0 : Not Increased \n + 1 : Increased + @return void + @note It can be overwritten with your function or register your functions by calling @ref reg_wizchip_bus_cbfunc(). + @sa wizchip_bus_write_buf() +*/ +void wizchip_bus_read_buf(uint32_t AddrSel, iodata_t* buf, int16_t len, uint8_t addrinc) { + uint16_t i; + if (addrinc) { + addrinc = sizeof(iodata_t); + } + for (i = 0; i < len; i++) { + *buf++ = WIZCHIP.IF.BUS._read_data(AddrSel); + AddrSel += (uint32_t) addrinc; + } +} + +/** + @brief Default function to write @ref iodata_t buffer by using BUS interface. + @details @ref wizchip_bus_write_buf() provides the default write @ref iodata_t data as many as len to BUS of @ref _WIZCHIP_. + @param AddrSel It specifies the address of register to be written. + @param buf It specifies your buffer pointer to be written to @ref _WIZCHIP_. + @param len It specifies the data length to be written to @ref _WIZCHIP_. + @param addrinc It specifies whether the address is increased by every write operation or not.\n + 0 : Not Increased \n + 1 : Increased + @return void + @note It can be overwritten with your function or register your functions by calling @ref reg_wizchip_bus_cbfunc(). + @sa wizchip_bus_read_buf() +*/ +void wizchip_bus_write_buf(uint32_t AddrSel, iodata_t* buf, int16_t len, uint8_t addrinc) { + uint16_t i; + if (addrinc) { + addrinc = sizeof(iodata_t); + } + for (i = 0; i < len ; i++) { + WIZCHIP.IF.BUS._write_data(AddrSel, *buf++); + AddrSel += (uint32_t)addrinc; + } + +} +#endif + +/** + @brief Default function to read in SPI interface. + @note This function help not to access wrong address. If you do not describe this function or register any functions, + null function is called. +*/ +//uint8_t wizchip_spi_readbyte(void) {return 0;}; +uint8_t wizchip_spi_readbyte(void) { + return 0; +} + +/** + @brief Default function to write in SPI interface. + @note This function help not to access wrong address. If you do not describe this function or register any functions, + null function is called. +*/ +//void wizchip_spi_writebyte(uint8_t wb) {}; +void wizchip_spi_writebyte(uint8_t wb) {} + +/** + @brief Default function to burst read in SPI interface. + @note This function help not to access wrong address. If you do not describe this function or register any functions, + null function is called. +*/ +//void wizchip_spi_readburst(uint8_t* pBuf, uint16_t len) {}; +#if 1 +// 20231018 taylor +void wizchip_spi_readburst(uint8_t* pBuf, uint16_t len) { + for (uint16_t i = 0; i < len; i++) { + *pBuf++ = WIZCHIP.IF.SPI._read_byte(); + } +} +#else +void wizchip_spi_readburst(uint8_t* pBuf, uint16_t len) {} +#endif + +/** + @brief Default function to burst write in SPI interface. + @note This function help not to access wrong address. If you do not describe this function or register any functions, + null function is called. +*/ +//void wizchip_spi_writeburst(uint8_t* pBuf, uint16_t len) {}; +#if 1 +// 20231018 taylor +void wizchip_spi_writeburst(uint8_t* pBuf, uint16_t len) { + for (uint16_t i = 0; i < len; i++) { + WIZCHIP.IF.SPI._write_byte(*pBuf++); + } +} +#else +void wizchip_spi_writeburst(uint8_t* pBuf, uint16_t len) {} +#endif +#if 1 //teddy 240122 + +/** + @brief Default function to read in QSPI interface. + @note This function help not to access wrong address. If you do not describe this function or register any functions, + null function is called. +*/ +void wizchip_qspi_read(uint8_t opcode, uint16_t addr, uint8_t* pBuf, uint16_t len) {} + +/** + @brief Default function to write in QSPI interface. + @note This function help not to access wrong address. If you do not describe this function or register any functions, + null function is called. +*/ +void wizchip_qspi_write(uint8_t opcode, uint16_t addr, uint8_t* pBuf, uint16_t len) {} + +#endif +/** + @\ref _WIZCHIP instance +*/ +// +//M20150401 : For a compiler didnot support a member of structure +// Replace the assignment of struct members with the assingment of array +// +/* + _WIZCHIP WIZCHIP = + { + .id = _WIZCHIP_ID_, + .if_mode = _WIZCHIP_IO_MODE_, + .CRIS._enter = wizchip_cris_enter, + .CRIS._exit = wizchip_cris_exit, + .CS._select = wizchip_cs_select, + .CS._deselect = wizchip_cs_deselect, + .IF.BUS._read_byte = wizchip_bus_readbyte, + .IF.BUS._write_byte = wizchip_bus_writebyte + // .IF.SPI._read_byte = wizchip_spi_readbyte, + // .IF.SPI._write_byte = wizchip_spi_writebyte + }; +*/ +_WIZCHIP WIZCHIP = { + _WIZCHIP_IO_MODE_, + _WIZCHIP_ID_, + { + wizchip_cris_enter, + wizchip_cris_exit + }, + { + wizchip_cs_select, + wizchip_cs_deselect + }, + { + { + //M20150601 : Rename the function + //wizchip_bus_readbyte, + //wizchip_bus_writebyte + wizchip_bus_readdata, + wizchip_bus_writedata + }, + + } +}; + + +static uint8_t _DNS_[4]; // DNS server ip address +#if (_WIZCHIP_ == W5100 || _WIZCHIP_ == W5100S || _WIZCHIP_ == W5200 || _WIZCHIP_ == W5300 || _WIZCHIP_ == W5500) +static dhcp_mode _DHCP_; // DHCP mode +//teddy 240122 +#elif ((_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300)) +static uint8_t _DNS6_[16]; ///< DSN server IPv6 address +static ipconf_mode _IPMODE_; ///< IP configuration mode +#endif + +void reg_wizchip_cris_cbfunc(void(*cris_en)(void), void(*cris_ex)(void)) { + if (!cris_en || !cris_ex) { + WIZCHIP.CRIS._enter = wizchip_cris_enter; + WIZCHIP.CRIS._exit = wizchip_cris_exit; + } else { + WIZCHIP.CRIS._enter = cris_en; + WIZCHIP.CRIS._exit = cris_ex; + } +} + +void reg_wizchip_cs_cbfunc(void(*cs_sel)(void), void(*cs_desel)(void)) { + if (!cs_sel || !cs_desel) { + WIZCHIP.CS._select = wizchip_cs_select; + WIZCHIP.CS._deselect = wizchip_cs_deselect; + } else { + WIZCHIP.CS._select = cs_sel; + WIZCHIP.CS._deselect = cs_desel; + } +} + +//M20150515 : For integrating with W5300 +//void reg_wizchip_bus_cbfunc(uint8_t(*bus_rb)(uint32_t addr), void (*bus_wb)(uint32_t addr, uint8_t wb)) +void reg_wizchip_bus_cbfunc(iodata_t(*bus_rb)(uint32_t addr), void (*bus_wb)(uint32_t addr, iodata_t wb)) { + while (!(WIZCHIP.if_mode & _WIZCHIP_IO_MODE_BUS_)); + //M20150601 : Rename call back function for integrating with W5300 + /* + if(!bus_rb || !bus_wb) + { + WIZCHIP.IF.BUS._read_byte = wizchip_bus_readbyte; + WIZCHIP.IF.BUS._write_byte = wizchip_bus_writebyte; + } + else + { + WIZCHIP.IF.BUS._read_byte = bus_rb; + WIZCHIP.IF.BUS._write_byte = bus_wb; + } + */ + if (!bus_rb || !bus_wb) { + WIZCHIP.IF.BUS._read_data = wizchip_bus_readdata; + WIZCHIP.IF.BUS._write_data = wizchip_bus_writedata; + } else { + WIZCHIP.IF.BUS._read_data = bus_rb; + WIZCHIP.IF.BUS._write_data = bus_wb; + } +} +#if 1 +// 20231103 taylor +void reg_wizchip_busbuf_cbfunc(void(*busbuf_rb)(uint32_t AddrSel, iodata_t* pBuf, int16_t len, uint8_t addrinc), void (*busbuf_wb)(uint32_t AddrSel, iodata_t* pBuf, int16_t len, uint8_t addrinc)) { + while (!(WIZCHIP.if_mode & _WIZCHIP_IO_MODE_BUS_)); + //M20150601 : Rename call back function for integrating with W5300 + /* + if(!bus_rb || !bus_wb) + { + WIZCHIP.IF.BUS._read_byte = wizchip_bus_readbyte; + WIZCHIP.IF.BUS._write_byte = wizchip_bus_writebyte; + } + else + { + WIZCHIP.IF.BUS._read_byte = bus_rb; + WIZCHIP.IF.BUS._write_byte = bus_wb; + } + */ + if (!busbuf_rb || !busbuf_wb) { + WIZCHIP.IF.BUS._read_data_buf = wizchip_bus_read_buf; + WIZCHIP.IF.BUS._write_data_buf = wizchip_bus_write_buf; + } else { + WIZCHIP.IF.BUS._read_data_buf = busbuf_rb; + WIZCHIP.IF.BUS._write_data_buf = busbuf_wb; + } +} +#endif + +#if _WIZCHIP_ == W6100 + +void reg_wizchip_spi_cbfunc(uint8_t (*spi_rb)(void), + void (*spi_wb)(uint8_t wb), + void (*spi_rbuf)(uint8_t* buf, datasize_t len), + void (*spi_wbuf)(uint8_t* buf, datasize_t len)) { + while (!(WIZCHIP.if_mode & _WIZCHIP_IO_MODE_SPI_)); + + if (!spi_rb) { + WIZCHIP.IF.SPI._read_byte = wizchip_spi_readbyte; + } else { + WIZCHIP.IF.SPI._read_byte = spi_rb; + } + if (!spi_wb) { + WIZCHIP.IF.SPI._write_byte = wizchip_spi_writebyte; + } else { + WIZCHIP.IF.SPI._write_byte = spi_wb; + } + + if (!spi_rbuf) { + WIZCHIP.IF.SPI._read_burst = wizchip_spi_readburst; + } else { + WIZCHIP.IF.SPI._read_burst = spi_rbuf; + } + if (!spi_wbuf) { + WIZCHIP.IF.SPI._write_burst = wizchip_spi_writeburst; + } else { + WIZCHIP.IF.SPI._write_burst = spi_wbuf; + } +} +#else + +void reg_wizchip_spi_cbfunc(uint8_t (*spi_rb)(void), void (*spi_wb)(uint8_t wb)) { + while (!(WIZCHIP.if_mode & _WIZCHIP_IO_MODE_SPI_)); + + if (!spi_rb || !spi_wb) { + WIZCHIP.IF.SPI._read_byte = wizchip_spi_readbyte; + WIZCHIP.IF.SPI._write_byte = wizchip_spi_writebyte; + } else { + WIZCHIP.IF.SPI._read_byte = spi_rb; + WIZCHIP.IF.SPI._write_byte = spi_wb; + } +} +#endif + +// 20140626 Eric Added for SPI burst operations +void reg_wizchip_spiburst_cbfunc(void (*spi_rb)(uint8_t* pBuf, uint16_t len), void (*spi_wb)(uint8_t* pBuf, uint16_t len)) { + while (!(WIZCHIP.if_mode & _WIZCHIP_IO_MODE_SPI_)); + + if (!spi_rb || !spi_wb) { + WIZCHIP.IF.SPI._read_burst = wizchip_spi_readburst; + WIZCHIP.IF.SPI._write_burst = wizchip_spi_writeburst; + } else { + WIZCHIP.IF.SPI._read_burst = spi_rb; + WIZCHIP.IF.SPI._write_burst = spi_wb; + } +} +#if 1 //teddy 240122 +void reg_wizchip_qspi_cbfunc(void (*qspi_rb)(uint8_t opcode, uint16_t addr, uint8_t* pBuf, uint16_t len), + void (*qspi_wb)(uint8_t opcode, uint16_t addr, uint8_t* pBuf, uint16_t len)) { + while (!(WIZCHIP.if_mode & _WIZCHIP_IO_MODE_SPI_QSPI_)); + + if (!qspi_rb || !qspi_wb) { + WIZCHIP.IF.QSPI._read_qspi = wizchip_qspi_read; + WIZCHIP.IF.QSPI._write_qspi = wizchip_qspi_write; + } else { + WIZCHIP.IF.QSPI._read_qspi = qspi_rb; + WIZCHIP.IF.QSPI._write_qspi = qspi_wb; + } +} +#endif + +int8_t ctlwizchip(ctlwizchip_type cwtype, void* arg) { + //teddy 240122 +#if _WIZCHIP_ == W5100S || _WIZCHIP_ == W5200 || _WIZCHIP_ == W5500 || _WIZCHIP_ == W6100 || _WIZCHIP_ == W6300 + uint8_t tmp = *(uint8_t*) arg; +#endif + uint8_t* ptmp[2] = {0, 0}; + switch (cwtype) { + //teddy 240122 +#if _WIZCHIP_ == W6100 || _WIZCHIP_ == W6300 + case CW_SYS_LOCK: + if (tmp & SYS_CHIP_LOCK) { + CHIPLOCK(); + } + if (tmp & SYS_NET_LOCK) { + NETLOCK(); + } + if (tmp & SYS_PHY_LOCK) { + PHYLOCK(); + } + break; + case CW_SYS_UNLOCK: + if (tmp & SYS_CHIP_LOCK) { + CHIPUNLOCK(); + } + if (tmp & SYS_NET_LOCK) { + NETUNLOCK(); + } + if (tmp & SYS_PHY_LOCK) { + PHYUNLOCK(); + } + break; + case CW_GET_SYSLOCK: + *(uint8_t*)arg = getSYSR() >> 5; + break; +#endif + case CW_RESET_WIZCHIP: + wizchip_sw_reset(); + break; + case CW_INIT_WIZCHIP: + if (arg != 0) { + ptmp[0] = (uint8_t*)arg; + ptmp[1] = ptmp[0] + _WIZCHIP_SOCK_NUM_; + } + return wizchip_init(ptmp[0], ptmp[1]); + case CW_CLR_INTERRUPT: + wizchip_clrinterrupt(*((intr_kind*)arg)); + break; + case CW_GET_INTERRUPT: + *((intr_kind*)arg) = wizchip_getinterrupt(); + break; + case CW_SET_INTRMASK: + wizchip_setinterruptmask(*((intr_kind*)arg)); + break; + case CW_GET_INTRMASK: + *((intr_kind*)arg) = wizchip_getinterruptmask(); + break; + //M20150601 : This can be supported by W5200, W5500 + //#if _WIZCHIP_ > W5100 +#if (_WIZCHIP_ == W5200 || _WIZCHIP_ == W5500) + case CW_SET_INTRTIME: + setINTLEVEL(*(uint16_t*)arg); + break; + case CW_GET_INTRTIME: + *(uint16_t*)arg = getINTLEVEL(); + break; + //teddy 240122 +#elif ((_WIZCHIP_ == W6100) || (_WIZCHIP_ == W6300)) + case CW_SET_INTRTIME: + setINTPTMR(*(uint16_t*)arg); + break; + case CW_GET_INTRTIME: + *(uint16_t*)arg = getINTPTMR(); + break; +#endif + case CW_GET_ID: + ((uint8_t*)arg)[0] = WIZCHIP.id[0]; + ((uint8_t*)arg)[1] = WIZCHIP.id[1]; + ((uint8_t*)arg)[2] = WIZCHIP.id[2]; + ((uint8_t*)arg)[3] = WIZCHIP.id[3]; + ((uint8_t*)arg)[4] = WIZCHIP.id[4]; + ((uint8_t*)arg)[5] = WIZCHIP.id[5]; + ((uint8_t*)arg)[6] = 0; + break; +#if 1 + // 20231017 taylor//teddy 240122 +#if _WIZCHIP_ == W6100 || _WIZCHIP_ == W6300 + case CW_GET_VER: + *(uint16_t*)arg = getVER(); + break; +#endif +#endif + //teddy 240122 +#if _WIZCHIP_ == W5100S || _WIZCHIP_ == W5500 || _WIZCHIP_ == W6100 || _WIZCHIP_ == W6300 + case CW_RESET_PHY: + wizphy_reset(); + break; + case CW_SET_PHYCONF: + wizphy_setphyconf((wiz_PhyConf*)arg); + break; + case CW_GET_PHYCONF: + wizphy_getphyconf((wiz_PhyConf*)arg); + break; + case CW_GET_PHYSTATUS: +#if 1 + // 20231012 taylor +#if _WIZCHIP_ == W5500 + wizphy_getphystat((wiz_PhyConf*)arg); +#endif +#else + wizphy_getphystat((wiz_PhyConf*)arg); +#endif + break; + case CW_SET_PHYPOWMODE: + //teddy 240122 +#if _WIZCHIP_ == W6100 ||_WIZCHIP_ == W6300 + wizphy_setphypmode(*(uint8_t*)arg); + break; +#else + return wizphy_setphypmode(*(uint8_t*)arg); +#endif +#endif + //teddy 240122 +#if _WIZCHIP_ == W5100S || _WIZCHIP_ == W5200 || _WIZCHIP_ == W5500 || _WIZCHIP_ == W6100 || _WIZCHIP_ == W6300 + case CW_GET_PHYPOWMODE: + tmp = wizphy_getphypmode(); + if ((int8_t)tmp == -1) { + return -1; + } + *(uint8_t*)arg = tmp; + break; + case CW_GET_PHYLINK: + tmp = wizphy_getphylink(); + if ((int8_t)tmp == -1) { + return -1; + } + *(uint8_t*)arg = tmp; + break; +#endif + default: + return -1; + } + return 0; +} + + +int8_t ctlnetwork(ctlnetwork_type cntype, void* arg) { + + switch (cntype) { + case CN_SET_NETINFO: + wizchip_setnetinfo((wiz_NetInfo*)arg); + break; + case CN_GET_NETINFO: + wizchip_getnetinfo((wiz_NetInfo*)arg); + break; + case CN_SET_NETMODE: +#if (_WIZCHIP_ == W5100 || _WIZCHIP_ == W5100S || _WIZCHIP_ == W5200 || _WIZCHIP_ == W5300 || _WIZCHIP_ == W5500) + return wizchip_setnetmode(*(netmode_type*)arg); + //teddy 240122 +#elif ((_WIZCHIP_ == 6100)||(_WIZCHIP_ == W6300)) + wizchip_setnetmode(*(netmode_type*)arg); +#endif + case CN_GET_NETMODE: + *(netmode_type*)arg = wizchip_getnetmode(); + break; + case CN_SET_TIMEOUT: + wizchip_settimeout((wiz_NetTimeout*)arg); + break; + case CN_GET_TIMEOUT: + wizchip_gettimeout((wiz_NetTimeout*)arg); + break; + //teddy 240122 +#if ((_WIZCHIP_ == 6100)||(_WIZCHIP_ == 6300)) + case CN_SET_PREFER: + setSLPSR(*(uint8_t*)arg); + break; + case CN_GET_PREFER: + *(uint8_t*)arg = getSLPSR(); + break; +#endif + default: + return -1; + } + return 0; +} + +void wizchip_sw_reset(void) { + uint8_t gw[4], sn[4], sip[4]; + uint8_t mac[6]; + //teddy 240122 +#if ((_WIZCHIP_ == 6100) ||(_WIZCHIP_ == 6300)) + uint8_t gw6[16], sn6[16], lla[16], gua[16]; + uint8_t islock = getSYSR(); +#endif + +#if (_WIZCHIP_ == W5100 || _WIZCHIP_ == W5100S || _WIZCHIP_ == W5200 || _WIZCHIP_ == W5300 || _WIZCHIP_ == W5500) + //A20150601 +#if _WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_ + uint16_t mr = (uint16_t)getMR(); + setMR(mr | MR_IND); +#endif + // + getSHAR(mac); + getGAR(gw); getSUBR(sn); getSIPR(sip); + setMR(MR_RST); + getMR(); // for delay + //A2015051 : For indirect bus mode +#if _WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_ + setMR(mr | MR_IND); +#endif + // + setSHAR(mac); + setGAR(gw); + setSUBR(sn); + setSIPR(sip); + //teddy 240122 +#elif ((_WIZCHIP_ == W6100)||(_WIZCHIP_ == W6300)) + CHIPUNLOCK(); + + getSHAR(mac); + getGAR(gw); getSUBR(sn); getSIPR(sip); getGA6R(gw6); getSUB6R(sn6); getLLAR(lla); getGUAR(gua); + setSYCR0(SYCR0_RST); + getSYCR0(); // for delay + + NETUNLOCK(); + + setSHAR(mac); + setGAR(gw); + setSUBR(sn); + setSIPR(sip); + setGA6R(gw6); + setSUB6R(sn6); + setLLAR(lla); + setGUAR(gua); + if (islock & SYSR_CHPL) { + CHIPLOCK(); + } + if (islock & SYSR_NETL) { + NETLOCK(); + } +#endif +} + +int8_t wizchip_init(uint8_t* txsize, uint8_t* rxsize) { + int8_t i; +#if _WIZCHIP_ < W5200 + int8_t j; +#endif + int8_t tmp = 0; + wizchip_sw_reset(); + if (txsize) { + tmp = 0; + //M20150601 : For integrating with W5300 +#if _WIZCHIP_ == W5300 + for (i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++) { + if (txsize[i] > 64) { + return -1; //No use 64KB even if W5300 support max 64KB memory allocation + } + tmp += txsize[i]; + if (tmp > 128) { + return -1; + } + } + if (tmp % 8) { + return -1; + } +#else + for (i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++) { + tmp += txsize[i]; + +#if _WIZCHIP_ < W5200 //2016.10.28 peter add condition for w5100 and w5100s + if (tmp > 8) { + return -1; + } +#elif _WIZCHIP_ == W6300 + if (tmp > 32) { + return -1; + } +#else + if (tmp > 16) { + return -1; + } +#endif + } +#endif + for (i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++) { +#if _WIZCHIP_ < W5200 //2016.10.28 peter add condition for w5100 + j = 0; + while ((txsize[i] >> j != 1) && (txsize[i] != 0)) { + j++; + } + setSn_TXBUF_SIZE(i, j); +#else + setSn_TXBUF_SIZE(i, txsize[i]); +#endif + } + } + + if (rxsize) { + tmp = 0; +#if _WIZCHIP_ == W5300 + for (i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++) { + if (rxsize[i] > 64) { + return -1; //No use 64KB even if W5300 support max 64KB memory allocation + } + tmp += rxsize[i]; + if (tmp > 128) { + return -1; + } + } + if (tmp % 8) { + return -1; + } +#else + for (i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++) { + tmp += rxsize[i]; +#if _WIZCHIP_ < W5200 //2016.10.28 peter add condition for w5100 and w5100s + if (tmp > 8) { + return -1; + } +#elif _WIZCHIP_ == W6300 + if (tmp > 32) { + return -1; + } +#else + if (tmp > 16) { + return -1; + } +#endif + } +#endif + for (i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++) { +#if _WIZCHIP_ < W5200 // add condition for w5100 + j = 0; + while ((rxsize[i] >> j != 1) && (txsize[i] != 0)) { + j++; + } + setSn_RXBUF_SIZE(i, j); +#else + setSn_RXBUF_SIZE(i, rxsize[i]); +#endif + } + } + return 0; +} + +void wizchip_clrinterrupt(intr_kind intr) { + uint8_t ir = (uint8_t)intr; + uint8_t sir = (uint8_t)((uint16_t)intr >> 8); + + //teddy 240122 +#if _WIZCHIP_ == W6100 || _WIZCHIP_ == W6300 + int i; + uint8_t slir = (uint8_t)((uint32_t)intr >> 16); + setIRCLR(ir); + for (i = 0; i < _WIZCHIP_SOCK_NUM_; i++) { + if (sir & (1 << i)) { + setSn_IRCLR(i, 0xFF); + } + } + setSLIRCLR(slir); + return; +#endif + +#if _WIZCHIP_ < W5500 + ir |= (1 << 4); // IK_WOL +#endif +#if _WIZCHIP_ == W5200 + ir |= (1 << 6); +#endif + +#if _WIZCHIP_ < W5200 + sir &= 0x0F; +#endif + +#if _WIZCHIP_ <= W5100S + ir |= sir; + setIR(ir); + //A20150601 : For integrating with W5300 +#elif _WIZCHIP_ == W5300 + setIR(((((uint16_t)ir) << 8) | (((uint16_t)sir) & 0x00FF))); +#else + setIR(ir); + //M20200227 : For clear + //setSIR(sir); + for (ir = 0; ir < 8; ir++) { + if (sir & (0x01 << ir)) { + setSn_IR(ir, 0xff); + } + } + +#endif +} + +intr_kind wizchip_getinterrupt(void) { + uint8_t ir = 0; + uint8_t sir = 0; + uint32_t ret = 0; + +#if _WIZCHIP_ <= W5100S + ir = getIR(); + sir = ir & 0x0F; + //A20150601 : For integrating with W5300 +#elif _WIZCHIP_ == W5300 + ret = getIR(); + ir = (uint8_t)(ret >> 8); + sir = (uint8_t)ret; +#else + ir = getIR(); + sir = getSIR(); +#endif + + //M20150601 : For Integrating with W5300 + //#if _WIZCHIP_ < W5500 +#if _WIZCHIP_ < W5200 + ir &= ~(1 << 4); // IK_WOL +#endif +#if _WIZCHIP_ == W5200 + ir &= ~(1 << 6); +#endif + ret = sir; + ret = (ret << 8) + ir; + //teddy 240122 +#if _WIZCHIP_ == W6100 || _WIZCHIP_ == W6300 + ret = (((uint32_t)getSLIR()) << 16) | ret; +#endif + + return (intr_kind)ret; +} + +void wizchip_setinterruptmask(intr_kind intr) { + uint8_t imr = (uint8_t)intr; + uint8_t simr = (uint8_t)((uint16_t)intr >> 8); +#if _WIZCHIP_ < W5500 + imr &= ~(1 << 4); // IK_WOL +#endif +#if _WIZCHIP_ == W5200 + imr &= ~(1 << 6); +#endif + +#if _WIZCHIP_ < W5200 + simr &= 0x0F; + imr |= simr; + setIMR(imr); + //A20150601 : For integrating with W5300 +#elif _WIZCHIP_ == W5300 + setIMR(((((uint16_t)imr) << 8) | (((uint16_t)simr) & 0x00FF))); +#else + setIMR(imr); + setSIMR(simr); + //teddy 240122 +#if _WIZCHIP_ == W6100 || _WIZCHIP_ == W6300 + uint8_t slimr = (uint8_t)((uint32_t)intr >> 16); + setSLIMR(slimr); +#endif +#endif +} + +intr_kind wizchip_getinterruptmask(void) { + uint8_t imr = 0; + uint8_t simr = 0; + uint32_t ret = 0; +#if _WIZCHIP_ < W5200 + imr = getIMR(); + simr = imr & 0x0F; + //A20150601 : For integrating with W5300 +#elif _WIZCHIP_ == W5300 + ret = getIMR(); + imr = (uint8_t)(ret >> 8); + simr = (uint8_t)ret; +#else + imr = getIMR(); + simr = getSIMR(); +#endif + +#if _WIZCHIP_ < W5500 + imr &= ~(1 << 4); // IK_WOL +#endif +#if _WIZCHIP_ == W5200 + imr &= ~(1 << 6); // IK_DEST_UNREACH +#endif + ret = simr; + ret = (ret << 8) + imr; + + //teddy 240122 +#if _WIZCHIP_ == W6100 || _WIZCHIP_ == W6300 + ret = (((uint32_t)getSLIMR()) << 16) | ret; +#endif + + return (intr_kind)ret; +} + +int8_t wizphy_getphylink(void) { + int8_t tmp = PHY_LINK_OFF; +#if _WIZCHIP_ == W5100S + if (getPHYSR() & PHYSR_LNK) { + tmp = PHY_LINK_ON; + } +#elif _WIZCHIP_ == W5200 + if (getPHYSTATUS() & PHYSTATUS_LINK) { + tmp = PHY_LINK_ON; + } +#elif _WIZCHIP_ == W5500 + if (getPHYCFGR() & PHYCFGR_LNK_ON) { + tmp = PHY_LINK_ON; + } + +#elif ((_WIZCHIP_ == W6100)||(_WIZCHIP_ == W6300)) + +#if (_PHY_IO_MODE_ == _PHY_IO_MODE_PHYCR_) + return (getPHYSR() & PHYSR_LNK); +#elif (_PHY_IO_MODE_ == _PHY_IO_MODE_MII_) + if (wiz_mdio_read(PHYRAR_BMSR) & BMSR_LINK_STATUS) { + return PHY_LINK_ON; + } + return PHY_LINK_OFF; +#endif + +#else + tmp = -1; +#endif + return tmp; +} + +#if _WIZCHIP_ > W5100 + +int8_t wizphy_getphypmode(void) { + int8_t tmp = 0; +#if _WIZCHIP_ == W5200 + if (getPHYSTATUS() & PHYSTATUS_POWERDOWN) { + tmp = PHY_POWER_DOWN; + } else { + tmp = PHY_POWER_NORM; + } +#elif _WIZCHIP_ == 5500 + if ((getPHYCFGR() & PHYCFGR_OPMDC_ALLA) == PHYCFGR_OPMDC_PDOWN) { + tmp = PHY_POWER_DOWN; + } else { + tmp = PHY_POWER_NORM; + } + //teddy 240122 +#elif _WIZCHIP_ == W6100 || _WIZCHIP_ == W6300 +#if (_PHY_IO_MODE_ == _PHY_IO_MODE_PHYCR_) + if (getPHYCR1() & PHYCR1_PWDN) { + return PHY_POWER_DOWN; + } +#elif (_PHY_IO_MODE_ == _PHY_IO_MODE_MII_) + if (wiz_mdio_read(PHYRAR_BMCR) & BMCR_PWDN) { + return PHY_POWER_DOWN; + } +#endif + return PHY_POWER_NORM; +#else + tmp = -1; +#endif + return tmp; +} +#endif + +#if _WIZCHIP_ == W5100S +void wizphy_reset(void) { + uint16_t tmp = wiz_mdio_read(PHYMDIO_BMCR); + tmp |= BMCR_RESET; + wiz_mdio_write(PHYMDIO_BMCR, tmp); + while (wiz_mdio_read(PHYMDIO_BMCR)&BMCR_RESET) {} +} + +void wizphy_setphyconf(wiz_PhyConf* phyconf) { + uint16_t tmp = wiz_mdio_read(PHYMDIO_BMCR); + if (phyconf->mode == PHY_MODE_AUTONEGO) { + tmp |= BMCR_AUTONEGO; + } else { + tmp &= ~BMCR_AUTONEGO; + if (phyconf->duplex == PHY_DUPLEX_FULL) { + tmp |= BMCR_DUP; + } else { + tmp &= ~BMCR_DUP; + } + if (phyconf->speed == PHY_SPEED_100) { + tmp |= BMCR_SPEED; + } else { + tmp &= ~BMCR_SPEED; + } + } + wiz_mdio_write(PHYMDIO_BMCR, tmp); +} + +void wizphy_getphyconf(wiz_PhyConf* phyconf) { + uint16_t tmp = 0; + tmp = wiz_mdio_read(PHYMDIO_BMCR); + phyconf->by = PHY_CONFBY_SW; + if (tmp & BMCR_AUTONEGO) { + phyconf->mode = PHY_MODE_AUTONEGO; + } else { + phyconf->mode = PHY_MODE_MANUAL; + if (tmp & BMCR_DUP) { + phyconf->duplex = PHY_DUPLEX_FULL; + } else { + phyconf->duplex = PHY_DUPLEX_HALF; + } + if (tmp & BMCR_SPEED) { + phyconf->speed = PHY_SPEED_100; + } else { + phyconf->speed = PHY_SPEED_10; + } + } +} + +int8_t wizphy_setphypmode(uint8_t pmode) { + uint16_t tmp = 0; + tmp = wiz_mdio_read(PHYMDIO_BMCR); + if (pmode == PHY_POWER_DOWN) { + tmp |= BMCR_PWDN; + } else { + tmp &= ~BMCR_PWDN; + } + wiz_mdio_write(PHYMDIO_BMCR, tmp); + tmp = wiz_mdio_read(PHYMDIO_BMCR); + if (pmode == PHY_POWER_DOWN) { + if (tmp & BMCR_PWDN) { + return 0; + } + } else { + if ((tmp & BMCR_PWDN) != BMCR_PWDN) { + return 0; + } + } + return -1; +} + +#elif _WIZCHIP_ == W5500 +void wizphy_reset(void) { + uint8_t tmp = getPHYCFGR(); + tmp &= PHYCFGR_RST; + setPHYCFGR(tmp); + tmp = getPHYCFGR(); + tmp |= ~PHYCFGR_RST; + setPHYCFGR(tmp); +} + +void wizphy_setphyconf(wiz_PhyConf* phyconf) { + uint8_t tmp = 0; + if (phyconf->by == PHY_CONFBY_SW) { + tmp |= PHYCFGR_OPMD; + } else { + tmp &= ~PHYCFGR_OPMD; + } + if (phyconf->mode == PHY_MODE_AUTONEGO) { + tmp |= PHYCFGR_OPMDC_ALLA; + } else { + if (phyconf->duplex == PHY_DUPLEX_FULL) { + if (phyconf->speed == PHY_SPEED_100) { + tmp |= PHYCFGR_OPMDC_100F; + } else { + tmp |= PHYCFGR_OPMDC_10F; + } + } else { + if (phyconf->speed == PHY_SPEED_100) { + tmp |= PHYCFGR_OPMDC_100H; + } else { + tmp |= PHYCFGR_OPMDC_10H; + } + } + } + setPHYCFGR(tmp); + wizphy_reset(); +} + +void wizphy_getphyconf(wiz_PhyConf* phyconf) { + uint8_t tmp = 0; + tmp = getPHYCFGR(); + phyconf->by = (tmp & PHYCFGR_OPMD) ? PHY_CONFBY_SW : PHY_CONFBY_HW; + switch (tmp & PHYCFGR_OPMDC_ALLA) { + case PHYCFGR_OPMDC_ALLA: + case PHYCFGR_OPMDC_100FA: + phyconf->mode = PHY_MODE_AUTONEGO; + break; + default: + phyconf->mode = PHY_MODE_MANUAL; + break; + } + switch (tmp & PHYCFGR_OPMDC_ALLA) { + case PHYCFGR_OPMDC_100FA: + case PHYCFGR_OPMDC_100F: + case PHYCFGR_OPMDC_100H: + phyconf->speed = PHY_SPEED_100; + break; + default: + phyconf->speed = PHY_SPEED_10; + break; + } + switch (tmp & PHYCFGR_OPMDC_ALLA) { + case PHYCFGR_OPMDC_100FA: + case PHYCFGR_OPMDC_100F: + case PHYCFGR_OPMDC_10F: + phyconf->duplex = PHY_DUPLEX_FULL; + break; + default: + phyconf->duplex = PHY_DUPLEX_HALF; + break; + } +} + +void wizphy_getphystat(wiz_PhyConf* phyconf) { + uint8_t tmp = getPHYCFGR(); + phyconf->duplex = (tmp & PHYCFGR_DPX_FULL) ? PHY_DUPLEX_FULL : PHY_DUPLEX_HALF; + phyconf->speed = (tmp & PHYCFGR_SPD_100) ? PHY_SPEED_100 : PHY_SPEED_10; +} + +int8_t wizphy_setphypmode(uint8_t pmode) { + uint8_t tmp = 0; + tmp = getPHYCFGR(); + if ((tmp & PHYCFGR_OPMD) == 0) { + return -1; + } + tmp &= ~PHYCFGR_OPMDC_ALLA; + if (pmode == PHY_POWER_DOWN) { + tmp |= PHYCFGR_OPMDC_PDOWN; + } else { + tmp |= PHYCFGR_OPMDC_ALLA; + } + setPHYCFGR(tmp); + wizphy_reset(); + tmp = getPHYCFGR(); + if (pmode == PHY_POWER_DOWN) { + if (tmp & PHYCFGR_OPMDC_PDOWN) { + return 0; + } + } else { + if (tmp & PHYCFGR_OPMDC_ALLA) { + return 0; + } + } + return -1; +} + +//teddy 240122 +#elif _WIZCHIP_ == W6100 || _WIZCHIP_ == W6300 +void wizphy_reset(void) { +#if (_PHY_IO_MODE_ == _PHY_IO_MODE_PHYCR_) + uint8_t tmp = getPHYCR1() | PHYCR1_RST; + PHYUNLOCK(); + setPHYCR1(tmp); + PHYLOCK(); +#elif (_PHY_IO_MODE_ == _PHY_IO_MODE_MII_) + wiz_mdio_write(PHYRAR_BMCR, wiz_mdio_read(PHYRAR_BMCR) | BMCR_RST); + while (wiz_mdio_read(PHYRAR_BMCR) & BMCR_RST); +#endif +} + +void wizphy_setphyconf(wiz_PhyConf* phyconf) { +#if (_PHY_IO_MODE_ == _PHY_IO_MODE_PHYCR_) + uint8_t tmp = 0; + if (phyconf->mode == PHY_MODE_TE) { + setPHYCR1(getPHYCR1() | PHYCR1_TE); + tmp = PHYCR0_AUTO; + } else { + setPHYCR1(getPHYCR1() & ~PHYCR1_TE); + if (phyconf->mode == PHY_MODE_AUTONEGO) { + tmp = PHYCR0_AUTO; + } else { + tmp |= 0x04; + if (phyconf->speed == PHY_SPEED_10) { + tmp |= 0x02; + } + if (phyconf->duplex == PHY_DUPLEX_HALF) { + tmp |= 0x01; + } + } + } + setPHYCR0(tmp); +#elif (_PHY_IO_MODE_ == _PHY_IO_MODE_MII_) + uint16_t tmp = wiz_mdio_read(PHYRAR_BMCR); + if (phyconf->mode == PHY_MODE_TE) { + setPHYCR1(getPHYCR1() | PHYCR1_TE); + setPHYCR0(PHYCR0_AUTO); + } else { + setPHYCR1(getPHYCR1() & ~PHYCR1_TE); + if (phyconf->mode == PHY_MODE_AUTONEGO) { + tmp |= BMCR_ANE; + } else { + tmp &= ~(BMCR_ANE | BMCR_DPX | BMCR_SPD); + if (phyconf->duplex == PHY_DUPLEX_FULL) { + tmp |= BMCR_DPX; + } + if (phyconf->speed == PHY_SPEED_100) { + tmp |= BMCR_SPD; + } + } + wiz_mdio_write(PHYRAR_BMCR, tmp); + } +#endif +} + +void wizphy_getphyconf(wiz_PhyConf* phyconf) { +#if (_PHY_IO_MODE_ == _PHY_IO_MODE_PHYCR_) + uint8_t tmp = 0; + tmp = getPHYSR(); + if (getPHYCR1() & PHYCR1_TE) { + phyconf->mode = PHY_MODE_TE; + } else { + phyconf->mode = (tmp & (1 << 5)) ? PHY_MODE_MANUAL : PHY_MODE_AUTONEGO ; + } + phyconf->speed = (tmp & (1 << 4)) ? PHY_SPEED_10 : PHY_SPEED_100; + phyconf->duplex = (tmp & (1 << 3)) ? PHY_DUPLEX_HALF : PHY_DUPLEX_FULL; +#elif (_PHY_IO_MODE_ == _PHY_IO_MODE_MII_) + uint16_t tmp = 0; + tmp = wiz_mdio_read(PHYRAR_BMCR); + if (getPHYCR1() & PHYCR1_TE) { + phyconf->mode = PHY_MODE_TE; + } else { + phyconf->mode = (tmp & BMCR_ANE) ? PHY_MODE_AUTONEGO : PHY_MODE_MANUAL; + } + phyconf->duplex = (tmp & BMCR_DPX) ? PHY_DUPLEX_FULL : PHY_DUPLEX_HALF; + phyconf->speed = (tmp & BMCR_SPD) ? PHY_SPEED_100 : PHY_SPEED_10; +#endif +} + +void wizphy_getphystat(wiz_PhyConf* phyconf) { + uint8_t tmp = 0; + tmp = getPHYSR(); + if (getPHYCR1() & PHYCR1_TE) { + phyconf->mode = PHY_MODE_TE; + } else { + phyconf->mode = (tmp & (1 << 5)) ? PHY_MODE_MANUAL : PHY_MODE_AUTONEGO ; + } + phyconf->speed = (tmp & PHYSR_SPD) ? PHY_SPEED_10 : PHY_SPEED_100; + phyconf->duplex = (tmp & PHYSR_DPX) ? PHY_DUPLEX_HALF : PHY_DUPLEX_FULL; +} + +void wizphy_setphypmode(uint8_t pmode) { +#if (_PHY_IO_MODE_ == _PHY_IO_MODE_PHYCR_) + uint8_t tmp = getPHYCR1(); + if (pmode == PHY_POWER_DOWN) { + tmp |= PHYCR1_PWDN; + } else { + tmp &= ~PHYCR1_PWDN; + } + setPHYCR1(tmp); +#elif (_PHY_IO_MODE_ == _PHY_IO_MODE_MII_) + uint16_t tmp = 0; + tmp = wiz_mdio_read(PHYRAR_BMCR); + if (pmode == PHY_POWER_DOWN) { + tmp |= BMCR_PWDN; + } else { + tmp &= ~BMCR_PWDN; + } + wiz_mdio_write(PHYRAR_BMCR, tmp); +#endif +} + +int8_t wizchip_arp(wiz_ARP* arp) { + uint8_t tmp; + if (arp->destinfo.len == 16) { + setSLDIP6R(arp->destinfo.ip); + setSLCR(SLCR_ARP6); + } else { + setSLDIP4R(arp->destinfo.ip); + setSLCR(SLCR_ARP4); + } + while (getSLCR()); + while ((tmp = getSLIR()) == 0x00); + setSLIRCLR(~SLIR_RA); + if (tmp & (SLIR_ARP4 | SLIR_ARP6)) { + getSLDHAR(arp->dha); + return 0; + } + return -1; +} + +int8_t wizchip_ping(wiz_PING* ping) { + uint8_t tmp; + setPINGIDR(ping->id); + setPINGSEQR(ping->seq); + if (ping->destinfo.len == 16) { + setSLDIP6R(ping->destinfo.ip); + setSLCR(SLCR_PING6); + } else { + setSLDIP4R(ping->destinfo.ip); + setSLCR(SLCR_PING4); + } + while (getSLCR()); + while ((tmp = getSLIR()) == 0x00); + setSLIRCLR(~SLIR_RA); + if (tmp & (SLIR_PING4 | SLIR_PING6)) { + return 0; + } + return -1; +} + +int8_t wizchip_dad(uint8_t* ipv6) { + uint8_t tmp; + setSLDIP6R(ipv6); + setSLCR(SLCR_NS); + while (getSLCR()); + while ((tmp = getSLIR()) == 0x00); + setSLIRCLR(~SLIR_RA); + if (tmp & SLIR_TOUT) { + return 0; + } + return -1; +} + +int8_t wizchip_slaac(wiz_Prefix* prefix) { + uint8_t tmp; + setSLCR(SLCR_RS); + while (getSLCR()); + while ((tmp = getSLIR()) == 0x00); + setSLIRCLR(~SLIR_RA); + if (tmp & SLIR_RS) { + prefix->len = getPLR(); + prefix->flag = getPFR(); + prefix->valid_lifetime = getVLTR(); + prefix->preferred_lifetime = getPLTR(); + getPAR(prefix->prefix); + return 0; + } + return -1; +} + +int8_t wizchip_unsolicited(void) { + uint8_t tmp; + setSLCR(SLCR_UNA); + while (getSLCR()); + while ((tmp = getSLIR()) == 0x00); + setSLIRCLR(~SLIR_RA); + if (tmp & SLIR_TOUT) { + return 0; + } + return -1; +} + +int8_t wizchip_getprefix(wiz_Prefix * prefix) { + if (getSLIR() & SLIR_RA) { + prefix->len = getPLR(); + prefix->flag = getPFR(); + prefix->valid_lifetime = getVLTR(); + prefix->preferred_lifetime = getPLTR(); + getPAR(prefix->prefix); + setSLIRCLR(SLIR_RA); + } + return -1; +} + + +#endif + +#if (_WIZCHIP_ == W5100 || _WIZCHIP_ == W5100S || _WIZCHIP_ == W5200 || _WIZCHIP_ == W5300 || _WIZCHIP_ == W5500) +void wizchip_setnetinfo(wiz_NetInfo* pnetinfo) { + setSHAR(pnetinfo->mac); + setGAR(pnetinfo->gw); + setSUBR(pnetinfo->sn); + setSIPR(pnetinfo->ip); + _DNS_[0] = pnetinfo->dns[0]; + _DNS_[1] = pnetinfo->dns[1]; + _DNS_[2] = pnetinfo->dns[2]; + _DNS_[3] = pnetinfo->dns[3]; + _DHCP_ = pnetinfo->dhcp; +} + +void wizchip_getnetinfo(wiz_NetInfo* pnetinfo) { + getSHAR(pnetinfo->mac); + getGAR(pnetinfo->gw); + getSUBR(pnetinfo->sn); + getSIPR(pnetinfo->ip); + pnetinfo->dns[0] = _DNS_[0]; + pnetinfo->dns[1] = _DNS_[1]; + pnetinfo->dns[2] = _DNS_[2]; + pnetinfo->dns[3] = _DNS_[3]; + pnetinfo->dhcp = _DHCP_; +} + +int8_t wizchip_setnetmode(netmode_type netmode) { + uint8_t tmp = 0; +#if _WIZCHIP_ != W5500 + if (netmode & ~(NM_WAKEONLAN | NM_PPPOE | NM_PINGBLOCK)) { + return -1; + } +#else + if (netmode & ~(NM_WAKEONLAN | NM_PPPOE | NM_PINGBLOCK | NM_FORCEARP)) { + return -1; + } +#endif + tmp = getMR(); + tmp |= (uint8_t)netmode; + setMR(tmp); + return 0; +} + +netmode_type wizchip_getnetmode(void) { + return (netmode_type) getMR(); +} + +void wizchip_settimeout(wiz_NetTimeout* nettime) { + setRCR(nettime->retry_cnt); + setRTR(nettime->time_100us); +} + +void wizchip_gettimeout(wiz_NetTimeout* nettime) { + nettime->retry_cnt = getRCR(); + nettime->time_100us = getRTR(); +} +//teddy 240122 +#elif ((_WIZCHIP_ == 6100) ||(_WIZCHIP_ == 6300)) +void wizchip_setnetinfo(wiz_NetInfo* pnetinfo) { + uint8_t i = 0; + setSHAR(pnetinfo->mac); + setGAR(pnetinfo->gw); + setSUBR(pnetinfo->sn); + setSIPR(pnetinfo->ip); + setGA6R(pnetinfo->gw6); + setSUB6R(pnetinfo->sn6); + setLLAR(pnetinfo->lla); + setGUAR(pnetinfo->gua); + + for (i = 0; i < 4; i++) { + _DNS_[i] = pnetinfo->dns[i]; + } + for (i = 0; i < 16; i++) { + _DNS6_[i] = pnetinfo->dns6[i]; + } + + _IPMODE_ = pnetinfo->ipmode; +} + +void wizchip_getnetinfo(wiz_NetInfo* pnetinfo) { + uint8_t i = 0; + getSHAR(pnetinfo->mac); + + getGAR(pnetinfo->gw); + getSUBR(pnetinfo->sn); + getSIPR(pnetinfo->ip); + + getGA6R(pnetinfo->gw6); + getSUB6R(pnetinfo->sn6); + getLLAR(pnetinfo->lla); + getGUAR(pnetinfo->gua); + for (i = 0; i < 4; i++) { + pnetinfo->dns[i] = _DNS_[i]; + } + for (i = 0; i < 16; i++) { + pnetinfo->dns6[i] = _DNS6_[i]; + } + + pnetinfo->ipmode = _IPMODE_; +} + +void wizchip_setnetmode(netmode_type netmode) { + uint32_t tmp = (uint32_t) netmode; + setNETMR((uint8_t)tmp); + setNETMR2((uint8_t)(tmp >> 8)); + setNET4MR((uint8_t)(tmp >> 16)); + setNET6MR((uint8_t)(tmp >> 24)); +} + +netmode_type wizchip_getnetmode(void) { + uint32_t ret = 0; + ret = getNETMR(); + ret = (ret << 8) + getNETMR2(); + ret = (ret << 16) + getNET4MR(); + ret = (ret << 24) + getNET6MR(); + return (netmode_type)ret; +} + +// netmode_type wizchip_getnetmode(void) +// { +// return (netmode_type) getMR(); +// } + +void wizchip_settimeout(wiz_NetTimeout* nettime) { + setRCR(nettime->s_retry_cnt); + setRTR(nettime->s_time_100us); + setSLRCR(nettime->sl_retry_cnt); + setSLRTR(nettime->sl_time_100us); +} + +void wizchip_gettimeout(wiz_NetTimeout* nettime) { + nettime->s_retry_cnt = getRCR(); + nettime->s_time_100us = getRTR(); + nettime->sl_retry_cnt = getSLRCR(); + nettime->sl_time_100us = getSLRTR(); +} +#endif + diff --git a/Ethernet/wizchip_conf.h b/Ethernet/wizchip_conf.h new file mode 100644 index 0000000..1bea81a --- /dev/null +++ b/Ethernet/wizchip_conf.h @@ -0,0 +1,1348 @@ +//***************************************************************************** +// +//! \file wizchip_conf.h +//! \brief WIZCHIP Config Header File. +//! \version 1.0.0 +//! \date 2013/10/21 +//! \par Revision history +//! <2015/02/05> Notice +//! The version history is not updated after this point. +//! Download the latest version directly from GitHub. Please visit the our GitHub repository for ioLibrary. +//! >> https://github.com/Wiznet/ioLibrary_Driver +//! <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. +// +//***************************************************************************** + +/** + @defgroup extra_functions 2. WIZnet Extra Functions + + @brief These functions is optional function. It could be replaced at WIZCHIP I/O function because they were made by WIZCHIP I/O functions. + @details There are functions of configuring WIZCHIP, network, interrupt, phy, network information and timer. \n + +*/ + +#ifndef _WIZCHIP_CONF_H_ +#define _WIZCHIP_CONF_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +/** + @brief Select WIZCHIP. + @todo You should select one, \b W5100, \b W5100S, \b W5200, \b W5300, \b W5500 or etc. \n\n + ex> #define \_WIZCHIP_ W5500 +*/ + +#define W5100 5100 +#define W5100S 5100+5 +#define W5200 5200 +#define W5300 5300 +#define W5500 5500 +#define W6100 6100 +#define W6300 6300 + + +#ifndef _WIZCHIP_ +// NOTE_LIHAN: Some sections of this code are not yet fully defined. +#define _WIZCHIP_ W6300 // W5100, W5100S, W5200, W5300, W5500, 6300 +#endif + +// +//#ifndef _WIZCHIP_ +// #error please Define your WIZnet chip numer +//#endif + + +#define _WIZCHIP_IO_MODE_NONE_ 0x0000 +#define _WIZCHIP_IO_MODE_BUS_ 0x0100 /**< Bus interface mode */ +#define _WIZCHIP_IO_MODE_SPI_ 0x0200 /**< SPI interface mode */ +//#define _WIZCHIP_IO_MODE_IIC_ 0x0400 +//#define _WIZCHIP_IO_MODE_SDIO_ 0x0800 +// Add to +// + +#define _WIZCHIP_IO_MODE_BUS_DIR_ (_WIZCHIP_IO_MODE_BUS_ + 1) /**< BUS interface mode for direct */ +#define _WIZCHIP_IO_MODE_BUS_INDIR_ (_WIZCHIP_IO_MODE_BUS_ + 2) /**< BUS interface mode for indirect */ + +#define _WIZCHIP_IO_MODE_SPI_VDM_ (_WIZCHIP_IO_MODE_SPI_ + 1) /**< SPI interface mode for variable length data*/ +#define _WIZCHIP_IO_MODE_SPI_FDM_ (_WIZCHIP_IO_MODE_SPI_ + 2) /**< SPI interface mode for fixed length data mode*/ +#define _WIZCHIP_IO_MODE_SPI_5500_ (_WIZCHIP_IO_MODE_SPI_ + 3) /**< SPI interface mode for fixed length data mode*/ +//teddy 240122 +#define _WIZCHIP_IO_MODE_SPI_QSPI_ (_WIZCHIP_IO_MODE_SPI_ + 4) /**< SPI interface mode for QSPI mode*/ + + + +/** + @brief PHY can be accessed by @ref _PHYCR0_, _PHYCR1_. + @details It provides hardware access method. + @note It is smaller s/w footprint than @ref _PHY_IO_MODE_MII_. + @sa _PHY_IO_MODE_MII_, _PHY_IO_MODE_ + @sa ctlwizchip(), getPHYCR0(), getPHYCR1(), setPHYCR1(), getPHYSR() +*/ +#define _PHY_IO_MODE_PHYCR_ 0x0000 + +/** + @brief PHY can be accessed by MDC/MDIO signals of MII interface. + @details It provide software access method. + @note It is bigger s/w footprint than @ref _PHY_IO_MODE_PHYCR_. + @sa _PHY_IO_MODE_PHYCR_, _PHY_IO_MODE_ + @sa ctlwizchip(), wiz_read_mdio(), wiz_write_mdio() +*/ +#define _PHY_IO_MODE_MII_ 0x0010 + +/** + @brief Select PHY Access Mode + @details @ref _PHY_IO_MODE_ selects PHY access method. + @todo You should select one of @ref _PHY_IO_MODE_PHYCR_ or @ref _PHY_IO_MODE_MII_. + @sa ctlwizchip() +*/ +#define _PHY_IO_MODE_ _PHY_IO_MODE_MII_ //_PHY_IO_MODE_MII_ + + + +#if (_WIZCHIP_ == W5100) +#define _WIZCHIP_ID_ "W5100\0" +/** + @brief Define interface mode. + @todo you should select interface mode as chip. Select one of @ref \_WIZCHIP_IO_MODE_SPI_ , @ref \_WIZCHIP_IO_MODE_BUS_DIR_ or @ref \_WIZCHIP_IO_MODE_BUS_INDIR_ +*/ +// #define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_BUS_DIR_ +// #define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_BUS_INDIR_ +#define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_SPI_ + +//A20150601 : Define the unit of IO DATA. +typedef uint8_t iodata_t; +//A20150401 : Indclude W5100.h file +#include "W5100/w5100.h" + +#elif (_WIZCHIP_ == W5100S) +#define _WIZCHIP_ID_ "W5100S\0" +/** + @brief Define interface mode. + @todo you should select interface mode as chip. Select one of @ref \_WIZCHIP_IO_MODE_SPI_ , @ref \_WIZCHIP_IO_MODE_BUS_DIR_ or @ref \_WIZCHIP_IO_MODE_BUS_INDIR_ +*/ +#if 0 +#define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_BUS_INDIR_ +#elif 0 +#define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_SPI_5500_ +#else +#define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_SPI_ +#endif + +//A20150601 : Define the unit of IO DATA. +typedef uint8_t iodata_t; +//A20150401 : Indclude W5100.h file +#include "W5100S/w5100s.h" +#elif (_WIZCHIP_ == W5200) +#define _WIZCHIP_ID_ "W5200\0" +/** + @brief Define interface mode. + @todo you should select interface mode as chip. Select one of @ref \_WIZCHIP_IO_MODE_SPI_ or @ref \ _WIZCHIP_IO_MODE_BUS_INDIR_ +*/ +#ifndef _WIZCHIP_IO_MODE_ +// #define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_BUS_INDIR_ +#define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_SPI_ +#endif +//A20150601 : Define the unit of IO DATA. +typedef uint8_t iodata_t; +#include "W5200/w5200.h" +#elif (_WIZCHIP_ == W5500) +#define _WIZCHIP_ID_ "W5500\0" + +/** + @brief Define interface mode. \n + @todo Should select interface mode as chip. + - @ref \_WIZCHIP_IO_MODE_SPI_ \n + -@ref \_WIZCHIP_IO_MODE_SPI_VDM_ : Valid only in @ref \_WIZCHIP_ == W5500 \n + -@ref \_WIZCHIP_IO_MODE_SPI_FDM_ : Valid only in @ref \_WIZCHIP_ == W5500 \n + - @ref \_WIZCHIP_IO_MODE_BUS_ \n + - @ref \_WIZCHIP_IO_MODE_BUS_DIR_ \n + - @ref \_WIZCHIP_IO_MODE_BUS_INDIR_ \n + - Others will be defined in future. \n\n + ex> #define \_WIZCHIP_IO_MODE_ \_WIZCHIP_IO_MODE_SPI_VDM_ + +*/ +#ifndef _WIZCHIP_IO_MODE_ +//#define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_SPI_FDM_ +#define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_SPI_ +#endif +//A20150601 : Define the unit of IO DATA. +typedef uint8_t iodata_t; +#include "W5500/w5500.h" +#elif ( _WIZCHIP_ == W5300) +#define _WIZCHIP_ID_ "W5300\0" +/** + @brief Define interface mode. + @todo you should select interface mode as chip. Select one of @ref \_WIZCHIP_IO_MODE_SPI_ , @ref \_WIZCHIP_IO_MODE_BUS_DIR_ or @ref \_WIZCHIP_IO_MODE_BUS_INDIR_ +*/ +#ifndef _WIZCHIP_IO_MODE_ +#define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_BUS_DIR_ +// #define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_BUS_INDIR_ +#endif + +//A20150601 : Define the unit and bus width of IO DATA. +/** + @brief Select the data width 8 or 16 bits. + @todo you should select the bus width. Select one of 8 or 16. +*/ +#ifndef _WIZCHIP_IO_BUS_WIDTH_ +#define _WIZCHIP_IO_BUS_WIDTH_ 16 // 8 +#endif +#if _WIZCHIP_IO_BUS_WIDTH_ == 8 +typedef uint8_t iodata_t; +#elif _WIZCHIP_IO_BUS_WIDTH_ == 16 +typedef uint16_t iodata_t; +#else +#error "Unknown _WIZCHIP_IO_BUS_WIDTH_. It should be 8 or 16." +#endif +// +#include "W5300/w5300.h" + + +#elif ( _WIZCHIP_ == W6100) + +#define _WIZCHIP_ID_ "W6100\0" + +/** + @brief Define @ref _WIZCHIP_ interface mode. + @todo You should select interface mode of @ref _WIZCHIP_.\n\n + Select one of @ref _WIZCHIP_IO_MODE_SPI_VDM_, @ref _WIZCHIP_IO_MODE_SPI_FDM_, and @ref _WIZCHIP_IO_MODE_BUS_INDIR_ + @sa WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF() +*/ +#if 1 +// 20231103 taylor +#define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_SPI_VDM_ +#elif 0 +#define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_SPI_VDM_ +#else +#define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_SPV_FDM_ +#endif + +typedef uint8_t iodata_t; ///< IO access unit. bus width +typedef int16_t datasize_t; ///< sent or received data size +#include "./W6100/w6100.h" +#include "../Application/Application.h" + +//teddy 240122 +#elif ( _WIZCHIP_ == W6300) + +#define _WIZCHIP_ID_ "W6300\0" + + + + +/** + @brief Define @ref _WIZCHIP_ interface mode. + @todo You should select interface mode of @ref _WIZCHIP_.\n\n + Select one of @ref _WIZCHIP_IO_MODE_SPI_QSPI_, @ref _WIZCHIP_IO_MODE_SPI_VDM_,@ref _WIZCHIP_IO_MODE_BUS_INDIR_ + @sa WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF() +*/ + +#define QSPI_SINGLE_MODE (0x00 << 6) // 0b0000 0000 // 0x00 +#define QSPI_DUAL_MODE (0x01 << 6) // 0b0100 0000 // 0x40 +#define QSPI_QUAD_MODE (0x02 << 6) // 0b1000 0000 // 0x80 + +#ifndef _WIZCHIP_QSPI_MODE_ +#define _WIZCHIP_QSPI_MODE_ QSPI_SINGLE_MODE +#endif + +//#define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_BUS_INDIR_ +#define _WIZCHIP_IO_MODE_ ((_WIZCHIP_IO_MODE_SPI_ & 0xff00) | (_WIZCHIP_QSPI_MODE_ & 0x00ff)) + + + +typedef uint8_t iodata_t; ///< IO access unit. bus width +typedef int16_t datasize_t; ///< sent or received data size +#include "./W6300/w6300.h" +#include "../Application/Application.h" + +#else +#error "Unknown defined _WIZCHIP_. You should define one of 5100, 5200, 5300, 5500, 6100 and 6300!!!" +#endif + +#ifndef _WIZCHIP_IO_MODE_ +#error "Undefined _WIZCHIP_IO_MODE_. You should define it !!!" +#endif + +/** + @brief Define I/O base address when BUS IF mode. + @todo Should re-define it to fit your system when BUS IF Mode (@ref \_WIZCHIP_IO_MODE_BUS_, + @ref \_WIZCHIP_IO_MODE_BUS_DIR_, @ref \_WIZCHIP_IO_MODE_BUS_INDIR_). \n\n + ex> #define \_WIZCHIP_IO_BASE_ 0x00008000 +*/ +#if _WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_ +#if 1 +// 20231108 taylor +#if (_WIZCHIP_ == W6300) +#define _WIZCHIP_IO_BASE_ 0x60000000 // for W6100-EVB +#elif (_WIZCHIP_ == W6100) +#define _WIZCHIP_IO_BASE_ 0x60000000 // for W5100S-EV +#elif (_WIZCHIP_ == W5100S) +#define _WIZCHIP_IO_BASE_ 0x60000000 // for W5100S-EVB +#elif (_WIZCHIP_ == W5300) +#define _WIZCHIP_IO_BASE_ 0x68000000 // for W5300 by javakys 20210408 @66c27e960a813f7ea6e8b1ce083d12b3e7e86fc0 +#else +#define _WIZCHIP_IO_BASE_ 0x00000000 +#endif + +#else +#if (_WIZCHIP_ == W6100) +#define _WIZCHIP_IO_BASE_ 0x60000000 // for W6100 BUS +#else +// #define _WIZCHIP_IO_BASE_ 0x60000000 // for 5100S IND +#define _WIZCHIP_IO_BASE_ 0x68000000 // for W5300 +#endif +#endif +#elif _WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_ +//#define _WIZCHIP_IO_BASE_ 0x00000000 // for 5100S SPI +#endif + +#ifndef _WIZCHIP_IO_BASE_ +#if 1 +// 20231108 taylor +#define _WIZCHIP_IO_BASE_ 0x00000000 +#else +#define _WIZCHIP_IO_BASE_ 0x00000000 // 0x8000 +#endif +#endif + +//M20150401 : Typing Error +//#if _WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS +#if _WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_ +#ifndef _WIZCHIP_IO_BASE_ +#error "You should be define _WIZCHIP_IO_BASE to fit your system memory map." +#endif +#endif + +#if _WIZCHIP_ >= W5200 +#define _WIZCHIP_SOCK_NUM_ 8 ///< The count of independant socket of @b WIZCHIP +#else +#define _WIZCHIP_SOCK_NUM_ 4 ///< The count of independant socket of @b WIZCHIP +#endif + + +/******************************************************** + WIZCHIP BASIC IF functions for SPI, SDIO, I2C , ETC. +*********************************************************/ +/** + @ingroup DATA_TYPE + @brief The set of callback functions for W5500:@ref WIZCHIP_IO_Functions W5200:@ref WIZCHIP_IO_Functions_W5200 +*/ +typedef struct __WIZCHIP { + uint16_t if_mode; ///< host interface mode + uint8_t id[8]; ///< @b WIZCHIP ID such as @b 5100, @b 5100S, @b 5200, @b 5500, and so on. + /** + The set of critical section callback func. + */ + struct _CRIS { + void (*_enter) (void); ///< crtical section enter + void (*_exit) (void); ///< critial section exit + } CRIS; + /** + The set of @ref \_WIZCHIP_ select control callback func. + */ + struct _CS { + void (*_select) (void); ///< @ref \_WIZCHIP_ selected + void (*_deselect)(void); ///< @ref \_WIZCHIP_ deselected + } CS; + /** + The set of interface IO callback func. + */ + union _IF { + /** + For BUS interface IO + */ + //M20156501 : Modify the function name for integrating with W5300 + //struct + //{ + // uint8_t (*_read_byte) (uint32_t AddrSel); + // void (*_write_byte) (uint32_t AddrSel, uint8_t wb); + //}BUS; + struct { + iodata_t (*_read_data) (uint32_t AddrSel); + void (*_write_data) (uint32_t AddrSel, iodata_t wb); +#if 1 + // 20231103 taylor + void (*_read_data_buf) (uint32_t AddrSel, iodata_t* pBuf, int16_t len, uint8_t addrinc); ///< Read @ref iodata_t as many as len from @ref _WIZCHIP_ through BUS + void (*_write_data_buf) (uint32_t AddrSel, iodata_t* pBuf, int16_t len, uint8_t addrinc); ///< Write @ref iodata_t data as many as len to @ref _WIZCHIP_ through BUS +#endif + } BUS; + + /** + For SPI interface IO + */ + struct { + uint8_t (*_read_byte) (void); + void (*_write_byte) (uint8_t wb); + void (*_read_burst) (uint8_t* pBuf, uint16_t len); + void (*_write_burst) (uint8_t* pBuf, uint16_t len); + } SPI; + + /** + For QSPI interface IO + */ + //teddy 240122 + struct { + void (*_read_qspi) (uint8_t opcode, uint16_t addr, uint8_t* pBuf, uint16_t len); + void (*_write_qspi) (uint8_t opcode, uint16_t addr, uint8_t* pBuf, uint16_t len); + } QSPI; + // To be added + // + } IF; +} _WIZCHIP; + +extern _WIZCHIP WIZCHIP; + +/** + @ingroup DATA_TYPE + WIZCHIP control type enumration used in @ref ctlwizchip(). +*/ +typedef enum { + CW_SYS_LOCK, ///< Lock or Unlock @ref _WIZCHIP_ with @ref SYS_CHIP_LOCK, @ref SYS_PHY_LOCK, and @ref SYS_NET_LOCK + CW_SYS_UNLOCK, ///< Lock or Unlock @ref _WIZCHIP_ with @ref SYS_CHIP_LOCK, @ref SYS_PHY_LOCK, and @ref SYS_NET_LOCK + CW_GET_SYSLOCK, ///< Get the lock status of @ref _WIZCHIP_ with @ref SYS_CHIP_LOCK, @ref SYS_PHY_LOCK, and @ref SYS_NET_LOCK + + CW_RESET_WIZCHIP, ///< Reset @ref _WIZCHIP_ by software + CW_INIT_WIZCHIP, ///< Initialize to SOCKETn buffer size with n byte array typed uint8_t + CW_GET_INTERRUPT, ///< Get the interrupt status with @ref intr_kind + CW_CLR_INTERRUPT, ///< Clear the interrupt with @ref intr_kind + CW_SET_INTRMASK, ///< Set the interrupt mask with @ref intr_kind + CW_GET_INTRMASK, ///< Get the interrupt mask with @ref intr_kind + CW_SET_INTRTIME, ///< Set the interrupt pending time + CW_GET_INTRTIME, ///< Get the interrupt pending time + CW_SET_IEN, ///< Set the global interrupt enable only when @ref SYS_CHIP_LOCK is not set + CW_GET_IEN, ///< Get the global interrupt enable + + CW_GET_ID, ///< Get @ref _WIZCHIP_ name. + CW_GET_VER, ///< Get the version of TCP/IP TOE engine + + CW_SET_SYSCLK, ///< Set the system clock with @ref SYSCLK_100MHZ or SYSCLK_10MHZ only when @ref SYS_CHIP_LOCK is unlock + CW_GET_SYSCLK, ///< Get the system clock with @ref SYSCLK_100MHZ or SYSCLK_10MHZ + + CW_RESET_PHY, ///< Reset PHY + CW_SET_PHYCONF, ///< Set PHY operation mode (Manual/Auto, 10/100, Half/Full) with @ref wiz_PhyConf + CW_GET_PHYCONF, ///< Get PHY operation mode (Manual/Auto, 10/100, Half/Full) with @ref wiz_PhyConf + CW_GET_PHYSTATUS, ///< Get real operation mode with @ref wiz_PhyConf when PHY is linked up. + CW_SET_PHYPOWMODE, ///< Set PHY power mode with @ref PHY_POWER_NORM or PHY_POWER_DOWN + CW_GET_PHYPOWMODE, ///< Get PHY Power mode with @ref PHY_POWER_NORM or PHY_POWER_DOWN + CW_GET_PHYLINK ///< Get PHY Link status with @ref PHY_LINK_ON or @ref PHY_LINK_OFF +} ctlwizchip_type; + +/** + @ingroup DATA_TYPE + Network control type enumration used in @ref ctlnetwork(). +*/ +typedef enum { + CN_SET_NETINFO, ///< Set Network with @ref wiz_NetInfo + CN_GET_NETINFO, ///< Get Network with @ref wiz_NetInfo + CN_SET_NETMODE, ///< Set network mode as WOL, PPPoE, Ping Block, and Force ARP mode + CN_GET_NETMODE, ///< Get network mode as WOL, PPPoE, Ping Block, and Force ARP mode + CN_SET_TIMEOUT, ///< Set network timeout as retry count and time. + CN_GET_TIMEOUT, ///< Get network timeout as retry count and time. + //teddy 240122 +#if ((_WIZCHIP_ == W6100)||(_WIZCHIP_ == W6300)) + CN_SET_PREFER, ///< Set the preferred source IPv6 address of @ref _SLCR_.\n Refer to @ref IPV6_ADDR_AUTO, @ref IPV6_ADDR_LLA, @ref IPV6_ADDR_GUA + CN_GET_PREFER, ///< Get the preferred source IPv6 address of @ref _SLCR_.\n Refer to @ref IPV6_ADDR_AUTO, @ref IPV6_ADDR_LLA, @ref IPV6_ADDR_GUA +#endif +} ctlnetwork_type; + +//teddy 240122 +#if ((_WIZCHIP_ == W6100)||(_WIZCHIP_ == W6300)) +/** + @ingroup DATA_TYPE + @brief Network Service Control Type enumeration + @details @ref ctlnetservice_type includes network management or monitor functions for @ref _WIZCHIP_. + @sa ctlnetservice(), wiz_IPAddress, wiz_Prefix +*/ +typedef enum { + CNS_ARP, ///< ARP process with @ref wiz_IPAddress + CNS_PING, ///< PING process with @ref wiz_IPAddress + CNS_DAD, ///< Duplicated IPv6 Address Detection + /** + @brief Stateless Address Auto-configuration(SLAAC) with @ref wiz_Prefix. + @details @ref CNS_SLAAC sends first RS message to all-router and then receives RA message from a router. + @note It is valid only when the first received RA option is the source link-layer address(0x01) and the second is prefix information(0x03).\n + Refer to @ref SLIR_RS. + @sa ctlnetservice() + @sa CNS_GET_PREFIX + */ + CNS_SLAAC, + CNS_UNSOL_NA, ///< Unsolicited Neighbor Advertisement for update @ref _WIZCHIP_ network information to neighbors + /** + @brief Get prefix information with @ref wiz_Prefix. + @details @ref CNS_GET_PREFIX can get prefix information of RA message to be sent by a router without RS message. + @note It is valid only when @ref IK_SOCKL_RA is set and the prefix information(0x03) of RA option is first received. + @sa ctlnetservice() + @sa CNS_SLAAC + */ + CNS_GET_PREFIX +} ctlnetservice_type; +#endif + +#if (_WIZCHIP_ == W5100 || _WIZCHIP_ == W5100S || _WIZCHIP_ == W5200 || _WIZCHIP_ == W5300 || _WIZCHIP_ == W5500) +/** + @ingroup DATA_TYPE + Interrupt kind when CW_SET_INTRRUPT, CW_GET_INTERRUPT, CW_SET_INTRMASK + and CW_GET_INTRMASK is used in @ref ctlnetwork(). + It can be used with OR operation. +*/ +typedef enum { +#if _WIZCHIP_ == W5500 + IK_WOL = (1 << 4), ///< Wake On Lan by receiving the magic packet. Valid in W500. +#elif _WIZCHIP_ == W5300 + IK_FMTU = (1 << 4), ///< Received a ICMP message (Fragment MTU) +#endif + + IK_PPPOE_TERMINATED = (1 << 5), ///< PPPoE Disconnected + +#if _WIZCHIP_ != W5200 + IK_DEST_UNREACH = (1 << 6), ///< Destination IP & Port Unreachable, No use in W5200 +#endif + + IK_IP_CONFLICT = (1 << 7), ///< IP conflict occurred + + IK_SOCK_0 = (1 << 8), ///< Socket 0 interrupt + IK_SOCK_1 = (1 << 9), ///< Socket 1 interrupt + IK_SOCK_2 = (1 << 10), ///< Socket 2 interrupt + IK_SOCK_3 = (1 << 11), ///< Socket 3 interrupt +#if _WIZCHIP_ > W5100S + IK_SOCK_4 = (1 << 12), ///< Socket 4 interrupt, No use in 5100 + IK_SOCK_5 = (1 << 13), ///< Socket 5 interrupt, No use in 5100 + IK_SOCK_6 = (1 << 14), ///< Socket 6 interrupt, No use in 5100 + IK_SOCK_7 = (1 << 15), ///< Socket 7 interrupt, No use in 5100 +#endif + +#if _WIZCHIP_ > W5100S + IK_SOCK_ALL = (0xFF << 8) ///< All Socket interrupt +#else + IK_SOCK_ALL = (0x0F << 8) ///< All Socket interrupt +#endif +} intr_kind; +//teddy 240122 +#elif ((_WIZCHIP_ == W6100)||(_WIZCHIP_ == W6300)) +/** + @ingroup DATA_TYPE + @brief Interrupt Kind + @details @ref intr_kind can be used as the interrupt bits of @ref _IR_, @ref _SIR_, and @ref _SLIR_,\n + It can be used as the interrupt mask bits of @ref _IMR_, @ref _SIMR_, and @ref _SLIMR_,\n + and also, It can be used as the interrupt clear bits of @ref _IRCLR_, @ref _Sn_IRCLR_, and @ref _SLIRCLR_. + @note It can be used with @b OR operation. + @sa ctlwizchip(), CW_GET_INTERRUPT, CW_CLR_INTERRUPT, CW_GET_INTRMASK, CW_SET_INTRMASK + @sa ctlnetservice(), ctlnetservice_type + @sa wizchip_getinterrupt(), wizchip_clrinterrupt(), wizchip_getinterruptmask(), wizchip_setinterruptmask() +*/ +typedef enum { + IK_PPPOE_TERMINATED = (1 << 0), ///< PPPoE Termination Interrupt + IK_DEST_UNREACH = (1 << 1), ///< ICMPv4 Destination Unreachable Interrupt + IK_IP_CONFLICT = (1 << 2), ///< IPv4 Address Conflict Interrupt + IK_DEST_UNREACH6 = (1 << 4), ///< ICMPv6 Destination Unreachable Interrupt + IK_WOL = (1 << 7), ///< WOL magic packet Interrupt + IK_NET_ALL = (0x97), ///< All Network Interrupt + + IK_SOCK_0 = (1 << 8), ///< Socket 0 Interrupt + IK_SOCK_1 = (1 << 9), ///< Socket 1 Interrupt + IK_SOCK_2 = (1 << 10), ///< Socket 2 Interrupt + IK_SOCK_3 = (1 << 11), ///< Socket 3 Interrupt + IK_SOCK_4 = (1 << 12), ///< Socket 4 Interrupt + IK_SOCK_5 = (1 << 13), ///< Socket 5 Interrupt + IK_SOCK_6 = (1 << 14), ///< Socket 6 Interrupt + IK_SOCK_7 = (1 << 15), ///< Socket 7 Interrupt + IK_SOCK_ALL = (0xFF << 8), ///< All Socket Interrupt + + IK_SOCKL_TOUT = (1 << 16), ///< @ref _SLCR_ Timeout Interrupt.\n Refer to @ref ctlnetservice_type. + IK_SOCKL_ARP4 = (1 << 17), ///< @ref _SLCR_ APR4 Interrupt.\n Refer to @ref CNS_ARP. + IK_SOCKL_PING4 = (1 << 18), ///< @ref _SLCR_ PING4 Interrupt.\n Refer to @ref CNS_PING. + IK_SOCKL_ARP6 = (1 << 19), ///< @ref _SLCR_ ARP6 Interrupt.\n Refer to @ref CNS_ARP. + IK_SOCKL_PING6 = (1 << 20), ///< @ref _SLCR_ PING6 Interrupt.\n Refer to @ref CNS_PING. + IK_SOCKL_NS = (1 << 21), ///< @ref _SLCR_ NS Interrupt.\n Refer to @ref CNS_DAD. + IK_SOCKL_RS = (1 << 22), ///< @ref _SLCR_ RS Interrupt.\n Refer to @ref CNS_SLAAC. + IK_SOCKL_RA = (1 << 23), ///< @ref _SLCR_ RA Interrupt.\n Refer to @ref CNS_GET_PREFIX. + IK_SOCKL_ALL = (0xFF << 16), ///< @ref _SLCR_ All Interrupt + + IK_INT_ALL = (0x00FFFF97) ///< All Interrupt +} intr_kind; +#endif + +//teddy 240122 +#if ((_WIZCHIP_ == W6100)||(_WIZCHIP_ == W6300)) +#define SYS_CHIP_LOCK (1<<2) ///< CHIP LOCK. \n Refer to @ref CW_SYS_LOCK, @ref CW_SYS_UNLOCK, and @ref CW_GET_SYSLOCK. +#define SYS_NET_LOCK (1<<1) ///< NETWORK Information LOCK. \n Refer to @ref CW_SYS_LOCK, @ref CW_SYS_UNLOCK, and @ref CW_GET_SYSLOCK. +#define SYS_PHY_LOCK (1<<0) ///< PHY LOCK.\n Refer to @ref CW_SYS_LOCK, @ref CW_SYS_UNLOCK, and @ref CW_GET_SYSLOCK. + +#define SYSCLK_100MHZ 0 ///< System Clock 100MHz.\n Refer to Refer to @ref CW_SET_SYSCLK and @ref CW_GET_SYSCLK. +#define SYSCLK_25MHZ 1 ///< System Clock 25MHz.\n Refer to Refer to @ref CW_SET_SYSCLK and @ref CW_GET_SYSCLK. + +#define PHY_MODE_MANUAL 0 ///< Configured PHY operation mode with user setting.\n Refer to @ref CW_SET_PHYCONF and @ref CW_GET_PHYCONF. +#define PHY_MODE_AUTONEGO 1 ///< Configured PHY operation mode with auto-negotiation.\n Refer to @ref CW_SET_PHYCONF and @ref CW_GET_PHYCONF. +#define PHY_MODE_TE 2 + +#define IPV6_ADDR_AUTO 0x00 ///< IPv6 Address Type : Auto.\n Refer to @ref CN_SET_PREFER, @ref CN_GET_PREFER. +#define IPV6_ADDR_LLA 0x02 ///< IPv6 Address Type : LLA. \n Refer to @ref CN_SET_PREFER, @ref CN_GET_PREFER, @ref CNS_DAD. +#define IPV6_ADDR_GUA 0x03 ///< IPv6 Address Type : GUA. \n Refer to @ref CN_SET_PREFER, @ref CN_GET_PREFER, @ref CNS_DAD. +#endif + +#define PHY_CONFBY_HW 0 ///< Configured PHY operation mode by HW pin +#define PHY_CONFBY_SW 1 ///< Configured PHY operation mode by SW register +#define PHY_MODE_MANUAL 0 ///< Configured PHY operation mode with user setting. +#define PHY_MODE_AUTONEGO 1 ///< Configured PHY operation mode with auto-negotiation +#define PHY_SPEED_10 0 ///< Link Speed 10 +#define PHY_SPEED_100 1 ///< Link Speed 100 +#define PHY_DUPLEX_HALF 0 ///< Link Half-Duplex +#define PHY_DUPLEX_FULL 1 ///< Link Full-Duplex +#define PHY_LINK_OFF 0 ///< Link Off +#define PHY_LINK_ON 1 ///< Link On +#define PHY_POWER_NORM 0 ///< PHY power normal mode +#define PHY_POWER_DOWN 1 ///< PHY power down mode + + +//teddy 240122 +#if _WIZCHIP_ == W5100S || _WIZCHIP_ == W5500 || _WIZCHIP_ == W6100 || _WIZCHIP_ == W6300 +/** + @ingroup DATA_TYPE + It configures PHY configuration when CW_SET PHYCONF or CW_GET_PHYCONF in W5500, + and it indicates the real PHY status configured by HW or SW in all WIZCHIP. \n + Valid only in W5500. +*/ +typedef struct wiz_PhyConf_t { + uint8_t by; ///< set by @ref PHY_CONFBY_HW or @ref PHY_CONFBY_SW + uint8_t mode; ///< set by @ref PHY_MODE_MANUAL or @ref PHY_MODE_AUTONEGO + uint8_t speed; ///< set by @ref PHY_SPEED_10 or @ref PHY_SPEED_100 + uint8_t duplex; ///< set by @ref PHY_DUPLEX_HALF @ref PHY_DUPLEX_FULL + //uint8_t power; ///< set by @ref PHY_POWER_NORM or @ref PHY_POWER_DOWN + //uint8_t link; ///< Valid only in CW_GET_PHYSTATUS. set by @ref PHY_LINK_ON or PHY_DUPLEX_OFF +} wiz_PhyConf; +#endif + +#if (_WIZCHIP_ == W5100 || _WIZCHIP_ == W5100S || _WIZCHIP_ == W5200 || _WIZCHIP_ == W5300 || _WIZCHIP_ == W5500) +/** + @ingroup DATA_TYPE + It used in setting dhcp_mode of @ref wiz_NetInfo. +*/ +typedef enum { + NETINFO_STATIC = 1, ///< Static IP configuration by manually. + NETINFO_DHCP ///< Dynamic IP configruation from a DHCP sever +} dhcp_mode; + +/** + @ingroup DATA_TYPE + Network Information for WIZCHIP +*/ +typedef struct wiz_NetInfo_t { + uint8_t mac[6]; ///< Source Mac Address + uint8_t ip[4]; ///< Source IP Address + uint8_t sn[4]; ///< Subnet Mask + uint8_t gw[4]; ///< Gateway IP Address + uint8_t dns[4]; ///< DNS server IP Address + dhcp_mode dhcp; ///< 1 - Static, 2 - DHCP +} wiz_NetInfo; + +/** + @ingroup DATA_TYPE + Network mode +*/ +typedef enum { +#if _WIZCHIP_ == W5500 + NM_FORCEARP = (1 << 1), ///< Force to APP send whenever udp data is sent. Valid only in W5500 +#endif + NM_WAKEONLAN = (1 << 5), ///< Wake On Lan + NM_PINGBLOCK = (1 << 4), ///< Block ping-request + NM_PPPOE = (1 << 3), ///< PPPoE mode +} netmode_type; + +/** + @ingroup DATA_TYPE + Used in CN_SET_TIMEOUT or CN_GET_TIMEOUT of @ref ctlwizchip() for timeout configruation. +*/ +typedef struct wiz_NetTimeout_t { + uint8_t retry_cnt; ///< retry count + uint16_t time_100us; ///< time unit 100us +} wiz_NetTimeout; +//teddy 240122 +#elif ((_WIZCHIP_ == W6100)||(_WIZCHIP_ == W6300)) +/** + @ingroup DATA_TYPE + @brief IP Address Configuration Mode + @details @ref ipconf_mode can be used to save the DHCP mode running on your system. + @sa ctlnetwork(), CN_SET_NETINFO, CN_GET_NETINFO + @sa wizchip_setnetinfo(), wizchip_getnetinfo(), wiz_NetInfo +*/ +typedef enum { + NETINFO_NONE = 0x00, ///< No use DHCP + NETINFO_STATIC_V4 = 0x01, ///< Static IPv4 configuration by manually. + NETINFO_STATIC_V6 = 0x02, ///< Static IPv6 configuration by manually. + NETINFO_STATIC_ALL = 0x03, ///< Static IPv4 and IPv6 configuration by manually. + NETINFO_SLAAC_V6 = 0x04, ///< Stateless Adders Auto Configuration for IPv6 + NETINFO_DHCP_V4 = 0x10, ///< Dynamic IPv4 configuration from a DHCP sever + NETINFO_DHCP_V6 = 0x20, ///< Dynamic IPv6 configuration from a DHCP sever + NETINFO_DHCP_ALL = 0x30 ///< Dynamic IPv4 and IPv6 configuration from a DHCP sever +} ipconf_mode; + +/** + @ingroup DATA_TYPE + @brief Network Information for @ref _WIZCHIP_ + @details @ref wiz_NetInfo is a structure type to configure or indicate the network information of @ref _WIZCHIP_. + @sa ctlnetwork(), CN_SET_NETINFO, CN_GET_NETINFO + @sa wizchip_setnetinfo(), wizchip_getnetinfo() +*/ + +typedef enum { + NETINFO_STATIC = 1, ///< Static IP configuration by manually. + NETINFO_DHCP ///< Dynamic IP configruation from a DHCP sever +} dhcp_mode; + +typedef struct wiz_NetInfo_t { + uint8_t mac[6]; ///< Source Hardware Address + uint8_t ip[4]; ///< Source IPv4 Address + uint8_t sn[4]; ///< Subnet Mask value + uint8_t gw[4]; ///< Gateway IPv4 Address + uint8_t lla[16]; ///< Source Link Local Address + uint8_t gua[16]; ///< Source Global Unicast Address + uint8_t sn6[16]; ///< IPv6 Prefix + uint8_t gw6[16]; ///< Gateway IPv6 Address + uint8_t dns[4]; ///< DNS server IPv4 Address + uint8_t dns6[16]; ///< DNS server IPv6 Address + ipconf_mode ipmode; ///< IP Configuration Mode + dhcp_mode dhcp; ///< 1 - Static, 2 - DHCP +} wiz_NetInfo; + +/** + @ingroup DATA_TYPE + @brief Network mode Configuration + @details @ref netmode_type includes the network mode control function such as ping, TCP/RST block and etc. + @sa ctlnetwork(), CN_SET_NETMODE, CN_GET_NETMODE +*/ +typedef enum { + // NETMR Bit Values + NM_IPB_V4 = (1 << 0), ///< IPv4 Packet Block + NM_IPB_V6 = (1 << 1), ///< IPv6 Packet Block + NM_WOL = (1 << 2), ///< Wake On Lan(WOL) Mode + NM_PB6_MULTI = (1 << 4), ///< PING6 request from multicasting group address Block + NM_PB6_ALLNODE = (1 << 5), ///< PING6 request from all-node multicasting address Block + NM_MR_MASK = (0x37), ///< @ref _NETMR_ Mask value + + // NETMR2 Bit Values + NM_PPPoE = (1 << 8), ///< PPPoE Mode + NM_DHA_SELECT = (1 << 15), ///< Destination Hardware Address Select + NM_MR2_MASK = (0x09 << 8), ///< @ref _NETMR2_ Mask value + + //NET4MR Bit Values + NM_PB4_ALL = (1 << 16), ///< All PING4 request Block + NM_TRSTB_V4 = (1 << 17), ///< TCP RST packet for IPv4 Send Block + NM_PARP_V4 = (1 << 18), ///< ARP request for IPv4 before PINGv4 Replay + NM_UNRB_V4 = (1 << 19), ///< Unreachable Destination for IPv4 Block + NM_NET4_MASK = (0x0F << 16), ///< @ref _NET4MR_ Mask value + + //NET4MR Bit Values + NM_PB6_ALL = (1 << 24), ///< All PING6 request Block + NM_TRSTB_V6 = (1 << 25), ///< TCP RST packet for IPv6 Send Block + NM_PARP_V6 = (1 << 26), ///< ARP request for IPv6 before PINGv4 Replay + NM_UNRB_V6 = (1 << 27), ///< Unreachable Destination for IPv6 Block + NM_NET6_MASK = (0x0F << 24), ///< @ref _NET6MR_ Mask value + + NM_MASK_ALL = (0x0F0F0937) ///< @ref netmode_type all mask value +} netmode_type; + +/** + @ingroup DATA_TYPE + @brief Network Timeout for @ref _WIZCHIP_ + @details @ref wiz_NetInfo is a structure type to configure or indicate the network timeout of @ref _WIZCHIP_. + @sa ctlnetwork(), CN_SET_TIMEOUT, CN_GET_TIMEOUT + @sa wizchip_settimeout(), wizchip_gettimeout() +*/ +typedef struct wiz_NetTimeout_t { + uint8_t s_retry_cnt; ///< The default retry count of SOCKETn + uint16_t s_time_100us; ///< The retransmission time of SOCKETn (unit 100us) + uint8_t sl_retry_cnt; ///< The retry count of SOCKET-less + uint16_t sl_time_100us; ///< The retransmission time of SOCKET-less (unit 100us) +} wiz_NetTimeout; + +/** + @ingroup DATA_TYPE + @brief Destination Information for Network Service of @ref _WIZCHIP_ + @details @ref wiz_NetInfo is a structure type to configure or indicate a destination information of network service. + @sa ctlnetservice(), CNS_ARP, CNS_PING + @sa IK_SOCKL_TOUT, IK_SOCKL_ARP4, IK_SOCKL_ARP6, IK_SOCKL_PING4, IK_SOCKL_PING6 +*/ +typedef struct wiz_IPAddress_t { + uint8_t ip[16]; ///< Destination IP Address. \n IPv4 index : 0 to 3, IPv6 index : 0 to 15 + uint8_t len; ///< Destination IP Address Length.\n IPv4 : 4, IPv6 : 16. +} wiz_IPAddress; + +/** + @ingroup DATA_TYPE + @brief Prefix Information + @details @ref wiz_Prefix is a structure type to indicate a prefix information(0x03) of received RA message from a router. + @sa ctlnetservice(), CNS_SLAAC, IK_SOCKL_RS + @sa IK_SOCKL_TOUT, IK_SOCKL_RA, CNS_GET_PREFIX +*/ +typedef struct wiz_Prefix_t { + uint8_t len; ///< Prefix Length. \n It is used to set @ref _SUB6R_ to 1 as many as len from LSB bit. + uint8_t flag; ///< Prefix Flag + uint32_t valid_lifetime; ///< Valid Lifetime + uint32_t preferred_lifetime; ///< Preferred Lifetime + uint8_t prefix[16]; ///< Prefix +} wiz_Prefix; + +/** + @ingroup DATA_TYPE + @brief Destination Information & Destination Hardware Address for @ref CNS_ARP + @details @ref wiz_ARP is a structure type to set a destination IP address for ARP-request or \n + indicate a destination hardware address in APR-reply. + @sa ctlnetservice(), CNS_ARP + @sa IK_SOCKL_TOUT, IK_SOCKL_ARP4, IK_SOCKL_ARP6 +*/ +typedef struct wiz_ARP_t { + wiz_IPAddress destinfo; ///< Destination IP address for ARP-request + uint8_t dha[6]; ///< Destination Hardware Address when ARP-reply is received from the destination. +} wiz_ARP; + +/** + @ingroup DATA_TYPE + @brief Destination Information & Destination Hardware Address for @ref CNS_ARP + @details @ref wiz_PING is a structure type to set a ID, sequence number, destination IP address for PING-request. + @sa ctlnetservice(), CNS_PING + @sa IK_SOCKL_TOUT, IK_SOCKL_PING4, IK_SOCKL_PING6 +*/ +typedef struct wiz_PING_t { + uint16_t id; + uint16_t seq; + wiz_IPAddress destinfo; +} wiz_PING; +#endif + +/** + @brief Registers call back function for critical section of I/O functions such as + \ref WIZCHIP_READ, @ref WIZCHIP_WRITE, @ref WIZCHIP_READ_BUF and @ref WIZCHIP_WRITE_BUF. + @param cris_en : callback function for critical section enter. + @param cris_ex : callback function for critical section exit. + @todo Describe @ref WIZCHIP_CRITICAL_ENTER and @ref WIZCHIP_CRITICAL_EXIT marco or register your functions. + @note If you do not describe or register, default functions(@ref wizchip_cris_enter & @ref wizchip_cris_exit) is called. +*/ +void reg_wizchip_cris_cbfunc(void(*cris_en)(void), void(*cris_ex)(void)); + + +/** + @brief Registers call back function for WIZCHIP select & deselect. + @param cs_sel : callback function for WIZCHIP select + @param cs_desel : callback fucntion for WIZCHIP deselect + @todo Describe @ref wizchip_cs_select and @ref wizchip_cs_deselect function or register your functions. + @note If you do not describe or register, null function is called. +*/ +void reg_wizchip_cs_cbfunc(void(*cs_sel)(void), void(*cs_desel)(void)); + +/** + @brief Registers call back function for bus interface. + @param bus_rb : callback function to read byte data using system bus + @param bus_wb : callback function to write byte data using system bus + @todo Describe @ref wizchip_bus_readbyte and @ref wizchip_bus_writebyte function + or register your functions. + @note If you do not describe or register, null function is called. +*/ +//M20150601 : For integrating with W5300 +//void reg_wizchip_bus_cbfunc(uint8_t (*bus_rb)(uint32_t addr), void (*bus_wb)(uint32_t addr, uint8_t wb)); +void reg_wizchip_bus_cbfunc(iodata_t (*bus_rb)(uint32_t addr), void (*bus_wb)(uint32_t addr, iodata_t wb)); + +/** + @brief Registers call back function for SPI interface. + @param spi_rb : callback function to read byte using SPI + @param spi_wb : callback function to write byte using SPI + @todo Describe \ref wizchip_spi_readbyte and \ref wizchip_spi_writebyte function + or register your functions. + @note If you do not describe or register, null function is called. +*/ +#if _WIZCHIP_ == W6100 +void reg_wizchip_spi_cbfunc(uint8_t (*spi_rb)(void), + void (*spi_wb)(uint8_t wb), + void (*spi_rbuf)(uint8_t* buf, datasize_t len), + void (*spi_wbuf)(uint8_t* buf, datasize_t len)); +#else +void reg_wizchip_spi_cbfunc(uint8_t (*spi_rb)(void), void (*spi_wb)(uint8_t wb)); +#endif + +/** + @brief Registers call back function for SPI interface. + @param spi_rb : callback function to burst read using SPI + @param spi_wb : callback function to burst write using SPI + @todo Describe \ref wizchip_spi_readbyte and \ref wizchip_spi_writebyte function + or register your functions. + @note If you do not describe or register, null function is called. +*/ +void reg_wizchip_spiburst_cbfunc(void (*spi_rb)(uint8_t* pBuf, uint16_t len), void (*spi_wb)(uint8_t* pBuf, uint16_t len)); + +//teddy 240122 +/** + @brief Registers call back function for QSPI interface. + @param spi_rb : callback function to read using QSPI + @param spi_wb : callback function to write using QSPI + @todo Describe \ref wizchip_qspi_read and \ref wizchip_qspi_write function + or register your functions. + @note If you do not describe or register, null function is called. +*/ +void reg_wizchip_qspi_cbfunc(void (*qspi_rb)(uint8_t opcode, uint16_t addr, uint8_t* pBuf, uint16_t len), void (*qspi_wb)(uint8_t opcode, uint16_t addr, uint8_t* pBuf, uint16_t len)); + +/** + @ingroup extra_functions + @brief Controls to the WIZCHIP. + @details Resets WIZCHIP & internal PHY, Configures PHY mode, Monitor PHY(Link,Speed,Half/Full/Auto), + controls interrupt & mask and so on. + @param cwtype : Decides to the control type + @param arg : arg type is dependent on cwtype. + @return 0 : Success \n + -1 : Fail because of invalid \ref ctlwizchip_type or unsupported \ref ctlwizchip_type in WIZCHIP +*/ +int8_t ctlwizchip(ctlwizchip_type cwtype, void* arg); + +/** + @ingroup extra_functions + @brief Controls to network. + @details Controls to network environment, mode, timeout and so on. + @param cntype : Input. Decides to the control type + @param arg : Inout. arg type is dependent on cntype. + @return -1 : Fail because of invalid \ref ctlnetwork_type or unsupported \ref ctlnetwork_type in WIZCHIP \n + 0 : Success +*/ +int8_t ctlnetwork(ctlnetwork_type cntype, void* arg); + +//teddy 240122 +#if ((_WIZCHIP_ == W6100)||(_WIZCHIP_ == W6300)) +/** + @ingroup extra_functions + @brief Controls to network service. + @details Controls to network environment, mode, timeout and so on. + @param cnstype : Decides to the control type + @param arg : arg type is dependent on cnstype. + @return -1 : Fail because of invalid @ref ctlnetwork_type or unsupported @ref ctlnetwork_type \n + 0 : Success +*/ +int8_t ctlnetservice(ctlnetservice_type cnstype, void* arg); +#endif + +/* + The following functions are implemented for internal use. + but You can call these functions for code size reduction instead of ctlwizchip() and ctlnetwork(). +*/ + +/** + @ingroup extra_functions + @brief Reset WIZCHIP by softly. +*/ +void wizchip_sw_reset(void); + +/** + @ingroup extra_functions + @brief Initializes WIZCHIP with socket buffer size + @param txsize Socket tx buffer sizes. If null, initialized the default size 2KB. + @param rxsize Socket rx buffer sizes. If null, initialized the default size 2KB. + @return 0 : succcess \n + -1 : fail. Invalid buffer size +*/ +int8_t wizchip_init(uint8_t* txsize, uint8_t* rxsize); + +/** + @ingroup extra_functions + @brief Clear Interrupt of WIZCHIP. + @param intr : @ref intr_kind value operated OR. It can type-cast to uint16_t. +*/ +void wizchip_clrinterrupt(intr_kind intr); + +/** + @ingroup extra_functions + @brief Get Interrupt of WIZCHIP. + @return @ref intr_kind value operated OR. It can type-cast to uint16_t. +*/ +intr_kind wizchip_getinterrupt(void); + +/** + @ingroup extra_functions + @brief Mask or Unmask Interrupt of WIZCHIP. + @param intr : @ref intr_kind value operated OR. It can type-cast to uint16_t. +*/ +void wizchip_setinterruptmask(intr_kind intr); + +/** + @ingroup extra_functions + @brief Get Interrupt mask of WIZCHIP. + @return : The operated OR vaule of @ref intr_kind. It can type-cast to uint16_t. +*/ +intr_kind wizchip_getinterruptmask(void); + +//todo +#if _WIZCHIP_ > W5100 +int8_t wizphy_getphylink(void); ///< get the link status of phy in WIZCHIP. No use in W5100 +int8_t wizphy_getphypmode(void); ///< get the power mode of PHY in WIZCHIP. No use in W5100 +#endif + +#if _WIZCHIP_ == W5100S || _WIZCHIP_ == W5500 +void wizphy_reset(void); ///< Reset phy. Vailid only in W5500 +/** + @ingroup extra_functions + @brief Set the phy information for WIZCHIP without power mode + @param phyconf : @ref wiz_PhyConf +*/ +void wizphy_setphyconf(wiz_PhyConf* phyconf); +/** + @ingroup extra_functions + @brief Get phy configuration information. + @param phyconf : @ref wiz_PhyConf +*/ +void wizphy_getphyconf(wiz_PhyConf* phyconf); +/** + @ingroup extra_functions + @brief Get phy status. + @param phyconf : @ref wiz_PhyConf +*/ +void wizphy_getphystat(wiz_PhyConf* phyconf); +/** + @ingroup extra_functions + @brief set the power mode of phy inside WIZCHIP. Refer to @ref PHYCFGR in W5500, @ref PHYSTATUS in W5200 + @param pmode Settig value of power down mode. +*/ +int8_t wizphy_setphypmode(uint8_t pmode); +//teddy 240122 +#elif ((_WIZCHIP_ == W6100)||(_WIZCHIP_ == W6300)) +/** + @ingroup extra_functions + @brief Reset the integrated PHY. + @details @ref wizphy_reset() resets the integrated Ethernet PHY \n + through @ref _PHY_IO_MODE_PHYCR_ or @ref _PHY_IO_MODE_MII_. \n + @note In @ref _PHY_IO_MODE_PHYCR_, It needs a stable reset time. \n + So you need to wait for the stable reset time.\n + The stable reset time for each @ref _WIZCHIP_ maybe different. + @sa ctlwizchip(), CW_RESET_PHY + @sa _PHY_IO_MODE_ +*/ +void wizphy_reset(void); ///< Reset phy. Vailid only in W5500 + +/** + @ingroup extra_functions + @details @ref wizphy_setphyconf() set a operation mode of the integrated Ethernet PHY \n + through @ref _PHY_IO_MODE_PHYCR_ or @ref _PHY_IO_MODE_MII_.\n + @param phyconf : @ref wiz_PhyConf + @note The operation mode can be applied to Ethernet PHY after the Ethernet PHY is reset by @ref wizphy_reset(). + @sa ctlwizchip(), CW_SET_PHYCONF, CW_GET_PHYCONF, CW_GET_PHYSTATUS, CW_RESET_PHY + @sa _PHY_IO_MODE_, wizphy_getphyconf(), wizphy_getphystatus(), wizphy_reset() +*/ +void wizphy_setphyconf(wiz_PhyConf* phyconf); + +/** + @ingroup extra_functions + @brief Get the integrated Ethernet PHY operation mode. + @details @ref wizphy_getphyconf() gets a operation mode of the integrated Ethernet PHY \n + through @ref _PHY_IO_MODE_PHYCR_ or @ref _PHY_IO_MODE_MII_.\n + @param phyconf : @ref wiz_PhyConf + @note It gets just the configured value for PHY operation, not real PHY operation.\n + To get real PHY operation, you can call @ref wizphy_getphystatus() + @sa ctlwizchip(), CW_GET_PHYCONF, CW_SET_PHYCONF, CW_GET_PHYSTATUS + @sa _PHY_IO_MODE_, wizphy_setphyconf(), wizphy_getphystatus() +*/ +void wizphy_getphyconf(wiz_PhyConf* phyconf); + +/** + @ingroup extra_functions + @brief Get the real PHY operation status when link is established. + @details @ref wizphy_getphystatus() gets a operation mode of the integrated Ethernet PHY. \n + @param phyconf : @ref wiz_PhyConf + @sa ctlwizchip(), CW_GET_PHYSTATUS, CW_GET_PHYCONF, CW_SET_PHYCONF + @sa wizphy_setphyconf(), wizphy_getphyconf() +*/ +void wizphy_getphystat(wiz_PhyConf* phyconf); + +/** + @ingroup extra_functions + @brief Set the power mode of integrated Ethernet PHY. + @details @ref wizphy_setphypmode() sets a power mode of the integrated Ethernet PHY \n + through @ref _PHY_IO_MODE_PHYCR_ or @ref _PHY_IO_MODE_MII_.\n + @param pmode @ref PHY_POWER_NORM or @ref PHY_POWER_DOWN + @note When the integrated Ethernet PHY enters in power down mode, \n + the system clock of @ref _WIZCHIP_ is changed to the lowest speed. \n + So, you should adjust the access time of @ref _WIZCHIP_ to the changed system clock. + @sa ctlwizchip(), CW_SET_PHYPOWMODE, CW_GET_PHYPOWMODE + @sa _PHY_IO_MODE_, wizphy_setphypmode(), wizphy_getphypmode() +*/ +void wizphy_setphypmode(uint8_t pmode); + +/** + @ingroup extra_functions + @brief get the power mode of integrated Ethernet PHY. + @details @ref wizphy_getphypmode() gets a power mode of the integrated Ethernet PHY \n + through @ref _PHY_IO_MODE_PHYCR_ or @ref _PHY_IO_MODE_MII_.\n + @return @ref PHY_POWER_NORM or @ref PHY_POWER_DOWN + @note When the integrated Ethernet PHY enters in power down mode,\n + the system clock of @ref _WIZCHIP_ is changed to the lowest speed. \n + So, you should adjust the access time of @ref _WIZCHIP_ to the changed system clock. + @sa ctlwizchip(), CW_SET_PHYPOWMODE, CW_GET_PHYPOWMODE + @sa _PHY_IO_MODE_, wizphy_setphypmode(), wizphy_getphypmode() +*/ +int8_t wizphy_getphypmode(void); + +/** + @ingroup extra_functions + @brief Set the network information for @ref _WIZCHIP_ + @param pnetinfo : @ref wiz_NetInfo + @sa ctlnetwork(), CN_SET_NETINFO, CN_GET_NETINFO + @sa wizchip_getnetinfo() +*/ +void wizchip_setnetinfo(wiz_NetInfo* pnetinfo); + +/** + @ingroup extra_functions + @brief Get the network information of @ref _WIZCHIP_ + @param pnetinfo : @ref wiz_NetInfo + @sa ctlnetwork(), CN_GET_NETINFO, CN_SET_NETINFO + @sa wizchip_setnetinfo() +*/ +void wizchip_getnetinfo(wiz_NetInfo* pnetinfo); + +/** + @ingroup extra_functions + @brief Set the network mode such as WOL, PPPoE, PING Block, and etc. + @param netmode : @ref netmode_type. + @sa ctlnetwork(), CN_SET_NETMODE, CN_GET_NETMODE + @sa wizchip_getnetmode() +*/ +void wizchip_setnetmode(netmode_type netmode); + +/** + @ingroup extra_functions + @brief Get the network mode such as WOL, PPPoE, PING Block, and etc. + @return @ref netmode_type. + @sa ctlnetwork(), CN_GET_NETMODE, CN_SET_NETMODE + @sa wizchip_setnetmode() +*/ +netmode_type wizchip_getnetmode(void); + +/** + @ingroup extra_functions + @brief Set retransmission time values and retry counts. + @param nettime : @ref wiz_NetTimeout. + @sa ctlnetwork(), CN_SET_TIMEOUT, CN_GET_TIMEOUT + @sa wizchip_gettimeout() +*/ +void wizchip_settimeout(wiz_NetTimeout* nettime); + +/** + @ingroup extra_functions + @brief Get retransmission time values and retry counts. + @param nettime : @ref wiz_NetTimeout. + @sa ctlnetwork(), CN_GET_TIMEOUT, CN_SET_TIMEOUT + @sa wizchip_settimeout() +*/ +void wizchip_gettimeout(wiz_NetTimeout* nettime); + +/** + @ingroup extra_functions + @brief ARP process. + @details @ref wizchip_arp() processes ARP. \n + It sends the APR-request to destination and waits to receive the ARP-reply. + @param arp @ref wiz_ARP.\n + It sets a destination IP address and indicates the destination hardware address. + @return 0 : success, destination hardware address is valid.\n + -1 : fail. destination hardware address is invalid because timeout is occurred.\n + @sa ctlnetservice(), CNS_ARP +*/ +int8_t wizchip_arp(wiz_ARP* arp); + +/** + @ingroup extra_functions + @brief PING process. + @details @ref wizchip_ping() processes PING. \n + It sends the PING-request to destination and waits to receive the PING-reply. + @param ping @ref wiz_PING, It sets a destination IP address, ID, SEQ of PING-request message + @return 0 : success, PING-reply is successfully received.\n + -1 : fail. Timeout is occurred.\n + @sa ctlnetservice(), CNS_PING +*/ +int8_t wizchip_ping(wiz_PING* ping); + +/** + @ingroup extra_functions + @brief DAD(Duplcated Address Detection) process. + @details @ref wizchip_dad() detects the duplication of source IPv6 address.\n + It sends a NA message for DAD to all-node multicasting address(FF02::01). + @param ipv6 : IPv6 address to be detected the duplication. + @return 0 : success, There is no duplicated address. \n + -1 : fail. @ref _WIZCHIP_ source IP address to use is duplicated with a neighbor's one. + @sa ctlnetservice(), CNS_DAD +*/ +int8_t wizchip_dad(uint8_t* ipv6); + +/** + @ingroup extra_functions + @brief Stateless Address Auto Configuration(SLAAC) process. + @details @ref wizchip_slaac() get a prefix information from a router for SLAAC.\n + It sends first a RS message to all-router and waits to receive a RS message with prefix information option from a router. + @param prefix @ref wiz_Prefix + @return 0 : success, RA message is successfully received, and prefix is valid. \n + -1 : fail. Timeout is occurred. + @note It is valid only when the prefix information type(0x03) of RA option received first.\n + The prefix option should be in the order of prefix length, prefix flag, valid lifetime, default lifetime and prefix address. \n + For more detail, Refer to @ref SLIR_RS. + @sa ctlnetservice(), CNS_SLAAC +*/ +int8_t wizchip_slaac(wiz_Prefix* prefix); + +/** + @ingroup extra_functions + @brief Unsolicited NA process. + @details @ref wizchip_unsolicited() updates the network information of @ref _WIZCHIP_ to neighbors.\n + It sends a unsolicited NA message with @ref _LLAR_ or @ref _GUAR_ to neighbors \n + in order to update the network information of @ref _WIZCHIP_.\n + Because the unsolicited NA message have no reply, timeout is always occurred. + @return always 0. Timeout is occurred. + @sa ctlnetservice(), CNS_UNSOL +*/ +int8_t wizchip_unsolicited(void); + +/** + @ingroup extra_functions + @brief Get a prefix information of RA message from a router. + @details @ref wizchip_getprefix() get a prefix information of RA is periodically sent by a router. \n + @return 0 : success, a RS message is successfully received from a router. + -1 : fail, a RS message is not received from a router yet. + @note It is valid only when the prefix information type(0x03) of RA option received first.\n + The prefix option should be in the order of prefix length, prefix flag, valid lifetime, default lifetime and prefix address. \n + For more detail, Refer to @ref SLIR_RS. + @sa ctlnetservice(), CNS_GET_PREFIX +*/ +int8_t wizchip_getprefix(wiz_Prefix * prefix); +#endif + +#if (_WIZCHIP_ == W5100 || _WIZCHIP_ == W5100S || _WIZCHIP_ == W5200 || _WIZCHIP_ == W5300 || _WIZCHIP_ == W5500) +/** + @ingroup extra_functions + @brief Set the network information for WIZCHIP + @param pnetinfo : @ref wizNetInfo +*/ +void wizchip_setnetinfo(wiz_NetInfo* pnetinfo); + +/** + @ingroup extra_functions + @brief Get the network information for WIZCHIP + @param pnetinfo : @ref wizNetInfo +*/ +void wizchip_getnetinfo(wiz_NetInfo* pnetinfo); + +/** + @ingroup extra_functions + @brief Set the network mode such WOL, PPPoE, Ping Block, and etc. + @param pnetinfo Value of network mode. Refer to @ref netmode_type. +*/ +int8_t wizchip_setnetmode(netmode_type netmode); + +/** + @ingroup extra_functions + @brief Get the network mode such WOL, PPPoE, Ping Block, and etc. + @return Value of network mode. Refer to @ref netmode_type. +*/ +netmode_type wizchip_getnetmode(void); + +/** + @ingroup extra_functions + @brief Set retry time value(@ref _RTR_) and retry count(@ref _RCR_). + @details @ref _RTR_ configures the retransmission timeout period and @ref _RCR_ configures the number of time of retransmission. + @param nettime @ref _RTR_ value and @ref _RCR_ value. Refer to @ref wiz_NetTimeout. +*/ +void wizchip_settimeout(wiz_NetTimeout* nettime); + +/** + @ingroup extra_functions + @brief Get retry time value(@ref _RTR_) and retry count(@ref _RCR_). + @details @ref _RTR_ configures the retransmission timeout period and @ref _RCR_ configures the number of time of retransmission. + @param nettime @ref _RTR_ value and @ref _RCR_ value. Refer to @ref wiz_NetTimeout. +*/ +void wizchip_gettimeout(wiz_NetTimeout* nettime); +//teddy 240122 +#elif ((_WIZCHIP_ == W6100)||(_WIZCHIP_ == W6300)) +/** + @ingroup extra_functions + @brief Set the network information for @ref _WIZCHIP_ + @param pnetinfo : @ref wiz_NetInfo + @sa ctlnetwork(), CN_SET_NETINFO, CN_GET_NETINFO + @sa wizchip_getnetinfo() +*/ +void wizchip_setnetinfo(wiz_NetInfo* pnetinfo); + +/** + @ingroup extra_functions + @brief Get the network information of @ref _WIZCHIP_ + @param pnetinfo : @ref wiz_NetInfo + @sa ctlnetwork(), CN_GET_NETINFO, CN_SET_NETINFO + @sa wizchip_setnetinfo() +*/ +void wizchip_getnetinfo(wiz_NetInfo* pnetinfo); + +/** + @ingroup extra_functions + @brief Set the network mode such as WOL, PPPoE, PING Block, and etc. + @param netmode : @ref netmode_type. + @sa ctlnetwork(), CN_SET_NETMODE, CN_GET_NETMODE + @sa wizchip_getnetmode() +*/ +void wizchip_setnetmode(netmode_type netmode); + +/** + @ingroup extra_functions + @brief Get the network mode such as WOL, PPPoE, PING Block, and etc. + @return @ref netmode_type. + @sa ctlnetwork(), CN_GET_NETMODE, CN_SET_NETMODE + @sa wizchip_setnetmode() +*/ +netmode_type wizchip_getnetmode(void); + +/** + @ingroup extra_functions + @brief Set retransmission time values and retry counts. + @param nettime : @ref wiz_NetTimeout. + @sa ctlnetwork(), CN_SET_TIMEOUT, CN_GET_TIMEOUT + @sa wizchip_gettimeout() +*/ +void wizchip_settimeout(wiz_NetTimeout* nettime); + +/** + @ingroup extra_functions + @brief Get retransmission time values and retry counts. + @param nettime : @ref wiz_NetTimeout. + @sa ctlnetwork(), CN_GET_TIMEOUT, CN_SET_TIMEOUT + @sa wizchip_settimeout() +*/ +void wizchip_gettimeout(wiz_NetTimeout* nettime); + +#endif + +#ifdef __cplusplus +} +#endif + +#endif // _WIZCHIP_CONF_H_ diff --git a/Internet/AAC/AddressAutoConfig.c b/Internet/AAC/AddressAutoConfig.c new file mode 100644 index 0000000..1d3b333 --- /dev/null +++ b/Internet/AAC/AddressAutoConfig.c @@ -0,0 +1,681 @@ +//* **************************************************************************** +//! \file AddressAutoConfig.c +//! \brief IPv6 AddressAutoConfig Source File. +//! \version 1.0.0 +//! \date 2019/01/01 +//! \par Revision history +//! <2019/01/01> 1st Release +//! \author WIZnet +//! \copyright +//! +//! Copyright (c) 2019, WIZnet Co., LTD. +//! +//! Permission is hereby granted, free of charge, to any person obtaining a copy +//! of this software and associated documentation files (the "Software"), to deal +//! in the Software without restriction, including without limitation the rights +//! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +//! copies of the Software, and to permit persons to whom the Software is +//! furnished to do so, subject to the following conditions: +//! +//! The above copyright notice and this permission notice shall be included in +//! all copies or substantial portions of the Software. +//! +//! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +//! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +//! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +//! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +//! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +//! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +//! SOFTWARE. +//! +//***************************************************************************** + +#include "AddressAutoConfig.h" + +#if (_WIZCHIP_ == W6100) + +#define MY_MAX_DHCP6_RETRY 3 +uint8_t AAC_SOCKET; // Socket number for AddressAutoConfi + +/** + @brief + +*/ +extern uint8_t DNS6_Address[16]; + +/** + @brief + + @param netinfo + @param test_buf + @return uint8_t +*/ +uint8_t AddressAutoConfig_Init(uint8_t s, wiz_NetInfo *netinfo) { + uint8_t MO_flag; + uint8_t result_aac = 0; + uint8_t data_buf[2048] = { + 0, + }; + + AAC_SOCKET = s; // SOCK_AAC + + // DAD LLA + printf("Duplicate_Address_Detection\r\n"); + Duplicate_Address_Detection(netinfo); + ctlnetwork(CN_SET_NETINFO, netinfo); + print_network_information(); + + // RSRA + printf("Address_Auto_Configuration Start\r\n"); + MO_flag = Address_Auto_Config_RA(AAC_SOCKET, data_buf, sizeof(data_buf), netinfo); + ctlnetwork(CN_SET_NETINFO, netinfo); + print_network_information(); + + if (MO_flag == SLAAC_RDNSS) { + // Completed + + printf("Address_Auto_Configuration Succeed\r\n"); + result_aac = 1; + } else if (MO_flag == SLAAC_DHCP6) { + // Need Stateless DHCP + // Get Other Information + + printf("Address_Auto_Configuration Failed\r\n"); + printf("Stateless DHCP Start\r\n"); + + memset(data_buf, 0, sizeof(data_buf)); + result_aac = Address_Auto_Config_SLDHCP(AAC_SOCKET, data_buf); + if (result_aac == 1) { + printf(" Stateless DHCP Succeed\r\n"); + } else { + printf(" Stateless DHCP Failed\r\n"); + } + } else if (MO_flag == SFAAC_DHCP6) { + // Need Stateful DHCP + // Get Managed Information + + printf("Address_Auto_Configuration Failed\r\n"); + printf("Stateful DHCP Start\r\n"); + + memset(data_buf, 0, sizeof(data_buf)); + result_aac = Address_Auto_Config_SFDHCP(AAC_SOCKET, data_buf, netinfo); + if (result_aac == 1) { + printf("Stateful DHCP Succeed\r\n"); + } else { + printf("Stateful DHCP Failed\r\n"); + } + + ctlnetwork(CN_SET_NETINFO, netinfo); + print_network_information(); + } else { + printf("Address_Auto_Configuration Failed MO_Flag : 0x%x\r\n", MO_flag); + result_aac = 0; + } + + while (SOCK_OK != close(AAC_SOCKET)); + + return result_aac; +} + +/** + @brief + + @param sn + @param test_buf + @return uint8_t +*/ +uint8_t Address_Auto_Config_SLDHCP(uint8_t sn, uint8_t *test_buf) { + uint8_t result = 0; + uint8_t tmp[16]; + uint32_t toggle = 1; + uint32_t my_dhcp_retry = 0; + + DHCP6_init(sn, test_buf); + + while (1) { + switch (DHCP6_run2()) { + case DHCP6_IP_ASSIGN: + case DHCP6_IP_CHANGED: + /* If this block empty, act with default_ip_assign & default_ip_update */ + // + // This example calls the registered 'my_ip_assign' in the two case. + // + // Add to ... + // + // + toggle = 1; + if (toggle) { + getGAR(tmp); + printf("> DHCP GW : %d.%d.%d.%d\r\n", tmp[0], tmp[1], tmp[2], tmp[3]); + getSUBR(tmp); + printf("> DHCP SN : %d.%d.%d.%d\r\n", tmp[0], tmp[1], tmp[2], tmp[3]); + getSIPR(tmp); + printf("> DHCP IP : %d.%d.%d.%d\r\n", tmp[0], tmp[1], tmp[2], tmp[3]); + toggle = 0; + close(sn); /* + If renewal IP address was defferent previous IP address, + socket becomes to disconnect or close for new connection. +*/ + } + break; + case DHCP6_IP_LEASED: + // + if (toggle) { + getSHAR(tmp); + printf("Mac address : %.2x:%.2x:%.2x:%.2x:%.2x:%.2x \r\n", tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5]); + getLLAR(tmp); + printf("your Link Local IP is %.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x \r\n", tmp[0], tmp[1], tmp[2], tmp[3], + tmp[4], tmp[5], tmp[6], tmp[7], + tmp[8], tmp[9], tmp[10], tmp[11], + tmp[12], tmp[13], tmp[14], tmp[15]); + getGUAR(tmp); + printf("your Global IP is %.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x \r\n", tmp[0], tmp[1], tmp[2], tmp[3], + tmp[4], tmp[5], tmp[6], tmp[7], + tmp[8], tmp[9], tmp[10], tmp[11], + tmp[12], tmp[13], tmp[14], tmp[15]); + getGA6R(tmp); + printf("your Gateway IP is %.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x \r\n", tmp[0], tmp[1], tmp[2], tmp[3], + tmp[4], tmp[5], tmp[6], tmp[7], + tmp[8], tmp[9], tmp[10], tmp[11], + tmp[12], tmp[13], tmp[14], tmp[15]); + + printf("your DNSv6 is %.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x \r\n", DNS6_Address[0], DNS6_Address[1], DNS6_Address[2], DNS6_Address[3], + DNS6_Address[4], DNS6_Address[5], DNS6_Address[6], DNS6_Address[7], + DNS6_Address[8], DNS6_Address[9], DNS6_Address[10], DNS6_Address[11], + DNS6_Address[12], DNS6_Address[13], DNS6_Address[14], DNS6_Address[15]); + toggle = 0; + } + return 1; + + case DHCP6_FAILED: + /* ===== Example pseudo code ===== */ + // The below code can be replaced your code or omitted. + // if omitted, retry to process DHCP + my_dhcp_retry++; + if (my_dhcp_retry > MY_MAX_DHCP6_RETRY) { +#if DEBUG_MODE != DEBUG_NO + printf(">> DHCP %d Failed\r\n", my_dhcp_retry); +#endif + my_dhcp_retry = 0; + DHCP6_stop(); // if restart, recall DHCP6_init() + } + break; + default: + break; + } + } + + return result; +} + +/** + @brief + + @param sn + @param test_buf + @return uint8_t +*/ +uint8_t Address_Auto_Config_SFDHCP(uint8_t sn, uint8_t *test_buf, wiz_NetInfo *netinfo) { + uint8_t result; + uint8_t tmp[16]; + uint32_t toggle = 1; + uint32_t my_dhcp_retry = 0; + + DHCP6_init(sn, test_buf); + + while (1) { + switch (DHCP6_run(netinfo)) { + case DHCP6_IP_ASSIGN: + case DHCP6_IP_CHANGED: + /* If this block empty, act with default_ip_assign & default_ip_update */ + // + // This example calls the registered 'my_ip_assign' in the two case. + // + // Add to ... + // + // + toggle = 1; + if (toggle) { + // getGAR(tmp); printf("> DHCP GW : %d.%d.%d.%d\r\n", tmp[0], tmp[1], tmp[2], tmp[3]); + // getSUBR(tmp); printf("> DHCP SN : %d.%d.%d.%d\r\n", tmp[0], tmp[1], tmp[2], tmp[3]); + // getSIPR(tmp); printf("> DHCP IP : %d.%d.%d.%d\r\n", tmp[0], tmp[1], tmp[2], tmp[3]); + toggle = 0; + close(sn); /* + If renewal IP address was defferent previous IP address, + socket becomes to disconnect or close for new connection. +*/ + } + break; + case DHCP6_IP_LEASED: + // + if (toggle) { + getSHAR(tmp); + printf("Mac address : %.2x:%.2x:%.2x:%.2x:%.2x:%.2x \r\n", tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5]); + getLLAR(tmp); + printf("your Link Local IP is %.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x \r\n", tmp[0], tmp[1], tmp[2], tmp[3], + tmp[4], tmp[5], tmp[6], tmp[7], + tmp[8], tmp[9], tmp[10], tmp[11], + tmp[12], tmp[13], tmp[14], tmp[15]); + getGUAR(tmp); + printf("your Global IP is %.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x \r\n", tmp[0], tmp[1], tmp[2], tmp[3], + tmp[4], tmp[5], tmp[6], tmp[7], + tmp[8], tmp[9], tmp[10], tmp[11], + tmp[12], tmp[13], tmp[14], tmp[15]); + getGA6R(tmp); + printf("your Gateway IP is %.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x \r\n", tmp[0], tmp[1], tmp[2], tmp[3], + tmp[4], tmp[5], tmp[6], tmp[7], + tmp[8], tmp[9], tmp[10], tmp[11], + tmp[12], tmp[13], tmp[14], tmp[15]); + + printf("your DNSv6 is %.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x \r\n", DNS6_Address[0], DNS6_Address[1], DNS6_Address[2], DNS6_Address[3], + DNS6_Address[4], DNS6_Address[5], DNS6_Address[6], DNS6_Address[7], + DNS6_Address[8], DNS6_Address[9], DNS6_Address[10], DNS6_Address[11], + DNS6_Address[12], DNS6_Address[13], DNS6_Address[14], DNS6_Address[15]); + toggle = 0; + } + return 1; + + case DHCP6_FAILED: + /* ===== Example pseudo code ===== */ + // The below code can be replaced your code or omitted. + // if omitted, retry to process DHCP + my_dhcp_retry++; + if (my_dhcp_retry > MY_MAX_DHCP6_RETRY) { +#if DEBUG_MODE != DEBUG_NO + printf(">> DHCP %d Failed\r\n", my_dhcp_retry); +#endif + my_dhcp_retry = 0; + DHCP6_stop(); // if restart, recall DHCP6_init() + return 0; + } + break; + default: + break; + } + } + + return result; +} + +/** + @brief + + @param sn + @param icmpbuf + @param buf_size + @param netinfo + @return uint8_t +*/ +uint8_t Address_Auto_Config_RA(uint8_t sn, uint8_t *icmpbuf, uint16_t buf_size, wiz_NetInfo *netinfo) { + uint8_t result; + + volatile uint16_t size; + uint8_t destip[16]; + uint16_t destport; + uint8_t addr_len, o_len; + uint8_t flags; + + uint8_t *p; + uint8_t *e; + int i; + uint8_t o_type, type, code, RA_flag, MO_flag; //, O_flag; + uint16_t Router_lifetime; + uint32_t Reachable_time, Retrans_time; + uint32_t end_point; + uint8_t prefix_len, pi_flag; + uint32_t validtime, prefertime, dnstime; + uint8_t prefix[16]; + + if (getSLCR() != 0x00) { //check clear CMD +#if (AutoConfig_debug == debug_on) + printf("ERROR : RQCMD is not clear\r\n"); +#endif + result = ERROR_SLCMD; + return result; + } + + setICMP6BLKR(ICMP6BLKR_RA); + printf("getICMP6BLKR() = 0x%x\r\n", getICMP6BLKR()); // 0X4 + + setSn_PNR(sn, PROTOCOL_NUM_ICMPv6); //ICMPv6 : 58 + printf("getSn_PROTOR(%d) = 0x%x\r\n", sn, getSn_PNR(sn)); // 0X3a + + socket(sn, Sn_MR_IPRAW6, 0, 0); + +#if 1 + printf("Sn_SR : %x \r\n", getSn_SR(sn)); // 0X21 33 +#else +#if (AutoConfig_debug == debug_on) + printf("Sn_SR : %x \r\n", getSn_SR(sn)); +#endif +#endif + + setSLRTR(4000); + printf("getSLRTR() = 0x%x\r\n", getSLRTR()); // 0xfa0 4000 + + setSLRCR(0); + printf("getSLRCR() = 0x%x\r\n", getSLRCR()); // 0 + + setSLCR(SLCR_RS); + printf("getSLCR() = 0x%x\r\n", getSLCR()); // 0 + printf("getSLIR() = 0x%x\r\n", getSLIR()); // 0 +#if (AutoConfig_debug == debug_on) + printf("Wait SLIR.....\r\n"); +#endif + + do { + if (getSn_RX_RSR(sn) > 0) { + printf("getSLIR() = 0x%x\r\n", getSLIR()); // 0 + + printf("getSn_RX_RSR(%d) = 0x%x\r\n", sn, getSn_RX_RSR(sn)); // 0x4a 74 + printf("size : %d \r\n", sizeof(icmpbuf)); + size = recvfrom(sn, icmpbuf, buf_size, destip, &destport, &addr_len); + printf("recvfrom IP : %x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x \r\n", destip[0], destip[1], destip[2], destip[3], destip[4], destip[5], destip[6], destip[7], destip[8], destip[9], destip[10], destip[11], destip[12], destip[13], destip[14], destip[15]); + // ================================================= + // 20190402 + // Taylor + // + // Set Gateway from source + memcpy(netinfo->gw6, destip, 16); + + // ================================================= + } + + p = icmpbuf; + } while (*p != ROUTER_ADVERTISEMENT); + + e = p + size; + switch (*p) { + case ROUTER_ADVERTISEMENT: + printf("RA\r\n"); + type = *p++; + printf("type : %x \r\n", type); + code = *p++; + printf("code : %x \r\n", code); + p++; + p++; //checksum + p++; //Cur hop limit + RA_flag = *p++; + printf("RA_flag : %x \r\n", RA_flag); + Router_lifetime = *p++ << 8; + Router_lifetime = Router_lifetime + (*p++); + printf("Router_lifetime : %d s \r\n", Router_lifetime); + Reachable_time = *p++ << 24; + Reachable_time = Reachable_time + (*p++ << 16); + Reachable_time = Reachable_time + (*p++ << 8); + Reachable_time = Reachable_time + (*p++); + printf("Reachable_time : %d ms \r\n", Reachable_time); + Retrans_time = *p++ << 24; + Retrans_time = Retrans_time + (*p++ << 16); + Retrans_time = Retrans_time + (*p++ << 8); + Retrans_time = Retrans_time + (*p++); + printf("Retrans_time : %d ms \r\n", Retrans_time); + + while (p < e) { + switch (*p) { + case RAO_SLLA: + o_type = *p++; + printf("Option Type : %d (Source LLA) \r\n", o_type); + o_len = (*p++) * 8; + printf("Option length : %d \r\n", o_len); + p += (o_len - 2); + break; + case RAO_TLLA: + o_type = *p++; + printf("Option Type : %d (Target LLA) \r\n", o_type); + o_len = (*p++) * 8; + printf("Option length : %d \r\n", o_len); + p += (o_len - 2); + break; + case RAO_PI: + o_type = *p++; + printf("Option Type : %d (Prefix information) \r\n", o_type); + o_len = (*p++) * 8; + printf("Option length : %d \r\n", o_len); + end_point = (uint32_t)p - 2 + o_len; + prefix_len = *p++; + printf("Prefix Length : %d \r\n", prefix_len); + pi_flag = *p++; + printf("Prefix Information Flag : %.2x \r\n", pi_flag); + validtime = (*p++ << 24); + validtime += (*p++ << 16); + validtime += (*p++ << 8); + validtime += (*p++); + printf("valid lifetime : %d \r\n", validtime); + prefertime = (*p++ << 24); + prefertime += (*p++ << 16); + prefertime += (*p++ << 8); + prefertime += (*p++); + printf("preferred lifetime : %d \r\n", prefertime); + p++; + p++; + p++; + p++; //reserved + getLLAR(prefix); + for (int i = 0; i < prefix_len / 8; i++) { + prefix[i] = *p++; + + // ================================================= + // 20190416 + // Taylor + // + // Set Subnet Mask from prefix + + netinfo->sn6[i] = 0xFF; + + // ================================================= + } + + memcpy(netinfo->gua, prefix, 16); + + while ((uint32_t)p != end_point) { + p++; + } + printf("prefix : "); + for (i = 0; i < prefix_len / 8; i++) { + printf("%.2x", prefix[i]); + if (1 == (i % 2)) { + printf(":"); + } + } + printf(":\r\n"); + break; + case RAO_RH: + o_type = *p++; + printf("Option Type : %d (Redirected Header) \r\n", o_type); + o_len = (*p++) * 8; + printf("Option length : %d \r\n", o_len); + p += (o_len - 2); + break; + case RAO_MTU: + o_type = *p++; + printf("Option Type : %d (MTU) \r\n", o_type); + o_len = (*p++) * 8; + printf("Option length : %d \r\n", o_len); + p += (o_len - 2); + break; + case RAO_RDNS: + o_type = *p++; + printf("Option Type : %d (Recursive DNS Server) \r\n", o_type); + o_len = (*p++) * 8; + printf("Option length : %d \r\n", o_len); + end_point = (uint32_t)p - 2 + o_len; + p++; + p++; //reserved + dnstime = (*p++ << 24); + dnstime += (*p++ << 16); + dnstime += (*p++ << 8); + dnstime += (*p++); + printf("DNS lifetime : %d \r\n", dnstime); + DNS6_Address[0] = *p++; + DNS6_Address[1] = *p++; + DNS6_Address[2] = *p++; + DNS6_Address[3] = *p++; + DNS6_Address[4] = *p++; + DNS6_Address[5] = *p++; + DNS6_Address[6] = *p++; + DNS6_Address[7] = *p++; + DNS6_Address[8] = *p++; + DNS6_Address[9] = *p++; + DNS6_Address[10] = *p++; + DNS6_Address[11] = *p++; + DNS6_Address[12] = *p++; + DNS6_Address[13] = *p++; + DNS6_Address[14] = *p++; + DNS6_Address[15] = *p++; + while ((uint32_t)p != end_point) { + p++; + } + printf("DNS IP : "); + for (i = 0; i < 15; i++) { + printf("%.2x", DNS6_Address[i]); + if (1 == (i % 2)) { + printf(":"); + } + } + printf("%x\r\n", DNS6_Address[15]); + break; + default: + printf("default\r\n"); + o_type = *p++; + printf("o_type : %d \r\n", o_type); + o_len = (*p++) * 8; + printf("o_len : %d \r\n", o_len); +#if 1 + // 20231106 taylor + if (o_len > 0) { + p += (o_len - 2); + } else { + p ++; + } +#else + p += (o_len - 2); +#endif + break; + } // ICMP option + } //while + } + + close(sn); + + printf("RA : %x \r\n", RA_flag); + + //M_flag = RA_flag >> 7; + MO_flag = RA_flag >> 6; + + printf("MO : %x \r\n", MO_flag); + + result = MO_flag; + + return result; +} + +/** + @brief + + @param netinfo + @return uint8_t +*/ +uint8_t Duplicate_Address_Detection(wiz_NetInfo *netinfo) { + uint8_t result; + + uint8_t WIZ_LLA[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + + uint8_t flags; + uint8_t tmp_array[16]; + uint16_t i; + + setSLRTR(2000); + setSLRCR(5); + + Generate_EUI64(netinfo->mac, WIZ_LLA); + + setSLDIP6R(WIZ_LLA); //target address setting + + //setSLIMR(SLIR_TIOUT|SLIR_NS); //only external interrupt??? + + if (getSLCR() != 0x00) { //check clear CMD +#if (AutoConfig_debug == debug_on) + printf("ERROR : RQCMD is not clear %x \r\n", getSLCR()); +#endif + while (1) + ; + } + + setSLCR(SLCR_NS); + +#if (AutoConfig_debug == debug_on) + printf("Wait RQIR.....\r\n"); +#endif + + do { + flags = getSLIR(); + + if (flags & SLIR_TOUT) { +#if (AutoConfig_debug == debug_on) + printf("\r\nTimeout !!! DAD SUCCESSED\r\n"); +#endif +#if 0 + // 20190401 + NETCFG_UNLOCK(); +#endif + //-- Set Link Local Address + memcpy(netinfo->lla, WIZ_LLA, 16); + +#if 0 + // 20190404 + // Display memcpy result + + printf("WIZ_LLA:\r\n"); + for (i = 0; i < 16; i += 2) { + printf("%.2x%.2x:", WIZ_LLA[i], WIZ_LLA[i + 1]); + } + printf("\r\n"); + + printf("netinfo->mac:\r\n"); + for (i = 0; i < 16; i += 2) { + printf("%.2x%.2x:", netinfo->lla[i], netinfo->lla[i + 1]); + } + printf("\r\n"); +#endif + +#if 0 + // 20190401 + NETCFG_LOCK(); +#endif + result = SUCCESS; + } else if (flags & SLIR_NS) { +#if (AutoConfig_debug == debug_on) + printf("\r\nReceived NA !!! DAD FAILED\r\n"); +#endif + result = ERROR_DAD_FAIL; + } + } while (!((flags & SLIR_TOUT) || (flags & SLIR_NS))); + printf("\r\nflags = 0x%x\r\n", flags); + setSLIRCLR(flags); + + return result; +} + +/** + @brief + + @param mac_addr + @param Link_Local_Addr +*/ +void Generate_EUI64(uint8_t *mac_addr, uint8_t *Link_Local_Addr) { + *Link_Local_Addr = 0xfe; + *(Link_Local_Addr + 1) = 0x80; + //00:00:00:00:00:00 + *(Link_Local_Addr + 8) = *(mac_addr); //flip the 7th bit of 1st byte + *(Link_Local_Addr + 8) ^= 1 << 1; + *(Link_Local_Addr + 9) = *(mac_addr + 1); + *(Link_Local_Addr + 10) = *(mac_addr + 2); + *(Link_Local_Addr + 11) = 0xFF; + *(Link_Local_Addr + 12) = 0xFE; + *(Link_Local_Addr + 13) = *(mac_addr + 3); + *(Link_Local_Addr + 14) = *(mac_addr + 4); + *(Link_Local_Addr + 15) = *(mac_addr + 5); +} + +#endif diff --git a/Internet/AAC/AddressAutoConfig.h b/Internet/AAC/AddressAutoConfig.h new file mode 100644 index 0000000..934e284 --- /dev/null +++ b/Internet/AAC/AddressAutoConfig.h @@ -0,0 +1,133 @@ +//* **************************************************************************** +//! \file AddressAutoConfig.h +//! \brief IPv6 AddressAutoConfig Header File. +//! \version 1.0.0 +//! \date 2019/01/01 +//! \par Revision history +//! <2019/01/01> 1st Release +//! \author WIZnet +//! \copyright +//! +//! Copyright (c) 2019, WIZnet Co., LTD. +//! +//! Permission is hereby granted, free of charge, to any person obtaining a copy +//! of this software and associated documentation files (the "Software"), to deal +//! in the Software without restriction, including without limitation the rights +//! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +//! copies of the Software, and to permit persons to whom the Software is +//! furnished to do so, subject to the following conditions: +//! +//! The above copyright notice and this permission notice shall be included in +//! all copies or substantial portions of the Software. +//! +//! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +//! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +//! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +//! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +//! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +//! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +//! SOFTWARE. +//! +//***************************************************************************** + +#ifndef _ADDRESSAUTOCONFIG_H_ +#define _ADDRESSAUTOCONFIG_H_ + +#include "stdio.h" +#include "stdint.h" +#if 1 +// 20231020 taylor +#if 0 +#endif +#else +#include "w6100.h" +#endif +#include "socket.h" +#if 1 +// 20231020 taylor +#include "../DHCP6/dhcpv6.h" +#else +#include "dhcpv6.h" +#endif + +#if (_WIZCHIP_ == W6100) + +#define AutoConfig_debug debug_on +#define debug_on 1 +#define debug_off 0 + +#define PROTOCOL_NUM_ICMPv6 58 + +#define ROUTER_ADVERTISEMENT 134 + +#define SUCCESS 0 +#define ERROR_DAD_FAIL -1 +#define ERROR_SLCMD -2 +#define ERROR_TIMEOUT -3 + +#define SLAAC_RDNSS 0 +#define SLAAC_DHCP6 1 +#define SFAAC_DHCP6 3 + +#define RAO_SLLA 1 +#define RAO_TLLA 2 +#define RAO_PI 3 +#define RAO_RH 4 +#define RAO_MTU 5 +#define RAO_RDNS 25 + +/** + @brief + + @param netinfo + @return uint8_t +*/ +uint8_t AddressAutoConfig_Init(uint8_t s, wiz_NetInfo* netinfo); + +/** + @brief + + @param mac_addr + @param Link_Local_Addr +*/ +void Generate_EUI64(uint8_t *mac_addr, uint8_t *Link_Local_Addr); + +/** + @brief + + @param netinfo + @return uint8_t +*/ +uint8_t Duplicate_Address_Detection(wiz_NetInfo* netinfo); + +/** + @brief + + @param sn + @param icmpbuf + @param buf_size + @param netinfo + @return uint8_t +*/ +uint8_t Address_Auto_Config_RA(uint8_t sn, uint8_t *icmpbuf, uint16_t buf_size, wiz_NetInfo* netinfo); + +/** + @brief + + @param sn + @param test_buf + @return uint8_t +*/ +uint8_t Address_Auto_Config_SLDHCP(uint8_t sn, uint8_t* test_buf); + +/** + @brief + + @param sn + @param test_buf + @return uint8_t +*/ +uint8_t Address_Auto_Config_SFDHCP(uint8_t sn, uint8_t* test_buf, wiz_NetInfo* netinfo); + +#endif +#endif // _ADDRESSAUTOCONFIG_H_ diff --git a/Internet/DHCP/dhcp.c b/Internet/DHCP/dhcp.c new file mode 100644 index 0000000..3925ca8 --- /dev/null +++ b/Internet/DHCP/dhcp.c @@ -0,0 +1,1118 @@ +//***************************************************************************** +// +//! \file dhcp.c +//! \brief DHCP APIs implement file. +//! \details Processing DHCP protocol as DISCOVER, OFFER, REQUEST, ACK, NACK and DECLINE. +//! \version 1.1.1 +//! \date 2019/10/08 +//! \par Revision history +//! <2019/10/08> compare DHCP server ip address +//! <2013/11/18> 1st Release +//! <2012/12/20> V1.1.0 +//! 1. Optimize code +//! 2. Add reg_dhcp_cbfunc() +//! 3. Add DHCP_stop() +//! 4. Integrate check_DHCP_state() & DHCP_run() to DHCP_run() +//! 5. Don't care system endian +//! 6. Add comments +//! <2012/12/26> V1.1.1 +//! 1. Modify variable declaration: dhcp_tick_1s is declared volatile for code optimization +//! \author Eric Jung & 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. +// +//***************************************************************************** + +#include "socket.h" +#include "dhcp.h" + +/* If you want to display debug & processing message, Define _DHCP_DEBUG_ in dhcp.h */ + +#ifdef _DHCP_DEBUG_ +#include +#endif + +/* DHCP state machine. */ +#define STATE_DHCP_INIT 0 ///< Initialize +#define STATE_DHCP_DISCOVER 1 ///< send DISCOVER and wait OFFER +#define STATE_DHCP_REQUEST 2 ///< send REQEUST and wait ACK or NACK +#define STATE_DHCP_LEASED 3 ///< ReceiveD ACK and IP leased +#define STATE_DHCP_REREQUEST 4 ///< send REQUEST for maintaining leased IP +#define STATE_DHCP_RELEASE 5 ///< No use +#define STATE_DHCP_STOP 6 ///< Stop processing DHCP + +#define DHCP_FLAGSBROADCAST 0x8000 ///< The broadcast value of flags in @ref RIP_MSG +#define DHCP_FLAGSUNICAST 0x0000 ///< The unicast value of flags in @ref RIP_MSG + +/* DHCP message OP code */ +#define DHCP_BOOTREQUEST 1 ///< Request Message used in op of @ref RIP_MSG +#define DHCP_BOOTREPLY 2 ///< Reply Message used i op of @ref RIP_MSG + +/* DHCP message type */ +#define DHCP_DISCOVER 1 ///< DISCOVER message in OPT of @ref RIP_MSG +#define DHCP_OFFER 2 ///< OFFER message in OPT of @ref RIP_MSG +#define DHCP_REQUEST 3 ///< REQUEST message in OPT of @ref RIP_MSG +#define DHCP_DECLINE 4 ///< DECLINE message in OPT of @ref RIP_MSG +#define DHCP_ACK 5 ///< ACK message in OPT of @ref RIP_MSG +#define DHCP_NAK 6 ///< NACK message in OPT of @ref RIP_MSG +#define DHCP_RELEASE 7 ///< RELEASE message in OPT of @ref RIP_MSG. No use +#define DHCP_INFORM 8 ///< INFORM message in OPT of @ref RIP_MSG. No use + +#define DHCP_HTYPE10MB 1 ///< Used in type of @ref RIP_MSG +#define DHCP_HTYPE100MB 2 ///< Used in type of @ref RIP_MSG + +#define DHCP_HLENETHERNET 6 ///< Used in hlen of @ref RIP_MSG +#define DHCP_HOPS 0 ///< Used in hops of @ref RIP_MSG +#define DHCP_SECS 0 ///< Used in secs of @ref RIP_MSG + +#define INFINITE_LEASETIME 0xffffffff ///< Infinite lease time + +#define OPT_SIZE 312 /// Max OPT size of @ref RIP_MSG +#define RIP_MSG_SIZE (236+OPT_SIZE) /// Max size of @ref RIP_MSG + +/* + @brief DHCP option and value (cf. RFC1533) +*/ +enum { + padOption = 0, + subnetMask = 1, + timerOffset = 2, + routersOnSubnet = 3, + timeServer = 4, + nameServer = 5, + dns = 6, + logServer = 7, + cookieServer = 8, + lprServer = 9, + impressServer = 10, + resourceLocationServer = 11, + hostName = 12, + bootFileSize = 13, + meritDumpFile = 14, + domainName = 15, + swapServer = 16, + rootPath = 17, + extentionsPath = 18, + IPforwarding = 19, + nonLocalSourceRouting = 20, + policyFilter = 21, + maxDgramReasmSize = 22, + defaultIPTTL = 23, + pathMTUagingTimeout = 24, + pathMTUplateauTable = 25, + ifMTU = 26, + allSubnetsLocal = 27, + broadcastAddr = 28, + performMaskDiscovery = 29, + maskSupplier = 30, + performRouterDiscovery = 31, + routerSolicitationAddr = 32, + staticRoute = 33, + trailerEncapsulation = 34, + arpCacheTimeout = 35, + ethernetEncapsulation = 36, + tcpDefaultTTL = 37, + tcpKeepaliveInterval = 38, + tcpKeepaliveGarbage = 39, + nisDomainName = 40, + nisServers = 41, + ntpServers = 42, + vendorSpecificInfo = 43, + netBIOSnameServer = 44, + netBIOSdgramDistServer = 45, + netBIOSnodeType = 46, + netBIOSscope = 47, + xFontServer = 48, + xDisplayManager = 49, + dhcpRequestedIPaddr = 50, + dhcpIPaddrLeaseTime = 51, + dhcpOptionOverload = 52, + dhcpMessageType = 53, + dhcpServerIdentifier = 54, + dhcpParamRequest = 55, + dhcpMsg = 56, + dhcpMaxMsgSize = 57, + dhcpT1value = 58, + dhcpT2value = 59, + dhcpClassIdentifier = 60, + dhcpClientIdentifier = 61, + endOption = 255 +}; + +/* + @brief DHCP message format +*/ +typedef struct { + uint8_t op; ///< @ref DHCP_BOOTREQUEST or @ref DHCP_BOOTREPLY + uint8_t htype; ///< @ref DHCP_HTYPE10MB or @ref DHCP_HTYPE100MB + uint8_t hlen; ///< @ref DHCP_HLENETHERNET + uint8_t hops; ///< @ref DHCP_HOPS + uint32_t xid; ///< @ref DHCP_XID This increase one every DHCP transaction. + uint16_t secs; ///< @ref DHCP_SECS + uint16_t flags; ///< @ref DHCP_FLAGSBROADCAST or @ref DHCP_FLAGSUNICAST + uint8_t ciaddr[4]; ///< @ref Request IP to DHCP sever + uint8_t yiaddr[4]; ///< @ref Offered IP from DHCP server + uint8_t siaddr[4]; ///< No use + uint8_t giaddr[4]; ///< No use + uint8_t chaddr[16]; ///< DHCP client 6bytes MAC address. Others is filled to zero + uint8_t sname[64]; ///< No use + uint8_t file[128]; ///< No use + uint8_t OPT[OPT_SIZE]; ///< Option +} RIP_MSG; + + + +uint8_t DHCP_SOCKET; // Socket number for DHCP + +uint8_t DHCP_SIP[4]; // DHCP Server IP address +uint8_t DHCP_REAL_SIP[4]; // For extract my DHCP server in a few DHCP server + +// Network information from DHCP Server +uint8_t OLD_allocated_ip[4] = {0, }; // Previous IP address +uint8_t DHCP_allocated_ip[4] = {0, }; // IP address from DHCP +uint8_t DHCP_allocated_gw[4] = {0, }; // Gateway address from DHCP +uint8_t DHCP_allocated_sn[4] = {0, }; // Subnet mask from DHCP +uint8_t DHCP_allocated_dns[4] = {0, }; // DNS address from DHCP + + +int8_t dhcp_state = STATE_DHCP_INIT; // DHCP state +int8_t dhcp_retry_count = 0; + +uint32_t dhcp_lease_time = INFINITE_LEASETIME; +volatile uint32_t dhcp_tick_1s = 0; // unit 1 second +uint32_t dhcp_tick_next = DHCP_WAIT_TIME ; + +uint32_t DHCP_XID; // Any number + +RIP_MSG* pDHCPMSG; // Buffer pointer for DHCP processing + +uint8_t HOST_NAME[] = DCHP_HOST_NAME; + +uint8_t DHCP_CHADDR[6]; // DHCP Client MAC address. + +/* The default callback function */ +void default_ip_assign(void); +void default_ip_update(void); +void default_ip_conflict(void); + +/* Callback handler */ +void (*dhcp_ip_assign)(void) = default_ip_assign; /* handler to be called when the IP address from DHCP server is first assigned */ +void (*dhcp_ip_update)(void) = default_ip_update; /* handler to be called when the IP address from DHCP server is updated */ +void (*dhcp_ip_conflict)(void) = default_ip_conflict; /* handler to be called when the IP address from DHCP server is conflict */ + +void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void)); + +char NibbleToHex(uint8_t nibble); + +/* send DISCOVER message to DHCP server */ +void send_DHCP_DISCOVER(void); + +/* send REQEUST message to DHCP server */ +void send_DHCP_REQUEST(void); + +/* send DECLINE message to DHCP server */ +void send_DHCP_DECLINE(void); + +/* IP conflict check by sending ARP-request to leased IP and wait ARP-response. */ +int8_t check_DHCP_leasedIP(void); + +/* check the timeout in DHCP process */ +uint8_t check_DHCP_timeout(void); + +/* Initialize to timeout process. */ +void reset_DHCP_timeout(void); + +/* Parse message as OFFER and ACK and NACK from DHCP server.*/ +int8_t parseDHCPCMSG(void); + +/* The default handler of ip assign first */ +void default_ip_assign(void) { + setSIPR(DHCP_allocated_ip); + setSUBR(DHCP_allocated_sn); + setGAR (DHCP_allocated_gw); +} + +/* The default handler of ip changed */ +void default_ip_update(void) { + /* WIZchip Software Reset */ +#if 1 + // 20231019 taylor//teddy 240122 +#if (_WIZCHIP_ == 6100)||(_WIZCHIP_ == 6300) + CHIPUNLOCK(); + setSYCR0(SYCR0_RST); + CHIPLOCK(); + getSYSR(); +#else + setMR(MR_RST); + getMR(); // for delay +#endif +#else + setMR(MR_RST); + getMR(); // for delay +#endif + default_ip_assign(); +#if _WIZCHIP_ == W6100 + NETUNLOCK(); + setSHAR(DHCP_CHADDR); + NETLOCK(); +#else + setSHAR(DHCP_CHADDR); +#endif +} + +/* The default handler of ip changed */ +void default_ip_conflict(void) { + // WIZchip Software Reset +#if 1 + // 20231019 taylor//teddy 240122 +#if (_WIZCHIP_ == 6100)||(_WIZCHIP_ == 6300) + // 20231019 taylor + CHIPUNLOCK(); + setSYCR0(SYCR0_RST); + CHIPLOCK(); + getSYSR(); +#else + setMR(MR_RST); + getMR(); // for delay +#endif +#else + setMR(MR_RST); + getMR(); // for delay +#endif +#if _WIZCHIP_ == W6100 + NETUNLOCK(); + setSHAR(DHCP_CHADDR); + NETLOCK(); +#else + setSHAR(DHCP_CHADDR); +#endif +} + +/* register the call back func. */ +void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void)) { + dhcp_ip_assign = default_ip_assign; + dhcp_ip_update = default_ip_update; + dhcp_ip_conflict = default_ip_conflict; + if (ip_assign) { + dhcp_ip_assign = ip_assign; + } + if (ip_update) { + dhcp_ip_update = ip_update; + } + if (ip_conflict) { + dhcp_ip_conflict = ip_conflict; + } +} + +/* make the common DHCP message */ +void makeDHCPMSG(void) { + uint8_t bk_mac[6]; + uint8_t* ptmp; + uint8_t i; + getSHAR(bk_mac); + pDHCPMSG->op = DHCP_BOOTREQUEST; + pDHCPMSG->htype = DHCP_HTYPE10MB; + pDHCPMSG->hlen = DHCP_HLENETHERNET; + pDHCPMSG->hops = DHCP_HOPS; + ptmp = (uint8_t*)(&pDHCPMSG->xid); + *(ptmp + 0) = (uint8_t)((DHCP_XID & 0xFF000000) >> 24); + *(ptmp + 1) = (uint8_t)((DHCP_XID & 0x00FF0000) >> 16); + *(ptmp + 2) = (uint8_t)((DHCP_XID & 0x0000FF00) >> 8); + *(ptmp + 3) = (uint8_t)((DHCP_XID & 0x000000FF) >> 0); + pDHCPMSG->secs = DHCP_SECS; + ptmp = (uint8_t*)(&pDHCPMSG->flags); + *(ptmp + 0) = (uint8_t)((DHCP_FLAGSBROADCAST & 0xFF00) >> 8); + *(ptmp + 1) = (uint8_t)((DHCP_FLAGSBROADCAST & 0x00FF) >> 0); + + pDHCPMSG->ciaddr[0] = 0; + pDHCPMSG->ciaddr[1] = 0; + pDHCPMSG->ciaddr[2] = 0; + pDHCPMSG->ciaddr[3] = 0; + + pDHCPMSG->yiaddr[0] = 0; + pDHCPMSG->yiaddr[1] = 0; + pDHCPMSG->yiaddr[2] = 0; + pDHCPMSG->yiaddr[3] = 0; + + pDHCPMSG->siaddr[0] = 0; + pDHCPMSG->siaddr[1] = 0; + pDHCPMSG->siaddr[2] = 0; + pDHCPMSG->siaddr[3] = 0; + + pDHCPMSG->giaddr[0] = 0; + pDHCPMSG->giaddr[1] = 0; + pDHCPMSG->giaddr[2] = 0; + pDHCPMSG->giaddr[3] = 0; + + pDHCPMSG->chaddr[0] = DHCP_CHADDR[0]; + pDHCPMSG->chaddr[1] = DHCP_CHADDR[1]; + pDHCPMSG->chaddr[2] = DHCP_CHADDR[2]; + pDHCPMSG->chaddr[3] = DHCP_CHADDR[3]; + pDHCPMSG->chaddr[4] = DHCP_CHADDR[4]; + pDHCPMSG->chaddr[5] = DHCP_CHADDR[5]; + + for (i = 6; i < 16; i++) { + pDHCPMSG->chaddr[i] = 0; + } + for (i = 0; i < 64; i++) { + pDHCPMSG->sname[i] = 0; + } + for (i = 0; i < 128; i++) { + pDHCPMSG->file[i] = 0; + } + + // MAGIC_COOKIE + pDHCPMSG->OPT[0] = (uint8_t)((MAGIC_COOKIE & 0xFF000000) >> 24); + pDHCPMSG->OPT[1] = (uint8_t)((MAGIC_COOKIE & 0x00FF0000) >> 16); + pDHCPMSG->OPT[2] = (uint8_t)((MAGIC_COOKIE & 0x0000FF00) >> 8); + pDHCPMSG->OPT[3] = (uint8_t) (MAGIC_COOKIE & 0x000000FF) >> 0; +} + +/* SEND DHCP DISCOVER */ +void send_DHCP_DISCOVER(void) { + uint16_t i; + uint8_t ip[4]; + uint16_t k = 0; + + makeDHCPMSG(); + DHCP_SIP[0] = 0; + DHCP_SIP[1] = 0; + DHCP_SIP[2] = 0; + DHCP_SIP[3] = 0; + DHCP_REAL_SIP[0] = 0; + DHCP_REAL_SIP[1] = 0; + DHCP_REAL_SIP[2] = 0; + DHCP_REAL_SIP[3] = 0; + + k = 4; // because MAGIC_COOKIE already made by makeDHCPMSG() + + // Option Request Param + pDHCPMSG->OPT[k++] = dhcpMessageType; + pDHCPMSG->OPT[k++] = 0x01; + pDHCPMSG->OPT[k++] = DHCP_DISCOVER; + + // Client identifier + pDHCPMSG->OPT[k++] = dhcpClientIdentifier; + pDHCPMSG->OPT[k++] = 0x07; + pDHCPMSG->OPT[k++] = 0x01; + pDHCPMSG->OPT[k++] = DHCP_CHADDR[0]; + pDHCPMSG->OPT[k++] = DHCP_CHADDR[1]; + pDHCPMSG->OPT[k++] = DHCP_CHADDR[2]; + pDHCPMSG->OPT[k++] = DHCP_CHADDR[3]; + pDHCPMSG->OPT[k++] = DHCP_CHADDR[4]; + pDHCPMSG->OPT[k++] = DHCP_CHADDR[5]; + + // host name + pDHCPMSG->OPT[k++] = hostName; + pDHCPMSG->OPT[k++] = 0; // fill zero length of hostname + for (i = 0 ; HOST_NAME[i] != 0; i++) { + pDHCPMSG->OPT[k++] = HOST_NAME[i]; + } + pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[3] >> 4); + pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[3]); + pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[4] >> 4); + pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[4]); + pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[5] >> 4); + pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[5]); + pDHCPMSG->OPT[k - (i + 6 + 1)] = i + 6; // length of hostname + + pDHCPMSG->OPT[k++] = dhcpParamRequest; + pDHCPMSG->OPT[k++] = 0x06; // length of request + pDHCPMSG->OPT[k++] = subnetMask; + pDHCPMSG->OPT[k++] = routersOnSubnet; + pDHCPMSG->OPT[k++] = dns; + pDHCPMSG->OPT[k++] = domainName; + pDHCPMSG->OPT[k++] = dhcpT1value; + pDHCPMSG->OPT[k++] = dhcpT2value; + pDHCPMSG->OPT[k++] = endOption; + + for (i = k; i < OPT_SIZE; i++) { + pDHCPMSG->OPT[i] = 0; + } + + // send broadcasting packet + ip[0] = 255; + ip[1] = 255; + ip[2] = 255; + ip[3] = 255; + +#ifdef _DHCP_DEBUG_ + printf("> Send DHCP_DISCOVER\r\n"); +#endif + +#if 1 + // 20231016 taylor//teddy 240122 +#if ((_WIZCHIP_ == 6100)|| (_WIZCHIP_ == 6300)) + sendto(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT, 4); +#else + sendto(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT); +#endif +#else + sendto(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT); +#endif +} + +/* SEND DHCP REQUEST */ +void send_DHCP_REQUEST(void) { + int i; + uint8_t ip[4]; + uint16_t k = 0; + + makeDHCPMSG(); + + if (dhcp_state == STATE_DHCP_LEASED || dhcp_state == STATE_DHCP_REREQUEST) { + *((uint8_t*)(&pDHCPMSG->flags)) = ((DHCP_FLAGSUNICAST & 0xFF00) >> 8); + *((uint8_t*)(&pDHCPMSG->flags) +1) = (DHCP_FLAGSUNICAST & 0x00FF); + pDHCPMSG->ciaddr[0] = DHCP_allocated_ip[0]; + pDHCPMSG->ciaddr[1] = DHCP_allocated_ip[1]; + pDHCPMSG->ciaddr[2] = DHCP_allocated_ip[2]; + pDHCPMSG->ciaddr[3] = DHCP_allocated_ip[3]; + ip[0] = DHCP_SIP[0]; + ip[1] = DHCP_SIP[1]; + ip[2] = DHCP_SIP[2]; + ip[3] = DHCP_SIP[3]; + } else { + ip[0] = 255; + ip[1] = 255; + ip[2] = 255; + ip[3] = 255; + } + + k = 4; // because MAGIC_COOKIE already made by makeDHCPMSG() + + // Option Request Param. + pDHCPMSG->OPT[k++] = dhcpMessageType; + pDHCPMSG->OPT[k++] = 0x01; + pDHCPMSG->OPT[k++] = DHCP_REQUEST; + + pDHCPMSG->OPT[k++] = dhcpClientIdentifier; + pDHCPMSG->OPT[k++] = 0x07; + pDHCPMSG->OPT[k++] = 0x01; + pDHCPMSG->OPT[k++] = DHCP_CHADDR[0]; + pDHCPMSG->OPT[k++] = DHCP_CHADDR[1]; + pDHCPMSG->OPT[k++] = DHCP_CHADDR[2]; + pDHCPMSG->OPT[k++] = DHCP_CHADDR[3]; + pDHCPMSG->OPT[k++] = DHCP_CHADDR[4]; + pDHCPMSG->OPT[k++] = DHCP_CHADDR[5]; + + if (ip[3] == 255) { // if(dchp_state == STATE_DHCP_LEASED || dchp_state == DHCP_REREQUEST_STATE) + pDHCPMSG->OPT[k++] = dhcpRequestedIPaddr; + pDHCPMSG->OPT[k++] = 0x04; + pDHCPMSG->OPT[k++] = DHCP_allocated_ip[0]; + pDHCPMSG->OPT[k++] = DHCP_allocated_ip[1]; + pDHCPMSG->OPT[k++] = DHCP_allocated_ip[2]; + pDHCPMSG->OPT[k++] = DHCP_allocated_ip[3]; + + pDHCPMSG->OPT[k++] = dhcpServerIdentifier; + pDHCPMSG->OPT[k++] = 0x04; + pDHCPMSG->OPT[k++] = DHCP_SIP[0]; + pDHCPMSG->OPT[k++] = DHCP_SIP[1]; + pDHCPMSG->OPT[k++] = DHCP_SIP[2]; + pDHCPMSG->OPT[k++] = DHCP_SIP[3]; + } + + // host name + pDHCPMSG->OPT[k++] = hostName; + pDHCPMSG->OPT[k++] = 0; // length of hostname + for (i = 0 ; HOST_NAME[i] != 0; i++) { + pDHCPMSG->OPT[k++] = HOST_NAME[i]; + } + pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[3] >> 4); + pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[3]); + pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[4] >> 4); + pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[4]); + pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[5] >> 4); + pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[5]); + pDHCPMSG->OPT[k - (i + 6 + 1)] = i + 6; // length of hostname + + pDHCPMSG->OPT[k++] = dhcpParamRequest; + pDHCPMSG->OPT[k++] = 0x08; + pDHCPMSG->OPT[k++] = subnetMask; + pDHCPMSG->OPT[k++] = routersOnSubnet; + pDHCPMSG->OPT[k++] = dns; + pDHCPMSG->OPT[k++] = domainName; + pDHCPMSG->OPT[k++] = dhcpT1value; + pDHCPMSG->OPT[k++] = dhcpT2value; + pDHCPMSG->OPT[k++] = performRouterDiscovery; + pDHCPMSG->OPT[k++] = staticRoute; + pDHCPMSG->OPT[k++] = endOption; + + for (i = k; i < OPT_SIZE; i++) { + pDHCPMSG->OPT[i] = 0; + } + +#ifdef _DHCP_DEBUG_ + printf("> Send DHCP_REQUEST\r\n"); +#endif + +#if 1 + // 20231016 taylor//teddy 240122 +#if ((_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300)) + sendto(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT, 4); +#else + sendto(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT); +#endif +#else + sendto(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT); +#endif + +} + +/* SEND DHCP DHCPDECLINE */ +void send_DHCP_DECLINE(void) { + int i; + uint8_t ip[4]; + uint16_t k = 0; + + makeDHCPMSG(); + + k = 4; // because MAGIC_COOKIE already made by makeDHCPMSG() + + *((uint8_t*)(&pDHCPMSG->flags)) = ((DHCP_FLAGSUNICAST & 0xFF00) >> 8); + *((uint8_t*)(&pDHCPMSG->flags) +1) = (DHCP_FLAGSUNICAST & 0x00FF); + + // Option Request Param. + pDHCPMSG->OPT[k++] = dhcpMessageType; + pDHCPMSG->OPT[k++] = 0x01; + pDHCPMSG->OPT[k++] = DHCP_DECLINE; + + pDHCPMSG->OPT[k++] = dhcpClientIdentifier; + pDHCPMSG->OPT[k++] = 0x07; + pDHCPMSG->OPT[k++] = 0x01; + pDHCPMSG->OPT[k++] = DHCP_CHADDR[0]; + pDHCPMSG->OPT[k++] = DHCP_CHADDR[1]; + pDHCPMSG->OPT[k++] = DHCP_CHADDR[2]; + pDHCPMSG->OPT[k++] = DHCP_CHADDR[3]; + pDHCPMSG->OPT[k++] = DHCP_CHADDR[4]; + pDHCPMSG->OPT[k++] = DHCP_CHADDR[5]; + + pDHCPMSG->OPT[k++] = dhcpRequestedIPaddr; + pDHCPMSG->OPT[k++] = 0x04; + pDHCPMSG->OPT[k++] = DHCP_allocated_ip[0]; + pDHCPMSG->OPT[k++] = DHCP_allocated_ip[1]; + pDHCPMSG->OPT[k++] = DHCP_allocated_ip[2]; + pDHCPMSG->OPT[k++] = DHCP_allocated_ip[3]; + + pDHCPMSG->OPT[k++] = dhcpServerIdentifier; + pDHCPMSG->OPT[k++] = 0x04; + pDHCPMSG->OPT[k++] = DHCP_SIP[0]; + pDHCPMSG->OPT[k++] = DHCP_SIP[1]; + pDHCPMSG->OPT[k++] = DHCP_SIP[2]; + pDHCPMSG->OPT[k++] = DHCP_SIP[3]; + + pDHCPMSG->OPT[k++] = endOption; + + for (i = k; i < OPT_SIZE; i++) { + pDHCPMSG->OPT[i] = 0; + } + + //send broadcasting packet + ip[0] = 0xFF; + ip[1] = 0xFF; + ip[2] = 0xFF; + ip[3] = 0xFF; + +#ifdef _DHCP_DEBUG_ + printf("\r\n> Send DHCP_DECLINE\r\n"); +#endif + +#if 1 + // 20231016 taylor//teddy 240122 +#if ((_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300)) + sendto(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT, 4); +#else + sendto(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT); +#endif +#else + sendto(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT); +#endif +} + +/* PARSE REPLY pDHCPMSG */ +int8_t parseDHCPMSG(void) { + uint8_t svr_addr[6]; + uint16_t svr_port; + uint16_t len; + + uint8_t * p; + uint8_t * e; + uint8_t type = 0; + uint8_t opt_len; +#if 1 + // 20231019 taylor + uint8_t addr_len; +#endif + + if ((len = getSn_RX_RSR(DHCP_SOCKET)) > 0) { +#if 1 + // 20231019 taylor//teddy 240122 +#if ((_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300)) + len = recvfrom(DHCP_SOCKET, (uint8_t *)pDHCPMSG, len, svr_addr, &svr_port, &addr_len); +#else + len = recvfrom(DHCP_SOCKET, (uint8_t *)pDHCPMSG, len, svr_addr, &svr_port); +#endif +#else + len = recvfrom(DHCP_SOCKET, (uint8_t *)pDHCPMSG, len, svr_addr, &svr_port); +#endif +#ifdef _DHCP_DEBUG_ + printf("DHCP message : %d.%d.%d.%d(%d) %d received. \r\n", svr_addr[0], svr_addr[1], svr_addr[2], svr_addr[3], svr_port, len); +#endif + } else { + return 0; + } + if (svr_port == DHCP_SERVER_PORT) { + // compare mac address + if ((pDHCPMSG->chaddr[0] != DHCP_CHADDR[0]) || (pDHCPMSG->chaddr[1] != DHCP_CHADDR[1]) || + (pDHCPMSG->chaddr[2] != DHCP_CHADDR[2]) || (pDHCPMSG->chaddr[3] != DHCP_CHADDR[3]) || + (pDHCPMSG->chaddr[4] != DHCP_CHADDR[4]) || (pDHCPMSG->chaddr[5] != DHCP_CHADDR[5])) { +#ifdef _DHCP_DEBUG_ + printf("No My DHCP Message. This message is ignored.\r\n"); +#endif + return 0; + } + //compare DHCP server ip address + if ((DHCP_SIP[0] != 0) || (DHCP_SIP[1] != 0) || (DHCP_SIP[2] != 0) || (DHCP_SIP[3] != 0)) { + if (((svr_addr[0] != DHCP_SIP[0]) || (svr_addr[1] != DHCP_SIP[1]) || (svr_addr[2] != DHCP_SIP[2]) || (svr_addr[3] != DHCP_SIP[3])) && + ((svr_addr[0] != DHCP_REAL_SIP[0]) || (svr_addr[1] != DHCP_REAL_SIP[1]) || (svr_addr[2] != DHCP_REAL_SIP[2]) || (svr_addr[3] != DHCP_REAL_SIP[3]))) { +#ifdef _DHCP_DEBUG_ + printf("Another DHCP sever send a response message. This is ignored.\r\n"); +#endif + return 0; + } + } + p = (uint8_t *)(&pDHCPMSG->op); + p = p + 240; // 240 = sizeof(RIP_MSG) + MAGIC_COOKIE size in RIP_MSG.opt - sizeof(RIP_MSG.opt) + e = p + (len - 240); + + while (p < e) { + + switch (*p) { + + case endOption : + p = e; // for break while(p < e) + break; + case padOption : + p++; + break; + case dhcpMessageType : + p++; + p++; + type = *p++; + break; + case subnetMask : + p++; + p++; + DHCP_allocated_sn[0] = *p++; + DHCP_allocated_sn[1] = *p++; + DHCP_allocated_sn[2] = *p++; + DHCP_allocated_sn[3] = *p++; + break; + case routersOnSubnet : + p++; + opt_len = *p++; + DHCP_allocated_gw[0] = *p++; + DHCP_allocated_gw[1] = *p++; + DHCP_allocated_gw[2] = *p++; + DHCP_allocated_gw[3] = *p++; + p = p + (opt_len - 4); + break; + case dns : + p++; + opt_len = *p++; + DHCP_allocated_dns[0] = *p++; + DHCP_allocated_dns[1] = *p++; + DHCP_allocated_dns[2] = *p++; + DHCP_allocated_dns[3] = *p++; + p = p + (opt_len - 4); + break; + case dhcpIPaddrLeaseTime : + p++; + opt_len = *p++; + dhcp_lease_time = *p++; + dhcp_lease_time = (dhcp_lease_time << 8) + *p++; + dhcp_lease_time = (dhcp_lease_time << 8) + *p++; + dhcp_lease_time = (dhcp_lease_time << 8) + *p++; +#ifdef _DHCP_DEBUG_ + dhcp_lease_time = 10; +#endif + break; + case dhcpServerIdentifier : + p++; + opt_len = *p++; + DHCP_SIP[0] = *p++; + DHCP_SIP[1] = *p++; + DHCP_SIP[2] = *p++; + DHCP_SIP[3] = *p++; + DHCP_REAL_SIP[0] = svr_addr[0]; + DHCP_REAL_SIP[1] = svr_addr[1]; + DHCP_REAL_SIP[2] = svr_addr[2]; + DHCP_REAL_SIP[3] = svr_addr[3]; + break; + default : + p++; + opt_len = *p++; + p += opt_len; + break; + } // switch + } // while + } // if + return type; +} + +uint8_t DHCP_run(void) { + uint8_t type; + uint8_t ret; + + if (dhcp_state == STATE_DHCP_STOP) { + return DHCP_STOPPED; + } + + if (getSn_SR(DHCP_SOCKET) != SOCK_UDP) { + socket(DHCP_SOCKET, Sn_MR_UDP, DHCP_CLIENT_PORT, 0x00); + } + + ret = DHCP_RUNNING; + type = parseDHCPMSG(); + + switch (dhcp_state) { + case STATE_DHCP_INIT : + DHCP_allocated_ip[0] = 0; + DHCP_allocated_ip[1] = 0; + DHCP_allocated_ip[2] = 0; + DHCP_allocated_ip[3] = 0; + send_DHCP_DISCOVER(); + dhcp_state = STATE_DHCP_DISCOVER; + break; + case STATE_DHCP_DISCOVER : + if (type == DHCP_OFFER) { +#ifdef _DHCP_DEBUG_ + printf("> Receive DHCP_OFFER\r\n"); +#endif + DHCP_allocated_ip[0] = pDHCPMSG->yiaddr[0]; + DHCP_allocated_ip[1] = pDHCPMSG->yiaddr[1]; + DHCP_allocated_ip[2] = pDHCPMSG->yiaddr[2]; + DHCP_allocated_ip[3] = pDHCPMSG->yiaddr[3]; + + send_DHCP_REQUEST(); + dhcp_state = STATE_DHCP_REQUEST; + } else { + ret = check_DHCP_timeout(); + } + break; + + case STATE_DHCP_REQUEST : + if (type == DHCP_ACK) { + +#ifdef _DHCP_DEBUG_ + printf("> Receive DHCP_ACK\r\n"); +#endif + if (check_DHCP_leasedIP()) { + // Network info assignment from DHCP + dhcp_ip_assign(); + reset_DHCP_timeout(); + + dhcp_state = STATE_DHCP_LEASED; + } else { + // IP address conflict occurred + reset_DHCP_timeout(); + dhcp_ip_conflict(); + dhcp_state = STATE_DHCP_INIT; + } + } else if (type == DHCP_NAK) { + +#ifdef _DHCP_DEBUG_ + printf("> Receive DHCP_NACK\r\n"); +#endif + + reset_DHCP_timeout(); + + dhcp_state = STATE_DHCP_DISCOVER; + } else { + ret = check_DHCP_timeout(); + } + break; + + case STATE_DHCP_LEASED : + ret = DHCP_IP_LEASED; + if ((dhcp_lease_time != INFINITE_LEASETIME) && ((dhcp_lease_time / 2) < dhcp_tick_1s)) { + +#ifdef _DHCP_DEBUG_ + printf("> Maintains the IP address \r\n"); +#endif + + type = 0; + OLD_allocated_ip[0] = DHCP_allocated_ip[0]; + OLD_allocated_ip[1] = DHCP_allocated_ip[1]; + OLD_allocated_ip[2] = DHCP_allocated_ip[2]; + OLD_allocated_ip[3] = DHCP_allocated_ip[3]; + + DHCP_XID++; + + send_DHCP_REQUEST(); + + reset_DHCP_timeout(); + + dhcp_state = STATE_DHCP_REREQUEST; + } + break; + + case STATE_DHCP_REREQUEST : + ret = DHCP_IP_LEASED; + if (type == DHCP_ACK) { + dhcp_retry_count = 0; + if (OLD_allocated_ip[0] != DHCP_allocated_ip[0] || + OLD_allocated_ip[1] != DHCP_allocated_ip[1] || + OLD_allocated_ip[2] != DHCP_allocated_ip[2] || + OLD_allocated_ip[3] != DHCP_allocated_ip[3]) { + ret = DHCP_IP_CHANGED; + dhcp_ip_update(); +#ifdef _DHCP_DEBUG_ + printf(">IP changed.\r\n"); +#endif + + } +#ifdef _DHCP_DEBUG_ + else { + printf(">IP is continued.\r\n"); + } +#endif + reset_DHCP_timeout(); + dhcp_state = STATE_DHCP_LEASED; + } else if (type == DHCP_NAK) { + +#ifdef _DHCP_DEBUG_ + printf("> Receive DHCP_NACK, Failed to maintain ip\r\n"); +#endif + + reset_DHCP_timeout(); + + dhcp_state = STATE_DHCP_DISCOVER; + } else { + ret = check_DHCP_timeout(); + } + break; + default : + break; + } + + return ret; +} + +void DHCP_stop(void) { + close(DHCP_SOCKET); + dhcp_state = STATE_DHCP_STOP; +} + +uint8_t check_DHCP_timeout(void) { + uint8_t ret = DHCP_RUNNING; + + if (dhcp_retry_count < MAX_DHCP_RETRY) { + if (dhcp_tick_next < dhcp_tick_1s) { + + switch (dhcp_state) { + case STATE_DHCP_DISCOVER : + // printf("<> state : STATE_DHCP_DISCOVER\r\n"); + send_DHCP_DISCOVER(); + break; + + case STATE_DHCP_REQUEST : + // printf("<> state : STATE_DHCP_REQUEST\r\n"); + + send_DHCP_REQUEST(); + break; + + case STATE_DHCP_REREQUEST : + // printf("<> state : STATE_DHCP_REREQUEST\r\n"); + + send_DHCP_REQUEST(); + break; + + default : + break; + } + + dhcp_tick_1s = 0; + dhcp_tick_next = dhcp_tick_1s + DHCP_WAIT_TIME; + dhcp_retry_count++; + } + } else { // timeout occurred + + switch (dhcp_state) { + case STATE_DHCP_DISCOVER: + dhcp_state = STATE_DHCP_INIT; + ret = DHCP_FAILED; + break; + case STATE_DHCP_REQUEST: + case STATE_DHCP_REREQUEST: + send_DHCP_DISCOVER(); + dhcp_state = STATE_DHCP_DISCOVER; + break; + default : + break; + } + reset_DHCP_timeout(); + } + return ret; +} + +int8_t check_DHCP_leasedIP(void) { + uint8_t tmp; + int32_t ret; + + //WIZchip RCR value changed for ARP Timeout count control + tmp = getRCR(); + setRCR(0x03); + + // IP conflict detection : ARP request - ARP reply + // Broadcasting ARP Request for check the IP conflict using UDP sendto() function +#if 1 + // 20231016 taylor//teddy 240122 +#if ((_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300)) + ret = sendto(DHCP_SOCKET, (uint8_t *)"CHECK_IP_CONFLICT", 17, DHCP_allocated_ip, 5000, 4); +#else + ret = sendto(DHCP_SOCKET, (uint8_t *)"CHECK_IP_CONFLICT", 17, DHCP_allocated_ip, 5000); +#endif +#else + ret = sendto(DHCP_SOCKET, (uint8_t *)"CHECK_IP_CONFLICT", 17, DHCP_allocated_ip, 5000); +#endif + + // RCR value restore + setRCR(tmp); + + if (ret == SOCKERR_TIMEOUT) { + // UDP send Timeout occurred : allocated IP address is unique, DHCP Success + +#ifdef _DHCP_DEBUG_ + printf("\r\n> Check leased IP - OK\r\n"); +#endif + + return 1; + } else { + // Received ARP reply or etc : IP address conflict occur, DHCP Failed + send_DHCP_DECLINE(); + + ret = dhcp_tick_1s; + while ((dhcp_tick_1s - ret) < 2) ; // wait for 1s over; wait to complete to send DECLINE message; + + return 0; + } +} + +void DHCP_init(uint8_t s, uint8_t * buf) { + uint8_t zeroip[4] = {0, 0, 0, 0}; + getSHAR(DHCP_CHADDR); + if ((DHCP_CHADDR[0] | DHCP_CHADDR[1] | DHCP_CHADDR[2] | DHCP_CHADDR[3] | DHCP_CHADDR[4] | DHCP_CHADDR[5]) == 0x00) { + // assigning temporary mac address, you should be set SHAR before call this function. + DHCP_CHADDR[0] = 0x00; + DHCP_CHADDR[1] = 0x08; + DHCP_CHADDR[2] = 0xdc; + DHCP_CHADDR[3] = 0x00; + DHCP_CHADDR[4] = 0x00; + DHCP_CHADDR[5] = 0x00; +#if _WIZCHIP_ == W6100 + NETUNLOCK(); + setSHAR(DHCP_CHADDR); + NETLOCK(); +#else + setSHAR(DHCP_CHADDR); +#endif + } + + DHCP_SOCKET = s; // SOCK_DHCP + pDHCPMSG = (RIP_MSG*)buf; + DHCP_XID = 0x12345678; + { + DHCP_XID += DHCP_CHADDR[3]; + DHCP_XID += DHCP_CHADDR[4]; + DHCP_XID += DHCP_CHADDR[5]; + DHCP_XID += (DHCP_CHADDR[3] ^ DHCP_CHADDR[4] ^ DHCP_CHADDR[5]); + } + // WIZchip Netinfo Clear + setSIPR(zeroip); + setGAR(zeroip); + + reset_DHCP_timeout(); + dhcp_state = STATE_DHCP_INIT; +} + + +/* Reset the DHCP timeout count and retry count. */ +void reset_DHCP_timeout(void) { + dhcp_tick_1s = 0; + dhcp_tick_next = DHCP_WAIT_TIME; + dhcp_retry_count = 0; +} + +void DHCP_time_handler(void) { + dhcp_tick_1s++; +} + +void getIPfromDHCP(uint8_t* ip) { + ip[0] = DHCP_allocated_ip[0]; + ip[1] = DHCP_allocated_ip[1]; + ip[2] = DHCP_allocated_ip[2]; + ip[3] = DHCP_allocated_ip[3]; +} + +void getGWfromDHCP(uint8_t* ip) { + ip[0] = DHCP_allocated_gw[0]; + ip[1] = DHCP_allocated_gw[1]; + ip[2] = DHCP_allocated_gw[2]; + ip[3] = DHCP_allocated_gw[3]; +} + +void getSNfromDHCP(uint8_t* ip) { + ip[0] = DHCP_allocated_sn[0]; + ip[1] = DHCP_allocated_sn[1]; + ip[2] = DHCP_allocated_sn[2]; + ip[3] = DHCP_allocated_sn[3]; +} + +void getDNSfromDHCP(uint8_t* ip) { + ip[0] = DHCP_allocated_dns[0]; + ip[1] = DHCP_allocated_dns[1]; + ip[2] = DHCP_allocated_dns[2]; + ip[3] = DHCP_allocated_dns[3]; +} + +uint32_t getDHCPLeasetime(void) { + return dhcp_lease_time; +} + +char NibbleToHex(uint8_t nibble) { + nibble &= 0x0F; + if (nibble <= 9) { + return nibble + '0'; + } else { + return nibble + ('A' - 0x0A); + } +} + + diff --git a/Internet/DHCP/dhcp.h b/Internet/DHCP/dhcp.h new file mode 100644 index 0000000..7d13a32 --- /dev/null +++ b/Internet/DHCP/dhcp.h @@ -0,0 +1,163 @@ +//***************************************************************************** +// +//! \file dhcp.h +//! \brief DHCP APIs Header file. +//! \details Processig DHCP protocol as DISCOVER, OFFER, REQUEST, ACK, NACK and DECLINE. +//! \version 1.1.1 +//! \date 2019/10/08 +//! \par Revision history +//! <2019/10/08> compare DHCP server ip address +//! <2013/11/18> 1st Release +//! <2012/12/20> V1.1.0 +//! 1. Move unreferenced DEFINE to dhcp.c +//! <2012/12/26> V1.1.1 +//! \author Eric Jung & 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 _DHCP_H_ +#define _DHCP_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + @brief + @details If you want to display debug & processing message, Define _DHCP_DEBUG_ + @note If defined, it depends on +*/ +#if 0 +// 20231023 taylor +#define _DHCP_DEBUG_ +#endif + + +/* Retry to processing DHCP */ +#define MAX_DHCP_RETRY 2 ///< Maximum retry count +#define DHCP_WAIT_TIME 10 ///< Wait Time 10s + + +/* UDP port numbers for DHCP */ +#define DHCP_SERVER_PORT 67 ///< DHCP server port number +#define DHCP_CLIENT_PORT 68 ///< DHCP client port number + + +#define MAGIC_COOKIE 0x63825363 ///< You should not modify it number. + +#define DCHP_HOST_NAME "WIZnet\0" + +/* + @brief return value of @ref DHCP_run() +*/ +enum { + DHCP_FAILED = 0, ///< Processing Fail + DHCP_RUNNING, ///< Processing DHCP protocol + DHCP_IP_ASSIGN, ///< First Occupy IP from DHPC server (if cbfunc == null, act as default default_ip_assign) + DHCP_IP_CHANGED, ///< Change IP address by new ip from DHCP (if cbfunc == null, act as default default_ip_update) + DHCP_IP_LEASED, ///< Stand by + DHCP_STOPPED ///< Stop processing DHCP protocol +}; + +/* + @brief DHCP client initialization (outside of the main loop) + @param s - socket number + @param buf - buffer for processing DHCP message +*/ +void DHCP_init(uint8_t s, uint8_t * buf); + +/* + @brief DHCP 1s Tick Timer handler + @note SHOULD BE register to your system 1s Tick timer handler +*/ +void DHCP_time_handler(void); + +/* + @brief Register call back function + @param ip_assign - callback func when IP is assigned from DHCP server first + @param ip_update - callback func when IP is changed + @param ip_conflict - callback func when the assigned IP is conflict with others. +*/ +void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void)); + +/* + @brief DHCP client in the main loop + @return The value is as the follow \n + @ref DHCP_FAILED \n + @ref DHCP_RUNNING \n + @ref DHCP_IP_ASSIGN \n + @ref DHCP_IP_CHANGED \n + @ref DHCP_IP_LEASED \n + @ref DHCP_STOPPED \n + + @note This function is always called by you main task. +*/ +uint8_t DHCP_run(void); + +/* + @brief Stop DHCP processing + @note If you want to restart. call DHCP_init() and DHCP_run() +*/ +void DHCP_stop(void); + +/* Get Network information assigned from DHCP server */ +/* + @brief Get IP address + @param ip - IP address to be returned +*/ +void getIPfromDHCP(uint8_t* ip); +/* + @brief Get Gateway address + @param ip - Gateway address to be returned +*/ +void getGWfromDHCP(uint8_t* ip); +/* + @brief Get Subnet mask value + @param ip - Subnet mask to be returned +*/ +void getSNfromDHCP(uint8_t* ip); +/* + @brief Get DNS address + @param ip - DNS address to be returned +*/ +void getDNSfromDHCP(uint8_t* ip); + +/* + @brief Get the leased time by DHCP sever + @return unit 1s +*/ +uint32_t getDHCPLeasetime(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _DHCP_H_ */ diff --git a/Internet/DHCP6/dhcpv6.c b/Internet/DHCP6/dhcpv6.c new file mode 100644 index 0000000..a894cc8 --- /dev/null +++ b/Internet/DHCP6/dhcpv6.c @@ -0,0 +1,1219 @@ +//***************************************************************************** +// +//! \file dhcpv6.c +//! \brief DHCPv6 APIs implement file. +//! \details Processig DHCPv6 protocol as SOLICIT, ADVERTISE. +//! \version 0.0.1 +//! \date 2016/06/08 +//! \par Revision history +//! <2016/07/18> 1st Release +//! \author JustinKim +//! \copyright +//! +//! Copyright (c) 2016, 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 "dhcpv6.h" +#include +#include +#include + +#if (_WIZCHIP_ == W6100) + +/* If you want to display debug & procssing message, Define _DHCP6_DEBUG_ in dhcpv6.h */ +#define _DHCP6_DEBUG_ +#ifdef _DHCP6_DEBUG_ +#include +#endif + +/* DHCP6 state machine. */ +#define STATE_DHCP6_INIT 0 ///< Initialize +#define STATE_DHCP6_SOLICIT 1 ///< send DISCOVER and wait OFFER +#define STATE_DHCP6_REQUEST 2 ///< send REQEUST and wait ACK or NACK +#define STATE_DHCP6_LEASED 3 ///< ReceiveD ACK and IP leased +#define STATE_DHCP6_REREQUEST 4 ///< send REQUEST for maintaining leased IP +#define STATE_DHCP6_RELEASE 5 ///< No use +#define STATE_DHCP6_STOP 6 ///< Stop procssing DHCPv6 + +/* DHCP6 message type */ +#define DHCP6_SOLICIT 1 ///< DISCOVER message in OPT of @ref RIP_MSG +#define DHCP6_ADVERTISE 2 ///< OFFER message in OPT of @ref RIP_MSG +#define DHCP6_REQUEST 3 ///< REQUEST message in OPT of @ref RIP_MSG +#define DHCP6_CONFIRM 4 ///< DECLINE message in OPT of @ref RIP_MSG +#define DHCP6_RENEW 5 ///< ACK message in OPT of @ref RIP_MSG +#define DHCP6_REBIND 6 ///< NACK message in OPT of @ref RIP_MSG +#define DHCP6_REPLY 7 ///< RELEASE message in OPT of @ref RIP_MSG. No use +#define DHCP6_RELEASE 8 ///< INFORM message in OPT of @ref RIP_MSG. No use +#define DHCP6_DECLINE 9 ///< INFORM message in OPT of @ref RIP_MSG. No use +#define DHCP6_RECONFIGURE 10 ///< INFORM message in OPT of @ref RIP_MSG. No use +#define DHCP6_INFO_REQUEST 11 ///< INFORM message in OPT of @ref RIP_MSG. No use + +uint8_t DNS6_Address[16] = { + 0, +}; +//todo + +/* + @brief DHCPv6 option (cf. RFC3315) +*/ +enum { + OPT_CLIENTID = 1, + OPT_SERVERID = 2, + OPT_IANA = 3, + OPT_IATA = 4, + OPT_IAADDR = 5, + OPT_REQUEST = 6, + OPT_PREFERENCE = 7, + OPT_ELAPSED_TIME = 8, + OPT_RELAY_MSG = 9, + OPT_AUTH = 11, + OPT_UNICAST = 12, + OPT_STATUS_CODE = 13, + OPT_RAPID_COMMIT = 14, + OPT_USER_CLASS = 15, + OPT_VENDOR_CLASS = 16, + OPT_VENDOR_OPTS = 17, + OPT_INTERFACE_ID = 18, + OPT_RECONF_MSG = 19, + OPT_RECONF_ACCEPT = 20, + SIP_Server_DNL = 21, + SIP_Server_V6ADDR = 22, + DNS_RecursiveNameServer = 23, + Domain_Search_List = 24, + OPT_IAPD = 25, + OPT_IAPREFIX = 26, + OPT_NIS_SERVERS = 27, + OPT_NISP_SERVERS = 28, + OPT_NIS_DOMAIN_NAME = 29, + OPT_NISP_DOMAIN_NAME = 30, + OPT_LIFETIME = 32, + FQ_DOMAIN_NAME = 39 +}; + +/* + @brief DHCPv6 message format +*/ +typedef struct { + uint8_t *OPT; ///< Option +} __attribute__((packed)) RIP_MSG; + +uint8_t DHCP6_SOCKET; // Socket number for DHCPv6 + +// Network information from DHCPv6 Server +uint8_t DHCP6_allocated_ip[16] = { + 0, +}; // IP address from DHCPv6 +int8_t dhcp6_state = STATE_DHCP6_INIT; // DHCPv6 state +int8_t dhcp6_retry_count = 0; + +volatile uint32_t dhcp6_tick_1s = 0; // unit 1 second +uint32_t dhcp6_tick_next = DHCP6_WAIT_TIME; + +uint32_t DHCP6_XID; // Any number + +RIP_MSG pDHCP6MSG; // Buffer pointer for DHCPv6 processing + +uint8_t HOST_NAME6[] = DCHP6_HOST_NAME; + +uint8_t DHCP6_CHADDR[6]; // DHCPv6 Client MAC address. + + +uint16_t DUID_type_s; +uint16_t Hardware_type_s; +uint8_t Time_s[4]; +uint32_t Enterprise_num_s; +uint8_t Server_MAC[6]; +uint8_t recv_IP[16]; +uint32_t PreLifeTime; +uint32_t ValidLifeTime; +uint16_t code; +uint8_t IAID[4]; +uint8_t T1[4]; +uint8_t T2[4]; +uint16_t iana_len; +uint16_t iaaddr_len; +uint16_t statuscode_len; +uint16_t Lstatuscode_len; +uint16_t serverid_len; +uint16_t clientid_len; +uint8_t status_msg[] = ""; + +unsigned size; +unsigned num; +unsigned num2 = 0; +unsigned growby; + +/** + @brief + + @param asize + @param agrowby +*/ +void InitDhcp6Option(unsigned asize, unsigned agrowby) { + size = asize; + growby = agrowby; + num = 0; +} + +/** + @brief + + @param value +*/ +void AppendDhcp6Option(uint8_t value) { + uint32_t need; + + need = num + 1; + if (need > size) { + size++; + } + pDHCP6MSG.OPT[num] = value; + num++; +} + +/** + @brief + + @param sMark +*/ +void DumpDhcp6Option(char *sMark) { + unsigned i; + printf("%20s => size=%02d,num=%02d : ", sMark, size, num); + for (i = num2; i < num; i++) { + printf("%.2x ", pDHCP6MSG.OPT[i]); + } + printf("\r\n"); + num2 = num; +} + +/** + @brief + + @param option +*/ +void DHCP6_Option_Select(uint8_t option) { + switch (option) + case OPT_CLIENTID: +case OPT_SERVERID: +case OPT_IANA: +case OPT_IATA: +case OPT_IAADDR: +case OPT_REQUEST: +case OPT_PREFERENCE: +case OPT_ELAPSED_TIME: +case OPT_RELAY_MSG: +case OPT_AUTH: +case OPT_UNICAST: +case OPT_STATUS_CODE: +case OPT_RAPID_COMMIT: +case OPT_USER_CLASS: +case OPT_VENDOR_CLASS: +case OPT_VENDOR_OPTS: +case OPT_INTERFACE_ID: +case OPT_RECONF_MSG: +case OPT_RECONF_ACCEPT: +case SIP_Server_DNL: +case SIP_Server_V6ADDR: +case DNS_RecursiveNameServer: +case Domain_Search_List: +case OPT_IAPD: +case OPT_IAPREFIX: +case OPT_NIS_SERVERS: +case OPT_NISP_SERVERS: +case OPT_NIS_DOMAIN_NAME: +case OPT_NISP_DOMAIN_NAME: +case FQ_DOMAIN_NAME: + break; +} + +/** + @brief + +*/ +void send_DHCP6_SOLICIT(void) { + uint16_t j; + uint8_t ip[16]; + uint8_t rip_msg_size; + + size = 0; + num = 0; + growby = 0; + + InitDhcp6Option(34, 1); + DumpDhcp6Option("option init"); + + AppendDhcp6Option(DHCP6_SOLICIT); + AppendDhcp6Option((uint8_t)((DHCP6_XID & 0x00FF0000) >> 16)); + AppendDhcp6Option((uint8_t)((DHCP6_XID & 0x00FF0000) >> 8)); + AppendDhcp6Option((uint8_t)((DHCP6_XID & 0x00FF0000) >> 0)); + DumpDhcp6Option("Type&XID"); + + // Elapsed time + // AppendDhcp6Option(0x00);AppendDhcp6Option(OPT_ELAPSED_TIME); + // AppendDhcp6Option(0x00);AppendDhcp6Option(0x02); + // AppendDhcp6Option(0x0c);AppendDhcp6Option(0x1c);DumpDhcp6Option("Option Elapsed Time"); + + // Client Identifier + AppendDhcp6Option(0x00); + AppendDhcp6Option(OPT_CLIENTID); + AppendDhcp6Option(0x00); + AppendDhcp6Option(0x0a); //length + AppendDhcp6Option(0x00); + AppendDhcp6Option(0x03); //DUID_Type + AppendDhcp6Option(0x00); + AppendDhcp6Option(0x01); //Hard_Type + + AppendDhcp6Option(DHCP6_CHADDR[0]); + AppendDhcp6Option(DHCP6_CHADDR[1]); // MAC Addr + AppendDhcp6Option(DHCP6_CHADDR[2]); + AppendDhcp6Option(DHCP6_CHADDR[3]); + AppendDhcp6Option(DHCP6_CHADDR[4]); + AppendDhcp6Option(DHCP6_CHADDR[5]); + DumpDhcp6Option("Option Client ID"); + + // Identity Association for Non-temporary Address + AppendDhcp6Option(0x00); + AppendDhcp6Option(OPT_IANA); + AppendDhcp6Option(0x00); + AppendDhcp6Option(0x0c); // length + AppendDhcp6Option(0x03); + AppendDhcp6Option(0x00); // IAID + AppendDhcp6Option(0x08); + AppendDhcp6Option(0xdc); + AppendDhcp6Option(0x00); + AppendDhcp6Option(0x00); // T1 + AppendDhcp6Option(0x00); + AppendDhcp6Option(0x00); + AppendDhcp6Option(0x00); + AppendDhcp6Option(0x00); // T2 + AppendDhcp6Option(0x00); + AppendDhcp6Option(0x00); + DumpDhcp6Option("Option IANA"); + + // Fully Qualified Domain Name + // AppendDhcp6Option(0x00);AppendDhcp6Option(39); + // AppendDhcp6Option(0x00);AppendDhcp6Option(0x06); // length + // AppendDhcp6Option(0x00);AppendDhcp6Option(0x04); + // AppendDhcp6Option(0x44);AppendDhcp6Option(0x45); + // AppendDhcp6Option(0x44);AppendDhcp6Option(0x59);DumpDhcp6Option("Option FQ Domain Name"); + + // Vendor Class + // AppendDhcp6Option(0x00);AppendDhcp6Option(16); + // AppendDhcp6Option(0x00);AppendDhcp6Option(0x0e); // length + // AppendDhcp6Option(0x00);AppendDhcp6Option(0x00); + // AppendDhcp6Option(0x01);AppendDhcp6Option(0x37); + // AppendDhcp6Option(0x00);AppendDhcp6Option(0x08); + // AppendDhcp6Option(0x4d);AppendDhcp6Option(0x53); + // AppendDhcp6Option(0x46);AppendDhcp6Option(0x54); + // AppendDhcp6Option(0x20);AppendDhcp6Option(0x35); + // AppendDhcp6Option(0x2e);AppendDhcp6Option(0x30);DumpDhcp6Option("Option Vendor Class"); + + // Option Request + // AppendDhcp6Option(0x00);AppendDhcp6Option(OPT_REQUEST); + // AppendDhcp6Option(0x00);AppendDhcp6Option(0x08); // length + // AppendDhcp6Option(0x00);AppendDhcp6Option(OPT_VENDOR_OPTS); + // AppendDhcp6Option(0x00);AppendDhcp6Option(DNS_RecursiveNameServer); + // AppendDhcp6Option(0x00);AppendDhcp6Option(Domain_Search_List); + // AppendDhcp6Option(0x00);AppendDhcp6Option(FQ_DOMAIN_NAME);DumpDhcp6Option("Option Request"); + + // send broadcasting packet + ip[0] = 0xff; + ip[1] = 0x02; + + for (j = 2; j < 13; j++) { + ip[j] = 0x00; + } + + ip[13] = 0x01; + ip[14] = 0x00; + ip[15] = 0x02; + + rip_msg_size = size; + +#ifdef _DHCP_DEBUG_ + printf("> Send DHCP_DISCOVER\r\n"); +#endif + + sendto(DHCP6_SOCKET, (uint8_t *)pDHCP6MSG.OPT, rip_msg_size, ip, DHCP6_SERVER_PORT, 16); + +#ifdef _DHCP_DEBUG_ + printf("> %d, %d\r\n", ret, rip_msg_size); +#endif + + //return ret +} + +/** + @brief + + @return uint8_t +*/ +uint8_t send_DHCP6_REQUEST(void) { + //uint16_t i; + uint16_t j; + uint8_t ip[16]; + uint8_t rip_msg_size; + uint8_t ret = 1; + + size = 0; + num = 0; + growby = 0; + + if (iana_len == 0) { + return 9; + } + printf("req : %x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x \r\n", recv_IP[0], recv_IP[1], recv_IP[2], recv_IP[3], recv_IP[4], recv_IP[5], recv_IP[6], recv_IP[7], recv_IP[8], recv_IP[9], recv_IP[10], recv_IP[11], recv_IP[12], recv_IP[13], recv_IP[14], recv_IP[15]); + + InitDhcp6Option(60, 1); + DumpDhcp6Option("option init"); + + AppendDhcp6Option(DHCP6_REQUEST); + AppendDhcp6Option((uint8_t)((DHCP6_XID & 0x00FF0000) >> 16)); + AppendDhcp6Option((uint8_t)((DHCP6_XID & 0x0000FF00) >> 8)); + AppendDhcp6Option((uint8_t)((DHCP6_XID & 0x000000FF) >> 0)); + DumpDhcp6Option("Type&XID"); + + // Elapsed time + //AppendDhcp6Option(0x00);AppendDhcp6Option(OPT_ELAPSED_TIME); + //AppendDhcp6Option(0x00);AppendDhcp6Option(0x02); + //AppendDhcp6Option(0x0c);AppendDhcp6Option(0x1c);DumpDhcp6Option("Option Elapsed Time"); + + // Identity Association for Non-temporary Address + AppendDhcp6Option(0x00); + AppendDhcp6Option(OPT_IANA); + AppendDhcp6Option((uint8_t)(iana_len >> 8)); + AppendDhcp6Option((uint8_t)iana_len); // length + AppendDhcp6Option(IAID[0]); + AppendDhcp6Option(IAID[1]); // IAID + AppendDhcp6Option(IAID[2]); + AppendDhcp6Option(IAID[3]); + AppendDhcp6Option(T1[0]); + AppendDhcp6Option(T1[1]); // T1 + AppendDhcp6Option(T1[2]); + AppendDhcp6Option(T1[3]); + AppendDhcp6Option(T2[0]); + AppendDhcp6Option(T2[1]); // T2 + AppendDhcp6Option(T2[2]); + AppendDhcp6Option(T2[3]); + DumpDhcp6Option("Option IANA"); + + // IA Address + AppendDhcp6Option(0x00); + AppendDhcp6Option(OPT_IAADDR); + AppendDhcp6Option((uint8_t)(iaaddr_len >> 8)); + AppendDhcp6Option((uint8_t)iaaddr_len); // length + AppendDhcp6Option(recv_IP[0]); + AppendDhcp6Option(recv_IP[1]); // IP + AppendDhcp6Option(recv_IP[2]); + AppendDhcp6Option(recv_IP[3]); + AppendDhcp6Option(recv_IP[4]); + AppendDhcp6Option(recv_IP[5]); + AppendDhcp6Option(recv_IP[6]); + AppendDhcp6Option(recv_IP[7]); + AppendDhcp6Option(recv_IP[8]); + AppendDhcp6Option(recv_IP[9]); + AppendDhcp6Option(recv_IP[10]); + AppendDhcp6Option(recv_IP[11]); + AppendDhcp6Option(recv_IP[12]); + AppendDhcp6Option(recv_IP[13]); + AppendDhcp6Option(recv_IP[14]); + AppendDhcp6Option(recv_IP[15]); + AppendDhcp6Option((uint8_t)(PreLifeTime >> 24)); + AppendDhcp6Option((uint8_t)(PreLifeTime >> 16)); + AppendDhcp6Option((uint8_t)(PreLifeTime >> 8)); + AppendDhcp6Option((uint8_t)PreLifeTime); + AppendDhcp6Option((uint8_t)(ValidLifeTime >> 24)); + AppendDhcp6Option((uint8_t)(ValidLifeTime >> 16)); + AppendDhcp6Option((uint8_t)(ValidLifeTime >> 8)); + AppendDhcp6Option((uint8_t)ValidLifeTime); + DumpDhcp6Option("Option IA_addr"); + + // Status code +#if 0 + // 20190318 + AppendDhcp6Option(0x00); AppendDhcp6Option(OPT_STATUS_CODE); DumpDhcp6Option("Option status_code type"); + AppendDhcp6Option((uint8_t)(Lstatuscode_len >> 8)); AppendDhcp6Option((uint8_t)Lstatuscode_len); DumpDhcp6Option("Option status_code length"); // length + AppendDhcp6Option((uint8_t)(code >> 8)); AppendDhcp6Option((uint8_t)code); DumpDhcp6Option("Option status_code code"); // code +#endif + // for(i=0; i<(statuscode_len-2); i++) + // AppendDhcp6Option(status_msg[i]); + // DumpDhcp6Option("Option status_code msg"); + +#if 0 + // 20190318 + AppendDhcp6Option(0x41); AppendDhcp6Option(0x73); + AppendDhcp6Option(0x73); AppendDhcp6Option(0x69); + AppendDhcp6Option(0x67); AppendDhcp6Option(0x6e); + AppendDhcp6Option(0x65); AppendDhcp6Option(0x64); + AppendDhcp6Option(0x20); AppendDhcp6Option(0x61); + AppendDhcp6Option(0x6e); AppendDhcp6Option(0x20); + AppendDhcp6Option(0x61); AppendDhcp6Option(0x64); + AppendDhcp6Option(0x64); AppendDhcp6Option(0x72); + AppendDhcp6Option(0x65); AppendDhcp6Option(0x73); + AppendDhcp6Option(0x73); AppendDhcp6Option(0x2e); +#endif + + // Client Identifier + AppendDhcp6Option(0x00); + AppendDhcp6Option(OPT_CLIENTID); + AppendDhcp6Option(0x00); + AppendDhcp6Option(0x0a); //length + AppendDhcp6Option(0x00); + AppendDhcp6Option(0x03); //DUID_Type + AppendDhcp6Option(0x00); + AppendDhcp6Option(0x01); //Hard_Type + + AppendDhcp6Option(DHCP6_CHADDR[0]); + AppendDhcp6Option(DHCP6_CHADDR[1]); // MAC Addr + AppendDhcp6Option(DHCP6_CHADDR[2]); + AppendDhcp6Option(DHCP6_CHADDR[3]); + AppendDhcp6Option(DHCP6_CHADDR[4]); + AppendDhcp6Option(DHCP6_CHADDR[5]); + DumpDhcp6Option("Option Client ID"); + // AppendDhcp6Option(0x00);AppendDhcp6Option(OPT_CLIENTID); + // AppendDhcp6Option((uint8_t)(clientid_len>>8));AppendDhcp6Option((uint8_t)clientid_len); //length + // AppendDhcp6Option((uint8_t)(DUID_type>>8));AppendDhcp6Option((uint8_t)DUID_type); //DUID_Type + // AppendDhcp6Option((uint8_t)(Hardware_type>>8));AppendDhcp6Option((uint8_t)Hardware_type); //Hard_Type + // AppendDhcp6Option(DHCP_CHADDR[0]);AppendDhcp6Option(DHCP_CHADDR[1]); // MAC Addr + // AppendDhcp6Option(DHCP_CHADDR[2]);AppendDhcp6Option(DHCP_CHADDR[3]); + // AppendDhcp6Option(DHCP_CHADDR[4]);AppendDhcp6Option(DHCP_CHADDR[5]);DumpDhcp6Option("Option Client ID"); + + //Server Identifier + AppendDhcp6Option(0x00); + AppendDhcp6Option(OPT_SERVERID); + AppendDhcp6Option((uint8_t)(serverid_len >> 8)); + AppendDhcp6Option((uint8_t)serverid_len); //length + AppendDhcp6Option((uint8_t)(DUID_type_s >> 8)); + AppendDhcp6Option((uint8_t)DUID_type_s); //DUID_Type + AppendDhcp6Option((uint8_t)(Hardware_type_s >> 8)); + AppendDhcp6Option((uint8_t)Hardware_type_s); //Hard_Type +#if 0 + // 20190318 + AppendDhcp6Option(Time_s[0]); AppendDhcp6Option(Time_s[1]); // Time + AppendDhcp6Option(Time_s[2]); AppendDhcp6Option(Time_s[3]); +#endif + AppendDhcp6Option(Server_MAC[0]); + AppendDhcp6Option(Server_MAC[1]); // MAC Addr + AppendDhcp6Option(Server_MAC[2]); + AppendDhcp6Option(Server_MAC[3]); + AppendDhcp6Option(Server_MAC[4]); + AppendDhcp6Option(Server_MAC[5]); + DumpDhcp6Option("Option Server ID"); + + // Fully Qualified Domain Name + // AppendDhcp6Option(0x00);AppendDhcp6Option(39); + // AppendDhcp6Option(0x00);AppendDhcp6Option(0x06); // length + // AppendDhcp6Option(0x00);AppendDhcp6Option(0x04); + // AppendDhcp6Option(0x44);AppendDhcp6Option(0x45); + // AppendDhcp6Option(0x44);AppendDhcp6Option(0x59);DumpDhcp6Option("Option FQ Domain Name"); + + // Vendor Class + // AppendDhcp6Option(0x00);AppendDhcp6Option(16); + // AppendDhcp6Option(0x00);AppendDhcp6Option(0x0e); // length + // AppendDhcp6Option(0x00);AppendDhcp6Option(0x00); + // AppendDhcp6Option(0x01);AppendDhcp6Option(0x37); + // AppendDhcp6Option(0x00);AppendDhcp6Option(0x08); + // AppendDhcp6Option(0x4d);AppendDhcp6Option(0x53); + // AppendDhcp6Option(0x46);AppendDhcp6Option(0x54); + // AppendDhcp6Option(0x20);AppendDhcp6Option(0x35); + // AppendDhcp6Option(0x2e);AppendDhcp6Option(0x30);DumpDhcp6Option("Option Vendor Class"); + + // Option Request + // AppendDhcp6Option(0x00);AppendDhcp6Option(OPT_REQUEST); + // AppendDhcp6Option(0x00);AppendDhcp6Option(0x08); // length + // AppendDhcp6Option(0x00);AppendDhcp6Option(OPT_VENDOR_OPTS); + // AppendDhcp6Option(0x00);AppendDhcp6Option(DNS_RecursiveNameServer); + // AppendDhcp6Option(0x00);AppendDhcp6Option(Domain_Search_List); + // AppendDhcp6Option(0x00);AppendDhcp6Option(FQ_DOMAIN_NAME);DumpDhcp6Option("Option Request"); + + // send broadcasting packet + ip[0] = 0xff; + ip[1] = 0x02; + + for (j = 2; j < 13; j++) { + ip[j] = 0x00; + } + + ip[13] = 0x01; + ip[14] = 0x00; + ip[15] = 0x02; + + rip_msg_size = size; + +#ifdef _DHCP_DEBUG_ + printf("> Send DHCP_REQUEST\r\n"); +#endif + + sendto(DHCP6_SOCKET, (uint8_t *)pDHCP6MSG.OPT, rip_msg_size, ip, DHCP6_SERVER_PORT, 16); +#ifdef _DHCP_DEBUG_ + printf("> %d, %d\r\n", ret, rip_msg_size); +#endif + + return ret; +} + +/** + @brief + + @return uint8_t +*/ +uint8_t send_DHCP_INFOREQ(void) { + //uint16_t i; + uint16_t j; + uint8_t ip[16]; + uint8_t rip_msg_size; + uint8_t ret = 0; + + size = 0; + num = 0; + growby = 0; + + //printf("req : %x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x \r\n",recv_IP[0],recv_IP[1],recv_IP[2],recv_IP[3],recv_IP[4],recv_IP[5],recv_IP[6],recv_IP[7],recv_IP[8],recv_IP[9],recv_IP[10],recv_IP[11],recv_IP[12],recv_IP[13],recv_IP[14],recv_IP[15]); + InitDhcp6Option(30, 1); + DumpDhcp6Option("option init"); + + AppendDhcp6Option(DHCP6_INFO_REQUEST); + AppendDhcp6Option((uint8_t)((DHCP6_XID & 0x00FF0000) >> 16)); + AppendDhcp6Option((uint8_t)((DHCP6_XID & 0x0000FF00) >> 8)); + AppendDhcp6Option((uint8_t)((DHCP6_XID & 0x000000FF) >> 0)); + DumpDhcp6Option("Type&XID"); + + // // Elapsed time + // AppendDhcp6Option(0x00);AppendDhcp6Option(OPT_ELAPSED_TIME); + // AppendDhcp6Option(0x00);AppendDhcp6Option(0x02); + // AppendDhcp6Option(0x0c);AppendDhcp6Option(0x1c);DumpDhcp6Option("Option Elapsed Time"); + + // Client Identifier + AppendDhcp6Option(0x00); + AppendDhcp6Option(OPT_CLIENTID); + AppendDhcp6Option(0x00); + AppendDhcp6Option(0x0a); //length + AppendDhcp6Option(0x00); + AppendDhcp6Option(0x03); //DUID_Type + AppendDhcp6Option(0x00); + AppendDhcp6Option(0x01); //Hard_Type + + AppendDhcp6Option(DHCP6_CHADDR[0]); + AppendDhcp6Option(DHCP6_CHADDR[1]); // MAC Addr + AppendDhcp6Option(DHCP6_CHADDR[2]); + AppendDhcp6Option(DHCP6_CHADDR[3]); + AppendDhcp6Option(DHCP6_CHADDR[4]); + AppendDhcp6Option(DHCP6_CHADDR[5]); + DumpDhcp6Option("Option Client ID"); + + // Option Request + AppendDhcp6Option(0x00); + AppendDhcp6Option(OPT_REQUEST); + AppendDhcp6Option(0x00); + AppendDhcp6Option(0x06); // length + //AppendDhcp6Option(0x00);AppendDhcp6Option(OPT_VENDOR_OPTS); + AppendDhcp6Option(0x00); + AppendDhcp6Option(DNS_RecursiveNameServer); + AppendDhcp6Option(0x00); + AppendDhcp6Option(Domain_Search_List); + AppendDhcp6Option(0x00); + AppendDhcp6Option(OPT_LIFETIME); + DumpDhcp6Option("Option Request"); + + // send broadcasting packet + ip[0] = 0xff; + ip[1] = 0x02; + + for (j = 2; j < 13; j++) { + ip[j] = 0x00; + } + + ip[13] = 0x01; + ip[14] = 0x00; + ip[15] = 0x02; + + rip_msg_size = size; + +#ifdef _DHCP_DEBUG_ + printf("> Send DHCP_REQUEST\r\n"); +#endif + + sendto(DHCP6_SOCKET, (uint8_t *)pDHCP6MSG.OPT, rip_msg_size, ip, DHCP6_SERVER_PORT, 16); + +#ifdef _DHCP_DEBUG_ + printf("> %d, %d\r\n", ret, rip_msg_size); +#endif + + return ret; +} + +/** + @brief + + @return int8_t +*/ +int8_t parseDHCP6MSG(void) { + uint8_t svr_addr[16]; + uint16_t svr_port; + uint8_t addlen; + uint16_t len; + uint8_t *p; + uint8_t *e; + uint8_t type, i; + uint16_t opt_len; + uint32_t end_point; + + if ((len = getSn_RX_RSR(DHCP6_SOCKET)) > 0) { + len = recvfrom(DHCP6_SOCKET, (uint8_t *)pDHCP6MSG.OPT, len, svr_addr, (uint16_t *)&svr_port, &addlen); +#ifdef _DHCP6_DEBUG_ + printf("DHCP message : %.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x(%d) %d received. \r\n", svr_addr[0], svr_addr[1], svr_addr[2], svr_addr[3], svr_addr[4], svr_addr[5], svr_addr[6], svr_addr[7], svr_addr[8], svr_addr[9], svr_addr[10], svr_addr[11], svr_addr[12], svr_addr[13], svr_addr[14], svr_addr[15], svr_port, len); +#endif + } else { + return 0; + } + + type = 0; + p = (uint8_t *)(pDHCP6MSG.OPT); + e = p + len; +#ifdef _DHCP6_DEBUG_ + printf("in server port %x\r\n", *p); +#endif + i = 0; + /* + while(p Receive DHCP_ADVERTISE\r\n"); +#endif + + DHCP6_allocated_ip[0] = recv_IP[0]; + DHCP6_allocated_ip[1] = recv_IP[1]; + DHCP6_allocated_ip[2] = recv_IP[2]; + DHCP6_allocated_ip[3] = recv_IP[3]; + DHCP6_allocated_ip[4] = recv_IP[4]; + DHCP6_allocated_ip[5] = recv_IP[5]; + DHCP6_allocated_ip[6] = recv_IP[6]; + DHCP6_allocated_ip[7] = recv_IP[7]; + DHCP6_allocated_ip[8] = recv_IP[8]; + DHCP6_allocated_ip[9] = recv_IP[9]; + DHCP6_allocated_ip[10] = recv_IP[10]; + DHCP6_allocated_ip[11] = recv_IP[11]; + DHCP6_allocated_ip[12] = recv_IP[12]; + DHCP6_allocated_ip[13] = recv_IP[13]; + DHCP6_allocated_ip[14] = recv_IP[14]; + DHCP6_allocated_ip[15] = recv_IP[15]; + + ret = send_DHCP_REQUEST(); + if (ret == 9) { + return 0; + } + dhcp6_state = STATE_DHCP6_REQUEST; + } //else ret = check_DHCP_timeout(); + break; + case STATE_DHCP6_REQUEST: + // 20190318 + //NETUNLOCK(); + + memcpy(netinfo->gua, recv_IP, 16); + + //NETLOCK(); + return DHCP6_IP_LEASED; + default: + break; + } + return ret; +} + +/** + @brief + +*/ +void DHCP6_stop(void) { + close(DHCP6_SOCKET); + dhcp6_state = STATE_DHCP6_STOP; +} + +/** + @brief + + @return uint8_t +*/ +uint8_t check_DHCP6_timeout(void) { + uint8_t ret = DHCP6_RUNNING; + + if (dhcp6_retry_count < MAX_DHCP6_RETRY) { + if (dhcp6_tick_next < dhcp6_tick_1s) { + switch (dhcp6_state) { + case STATE_DHCP6_SOLICIT: { +#ifdef _DHCP6_DEBUG_ + printf("<> state : STATE_DHCP_DISCOVER\r\n"); +#endif + send_DHCP6_SOLICIT(); + break; + } + default: { + break; + } + } + + dhcp6_tick_1s = 0; + dhcp6_tick_next = dhcp6_tick_1s + DHCP6_WAIT_TIME; + dhcp6_retry_count++; + } + } else { + // timeout occurred + + switch (dhcp6_state) { + case STATE_DHCP6_SOLICIT: + dhcp6_state = STATE_DHCP6_INIT; + ret = DHCP6_FAILED; + break; + default: + break; + } + reset_DHCP6_timeout(); + } + return ret; +} + +/** + @brief + + @param s + @param buf +*/ +void DHCP6_init(uint8_t s, uint8_t *buf) { + uint8_t zeroip[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + getSHAR(DHCP6_CHADDR); + if ((DHCP6_CHADDR[0] | DHCP6_CHADDR[1] | DHCP6_CHADDR[2] | DHCP6_CHADDR[3] | DHCP6_CHADDR[4] | DHCP6_CHADDR[5]) == 0x00) { +#ifdef _DHCP6_DEBUG_ + printf("DHCP_init-set MAC\r\n"); +#endif + // assing temporary mac address, you should be set SHAR before call this function. + DHCP6_CHADDR[0] = 0x00; + DHCP6_CHADDR[1] = 0x08; + DHCP6_CHADDR[2] = 0xdc; + DHCP6_CHADDR[3] = 0x00; + DHCP6_CHADDR[4] = 0x00; + DHCP6_CHADDR[5] = 0x00; + setSHAR(DHCP6_CHADDR); + } + + DHCP6_SOCKET = s; // SOCK_DHCP + + memset(buf, 0, sizeof(buf)); + pDHCP6MSG.OPT = buf; + DHCP6_XID = 0x515789; + + reset_DHCP_timeout(); + dhcp6_state = STATE_DHCP6_INIT; +} + +/** + @brief + +*/ +void reset_DHCP6_timeout(void) { + dhcp6_tick_1s = 0; + dhcp6_tick_next = DHCP6_WAIT_TIME; + dhcp6_retry_count = 0; +} + +/** + @brief + +*/ +void DHCP6_time_handler(void) { + dhcp6_tick_1s++; +} + +#endif diff --git a/Internet/DHCP6/dhcpv6.h b/Internet/DHCP6/dhcpv6.h new file mode 100644 index 0000000..b2ff927 --- /dev/null +++ b/Internet/DHCP6/dhcpv6.h @@ -0,0 +1,162 @@ +//***************************************************************************** +// +//! \file dhcpv6.h +//! \brief DHCPv6 APIs Header file. +//! \details Processig DHCPv6 protocol as SOLICIT, ADVERTISE. +//! \version 0.0.1 +//! \date 2016/06/08 +//! \par Revision history +//! <2016/07/18> 1st Release +//! \author JustinKim +//! \copyright +//! +//! Copyright (c) 2016, 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 _DHCP6_H_ +#define _DHCP6_H_ + +#include +#if 1 +// 20231020 taylor +#if 0 +#include "W6100.h" +#endif +#else +#include "W6100.h" +#endif +#include "socket.h" + +#if (_WIZCHIP_ == W6100) + +/* + @brief + @details If you want to display debug & procssing message, Define _DHCP_DEBUG_ + @note If defined, it dependens on +*/ +#if 0 +#define _DHCP6_DEBUG_ +#endif + +/* Retry to processing DHCPv6 */ +#define MAX_DHCP6_RETRY 2 ///< Maxium retry count +#define DHCP6_WAIT_TIME 10 ///< Wait Time 10s + +/* UDP port numbers for DHCPv6 */ +#define DHCP6_SERVER_PORT 547 ///< DHCP6 server port number +#define DHCP6_CLIENT_PORT 546 ///< DHCP6 client port number + +#define DCHP6_HOST_NAME "WIZnet\0" + +/* + @brief return value of @ref DHCP6_run() +*/ +enum { + DHCP6_FAILED = 0, ///< Procssing Fail + DHCP6_RUNNING, ///< Procssing DHCPv6 proctocol + DHCP6_IP_ASSIGN, ///< First Occupy IP from DHCPv6 server (if cbfunc == null, act as default default_ip_assign) + DHCP6_IP_CHANGED, ///< Change IP address by new ip from DHCPv6 (if cbfunc == null, act as default default_ip_update) + DHCP6_IP_LEASED, ///< Stand by + DHCP6_STOPPED ///< Stop procssing DHCPv6 protocol +}; + +/** + @brief + + @param asize + @param agrowby +*/ +void InitDhcp6Option(unsigned asize, unsigned agrowby); +/** + @brief + + @param value +*/ +void AppendDhcp6Option(uint8_t value); +/** + @brief + + @param sMark +*/ +void DumpDhcp6Option(char *sMark); +/** + @brief + + @param Option +*/ +void DHCP6_Option_Select(uint8_t Option); +/* + @brief DHCPv6 client initialization (outside of the main loop) + @param s - socket number + @param buf - buffer for procssing DHCPv6 message +*/ +void DHCP6_init(uint8_t s, uint8_t *buf); + +/* + @brief DHCPv6 1s Tick Timer handler + @note SHOULD BE register to your system 1s Tick timer handler +*/ +void DHCP6_time_handler(void); + +/** + @brief + + @param netinfo + @return uint8_t +*/ +uint8_t DHCP6_run(wiz_NetInfo *netinfo); + +/** + @brief + + @return uint8_t +*/ +uint8_t DHCP6_run2(void); + +/* + @brief Stop DHCPv6 procssing + @note If you want to restart. call DHCP6_init() and DHCP_run() +*/ +void DHCP6_stop(void); + +/* send DISCOVER message to DHCPv6 server */ +void send_DHCP6_SOLICIT(void); +uint8_t send_DHCP6_REQUEST(void); + +/* check the timeout in DHCPv6 process */ +uint8_t check_DHCP6_timeout(void); + +/* Intialize to timeout process. */ +void reset_DHCP6_timeout(void); + +int8_t parseDHCP6MSG(void); +uint8_t DHCP6_run2(void); + +#endif +#endif /* _DHCP6_H_ */ diff --git a/Internet/DNS/dns.c b/Internet/DNS/dns.c new file mode 100644 index 0000000..e4e1969 --- /dev/null +++ b/Internet/DNS/dns.c @@ -0,0 +1,615 @@ +//***************************************************************************** +// +//! \file dns.c +//! \brief DNS APIs Implement file. +//! \details Send DNS query & Receive DNS reponse. \n +//! It depends on stdlib.h & string.h in ansi-c library +//! \version 1.1.0 +//! \date 2013/11/18 +//! \par Revision history +//! <2013/10/21> 1st Release +//! <2013/12/20> V1.1.0 +//! 1. Remove secondary DNS server in DNS_run +//! If 1st DNS_run failed, call DNS_run with 2nd DNS again +//! 2. DNS_timerHandler -> DNS_time_handler +//! 3. Remove the unused define +//! 4. Integrated dns.h dns.c & dns_parse.h dns_parse.c into dns.h & dns.c +//! <2013/12/20> V1.1.0 +//! +//! \author Eric Jung & 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. +// +//***************************************************************************** + +#include +#include + +#include "socket.h" +#include "dns.h" + +#ifdef _DNS_DEBUG_ +#include +#endif + +#define INITRTT 2000L /* Initial smoothed response time */ +#define MAXCNAME (MAX_DOMAIN_NAME + (MAX_DOMAIN_NAME>>1)) /* Maximum amount of cname recursion */ + +#define TYPE_A 1 /* Host address */ +#define TYPE_NS 2 /* Name server */ +#define TYPE_MD 3 /* Mail destination (obsolete) */ +#define TYPE_MF 4 /* Mail forwarder (obsolete) */ +#define TYPE_CNAME 5 /* Canonical name */ +#define TYPE_SOA 6 /* Start of Authority */ +#define TYPE_MB 7 /* Mailbox name (experimental) */ +#define TYPE_MG 8 /* Mail group member (experimental) */ +#define TYPE_MR 9 /* Mail rename name (experimental) */ +#define TYPE_NULL 10 /* Null (experimental) */ +#define TYPE_WKS 11 /* Well-known sockets */ +#define TYPE_PTR 12 /* Pointer record */ +#define TYPE_HINFO 13 /* Host information */ +#define TYPE_MINFO 14 /* Mailbox information (experimental)*/ +#define TYPE_MX 15 /* Mail exchanger */ +#define TYPE_TXT 16 /* Text strings */ +#define TYPE_ANY 255 /* Matches any type */ + +#define CLASS_IN 1 /* The ARPA Internet */ + +/* Round trip timing parameters */ +#define AGAIN 8 /* Average RTT gain = 1/8 */ +#define LAGAIN 3 /* Log2(AGAIN) */ +#define DGAIN 4 /* Mean deviation gain = 1/4 */ +#define LDGAIN 2 /* log2(DGAIN) */ + +/* Header for all domain messages */ +struct dhdr { + uint16_t id; /* Identification */ + uint8_t qr; /* Query/Response */ +#define QUERY 0 +#define RESPONSE 1 + uint8_t opcode; +#define IQUERY 1 + uint8_t aa; /* Authoratative answer */ + uint8_t tc; /* Truncation */ + uint8_t rd; /* Recursion desired */ + uint8_t ra; /* Recursion available */ + uint8_t rcode; /* Response code */ +#define NO_ERROR 0 +#define FORMAT_ERROR 1 +#define SERVER_FAIL 2 +#define NAME_ERROR 3 +#define NOT_IMPL 4 +#define REFUSED 5 + uint16_t qdcount; /* Question count */ + uint16_t ancount; /* Answer count */ + uint16_t nscount; /* Authority (name server) count */ + uint16_t arcount; /* Additional record count */ +}; + + +uint8_t* pDNSMSG; // DNS message buffer +uint8_t DNS_SOCKET; // SOCKET number for DNS +uint16_t DNS_MSGID; // DNS message ID + +uint32_t dns_1s_tick; // for timout of DNS processing +static uint8_t retry_count; + +/* converts uint16_t from network buffer to a host byte order integer. */ +uint16_t get16(uint8_t * s) { + uint16_t i; + i = *s++ << 8; + i = i + *s; + return i; +} + +/* copies uint16_t to the network buffer with network byte order. */ +uint8_t * put16(uint8_t * s, uint16_t i) { + *s++ = i >> 8; + *s++ = i; + return s; +} + + +/* + CONVERT A DOMAIN NAME TO THE HUMAN-READABLE FORM + + Description : This function converts a compressed domain name to the human-readable form + Arguments : msg - is a pointer to the reply message + compressed - is a pointer to the domain name in reply message. + buf - is a pointer to the buffer for the human-readable form name. + len - is the MAX. size of buffer. + Returns : the length of compressed message +*/ +int parse_name(uint8_t * msg, uint8_t * compressed, char * buf, int16_t len) { + uint16_t slen; /* Length of current segment */ + uint8_t * cp; + int clen = 0; /* Total length of compressed name */ + int indirect = 0; /* Set if indirection encountered */ + int nseg = 0; /* Total number of segments in name */ + + cp = compressed; + + for (;;) { + slen = *cp++; /* Length of this segment */ + + if (!indirect) { + clen++; + } + + if ((slen & 0xc0) == 0xc0) { + if (!indirect) { + clen++; + } + indirect = 1; + /* Follow indirection */ + cp = &msg[((slen & 0x3f) << 8) + *cp]; + slen = *cp++; + } + + if (slen == 0) { /* zero length == all done */ + break; + } + + len -= slen + 1; + + if (len < 0) { + return -1; + } + + if (!indirect) { + clen += slen; + } + + while (slen-- != 0) { + *buf++ = (char) * cp++; + } + *buf++ = '.'; + nseg++; + } + + if (nseg == 0) { + /* Root name; represent as single dot */ + *buf++ = '.'; + len--; + } + + *buf++ = '\0'; + len--; + + return clen; /* Length of compressed message */ +} + +/* + PARSE QUESTION SECTION + + Description : This function parses the qeustion record of the reply message. + Arguments : msg - is a pointer to the reply message + cp - is a pointer to the qeustion record. + Returns : a pointer the to next record. +*/ +uint8_t * dns_question(uint8_t * msg, uint8_t * cp) { + int len; + char name[MAXCNAME]; + + len = parse_name(msg, cp, name, MAXCNAME); + + + if (len == -1) { + return 0; + } + + cp += len; + cp += 2; /* type */ + cp += 2; /* class */ + + return cp; +} + + +/* + PARSE ANSER SECTION + + Description : This function parses the answer record of the reply message. + Arguments : msg - is a pointer to the reply message + cp - is a pointer to the answer record. + Returns : a pointer the to next record. +*/ +uint8_t * dns_answer(uint8_t * msg, uint8_t * cp, uint8_t * ip_from_dns) { + int len, type; + char name[MAXCNAME]; + + len = parse_name(msg, cp, name, MAXCNAME); + + if (len == -1) { + return 0; + } + + cp += len; + type = get16(cp); + cp += 2; /* type */ + cp += 2; /* class */ + cp += 4; /* ttl */ + cp += 2; /* len */ + + + switch (type) { + case TYPE_A: + /* Just read the address directly into the structure */ + ip_from_dns[0] = *cp++; + ip_from_dns[1] = *cp++; + ip_from_dns[2] = *cp++; + ip_from_dns[3] = *cp++; + break; + case TYPE_CNAME: + case TYPE_MB: + case TYPE_MG: + case TYPE_MR: + case TYPE_NS: + case TYPE_PTR: + /* These types all consist of a single domain name */ + /* convert it to ascii format */ + len = parse_name(msg, cp, name, MAXCNAME); + if (len == -1) { + return 0; + } + + cp += len; + break; + case TYPE_HINFO: + len = *cp++; + cp += len; + + len = *cp++; + cp += len; + break; + case TYPE_MX: + cp += 2; + /* Get domain name of exchanger */ + len = parse_name(msg, cp, name, MAXCNAME); + if (len == -1) { + return 0; + } + + cp += len; + break; + case TYPE_SOA: + /* Get domain name of name server */ + len = parse_name(msg, cp, name, MAXCNAME); + if (len == -1) { + return 0; + } + + cp += len; + + /* Get domain name of responsible person */ + len = parse_name(msg, cp, name, MAXCNAME); + if (len == -1) { + return 0; + } + + cp += len; + + cp += 4; + cp += 4; + cp += 4; + cp += 4; + cp += 4; + break; + case TYPE_TXT: + /* Just stash */ + break; + default: + /* Ignore */ + break; + } + + return cp; +} + +/* + PARSE THE DNS REPLY + + Description : This function parses the reply message from DNS server. + Arguments : dhdr - is a pointer to the header for DNS message + buf - is a pointer to the reply message. + len - is the size of reply message. + Returns : -1 - Domain name lenght is too big + 0 - Fail (Timout or parse error) + 1 - Success, +*/ +int8_t parseDNSMSG(struct dhdr * pdhdr, uint8_t * pbuf, uint8_t * ip_from_dns) { + uint16_t tmp; + uint16_t i; + uint8_t * msg; + uint8_t * cp; + + msg = pbuf; + memset(pdhdr, 0, sizeof(*pdhdr)); + + pdhdr->id = get16(&msg[0]); + tmp = get16(&msg[2]); + if (tmp & 0x8000) { + pdhdr->qr = 1; + } + + pdhdr->opcode = (tmp >> 11) & 0xf; + + if (tmp & 0x0400) { + pdhdr->aa = 1; + } + if (tmp & 0x0200) { + pdhdr->tc = 1; + } + if (tmp & 0x0100) { + pdhdr->rd = 1; + } + if (tmp & 0x0080) { + pdhdr->ra = 1; + } + + pdhdr->rcode = tmp & 0xf; + pdhdr->qdcount = get16(&msg[4]); + pdhdr->ancount = get16(&msg[6]); + pdhdr->nscount = get16(&msg[8]); + pdhdr->arcount = get16(&msg[10]); + + + /* Now parse the variable length sections */ + cp = &msg[12]; + + /* Question section */ + for (i = 0; i < pdhdr->qdcount; i++) { + cp = dns_question(msg, cp); +#ifdef _DNS_DEUBG_ + printf("MAX_DOMAIN_NAME is too small, it should be redfine in dns.h"); +#endif + if (!cp) { + return -1; + } + } + + /* Answer section */ + for (i = 0; i < pdhdr->ancount; i++) { + 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"); +#endif + if (!cp) { + return -1; + } + } + + /* Name server (authority) section */ + for (i = 0; i < pdhdr->nscount; i++) { + ; + } + + /* Additional section */ + for (i = 0; i < pdhdr->arcount; i++) { + ; + } + + if (pdhdr->rcode == 0) { + return 1; // No error + } else { + return 0; + } +} + + +/* + MAKE DNS QUERY MESSAGE + + Description : This function makes DNS query message. + Arguments : op - Recursion desired + name - is a pointer to the domain name. + buf - is a pointer to the buffer for DNS message. + 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; + char *cp1; + char sname[MAXCNAME]; + char *dname; + uint16_t p; + uint16_t dlen; + + cp = buf; + + DNS_MSGID++; + cp = put16(cp, DNS_MSGID); + p = (op << 11) | 0x0100; /* Recursion desired */ + cp = put16(cp, p); + cp = put16(cp, 1); + cp = put16(cp, 0); + cp = put16(cp, 0); + cp = put16(cp, 0); + + 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 */ + } + + *cp++ = len; /* Write length of component */ + if (len == 0) { + break; + } + + /* 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 */ + break; + } + dname += len + 1; + dlen -= len + 1; + } + + cp = put16(cp, 0x0001); /* type */ + cp = put16(cp, 0x0001); /* class */ + + return ((int16_t)((uint32_t)(cp) - (uint32_t)(buf))); +} + +/* + CHECK DNS TIMEOUT + + Description : This function check the DNS timeout + Arguments : None. + Returns : -1 - timeout occurred, 0 - timer over, but no timeout, 1 - no timer over, no timeout occur + Note : timeout : retry count and timer both over. +*/ + +int8_t check_DNS_timeout(void) { + + if (dns_1s_tick >= DNS_WAIT_TIME) { + dns_1s_tick = 0; + if (retry_count >= MAX_DNS_RETRY) { + retry_count = 0; + return -1; // timeout occurred + } + retry_count++; + return 0; // timer over, but no timeout + } + + return 1; // no timer over, no timeout occur +} + + + +/* DNS CLIENT INIT */ +void DNS_init(uint8_t s, uint8_t * buf) { + DNS_SOCKET = s; // SOCK_DNS + pDNSMSG = buf; // User's shared buffer + DNS_MSGID = DNS_MSG_ID; +} + +/* DNS CLIENT RUN */ +int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns) { + int8_t ret; + struct dhdr dhp; + uint8_t ip[4]; + uint16_t len, port; + int8_t ret_check_timeout; + + retry_count = 0; + dns_1s_tick = 0; +#if 1 + // 20231019 taylor + uint8_t addr_len; +#endif + + // Socket open + socket(DNS_SOCKET, Sn_MR_UDP, 0, 0); + +#ifdef _DNS_DEBUG_ + printf("> DNS Query to DNS Server : %d.%d.%d.%d\r\n", dns_ip[0], dns_ip[1], dns_ip[2], dns_ip[3]); +#endif + + len = dns_makequery(0, (char *)name, pDNSMSG, MAX_DNS_BUF_SIZE); +#if 1 + // 20231016 taylor//teddy 240122 +#if ((_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300)) + sendto(DNS_SOCKET, pDNSMSG, len, dns_ip, IPPORT_DOMAIN, 4); +#else + sendto(DNS_SOCKET, pDNSMSG, len, dns_ip, IPPORT_DOMAIN); +#endif +#else + sendto(DNS_SOCKET, pDNSMSG, len, dns_ip, IPPORT_DOMAIN); +#endif + + while (1) { + if ((len = getSn_RX_RSR(DNS_SOCKET)) > 0) { + if (len > MAX_DNS_BUF_SIZE) { + len = MAX_DNS_BUF_SIZE; + } +#if 1 + // 20231019 taylor//teddy 240122 +#if ((_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300)) + len = recvfrom(DNS_SOCKET, pDNSMSG, len, ip, &port, &addr_len); +#else + len = recvfrom(DNS_SOCKET, pDNSMSG, len, ip, &port); +#endif +#else + len = recvfrom(DNS_SOCKET, pDNSMSG, len, ip, &port); +#endif +#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); +#endif + ret = parseDNSMSG(&dhp, pDNSMSG, ip_from_dns); + break; + } + // Check Timeout + ret_check_timeout = check_DNS_timeout(); + if (ret_check_timeout < 0) { + +#ifdef _DNS_DEBUG_ + printf("> DNS Server is not responding : %d.%d.%d.%d\r\n", dns_ip[0], dns_ip[1], dns_ip[2], dns_ip[3]); +#endif + close(DNS_SOCKET); + return 0; // timeout occurred + } else if (ret_check_timeout == 0) { + +#ifdef _DNS_DEBUG_ + printf("> DNS Timeout\r\n"); +#endif +#if 1 + // 20231016 taylor//teddy 240122 +#if ((_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300)) + sendto(DNS_SOCKET, pDNSMSG, len, dns_ip, IPPORT_DOMAIN, 4); +#else + sendto(DNS_SOCKET, pDNSMSG, len, dns_ip, IPPORT_DOMAIN); +#endif +#else + sendto(DNS_SOCKET, pDNSMSG, len, dns_ip, IPPORT_DOMAIN); +#endif + } + } + close(DNS_SOCKET); + // Return value + // 0 > : failed / 1 - success + return ret; +} + + +/* DNS TIMER HANDLER */ +void DNS_time_handler(void) { + dns_1s_tick++; +} diff --git a/Internet/DNS/dns.h b/Internet/DNS/dns.h new file mode 100644 index 0000000..8d0e242 --- /dev/null +++ b/Internet/DNS/dns.h @@ -0,0 +1,109 @@ +//***************************************************************************** +// +//! \file dns.h +//! \brief DNS APIs Header file. +//! \details Send DNS query & Receive DNS reponse. +//! \version 1.1.0 +//! \date 2013/11/18 +//! \par Revision history +//! <2013/10/21> 1st Release +//! <2013/12/20> V1.1.0 +//! 1. Remove secondary DNS server in DNS_run +//! If 1st DNS_run failed, call DNS_run with 2nd DNS again +//! 2. DNS_timerHandler -> DNS_time_handler +//! 3. Move the no reference define to dns.c +//! 4. Integrated dns.h dns.c & dns_parse.h dns_parse.c into dns.h & dns.c +//! <2013/12/20> V1.1.0 +//! +//! \author Eric Jung & 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 _DNS_H_ +#define _DNS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +/* + @brief Define it for Debug & Monitor DNS processing. + @note If defined, it dependens on +*/ +//#define _DNS_DEBUG_ + +#define MAX_DNS_BUF_SIZE 256 ///< maximum size of DNS buffer. */ +/* + @brief Maxium length of your queried Domain name + @todo SHOULD BE defined it equal as or greater than your Domain name lenght + null character(1) + @note SHOULD BE careful to stack overflow because it is allocated 1.5 times as MAX_DOMAIN_NAME in stack. +*/ +#define MAX_DOMAIN_NAME 128 // for example "www.google.com" + +#define MAX_DNS_RETRY 2 ///< Requery Count +#define DNS_WAIT_TIME 3 ///< Wait response time. unit 1s. + +#define IPPORT_DOMAIN 53 ///< DNS server port number + +#define DNS_MSG_ID 0x1122 ///< ID for DNS message. You can be modifyed it any number +/* + @brief DNS process initialize + @param s : Socket number for DNS + @param buf : Buffer for DNS message +*/ +void DNS_init(uint8_t s, uint8_t * buf); + +/* + @brief DNS process + @details Send DNS query and receive DNS response + @param dns_ip : DNS server ip + @param name : Domain name to be queryed + @param ip_from_dns : IP address from DNS server + @return -1 : failed. @ref MAX_DOMIN_NAME is too small \n + 0 : failed (Timeout or Parse error)\n + 1 : success + @note This funtion blocks until success or fail. max time = @ref MAX_DNS_RETRY * @ref DNS_WAIT_TIME +*/ +int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns); + +/* + @brief DNS 1s Tick Timer handler + @note SHOULD BE register to your system 1s Tick timer handler +*/ +void DNS_time_handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _DNS_H_ */ diff --git a/Internet/MQTT/MQTTClient.c b/Internet/MQTT/MQTTClient.c new file mode 100644 index 0000000..8a7c9f6 --- /dev/null +++ b/Internet/MQTT/MQTTClient.c @@ -0,0 +1,572 @@ +/******************************************************************************* + Copyright (c) 2014, 2015 IBM Corp. + + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + and Eclipse Distribution License v1.0 which accompany this distribution. + + The Eclipse Public License is available at + http://www.eclipse.org/legal/epl-v10.html + and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + + Contributors: + Allan Stockdill-Mander/Ian Craggs - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "MQTTClient.h" + +static void NewMessageData(MessageData* md, MQTTString* aTopicName, MQTTMessage* aMessage) { + md->topicName = aTopicName; + md->message = aMessage; +} + + +static int getNextPacketId(MQTTClient *c) { + return c->next_packetid = (c->next_packetid == MAX_PACKET_ID) ? 1 : c->next_packetid + 1; +} + + +static int sendPacket(MQTTClient* c, int length, Timer* timer) { + int rc = FAILURE, + sent = 0; + + while (sent < length && !TimerIsExpired(timer)) { + rc = c->ipstack->mqttwrite(c->ipstack, &c->buf[sent], length, TimerLeftMS(timer)); + if (rc < 0) { // there was an error writing the data + break; + } + sent += rc; + } + if (sent == length) { + TimerCountdown(&c->ping_timer, c->keepAliveInterval); // record the fact that we have successfully sent the packet + rc = SUCCESSS; + } else { + rc = FAILURE; + } + return rc; +} + + +void MQTTClientInit(MQTTClient* c, Network* network, unsigned int command_timeout_ms, + unsigned char* sendbuf, size_t sendbuf_size, unsigned char* readbuf, size_t readbuf_size) { + int i; + c->ipstack = network; + + for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i) { + c->messageHandlers[i].topicFilter = 0; + } + c->command_timeout_ms = command_timeout_ms; + c->buf = sendbuf; + c->buf_size = sendbuf_size; + c->readbuf = readbuf; + c->readbuf_size = readbuf_size; + c->isconnected = 0; + c->ping_outstanding = 0; + c->defaultMessageHandler = NULL; + c->next_packetid = 1; + TimerInit(&c->ping_timer); +#if defined(MQTT_TASK) + MutexInit(&c->mutex); +#endif +} + + +static int decodePacket(MQTTClient* c, int* value, int timeout) { + unsigned char i; + int multiplier = 1; + int len = 0; + const int MAX_NO_OF_REMAINING_LENGTH_BYTES = 4; + + *value = 0; + do { + int rc = MQTTPACKET_READ_ERROR; + + if (++len > MAX_NO_OF_REMAINING_LENGTH_BYTES) { + rc = MQTTPACKET_READ_ERROR; /* bad data */ + goto exit; + } + rc = c->ipstack->mqttread(c->ipstack, &i, 1, timeout); + if (rc != 1) { + goto exit; + } + *value += (i & 127) * multiplier; + multiplier *= 128; + } while ((i & 128) != 0); +exit: + return len; +} + + +static int readPacket(MQTTClient* c, Timer* timer) { + int rc = FAILURE; + MQTTHeader header = {0}; + int len = 0; + int rem_len = 0; + + /* 1. read the header byte. This has the packet type in it */ + if (c->ipstack->mqttread(c->ipstack, c->readbuf, 1, TimerLeftMS(timer)) != 1) { + goto exit; + } + + len = 1; + /* 2. read the remaining length. This is variable in itself */ + decodePacket(c, &rem_len, TimerLeftMS(timer)); + len += MQTTPacket_encode(c->readbuf + 1, rem_len); /* put the original remaining length back into the buffer */ + + /* 3. read the rest of the buffer using a callback to supply the rest of the data */ + if (rem_len > 0 && (c->ipstack->mqttread(c->ipstack, c->readbuf + len, rem_len, TimerLeftMS(timer)) != rem_len)) { + goto exit; + } + + header.byte = c->readbuf[0]; + rc = header.bits.type; +exit: + return rc; +} + + +// assume topic filter and name is in correct format +// # can only be at end +// + and # can only be next to separator +static char isTopicMatched(char* topicFilter, MQTTString* topicName) { + char* curf = topicFilter; + char* curn = topicName->lenstring.data; + char* curn_end = curn + topicName->lenstring.len; + + while (*curf && curn < curn_end) { + if (*curn == '/' && *curf != '/') { + break; + } + if (*curf != '+' && *curf != '#' && *curf != *curn) { + break; + } + if (*curf == '+') { + // skip until we meet the next separator, or end of string + char* nextpos = curn + 1; + while (nextpos < curn_end && *nextpos != '/') { + nextpos = ++curn + 1; + } + } else if (*curf == '#') { + curn = curn_end - 1; // skip until end of string + } + curf++; + curn++; + }; + + return (curn == curn_end) && (*curf == '\0'); +} + + +int deliverMessage(MQTTClient* c, MQTTString* topicName, MQTTMessage* message) { + int i; + int rc = FAILURE; + + // we have to find the right message handler - indexed by topic + for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i) { + if (c->messageHandlers[i].topicFilter != 0 && (MQTTPacket_equals(topicName, (char *)c->messageHandlers[i].topicFilter) || + isTopicMatched((char *)c->messageHandlers[i].topicFilter, topicName))) { + if (c->messageHandlers[i].fp != NULL) { + MessageData md; + NewMessageData(&md, topicName, message); + c->messageHandlers[i].fp(&md); + rc = SUCCESSS; + } + } + } + + if (rc == FAILURE && c->defaultMessageHandler != NULL) { + MessageData md; + NewMessageData(&md, topicName, message); + c->defaultMessageHandler(&md); + rc = SUCCESSS; + } + + return rc; +} + + +int keepalive(MQTTClient* c) { + int rc = FAILURE; + + if (c->keepAliveInterval == 0) { + rc = SUCCESSS; + goto exit; + } + + if (TimerIsExpired(&c->ping_timer)) { + if (!c->ping_outstanding) { + Timer timer; + TimerInit(&timer); + TimerCountdownMS(&timer, 1000); + int len = MQTTSerialize_pingreq(c->buf, c->buf_size); + if (len > 0 && (rc = sendPacket(c, len, &timer)) == SUCCESSS) { // send the ping packet + c->ping_outstanding = 1; + } + } + } + +exit: + return rc; +} + + +int cycle(MQTTClient* c, Timer* timer) { + // read the socket, see what work is due + unsigned short packet_type = readPacket(c, timer); + + int len = 0, + rc = SUCCESSS; + + switch (packet_type) { + case CONNACK: + case PUBACK: + case SUBACK: + break; + case PUBLISH: { + MQTTString topicName; + MQTTMessage msg; + int intQoS; + if (MQTTDeserialize_publish(&msg.dup, &intQoS, &msg.retained, &msg.id, &topicName, + (unsigned char * *)&msg.payload, (int *)&msg.payloadlen, c->readbuf, c->readbuf_size) != 1) { + goto exit; + } + msg.qos = (enum QoS)intQoS; + deliverMessage(c, &topicName, &msg); + if (msg.qos != QOS0) { + if (msg.qos == QOS1) { + len = MQTTSerialize_ack(c->buf, c->buf_size, PUBACK, 0, msg.id); + } else if (msg.qos == QOS2) { + len = MQTTSerialize_ack(c->buf, c->buf_size, PUBREC, 0, msg.id); + } + if (len <= 0) { + rc = FAILURE; + } else { + rc = sendPacket(c, len, timer); + } + if (rc == FAILURE) { + goto exit; // there was a problem + } + } + break; + } + case PUBREC: { + unsigned short mypacketid; + unsigned char dup, type; + if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->readbuf, c->readbuf_size) != 1) { + rc = FAILURE; + } else if ((len = MQTTSerialize_ack(c->buf, c->buf_size, PUBREL, 0, mypacketid)) <= 0) { + rc = FAILURE; + } else if ((rc = sendPacket(c, len, timer)) != SUCCESSS) { // send the PUBREL packet + rc = FAILURE; // there was a problem + } + if (rc == FAILURE) { + goto exit; // there was a problem + } + break; + } + case PUBCOMP: + break; + case PINGRESP: + c->ping_outstanding = 0; + break; + } + keepalive(c); +exit: + if (rc == SUCCESSS) { + rc = packet_type; + } + return rc; +} + + +int MQTTYield(MQTTClient* c, int timeout_ms) { + int rc = SUCCESSS; + Timer timer; + + TimerInit(&timer); + TimerCountdownMS(&timer, timeout_ms); + + if (cycle(c, &timer) == FAILURE) { + rc = FAILURE; + } + + return rc; +} + + +void MQTTRun(void* parm) { + Timer timer; + MQTTClient* c = (MQTTClient*)parm; + + TimerInit(&timer); + + while (1) { +#if defined(MQTT_TASK) + MutexLock(&c->mutex); +#endif + TimerCountdownMS(&timer, 500); /* Don't wait too long if no traffic is incoming */ + cycle(c, &timer); +#if defined(MQTT_TASK) + MutexUnlock(&c->mutex); +#endif + } +} + + +#if defined(MQTT_TASK) +int MQTTStartTask(MQTTClient* client) { + return ThreadStart(&client->thread, &MQTTRun, client); +} +#endif + + +int waitfor(MQTTClient* c, int packet_type, Timer* timer) { + int rc = FAILURE; + + do { + if (TimerIsExpired(timer)) { + break; // we timed out + } + } while ((rc = cycle(c, timer)) != packet_type); + + return rc; +} + + +int MQTTConnect(MQTTClient* c, MQTTPacket_connectData* options) { + Timer connect_timer; + int rc = FAILURE; + MQTTPacket_connectData default_options = MQTTPacket_connectData_initializer; + int len = 0; + +#if defined(MQTT_TASK) + MutexLock(&c->mutex); +#endif + if (c->isconnected) { /* don't send connect packet again if we are already connected */ + goto exit; + } + + TimerInit(&connect_timer); + TimerCountdownMS(&connect_timer, c->command_timeout_ms); + + if (options == 0) { + options = &default_options; /* set default options if none were supplied */ + } + + c->keepAliveInterval = options->keepAliveInterval; + TimerCountdown(&c->ping_timer, c->keepAliveInterval); + if ((len = MQTTSerialize_connect(c->buf, c->buf_size, options)) <= 0) { + goto exit; + } + if ((rc = sendPacket(c, len, &connect_timer)) != SUCCESSS) { // send the connect packet + goto exit; // there was a problem + } + + // this will be a blocking call, wait for the connack + if (waitfor(c, CONNACK, &connect_timer) == CONNACK) { + unsigned char connack_rc = 255; + unsigned char sessionPresent = 0; + if (MQTTDeserialize_connack(&sessionPresent, &connack_rc, c->readbuf, c->readbuf_size) == 1) { + rc = connack_rc; + } else { + rc = FAILURE; + } + } else { + rc = FAILURE; + } + +exit: + if (rc == SUCCESSS) { + c->isconnected = 1; + } + +#if defined(MQTT_TASK) + MutexUnlock(&c->mutex); +#endif + + return rc; +} + + +int MQTTSubscribe(MQTTClient* c, const char* topicFilter, enum QoS qos, messageHandler messageHandler) { + int rc = FAILURE; + Timer timer; + int len = 0; + MQTTString topic = MQTTString_initializer; + topic.cstring = (char *)topicFilter; + // This was added because enum QoS was previously typed to *int which resulted in HardFault and unaligned integer read. + // This coping below makes sure the parameter for MQTTSerialize_subscribe is always char no matter what compiler is using for enums + char charQos = (char)qos; + +#if defined(MQTT_TASK) + MutexLock(&c->mutex); +#endif + if (!c->isconnected) { + goto exit; + } + + TimerInit(&timer); + TimerCountdownMS(&timer, c->command_timeout_ms); + + len = MQTTSerialize_subscribe(c->buf, c->buf_size, 0, getNextPacketId(c), 1, &topic, &charQos); + if (len <= 0) { + goto exit; + } + if ((rc = sendPacket(c, len, &timer)) != SUCCESSS) { // send the subscribe packet + goto exit; // there was a problem + } + + if (waitfor(c, SUBACK, &timer) == SUBACK) { // wait for suback + int count = 0, grantedQoS = -1; + unsigned short mypacketid; + if (MQTTDeserialize_suback(&mypacketid, 1, &count, &grantedQoS, c->readbuf, c->readbuf_size) == 1) { + rc = grantedQoS; // 0, 1, 2 or 0x80 + } + if (rc != 0x80) { + int i; + for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i) { + if (c->messageHandlers[i].topicFilter == 0) { + c->messageHandlers[i].topicFilter = topicFilter; + c->messageHandlers[i].fp = messageHandler; + rc = 0; + break; + } + } + } + } else { + rc = FAILURE; + } + +exit: +#if defined(MQTT_TASK) + MutexUnlock(&c->mutex); +#endif + return rc; +} + + +int MQTTUnsubscribe(MQTTClient* c, const char* topicFilter) { + int rc = FAILURE; + Timer timer; + MQTTString topic = MQTTString_initializer; + topic.cstring = (char *)topicFilter; + int len = 0; + +#if defined(MQTT_TASK) + MutexLock(&c->mutex); +#endif + if (!c->isconnected) { + goto exit; + } + + TimerInit(&timer); + TimerCountdownMS(&timer, c->command_timeout_ms); + + if ((len = MQTTSerialize_unsubscribe(c->buf, c->buf_size, 0, getNextPacketId(c), 1, &topic)) <= 0) { + goto exit; + } + if ((rc = sendPacket(c, len, &timer)) != SUCCESSS) { // send the subscribe packet + goto exit; // there was a problem + } + + if (waitfor(c, UNSUBACK, &timer) == UNSUBACK) { + unsigned short mypacketid; // should be the same as the packetid above + if (MQTTDeserialize_unsuback(&mypacketid, c->readbuf, c->readbuf_size) == 1) { + rc = 0; + } + } else { + rc = FAILURE; + } + +exit: +#if defined(MQTT_TASK) + MutexUnlock(&c->mutex); +#endif + return rc; +} + + +int MQTTPublish(MQTTClient* c, const char* topicName, MQTTMessage* message) { + int rc = FAILURE; + Timer timer; + MQTTString topic = MQTTString_initializer; + topic.cstring = (char *)topicName; + int len = 0; + +#if defined(MQTT_TASK) + MutexLock(&c->mutex); +#endif + if (!c->isconnected) { + goto exit; + } + + TimerInit(&timer); + TimerCountdownMS(&timer, c->command_timeout_ms); + + if (message->qos == QOS1 || message->qos == QOS2) { + message->id = getNextPacketId(c); + } + + len = MQTTSerialize_publish(c->buf, c->buf_size, 0, message->qos, message->retained, message->id, + topic, (unsigned char*)message->payload, message->payloadlen); + if (len <= 0) { + goto exit; + } + if ((rc = sendPacket(c, len, &timer)) != SUCCESSS) { // send the subscribe packet + goto exit; // there was a problem + } + + if (message->qos == QOS1) { + if (waitfor(c, PUBACK, &timer) == PUBACK) { + unsigned short mypacketid; + unsigned char dup, type; + if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->readbuf, c->readbuf_size) != 1) { + rc = FAILURE; + } + } else { + rc = FAILURE; + } + } else if (message->qos == QOS2) { + if (waitfor(c, PUBCOMP, &timer) == PUBCOMP) { + unsigned short mypacketid; + unsigned char dup, type; + if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->readbuf, c->readbuf_size) != 1) { + rc = FAILURE; + } + } else { + rc = FAILURE; + } + } + +exit: +#if defined(MQTT_TASK) + MutexUnlock(&c->mutex); +#endif + return rc; +} + + +int MQTTDisconnect(MQTTClient* c) { + int rc = FAILURE; + Timer timer; // we might wait for incomplete incoming publishes to complete + int len = 0; + +#if defined(MQTT_TASK) + MutexLock(&c->mutex); +#endif + TimerInit(&timer); + TimerCountdownMS(&timer, c->command_timeout_ms); + + len = MQTTSerialize_disconnect(c->buf, c->buf_size); + if (len > 0) { + rc = sendPacket(c, len, &timer); // send the disconnect packet + } + + c->isconnected = 0; + +#if defined(MQTT_TASK) + MutexUnlock(&c->mutex); +#endif + return rc; +} + diff --git a/Internet/MQTT/MQTTClient.h b/Internet/MQTT/MQTTClient.h new file mode 100644 index 0000000..0818404 --- /dev/null +++ b/Internet/MQTT/MQTTClient.h @@ -0,0 +1,178 @@ +/******************************************************************************* + Copyright (c) 2014, 2015 IBM Corp. + + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + and Eclipse Distribution License v1.0 which accompany this distribution. + + The Eclipse Public License is available at + http://www.eclipse.org/legal/epl-v10.html + and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + + Contributors: + Allan Stockdill-Mander/Ian Craggs - initial API and implementation and/or initial documentation + Ian Craggs - documentation and platform specific header + *******************************************************************************/ + +#if !defined(__MQTT_CLIENT_C_) +#define __MQTT_CLIENT_C_ + +#if defined(__cplusplus) +extern "C" { +#endif + +#if defined(WIN32_DLL) || defined(WIN64_DLL) +#define DLLImport __declspec(dllimport) +#define DLLExport __declspec(dllexport) +#elif defined(LINUX_SO) +#define DLLImport extern +#define DLLExport __attribute__ ((visibility ("default"))) +#else +#define DLLImport +#define DLLExport +#endif + +#include "./MQTTPacket/src/MQTTPacket.h" +#include "stdio.h" +#include "mqtt_interface.h" + +#define MAX_PACKET_ID 65535 /* according to the MQTT specification - do not change! */ + +#if !defined(MAX_MESSAGE_HANDLERS) +#define MAX_MESSAGE_HANDLERS 5 /* redefinable - how many subscriptions do you want? */ +#endif + +enum QoS { QOS0, QOS1, QOS2 }; + +/* all failure return codes must be negative */ +enum returnCode { BUFFER_OVERFLOW = -2, FAILURE = -1, SUCCESSS = 0 }; + +/* The Platform specific header must define the Network and Timer structures and functions + which operate on them. + + typedef struct Network + { + int (*mqttread)(Network*, unsigned char* read_buffer, int, int); + int (*mqttwrite)(Network*, unsigned char* send_buffer, int, int); + } Network;*/ + +/* The Timer structure must be defined in the platform specific header, + and have the following functions to operate on it. */ +extern void TimerInit(Timer*); +extern char TimerIsExpired(Timer*); +extern void TimerCountdownMS(Timer*, unsigned int); +extern void TimerCountdown(Timer*, unsigned int); +extern int TimerLeftMS(Timer*); + +typedef struct MQTTMessage { + enum QoS qos; + unsigned char retained; + unsigned char dup; + unsigned short id; + void *payload; + size_t payloadlen; +} MQTTMessage; + +typedef struct MessageData { + MQTTMessage* message; + MQTTString* topicName; +} MessageData; + +typedef void (*messageHandler)(MessageData*); + +typedef struct MQTTClient { + unsigned int next_packetid, + command_timeout_ms; + size_t buf_size, + readbuf_size; + unsigned char *buf, + *readbuf; + unsigned int keepAliveInterval; + char ping_outstanding; + int isconnected; + + struct MessageHandlers { + const char* topicFilter; + void (*fp) (MessageData*); + } messageHandlers[MAX_MESSAGE_HANDLERS]; /* Message handlers are indexed by subscription topic */ + + void (*defaultMessageHandler) (MessageData*); + + Network* ipstack; + Timer ping_timer; +#if defined(MQTT_TASK) + Mutex mutex; + Thread thread; +#endif +} MQTTClient; + +#define DefaultClient {0, 0, 0, 0, NULL, NULL, 0, 0, 0} + + +/** + Create an MQTT client object + @param client + @param network + @param command_timeout_ms + @param +*/ +DLLExport void MQTTClientInit(MQTTClient* client, Network* network, unsigned int command_timeout_ms, + unsigned char* sendbuf, size_t sendbuf_size, unsigned char* readbuf, size_t readbuf_size); + +/** MQTT Connect - send an MQTT connect packet down the network and wait for a Connack + The nework object must be connected to the network endpoint before calling this + @param options - connect options + @return success code +*/ +DLLExport int MQTTConnect(MQTTClient* client, MQTTPacket_connectData* options); + +/** MQTT Publish - send an MQTT publish packet and wait for all acks to complete for all QoSs + @param client - the client object to use + @param topic - the topic to publish to + @param message - the message to send + @return success code +*/ +DLLExport int MQTTPublish(MQTTClient* client, const char*, MQTTMessage*); + +/** MQTT Subscribe - send an MQTT subscribe packet and wait for suback before returning. + @param client - the client object to use + @param topicFilter - the topic filter to subscribe to + @param message - the message to send + @return success code +*/ +DLLExport int MQTTSubscribe(MQTTClient* client, const char* topicFilter, enum QoS, messageHandler); + +/** MQTT Subscribe - send an MQTT unsubscribe packet and wait for unsuback before returning. + @param client - the client object to use + @param topicFilter - the topic filter to unsubscribe from + @return success code +*/ +DLLExport int MQTTUnsubscribe(MQTTClient* client, const char* topicFilter); + +/** MQTT Disconnect - send an MQTT disconnect packet and close the connection + @param client - the client object to use + @return success code +*/ +DLLExport int MQTTDisconnect(MQTTClient* client); + +/** MQTT Yield - MQTT background + @param client - the client object to use + @param time - the time, in milliseconds, to yield for + @return success code +*/ +DLLExport int MQTTYield(MQTTClient* client, int time); + +#if defined(MQTT_TASK) +/** MQTT start background thread for a client. After this, MQTTYield should not be called. + @param client - the client object to use + @return success code +*/ +DLLExport int MQTTStartTask(MQTTClient* client); +#endif + +#if defined(__cplusplus) +} +#endif + +#endif diff --git a/Internet/MQTT/MQTTPacket/src/MQTTConnect.h b/Internet/MQTT/MQTTPacket/src/MQTTConnect.h new file mode 100644 index 0000000..3a68e2f --- /dev/null +++ b/Internet/MQTT/MQTTPacket/src/MQTTConnect.h @@ -0,0 +1,128 @@ +/******************************************************************************* + Copyright (c) 2014 IBM Corp. + + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + and Eclipse Distribution License v1.0 which accompany this distribution. + + The Eclipse Public License is available at + http://www.eclipse.org/legal/epl-v10.html + and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + + Contributors: + Ian Craggs - initial API and implementation and/or initial documentation + Xiang Rong - 442039 Add makefile to Embedded C client + *******************************************************************************/ + +#ifndef MQTTCONNECT_H_ +#define MQTTCONNECT_H_ + +#if !defined(DLLImport) +#define DLLImport +#endif +#if !defined(DLLExport) +#define DLLExport +#endif + + +typedef union { + unsigned char all; /**< all connect flags */ +#if defined(REVERSED) + struct { + unsigned int username : 1; /**< 3.1 user name */ + unsigned int password : 1; /**< 3.1 password */ + unsigned int willRetain : 1; /**< will retain setting */ + unsigned int willQoS : 2; /**< will QoS value */ + unsigned int will : 1; /**< will flag */ + unsigned int cleansession : 1; /**< clean session flag */ + unsigned int : 1; /**< unused */ + } bits; +#else + struct { + unsigned int : 1; /**< unused */ + unsigned int cleansession : 1; /**< cleansession flag */ + unsigned int will : 1; /**< will flag */ + unsigned int willQoS : 2; /**< will QoS value */ + unsigned int willRetain : 1; /**< will retain setting */ + unsigned int password : 1; /**< 3.1 password */ + unsigned int username : 1; /**< 3.1 user name */ + } bits; +#endif +} MQTTConnectFlags; /**< connect flags byte */ + + + +/** + Defines the MQTT "Last Will and Testament" (LWT) settings for + the connect packet. +*/ +typedef struct { + /** The eyecatcher for this structure. must be MQTW. */ + char struct_id[4]; + /** The version number of this structure. Must be 0 */ + int struct_version; + /** The LWT topic to which the LWT message will be published. */ + MQTTString topicName; + /** The LWT payload. */ + MQTTString message; + /** + The retained flag for the LWT message (see MQTTAsync_message.retained). + */ + unsigned char retained; + /** + The quality of service setting for the LWT message (see + MQTTAsync_message.qos and @ref qos). + */ + char qos; +} MQTTPacket_willOptions; + + +#define MQTTPacket_willOptions_initializer { {'M', 'Q', 'T', 'W'}, 0, {NULL, {0, NULL}}, {NULL, {0, NULL}}, 0, 0 } + + +typedef struct { + /** The eyecatcher for this structure. must be MQTC. */ + char struct_id[4]; + /** The version number of this structure. Must be 0 */ + int struct_version; + /** Version of MQTT to be used. 3 = 3.1 4 = 3.1.1 + */ + unsigned char MQTTVersion; + MQTTString clientID; + unsigned short keepAliveInterval; + unsigned char cleansession; + unsigned char willFlag; + MQTTPacket_willOptions will; + MQTTString username; + MQTTString password; +} MQTTPacket_connectData; + +typedef union { + unsigned char all; /**< all connack flags */ +#if defined(REVERSED) + struct { + unsigned int sessionpresent : 1; /**< session present flag */ + unsigned int : 7; /**< unused */ + } bits; +#else + struct { + unsigned int : 7; /**< unused */ + unsigned int sessionpresent : 1; /**< session present flag */ + } bits; +#endif +} MQTTConnackFlags; /**< connack flags byte */ + +#define MQTTPacket_connectData_initializer { {'M', 'Q', 'T', 'C'}, 0, 4, {NULL, {0, NULL}}, 60, 1, 0, \ + MQTTPacket_willOptions_initializer, {NULL, {0, NULL}}, {NULL, {0, NULL}} } + +DLLExport int MQTTSerialize_connect(unsigned char* buf, int buflen, MQTTPacket_connectData* options); +DLLExport int MQTTDeserialize_connect(MQTTPacket_connectData* data, unsigned char* buf, int len); + +DLLExport int MQTTSerialize_connack(unsigned char* buf, int buflen, unsigned char connack_rc, unsigned char sessionPresent); +DLLExport int MQTTDeserialize_connack(unsigned char* sessionPresent, unsigned char* connack_rc, unsigned char* buf, int buflen); + +DLLExport int MQTTSerialize_disconnect(unsigned char* buf, int buflen); +DLLExport int MQTTSerialize_pingreq(unsigned char* buf, int buflen); + +#endif /* MQTTCONNECT_H_ */ diff --git a/Internet/MQTT/MQTTPacket/src/MQTTConnectClient.c b/Internet/MQTT/MQTTPacket/src/MQTTConnectClient.c new file mode 100644 index 0000000..fe76faa --- /dev/null +++ b/Internet/MQTT/MQTTPacket/src/MQTTConnectClient.c @@ -0,0 +1,211 @@ +/******************************************************************************* + Copyright (c) 2014 IBM Corp. + + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + and Eclipse Distribution License v1.0 which accompany this distribution. + + The Eclipse Public License is available at + http://www.eclipse.org/legal/epl-v10.html + and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + + Contributors: + Ian Craggs - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "MQTTPacket.h" +#include "StackTrace.h" + +#include + +/** + Determines the length of the MQTT connect packet that would be produced using the supplied connect options. + @param options the options to be used to build the connect packet + @return the length of buffer needed to contain the serialized version of the packet +*/ +int MQTTSerialize_connectLength(MQTTPacket_connectData* options) { + int len = 0; + + FUNC_ENTRY; + + if (options->MQTTVersion == 3) { + len = 12; /* variable depending on MQTT or MQIsdp */ + } else if (options->MQTTVersion == 4) { + len = 10; + } + + len += MQTTstrlen(options->clientID) +2; + if (options->willFlag) { + len += MQTTstrlen(options->will.topicName) +2 + MQTTstrlen(options->will.message) +2; + } + if (options->username.cstring || options->username.lenstring.data) { + len += MQTTstrlen(options->username) +2; + } + if (options->password.cstring || options->password.lenstring.data) { + len += MQTTstrlen(options->password) +2; + } + + FUNC_EXIT_RC(len); + return len; +} + + +/** + Serializes the connect options into the buffer. + @param buf the buffer into which the packet will be serialized + @param len the length in bytes of the supplied buffer + @param options the options to be used to build the connect packet + @return serialized length, or error if 0 +*/ +int MQTTSerialize_connect(unsigned char* buf, int buflen, MQTTPacket_connectData* options) { + unsigned char *ptr = buf; + MQTTHeader header = {0}; + MQTTConnectFlags flags = {0}; + int len = 0; + int rc = -1; + + FUNC_ENTRY; + if (MQTTPacket_len(len = MQTTSerialize_connectLength(options)) > buflen) { + rc = MQTTPACKET_BUFFER_TOO_SHORT; + goto exit; + } + + header.byte = 0; + header.bits.type = CONNECT; + writeChar(&ptr, header.byte); /* write header */ + + ptr += MQTTPacket_encode(ptr, len); /* write remaining length */ + + if (options->MQTTVersion == 4) { + writeCString(&ptr, "MQTT"); + writeChar(&ptr, (char) 4); + } else { + writeCString(&ptr, "MQIsdp"); + writeChar(&ptr, (char) 3); + } + + flags.all = 0; + flags.bits.cleansession = options->cleansession; + flags.bits.will = (options->willFlag) ? 1 : 0; + if (flags.bits.will) { + flags.bits.willQoS = options->will.qos; + flags.bits.willRetain = options->will.retained; + } + + if (options->username.cstring || options->username.lenstring.data) { + flags.bits.username = 1; + } + if (options->password.cstring || options->password.lenstring.data) { + flags.bits.password = 1; + } + + writeChar(&ptr, flags.all); + writeInt(&ptr, options->keepAliveInterval); + writeMQTTString(&ptr, options->clientID); + if (options->willFlag) { + writeMQTTString(&ptr, options->will.topicName); + writeMQTTString(&ptr, options->will.message); + } + if (flags.bits.username) { + writeMQTTString(&ptr, options->username); + } + if (flags.bits.password) { + writeMQTTString(&ptr, options->password); + } + + rc = ptr - buf; + +exit: FUNC_EXIT_RC(rc); + return rc; +} + + +/** + Deserializes the supplied (wire) buffer into connack data - return code + @param sessionPresent the session present flag returned (only for MQTT 3.1.1) + @param connack_rc returned integer value of the connack return code + @param buf the raw buffer data, of the correct length determined by the remaining length field + @param len the length in bytes of the data in the supplied buffer + @return error code. 1 is success, 0 is failure +*/ +int MQTTDeserialize_connack(unsigned char* sessionPresent, unsigned char* connack_rc, unsigned char* buf, int buflen) { + MQTTHeader header = {0}; + unsigned char* curdata = buf; + unsigned char* enddata = NULL; + int rc = 0; + int mylen; + MQTTConnackFlags flags = {0}; + + FUNC_ENTRY; + header.byte = readChar(&curdata); + if (header.bits.type != CONNACK) { + goto exit; + } + + curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */ + enddata = curdata + mylen; + if (enddata - curdata < 2) { + goto exit; + } + + flags.all = readChar(&curdata); + *sessionPresent = flags.bits.sessionpresent; + *connack_rc = readChar(&curdata); + + rc = 1; +exit: + FUNC_EXIT_RC(rc); + return rc; +} + + +/** + Serializes a 0-length packet into the supplied buffer, ready for writing to a socket + @param buf the buffer into which the packet will be serialized + @param buflen the length in bytes of the supplied buffer, to avoid overruns + @param packettype the message type + @return serialized length, or error if 0 +*/ +int MQTTSerialize_zero(unsigned char* buf, int buflen, unsigned char packettype) { + MQTTHeader header = {0}; + int rc = -1; + unsigned char *ptr = buf; + + FUNC_ENTRY; + if (buflen < 2) { + rc = MQTTPACKET_BUFFER_TOO_SHORT; + goto exit; + } + header.byte = 0; + header.bits.type = packettype; + writeChar(&ptr, header.byte); /* write header */ + + ptr += MQTTPacket_encode(ptr, 0); /* write remaining length */ + rc = ptr - buf; +exit: + FUNC_EXIT_RC(rc); + return rc; +} + + +/** + Serializes a disconnect packet into the supplied buffer, ready for writing to a socket + @param buf the buffer into which the packet will be serialized + @param buflen the length in bytes of the supplied buffer, to avoid overruns + @return serialized length, or error if 0 +*/ +int MQTTSerialize_disconnect(unsigned char* buf, int buflen) { + return MQTTSerialize_zero(buf, buflen, DISCONNECT); +} + + +/** + Serializes a disconnect packet into the supplied buffer, ready for writing to a socket + @param buf the buffer into which the packet will be serialized + @param buflen the length in bytes of the supplied buffer, to avoid overruns + @return serialized length, or error if 0 +*/ +int MQTTSerialize_pingreq(unsigned char* buf, int buflen) { + return MQTTSerialize_zero(buf, buflen, PINGREQ); +} diff --git a/Internet/MQTT/MQTTPacket/src/MQTTConnectServer.c b/Internet/MQTT/MQTTPacket/src/MQTTConnectServer.c new file mode 100644 index 0000000..c0701cd --- /dev/null +++ b/Internet/MQTT/MQTTPacket/src/MQTTConnectServer.c @@ -0,0 +1,148 @@ +/******************************************************************************* + Copyright (c) 2014 IBM Corp. + + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + and Eclipse Distribution License v1.0 which accompany this distribution. + + The Eclipse Public License is available at + http://www.eclipse.org/legal/epl-v10.html + and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + + Contributors: + Ian Craggs - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "StackTrace.h" +#include "MQTTPacket.h" +#include + +#define min(a, b) ((a < b) ? a : b) + + +/** + Validates MQTT protocol name and version combinations + @param protocol the MQTT protocol name as an MQTTString + @param version the MQTT protocol version number, as in the connect packet + @return correct MQTT combination? 1 is true, 0 is false +*/ +int MQTTPacket_checkVersion(MQTTString* protocol, int version) { + int rc = 0; + + if (version == 3 && memcmp(protocol->lenstring.data, "MQIsdp", + min(6, protocol->lenstring.len)) == 0) { + rc = 1; + } else if (version == 4 && memcmp(protocol->lenstring.data, "MQTT", + min(4, protocol->lenstring.len)) == 0) { + rc = 1; + } + return rc; +} + + +/** + Deserializes the supplied (wire) buffer into connect data structure + @param data the connect data structure to be filled out + @param buf the raw buffer data, of the correct length determined by the remaining length field + @param len the length in bytes of the data in the supplied buffer + @return error code. 1 is success, 0 is failure +*/ +int MQTTDeserialize_connect(MQTTPacket_connectData* data, unsigned char* buf, int len) { + MQTTHeader header = {0}; + MQTTConnectFlags flags = {0}; + unsigned char* curdata = buf; + unsigned char* enddata = &buf[len]; + int rc = 0; + MQTTString Protocol; + int version; + int mylen = 0; + + FUNC_ENTRY; + header.byte = readChar(&curdata); + if (header.bits.type != CONNECT) { + goto exit; + } + + curdata += MQTTPacket_decodeBuf(curdata, &mylen); /* read remaining length */ + + if (!readMQTTLenString(&Protocol, &curdata, enddata) || + enddata - curdata < 0) { /* do we have enough data to read the protocol version byte? */ + goto exit; + } + + version = (int)readChar(&curdata); /* Protocol version */ + /* If we don't recognize the protocol version, we don't parse the connect packet on the + basis that we don't know what the format will be. + */ + if (MQTTPacket_checkVersion(&Protocol, version)) { + flags.all = readChar(&curdata); + data->cleansession = flags.bits.cleansession; + data->keepAliveInterval = readInt(&curdata); + if (!readMQTTLenString(&data->clientID, &curdata, enddata)) { + goto exit; + } + data->willFlag = flags.bits.will; + if (flags.bits.will) { + data->will.qos = flags.bits.willQoS; + data->will.retained = flags.bits.willRetain; + if (!readMQTTLenString(&data->will.topicName, &curdata, enddata) || + !readMQTTLenString(&data->will.message, &curdata, enddata)) { + goto exit; + } + } + if (flags.bits.username) { + if (enddata - curdata < 3 || !readMQTTLenString(&data->username, &curdata, enddata)) { + goto exit; /* username flag set, but no username supplied - invalid */ + } + if (flags.bits.password && + (enddata - curdata < 3 || !readMQTTLenString(&data->password, &curdata, enddata))) { + goto exit; /* password flag set, but no password supplied - invalid */ + } + } else if (flags.bits.password) { + goto exit; /* password flag set without username - invalid */ + } + rc = 1; + } +exit: + FUNC_EXIT_RC(rc); + return rc; +} + + +/** + Serializes the connack packet into the supplied buffer. + @param buf the buffer into which the packet will be serialized + @param buflen the length in bytes of the supplied buffer + @param connack_rc the integer connack return code to be used + @param sessionPresent the MQTT 3.1.1 sessionPresent flag + @return serialized length, or error if 0 +*/ +int MQTTSerialize_connack(unsigned char* buf, int buflen, unsigned char connack_rc, unsigned char sessionPresent) { + MQTTHeader header = {0}; + int rc = 0; + unsigned char *ptr = buf; + MQTTConnackFlags flags = {0}; + + FUNC_ENTRY; + if (buflen < 2) { + rc = MQTTPACKET_BUFFER_TOO_SHORT; + goto exit; + } + header.byte = 0; + header.bits.type = CONNACK; + writeChar(&ptr, header.byte); /* write header */ + + ptr += MQTTPacket_encode(ptr, 2); /* write remaining length */ + + flags.all = 0; + flags.bits.sessionpresent = sessionPresent; + writeChar(&ptr, flags.all); + writeChar(&ptr, connack_rc); + + rc = ptr - buf; +exit: + FUNC_EXIT_RC(rc); + return rc; +} + diff --git a/Internet/MQTT/MQTTPacket/src/MQTTDeserializePublish.c b/Internet/MQTT/MQTTPacket/src/MQTTDeserializePublish.c new file mode 100644 index 0000000..f53855e --- /dev/null +++ b/Internet/MQTT/MQTTPacket/src/MQTTDeserializePublish.c @@ -0,0 +1,109 @@ +/******************************************************************************* + Copyright (c) 2014 IBM Corp. + + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + and Eclipse Distribution License v1.0 which accompany this distribution. + + The Eclipse Public License is available at + http://www.eclipse.org/legal/epl-v10.html + and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + + Contributors: + Ian Craggs - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "StackTrace.h" +#include "MQTTPacket.h" +#include + +#define min(a, b) ((a < b) ? 1 : 0) + +/** + Deserializes the supplied (wire) buffer into publish data + @param dup returned integer - the MQTT dup flag + @param qos returned integer - the MQTT QoS value + @param retained returned integer - the MQTT retained flag + @param packetid returned integer - the MQTT packet identifier + @param topicName returned MQTTString - the MQTT topic in the publish + @param payload returned byte buffer - the MQTT publish payload + @param payloadlen returned integer - the length of the MQTT payload + @param buf the raw buffer data, of the correct length determined by the remaining length field + @param buflen the length in bytes of the data in the supplied buffer + @return error code. 1 is success +*/ +int MQTTDeserialize_publish(unsigned char* dup, int* qos, unsigned char* retained, unsigned short* packetid, MQTTString* topicName, + unsigned char** payload, int* payloadlen, unsigned char* buf, int buflen) { + MQTTHeader header = {0}; + unsigned char* curdata = buf; + unsigned char* enddata = NULL; + int rc = 0; + int mylen = 0; + + FUNC_ENTRY; + header.byte = readChar(&curdata); + if (header.bits.type != PUBLISH) { + goto exit; + } + *dup = header.bits.dup; + *qos = header.bits.qos; + *retained = header.bits.retain; + + curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */ + enddata = curdata + mylen; + + if (!readMQTTLenString(topicName, &curdata, enddata) || + enddata - curdata < 0) { /* do we have enough data to read the protocol version byte? */ + goto exit; + } + + if (*qos > 0) { + *packetid = readInt(&curdata); + } + + *payloadlen = enddata - curdata; + *payload = curdata; + rc = 1; +exit: + FUNC_EXIT_RC(rc); + return rc; +} + + + +/** + Deserializes the supplied (wire) buffer into an ack + @param packettype returned integer - the MQTT packet type + @param dup returned integer - the MQTT dup flag + @param packetid returned integer - the MQTT packet identifier + @param buf the raw buffer data, of the correct length determined by the remaining length field + @param buflen the length in bytes of the data in the supplied buffer + @return error code. 1 is success, 0 is failure +*/ +int MQTTDeserialize_ack(unsigned char* packettype, unsigned char* dup, unsigned short* packetid, unsigned char* buf, int buflen) { + MQTTHeader header = {0}; + unsigned char* curdata = buf; + unsigned char* enddata = NULL; + int rc = 0; + int mylen; + + FUNC_ENTRY; + header.byte = readChar(&curdata); + *dup = header.bits.dup; + *packettype = header.bits.type; + + curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */ + enddata = curdata + mylen; + + if (enddata - curdata < 2) { + goto exit; + } + *packetid = readInt(&curdata); + + rc = 1; +exit: + FUNC_EXIT_RC(rc); + return rc; +} + diff --git a/Internet/MQTT/MQTTPacket/src/MQTTFormat.c b/Internet/MQTT/MQTTPacket/src/MQTTFormat.c new file mode 100644 index 0000000..c0c4447 --- /dev/null +++ b/Internet/MQTT/MQTTPacket/src/MQTTFormat.c @@ -0,0 +1,241 @@ +/******************************************************************************* + Copyright (c) 2014 IBM Corp. + + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + and Eclipse Distribution License v1.0 which accompany this distribution. + + The Eclipse Public License is available at + http://www.eclipse.org/legal/epl-v10.html + and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + + Contributors: + Ian Craggs - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "StackTrace.h" +#include "MQTTPacket.h" + +#include + + +const char* MQTTPacket_names[] = { + "RESERVED", "CONNECT", "CONNACK", "PUBLISH", "PUBACK", "PUBREC", "PUBREL", + "PUBCOMP", "SUBSCRIBE", "SUBACK", "UNSUBSCRIBE", "UNSUBACK", + "PINGREQ", "PINGRESP", "DISCONNECT" +}; + + +const char* MQTTPacket_getName(unsigned short packetid) { + return MQTTPacket_names[packetid]; +} + + +int MQTTStringFormat_connect(char* strbuf, int strbuflen, MQTTPacket_connectData* data) { + int strindex = 0; + + strindex = snprintf(strbuf, strbuflen, + "CONNECT MQTT version %d, client id %.*s, clean session %d, keep alive %d", + (int)data->MQTTVersion, data->clientID.lenstring.len, data->clientID.lenstring.data, + (int)data->cleansession, data->keepAliveInterval); + if (data->willFlag) + strindex += snprintf(&strbuf[strindex], strbuflen - strindex, + ", will QoS %d, will retain %d, will topic %.*s, will message %.*s", + data->will.qos, data->will.retained, + data->will.topicName.lenstring.len, data->will.topicName.lenstring.data, + data->will.message.lenstring.len, data->will.message.lenstring.data); + if (data->username.lenstring.data && data->username.lenstring.len > 0) + strindex += snprintf(&strbuf[strindex], strbuflen - strindex, + ", user name %.*s", data->username.lenstring.len, data->username.lenstring.data); + if (data->password.lenstring.data && data->password.lenstring.len > 0) + strindex += snprintf(&strbuf[strindex], strbuflen - strindex, + ", password %.*s", data->password.lenstring.len, data->password.lenstring.data); + return strindex; +} + + +int MQTTStringFormat_connack(char* strbuf, int strbuflen, unsigned char connack_rc, unsigned char sessionPresent) { + int strindex = snprintf(strbuf, strbuflen, "CONNACK session present %d, rc %d", sessionPresent, connack_rc); + return strindex; +} + + +int MQTTStringFormat_publish(char* strbuf, int strbuflen, unsigned char dup, int qos, unsigned char retained, + unsigned short packetid, MQTTString topicName, unsigned char* payload, int payloadlen) { + int strindex = snprintf(strbuf, strbuflen, + "PUBLISH dup %d, QoS %d, retained %d, packet id %d, topic %.*s, payload length %d, payload %.*s", + dup, qos, retained, packetid, + (topicName.lenstring.len < 20) ? topicName.lenstring.len : 20, topicName.lenstring.data, + payloadlen, (payloadlen < 20) ? payloadlen : 20, payload); + return strindex; +} + + +int MQTTStringFormat_ack(char* strbuf, int strbuflen, unsigned char packettype, unsigned char dup, unsigned short packetid) { + int strindex = snprintf(strbuf, strbuflen, "%s, packet id %d", MQTTPacket_names[packettype], packetid); + if (dup) { + strindex += snprintf(strbuf + strindex, strbuflen - strindex, ", dup %d", dup); + } + return strindex; +} + + +int MQTTStringFormat_subscribe(char* strbuf, int strbuflen, unsigned char dup, unsigned short packetid, int count, + MQTTString topicFilters[], int requestedQoSs[]) { + return snprintf(strbuf, strbuflen, + "SUBSCRIBE dup %d, packet id %d count %d topic %.*s qos %d", + dup, packetid, count, + topicFilters[0].lenstring.len, topicFilters[0].lenstring.data, + requestedQoSs[0]); +} + + +int MQTTStringFormat_suback(char* strbuf, int strbuflen, unsigned short packetid, int count, int* grantedQoSs) { + return snprintf(strbuf, strbuflen, + "SUBACK packet id %d count %d granted qos %d", packetid, count, grantedQoSs[0]); +} + + +int MQTTStringFormat_unsubscribe(char* strbuf, int strbuflen, unsigned char dup, unsigned short packetid, + int count, MQTTString topicFilters[]) { + return snprintf(strbuf, strbuflen, + "UNSUBSCRIBE dup %d, packet id %d count %d topic %.*s", + dup, packetid, count, + topicFilters[0].lenstring.len, topicFilters[0].lenstring.data); +} + + +char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf, int buflen) { + int index = 0; + int rem_length = 0; + MQTTHeader header = {0}; + header.byte = buf[index++]; + index += MQTTPacket_decodeBuf(&buf[index], &rem_length); + + switch (header.bits.type) { + case CONNACK: { + unsigned char sessionPresent, connack_rc; + if (MQTTDeserialize_connack(&sessionPresent, &connack_rc, buf, buflen) == 1) { + MQTTStringFormat_connack(strbuf, strbuflen, connack_rc, sessionPresent); + } + } + break; + case PUBLISH: { + unsigned char dup, retained, *payload; + unsigned short packetid; + int qos, payloadlen; + MQTTString topicName = MQTTString_initializer; + if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName, + &payload, &payloadlen, buf, buflen) == 1) + MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, packetid, + topicName, payload, payloadlen); + } + break; + case PUBACK: + case PUBREC: + case PUBREL: + case PUBCOMP: { + unsigned char packettype, dup; + unsigned short packetid; + if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1) { + MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid); + } + } + break; + case SUBACK: { + unsigned short packetid; + int maxcount = 1, count = 0; + int grantedQoSs[1]; + if (MQTTDeserialize_suback(&packetid, maxcount, &count, grantedQoSs, buf, buflen) == 1) { + MQTTStringFormat_suback(strbuf, strbuflen, packetid, count, grantedQoSs); + } + } + break; + case UNSUBACK: { + unsigned short packetid; + if (MQTTDeserialize_unsuback(&packetid, buf, buflen) == 1) { + MQTTStringFormat_ack(strbuf, strbuflen, UNSUBACK, 0, packetid); + } + } + break; + case PINGREQ: + case PINGRESP: + case DISCONNECT: + snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]); + break; + } + return strbuf; +} + + +char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf, int buflen) { + int index = 0; + int rem_length = 0; + MQTTHeader header = {0}; + + header.byte = buf[index++]; + index += MQTTPacket_decodeBuf(&buf[index], &rem_length); + + switch (header.bits.type) { + case CONNECT: { + MQTTPacket_connectData data; + int rc; + if ((rc = MQTTDeserialize_connect(&data, buf, buflen)) == 1) { + MQTTStringFormat_connect(strbuf, strbuflen, &data); + } + } + break; + case PUBLISH: { + unsigned char dup, retained, *payload; + unsigned short packetid; + int qos, payloadlen; + MQTTString topicName = MQTTString_initializer; + if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName, + &payload, &payloadlen, buf, buflen) == 1) + MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, packetid, + topicName, payload, payloadlen); + } + break; + case PUBACK: + case PUBREC: + case PUBREL: + case PUBCOMP: { + unsigned char packettype, dup; + unsigned short packetid; + if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1) { + MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid); + } + } + break; + case SUBSCRIBE: { + unsigned char dup; + unsigned short packetid; + int maxcount = 1, count = 0; + MQTTString topicFilters[1]; + int requestedQoSs[1]; + if (MQTTDeserialize_subscribe(&dup, &packetid, maxcount, &count, + topicFilters, requestedQoSs, buf, buflen) == 1) { + MQTTStringFormat_subscribe(strbuf, strbuflen, dup, packetid, count, topicFilters, requestedQoSs); + }; + } + break; + case UNSUBSCRIBE: { + unsigned char dup; + unsigned short packetid; + int maxcount = 1, count = 0; + MQTTString topicFilters[1]; + if (MQTTDeserialize_unsubscribe(&dup, &packetid, maxcount, &count, topicFilters, buf, buflen) == 1) { + MQTTStringFormat_unsubscribe(strbuf, strbuflen, dup, packetid, count, topicFilters); + } + } + break; + case PINGREQ: + case PINGRESP: + case DISCONNECT: + snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]); + break; + } + strbuf[strbuflen] = '\0'; + return strbuf; +} diff --git a/Internet/MQTT/MQTTPacket/src/MQTTFormat.h b/Internet/MQTT/MQTTPacket/src/MQTTFormat.h new file mode 100644 index 0000000..a6f8fe5 --- /dev/null +++ b/Internet/MQTT/MQTTPacket/src/MQTTFormat.h @@ -0,0 +1,37 @@ +/******************************************************************************* + Copyright (c) 2014 IBM Corp. + + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + and Eclipse Distribution License v1.0 which accompany this distribution. + + The Eclipse Public License is available at + http://www.eclipse.org/legal/epl-v10.html + and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + + Contributors: + Ian Craggs - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#if !defined(MQTTFORMAT_H) +#define MQTTFORMAT_H + +#include "StackTrace.h" +#include "MQTTPacket.h" + +const char* MQTTPacket_getName(unsigned short packetid); +int MQTTStringFormat_connect(char* strbuf, int strbuflen, MQTTPacket_connectData* data); +int MQTTStringFormat_connack(char* strbuf, int strbuflen, unsigned char connack_rc, unsigned char sessionPresent); +int MQTTStringFormat_publish(char* strbuf, int strbuflen, unsigned char dup, int qos, unsigned char retained, + unsigned short packetid, MQTTString topicName, unsigned char* payload, int payloadlen); +int MQTTStringFormat_ack(char* strbuf, int strbuflen, unsigned char packettype, unsigned char dup, unsigned short packetid); +int MQTTStringFormat_subscribe(char* strbuf, int strbuflen, unsigned char dup, unsigned short packetid, int count, + MQTTString topicFilters[], int requestedQoSs[]); +int MQTTStringFormat_suback(char* strbuf, int strbuflen, unsigned short packetid, int count, int* grantedQoSs); +int MQTTStringFormat_unsubscribe(char* strbuf, int strbuflen, unsigned char dup, unsigned short packetid, + int count, MQTTString topicFilters[]); +char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf, int buflen); +char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf, int buflen); + +#endif diff --git a/Internet/MQTT/MQTTPacket/src/MQTTPacket.c b/Internet/MQTT/MQTTPacket/src/MQTTPacket.c new file mode 100644 index 0000000..b1fdfee --- /dev/null +++ b/Internet/MQTT/MQTTPacket/src/MQTTPacket.c @@ -0,0 +1,401 @@ +/******************************************************************************* + Copyright (c) 2014 IBM Corp. + + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + and Eclipse Distribution License v1.0 which accompany this distribution. + + The Eclipse Public License is available at + http://www.eclipse.org/legal/epl-v10.html + and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + + Contributors: + Ian Craggs - initial API and implementation and/or initial documentation + Sergio R. Caprile - non-blocking packet read functions for stream transport + *******************************************************************************/ + +#include "StackTrace.h" +#include "MQTTPacket.h" + +#include + +/** + Encodes the message length according to the MQTT algorithm + @param buf the buffer into which the encoded data is written + @param length the length to be encoded + @return the number of bytes written to buffer +*/ +int MQTTPacket_encode(unsigned char* buf, int length) { + int rc = 0; + + FUNC_ENTRY; + do { + char d = length % 128; + length /= 128; + /* if there are more digits to encode, set the top bit of this digit */ + if (length > 0) { + d |= 0x80; + } + buf[rc++] = d; + } while (length > 0); + FUNC_EXIT_RC(rc); + return rc; +} + + +/** + Decodes the message length according to the MQTT algorithm + @param getcharfn pointer to function to read the next character from the data source + @param value the decoded length returned + @return the number of bytes read from the socket +*/ +int MQTTPacket_decode(int (*getcharfn)(unsigned char*, int), int* value) { + unsigned char c; + int multiplier = 1; + int len = 0; +#define MAX_NO_OF_REMAINING_LENGTH_BYTES 4 + + FUNC_ENTRY; + *value = 0; + do { + int rc = MQTTPACKET_READ_ERROR; + + if (++len > MAX_NO_OF_REMAINING_LENGTH_BYTES) { + rc = MQTTPACKET_READ_ERROR; /* bad data */ + goto exit; + } + rc = (*getcharfn)(&c, 1); + if (rc != 1) { + goto exit; + } + *value += (c & 127) * multiplier; + multiplier *= 128; + } while ((c & 128) != 0); +exit: + FUNC_EXIT_RC(len); + return len; +} + + +int MQTTPacket_len(int rem_len) { + rem_len += 1; /* header byte */ + + /* now remaining_length field */ + if (rem_len < 128) { + rem_len += 1; + } else if (rem_len < 16384) { + rem_len += 2; + } else if (rem_len < 2097151) { + rem_len += 3; + } else { + rem_len += 4; + } + return rem_len; +} + + +static unsigned char* bufptr; + +int bufchar(unsigned char* c, int count) { + int i; + + for (i = 0; i < count; ++i) { + *c = *bufptr++; + } + return count; +} + + +int MQTTPacket_decodeBuf(unsigned char* buf, int* value) { + bufptr = buf; + return MQTTPacket_decode(bufchar, value); +} + + +/** + Calculates an integer from two bytes read from the input buffer + @param pptr pointer to the input buffer - incremented by the number of bytes used & returned + @return the integer value calculated +*/ +int readInt(unsigned char** pptr) { + unsigned char* ptr = *pptr; + int len = 256 * (*ptr) + (*(ptr + 1)); + *pptr += 2; + return len; +} + + +/** + Reads one character from the input buffer. + @param pptr pointer to the input buffer - incremented by the number of bytes used & returned + @return the character read +*/ +char readChar(unsigned char** pptr) { + char c = **pptr; + (*pptr)++; + return c; +} + + +/** + Writes one character to an output buffer. + @param pptr pointer to the output buffer - incremented by the number of bytes used & returned + @param c the character to write +*/ +void writeChar(unsigned char** pptr, char c) { + **pptr = c; + (*pptr)++; +} + + +/** + Writes an integer as 2 bytes to an output buffer. + @param pptr pointer to the output buffer - incremented by the number of bytes used & returned + @param anInt the integer to write +*/ +void writeInt(unsigned char** pptr, int anInt) { + **pptr = (unsigned char)(anInt / 256); + (*pptr)++; + **pptr = (unsigned char)(anInt % 256); + (*pptr)++; +} + + +/** + Writes a "UTF" string to an output buffer. Converts C string to length-delimited. + @param pptr pointer to the output buffer - incremented by the number of bytes used & returned + @param string the C string to write +*/ +void writeCString(unsigned char** pptr, const char* string) { + int len = strlen(string); + writeInt(pptr, len); + memcpy(*pptr, string, len); + *pptr += len; +} + + +int getLenStringLen(char* ptr) { + int len = 256 * ((unsigned char)(*ptr)) + (unsigned char)(*(ptr + 1)); + return len; +} + + +void writeMQTTString(unsigned char** pptr, MQTTString mqttstring) { + if (mqttstring.lenstring.len > 0) { + writeInt(pptr, mqttstring.lenstring.len); + memcpy(*pptr, mqttstring.lenstring.data, mqttstring.lenstring.len); + *pptr += mqttstring.lenstring.len; + } else if (mqttstring.cstring) { + writeCString(pptr, mqttstring.cstring); + } else { + writeInt(pptr, 0); + } +} + + +/** + @param mqttstring the MQTTString structure into which the data is to be read + @param pptr pointer to the output buffer - incremented by the number of bytes used & returned + @param enddata pointer to the end of the data: do not read beyond + @return 1 if successful, 0 if not +*/ +int readMQTTLenString(MQTTString* mqttstring, unsigned char** pptr, unsigned char* enddata) { + int rc = 0; + + FUNC_ENTRY; + /* the first two bytes are the length of the string */ + if (enddata - (*pptr) > 1) { /* enough length to read the integer? */ + mqttstring->lenstring.len = readInt(pptr); /* increments pptr to point past length */ + if (&(*pptr)[mqttstring->lenstring.len] <= enddata) { + mqttstring->lenstring.data = (char*)*pptr; + *pptr += mqttstring->lenstring.len; + rc = 1; + } + } + mqttstring->cstring = NULL; + FUNC_EXIT_RC(rc); + return rc; +} + + +/** + Return the length of the MQTTstring - C string if there is one, otherwise the length delimited string + @param mqttstring the string to return the length of + @return the length of the string +*/ +int MQTTstrlen(MQTTString mqttstring) { + int rc = 0; + + if (mqttstring.cstring) { + rc = strlen(mqttstring.cstring); + } else { + rc = mqttstring.lenstring.len; + } + return rc; +} + + +/** + Compares an MQTTString to a C string + @param a the MQTTString to compare + @param bptr the C string to compare + @return boolean - equal or not +*/ +int MQTTPacket_equals(MQTTString* a, char* bptr) { + int alen = 0, + blen = 0; + char *aptr; + + if (a->cstring) { + aptr = a->cstring; + alen = strlen(a->cstring); + } else { + aptr = a->lenstring.data; + alen = a->lenstring.len; + } + blen = strlen(bptr); + + return (alen == blen) && (strncmp(aptr, bptr, alen) == 0); +} + + +/** + Helper function to read packet data from some source into a buffer + @param buf the buffer into which the packet will be serialized + @param buflen the length in bytes of the supplied buffer + @param getfn pointer to a function which will read any number of bytes from the needed source + @return integer MQTT packet type, or -1 on error + @note the whole message must fit into the caller's buffer +*/ +int MQTTPacket_read(unsigned char* buf, int buflen, int (*getfn)(unsigned char*, int)) { + int rc = -1; + MQTTHeader header = {0}; + int len = 0; + int rem_len = 0; + + /* 1. read the header byte. This has the packet type in it */ + if ((*getfn)(buf, 1) != 1) { + goto exit; + } + + len = 1; + /* 2. read the remaining length. This is variable in itself */ + MQTTPacket_decode(getfn, &rem_len); + len += MQTTPacket_encode(buf + 1, rem_len); /* put the original remaining length back into the buffer */ + + /* 3. read the rest of the buffer using a callback to supply the rest of the data */ + if ((rem_len + len) > buflen) { + goto exit; + } + if ((*getfn)(buf + len, rem_len) != rem_len) { + goto exit; + } + + header.byte = buf[0]; + rc = header.bits.type; +exit: + return rc; +} + +/** + Decodes the message length according to the MQTT algorithm, non-blocking + @param trp pointer to a transport structure holding what is needed to solve getting data from it + @param value the decoded length returned + @return integer the number of bytes read from the socket, 0 for call again, or -1 on error +*/ +static int MQTTPacket_decodenb(MQTTTransport *trp) { + unsigned char c; + int rc = MQTTPACKET_READ_ERROR; + + FUNC_ENTRY; + if (trp->len == 0) { /* initialize on first call */ + trp->multiplier = 1; + trp->rem_len = 0; + } + do { + int frc; + if (++(trp->len) > MAX_NO_OF_REMAINING_LENGTH_BYTES) { + goto exit; + } + if ((frc = (*trp->getfn)(trp->sck, &c, 1)) == -1) { + goto exit; + } + if (frc == 0) { + rc = 0; + goto exit; + } + trp->rem_len += (c & 127) * trp->multiplier; + trp->multiplier *= 128; + } while ((c & 128) != 0); + rc = trp->len; +exit: + FUNC_EXIT_RC(rc); + return rc; +} + +/** + Helper function to read packet data from some source into a buffer, non-blocking + @param buf the buffer into which the packet will be serialized + @param buflen the length in bytes of the supplied buffer + @param trp pointer to a transport structure holding what is needed to solve getting data from it + @return integer MQTT packet type, 0 for call again, or -1 on error + @note the whole message must fit into the caller's buffer +*/ +int MQTTPacket_readnb(unsigned char* buf, int buflen, MQTTTransport *trp) { + int rc = -1, frc; + MQTTHeader header = {0}; + + switch (trp->state) { + default: + trp->state = 0; + /*FALLTHROUGH*/ + case 0: + /* read the header byte. This has the packet type in it */ + if ((frc = (*trp->getfn)(trp->sck, buf, 1)) == -1) { + goto exit; + } + if (frc == 0) { + return 0; + } + trp->len = 0; + ++trp->state; + /*FALLTHROUGH*/ + /* read the remaining length. This is variable in itself */ + case 1: + if ((frc = MQTTPacket_decodenb(trp)) == MQTTPACKET_READ_ERROR) { + goto exit; + } + if (frc == 0) { + return 0; + } + trp->len = 1 + MQTTPacket_encode(buf + 1, trp->rem_len); /* put the original remaining length back into the buffer */ + if ((trp->rem_len + trp->len) > buflen) { + goto exit; + } + ++trp->state; + /*FALLTHROUGH*/ + case 2: + /* read the rest of the buffer using a callback to supply the rest of the data */ + if ((frc = (*trp->getfn)(trp->sck, buf + trp->len, trp->rem_len)) == -1) { + goto exit; + } + if (frc == 0) { + return 0; + } + trp->rem_len -= frc; + trp->len += frc; + if (trp->rem_len) { + return 0; + } + + header.byte = buf[0]; + rc = header.bits.type; + break; + } + +exit: + trp->state = 0; + return rc; +} + diff --git a/Internet/MQTT/MQTTPacket/src/MQTTPacket.h b/Internet/MQTT/MQTTPacket/src/MQTTPacket.h new file mode 100644 index 0000000..b83598b --- /dev/null +++ b/Internet/MQTT/MQTTPacket/src/MQTTPacket.h @@ -0,0 +1,126 @@ +/******************************************************************************* + Copyright (c) 2014 IBM Corp. + + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + and Eclipse Distribution License v1.0 which accompany this distribution. + + The Eclipse Public License is available at + http://www.eclipse.org/legal/epl-v10.html + and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + + Contributors: + Ian Craggs - initial API and implementation and/or initial documentation + Xiang Rong - 442039 Add makefile to Embedded C client + *******************************************************************************/ + +#ifndef MQTTPACKET_H_ +#define MQTTPACKET_H_ + +#if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ +extern "C" { +#endif + +#if defined(WIN32_DLL) || defined(WIN64_DLL) +#define DLLImport __declspec(dllimport) +#define DLLExport __declspec(dllexport) +#elif defined(LINUX_SO) +#define DLLImport extern +#define DLLExport __attribute__ ((visibility ("default"))) +#else +#define DLLImport +#define DLLExport +#endif + +enum errors { + MQTTPACKET_BUFFER_TOO_SHORT = -2, + MQTTPACKET_READ_ERROR = -1, + MQTTPACKET_READ_COMPLETE +}; + +enum msgTypes { + CONNECT = 1, CONNACK, PUBLISH, PUBACK, PUBREC, PUBREL, + PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK, + PINGREQ, PINGRESP, DISCONNECT +}; + +/** + Bitfields for the MQTT header byte. +*/ +typedef union { + unsigned char byte; /**< the whole byte */ +#if defined(REVERSED) + struct { + unsigned int type : 4; /**< message type nibble */ + unsigned int dup : 1; /**< DUP flag bit */ + unsigned int qos : 2; /**< QoS value, 0, 1 or 2 */ + unsigned int retain : 1; /**< retained flag bit */ + } bits; +#else + struct { + unsigned int retain : 1; /**< retained flag bit */ + unsigned int qos : 2; /**< QoS value, 0, 1 or 2 */ + unsigned int dup : 1; /**< DUP flag bit */ + unsigned int type : 4; /**< message type nibble */ + } bits; +#endif +} MQTTHeader; + +typedef struct { + int len; + char* data; +} MQTTLenString; + +typedef struct { + char* cstring; + MQTTLenString lenstring; +} MQTTString; + +#define MQTTString_initializer {NULL, {0, NULL}} + +int MQTTstrlen(MQTTString mqttstring); + +#include "MQTTConnect.h" +#include "MQTTPublish.h" +#include "MQTTSubscribe.h" +#include "MQTTUnsubscribe.h" +#include "MQTTFormat.h" + +int MQTTSerialize_ack(unsigned char* buf, int buflen, unsigned char type, unsigned char dup, unsigned short packetid); +int MQTTDeserialize_ack(unsigned char* packettype, unsigned char* dup, unsigned short* packetid, unsigned char* buf, int buflen); + +int MQTTPacket_len(int rem_len); +int MQTTPacket_equals(MQTTString* a, char* b); + +int MQTTPacket_encode(unsigned char* buf, int length); +int MQTTPacket_decode(int (*getcharfn)(unsigned char*, int), int* value); +int MQTTPacket_decodeBuf(unsigned char* buf, int* value); + +int readInt(unsigned char** pptr); +char readChar(unsigned char** pptr); +void writeChar(unsigned char** pptr, char c); +void writeInt(unsigned char** pptr, int anInt); +int readMQTTLenString(MQTTString* mqttstring, unsigned char** pptr, unsigned char* enddata); +void writeCString(unsigned char** pptr, const char* string); +void writeMQTTString(unsigned char** pptr, MQTTString mqttstring); + +DLLExport int MQTTPacket_read(unsigned char* buf, int buflen, int (*getfn)(unsigned char*, int)); + +typedef struct { + int (*getfn)(void *, unsigned char*, int); /* must return -1 for error, 0 for call again, or the number of bytes read */ + void *sck; /* pointer to whatever the system may use to identify the transport */ + int multiplier; + int rem_len; + int len; + char state; +} MQTTTransport; + +int MQTTPacket_readnb(unsigned char* buf, int buflen, MQTTTransport *trp); + +#ifdef __cplusplus /* If this is a C++ compiler, use C linkage */ +} +#endif + + +#endif /* MQTTPACKET_H_ */ diff --git a/Internet/MQTT/MQTTPacket/src/MQTTPublish.h b/Internet/MQTT/MQTTPacket/src/MQTTPublish.h new file mode 100644 index 0000000..867321d --- /dev/null +++ b/Internet/MQTT/MQTTPacket/src/MQTTPublish.h @@ -0,0 +1,38 @@ +/******************************************************************************* + Copyright (c) 2014 IBM Corp. + + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + and Eclipse Distribution License v1.0 which accompany this distribution. + + The Eclipse Public License is available at + http://www.eclipse.org/legal/epl-v10.html + and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + + Contributors: + Ian Craggs - initial API and implementation and/or initial documentation + Xiang Rong - 442039 Add makefile to Embedded C client + *******************************************************************************/ + +#ifndef MQTTPUBLISH_H_ +#define MQTTPUBLISH_H_ + +#if !defined(DLLImport) +#define DLLImport +#endif +#if !defined(DLLExport) +#define DLLExport +#endif + +DLLExport int MQTTSerialize_publish(unsigned char* buf, int buflen, unsigned char dup, int qos, unsigned char retained, unsigned short packetid, + MQTTString topicName, unsigned char* payload, int payloadlen); + +DLLExport int MQTTDeserialize_publish(unsigned char* dup, int* qos, unsigned char* retained, unsigned short* packetid, MQTTString* topicName, + unsigned char** payload, int* payloadlen, unsigned char* buf, int len); + +DLLExport int MQTTSerialize_puback(unsigned char* buf, int buflen, unsigned short packetid); +DLLExport int MQTTSerialize_pubrel(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid); +DLLExport int MQTTSerialize_pubcomp(unsigned char* buf, int buflen, unsigned short packetid); + +#endif /* MQTTPUBLISH_H_ */ diff --git a/Internet/MQTT/MQTTPacket/src/MQTTSerializePublish.c b/Internet/MQTT/MQTTPacket/src/MQTTSerializePublish.c new file mode 100644 index 0000000..9f18007 --- /dev/null +++ b/Internet/MQTT/MQTTPacket/src/MQTTSerializePublish.c @@ -0,0 +1,163 @@ +/******************************************************************************* + Copyright (c) 2014 IBM Corp. + + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + and Eclipse Distribution License v1.0 which accompany this distribution. + + The Eclipse Public License is available at + http://www.eclipse.org/legal/epl-v10.html + and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + + Contributors: + Ian Craggs - initial API and implementation and/or initial documentation + Ian Craggs - fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=453144 + *******************************************************************************/ + +#include "MQTTPacket.h" +#include "StackTrace.h" + +#include + + +/** + Determines the length of the MQTT publish packet that would be produced using the supplied parameters + @param qos the MQTT QoS of the publish (packetid is omitted for QoS 0) + @param topicName the topic name to be used in the publish + @param payloadlen the length of the payload to be sent + @return the length of buffer needed to contain the serialized version of the packet +*/ +int MQTTSerialize_publishLength(int qos, MQTTString topicName, int payloadlen) { + int len = 0; + + len += 2 + MQTTstrlen(topicName) + payloadlen; + if (qos > 0) { + len += 2; /* packetid */ + } + return len; +} + + +/** + Serializes the supplied publish data into the supplied buffer, ready for sending + @param buf the buffer into which the packet will be serialized + @param buflen the length in bytes of the supplied buffer + @param dup integer - the MQTT dup flag + @param qos integer - the MQTT QoS value + @param retained integer - the MQTT retained flag + @param packetid integer - the MQTT packet identifier + @param topicName MQTTString - the MQTT topic in the publish + @param payload byte buffer - the MQTT publish payload + @param payloadlen integer - the length of the MQTT payload + @return the length of the serialized data. <= 0 indicates error +*/ +int MQTTSerialize_publish(unsigned char* buf, int buflen, unsigned char dup, int qos, unsigned char retained, unsigned short packetid, + MQTTString topicName, unsigned char* payload, int payloadlen) { + unsigned char *ptr = buf; + MQTTHeader header = {0}; + int rem_len = 0; + int rc = 0; + + FUNC_ENTRY; + if (MQTTPacket_len(rem_len = MQTTSerialize_publishLength(qos, topicName, payloadlen)) > buflen) { + rc = MQTTPACKET_BUFFER_TOO_SHORT; + goto exit; + } + + header.bits.type = PUBLISH; + header.bits.dup = dup; + header.bits.qos = qos; + header.bits.retain = retained; + writeChar(&ptr, header.byte); /* write header */ + + ptr += MQTTPacket_encode(ptr, rem_len); /* write remaining length */; + + writeMQTTString(&ptr, topicName); + + if (qos > 0) { + writeInt(&ptr, packetid); + } + + memcpy(ptr, payload, payloadlen); + ptr += payloadlen; + + rc = ptr - buf; + +exit: + FUNC_EXIT_RC(rc); + return rc; +} + + + +/** + Serializes the ack packet into the supplied buffer. + @param buf the buffer into which the packet will be serialized + @param buflen the length in bytes of the supplied buffer + @param type the MQTT packet type + @param dup the MQTT dup flag + @param packetid the MQTT packet identifier + @return serialized length, or error if 0 +*/ +int MQTTSerialize_ack(unsigned char* buf, int buflen, unsigned char packettype, unsigned char dup, unsigned short packetid) { + MQTTHeader header = {0}; + int rc = 0; + unsigned char *ptr = buf; + + FUNC_ENTRY; + if (buflen < 4) { + rc = MQTTPACKET_BUFFER_TOO_SHORT; + goto exit; + } + header.bits.type = packettype; + header.bits.dup = dup; + header.bits.qos = (packettype == PUBREL) ? 1 : 0; + writeChar(&ptr, header.byte); /* write header */ + + ptr += MQTTPacket_encode(ptr, 2); /* write remaining length */ + writeInt(&ptr, packetid); + rc = ptr - buf; +exit: + FUNC_EXIT_RC(rc); + return rc; +} + + +/** + Serializes a puback packet into the supplied buffer. + @param buf the buffer into which the packet will be serialized + @param buflen the length in bytes of the supplied buffer + @param packetid integer - the MQTT packet identifier + @return serialized length, or error if 0 +*/ +int MQTTSerialize_puback(unsigned char* buf, int buflen, unsigned short packetid) { + return MQTTSerialize_ack(buf, buflen, PUBACK, 0, packetid); +} + + +/** + Serializes a pubrel packet into the supplied buffer. + @param buf the buffer into which the packet will be serialized + @param buflen the length in bytes of the supplied buffer + @param dup integer - the MQTT dup flag + @param packetid integer - the MQTT packet identifier + @return serialized length, or error if 0 +*/ +int MQTTSerialize_pubrel(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid) { + return MQTTSerialize_ack(buf, buflen, PUBREL, dup, packetid); +} + + +/** + Serializes a pubrel packet into the supplied buffer. + @param buf the buffer into which the packet will be serialized + @param buflen the length in bytes of the supplied buffer + @param packetid integer - the MQTT packet identifier + @return serialized length, or error if 0 +*/ +int MQTTSerialize_pubcomp(unsigned char* buf, int buflen, unsigned short packetid) { + return MQTTSerialize_ack(buf, buflen, PUBCOMP, 0, packetid); +} + + diff --git a/Internet/MQTT/MQTTPacket/src/MQTTSubscribe.h b/Internet/MQTT/MQTTPacket/src/MQTTSubscribe.h new file mode 100644 index 0000000..3c851ca --- /dev/null +++ b/Internet/MQTT/MQTTPacket/src/MQTTSubscribe.h @@ -0,0 +1,39 @@ +/******************************************************************************* + Copyright (c) 2014 IBM Corp. + + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + and Eclipse Distribution License v1.0 which accompany this distribution. + + The Eclipse Public License is available at + http://www.eclipse.org/legal/epl-v10.html + and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + + Contributors: + Ian Craggs - initial API and implementation and/or initial documentation + Xiang Rong - 442039 Add makefile to Embedded C client + *******************************************************************************/ + +#ifndef MQTTSUBSCRIBE_H_ +#define MQTTSUBSCRIBE_H_ + +#if !defined(DLLImport) +#define DLLImport +#endif +#if !defined(DLLExport) +#define DLLExport +#endif + +DLLExport int MQTTSerialize_subscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid, + int count, MQTTString topicFilters[], char requestedQoSs[]); + +DLLExport int MQTTDeserialize_subscribe(unsigned char* dup, unsigned short* packetid, + int maxcount, int* count, MQTTString topicFilters[], int requestedQoSs[], unsigned char* buf, int len); + +DLLExport int MQTTSerialize_suback(unsigned char* buf, int buflen, unsigned short packetid, int count, int* grantedQoSs); + +DLLExport int MQTTDeserialize_suback(unsigned short* packetid, int maxcount, int* count, int grantedQoSs[], unsigned char* buf, int len); + + +#endif /* MQTTSUBSCRIBE_H_ */ diff --git a/Internet/MQTT/MQTTPacket/src/MQTTSubscribeClient.c b/Internet/MQTT/MQTTPacket/src/MQTTSubscribeClient.c new file mode 100644 index 0000000..24124d9 --- /dev/null +++ b/Internet/MQTT/MQTTPacket/src/MQTTSubscribeClient.c @@ -0,0 +1,133 @@ +/******************************************************************************* + Copyright (c) 2014 IBM Corp. + + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + and Eclipse Distribution License v1.0 which accompany this distribution. + + The Eclipse Public License is available at + http://www.eclipse.org/legal/epl-v10.html + and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + + Contributors: + Ian Craggs - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "MQTTPacket.h" +#include "StackTrace.h" + +#include + +/** + Determines the length of the MQTT subscribe packet that would be produced using the supplied parameters + @param count the number of topic filter strings in topicFilters + @param topicFilters the array of topic filter strings to be used in the publish + @return the length of buffer needed to contain the serialized version of the packet +*/ +int MQTTSerialize_subscribeLength(int count, MQTTString topicFilters[]) { + int i; + int len = 2; /* packetid */ + + for (i = 0; i < count; ++i) { + len += 2 + MQTTstrlen(topicFilters[i]) + 1; /* length + topic + req_qos */ + } + return len; +} + + +/** + Serializes the supplied subscribe data into the supplied buffer, ready for sending + @param buf the buffer into which the packet will be serialized + @param buflen the length in bytes of the supplied bufferr + @param dup integer - the MQTT dup flag + @param packetid integer - the MQTT packet identifier + @param count - number of members in the topicFilters and reqQos arrays + @param topicFilters - array of topic filter names + @param requestedQoSs - array of requested QoS + @return the length of the serialized data. <= 0 indicates error +*/ +int MQTTSerialize_subscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid, int count, + MQTTString topicFilters[], char requestedQoSs[]) { + unsigned char *ptr = buf; + MQTTHeader header = {0}; + int rem_len = 0; + int rc = 0; + int i = 0; + + FUNC_ENTRY; + if (MQTTPacket_len(rem_len = MQTTSerialize_subscribeLength(count, topicFilters)) > buflen) { + rc = MQTTPACKET_BUFFER_TOO_SHORT; + goto exit; + } + + header.byte = 0; + header.bits.type = SUBSCRIBE; + header.bits.dup = dup; + header.bits.qos = 1; + writeChar(&ptr, header.byte); /* write header */ + + ptr += MQTTPacket_encode(ptr, rem_len); /* write remaining length */; + + writeInt(&ptr, packetid); + + for (i = 0; i < count; ++i) { + writeMQTTString(&ptr, topicFilters[i]); + writeChar(&ptr, requestedQoSs[i]); + } + + rc = ptr - buf; +exit: + FUNC_EXIT_RC(rc); + return rc; +} + + + +/** + Deserializes the supplied (wire) buffer into suback data + @param packetid returned integer - the MQTT packet identifier + @param maxcount - the maximum number of members allowed in the grantedQoSs array + @param count returned integer - number of members in the grantedQoSs array + @param grantedQoSs returned array of integers - the granted qualities of service + @param buf the raw buffer data, of the correct length determined by the remaining length field + @param buflen the length in bytes of the data in the supplied buffer + @return error code. 1 is success, 0 is failure +*/ +int MQTTDeserialize_suback(unsigned short* packetid, int maxcount, int* count, int grantedQoSs[], unsigned char* buf, int buflen) { + MQTTHeader header = {0}; + unsigned char* curdata = buf; + unsigned char* enddata = NULL; + int rc = 0; + int mylen; + + FUNC_ENTRY; + header.byte = readChar(&curdata); + if (header.bits.type != SUBACK) { + goto exit; + } + + curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */ + enddata = curdata + mylen; + if (enddata - curdata < 2) { + goto exit; + } + + *packetid = readInt(&curdata); + + *count = 0; + while (curdata < enddata) { + if (*count > maxcount) { + rc = -1; + goto exit; + } + grantedQoSs[(*count)++] = readChar(&curdata); + } + + rc = 1; +exit: + FUNC_EXIT_RC(rc); + return rc; +} + + diff --git a/Internet/MQTT/MQTTPacket/src/MQTTSubscribeServer.c b/Internet/MQTT/MQTTPacket/src/MQTTSubscribeServer.c new file mode 100644 index 0000000..789952d --- /dev/null +++ b/Internet/MQTT/MQTTPacket/src/MQTTSubscribeServer.c @@ -0,0 +1,112 @@ +/******************************************************************************* + Copyright (c) 2014 IBM Corp. + + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + and Eclipse Distribution License v1.0 which accompany this distribution. + + The Eclipse Public License is available at + http://www.eclipse.org/legal/epl-v10.html + and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + + Contributors: + Ian Craggs - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "MQTTPacket.h" +#include "StackTrace.h" + +#include + + +/** + Deserializes the supplied (wire) buffer into subscribe data + @param dup integer returned - the MQTT dup flag + @param packetid integer returned - the MQTT packet identifier + @param maxcount - the maximum number of members allowed in the topicFilters and requestedQoSs arrays + @param count - number of members in the topicFilters and requestedQoSs arrays + @param topicFilters - array of topic filter names + @param requestedQoSs - array of requested QoS + @param buf the raw buffer data, of the correct length determined by the remaining length field + @param buflen the length in bytes of the data in the supplied buffer + @return the length of the serialized data. <= 0 indicates error +*/ +int MQTTDeserialize_subscribe(unsigned char* dup, unsigned short* packetid, int maxcount, int* count, MQTTString topicFilters[], + int requestedQoSs[], unsigned char* buf, int buflen) { + MQTTHeader header = {0}; + unsigned char* curdata = buf; + unsigned char* enddata = NULL; + int rc = -1; + int mylen = 0; + + FUNC_ENTRY; + header.byte = readChar(&curdata); + if (header.bits.type != SUBSCRIBE) { + goto exit; + } + *dup = header.bits.dup; + + curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */ + enddata = curdata + mylen; + + *packetid = readInt(&curdata); + + *count = 0; + while (curdata < enddata) { + if (!readMQTTLenString(&topicFilters[*count], &curdata, enddata)) { + goto exit; + } + if (curdata >= enddata) { /* do we have enough data to read the req_qos version byte? */ + goto exit; + } + requestedQoSs[*count] = readChar(&curdata); + (*count)++; + } + + rc = 1; +exit: + FUNC_EXIT_RC(rc); + return rc; +} + + +/** + Serializes the supplied suback data into the supplied buffer, ready for sending + @param buf the buffer into which the packet will be serialized + @param buflen the length in bytes of the supplied buffer + @param packetid integer - the MQTT packet identifier + @param count - number of members in the grantedQoSs array + @param grantedQoSs - array of granted QoS + @return the length of the serialized data. <= 0 indicates error +*/ +int MQTTSerialize_suback(unsigned char* buf, int buflen, unsigned short packetid, int count, int* grantedQoSs) { + MQTTHeader header = {0}; + int rc = -1; + unsigned char *ptr = buf; + int i; + + FUNC_ENTRY; + if (buflen < 2 + count) { + rc = MQTTPACKET_BUFFER_TOO_SHORT; + goto exit; + } + header.byte = 0; + header.bits.type = SUBACK; + writeChar(&ptr, header.byte); /* write header */ + + ptr += MQTTPacket_encode(ptr, 2 + count); /* write remaining length */ + + writeInt(&ptr, packetid); + + for (i = 0; i < count; ++i) { + writeChar(&ptr, grantedQoSs[i]); + } + + rc = ptr - buf; +exit: + FUNC_EXIT_RC(rc); + return rc; +} + + diff --git a/Internet/MQTT/MQTTPacket/src/MQTTUnsubscribe.h b/Internet/MQTT/MQTTPacket/src/MQTTUnsubscribe.h new file mode 100644 index 0000000..b32d302 --- /dev/null +++ b/Internet/MQTT/MQTTPacket/src/MQTTUnsubscribe.h @@ -0,0 +1,38 @@ +/******************************************************************************* + Copyright (c) 2014 IBM Corp. + + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + and Eclipse Distribution License v1.0 which accompany this distribution. + + The Eclipse Public License is available at + http://www.eclipse.org/legal/epl-v10.html + and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + + Contributors: + Ian Craggs - initial API and implementation and/or initial documentation + Xiang Rong - 442039 Add makefile to Embedded C client + *******************************************************************************/ + +#ifndef MQTTUNSUBSCRIBE_H_ +#define MQTTUNSUBSCRIBE_H_ + +#if !defined(DLLImport) +#define DLLImport +#endif +#if !defined(DLLExport) +#define DLLExport +#endif + +DLLExport int MQTTSerialize_unsubscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid, + int count, MQTTString topicFilters[]); + +DLLExport int MQTTDeserialize_unsubscribe(unsigned char* dup, unsigned short* packetid, int max_count, int* count, MQTTString topicFilters[], + unsigned char* buf, int len); + +DLLExport int MQTTSerialize_unsuback(unsigned char* buf, int buflen, unsigned short packetid); + +DLLExport int MQTTDeserialize_unsuback(unsigned short* packetid, unsigned char* buf, int len); + +#endif /* MQTTUNSUBSCRIBE_H_ */ diff --git a/Internet/MQTT/MQTTPacket/src/MQTTUnsubscribeClient.c b/Internet/MQTT/MQTTPacket/src/MQTTUnsubscribeClient.c new file mode 100644 index 0000000..4767207 --- /dev/null +++ b/Internet/MQTT/MQTTPacket/src/MQTTUnsubscribeClient.c @@ -0,0 +1,105 @@ +/******************************************************************************* + Copyright (c) 2014 IBM Corp. + + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + and Eclipse Distribution License v1.0 which accompany this distribution. + + The Eclipse Public License is available at + http://www.eclipse.org/legal/epl-v10.html + and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + + Contributors: + Ian Craggs - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "MQTTPacket.h" +#include "StackTrace.h" + +#include + +/** + Determines the length of the MQTT unsubscribe packet that would be produced using the supplied parameters + @param count the number of topic filter strings in topicFilters + @param topicFilters the array of topic filter strings to be used in the publish + @return the length of buffer needed to contain the serialized version of the packet +*/ +int MQTTSerialize_unsubscribeLength(int count, MQTTString topicFilters[]) { + int i; + int len = 2; /* packetid */ + + for (i = 0; i < count; ++i) { + len += 2 + MQTTstrlen(topicFilters[i]); /* length + topic*/ + } + return len; +} + + +/** + Serializes the supplied unsubscribe data into the supplied buffer, ready for sending + @param buf the raw buffer data, of the correct length determined by the remaining length field + @param buflen the length in bytes of the data in the supplied buffer + @param dup integer - the MQTT dup flag + @param packetid integer - the MQTT packet identifier + @param count - number of members in the topicFilters array + @param topicFilters - array of topic filter names + @return the length of the serialized data. <= 0 indicates error +*/ +int MQTTSerialize_unsubscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid, + int count, MQTTString topicFilters[]) { + unsigned char *ptr = buf; + MQTTHeader header = {0}; + int rem_len = 0; + int rc = -1; + int i = 0; + + FUNC_ENTRY; + if (MQTTPacket_len(rem_len = MQTTSerialize_unsubscribeLength(count, topicFilters)) > buflen) { + rc = MQTTPACKET_BUFFER_TOO_SHORT; + goto exit; + } + + header.byte = 0; + header.bits.type = UNSUBSCRIBE; + header.bits.dup = dup; + header.bits.qos = 1; + writeChar(&ptr, header.byte); /* write header */ + + ptr += MQTTPacket_encode(ptr, rem_len); /* write remaining length */; + + writeInt(&ptr, packetid); + + for (i = 0; i < count; ++i) { + writeMQTTString(&ptr, topicFilters[i]); + } + + rc = ptr - buf; +exit: + FUNC_EXIT_RC(rc); + return rc; +} + + +/** + Deserializes the supplied (wire) buffer into unsuback data + @param packetid returned integer - the MQTT packet identifier + @param buf the raw buffer data, of the correct length determined by the remaining length field + @param buflen the length in bytes of the data in the supplied buffer + @return error code. 1 is success, 0 is failure +*/ +int MQTTDeserialize_unsuback(unsigned short* packetid, unsigned char* buf, int buflen) { + unsigned char type = 0; + unsigned char dup = 0; + int rc = 0; + + FUNC_ENTRY; + rc = MQTTDeserialize_ack(&type, &dup, packetid, buf, buflen); + if (type == UNSUBACK) { + rc = 1; + } + FUNC_EXIT_RC(rc); + return rc; +} + + diff --git a/Internet/MQTT/MQTTPacket/src/MQTTUnsubscribeServer.c b/Internet/MQTT/MQTTPacket/src/MQTTUnsubscribeServer.c new file mode 100644 index 0000000..207e6ac --- /dev/null +++ b/Internet/MQTT/MQTTPacket/src/MQTTUnsubscribeServer.c @@ -0,0 +1,100 @@ +/******************************************************************************* + Copyright (c) 2014 IBM Corp. + + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + and Eclipse Distribution License v1.0 which accompany this distribution. + + The Eclipse Public License is available at + http://www.eclipse.org/legal/epl-v10.html + and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + + Contributors: + Ian Craggs - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "MQTTPacket.h" +#include "StackTrace.h" + +#include + + +/** + Deserializes the supplied (wire) buffer into unsubscribe data + @param dup integer returned - the MQTT dup flag + @param packetid integer returned - the MQTT packet identifier + @param maxcount - the maximum number of members allowed in the topicFilters and requestedQoSs arrays + @param count - number of members in the topicFilters and requestedQoSs arrays + @param topicFilters - array of topic filter names + @param buf the raw buffer data, of the correct length determined by the remaining length field + @param buflen the length in bytes of the data in the supplied buffer + @return the length of the serialized data. <= 0 indicates error +*/ +int MQTTDeserialize_unsubscribe(unsigned char* dup, unsigned short* packetid, int maxcount, int* count, MQTTString topicFilters[], + unsigned char* buf, int len) { + MQTTHeader header = {0}; + unsigned char* curdata = buf; + unsigned char* enddata = NULL; + int rc = 0; + int mylen = 0; + + FUNC_ENTRY; + header.byte = readChar(&curdata); + if (header.bits.type != UNSUBSCRIBE) { + goto exit; + } + *dup = header.bits.dup; + + curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */ + enddata = curdata + mylen; + + *packetid = readInt(&curdata); + + *count = 0; + while (curdata < enddata) { + if (!readMQTTLenString(&topicFilters[*count], &curdata, enddata)) { + goto exit; + } + (*count)++; + } + + rc = 1; +exit: + FUNC_EXIT_RC(rc); + return rc; +} + + +/** + Serializes the supplied unsuback data into the supplied buffer, ready for sending + @param buf the buffer into which the packet will be serialized + @param buflen the length in bytes of the supplied buffer + @param packetid integer - the MQTT packet identifier + @return the length of the serialized data. <= 0 indicates error +*/ +int MQTTSerialize_unsuback(unsigned char* buf, int buflen, unsigned short packetid) { + MQTTHeader header = {0}; + int rc = 0; + unsigned char *ptr = buf; + + FUNC_ENTRY; + if (buflen < 2) { + rc = MQTTPACKET_BUFFER_TOO_SHORT; + goto exit; + } + header.byte = 0; + header.bits.type = UNSUBACK; + writeChar(&ptr, header.byte); /* write header */ + + ptr += MQTTPacket_encode(ptr, 2); /* write remaining length */ + + writeInt(&ptr, packetid); + + rc = ptr - buf; +exit: + FUNC_EXIT_RC(rc); + return rc; +} + + diff --git a/Internet/MQTT/MQTTPacket/src/StackTrace.h b/Internet/MQTT/MQTTPacket/src/StackTrace.h new file mode 100644 index 0000000..c02daaf --- /dev/null +++ b/Internet/MQTT/MQTTPacket/src/StackTrace.h @@ -0,0 +1,78 @@ +/******************************************************************************* + Copyright (c) 2014 IBM Corp. + + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + and Eclipse Distribution License v1.0 which accompany this distribution. + + The Eclipse Public License is available at + http://www.eclipse.org/legal/epl-v10.html + and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + + Contributors: + Ian Craggs - initial API and implementation and/or initial documentation + Ian Craggs - fix for bug #434081 + *******************************************************************************/ + +#ifndef STACKTRACE_H_ +#define STACKTRACE_H_ + +#include +#define NOSTACKTRACE 1 + +#if defined(NOSTACKTRACE) +#define FUNC_ENTRY +#define FUNC_ENTRY_NOLOG +#define FUNC_ENTRY_MED +#define FUNC_ENTRY_MAX +#define FUNC_EXIT +#define FUNC_EXIT_NOLOG +#define FUNC_EXIT_MED +#define FUNC_EXIT_MAX +#define FUNC_EXIT_RC(x) +#define FUNC_EXIT_MED_RC(x) +#define FUNC_EXIT_MAX_RC(x) + +#else + +#if defined(WIN32) +#define inline __inline +#define FUNC_ENTRY StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MINIMUM) +#define FUNC_ENTRY_NOLOG StackTrace_entry(__FUNCTION__, __LINE__, -1) +#define FUNC_ENTRY_MED StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MEDIUM) +#define FUNC_ENTRY_MAX StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MAXIMUM) +#define FUNC_EXIT StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MINIMUM) +#define FUNC_EXIT_NOLOG StackTrace_exit(__FUNCTION__, __LINE__, -1) +#define FUNC_EXIT_MED StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MEDIUM) +#define FUNC_EXIT_MAX StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MAXIMUM) +#define FUNC_EXIT_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MINIMUM) +#define FUNC_EXIT_MED_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MEDIUM) +#define FUNC_EXIT_MAX_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MAXIMUM) +#else +#define FUNC_ENTRY StackTrace_entry(__func__, __LINE__, TRACE_MINIMUM) +#define FUNC_ENTRY_NOLOG StackTrace_entry(__func__, __LINE__, -1) +#define FUNC_ENTRY_MED StackTrace_entry(__func__, __LINE__, TRACE_MEDIUM) +#define FUNC_ENTRY_MAX StackTrace_entry(__func__, __LINE__, TRACE_MAXIMUM) +#define FUNC_EXIT StackTrace_exit(__func__, __LINE__, NULL, TRACE_MINIMUM) +#define FUNC_EXIT_NOLOG StackTrace_exit(__func__, __LINE__, NULL, -1) +#define FUNC_EXIT_MED StackTrace_exit(__func__, __LINE__, NULL, TRACE_MEDIUM) +#define FUNC_EXIT_MAX StackTrace_exit(__func__, __LINE__, NULL, TRACE_MAXIMUM) +#define FUNC_EXIT_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MINIMUM) +#define FUNC_EXIT_MED_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MEDIUM) +#define FUNC_EXIT_MAX_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MAXIMUM) + +void StackTrace_entry(const char* name, int line, int trace); +void StackTrace_exit(const char* name, int line, void* return_value, int trace); + +void StackTrace_printStack(FILE* dest); +char* StackTrace_get(unsigned long); + +#endif + +#endif + + + + +#endif /* STACKTRACE_H_ */ diff --git a/Internet/MQTT/mqtt_interface.c b/Internet/MQTT/mqtt_interface.c new file mode 100644 index 0000000..19de0e2 --- /dev/null +++ b/Internet/MQTT/mqtt_interface.c @@ -0,0 +1,190 @@ +//***************************************************************************** +//! \file mqtt_interface.c +//! \brief Paho MQTT to WIZnet Chip interface implement file. +//! \details The process of porting an interface to use paho MQTT. +//! \version 1.0.0 +//! \date 2016/12/06 +//! \par Revision history +//! <2016/12/06> 1st Release +//! +//! \author Peter Bang & Justin Kim +//! \copyright +//! +//! Copyright (c) 2016, 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 "mqtt_interface.h" +#include "wizchip_conf.h" +#include "socket.h" + +unsigned long MilliTimer; + +/* + @brief MQTT MilliTimer handler + @note MUST BE register to your system 1m Tick timer handler. +*/ +void MilliTimer_Handler(void) { + MilliTimer++; +} + +/* + @brief Timer Initialize + @param timer : pointer to a Timer structure + that contains the configuration information for the Timer. +*/ +void TimerInit(Timer* timer) { + timer->end_time = 0; +} + +/* + @brief expired Timer + @param timer : pointer to a Timer structure + that contains the configuration information for the Timer. +*/ +char TimerIsExpired(Timer* timer) { + long left = timer->end_time - MilliTimer; + return (left < 0); +} + +/* + @brief Countdown millisecond Timer + @param timer : pointer to a Timer structure + that contains the configuration information for the Timer. + timeout : setting timeout millisecond. +*/ +void TimerCountdownMS(Timer* timer, unsigned int timeout) { + timer->end_time = MilliTimer + timeout; +} + +/* + @brief Countdown second Timer + @param timer : pointer to a Timer structure + that contains the configuration information for the Timer. + timeout : setting timeout millisecond. +*/ +void TimerCountdown(Timer* timer, unsigned int timeout) { + timer->end_time = MilliTimer + (timeout * 1000); +} + +/* + @brief left millisecond Timer + @param timer : pointer to a Timer structure + that contains the configuration information for the Timer. +*/ +int TimerLeftMS(Timer* timer) { + long left = timer->end_time - MilliTimer; + return (left < 0) ? 0 : left; +} + +/* + @brief New network setting + @param n : pointer to a Network structure + that contains the configuration information for the Network. + sn : socket number where x can be (0..7). + @retval None +*/ +void NewNetwork(Network* n, int sn) { + n->my_socket = sn; + n->mqttread = w5x00_read; + n->mqttwrite = w5x00_write; + n->disconnect = w5x00_disconnect; +} + +/* + @brief read function + @param n : pointer to a Network structure + that contains the configuration information for the Network. + buffer : pointer to a read buffer. + len : buffer length. + @retval received data length or SOCKERR code +*/ +int w5x00_read(Network* n, unsigned char* buffer, int len, long time) { + + if ((getSn_SR(n->my_socket) == SOCK_ESTABLISHED) && (getSn_RX_RSR(n->my_socket) > 0)) { + return recv(n->my_socket, buffer, len); + } + + return SOCK_ERROR; +} + +/* + @brief write function + @param n : pointer to a Network structure + that contains the configuration information for the Network. + buffer : pointer to a read buffer. + len : buffer length. + @retval length of data sent or SOCKERR code +*/ +int w5x00_write(Network* n, unsigned char* buffer, int len, long time) { + if (getSn_SR(n->my_socket) == SOCK_ESTABLISHED) { + return send(n->my_socket, buffer, len); + } + + return SOCK_ERROR; +} + +/* + @brief disconnect function + @param n : pointer to a Network structure + that contains the configuration information for the Network. +*/ +void w5x00_disconnect(Network* n) { + disconnect(n->my_socket); +} + +/* + @brief connect network function + @param n : pointer to a Network structure + that contains the configuration information for the Network. + ip : server iP. + port : server port. + @retval SOCKOK code or SOCKERR code +*/ +int ConnectNetwork(Network* n, uint8_t* ip, uint16_t port) { + uint16_t myport = 12345; + + if (socket(n->my_socket, Sn_MR_TCP, myport, 0) != n->my_socket) { + return SOCK_ERROR; + } + +#if 1 + // 20231016 taylor//teddy 240122 +#if ((_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300)) + if (connect(n->my_socket, ip, port, 4) != SOCK_OK) +#else + if (connect(n->my_socket, ip, port) != SOCK_OK) +#endif +#else + if (connect(n->my_socket, ip, port) != SOCK_OK) +#endif + return SOCK_ERROR; + + return SOCK_OK; +} diff --git a/Internet/MQTT/mqtt_interface.h b/Internet/MQTT/mqtt_interface.h new file mode 100644 index 0000000..ad90421 --- /dev/null +++ b/Internet/MQTT/mqtt_interface.h @@ -0,0 +1,270 @@ +//***************************************************************************** +//! \file mqtt_interface.h +//! \brief Paho MQTT to WIZnet Chip interface Header file. +//! \details The process of porting an interface to use paho MQTT. +//! \version 1.0.0 +//! \date 2016/12/06 +//! \par Revision history +//! <2016/12/06> 1st Release +//! +//! \author Peter Bang & Justin Kim +//! \copyright +//! +//! Copyright (c) 2016, 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. +// +//***************************************************************************** + +/* MQTT subscribe Example.... W5500 + STM32F103(IoT board) + //Include: Board configuration + #include "IoTEVB.h" + + //Include: MCU peripheral Library + #include "stm32f10x_rcc.h" + #include "stm32f10x.h" + + //Include: W5500 iolibrary + #include "w5500.h" + #include "wizchip_conf.h" + #include "misc.h" + + //Include: Internet iolibrary + #include "MQTTClient.h" + + //Include: MCU Specific W5500 driver + #include "W5500HardwareDriver.h" + + //Include: Standard IO Library + #include + + //Socket number defines + #define TCP_SOCKET 0 + + //Receive Buffer Size define + #define BUFFER_SIZE 2048 + + //Global variables + unsigned char targetIP[4] = {}; // mqtt server IP + unsigned int targetPort = 1883; // mqtt server port + uint8_t mac_address[6] = {}; + wiz_NetInfo gWIZNETINFO = { .mac = {}, //user MAC + .ip = {}, //user IP + .sn = {}, + .gw = {}, + .dns = {}, + .dhcp = NETINFO_STATIC}; + + unsigned char tempBuffer[BUFFER_SIZE] = {}; + + struct opts_struct + { + char* clientid; + int nodelimiter; + char* delimiter; + enum QoS qos; + char* username; + char* password; + char* host; + int port; + int showtopics; + } opts ={ (char*)"stdout-subscriber", 0, (char*)"\n", QOS0, NULL, NULL, targetIP, targetPort, 0 }; + + + // @brief messageArrived callback function + void messageArrived(MessageData* md) + { + unsigned char testbuffer[100]; + MQTTMessage* message = md->message; + + if (opts.showtopics) + { + memcpy(testbuffer,(char*)message->payload,(int)message->payloadlen); + (testbuffer + (int)message->payloadlen + 1) = "\n"; + printf("%s\r\n",testbuffer); + } + + if (opts.nodelimiter) + printf("%.*s", (int)message->payloadlen, (char*)message->payload); + else + printf("%.*s%s", (int)message->payloadlen, (char*)message->payload, opts.delimiter); + } + + + // @brief 1 millisecond Tick Timer setting + void NVIC_configuration(void) + { + NVIC_InitTypeDef NVIC_InitStructure; + SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK); + SysTick_Config(72000); + NVIC_InitStructure.NVIC_IRQChannel = SysTick_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; // Highest priority + NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + } + + // @brief 1 millisecond Tick Timer Handler setting + void SysTick_Handler(void) + { + MilliTimer_Handler(); + } + + int main(void) + { + led_ctrl led1,led2; + int i; + int rc = 0; + unsigned char buf[100]; + //Usart initialization for Debug. + USART1Initialze(); + printf("USART initialized.\n\r"); + + I2C1Initialize(); + printf("I2C initialized.\n\r"); + + MACEEP_Read(mac_address,0xfa,6); + + printf("Mac address\n\r"); + for(i = 0 ; i < 6 ; i++) + { + printf("%02x ",mac_address[i]); + } + printf("\n\r"); + + //LED initialization. + led_initialize(); + led1 = led2 = ON; + + led2Ctrl(led2); + led1Ctrl(led1); + + //W5500 initialization. + W5500HardwareInitilize(); + printf("W5500 hardware interface initialized.\n\r"); + + W5500Initialze(); + printf("W5500 IC initialized.\n\r"); + + //Set network informations + wizchip_setnetinfo(&gWIZNETINFO); + + setSHAR(mac_address); + + print_network_information(); + + Network n; + MQTTClient c; + + NewNetwork(&n, TCP_SOCKET); + ConnectNetwork(&n, targetIP, targetPort); + MQTTClientInit(&c,&n,1000,buf,100,tempBuffer,2048); + + MQTTPacket_connectData data = MQTTPacket_connectData_initializer; + data.willFlag = 0; + data.MQTTVersion = 3; + data.clientID.cstring = opts.clientid; + data.username.cstring = opts.username; + data.password.cstring = opts.password; + + data.keepAliveInterval = 60; + data.cleansession = 1; + + rc = MQTTConnect(&c, &data); + printf("Connected %d\r\n", rc); + opts.showtopics = 1; + + printf("Subscribing to %s\r\n", "hello/wiznet"); + rc = MQTTSubscribe(&c, "hello/wiznet", opts.qos, messageArrived); + printf("Subscribed %d\r\n", rc); + + while(1) + { + MQTTYield(&c, data.keepAliveInterval); + } + } +*/ + +#ifndef __MQTT_INTERFACE_H_ +#define __MQTT_INTERFACE_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* + @brief MQTT MilliTimer handler + @note MUST BE register to your system 1m Tick timer handler +*/ +void MilliTimer_Handler(void); + +/* + @brief Timer structure +*/ +typedef struct Timer Timer; +struct Timer { + unsigned long systick_period; + unsigned long end_time; +}; + +/* + @brief Network structure +*/ +typedef struct Network Network; +struct Network { + int my_socket; + int (*mqttread) (Network*, unsigned char*, int, long); + int (*mqttwrite) (Network*, unsigned char*, int, long); + void (*disconnect) (Network*); +}; + +/* + @brief Timer function +*/ +void TimerInit(Timer*); +char TimerIsExpired(Timer*); +void TimerCountdownMS(Timer*, unsigned int); +void TimerCountdown(Timer*, unsigned int); +int TimerLeftMS(Timer*); + +/* + @brief Network interface porting +*/ +int w5x00_read(Network*, unsigned char*, int, long); +int w5x00_write(Network*, unsigned char*, int, long); +void w5x00_disconnect(Network*); +void NewNetwork(Network* n, int sn); +int ConnectNetwork(Network* n, uint8_t* ip, uint16_t port); + +#ifdef __cplusplus +} +#endif + +#endif //__MQTT_INTERFACE_H_ diff --git a/Internet/SNMP/snmp.c b/Internet/SNMP/snmp.c new file mode 100644 index 0000000..2ba75e5 --- /dev/null +++ b/Internet/SNMP/snmp.c @@ -0,0 +1,917 @@ +#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 1 + // 20231019 taylor + uint8_t addr_len; +#endif + + 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) { +#if 1 + // 20231019 taylor//teddy 240122 +#if ((_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300)) + request_msg.len = recvfrom(SOCK_SNMP_AGENT, request_msg.buffer, len, svr_addr, &svr_port, &addr_len); +#else + request_msg.len = recvfrom(SOCK_SNMP_AGENT, request_msg.buffer, len, svr_addr, &svr_port); +#endif +#else + request_msg.len = recvfrom(SOCK_SNMP_AGENT, request_msg.buffer, len, svr_addr, &svr_port); +#endif + } 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) { +#if 1 + // 20231016 taylor//teddy 240122 +#if ((_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300)) + sendto(SOCK_SNMP_AGENT, response_msg.buffer, response_msg.index, svr_addr, svr_port, 4); +#else + sendto(SOCK_SNMP_AGENT, response_msg.buffer, response_msg.index, svr_addr, svr_port); +#endif +#else + sendto(SOCK_SNMP_AGENT, response_msg.buffer, response_msg.index, svr_addr, svr_port); +#endif + } + +#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; i < len; i++) { + if (buff[i] == '.') { + buff[i] = ' '; + } + } + + sscanf((char const*)buff, "%u %u %u %u", &ip1, &ip2, &ip3, &ip4); + pDes[0] = ip1; pDes[1] = ip2; pDes[2] = ip3; pDes[3] = ip4; +} + + +int32_t makeTrapVariableBindings(dataEntryType *oid_data, void *ptr, uint32_t *len) { + uint32_t j; + + ((uint8_t*)ptr)[0] = 0x30; + ((uint8_t*)ptr)[1] = 0xff; + ((uint8_t*)ptr)[2] = 0x06; + ((uint8_t*)ptr)[3] = oid_data->oidlen; + + 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 < enterprise_oid.oidlen; i++) { + packet_trap[packet_index++] = enterprise_oid.oid[i]; + } + + packet_trap[packet_index++] = 0x40; // agent ip + packet_trap[packet_index++] = 0x04; + packet_trap[packet_index++] = agentIP[0]; + packet_trap[packet_index++] = agentIP[1]; + packet_trap[packet_index++] = agentIP[2]; + packet_trap[packet_index++] = agentIP[3]; + + packet_trap[packet_index++] = 0x02; // Generic Trap + packet_trap[packet_index++] = 0x01; + packet_trap[packet_index++] = (uint8_t)genericTrap; + + packet_trap[packet_index++] = 0x02; // Specific Trap + packet_trap[packet_index++] = 0x01; + packet_trap[packet_index++] = (uint8_t)specificTrap; + + packet_trap[packet_index++] = 0x43; // Timestamp + packet_trap[packet_index++] = 0x01; + packet_trap[packet_index++] = 0x00; + + packet_trap[packet_index++] = 0x30; // Sequence of variable-bindings + packet_trap[packet_index] = 0xff; + packet_buff3 = packet_index++; + + // variable-bindings + { + va_start(ap, va_count); + + for (i = 0; i < va_count; i++) { + dataEntryType* fff = va_arg(ap, dataEntryType*); + makeTrapVariableBindings(fff, &(packet_trap[packet_index]), &length_buff); + packet_index = packet_index + length_buff; + length_var_bindings = length_var_bindings + length_buff; + } + + packet_trap[packet_buff3] = length_var_bindings; + + va_end(ap); + } + + + packet_trap[packet_buff1] = packet_index - 2; + packet_trap[packet_buff2] = packet_index - (9 + (uint8_t)strlen((char const*)community)); + + // Send SNMP Trap Packet to NMS + { + socket(SOCK_SNMP_TRAP, Sn_MR_UDP, PORT_SNMP_TRAP, 0); +#if 1 + // 20231016 taylor//teddy 240122 +#if ((_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300)) + sendto(SOCK_SNMP_TRAP, packet_trap, packet_index, managerIP, PORT_SNMP_TRAP, 4); +#else + sendto(SOCK_SNMP_TRAP, packet_trap, packet_index, managerIP, PORT_SNMP_TRAP); +#endif +#else + sendto(SOCK_SNMP_TRAP, packet_trap, packet_index, managerIP, PORT_SNMP_TRAP); +#endif + + close(SOCK_SNMP_TRAP); + return 0; + } +} + +#ifdef _SNMP_DEBUG_ +void dumpCode(uint8_t* header, uint8_t* tail, uint8_t *buff, int32_t len) { + int i; + + printf((char const*)header); + + for (i = 0; i < len; i++) { + if (i % 16 == 0) { + printf("0x%04x : ", i); + } + printf("%02x ", buff[i]); + + if (i % 16 - 15 == 0) { + int j; + printf(" "); + for (j = i - 15; j <= i; j++) { + if (isprint(buff[j])) { + printf("%c", buff[j]); + } else { + printf("."); + } + } + printf("\r\n"); + } + } + + if (i % 16 != 0) { + int j; + int spaces = (len - i + 16 - i % 16) * 3 + 2; + for (j = 0; j < spaces; j++) { + printf(" "); + } + for (j = i - i % 16; j < len; j++) { + if (isprint(buff[j])) { + printf("%c", buff[j]); + } else { + printf("."); + } + } + } + printf((char const*)tail); +} +#endif + diff --git a/Internet/SNMP/snmp.h b/Internet/SNMP/snmp.h new file mode 100644 index 0000000..d197dfb --- /dev/null +++ b/Internet/SNMP/snmp.h @@ -0,0 +1,122 @@ +#ifndef _SNMP_H_ +#define _SNMP_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +// SNMP Debug Message (dump) Enable +#define _SNMP_DEBUG_ + +#define PORT_SNMP_AGENT 161 +#define PORT_SNMP_TRAP 162 + +#define SNMP_V1 0 + +#define MAX_OID 12 +#define MAX_STRING 64 +#define MAX_SNMPMSG_LEN 512 +#define MAX_TRAPMSG_LEN 512 + +// SNMP Error code +#define SNMP_SUCCESS 0 +#define OID_NOT_FOUND -1 +#define TABLE_FULL -2 +#define ILLEGAL_LENGTH -3 +#define INVALID_ENTRY_ID -4 +#define INVALID_DATA_TYPE -5 + +#define NO_SUCH_NAME 2 +#define BAD_VALUE 3 + +// SNMPv1 Commands +#define GET_REQUEST 0xa0 +#define GET_NEXT_REQUEST 0xa1 +#define GET_RESPONSE 0xa2 +#define SET_REQUEST 0xa3 + +// Macros: SNMPv1 request validation checker +#define VALID_REQUEST(x) ((x == GET_REQUEST) || (x == GET_NEXT_REQUEST) || (x == SET_REQUEST)) + +// SNMPv1 Return Types +#define SNMPDTYPE_INTEGER 0x02 +#define SNMPDTYPE_OCTET_STRING 0x04 +#define SNMPDTYPE_NULL_ITEM 0x05 +#define SNMPDTYPE_OBJ_ID 0x06 +#define SNMPDTYPE_SEQUENCE 0x30 +#define SNMPDTYPE_SEQUENCE_OF SNMPDTYPE_SEQUENCE + +#define SNMPDTYPE_COUNTER 0x41 +#define SNMPDTYPE_GAUGE 0x42 +#define SNMPDTYPE_TIME_TICKS 0x43 +#define SNMPDTYPE_OPAQUE 0x44 + +// SNMP Trap: Standard Trap Types (Generic) +#define SNMPTRAP_COLDSTART 0x00 // Generic trap-type 0: Cold Start +#define SNMPTRAP_WARMSTART 0x01 // Generic trap-type 1: Warm Start +#define SNMPTRAP_LINKDOWN 0x02 // Generic trap-type 2: Link Down +#define SNMPTRAP_LINKUP 0x03 // Generic trap-type 3: Link Up +#define SNMPTRAP_AUTHENTICATION 0x04 // Generic trap-type 4: Authentication Failure +#define SNMPTRAP_EGPNEIGHBORLOSS 0x05 // Generic trap-type 5: EGP Neighbor Loss + +// Macros +#define COPY_SEGMENT(x) \ +{ \ + request_msg.index += seglen; \ + memcpy(&response_msg.buffer[response_msg.index], &request_msg.buffer[x.start], seglen ); \ + response_msg.index += seglen; \ +} + +#ifndef HTONL +#define HTONL(x) \ + ((((x) >> 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/Internet/SNMP/snmp_custom.c b/Internet/SNMP/snmp_custom.c new file mode 100644 index 0000000..89a7d65 --- /dev/null +++ b/Internet/SNMP/snmp_custom.c @@ -0,0 +1,178 @@ + +/******************************************************************************************** + 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/Internet/SNMP/snmp_custom.h b/Internet/SNMP/snmp_custom.h new file mode 100644 index 0000000..c200565 --- /dev/null +++ b/Internet/SNMP/snmp_custom.h @@ -0,0 +1,41 @@ +#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/Internet/SNMP/tools/OID_Converter/Readme.txt b/Internet/SNMP/tools/OID_Converter/Readme.txt new file mode 100644 index 0000000..4476586 --- /dev/null +++ b/Internet/SNMP/tools/OID_Converter/Readme.txt @@ -0,0 +1,45 @@ +============================================================ + +============================================================ + ++ 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/Internet/SNMP/tools/net-snmp-5.7(win32-bin)/snmptrapd.conf b/Internet/SNMP/tools/net-snmp-5.7(win32-bin)/snmptrapd.conf new file mode 100644 index 0000000..494e4ec --- /dev/null +++ b/Internet/SNMP/tools/net-snmp-5.7(win32-bin)/snmptrapd.conf @@ -0,0 +1,33 @@ +# +# 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/Internet/SNTP/sntp.c b/Internet/SNTP/sntp.c new file mode 100644 index 0000000..0a0424d --- /dev/null +++ b/Internet/SNTP/sntp.c @@ -0,0 +1,469 @@ +/* + 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 +#if 1 + // 20231019 taylor + uint8_t addr_len; +#endif + + 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 + } +#if 1 + // 20231019 taylor//teddy 240122 +#if ((_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300)) + recvfrom(NTP_SOCKET, data_buf, RSR_len, (uint8_t *)&destip, &destport, &addr_len); +#else + recvfrom(NTP_SOCKET, data_buf, RSR_len, (uint8_t *)&destip, &destport); +#endif +#else + recvfrom(NTP_SOCKET, data_buf, RSR_len, (uint8_t *)&destip, &destport); +#endif + + 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 +#if 1 + // 20231016 taylor//teddy 240122 +#if ((_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300)) + sendto(NTP_SOCKET, ntpmessage, sizeof(ntpmessage), NTPformat.dstaddr, ntp_port, 4); +#else + sendto(NTP_SOCKET, ntpmessage, sizeof(ntpmessage), NTPformat.dstaddr, ntp_port); +#endif +#else + sendto(NTP_SOCKET, ntpmessage, sizeof(ntpmessage), NTPformat.dstaddr, ntp_port); +#endif + ntp_retry_cnt++; + } else { // send request again? it should wait for a while + if ((ntp_retry_cnt % 0xFFF) == 0) { //wait time +#if 1 + // 20231016 taylor//teddy 240122 +#if ((_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300)) + sendto(NTP_SOCKET, ntpmessage, sizeof(ntpmessage), NTPformat.dstaddr, ntp_port, 4); +#else + sendto(NTP_SOCKET, ntpmessage, sizeof(ntpmessage), NTPformat.dstaddr, ntp_port); +#endif +#else + sendto(NTP_SOCKET, ntpmessage, sizeof(ntpmessage), NTPformat.dstaddr, ntp_port); +#endif +#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; + uint8_t leap; + 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 (1) { + leap = 0; + if (((EPOCH + r) % 400 == 0) || + (((EPOCH + r) % 100 != 0) && ((EPOCH + r) % 4 == 0))) { + leap = 1; + } + + if (leap) { + if (n < r_year_total_sec) { + break; + } + n -= r_year_total_sec; + d += 366; + } else { + if (n < p_year_total_sec) { + break; + } + n -= p_year_total_sec; + d += 365; + } + + r++; + y++; + } + + 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 < l; i++) { + if ((i % 400 == 0) || ((i % 100 != 0) && (i % 4 == 0))) { + run_year_cnt += 1; + } + } + + total_day = (l - EPOCH - run_year_cnt) * 365 + run_year_cnt * 366; + + for (i = 1; i <= Nowdatetime.mo; i++) { + if (i == 5 || i == 7 || i == 10 || i == 12) { + total_day += 30; + } + if (i == 3) { + if (l % 400 == 0 || l % 100 != 0 && l % 4 == 0) { + total_day += 29; + } else { + total_day += 28; + } + } + if (i == 2 || i == 4 || i == 6 || i == 8 || i == 9 || i == 11) { + total_day += 31; + } + } + + seconds = (total_day + Nowdatetime.dd - 1) * 24 * 3600; + seconds += Nowdatetime.ss;//seconds + seconds += Nowdatetime.mm * 60; //minute + seconds += Nowdatetime.hh * 3600; //hour + + return seconds; +} diff --git a/Internet/SNTP/sntp.h b/Internet/SNTP/sntp.h new file mode 100644 index 0000000..2327abd --- /dev/null +++ b/Internet/SNTP/sntp.h @@ -0,0 +1,74 @@ +/* + sntp.h + + Created on: 2014. 12. 15. + Author: Administrator +*/ + +#ifndef SNTP_H_ +#define SNTP_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/* + @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/Internet/TFTP/netutil.c b/Internet/TFTP/netutil.c new file mode 100644 index 0000000..aebcfc0 --- /dev/null +++ b/Internet/TFTP/netutil.c @@ -0,0 +1,151 @@ +#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/Internet/TFTP/netutil.h b/Internet/TFTP/netutil.h new file mode 100644 index 0000000..08375a3 --- /dev/null +++ b/Internet/TFTP/netutil.h @@ -0,0 +1,27 @@ + +#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/Internet/TFTP/tftp.c b/Internet/TFTP/tftp.c new file mode 100644 index 0000000..176c971 --- /dev/null +++ b/Internet/TFTP/tftp.c @@ -0,0 +1,639 @@ +/** + @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); + +#if 1 + // 20231016 taylor//teddy 240122 +#if ((_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300)) + snd_len = sendto(socket, packet, len, (uint8_t *)&ip, port, 4); +#else + snd_len = sendto(socket, packet, len, (uint8_t *)&ip, port); +#endif +#else + snd_len = sendto(socket, packet, len, (uint8_t *)&ip, port); +#endif + 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; +#if 1 + // 20231019 taylor + uint8_t addr_len; +#endif + + /* 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) { +#if 1 + // 20231019 taylor//teddy 240122 +#if ((_WIZCHIP_ == 6100) || (_WIZCHIP_ == 6300)) + recv_len = recvfrom(socket, packet, len, (uint8_t *)ip, port, &addr_len); +#else + recv_len = recvfrom(socket, packet, len, (uint8_t *)ip, port); +#endif +#else + recv_len = recvfrom(socket, packet, len, (uint8_t *)ip, port); +#endif + 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/Internet/TFTP/tftp.h b/Internet/TFTP/tftp.h new file mode 100644 index 0000000..699e39f --- /dev/null +++ b/Internet/TFTP/tftp.h @@ -0,0 +1,102 @@ +/** + @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 +#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/Internet/httpServer/httpParser.c b/Internet/httpServer/httpParser.c new file mode 100644 index 0000000..b7c77e8 --- /dev/null +++ b/Internet/httpServer/httpParser.c @@ -0,0 +1,430 @@ +/** + @file httpd.c + @brief functions associated http processing +*/ + +#include +#include +#include "socket.h" +#include "httpParser.h" + +/***************************************************************************** + Public types/enumerations/variables + ****************************************************************************/ +//uint8_t BUFPUB[2048]; +uint8_t BUFPUB[256]; + +/***************************************************************************** + Private functions + ****************************************************************************/ +static void replacetochar(uint8_t * str, uint8_t oldchar, uint8_t newchar); /* Replace old character with new character in the string */ +static uint8_t C2D(uint8_t c); /* Convert a character to HEX */ + +/** + @brief convert escape characters(%XX) to ASCII character +*/ +void unescape_http_url( + char * url /**< pointer to be converted ( escape characters )*/ +) { + int x, y; + + for (x = 0, y = 0; url[y]; ++x, ++y) { + if ((url[x] = url[y]) == '%') { + url[x] = C2D(url[y + 1]) * 0x10+C2D(url[y + 2]); + y += 2; + } + } + url[x] = '\0'; +} + + +/** + @brief make response header such as html, gif, jpeg,etc. +*/ +void make_http_response_head( + char * buf, /**< pointer to response header to be made */ + char type, /**< response type */ + uint32_t len /**< size of response header */ +) { + char * head; + char tmp[10]; + + /* file type*/ + if (type == PTYPE_HTML) { + head = RES_HTMLHEAD_OK; + } else if (type == PTYPE_GIF) { + head = RES_GIFHEAD_OK; + } else if (type == PTYPE_TEXT) { + head = RES_TEXTHEAD_OK; + } else if (type == PTYPE_JPEG) { + head = RES_JPEGHEAD_OK; + } else if (type == PTYPE_FLASH) { + head = RES_FLASHHEAD_OK; + } else if (type == PTYPE_XML) { + head = RES_XMLHEAD_OK; + } else if (type == PTYPE_CSS) { + head = RES_CSSHEAD_OK; + } else if (type == PTYPE_JSON) { + head = RES_JSONHEAD_OK; + } else if (type == PTYPE_JS) { + head = RES_JSHEAD_OK; + } else if (type == PTYPE_CGI) { + head = RES_CGIHEAD_OK; + } else if (type == PTYPE_PNG) { + head = RES_PNGHEAD_OK; + } else if (type == PTYPE_ICO) { + head = RES_ICOHEAD_OK; + } else if (type == PTYPE_TTF) { + head = RES_TTFHEAD_OK; + } else if (type == PTYPE_OTF) { + head = RES_OTFHEAD_OK; + } else if (type == PTYPE_WOFF) { + head = RES_WOFFHEAD_OK; + } else if (type == PTYPE_EOT) { + head = RES_EOTHEAD_OK; + } else if (type == PTYPE_SVG) { + head = RES_SVGHEAD_OK; + } +#ifdef _HTTPPARSER_DEBUG_ + else { + head = NULL; + printf("\r\n\r\n-MAKE HEAD UNKNOWN-\r\n"); + } +#else + else { + head = NULL; + } +#endif + + sprintf(tmp, "%ld", len); + strcpy(buf, head); + strcat(buf, tmp); + strcat(buf, "\r\n\r\n"); +} + + +/** + @brief find MIME type of a file +*/ +void find_http_uri_type( + uint8_t * type, /**< type to be returned */ + uint8_t * buff /**< file name */ +) { + /* Decide type according to extension*/ + + char * buf; + buf = (char *)buff; + + if (strstr(buf, ".htm") || strstr(buf, ".html")) { + *type = PTYPE_HTML; + } else if (strstr(buf, ".gif")) { + *type = PTYPE_GIF; + } else if (strstr(buf, ".text") || strstr(buf, ".txt")) { + *type = PTYPE_TEXT; + } else if (strstr(buf, ".jpeg") || strstr(buf, ".jpg")) { + *type = PTYPE_JPEG; + } else if (strstr(buf, ".swf")) { + *type = PTYPE_FLASH; + } else if (strstr(buf, ".cgi") || strstr(buf, ".CGI")) { + *type = PTYPE_CGI; + } else if (strstr(buf, ".json") || strstr(buf, ".JSON")) { + *type = PTYPE_JSON; + } else if (strstr(buf, ".js") || strstr(buf, ".JS")) { + *type = PTYPE_JS; + } else if (strstr(buf, ".CGI") || strstr(buf, ".cgi")) { + *type = PTYPE_CGI; + } else if (strstr(buf, ".xml") || strstr(buf, ".XML")) { + *type = PTYPE_XML; + } else if (strstr(buf, ".css") || strstr(buf, ".CSS")) { + *type = PTYPE_CSS; + } else if (strstr(buf, ".png") || strstr(buf, ".PNG")) { + *type = PTYPE_PNG; + } else if (strstr(buf, ".ico") || strstr(buf, ".ICO")) { + *type = PTYPE_ICO; + } else if (strstr(buf, ".ttf") || strstr(buf, ".TTF")) { + *type = PTYPE_TTF; + } else if (strstr(buf, ".otf") || strstr(buf, ".OTF")) { + *type = PTYPE_OTF; + } else if (strstr(buf, ".woff") || strstr(buf, ".WOFF")) { + *type = PTYPE_WOFF; + } else if (strstr(buf, ".eot") || strstr(buf, ".EOT")) { + *type = PTYPE_EOT; + } else if (strstr(buf, ".svg") || strstr(buf, ".SVG")) { + *type = PTYPE_SVG; + } else { + *type = PTYPE_ERR; + } +} + + +/** + @brief parse http request from a peer +*/ +void parse_http_request( + st_http_request * request, /**< request to be returned */ + uint8_t * buf /**< pointer to be parsed */ +) { + char * nexttok; + nexttok = strtok((char*)buf, " "); + if (!nexttok) { + request->METHOD = METHOD_ERR; + return; + } + if (!strcmp(nexttok, "GET") || !strcmp(nexttok, "get")) { + request->METHOD = METHOD_GET; + nexttok = strtok(NULL, " "); + + } else if (!strcmp(nexttok, "HEAD") || !strcmp(nexttok, "head")) { + request->METHOD = METHOD_HEAD; + nexttok = strtok(NULL, " "); + + } else if (!strcmp(nexttok, "POST") || !strcmp(nexttok, "post")) { + nexttok = strtok(NULL, "\0"); + request->METHOD = METHOD_POST; + } else { + request->METHOD = METHOD_ERR; + } + + if (!nexttok) { + request->METHOD = METHOD_ERR; + return; + } + strcpy((char *)request->URI, nexttok); +} + +#ifdef _OLD_ +/** + @brief get next parameter value in the request +*/ +uint8_t * get_http_param_value( + char* uri, + char* param_name +) { + char tempURI[MAX_URI_SIZE]; + uint8_t * name = 0; + + + if (!uri || !param_name) { + return 0; + } + + strcpy((char*)tempURI, uri); + if ((name = (uint8_t *)strstr(tempURI, param_name))) { + name += strlen(param_name) + 1; // strlen(para_name) + strlen("=") + if ((name = (uint8_t *)strtok((char *)name, "& \r\n\t\0"))) { + unescape_http_url((char *)name); + replacetochar(name, '+', ' '); + } + } +#ifdef _HTTPPARSER_DEBUG_ + printf(" %s=%s", param_name, name); +#endif + + return name; +} +#else +/** + @brief get next parameter value in the request +*/ +uint8_t * get_http_param_value(char* uri, char* param_name) { + + uint8_t * name = 0; + uint8_t * ret = BUFPUB; + uint8_t * pos2; + uint16_t len = 0, content_len = 0; + uint8_t tmp_buf[10] = {0x00, }; + + if (!uri || !param_name) { + return 0; + } + + /***************/ + mid(uri, "Content-Length: ", "\r\n", (char *)tmp_buf); + content_len = ATOI(tmp_buf, 10); + uri = strstr(uri, "\r\n\r\n"); + uri += 4; + uri[content_len] = 0; + /***************/ + + if ((name = (uint8_t *)strstr(uri, param_name))) { + name += strlen(param_name) + 1; + pos2 = (uint8_t*)strstr((char*)name, "&"); + if (!pos2) { + pos2 = name + strlen((char*)name); + } + len = pos2 - name; + + if (len) { + ret[len] = 0; + strncpy((char*)ret, (char*)name, len); + unescape_http_url((char *)ret); + replacetochar(ret, '+', ' '); + //ret[len] = 0; + //ret[strlen((int8*)ret)] = 0; + //printf("len=%d\r\n",len); + } else { + ret[0] = 0; + } + } else { + return 0; + } +#ifdef _HTTPPARSER_DEBUG_ + printf(" %s=%s\r\n", param_name, ret); +#endif + return ret; +} +#endif + +#ifdef _OLD_ +uint8_t * get_http_uri_name(uint8_t * uri) { + char tempURI[MAX_URI_SIZE]; + uint8_t * uri_name; + + if (!uri) { + return 0; + } + + strcpy(tempURI, (char *)uri); + + uri_name = (uint8_t *)strtok(tempURI, " ?"); + + if (strcmp((char *)uri_name, "/")) { + uri_name++; + } + +#ifdef _HTTPPARSER_DEBUG_ + printf(" uri_name = %s\r\n", uri_name); +#endif + + return uri_name; +} +#else + +uint8_t get_http_uri_name(uint8_t * uri, uint8_t * uri_buf) { + uint8_t * uri_ptr; + if (!uri) { + return 0; + } + + strcpy((char *)uri_buf, (char *)uri); + + uri_ptr = (uint8_t *)strtok((char *)uri_buf, " ?"); + + if (strcmp((char *)uri_ptr, "/")) { + uri_ptr++; + } + strcpy((char *)uri_buf, (char *)uri_ptr); + +#ifdef _HTTPPARSER_DEBUG_ + printf(" uri_name = %s\r\n", uri_buf); +#endif + + return 1; +} + +#endif + +void inet_addr_(uint8_t * addr, uint8_t *ip) { + uint8_t i; + uint8_t taddr[30]; + uint8_t * nexttok; + uint8_t num; + + strcpy((char *)taddr, (char *)addr); + + nexttok = taddr; + for (i = 0; i < 4 ; i++) { + nexttok = (uint8_t *)strtok((char *)nexttok, "."); + if (nexttok[0] == '0' && nexttok[1] == 'x') { + num = ATOI(nexttok + 2, 0x10); + } else { + num = ATOI(nexttok, 10); + } + ip[i] = num; + nexttok = NULL; + } +} + + +/** + @brief CONVERT STRING INTO INTEGER + @return a integer number +*/ +uint16_t ATOI( + uint8_t * str, /**< is a pointer to convert */ + uint8_t base /**< is a base value (must be in the range 2 - 16) */ +) { + unsigned int num = 0; + // debug_2013_11_25 + // while (*str !=0) + while ((*str != 0) && (*str != 0x20)) { // not include the space(0x020) + num = num * base + C2D(*str++); + } + return num; +} + +/** + @brief Check strings and then execute callback function by each string. + @param src The information of URI + @param s1 The start string to be researched + @param s2 The end string to be researched + @param sub The string between s1 and s2 + @return The length value atfer working +*/ +void mid(char* src, char* s1, char* s2, char* sub) { + char* sub1; + char* sub2; + uint16_t n; + + sub1 = strstr((char*)src, (char*)s1); + sub1 += strlen((char*)s1); + sub2 = strstr((char*)sub1, (char*)s2); + + n = sub2 - sub1; + strncpy((char*)sub, (char*)sub1, n); + sub[n] = '\0'; +} + +//////////////////////////////////////////////////////////////////// +// Static functions +//////////////////////////////////////////////////////////////////// + +/** + @brief replace the specified character in a string with new character +*/ +static void replacetochar( + uint8_t * str, /**< pointer to be replaced */ + uint8_t oldchar, /**< old character */ + uint8_t newchar /**< new character */ +) { + int x; + for (x = 0; str[x]; x++) + if (str[x] == oldchar) { + str[x] = newchar; + } +} + +/** + @brief CONVERT CHAR INTO HEX + @return HEX + + This function converts HEX(0-F) to a character +*/ +static uint8_t C2D( + uint8_t c /**< is a character('0'-'F') to convert to HEX */ +) { + if (c >= '0' && c <= '9') { + return c - '0'; + } + if (c >= 'a' && c <= 'f') { + return 10 + c - 'a'; + } + if (c >= 'A' && c <= 'F') { + return 10 + c - 'A'; + } + + return (char)c; +} + + + diff --git a/Internet/httpServer/httpParser.h b/Internet/httpServer/httpParser.h new file mode 100644 index 0000000..58e0021 --- /dev/null +++ b/Internet/httpServer/httpParser.h @@ -0,0 +1,157 @@ +/** + @file httpd.h + @brief Define Constants and fucntions associated with HTTP protocol. +*/ + +#include + +#ifndef __HTTPPARSER_H__ +#define __HTTPPARSER_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +//#define _HTTPPARSER_DEBUG_ + +#define HTTP_SERVER_PORT 80 /**< HTTP server well-known port number */ + +/* HTTP Method */ +#define METHOD_ERR 0 /**< Error Method. */ +#define METHOD_GET 1 /**< GET Method. */ +#define METHOD_HEAD 2 /**< HEAD Method. */ +#define METHOD_POST 3 /**< POST Method. */ + +/* HTTP GET Method */ +#define PTYPE_ERR 0 /**< Error file. */ +#define PTYPE_HTML 1 /**< HTML file. */ +#define PTYPE_GIF 2 /**< GIF file. */ +#define PTYPE_TEXT 3 /**< TEXT file. */ +#define PTYPE_JPEG 4 /**< JPEG file. */ +#define PTYPE_FLASH 5 /**< FLASH file. */ +#define PTYPE_MPEG 6 /**< MPEG file. */ +#define PTYPE_PDF 7 /**< PDF file. */ +#define PTYPE_CGI 8 /**< CGI file. */ +#define PTYPE_XML 9 /**< XML file. */ +#define PTYPE_CSS 10 /**< CSS file. */ +#define PTYPE_JS 11 /**< JavaScript file. */ +#define PTYPE_JSON 12 /**< JSON (JavaScript Standard Object Notation) file. */ +#define PTYPE_PNG 13 /**< PNG file. */ +#define PTYPE_ICO 14 /**< ICON file. */ + +#define PTYPE_TTF 20 /**< Font type: TTF file. */ +#define PTYPE_OTF 21 /**< Font type: OTF file. */ +#define PTYPE_WOFF 22 /**< Font type: WOFF file. */ +#define PTYPE_EOT 23 /**< Font type: EOT file. */ +#define PTYPE_SVG 24 /**< Font type: SVG file. */ + + +/* HTTP response */ +#define STATUS_OK 200 +#define STATUS_CREATED 201 +#define STATUS_ACCEPTED 202 +#define STATUS_NO_CONTENT 204 +#define STATUS_MV_PERM 301 +#define STATUS_MV_TEMP 302 +#define STATUS_NOT_MODIF 304 +#define STATUS_BAD_REQ 400 +#define STATUS_UNAUTH 401 +#define STATUS_FORBIDDEN 403 +#define STATUS_NOT_FOUND 404 +#define STATUS_INT_SERR 500 +#define STATUS_NOT_IMPL 501 +#define STATUS_BAD_GATEWAY 502 +#define STATUS_SERV_UNAVAIL 503 + +/* HTML Doc. for ERROR */ +static const char ERROR_HTML_PAGE[] = "HTTP/1.1 404 Not Found\r\nContent-Type: text/html\r\nContent-Length: 78\r\n\r\n\r\n\r\nSorry, the page you requested was not found.\r\n\r\n\r\n\0"; +static const char ERROR_REQUEST_PAGE[] = "HTTP/1.1 400 OK\r\nContent-Type: text/html\r\nContent-Length: 50\r\n\r\n\r\n\r\nInvalid request.\r\n\r\n\r\n\0"; + +/* HTML Doc. for CGI result */ +#define HTML_HEADER "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: " + +/* Response header for HTML*/ +#define RES_HTMLHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: keep-alive\r\nContent-Length: " + +/* Response head for TEXT */ +#define RES_TEXTHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: " + +/* Response head for GIF */ +#define RES_GIFHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: image/gif\r\nContent-Length: " + +/* Response head for JPEG */ +#define RES_JPEGHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nContent-Length: " + +/* Response head for PNG */ +#define RES_PNGHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: image/png\r\nContent-Length: " + +/* Response head for FLASH */ +#define RES_FLASHHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: application/x-shockwave-flash\r\nContent-Length: " + +/* Response head for XML */ +#define RES_XMLHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: text/xml\r\nConnection: keep-alive\r\nContent-Length: " + +/* Response head for CSS */ +#define RES_CSSHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: text/css\r\nContent-Length: " + +/* Response head for JavaScript */ +#define RES_JSHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: application/javascript\r\nContent-Length: " + +/* Response head for JSON */ +#define RES_JSONHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: " + +/* Response head for ICO */ +#define RES_ICOHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: image/x-icon\r\nContent-Length: " + +/* Response head for CGI */ +#define RES_CGIHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: " + +/* Response head for TTF, Font */ +#define RES_TTFHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: application/x-font-truetype\r\nContent-Length: " + +/* Response head for OTF, Font */ +#define RES_OTFHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: application/x-font-opentype\r\nContent-Length: " + +/* Response head for WOFF, Font */ +#define RES_WOFFHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: application/font-woff\r\nContent-Length: " + +/* Response head for EOT, Font */ +#define RES_EOTHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.ms-fontobject\r\nContent-Length: " + +/* Response head for SVG, Font */ +#define RES_SVGHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: image/svg+xml\r\nContent-Length: " + +/** + @brief Structure of HTTP REQUEST +*/ + +//#define MAX_URI_SIZE 1461 +#define MAX_URI_SIZE 512 + +typedef struct _st_http_request { + uint8_t METHOD; /**< request method(METHOD_GET...). */ + uint8_t TYPE; /**< request type(PTYPE_HTML...). */ + uint8_t URI[MAX_URI_SIZE]; /**< request file name. */ +} st_http_request; + +// HTTP Parsing functions +void unescape_http_url(char * url); /* convert escape character to ascii */ +void parse_http_request(st_http_request *, uint8_t *); /* parse request from peer */ +void find_http_uri_type(uint8_t *, uint8_t *); /* find MIME type of a file */ +void make_http_response_head(char *, char, uint32_t); /* make response header */ +uint8_t * get_http_param_value(char* uri, char* param_name); /* get the user-specific parameter value */ +uint8_t get_http_uri_name(uint8_t * uri, uint8_t * uri_buf); /* get the requested URI name */ +#ifdef _OLD_ +uint8_t * get_http_uri_name(uint8_t * uri); +#endif + +// Utility functions +uint16_t ATOI(uint8_t * str, uint8_t base); +void mid(char* src, char* s1, char* s2, char* sub); +void inet_addr_(uint8_t * addr, uint8_t * ip); + +#ifdef __cplusplus +} +#endif + +#endif /* end of __HTTPPARSER_H__ */ diff --git a/Internet/httpServer/httpServer.c b/Internet/httpServer/httpServer.c new file mode 100644 index 0000000..1663561 --- /dev/null +++ b/Internet/httpServer/httpServer.c @@ -0,0 +1,707 @@ +#include +#include +#include + +#include "socket.h" +#include "wizchip_conf.h" + +#include "httpServer.h" +#include "httpParser.h" +#include "httpUtil.h" + +#ifdef _USE_SDCARD_ +#include "ff.h" // header file for FatFs library (FAT file system) +#endif + +#ifndef DATA_BUF_SIZE +#define DATA_BUF_SIZE 2048 +#endif + +/***************************************************************************** + Private types/enumerations/variables + ****************************************************************************/ +static uint8_t HTTPSock_Num[_WIZCHIP_SOCK_NUM_] = {0, }; +static st_http_request * http_request; /**< Pointer to received HTTP request */ +static st_http_request * parsed_http_request; /**< Pointer to parsed HTTP request */ +static uint8_t * http_response; /**< Pointer to HTTP response */ + +// ## For Debugging +//static uint8_t uri_buf[128]; + +// Number of registered web content in code flash memory +static uint16_t total_content_cnt = 0; +/***************************************************************************** + Public types/enumerations/variables + ****************************************************************************/ +uint8_t * pHTTP_TX; +uint8_t * pHTTP_RX; + +volatile uint32_t httpServer_tick_1s = 0; +st_http_socket HTTPSock_Status[_WIZCHIP_SOCK_NUM_] = { {STATE_HTTP_IDLE, }, }; +httpServer_webContent web_content[MAX_CONTENT_CALLBACK]; + +#ifdef _USE_SDCARD_ +FIL fs; // FatFs: File object +FRESULT fr; // FatFs: File function return code +#endif + +/***************************************************************************** + Private functions + ****************************************************************************/ +void httpServer_Sockinit(uint8_t cnt, uint8_t * socklist); +static uint8_t getHTTPSocketNum(uint8_t seqnum); +static int8_t getHTTPSequenceNum(uint8_t socket); +static int8_t http_disconnect(uint8_t sn); + +static void http_process_handler(uint8_t s, st_http_request * p_http_request); +static void send_http_response_header(uint8_t s, uint8_t content_type, uint32_t body_len, uint16_t http_status); +static void send_http_response_body(uint8_t s, uint8_t * uri_name, uint8_t * buf, uint32_t start_addr, uint32_t file_len); +static void send_http_response_cgi(uint8_t s, uint8_t * buf, uint8_t * http_body, uint16_t file_len); + +/***************************************************************************** + Public functions + ****************************************************************************/ +// Callback functions definition: MCU Reset / WDT Reset +void default_mcu_reset(void) {;} +void default_wdt_reset(void) {;} +void (*HTTPServer_ReStart)(void) = default_mcu_reset; +void (*HTTPServer_WDT_Reset)(void) = default_wdt_reset; + +void httpServer_Sockinit(uint8_t cnt, uint8_t * socklist) { + uint8_t i; + + for (i = 0; i < cnt; i++) { + // Mapping the H/W socket numbers to the sequential index numbers + HTTPSock_Num[i] = socklist[i]; + } +} + +static uint8_t getHTTPSocketNum(uint8_t seqnum) { + // Return the 'H/W socket number' corresponding to the index number + return HTTPSock_Num[seqnum]; +} + +static int8_t getHTTPSequenceNum(uint8_t socket) { + uint8_t i; + + for (i = 0; i < _WIZCHIP_SOCK_NUM_; i++) + if (HTTPSock_Num[i] == socket) { + return i; + } + + return -1; +} + +void httpServer_init(uint8_t * tx_buf, uint8_t * rx_buf, uint8_t cnt, uint8_t * socklist) { + // User's shared buffer + pHTTP_TX = tx_buf; + pHTTP_RX = rx_buf; + + // H/W Socket number mapping + httpServer_Sockinit(cnt, socklist); +} + + +/* Register the call back functions for HTTP Server */ +void reg_httpServer_cbfunc(void(*mcu_reset)(void), void(*wdt_reset)(void)) { + // Callback: HW Reset and WDT reset function for each MCU platforms + if (mcu_reset) { + HTTPServer_ReStart = mcu_reset; + } + if (wdt_reset) { + HTTPServer_WDT_Reset = wdt_reset; + } +} + + +void httpServer_run(uint8_t seqnum) { + uint8_t s; // socket number + uint16_t len; + uint32_t gettime = 0; + +#ifdef _HTTPSERVER_DEBUG_ + uint8_t destip[4] = {0, }; + uint16_t destport = 0; +#endif + + http_request = (st_http_request *)pHTTP_RX; // Structure of HTTP Request + parsed_http_request = (st_http_request *)pHTTP_TX; + + // Get the H/W socket number + s = getHTTPSocketNum(seqnum); + + /* HTTP Service Start */ + switch (getSn_SR(s)) { + case SOCK_ESTABLISHED: + // Interrupt clear + if (getSn_IR(s) & Sn_IR_CON) { + setSn_IR(s, Sn_IR_CON); + } + + // HTTP Process states + switch (HTTPSock_Status[seqnum].sock_status) { + + case STATE_HTTP_IDLE : + if ((len = getSn_RX_RSR(s)) > 0) { + if (len > DATA_BUF_SIZE) { + len = DATA_BUF_SIZE; + } + len = recv(s, (uint8_t *)http_request, len); + + *(((uint8_t *)http_request) + len) = '\0'; + + parse_http_request(parsed_http_request, (uint8_t *)http_request); +#ifdef _HTTPSERVER_DEBUG_ + getSn_DIPR(s, destip); + destport = getSn_DPORT(s); + printf("\r\n"); + printf("> HTTPSocket[%d] : HTTP Request received ", s); + printf("from %d.%d.%d.%d : %d\r\n", destip[0], destip[1], destip[2], destip[3], destport); +#endif +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : [State] STATE_HTTP_REQ_DONE\r\n", s); +#endif + // HTTP 'response' handler; includes send_http_response_header / body function + http_process_handler(s, parsed_http_request); + + gettime = get_httpServer_timecount(); + // Check the TX socket buffer for End of HTTP response sends + while (getSn_TX_FSR(s) != (getSn_TxMAX(s))) { + if ((get_httpServer_timecount() - gettime) > 3) { +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : [State] STATE_HTTP_REQ_DONE: TX Buffer clear timeout\r\n", s); +#endif + break; + } + } + + if (HTTPSock_Status[seqnum].file_len > 0) { + HTTPSock_Status[seqnum].sock_status = STATE_HTTP_RES_INPROC; + } else { + HTTPSock_Status[seqnum].sock_status = STATE_HTTP_RES_DONE; // Send the 'HTTP response' end + } + } + break; + + case STATE_HTTP_RES_INPROC : + /* Repeat: Send the remain parts of HTTP responses */ +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : [State] STATE_HTTP_RES_INPROC\r\n", s); +#endif + // Repeatedly send remaining data to client + send_http_response_body(s, 0, http_response, 0, 0); + + if (HTTPSock_Status[seqnum].file_len == 0) { + HTTPSock_Status[seqnum].sock_status = STATE_HTTP_RES_DONE; + } + break; + + case STATE_HTTP_RES_DONE : +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : [State] STATE_HTTP_RES_DONE\r\n", s); +#endif + // Socket file info structure re-initialize + HTTPSock_Status[seqnum].file_len = 0; + HTTPSock_Status[seqnum].file_offset = 0; + HTTPSock_Status[seqnum].file_start = 0; + HTTPSock_Status[seqnum].sock_status = STATE_HTTP_IDLE; + + //#ifdef _USE_SDCARD_ + // f_close(&fs); + //#endif +#ifdef _USE_WATCHDOG_ + HTTPServer_WDT_Reset(); +#endif + http_disconnect(s); + break; + + default : + break; + } + break; + + case SOCK_CLOSE_WAIT: +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : ClOSE_WAIT\r\n", s); // if a peer requests to close the current connection +#endif + disconnect(s); + break; + + case SOCK_CLOSED: +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : CLOSED\r\n", s); +#endif + if (socket(s, Sn_MR_TCP, HTTP_SERVER_PORT, 0x00) == s) { /* Reinitialize the socket */ +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : OPEN\r\n", s); +#endif + } + break; + + case SOCK_INIT: + listen(s); + break; + + case SOCK_LISTEN: + break; + + default : + break; + + } // end of switch + +#ifdef _USE_WATCHDOG_ + HTTPServer_WDT_Reset(); +#endif +} + +//////////////////////////////////////////// +// Private Functions +//////////////////////////////////////////// +static void send_http_response_header(uint8_t s, uint8_t content_type, uint32_t body_len, uint16_t http_status) { + switch (http_status) { + case STATUS_OK: // HTTP/1.1 200 OK + if ((content_type != PTYPE_CGI) && (content_type != PTYPE_XML)) { // CGI/XML type request does not respond HTTP header +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : HTTP Response Header - STATUS_OK\r\n", s); +#endif + make_http_response_head((char*)http_response, content_type, body_len); + } else { +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : HTTP Response Header - NONE / CGI or XML\r\n", s); +#endif + // CGI/XML type request does not respond HTTP header to client + http_status = 0; + } + break; + case STATUS_BAD_REQ: // HTTP/1.1 400 OK +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : HTTP Response Header - STATUS_BAD_REQ\r\n", s); +#endif + memcpy(http_response, ERROR_REQUEST_PAGE, sizeof(ERROR_REQUEST_PAGE)); + break; + case STATUS_NOT_FOUND: // HTTP/1.1 404 Not Found +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : HTTP Response Header - STATUS_NOT_FOUND\r\n", s); +#endif + memcpy(http_response, ERROR_HTML_PAGE, sizeof(ERROR_HTML_PAGE)); + break; + default: + break; + } + + // Send the HTTP Response 'header' + if (http_status) { +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : [Send] HTTP Response Header [ %d ]byte\r\n", s, (uint16_t)strlen((char *)http_response)); +#endif + send(s, http_response, strlen((char *)http_response)); + } +} + +static void send_http_response_body(uint8_t s, uint8_t * uri_name, uint8_t * buf, uint32_t start_addr, uint32_t file_len) { + int8_t get_seqnum; + uint32_t send_len; + + uint8_t flag_datasend_end = 0; + +#ifdef _USE_SDCARD_ + uint16_t blocklen; +#endif +#ifdef _USE_FLASH_ + uint32_t addr = 0; +#endif + + if ((get_seqnum = getHTTPSequenceNum(s)) == -1) { + return; // exception handling; invalid number + } + + // Send the HTTP Response 'body'; requested file + if (!HTTPSock_Status[get_seqnum].file_len) { // ### Send HTTP response body: First part ### + if (file_len > DATA_BUF_SIZE - 1) { + HTTPSock_Status[get_seqnum].file_start = start_addr; + HTTPSock_Status[get_seqnum].file_len = file_len; + send_len = DATA_BUF_SIZE - 1; + + ///////////////////////////////////////////////////////////////////////////////////////////////// + // ## 20141219 Eric added, for 'File object structure' (fs) allocation reduced (8 -> 1) + memset(HTTPSock_Status[get_seqnum].file_name, 0x00, MAX_CONTENT_NAME_LEN); + strcpy((char *)HTTPSock_Status[get_seqnum].file_name, (char *)uri_name); +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : HTTP Response body - file name [ %s ]\r\n", s, HTTPSock_Status[get_seqnum].file_name); +#endif + ///////////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : HTTP Response body - file len [ %ld ]byte\r\n", s, file_len); +#endif + } else { + // Send process end + send_len = file_len; + +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : HTTP Response end - file len [ %ld ]byte\r\n", s, send_len); +#endif + } +#ifdef _USE_FLASH_ + if (HTTPSock_Status[get_seqnum]->storage_type == DATAFLASH) { + addr = start_addr; + } +#endif + } else { // remained parts +#ifdef _USE_FLASH_ + if (HTTPSock_Status[get_seqnum]->storage_type == DATAFLASH) { + addr = HTTPSock_Status[get_seqnum].file_start + HTTPSock_Status[get_seqnum].file_offset; + } +#endif + send_len = HTTPSock_Status[get_seqnum].file_len - HTTPSock_Status[get_seqnum].file_offset; + + if (send_len > DATA_BUF_SIZE - 1) { + send_len = DATA_BUF_SIZE - 1; + //HTTPSock_Status[get_seqnum]->file_offset += send_len; + } else { +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : HTTP Response end - file len [ %ld ]byte\r\n", s, HTTPSock_Status[get_seqnum].file_len); +#endif + // Send process end + flag_datasend_end = 1; + } +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : HTTP Response body - send len [ %ld ]byte\r\n", s, send_len); +#endif + } + + /*****************************************************/ + //HTTPSock_Status[get_seqnum]->storage_type == NONE + //HTTPSock_Status[get_seqnum]->storage_type == CODEFLASH + //HTTPSock_Status[get_seqnum]->storage_type == SDCARD + //HTTPSock_Status[get_seqnum]->storage_type == DATAFLASH + /*****************************************************/ + + if (HTTPSock_Status[get_seqnum].storage_type == CODEFLASH) { + if (HTTPSock_Status[get_seqnum].file_len) { + start_addr = HTTPSock_Status[get_seqnum].file_start; + } + read_userReg_webContent(start_addr, &buf[0], HTTPSock_Status[get_seqnum].file_offset, send_len); + } +#ifdef _USE_SDCARD_ + else if (HTTPSock_Status[get_seqnum].storage_type == SDCARD) { + // Data read from SD Card + fr = f_read(&fs, &buf[0], send_len, (void *)&blocklen); + if (fr != FR_OK) { + send_len = 0; +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : [FatFs] Error code return: %d (File Read) / HTTP Send Failed - %s\r\n", s, fr, HTTPSock_Status[get_seqnum].file_name); +#endif + } else { + *(buf + send_len + 1) = 0; // Insert '/0' for indicates the 'End of String' (null terminated) + } + } +#endif + +#ifdef _USE_FLASH_ + else if (HTTPSock_Status[get_seqnum]->storage_type == DATAFLASH) { + // Data read from external data flash memory + read_from_flashbuf(addr, &buf[0], send_len); + *(buf + send_len + 1) = 0; // Insert '/0' for indicates the 'End of String' (null terminated) + } +#endif + else { + send_len = 0; + } + // Requested content send to HTTP client +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : [Send] HTTP Response body [ %ld ]byte\r\n", s, send_len); +#endif + + if (send_len) { + send(s, buf, send_len); + } else { + flag_datasend_end = 1; + } + + if (flag_datasend_end) { + HTTPSock_Status[get_seqnum].file_start = 0; + HTTPSock_Status[get_seqnum].file_len = 0; + HTTPSock_Status[get_seqnum].file_offset = 0; + flag_datasend_end = 0; + } else { + HTTPSock_Status[get_seqnum].file_offset += send_len; +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : HTTP Response body - offset [ %ld ]\r\n", s, HTTPSock_Status[get_seqnum].file_offset); +#endif + } + + // ## 20141219 Eric added, for 'File object structure' (fs) allocation reduced (8 -> 1) +#ifdef _USE_SDCARD_ + f_close(&fs); +#endif + // ## 20141219 added end +} + +static void send_http_response_cgi(uint8_t s, uint8_t * buf, uint8_t * http_body, uint16_t file_len) { + uint16_t send_len = 0; + +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : HTTP Response Header + Body - CGI\r\n", s); +#endif + send_len = sprintf((char *)buf, "%s%d\r\n\r\n%s", RES_CGIHEAD_OK, file_len, http_body); +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : HTTP Response Header + Body - send len [ %d ]byte\r\n", s, send_len); +#endif + + send(s, buf, send_len); +} + + +static int8_t http_disconnect(uint8_t sn) { + setSn_CR(sn, Sn_CR_DISCON); + /* wait to process the command... */ + while (getSn_CR(sn)); + + return SOCK_OK; +} + + +static void http_process_handler(uint8_t s, st_http_request * p_http_request) { + uint8_t * uri_name; + uint32_t content_addr = 0; + uint16_t content_num = 0; + uint32_t file_len = 0; + + uint8_t uri_buf[MAX_URI_SIZE] = {0x00, }; + + uint16_t http_status; + int8_t get_seqnum; + uint8_t content_found; + + if ((get_seqnum = getHTTPSequenceNum(s)) == -1) { + return; // exception handling; invalid number + } + + http_status = 0; + http_response = pHTTP_RX; + file_len = 0; + + //method Analyze + switch (p_http_request->METHOD) { + case METHOD_ERR : + http_status = STATUS_BAD_REQ; + send_http_response_header(s, 0, 0, http_status); + break; + + case METHOD_HEAD : + case METHOD_GET : + get_http_uri_name(p_http_request->URI, uri_buf); + uri_name = uri_buf; + + if (!strcmp((char *)uri_name, "/")) { + strcpy((char *)uri_name, INITIAL_WEBPAGE); // If URI is "/", respond by index.html + } + if (!strcmp((char *)uri_name, "m")) { + strcpy((char *)uri_name, M_INITIAL_WEBPAGE); + } + if (!strcmp((char *)uri_name, "mobile")) { + strcpy((char *)uri_name, MOBILE_INITIAL_WEBPAGE); + } + find_http_uri_type(&p_http_request->TYPE, uri_name); // Checking requested file types (HTML, TEXT, GIF, JPEG and Etc. are included) + +#ifdef _HTTPSERVER_DEBUG_ + printf("\r\n> HTTPSocket[%d] : HTTP Method GET\r\n", s); + printf("> HTTPSocket[%d] : Request Type = %d\r\n", s, p_http_request->TYPE); + printf("> HTTPSocket[%d] : Request URI = %s\r\n", s, uri_name); +#endif + + if (p_http_request->TYPE == PTYPE_CGI) { + content_found = http_get_cgi_handler(uri_name, pHTTP_TX, &file_len); + if (content_found && (file_len <= (DATA_BUF_SIZE - (strlen(RES_CGIHEAD_OK) +8)))) { + send_http_response_cgi(s, http_response, pHTTP_TX, (uint16_t)file_len); + } else { + send_http_response_header(s, PTYPE_CGI, 0, STATUS_NOT_FOUND); + } + } else { + // Find the User registered index for web content + if (find_userReg_webContent(uri_buf, &content_num, &file_len)) { + content_found = 1; // Web content found in code flash memory + content_addr = (uint32_t)content_num; + HTTPSock_Status[get_seqnum].storage_type = CODEFLASH; + } + // Not CGI request, Web content in 'SD card' or 'Data flash' requested +#ifdef _USE_SDCARD_ +#ifdef _HTTPSERVER_DEBUG_ + printf("\r\n> HTTPSocket[%d] : Searching the requested content\r\n", s); +#endif + if ((fr = f_open(&fs, (const char *)uri_name, FA_READ)) == 0) { + content_found = 1; // file open succeed + + file_len = fs.fsize; + content_addr = fs.sclust; + HTTPSock_Status[get_seqnum].storage_type = SDCARD; + } +#elif _USE_FLASH_ + else if (/* Read content from Dataflash */) { + content_found = 1; + HTTPSock_Status[get_seqnum]->storage_type = DATAFLASH; + ; // To do + } +#endif + else { + content_found = 0; // fail to find content + } + + if (!content_found) { +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : Unknown Page Request\r\n", s); +#endif + http_status = STATUS_NOT_FOUND; + } else { +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : Find Content [%s] ok - Start [%ld] len [ %ld ]byte\r\n", s, uri_name, content_addr, file_len); +#endif + http_status = STATUS_OK; + } + + // Send HTTP header + if (http_status) { +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : Requested content len = [ %ld ]byte\r\n", s, file_len); +#endif + send_http_response_header(s, p_http_request->TYPE, file_len, http_status); + } + + // Send HTTP body (content) + if (http_status == STATUS_OK) { + send_http_response_body(s, uri_name, http_response, content_addr, file_len); + } + } + break; + + case METHOD_POST : + mid((char *)p_http_request->URI, "/", " HTTP", (char *)uri_buf); + uri_name = uri_buf; + find_http_uri_type(&p_http_request->TYPE, uri_name); // Check file type (HTML, TEXT, GIF, JPEG are included) + +#ifdef _HTTPSERVER_DEBUG_ + printf("\r\n> HTTPSocket[%d] : HTTP Method POST\r\n", s); + printf("> HTTPSocket[%d] : Request URI = %s ", s, uri_name); + printf("Type = %d\r\n", p_http_request->TYPE); +#endif + + if (p_http_request->TYPE == PTYPE_CGI) { // HTTP POST Method; CGI Process + content_found = http_post_cgi_handler(uri_name, p_http_request, http_response, &file_len); +#ifdef _HTTPSERVER_DEBUG_ + printf("> HTTPSocket[%d] : [CGI: %s] / Response len [ %ld ]byte\r\n", s, content_found ? "Content found" : "Content not found", file_len); +#endif + if (content_found && (file_len <= (DATA_BUF_SIZE - (strlen(RES_CGIHEAD_OK) +8)))) { + send_http_response_cgi(s, pHTTP_TX, http_response, (uint16_t)file_len); + + // Reset the H/W for apply to the change configuration information + if (content_found == HTTP_RESET) { + HTTPServer_ReStart(); + } + } else { + send_http_response_header(s, PTYPE_CGI, 0, STATUS_NOT_FOUND); + } + } else { // HTTP POST Method; Content not found + send_http_response_header(s, 0, 0, STATUS_NOT_FOUND); + } + break; + + default : + http_status = STATUS_BAD_REQ; + send_http_response_header(s, 0, 0, http_status); + break; + } +} + +void httpServer_time_handler(void) { + httpServer_tick_1s++; +} + +uint32_t get_httpServer_timecount(void) { + return httpServer_tick_1s; +} + +void reg_httpServer_webContent(uint8_t * content_name, uint8_t * content) { + uint16_t name_len; + uint32_t content_len; + + if (content_name == NULL || content == NULL) { + return; + } else if (total_content_cnt >= MAX_CONTENT_CALLBACK) { + return; + } + + name_len = strlen((char *)content_name); + content_len = strlen((char *)content); + + web_content[total_content_cnt].content_name = malloc(name_len + 1); + strcpy((char *)web_content[total_content_cnt].content_name, (const char *)content_name); + web_content[total_content_cnt].content_len = content_len; + web_content[total_content_cnt].content = content; + + total_content_cnt++; +} + +uint8_t display_reg_webContent_list(void) { + uint16_t i; + uint8_t ret; + + if (total_content_cnt == 0) { + printf(">> Web content file not found\r\n"); + ret = 0; + } else { + printf("\r\n=== List of Web content in code flash ===\r\n"); + for (i = 0; i < total_content_cnt; i++) { + printf(" [%d] ", i + 1); + printf("%s, ", web_content[i].content_name); + printf("%ld byte, ", web_content[i].content_len); + + if (web_content[i].content_len < 30) { + printf("[%s]\r\n", web_content[i].content); + } else { + printf("[ ... ]\r\n"); + } + } + printf("=========================================\r\n\r\n"); + ret = 1; + } + + return ret; +} + +uint8_t find_userReg_webContent(uint8_t * content_name, uint16_t * content_num, uint32_t * file_len) { + uint16_t i; + uint8_t ret = 0; // '0' means 'File Not Found' + + for (i = 0; i < total_content_cnt; i++) { + if (!strcmp((char *)content_name, (char *)web_content[i].content_name)) { + *file_len = web_content[i].content_len; + *content_num = i; + ret = 1; // If the requested content found, ret set to '1' (Found) + break; + } + } + return ret; +} + + +uint16_t read_userReg_webContent(uint16_t content_num, uint8_t * buf, uint32_t offset, uint16_t size) { + uint16_t ret = 0; + uint8_t * ptr; + + if (content_num > total_content_cnt) { + return 0; + } + + ptr = web_content[content_num].content; + if (offset) { + ptr += offset; + } + + strncpy((char *)buf, (char *)ptr, size); + *(buf + size) = 0; // Insert '/0' for indicates the 'End of String' (null terminated) + + ret = strlen((void *)buf); + return ret; +} diff --git a/Internet/httpServer/httpServer.h b/Internet/httpServer/httpServer.h new file mode 100644 index 0000000..4ccd476 --- /dev/null +++ b/Internet/httpServer/httpServer.h @@ -0,0 +1,108 @@ +/** + @file httpServer.h + @brief Define constants and functions related HTTP Web server. +*/ + +#include + +#ifndef __HTTPSERVER_H__ +#define __HTTPSERVER_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +// HTTP Server debug message enable +#define _HTTPSERVER_DEBUG_ + +#define INITIAL_WEBPAGE "index.html" +#define M_INITIAL_WEBPAGE "m/index.html" +#define MOBILE_INITIAL_WEBPAGE "mobile/index.html" + +/* Web Server Content Storage Select */ +//#define _USE_SDCARD_ +#ifndef _USE_SDCARD_ +//#define _USE_FLASH_ +#endif + +#if !defined(_USE_SDCARD_) && !defined(_USE_FLASH_) +#define _NOTUSED_STORAGE_ +#endif + + +/* Watchdog timer */ +//#define _USE_WATCHDOG_ + +/********************************************* + HTTP Process states list +*********************************************/ +#define STATE_HTTP_IDLE 0 /* IDLE, Waiting for data received (TCP established) */ +#define STATE_HTTP_REQ_INPROC 1 /* Received HTTP request from HTTP client */ +#define STATE_HTTP_REQ_DONE 2 /* The end of HTTP request parse */ +#define STATE_HTTP_RES_INPROC 3 /* Sending the HTTP response to HTTP client (in progress) */ +#define STATE_HTTP_RES_DONE 4 /* The end of HTTP response send (HTTP transaction ended) */ + +/********************************************* + HTTP Simple Return Value +*********************************************/ +#define HTTP_FAILED 0 +#define HTTP_OK 1 +#define HTTP_RESET 2 + +/********************************************* + HTTP Content NAME length +*********************************************/ +#define MAX_CONTENT_NAME_LEN 128 + +/********************************************* + HTTP Timeout +*********************************************/ +#define HTTP_MAX_TIMEOUT_SEC 3 // Sec. + +typedef enum { + NONE, ///< Web storage none + CODEFLASH, ///< Code flash memory + SDCARD, ///< SD card + DATAFLASH ///< External data flash memory +} StorageType; + +typedef struct _st_http_socket { + uint8_t sock_status; + uint8_t file_name[MAX_CONTENT_NAME_LEN]; + uint32_t file_start; + uint32_t file_len; + uint32_t file_offset; // (start addr + sent size...) + uint8_t storage_type; // Storage type; Code flash, SDcard, Data flash ... +} st_http_socket; + +// Web content structure for file in code flash memory +#define MAX_CONTENT_CALLBACK 20 + +typedef struct _httpServer_webContent { + uint8_t * content_name; + uint32_t content_len; + uint8_t * content; +} httpServer_webContent; + + +void httpServer_init(uint8_t * tx_buf, uint8_t * rx_buf, uint8_t cnt, uint8_t * socklist); +void reg_httpServer_cbfunc(void(*mcu_reset)(void), void(*wdt_reset)(void)); +void httpServer_run(uint8_t seqnum); + +void reg_httpServer_webContent(uint8_t * content_name, uint8_t * content); +uint8_t find_userReg_webContent(uint8_t * content_name, uint16_t * content_num, uint32_t * file_len); +uint16_t read_userReg_webContent(uint16_t content_num, uint8_t * buf, uint32_t offset, uint16_t size); +uint8_t display_reg_webContent_list(void); + +/* + @brief HTTP Server 1sec Tick Timer handler + @note SHOULD BE register to your system 1s Tick timer handler +*/ +void httpServer_time_handler(void); +uint32_t get_httpServer_timecount(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Internet/httpServer/httpUtil.c b/Internet/httpServer/httpUtil.c new file mode 100644 index 0000000..442613d --- /dev/null +++ b/Internet/httpServer/httpUtil.c @@ -0,0 +1,65 @@ +/** + @file httpUtil.c + @brief HTTP Server Utilities + @version 1.0 + @date 2014/07/15 + @par Revision + 2014/07/15 - 1.0 Release + @author + \n\n @par Copyright (C) 1998 - 2014 WIZnet. All rights reserved. +*/ + +#include +#include +#include +#include "httpUtil.h" + +uint8_t http_get_cgi_handler(uint8_t * uri_name, uint8_t * buf, uint32_t * file_len) { + uint8_t ret = HTTP_OK; + uint16_t len = 0; + + if (predefined_get_cgi_processor(uri_name, buf, &len)) { + ; + } else if (strcmp((const char *)uri_name, "example.cgi") == 0) { + // To do + ; + } else { + // CGI file not found + ret = HTTP_FAILED; + } + + if (ret) { + *file_len = len; + } + return ret; +} + +uint8_t http_post_cgi_handler(uint8_t * uri_name, st_http_request * p_http_request, uint8_t * buf, uint32_t * file_len) { + uint8_t ret = HTTP_OK; + uint16_t len = 0; + uint8_t val = 0; + + if (predefined_set_cgi_processor(uri_name, p_http_request->URI, buf, &len)) { + ; + } else if (strcmp((const char *)uri_name, "example.cgi") == 0) { + // To do + val = 1; + len = sprintf((char *)buf, "%d", val); + } else { + // CGI file not found + ret = HTTP_FAILED; + } + + if (ret) { + *file_len = len; + } + return ret; +} + +uint8_t predefined_get_cgi_processor(uint8_t * uri_name, uint8_t * buf, uint16_t * len) { + ; +} + +uint8_t predefined_set_cgi_processor(uint8_t * uri_name, uint8_t * uri, uint8_t * buf, uint16_t * en) { + ; +} diff --git a/Internet/httpServer/httpUtil.h b/Internet/httpServer/httpUtil.h new file mode 100644 index 0000000..8e670b9 --- /dev/null +++ b/Internet/httpServer/httpUtil.h @@ -0,0 +1,32 @@ +/** + @file httpUtil.h + @brief Header File for HTTP Server Utilities + @version 1.0 + @date 2014/07/15 + @par Revision + 2014/07/15 - 1.0 Release + @author + \n\n @par Copyright (C) 1998 - 2014 WIZnet. All rights reserved. +*/ + +#ifndef __HTTPUTIL_H__ +#define __HTTPUTIL_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "httpServer.h" +#include "httpParser.h" + +uint8_t http_get_cgi_handler(uint8_t * uri_name, uint8_t * buf, uint32_t * file_len); +uint8_t http_post_cgi_handler(uint8_t * uri_name, st_http_request * p_http_request, uint8_t * buf, uint32_t * file_len); + +uint8_t predefined_get_cgi_processor(uint8_t * uri_name, uint8_t * buf, uint16_t * len); +uint8_t predefined_set_cgi_processor(uint8_t * uri_name, uint8_t * uri, uint8_t * buf, uint16_t * len); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/README.md b/README.md new file mode 100644 index 0000000..3d153bb --- /dev/null +++ b/README.md @@ -0,0 +1,140 @@ +# ioLibrary Driver +The ioLibrary means “Internet Offload Library” for WIZnet chip. It includes drivers and application protocols. +The driver (ioLibrary) can be used for the application design of WIZnet TCP/IP chips as W6300, W6100, [W5500](https://docs.wiznet.io/Product/iEthernet/W5500/overview), W5300, W5200, W5100 [W5100S](https://docs.wiznet.io/Product/iEthernet/W5100S/overview). + +## ioLibrary +This driver provides the Berkeley Socket type APIs. +- The tree of Directory + + +```1 +ioLibrary + ┣ Application + ┃ ┣ loopback + ┃ ┃ ┣ loopback.c + ┃ ┃ ┗ loopback.h + ┃ ┗ multicast + ┃ ┣ multicast.c + ┃ ┗ multicast.h + ┣ Ethernet + ┃ ┣ W5100 + ┃ ┃ ┣ w5100.c + ┃ ┃ ┗ w5100.h + ┃ ┣ W5100S + ┃ ┃ ┣ w5100s.c + ┃ ┃ ┗ w5100s.h + ┃ ┣ W5200 + ┃ ┃ ┣ w5200.c + ┃ ┃ ┗ w5200.h + ┃ ┣ W5300 + ┃ ┃ ┣ w5300.c + ┃ ┃ ┗ w5300.h + ┃ ┣ W5500 + ┃ ┃ ┣ w5500.c + ┃ ┃ ┗ w5500.h + ┃ ┣ W6100 + ┃ ┃ ┣ w6100.c + ┃ ┃ ┗ w6100.h + ┃ ┗ W6300 + ┃ ┣ w6300.c + ┃ ┗ w6300.h + ┗ Internet + ┣ AAC + ┃ ┣ AddressAutoConfig.c + ┃ ┗ AddressAutoConfig.h + ┣ DHCP + ┃ ┣ dhcp.c + ┃ ┗ dhcp.h + ┣ DHCP6 + ┃ ┣ dhcp6.c + ┃ ┗ dhcp6.h + ┣ DNS + ┃ ┣ dns.c + ┃ ┗ dns.h + ┣ FTPClient + ┃ ┣ ftpc.c + ┃ ┣ ftpc.h + ┃ ┗ stdio_private.h + ┣ FTPServer + ┃ ┣ ftpd.c + ┃ ┣ ftpd.h + ┃ ┣ REAME.md + ┃ ┗ stdio_private.h + ┣ httpServer + ┃ ┣ httpParser.c + ┃ ┣ httpParser.h + ┃ ┣ httpServer.c + ┃ ┣ httpServer.h + ┃ ┣ httpUtil.c + ┃ ┗ httpUtil.h + ┣ MQTT + ┃ ┣ MQTTPacket + ┃ ┣ mqtt_interface.c + ┃ ┣ mqtt_interface.h + ┃ ┣ MQTTClient.c + ┃ ┗ MQTTClient.h + ┣ SNMP + ┃ ┣ tools + ┃ ┣ snmp.c + ┃ ┣ snmp.h + ┃ ┣ snmp_custom.c + ┃ ┗ snmp_custom.h + ┣ SNTP + ┃ ┣ sntp.c + ┃ ┗ sntp.h + ┗ TFTP + ┣ netutil.c + ┣ netutil.h + ┣ tftp.c + ┗ tftp.h + +``` + +- Ethernet : SOCKET APIs like BSD & WIZCHIP([W5500](https://docs.wiznet.io/Product/iEthernet/W5500/overview) / W5300 / W5200 / W5100 / [W5100S](https://docs.wiznet.io/Product/iEthernet/W5100S/overview)) Driver +- Internet : + - DHCP client + - DNS client + - FTP client + - FTP server + - SNMP agent/trap + - SNTP client + - TFTP client + - HTTP server + - MQTT Client + - Others will be added. + +## How to add an ioLibrary in project through github site. + - Example, refer to https://www.youtube.com/watch?v=mt815RBGdsA + - [ioLibrary Doxygen doument](https://github.com/Wiznet/ioLibrary_Driver/blob/master/Ethernet/Socket_APIs_V3.0.3.chm) : Refer to **TODO** in this document + - Define what chip is used in **wizchip_conf.h** + - Define what Host I/F mode is used in **wizchip_conf.h** + +## Revision History + * ioLibrary V4.0.0 Released : 29, MAR, 2018 + * New features added: Library for W5100S added. + * ioLibrary V3.1.1 Released : 14, Dec, 2016 + * Bug fixed : In Socket.c Fixed MACraw & IPraw sendto function. + * ioLibrary V3.1.0 Released : 05, Dec, 2016 + * Internet application protocol add to MQTT Client (using paho MQTT 3.11) + * ioLibrary V3.0.3 Released : 03, May, 2016 + * In W5300, Fixed some compile errors in close(). Refer to M20160503 + * In close(), replace socket() with some command sequences. + * ioLibrary V3.0.2 Released : 26, April, 2016 + * Applied the erratum #1 in close() of socket.c (Refer to A20160426) + * ioLibrary V3.0.1 Released : 15, July, 2015 + * Bug fixed : In W5100, Fixed CS control problem in read/write buffer with SPI. Refer to M20150715. + * ioLibrary V3.0 Released : 01, June, 2015 + * Add to W5300 + * Typing Error in comments + * Refer to 20150601 in sources. + + * Type casting error Fixed : 09, April. 2015 + In socket.c, send() : Refer to M20150409 + + * ioLibrary V2.0 released : April. 2015 + * Added to W5100, W5200 + * Correct to some typing error + * Fixed the warning of type casting. + + * Last release : Nov. 2014 + diff --git a/iolibrary.chm b/iolibrary.chm new file mode 100644 index 0000000..22ed4b0 Binary files /dev/null and b/iolibrary.chm differ diff --git a/license.txt b/license.txt new file mode 100644 index 0000000..12b994a --- /dev/null +++ b/license.txt @@ -0,0 +1,22 @@ + +Copyright (c) 2014 WIZnet Co.,Ltd. +Copyright (c) WIZnet ioLibrary Project. +All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE.