Skip to content

Commit fcde134

Browse files
Added more plca()
1 parent adad058 commit fcde134

2 files changed

Lines changed: 69 additions & 19 deletions

File tree

general/include/lan8670.h

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int lan8670_reset(lan8670_t *lan); // Performs a software reset of the LAN8670 E
4747
*
4848
* @param lan Pointer to the lan8670_t instance.
4949
* @param setting true to enable loopback mode, false to disable it.
50-
* @return 0 on success, or a non-zero error code from the read/write operations.
50+
* @return 0 on success, or a non-zero error code.
5151
*/
5252
int lan8670_loopback(lan8670_t *lan, bool setting); // Enables or disables loopback mode on the LAN8670.
5353

@@ -59,15 +59,15 @@ int lan8670_loopback(lan8670_t *lan, bool setting); // Enables or disables loopb
5959
*
6060
* @param lan Pointer to the lan8670_t instance.
6161
* @param setting true to enable low power mode, false to disable it.
62-
* @return 0 on success, or a non-zero error code from the read/write operations.
62+
* @return 0 on success, or a non-zero error code.
6363
*/
6464
int lan8670_low_power_mode(lan8670_t *lan, bool setting); // Enables or disables the LAN8670's low power mode.
6565

6666
/**
6767
* @brief Electrically isolates the LAN8670 from MII/RMII.
6868
* @param lan Pointer to the lan8670_t instance.
6969
* @param setting true to isolate the device, false for normal operation.
70-
* @return 0 on success, or a non-zero error code from the read/write operations.
70+
* @return 0 on success, or a non-zero error code.
7171
*/
7272
int lan8670_isolate(lan8670_t *lan, bool setting); // Electrically isolates the LAN8670 from MII/RMII.
7373

@@ -80,28 +80,69 @@ int lan8670_isolate(lan8670_t *lan, bool setting); // Electrically isolates the
8080
*
8181
* @param lan Pointer to the lan8670_t instance.
8282
* @param setting true to enable collision test mode, false to disable it.
83-
* @return 0 on success, or a non-zero error code from the read/write operations.
83+
* @return 0 on success, or a non-zero error code.
8484
*/
8585
int lan8670_collision_test(lan8670_t *lan, bool setting); // Enables or disables the LAN8670's collision test mode.
8686

8787
/**
8888
* @brief Detects jabber condition on the LAN8670.
8989
* @param lan Pointer to the lan8670_t instance.
9090
* @param jabber_status Pointer to a boolean variable to store the jabber status.
91-
* @return 0 on success, or a non-zero error code from the read operation.
91+
* @return 0 on success, or a non-zero error code.
9292
*/
9393
int lan8670_detect_jabber(lan8670_t *lan, bool *jabber_status); // Detects jabber condition on the LAN8670.
9494

95+
/**
96+
* @brief Enables or disables collision detection on the LAN8670.
97+
* @param lan Pointer to the lan8670_t instance.
98+
* @param setting true to enable collision detection, false to disable it.
99+
* @return 0 on success, or a non-zero error code.
100+
*/
101+
int lan8670_collision_detection(lan8670_t *lan, bool setting);
102+
95103
/**
96104
* @brief Enables or disables Physical Layer Collision Avoidence (PLCA).
97105
*
98-
* Note: When PLCA is enabled on a properly configured mixing segment, no collisions should occur
99-
* on the physical layer. It is therefore recommended to disable physical layer collision detection to
100-
* achieve a higher level of noise tolerance.
106+
* Note: When PLCA is enabled, collision detection should be disabled.
107+
* This can be done using the lan8670_collision_detection() function.
108+
* (See page 141 of the datasheet for more information.)
101109
*
102110
* @param lan Pointer to the lan8670_t instance.
103111
* @param setting true to enable PLCA, false to disable it.
104-
* @return 0 on success, or a non-zero error code from the read/write operations.
112+
* @return 0 on success, or a non-zero error code.
105113
*/
106-
int lan8670_plca(lan8670_t *lan, bool setting);
114+
int lan8670_plca_on(lan8670_t *lan, bool setting);
115+
116+
/**
117+
* @brief Resets the PLCA reconciliation sublayer.
118+
*
119+
* @param lan Pointer to the lan8670_t instance.
120+
* @return 0 on success, or a non-zero error code.
121+
*/
122+
int lan8670_plca_reset(lan8670_t *lan);
123+
124+
/**
125+
* @brief Configures the maximum number of nodes supported on the multidrop network.
126+
*
127+
* Proper operation requires that this field be set to at least the
128+
* number of nodes that may exist on the network.
129+
*
130+
* @param lan Pointer to the lan8670_t instance.
131+
* @param node_count The number of nodes on the network.
132+
* @return 0 on success, or a non-zero error code.
133+
*/
134+
int lan8670_plca_set_node_count(lan8670_t *lan, uint8_t node_count);
135+
136+
/**
137+
* @brief Sets the ID of the PLCA node.
138+
*
139+
* This ID must be unique for each node on the network.
140+
* The ID for the controller node must be 0.
141+
*
142+
* @param lan Pointer to the lan8670_t instance.
143+
* @param id The ID of the PLCA node (0-31).
144+
* @return 0 on success, or a non-zero error code.
145+
*/
146+
int lan8670_plca_set_node_id(lan8670_t *lan, uint8_t id);
147+
107148
// clang-format on

