Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions general/include/lan8670.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,32 @@ int32_t LAN8670_Get_Link_State(lan8670_t *lan, uint8_t *state);
* @return Status.
*/
int32_t LAN8670_RegisterBusIO(lan8670_t *lan, lan8670_IOCtx_t *ioctx);

/**
* @brief Reads the PLCA status.
*
* @param lan Pointer to the lan8670_t instance.
* @param status Buffer for the returned status value. false=The PLCA reconciliation sublayer is not regularly receiving or transmitting the BEACON, true=The PLCA reconciliation sublayer is regularly receiving or transmitting the BEACON
* @return Status (an error code, not related to the *status bool).
*/
int32_t LAN8670_PLCA_Get_Status(lan8670_t *lan, bool *status);

/**
* @brief Reads the PLCA TOTMR (Transmit Opportunity Timer) setting. Should be 32 bit-times by default.
*
* @param lan Pointer to the lan8670_t instance.
* @param buffer Buffer for the register value. The value has a unit of bit-times.
* @return Status.
*/
int32_t LAN8670_PLCA_ReadTOTMR(lan8670_t *lan, bool *buffer);
Comment thread
bjackson312006 marked this conversation as resolved.
Outdated

/**
* @brief Writes the PLCA TOTMR (Transmit Opportunity Timer) setting.
*
* @param lan Pointer to the lan8670_t instance.
* @param data Setting to write to the register. Should be an integer with a unit of bit-times.
* @return Status.
*/
int32_t LAN8670_PLCA_WriteTOTMR(lan8670_t *lan, uint8_t data);

// clang-format on
41 changes: 39 additions & 2 deletions general/src/lan8670.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <stdio.h> // Used for debug()
#include <stdarg.h> // Used for debug()
#include "u_tx_debug.h"

/* SMI Registers */
#define REG_BASIC_CONTROL 0x00 // Basic Control Register. (Datasheet pgs. 63-64)
Expand Down Expand Up @@ -317,9 +318,8 @@ static int mmd_write_register(lan8670_t *lan, uint16_t mmd_addr, uint16_t regist
* @param value Pointer to store the read value.
* @return Status.
*/
static int __attribute__((unused)) mmd_read_register_field(lan8670_t *lan, uint16_t mmd_addr, uint16_t register_offset, int start, int end, uint16_t *value)
static int mmd_read_register_field(lan8670_t *lan, uint16_t mmd_addr, uint16_t register_offset, int start, int end, uint16_t *value)
{
// NOTE: Remove the __attribute__((unused)) if this function gets used.

/* Validate bit range */
if (start > end) {
Expand Down Expand Up @@ -503,6 +503,43 @@ int32_t LAN8670_PLCA_Set_Node_Id(lan8670_t *lan, uint8_t id)
return mmd_write_register_field(lan, MMD_MISC, MISC_PLCA_CTRL1, 0, 7, id);
}

/* false=The PLCA reconciliation sublayer is not regularly receiving or transmitting the BEACON, true=The PLCA reconciliation sublayer is regularly receiving or transmitting the BEACON. */
int32_t LAN8670_PLCA_Get_Status(lan8670_t *lan, bool *status) {
uint16_t reading = 0;
int status = mmd_read_register_field(lan, MMD_MISC, MISC_PLCA_STS, 15, 15, &reading);
if(status != LAN8670_STATUS_OK) {
PRINTLN_ERROR("Failed to call mmd_read_register_field() (Status: %d).", status);
return status;
Comment thread
bjackson312006 marked this conversation as resolved.
Outdated
}

if(reading == 0) {
return false;
}
return true;
Comment thread
bjackson312006 marked this conversation as resolved.
Outdated
}

/* Reads the value of the TOMTR register. Should be 32 bit-times by default. */
Comment thread
bjackson312006 marked this conversation as resolved.
Comment thread
bjackson312006 marked this conversation as resolved.
int32_t LAN8670_PLCA_ReadTOTMR(lan8670_t *lan, uint8_t *buffer) {
uint8_t reading = 0;
int status = mmd_read_register_field(lan, MMD_MISC, MISC_PLCA_TOTMR, 0, 7, &reading);
if(status != LAN8670_STATUS_OK) {
PRINTLN_ERROR("Failed to call mmd_read_register_field() (Status: %d).", status);
return status;
}

*buffer = reading;
Comment thread
bjackson312006 marked this conversation as resolved.
Outdated
return LAN8670_STATUS_OK;
}

/* Writes the value of the TOMTOR register. */
Comment thread
bjackson312006 marked this conversation as resolved.
Comment thread
bjackson312006 marked this conversation as resolved.
int32_t LAN8670_PLCA_WriteTOTMR(lan8670_t *lan, uint8_t data) {
int status = mmd_write_register_field(lan, MMD_MISC, MISC_PLCA_TOTMR, 0, 7, (uint16_t)data);
if(status != LAN8670_STATUS_OK) {
PRINTLN_ERROR("Failed to call mmd_write_register_field() (Status: %d).", status);
return status;
}
Comment thread
bjackson312006 marked this conversation as resolved.
Comment thread
bjackson312006 marked this conversation as resolved.
}

int32_t LAN8670_Get_Link_State(lan8670_t *lan, uint8_t *state)
{
// Read bit 2 of the Basic Status register. (Note: For the LAN8670, this will always be 1.)
Expand Down