82
82
_REG_RCR = {"w5100s" : const (0x0019 ), "w5500" : const (0x001B ), "w6100" : const (0x4204 )}
83
83
_REG_RTR = {"w5100s" : const (0x0017 ), "w5500" : const (0x0019 ), "w6100" : const (0x4200 )}
84
84
85
- # Wiznet Socket Registers.
86
- _REG_SNMR = const (0x0000 ) # Socket n Mode
87
- _REG_SNCR = const (0x0001 ) # Socket n Command
88
- _REG_SNIR = const (0x0002 ) # Socket n Interrupt
89
- _REG_SNSR = const (0x0003 ) # Socket n Status
90
- _REG_SNPORT = const (0x0004 ) # Socket n Source Port
91
- _REG_SNDIPR = const (0x000C ) # Destination IP Address
92
- _REG_SNDPORT = const (0x0010 ) # Destination Port
93
- _REG_SNRX_RSR = const (0x0026 ) # RX Free Size
94
- _REG_SNRX_RD = const (0x0028 ) # Read Size Pointer
95
- _REG_SNTX_FSR = const (0x0020 ) # Socket n TX Free Size
96
- _REG_SNTX_WR = const (0x0024 ) # TX Write Pointer
85
+ # *** Wiznet Socket Registers ***
86
+ # Socket n Mode.
87
+ _REG_SNMR = const (0x0000 )
88
+ # Socket n Command.
89
+ _REG_SNCR = {"w5100s" : const (0x0001 ), "w5500" : const (0x0001 ), "w6100" : const (0x0010 )}
90
+ # Socket n Interrupt.
91
+ _REG_SNIR = {"w5100s" : const (0x0002 ), "w5500" : const (0x0002 ), "w6100" : const (0x0020 )}
92
+ # Socket n Status.
93
+ _REG_SNSR = {"w5100s" : const (0x0003 ), "w5500" : const (0x0003 ), "w6100" : const (0x0030 )}
94
+ # Socket n Source Port.
95
+ _REG_SNPORT = {"w5100s" : const (0x0004 ), "w5500" : const (0x0004 ), "w6100" : const (0x0114 )}
96
+ # Destination IPv4 Address.
97
+ _REG_SNDIPR = {"w5100s" : const (0x000C ), "w5500" : const (0x000C ), "w6100" : const (0x0120 )}
98
+ # Destination Port.
99
+ _REG_SNDPORT = {"w5100s" : const (0x0010 ), "w5500" : const (0x0010 ), "w6100" : const (0x0140 )}
100
+ # RX Free Size.
101
+ _REG_SNRX_RSR = {
102
+ "w5100s" : const (0x0026 ),
103
+ "w5500" : const (0x0026 ),
104
+ "w6100" : const (0x0224 ),
105
+ }
106
+ # Read Size Pointer.
107
+ _REG_SNRX_RD = {"w5100s" : const (0x0028 ), "w5500" : const (0x0028 ), "w6100" : const (0x0228 )}
108
+ # Socket n TX Free Size.
109
+ _REG_SNTX_FSR = {
110
+ "w5100s" : const (0x0020 ),
111
+ "w5500" : const (0x0020 ),
112
+ "w6100" : const (0x0204 ),
113
+ }
114
+ # TX Write Pointer.
115
+ _REG_SNTX_WR = {"w5100s" : const (0x0024 ), "w5500" : const (0x0024 ), "w6100" : const (0x020C )}
97
116
98
117
# SNSR Commands
99
118
SNSR_SOCK_CLOSED = const (0x00 )
149
168
_DEFAULT_MAC = (0xDE , 0xAD , 0xBE , 0xEF , 0xFE , 0xED )
150
169
151
170
# Maximum number of sockets to support, differs between chip versions.
152
- _MAX_SOCK_NUM = {"w5100s" : const (0x04 ), "w5500" : const (0x08 )}
171
+ _MAX_SOCK_NUM = {"w5100s" : const (0x04 ), "w5500" : const (0x08 ), "w6100" : const ( 0x08 ) }
153
172
_SOCKET_INVALID = const (0xFF )
154
173
155
174
@@ -405,7 +424,7 @@ def remote_ip(self, socket_num: int) -> str:
405
424
self ._sock_num_in_range (socket_num )
406
425
for octet in range (4 ):
407
426
self ._pbuff [octet ] = self ._read_socket_register (
408
- socket_num , _REG_SNDIPR + octet
427
+ socket_num , _REG_SNDIPR [ self . _chip_type ] + octet
409
428
)
410
429
return self .pretty_ip (self ._pbuff [:4 ])
411
430
@@ -420,7 +439,7 @@ def remote_port(self, socket_num: int) -> int:
420
439
:raises ValueError: If the socket number is out of range.
421
440
"""
422
441
self ._sock_num_in_range (socket_num )
423
- return self ._read_two_byte_sock_reg (socket_num , _REG_SNDPORT )
442
+ return self ._read_two_byte_sock_reg (socket_num , _REG_SNDPORT [ self . _chip_type ] )
424
443
425
444
@property
426
445
def link_status (self ) -> bool :
@@ -1120,27 +1139,27 @@ def _get_tx_free_size(self, sock: int) -> int:
1120
1139
1121
1140
def _read_snrx_rd (self , sock : int ) -> int :
1122
1141
"""Read socket n RX Read Data Pointer Register."""
1123
- return self ._read_two_byte_sock_reg (sock , _REG_SNRX_RD )
1142
+ return self ._read_two_byte_sock_reg (sock , _REG_SNRX_RD [ self . _chip_type ] )
1124
1143
1125
1144
def _write_snrx_rd (self , sock : int , data : int ) -> None :
1126
1145
"""Write socket n RX Read Data Pointer Register."""
1127
- self ._write_two_byte_sock_reg (sock , _REG_SNRX_RD , data )
1146
+ self ._write_two_byte_sock_reg (sock , _REG_SNRX_RD [ self . _chip_type ] , data )
1128
1147
1129
1148
def _read_sntx_wr (self , sock : int ) -> int :
1130
1149
"""Read the socket write buffer pointer for socket `sock`."""
1131
- return self ._read_two_byte_sock_reg (sock , _REG_SNTX_WR )
1150
+ return self ._read_two_byte_sock_reg (sock , _REG_SNTX_WR [ self . _chip_type ] )
1132
1151
1133
1152
def _write_sntx_wr (self , sock : int , data : int ) -> None :
1134
1153
"""Write the socket write buffer pointer for socket `sock`."""
1135
- self ._write_two_byte_sock_reg (sock , _REG_SNTX_WR , data )
1154
+ self ._write_two_byte_sock_reg (sock , _REG_SNTX_WR [ self . _chip_type ] , data )
1136
1155
1137
1156
def _read_sntx_fsr (self , sock : int ) -> int :
1138
1157
"""Read socket n TX Free Size Register"""
1139
- return self ._read_two_byte_sock_reg (sock , _REG_SNTX_FSR )
1158
+ return self ._read_two_byte_sock_reg (sock , _REG_SNTX_FSR [ self . _chip_type ] )
1140
1159
1141
1160
def _read_snrx_rsr (self , sock : int ) -> int :
1142
1161
"""Read socket n Received Size Register"""
1143
- return self ._read_two_byte_sock_reg (sock , _REG_SNRX_RSR )
1162
+ return self ._read_two_byte_sock_reg (sock , _REG_SNRX_RSR [ self . _chip_type ] )
1144
1163
1145
1164
def _read_sndipr (self , sock ) -> bytes :
1146
1165
"""Read socket destination IP address."""
@@ -1154,23 +1173,25 @@ def _read_sndipr(self, sock) -> bytes:
1154
1173
def write_sndipr (self , sock : int , ip_addr : bytes ) -> None :
1155
1174
"""Write to socket destination IP Address."""
1156
1175
for offset , value in enumerate (ip_addr ):
1157
- self ._write_socket_register (sock , _REG_SNDIPR + offset , value )
1176
+ self ._write_socket_register (
1177
+ sock , _REG_SNDIPR [self ._chip_type ] + offset , value
1178
+ )
1158
1179
1159
1180
def write_sndport (self , sock : int , port : int ) -> None :
1160
1181
"""Write to socket destination port."""
1161
- self ._write_two_byte_sock_reg (sock , _REG_SNDPORT , port )
1182
+ self ._write_two_byte_sock_reg (sock , _REG_SNDPORT [ self . _chip_type ] , port )
1162
1183
1163
1184
def read_snsr (self , sock : int ) -> int :
1164
1185
"""Read Socket n Status Register."""
1165
- return self ._read_socket_register (sock , _REG_SNSR )
1186
+ return self ._read_socket_register (sock , _REG_SNSR [ self . _chip_type ] )
1166
1187
1167
1188
def read_snir (self , sock : int ) -> int :
1168
1189
"""Read Socket n Interrupt Register."""
1169
- return self ._read_socket_register (sock , _REG_SNIR )
1190
+ return self ._read_socket_register (sock , _REG_SNIR [ self . _chip_type ] )
1170
1191
1171
1192
def write_snir (self , sock : int , data : int ) -> None :
1172
1193
"""Write to Socket n Interrupt Register."""
1173
- self ._write_socket_register (sock , _REG_SNIR , data )
1194
+ self ._write_socket_register (sock , _REG_SNIR [ self . _chip_type ] , data )
1174
1195
1175
1196
def _read_snmr (self , sock : int ) -> int :
1176
1197
"""Read the socket MR register."""
@@ -1182,13 +1203,13 @@ def write_snmr(self, sock: int, protocol: int) -> None:
1182
1203
1183
1204
def write_sock_port (self , sock : int , port : int ) -> None :
1184
1205
"""Write to the socket port number."""
1185
- self ._write_two_byte_sock_reg (sock , _REG_SNPORT , port )
1206
+ self ._write_two_byte_sock_reg (sock , _REG_SNPORT [ self . _chip_type ] , port )
1186
1207
1187
1208
def write_sncr (self , sock : int , data : int ) -> None :
1188
1209
"""Write to socket command register."""
1189
- self ._write_socket_register (sock , _REG_SNCR , data )
1210
+ self ._write_socket_register (sock , _REG_SNCR [ self . _chip_type ] , data )
1190
1211
# Wait for command to complete before continuing.
1191
- while self ._read_socket_register (sock , _REG_SNCR ):
1212
+ while self ._read_socket_register (sock , _REG_SNCR [ self . _chip_type ] ):
1192
1213
pass
1193
1214
1194
1215
@property
0 commit comments