Skip to content

Commit fac5cdb

Browse files
More changes for similarity w/ ethernetif.c driver
1 parent b436423 commit fac5cdb

2 files changed

Lines changed: 52 additions & 30 deletions

File tree

general/include/lan8670.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ typedef struct {
4141
* @param device_address The address of the LAN8670.
4242
* @param read Function pointer for reading data from the LAN8670.
4343
* @param write Function pointer for writing data to the LAN8670.
44+
* @return 0 on success, or a non-zero error code.
4445
*/
45-
void lan8670_init(lan8670_t *lan, uint32_t device_address, lan8670_ReadReg_Func read, lan8670_WriteReg_Func write); // Initializes a LAN8670 instance.
46+
int32_t LAN8670_Init(lan8670_t *lan); // Initializes a LAN8670 instance.
4647

4748
/**
4849
* @brief Performs a software reset of the LAN8670 Ethernet PHY.
4950
* @param lan Pointer to the lan8670_t instance.
5051
* @return 0 on success, or a non-zero error code.
5152
*/
52-
int lan8670_reset(lan8670_t *lan); // Performs a software reset of the LAN8670 Ethernet PHY.
53+
int32_t LAN8670_Reset(lan8670_t *lan); // Performs a software reset of the LAN8670 Ethernet PHY.
5354

5455
/**
5556
* @brief Enables or disables loopback mode on the LAN8670.
@@ -62,7 +63,7 @@ int lan8670_reset(lan8670_t *lan); // Performs a software reset of the LAN8670 E
6263
* @param setting true to enable loopback mode, false to disable it.
6364
* @return 0 on success, or a non-zero error code.
6465
*/
65-
int lan8670_loopback(lan8670_t *lan, bool setting); // Enables or disables loopback mode on the LAN8670.
66+
int32_t LAN8670_Loopback(lan8670_t *lan, bool setting); // Enables or disables loopback mode on the LAN8670.
6667

6768
/**
6869
* @brief Enables or disables the LAN8670's low power mode.
@@ -74,15 +75,15 @@ int lan8670_loopback(lan8670_t *lan, bool setting); // Enables or disables loopb
7475
* @param setting true to enable low power mode, false to disable it.
7576
* @return 0 on success, or a non-zero error code.
7677
*/
77-
int lan8670_low_power_mode(lan8670_t *lan, bool setting); // Enables or disables the LAN8670's low power mode.
78+
int32_t LAN8670_Low_Power_Mode(lan8670_t *lan, bool setting); // Enables or disables the LAN8670's low power mode.
7879

7980
/**
8081
* @brief Electrically isolates the LAN8670 from MII/RMII.
8182
* @param lan Pointer to the lan8670_t instance.
8283
* @param setting true to isolate the device, false for normal operation.
8384
* @return 0 on success, or a non-zero error code.
8485
*/
85-
int lan8670_isolate(lan8670_t *lan, bool setting); // Electrically isolates the LAN8670 from MII/RMII.
86+
int32_t LAN8670_Isolate(lan8670_t *lan, bool setting); // Electrically isolates the LAN8670 from MII/RMII.
8687

8788
/**
8889
* @brief Enables or disables the LAN8670's collision test mode.
@@ -95,23 +96,23 @@ int lan8670_isolate(lan8670_t *lan, bool setting); // Electrically isolates the
9596
* @param setting true to enable collision test mode, false to disable it.
9697
* @return 0 on success, or a non-zero error code.
9798
*/
98-
int lan8670_collision_test(lan8670_t *lan, bool setting); // Enables or disables the LAN8670's collision test mode.
99+
int32_t LAN8670_Collision_Test(lan8670_t *lan, bool setting); // Enables or disables the LAN8670's collision test mode.
99100

100101
/**
101102
* @brief Detects jabber condition on the LAN8670.
102103
* @param lan Pointer to the lan8670_t instance.
103104
* @param jabber_status Pointer to a boolean variable to store the jabber status.
104105
* @return 0 on success, or a non-zero error code.
105106
*/
106-
int lan8670_detect_jabber(lan8670_t *lan, bool *jabber_status); // Detects jabber condition on the LAN8670.
107+
int32_t LAN8670_Detect_Jabber(lan8670_t *lan, bool *jabber_status); // Detects jabber condition on the LAN8670.
107108

108109
/**
109110
* @brief Enables or disables collision detection on the LAN8670.
110111
* @param lan Pointer to the lan8670_t instance.
111112
* @param setting true to enable collision detection, false to disable it.
112113
* @return 0 on success, or a non-zero error code.
113114
*/
114-
int lan8670_collision_detection(lan8670_t *lan, bool setting);
115+
int32_t LAN8670_Collision_Detection(lan8670_t *lan, bool setting);
115116

116117
/**
117118
* @brief Enables or disables Physical Layer Collision Avoidence (PLCA).
@@ -124,15 +125,15 @@ int lan8670_collision_detection(lan8670_t *lan, bool setting);
124125
* @param setting true to enable PLCA, false to disable it.
125126
* @return 0 on success, or a non-zero error code.
126127
*/
127-
int lan8670_plca_on(lan8670_t *lan, bool setting);
128+
int32_t LAN8670_PLCA_On(lan8670_t *lan, bool setting);
128129

129130
/**
130131
* @brief Resets the PLCA reconciliation sublayer.
131132
*
132133
* @param lan Pointer to the lan8670_t instance.
133134
* @return 0 on success, or a non-zero error code.
134135
*/
135-
int lan8670_plca_reset(lan8670_t *lan);
136+
int32_t LAN8670_PLCA_Reset(lan8670_t *lan);
136137

137138
/**
138139
* @brief Configures the maximum number of nodes supported on the multidrop network.
@@ -144,7 +145,7 @@ int lan8670_plca_reset(lan8670_t *lan);
144145
* @param node_count The number of nodes on the network.
145146
* @return 0 on success, or a non-zero error code.
146147
*/
147-
int lan8670_plca_set_node_count(lan8670_t *lan, uint8_t node_count);
148+
int32_t LAN8670_PLCA_Set_Node_Count(lan8670_t *lan, uint8_t node_count);
148149

149150
/**
150151
* @brief Sets the ID of the PLCA node.
@@ -156,14 +157,14 @@ int lan8670_plca_set_node_count(lan8670_t *lan, uint8_t node_count);
156157
* @param id The ID of the PLCA node (0-31).
157158
* @return 0 on success, or a non-zero error code.
158159
*/
159-
int lan8670_plca_set_node_id(lan8670_t *lan, uint8_t id);
160+
int32_t LAN8670_PLCA_Set_Node_Id(lan8670_t *lan, uint8_t id);
160161

161162
/**
162163
* @brief Gets the current link state of the LAN8670.
163164
* @param lan Pointer to the lan8670_t instance.
164165
* @param link_up Pointer to a boolean variable to store the link state (true if link is up, false if down).
165166
* @return 0 on success, or a non-zero error code.
166167
*/
167-
int lan8670_get_link_state(lan8670_t *lan, bool *link_up);
168+
int32_t LAN8670_Get_Link_State(lan8670_t *lan, bool *link_up);
168169

169170
// clang-format on

general/src/lan8670.c

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -407,82 +407,103 @@ static int mmd_write_register_field(lan8670_t *lan, uint16_t mmd_addr, uint16_t
407407

408408
/**** API FUNCTIONS ****/
409409

410-
void lan8670_init(lan8670_t *lan, uint32_t device_address, lan8670_ReadReg_Func read, lan8670_WriteReg_Func write)
410+
int32_t LAN8670_Init(lan8670_t *lan)
411411
{
412-
lan->IO.WriteReg = write;
413-
lan->IO.ReadReg = read;
414-
lan->DevAddr = device_address;
415-
lan->debug = false; // Default to no debugging. Set this to true (after calling lan8670_init()) if you want debugging enabled.
412+
// Set the device address to the SMIADR[4:0] field of the Strap Control 0 Register.
413+
uint32_t buffer = 0;
414+
int32_t status = read_register_field(lan, REG_STRAP_CTRL0, 0, 4, &buffer);
415+
if(status != 0) {
416+
debug(lan, "ERROR 0000: LAN8670_Init() failed to read Strap Control Register 0 (Status: %d)\n", status);
417+
return -1;
418+
}
419+
lan->DevAddr = buffer;
420+
421+
lan->debug = false; // Default to no debugging.
422+
}
423+
424+
int32_t LAN8670_RegisterBusIO(lan8670_t *lan, lan8670_IOCtx_t *ioctx)
425+
{
426+
if(!lan || !ioctx->ReadReg || !ioctx->WriteReg || !ioctx->GetTick) {
427+
return -1; // Invalid parameters
428+
}
429+
430+
lan->IO.Init = ioctx->Init;
431+
lan->IO.DeInit = ioctx->DeInit;
432+
lan->IO.WriteReg = ioctx->WriteReg;
433+
lan->IO.ReadReg = ioctx->ReadReg;
434+
lan->IO.GetTick = ioctx->GetTick;
435+
436+
return 0;
416437
}
417438

418-
int lan8670_reset(lan8670_t *lan)
439+
int32_t LAN8670_Reset(lan8670_t *lan)
419440
{
420441
// Set bit 15 in the Basic Control Register, and clear all other bits.
421442
// This starts a software reset of the PHY.
422443
return lan->IO.WriteReg(lan->DevAddr, REG_BASIC_CONTROL, 0x8000);
423444
}
424445

425-
int lan8670_loopback(lan8670_t *lan, bool setting)
446+
int32_t LAN8670_Loopback(lan8670_t *lan, bool setting)
426447
{
427448
// Modify bit 14 of the Basic Control Register to whatever 'setting' is.
428449
return write_register_field(lan, REG_BASIC_CONTROL, 14, 14, setting);
429450
}
430451

431-
int lan8670_low_power_mode(lan8670_t *lan, bool setting)
452+
int32_t LAN8670_Low_Power_Mode(lan8670_t *lan, bool setting)
432453
{
433454
// Modify bit 11 of the Basic Control Register to whatever 'setting' is.
434455
return write_register_field(lan, REG_BASIC_CONTROL, 11, 11, setting);
435456
}
436457

437-
int lan8670_isolate(lan8670_t *lan, bool setting)
458+
int32_t LAN8670_Isolate(lan8670_t *lan, bool setting)
438459
{
439460
// Modify bit 10 of the Basic Control Register to whatever 'setting' is.
440461
return write_register_field(lan, REG_BASIC_CONTROL, 10, 10, setting);
441462
}
442463

443-
int lan8670_collision_test(lan8670_t *lan, bool setting)
464+
int32_t LAN8670_Collision_Test(lan8670_t *lan, bool setting)
444465
{
445466
// Modify bit 7 of the Basic Control Register to whatever 'setting' is.
446467
return write_register_field(lan, REG_BASIC_CONTROL, 7, 7, setting);
447468
}
448469

449-
int lan8670_detect_jabber(lan8670_t *lan, bool *jabber_status)
470+
int32_t LAN8670_Detect_Jabber(lan8670_t *lan, bool *jabber_status)
450471
{
451472
// Read bit 1 of the Basic Status Register to 'jabber_status'.
452473
return read_register_field(lan, REG_BASIC_STATUS, 1, 1, jabber_status);
453474
}
454475

455-
int lan8670_collision_detection(lan8670_t *lan, bool setting) {
476+
int32_t LAN8670_Collision_Detection(lan8670_t *lan, bool setting) {
456477
// Modify bit 15 of the Collision Detector Control 0 Register to whatever 'setting' is.
457478
return mmd_write_register_field(lan, MMD_MISC, MISC_CDCTL0, 15, 15, setting);
458479
}
459480

460-
int lan8670_plca_on(lan8670_t *lan, bool setting)
481+
int32_t LAN8670_PLCA_On(lan8670_t *lan, bool setting)
461482
{
462483
// Set/clear bit 15 of the PLCA Control 0 Register to whatever 'setting' is.
463484
return mmd_write_register_field(lan, MMD_MISC, MISC_PLCA_CTRL0, 15, 15, setting);
464485
}
465486

466-
int lan8670_plca_reset(lan8670_t *lan)
487+
int32_t LAN8670_PLCA_Reset(lan8670_t *lan)
467488
{
468489
// Set bit 14 in the PLCA Control 0 Register, and clear all other bits.
469490
// This starts a software reset of the PLCA reconciliation sublayer.
470491
return mmd_write_register(lan, MMD_MISC, MISC_PLCA_CTRL0, 0x4000);
471492
}
472493

473-
int lan8670_plca_set_node_count(lan8670_t *lan, uint8_t node_count)
494+
int32_t LAN8670_PLCA_Set_Node_Count(lan8670_t *lan, uint8_t node_count)
474495
{
475496
// Modify bits 8-15 of the PLCA Control 1 Register to whatever 'node_count' is.
476497
return mmd_write_register_field(lan, MMD_MISC, MISC_PLCA_CTRL1, 8, 15, node_count);
477498
}
478499

479-
int lan8670_plca_set_node_id(lan8670_t *lan, uint8_t id)
500+
int32_t LAN8670_PLCA_Set_Node_Id(lan8670_t *lan, uint8_t id)
480501
{
481502
// Modify bits 0-7 of the PLCA Control 1 Register to whatever 'id' is.
482503
return mmd_write_register_field(lan, MMD_MISC, MISC_PLCA_CTRL1, 0, 7, id);
483504
}
484505

485-
int lan8670_get_link_state(lan8670_t *lan, bool *link_up)
506+
int32_t LAN8670_Get_Link_State(lan8670_t *lan, bool *link_up)
486507
{
487508
uint32_t link_status = 0;
488509

0 commit comments

Comments
 (0)