Skip to content

Commit 9ecadf0

Browse files
Added get link state function (technically dont need)
1 parent 26fb52e commit 9ecadf0

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

general/include/lan8670.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,18 @@ int32_t LAN8670_PLCA_Set_Node_Count(lan8670_t *lan, uint8_t node_count);
160160
*/
161161
int32_t LAN8670_PLCA_Set_Node_Id(lan8670_t *lan, uint8_t id);
162162

163+
/**
164+
* @brief Gets the current link state of the LAN8670.
165+
*
166+
* The link state can be one of the following:
167+
* - 0: Link is down
168+
* - 1: Link is up
169+
*
170+
* @param lan Pointer to the lan8670_t instance.
171+
* @param state Pointer to a variable to store the link state.
172+
* @note For the LAN8670, the link state bit is always 1 (link is up). If this function returns 0, something weird has happened.
173+
* @return Status.
174+
*/
175+
int32_t LAN8670_Get_Link_State(lan8670_t *lan, uint8_t *state);
176+
163177
// clang-format on

general/src/lan8670.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,4 +503,19 @@ int32_t LAN8670_PLCA_Set_Node_Id(lan8670_t *lan, uint8_t id)
503503
return mmd_write_register_field(lan, MMD_MISC, MISC_PLCA_CTRL1, 0, 7, id);
504504
}
505505

506+
int32_t LAN8670_Get_Link_State(lan8670_t *lan, uint8_t *state)
507+
{
508+
// Read bit 2 of the Basic Status register. (Note: For the LAN8670, this will always be 1.)
509+
uint32_t value = 0;
510+
int status = read_register_field(lan, REG_BASIC_STATUS, 2, 2, &value);
511+
if (status != LAN8670_STATUS_OK) {
512+
debug(lan, "ERROR 8000: LAN8670_Get_Link_State() failed to read Basic Status Register (Status: %d)\n", status);
513+
return status;
514+
}
515+
516+
// Store the link state in the provided pointer.
517+
*state = (uint8_t)value;
518+
return LAN8670_STATUS_OK;
519+
}
520+
506521
// clang-format on

0 commit comments

Comments
 (0)