@@ -452,77 +452,78 @@ def ifconfig(
452
452
453
453
self ._dns = dns_server
454
454
455
- def _w5100_init (self ) -> int :
455
+ def _w5xxx_init (self ) -> int :
456
456
"""
457
457
Detect and initialize a Wiznet5k ethernet module.
458
458
459
459
:return int: 1 if the initialization succeeds, 0 if it fails.
460
460
"""
461
+
462
+ def _detect_and_reset_w5500 () -> bool :
463
+ """
464
+ Detect and reset a W5500 chip. Called at startup to initialize the
465
+ interface hardware.
466
+
467
+ :return bool: True if a W5500 chip is detected, False if not.
468
+ """
469
+ self ._chip_type = "w5500"
470
+ # assert self.sw_reset() == 0, "Chip not reset properly!"
471
+ self ._write_mr (0x08 )
472
+ # assert self._read_mr()[0] == 0x08, "Expected 0x08."
473
+ if self ._read_mr ()[0 ] != 0x08 :
474
+ return False
475
+
476
+ self ._write_mr (0x10 )
477
+ # assert self._read_mr()[0] == 0x10, "Expected 0x10."
478
+ if self ._read_mr ()[0 ] != 0x10 :
479
+ return False
480
+
481
+ self ._write_mr (0x00 )
482
+ # assert self._read_mr()[0] == 0x00, "Expected 0x00."
483
+ if self ._read_mr ()[0 ] != 0x00 :
484
+ return False
485
+
486
+ if self .read (REG_VERSIONR_W5500 , 0x00 )[0 ] != 0x04 :
487
+ return False
488
+ # self._chip_type = "w5500"
489
+ # self._ch_base_msb = 0x10
490
+ return True
491
+
492
+ def _detect_and_reset_w5100s () -> bool :
493
+ """
494
+ Detect and reset a W5100S chip. Called at startup to initialize the
495
+ interface hardware.
496
+
497
+ :return bool: True if a W5100 chip is detected, False if not.
498
+ """
499
+ self ._chip_type = "w5100s"
500
+ # sw reset
501
+ assert self .sw_reset () == 0 , "Chip not reset properly!"
502
+ if self .read (REG_VERSIONR_W5100S , 0x00 )[0 ] != 0x51 :
503
+ return False
504
+
505
+ self ._ch_base_msb = 0x0400
506
+ return True
507
+
461
508
time .sleep (1 )
462
509
self ._cs .switch_to_output ()
463
510
self ._cs .value = 1
464
511
465
512
# Detect if chip is Wiznet W5500
466
- if self . detect_w5500 () == 1 :
513
+ if _detect_and_reset_w5500 () :
467
514
# perform w5500 initialization
468
515
for i in range (0 , W5200_W5500_MAX_SOCK_NUM ):
469
516
ctrl_byte = 0x0C + (i << 5 )
470
517
self .write (0x1E , ctrl_byte , 2 )
471
518
self .write (0x1F , ctrl_byte , 2 )
472
519
else :
473
520
# Detect if chip is Wiznet W5100S
474
- if self . detect_w5100s () == 1 :
521
+ if _detect_and_reset_w5100s () :
475
522
pass
476
523
else :
477
524
return 0
478
525
return 1
479
526
480
- def detect_w5500 (self ) -> int :
481
- """
482
- Detect W5500 chip.
483
-
484
- :return int: 1 if a W5500 chip is detected, -1 if not.
485
- """
486
- self ._chip_type = "w5500"
487
- if self .sw_reset () != 0 :
488
- raise RuntimeError ("Chip not reset properly!" )
489
- self ._write_mr (0x08 )
490
- # assert self._read_mr()[0] == 0x08, "Expected 0x08."
491
- if self ._read_mr ()[0 ] != 0x08 :
492
- return - 1
493
-
494
- self ._write_mr (0x10 )
495
- # assert self._read_mr()[0] == 0x10, "Expected 0x10."
496
- if self ._read_mr ()[0 ] != 0x10 :
497
- return - 1
498
-
499
- self ._write_mr (0x00 )
500
- # assert self._read_mr()[0] == 0x00, "Expected 0x00."
501
- if self ._read_mr ()[0 ] != 0x00 :
502
- return - 1
503
-
504
- if self .read (REG_VERSIONR_W5500 , 0x00 )[0 ] != 0x04 :
505
- return - 1
506
- # self._chip_type = "w5500"
507
- # self._ch_base_msb = 0x10
508
- return 1
509
-
510
- def detect_w5100s (self ) -> int :
511
- """
512
- Detect W5100S chip.
513
-
514
- :return int: 1 if a W5100 chip is detected, -1 if not.
515
- """
516
- self ._chip_type = "w5100s"
517
- # sw reset
518
- if self .sw_reset () != 0 :
519
- raise RuntimeError ("Chip not reset properly!" )
520
- if self .read (REG_VERSIONR_W5100S , 0x00 )[0 ] != 0x51 :
521
- return - 1
522
-
523
- self ._ch_base_msb = 0x0400
524
- return 1
525
-
526
527
def sw_reset (self ) -> int :
527
528
"""Perform a soft-reset on the Wiznet chip.
528
529
0 commit comments