Skip to content

Commit

Permalink
drivers: eth: e1000: Use double with PTP clock
Browse files Browse the repository at this point in the history
Instead of mixing floats and doubles, convert the code to
use double so that we avoid float->double conversion warning
from compiler.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
  • Loading branch information
jukkar authored and nashif committed Jun 29, 2024
1 parent c95f61f commit 3b72fe5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions drivers/ethernet/eth_e1000.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,27 +371,27 @@ static int ptp_clock_e1000_rate_adjust(const struct device *dev, double ratio)
float val;

/* No change needed. */
if (ratio == 1.0f) {
if (ratio == 1.0) {
return 0;
}

ratio *= context->clk_ratio;

/* Limit possible ratio. */
if ((ratio > 1.0f + 1.0f/(2 * hw_inc)) ||
(ratio < 1.0f - 1.0f/(2 * hw_inc))) {
if ((ratio > 1.0 + 1.0/(2.0 * hw_inc)) ||
(ratio < 1.0 - 1.0/(2.0 * hw_inc))) {
return -EINVAL;
}

/* Save new ratio. */
context->clk_ratio = ratio;

if (ratio < 1.0f) {
if (ratio < 1.0) {
corr = hw_inc - 1;
val = 1.0f / (hw_inc * (1.0f - ratio));
} else if (ratio > 1.0f) {
val = 1.0 / (hw_inc * (1.0 - ratio));
} else if (ratio > 1.0) {
corr = hw_inc + 1;
val = 1.0f / (hw_inc * (ratio - 1.0f));
val = 1.0 / (hw_inc * (ratio - 1.0));
} else {
val = 0;
corr = hw_inc;
Expand Down
2 changes: 1 addition & 1 deletion drivers/ethernet/eth_e1000_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct e1000_dev {
uint8_t rxb[NET_ETH_MTU];
#if defined(CONFIG_ETH_E1000_PTP_CLOCK)
const struct device *ptp_clock;
float clk_ratio;
double clk_ratio;
#endif
};

Expand Down

0 comments on commit 3b72fe5

Please sign in to comment.