Skip to content

Commit c9d989d

Browse files
Made it so DevAddr gets hardcoded in LAN8670_Init()
1 parent ddcea9a commit c9d989d

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

general/include/lan8670.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,10 @@ typedef struct {
4747
/**
4848
* @brief Initializes a LAN8670 instance.
4949
* @param lan Pointer to the lan8670_t instance.
50-
* @param device_address The address of the LAN8670.
51-
* @param read Function pointer for reading data from the LAN8670.
52-
* @param write Function pointer for writing data to the LAN8670.
50+
* @param DevAddr The device address of the LAN8670. This is a 5-bit value indicated by the PHYAD0-PHYAD4 pins and their pull-up/pull-down configuration.
5351
* @return Status.
5452
*/
55-
int32_t LAN8670_Init(lan8670_t *lan); // Initializes a LAN8670 instance.
53+
int32_t LAN8670_Init(lan8670_t *lan, uint32_t DevAddr); // Initializes a LAN8670 instance.
5654

5755
/**
5856
* @brief Performs a software reset of the LAN8670 Ethernet PHY.

general/src/lan8670.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,16 +411,21 @@ static int mmd_write_register_field(lan8670_t *lan, uint16_t mmd_addr, uint16_t
411411

412412
/**** API FUNCTIONS ****/
413413

414-
int32_t LAN8670_Init(lan8670_t *lan)
414+
int32_t LAN8670_Init(lan8670_t *lan, uint32_t DevAddr)
415415
{
416-
// Set the device address to the SMIADR[4:0] field of the Strap Control 0 Register.
416+
// Store the DevAddr
417+
lan->DevAddr = DevAddr;
418+
419+
// Double-check that DevAddr is the same as what's stored in the SMIADR[4:0] field of the Strap Control 0 Register.
417420
uint32_t buffer = 0;
418421
int32_t status = read_register_field(lan, REG_STRAP_CTRL0, 0, 4, &buffer);
419422
if(status != 0) {
420423
debug(lan, "ERROR 0000: LAN8670_Init() failed to read Strap Control Register 0 (Status: %d)\n", status);
421424
return LAN8670_STATUS_READ_ERROR;
422425
}
423-
lan->DevAddr = buffer;
426+
if(lan->DevAddr != buffer) {
427+
PRINTLN_WARNING("The hardcoded DevAddr value isn't the same as what's stored in SMIADR[4:0]. Something weird is probably going on (how did it even read the register in the first place)? (DevAddr=%d, SMIADR[4:0]=%d).", lan->DevAddr, buffer);
428+
}
424429

425430
lan->debug = false; // Default to no debugging.
426431

0 commit comments

Comments
 (0)