general/src/lan8670.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#include <stdio.h> // Used for debug()
1212
#include <stdarg.h> // Used for debug()
13-
#include <assert.h> // Used for compile-time checks
1413

1514
/* SMI Registers */
1615
#define REG_BASIC_CONTROL 0x00 // Basic Control Register. (Datasheet pgs. 63-64)
@@ -449,27 +448,37 @@ int lan8670_collision_test(lan8670_t *lan, bool setting)
449448

450449
int lan8670_detect_jabber(lan8670_t *lan, bool *jabber_status)
451450
{
452-
// Read bit 1 of the Basic Status Register to 'jabber_status'. If it's 1, jabber is detected.
451+
// Read bit 1 of the Basic Status Register to 'jabber_status'.
453452
return read_register_field(lan, REG_BASIC_STATUS, 1, 1, jabber_status);
454453
}
455454

456-
int lan8670_plca_reset(lan8670_t *lan)
457-
{
458-
// Set bit 14 in the PLCA Control 0 Register, and clear all other bits.
459-
// This starts a software reset of the PLCA reconciliation sublayer.
460-
return mmd_write_register(lan, MMD_MISC, MISC_PLCA_CTRL0, 0x4000);
455+
int lan8670_collision_detection(lan8670_t *lan, bool setting) {
456+
// Modify bit 15 of the Collision Detector Control 0 Register to whatever 'setting' is.
457+
return mmd_write_register_field(lan, MMD_MISC, MISC_CDCTL0, 15, 15, setting);
461458
}
462459

463-
int lan8670_plca(lan8670_t *lan, bool setting)
460+
int lan8670_plca_on(lan8670_t *lan, bool setting)
464461
{
465462
// Set/clear bit 15 of the PLCA Control 0 Register to whatever 'setting' is.
466463
return mmd_write_register_field(lan, MMD_MISC, MISC_PLCA_CTRL0, 15, 15, setting);
467464
}
468465

466+
int lan8670_plca_reset(lan8670_t *lan)
467+
{
468+
// Set bit 14 in the PLCA Control 0 Register, and clear all other bits.
469+
// This starts a software reset of the PLCA reconciliation sublayer.
470+
return mmd_write_register(lan, MMD_MISC, MISC_PLCA_CTRL0, 0x4000);
471+
}
472+
469473
int lan8670_plca_set_node_count(lan8670_t *lan, uint8_t node_count)
470474
{
471-
// Set bits 8-15 of the PLCA Control 1 Register to whatever 'node_count' is.
475+
// Modify bits 8-15 of the PLCA Control 1 Register to whatever 'node_count' is.
472476
return mmd_write_register_field(lan, MMD_MISC, MISC_PLCA_CTRL1, 8, 15, node_count);
473477
}
474478

479+
int lan8670_plca_set_node_id(lan8670_t *lan, uint8_t id)
480+
{
481+
// Modify bits 0-7 of the PLCA Control 1 Register to whatever 'id' is.
482+
return mmd_write_register_field(lan, MMD_MISC, MISC_PLCA_CTRL1, 0, 7, id);
483+
}
475484
// clang-format on

0 commit comments

Comments
 (0)