Conversation
|
/AzurePipelines run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
|
/AzurePipelines run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
5513eaa to
94940e7
Compare
|
V2: Rebase to latest main |
3988f35 to
a021cb3
Compare
|
/AzurePipelines run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
a021cb3 to
206c239
Compare
|
V3: Resolve identified Sphinx documentation errors |
|
/AzurePipelines run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
206c239 to
cbda533
Compare
|
V4: Remove diff headers included in max17616.h |
b1687b3 to
39f0f5a
Compare
|
/AzurePipelines run |
|
Commenter does not have sufficient privileges for PR 2734 in repo analogdevicesinc/no-OS |
|
/AzurePipelines run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
drivers/power/max17616/max17616.c
Outdated
| if (ret == 0) | ||
| *value = max17616_direct_to_int(raw_value, | ||
| &max17616_vin_coeffs); |
There was a problem hiding this comment.
error handling be done first, and only do the value conversion if the read was successful
ret = max17616_read_word(dev, MAX17616_CMD(MAX17616_READ_VIN),
&raw_value);
if (ret)
return ret;
*value = max17616_direct_to_int(raw_value,
&max17616_vin_coeffs);
There was a problem hiding this comment.
Thanks. Fixed in latest commit.
drivers/power/max17616/max17616.c
Outdated
| case MAX17616_POWER: | ||
| /* Calculate power from voltage and current */ | ||
| { | ||
| int vin, iout; |
There was a problem hiding this comment.
variable declarations should be moved to top of function
There was a problem hiding this comment.
Thanks. Fixed in latest commit.
drivers/power/max17616/max17616.c
Outdated
| if (ret == 0) | ||
| *value = vin * iout; |
There was a problem hiding this comment.
error handling be done first before processing success case
There was a problem hiding this comment.
Thanks. Fixed in latest commit.
drivers/power/max17616/max17616.c
Outdated
| int ret = max17616_read_byte(dev,MAX17616_CMD(MAX17616_OPERATION), | ||
| &operation); | ||
|
|
||
| if (ret == 0) | ||
| *enabled = (operation & 0x80) ? true : false; |
There was a problem hiding this comment.
Thanks. Fixed in latest commit.
drivers/power/max17616/max17616.c
Outdated
|
|
||
| /* Extract bits 7:6 and convert to enum */ | ||
| switch (raw_value & 0xC0) { | ||
| case 0x00: |
There was a problem hiding this comment.
consider using macros in switch cases
There was a problem hiding this comment.
Thanks. Fixed in latest commit.
drivers/power/max17616/max17616.c
Outdated
|
|
||
| /* Extract bits 3:0 and convert to enum */ | ||
| switch (raw_value & 0x0F) { | ||
| case 0x00: |
There was a problem hiding this comment.
Thanks. Fixed in latest commit.
drivers/power/max17616/max17616.h
Outdated
| MAX17616_STATUS_BIT_GENERAL = 0, // Not supported | ||
| MAX17616_STATUS_BIT_CML = 1, // Comms, memory, or logic Fault | ||
| MAX17616_STATUS_BIT_TEMPERATURE = 2, // Temperature Fault or Warning | ||
| MAX17616_STATUS_BIT_VIN_UV = 3, // Input Under Voltage Fault | ||
| MAX17616_STATUS_BIT_IOUT_OC = 4, // Output Over Current Fault | ||
| MAX17616_STATUS_BIT_VOUT_OV = 5, // An output overvoltage fault occurred | ||
| MAX17616_STATUS_BIT_OFF = 6, // Max17616 is not enabled | ||
| MAX17616_STATUS_BIT_BUSY = 7 // Not supported |
There was a problem hiding this comment.
no need for explicit numbering since enum values are already in correct order
There was a problem hiding this comment.
Thanks. Fixed in latest commit.
drivers/power/max17616/max17616.h
Outdated
| MAX17616_STATUS_BIT_STARTUP = 0, // Not supported | ||
| MAX17616_STATUS_BIT_OTHER = 1, // Not supported | ||
| MAX17616_STATUS_BIT_FANS = 2, // Not supported | ||
| MAX17616_STATUS_BIT_POWER_GOOD = 3, // Not supported | ||
| MAX17616_STATUS_BIT_MFR = 4, // Manufacturer specific Fault | ||
| MAX17616_STATUS_BIT_INPUT = 5, // Input V, I, or P Fault | ||
| MAX17616_STATUS_BIT_IOUT_POUT = 6, // Output current or power Fault | ||
| MAX17616_STATUS_BIT_VOUT = 7 // Output voltage Fault |
There was a problem hiding this comment.
Thanks. Fixed in latest commit.
02d0e3e to
e409f37
Compare
amiclaus
left a comment
There was a problem hiding this comment.
looks good overall, some inline comments.
drivers/power/max17616/max17616.c
Outdated
| uint8_t *data, size_t nbytes) | ||
| { | ||
| int ret; | ||
| uint8_t rxbuf[nbytes + 2]; |
There was a problem hiding this comment.
use a fixed max buffer size/dynamic allocation.
There was a problem hiding this comment.
Fixed buffer size allocation to 256
drivers/power/max17616/max17616.c
Outdated
| { | ||
| uint16_t raw_value; | ||
| int ret; | ||
| float vin, iout; |
There was a problem hiding this comment.
float values are discouraged for no-os drivers.
There was a problem hiding this comment.
Replaced all float instances with uint32_t and adjusted calculations
drivers/power/max17616/max17616.c
Outdated
|
|
||
| case MAX17616_POWER: | ||
| /* Calculate power from voltage and current: P = V × I */ | ||
| ret = max17616_read_value(dev, MAX17616_VOUT, &vin); |
There was a problem hiding this comment.
we store vout or vin here? if vout then use an appropriate naming.
There was a problem hiding this comment.
Used correct parameter
| if (!iio_desc) | ||
| return -ENODEV; | ||
|
|
||
| if (iio_desc->iio_dev) |
There was a problem hiding this comment.
Corrected the struct member to validate
drivers/power/max17616/max17616.h
Outdated
| MAX17616_VIN, /* Input voltage in volts */ | ||
| MAX17616_VOUT, /* Output voltage in volt */ | ||
| MAX17616_IOUT, /* Output current in amps */ | ||
| MAX17616_TEMP, /* Temperature in degreesCelsius */ |
There was a problem hiding this comment.
Placed a space in between
| return -EINVAL; | ||
|
|
||
| return max17616_write_byte(dev, MAX17616_CMD(MAX17616_SET_ISTART_RATIO), | ||
| (uint8_t)istart_ratio); |
There was a problem hiding this comment.
any istart_ratio value is valid?
There was a problem hiding this comment.
Provided the default values as per datasheet in the initialization
drivers/power/max17616/max17616.c
Outdated
| return -EINVAL; | ||
|
|
||
| /* Combine voltage selection (bits 4:2) and PGOOD threshold (bits 1:0) */ | ||
| reg_value = ((uint8_t)voltage << 2) | (uint8_t)threshold; |
There was a problem hiding this comment.
consider using field preparation functions + macros.
There was a problem hiding this comment.
Used no-OS field preparation macros
e409f37 to
f120728
Compare
|
V12
|
f120728 to
709e096
Compare
drivers/power/max17616/max17616.c
Outdated
| * Since R = -1 for all MAX17616 coefficients: | ||
| * X_milli = ((Y x 10 - b) x 1000) / m | ||
| */ | ||
| static float max17616_direct_to_milliunit(uint16_t raw_value, |
There was a problem hiding this comment.
why float if it returns an int32_t ?
There was a problem hiding this comment.
Thanks. This was overlooked. Changed function return with proper data type.
| test_expected_read_length = 2; | ||
| no_os_get_unaligned_le16_ExpectAndReturn(response_data, 0x3040); | ||
|
|
||
| int result = max17616_read_value(&device, MAX17616_VIN, &value); |
There was a problem hiding this comment.
the function expects an int32_t not a float.
There was a problem hiding this comment.
Updated test variable data type in this test case.
| no_os_i2c_read_IgnoreAndReturn(0); | ||
| no_os_get_unaligned_le16_IgnoreAndReturn(0x2000); // IOUT value | ||
|
|
||
| result = max17616_read_value(&device, MAX17616_POWER, &value); |
There was a problem hiding this comment.
Updated test variable data type in this test case.
| float value = 0.0f; | ||
|
|
||
| // Test with NULL device | ||
| int result = max17616_read_value(NULL, MAX17616_VIN, &value); |
There was a problem hiding this comment.
same. please check all occurences where u pass float to a function that expects int32_t
There was a problem hiding this comment.
Updated test variable data type in this test case. Also updated lines 1317, 1325, 1333, and 1524.
| TEST_ASSERT_EQUAL_INT(-EINVAL, result); | ||
|
|
||
| // Test with NULL value pointer | ||
| result = max17616_read_value(&device, MAX17616_VIN, NULL); |
There was a problem hiding this comment.
Updated test variable data type in this test case.
|
|
||
| /* Check reasonable ranges for valid values */ | ||
| if (telemetry->valid_mask & 0x01) { /* VIN */ | ||
| if (telemetry->vin_mv < 0 || telemetry->vin_mv > 1000) { /* 0-100V */ |
There was a problem hiding this comment.
this is a bit unclear. the comment says 100V but your check is for 1000mV
There was a problem hiding this comment.
Updated stale test cases from float to int32_t conversion
| } | ||
|
|
||
| if (telemetry->valid_mask & 0x08) { /* IOUT */ | ||
| if (telemetry->iout_ma < 0 || telemetry->iout_ma > 1000) { /* 0-100A */ |
There was a problem hiding this comment.
Updated stale test cases from float to int32_t conversion
| } | ||
|
|
||
| if (telemetry->valid_mask & 0x02) { /* VOUT */ | ||
| if (telemetry->vout_mv < 0 || telemetry->vout_mv > 500) { /* 0-50V */ |
There was a problem hiding this comment.
Updated stale test cases from float to int32_t conversion
| }, | ||
| { | ||
| .name = "pout", | ||
| .ch_type = IIO_ALTVOLTAGE, |
There was a problem hiding this comment.
shouldn't this be IIO_POWER?
There was a problem hiding this comment.
Corrected channel type for power
| struct max17616_iio_desc *iio_max17616 = (struct max17616_iio_desc *)device; | ||
| struct max17616_telemetry telemetry; | ||
| struct max17616_status status; | ||
| uint16_t raw_value; |
There was a problem hiding this comment.
Removed unused variable
709e096 to
644b67f
Compare
|
V13
|
amiclaus
left a comment
There was a problem hiding this comment.
some comments on my side.
drivers/power/max17616/max17616.c
Outdated
| int max17616_remove(struct max17616_dev *dev) | ||
| { | ||
| int ret; | ||
|
|
There was a problem hiding this comment.
missing NULL check for dev.
There was a problem hiding this comment.
the NULL dev is pre-checked by the calling function (a valid dev is a requirement to call this function)
| if (ret) | ||
| return ret; | ||
|
|
||
| *value_milliunit = (int32_t)(((uint64_t)(uint32_t)vout_mv * |
There was a problem hiding this comment.
do we want here to cat to uint? was looking at max17616_read_telemetry_all which handles stuff with signed integers.
There was a problem hiding this comment.
looking at the max17616_read_telemetry_all, the calculation there needs to follow the cast to uint for proper protection against overflow (resulting to large negative values) calculation. changed calculation in max17616_read_telemetry_all instead
| int max17616_verify_manufacturer_id(struct max17616_dev *dev) | ||
| { | ||
| uint8_t mfr_id[8]; | ||
| int ret; |
There was a problem hiding this comment.
missing NULL validation for dev throughout multiple functions.
There was a problem hiding this comment.
the NULL dev is pre-checked in the init (which is the only function calling these static functions)
| #include <stdbool.h> | ||
| #include <stdlib.h> | ||
| #include <errno.h> | ||
| #include <stdio.h> |
There was a problem hiding this comment.
#include <stdio.h> seems to be redundant.
There was a problem hiding this comment.
true. thanks. removed #include <stdio.h>
| memset(telemetry, 0, sizeof(struct max17616_telemetry)); | ||
|
|
||
| ret = max17616_read_value(dev, MAX17616_VIN, &telemetry->vin_mv); | ||
| if (ret == 0) |
There was a problem hiding this comment.
if (!ret) for all occurences.
There was a problem hiding this comment.
retained (ret == 0) for clarity. it indicates that the function seeks for success. it has become relatively important with the related comment on basic_example.c and corresponding changes
| int value; | ||
| int ret; | ||
|
|
||
| ret = sscanf(buf, "%d", &value); |
There was a problem hiding this comment.
no range validation for value?
There was a problem hiding this comment.
great observation. thanks. added the validation of values range in the driver side so as not be repeated here or other application call (DRY principle).
| * @param priv - Private data identifying which global attribute to write | ||
| * @return Number of bytes written on success, negative error code otherwise | ||
| */ | ||
| STATIC int max17616_iio_write_global_attr(void *device, char *buf, uint32_t len, |
There was a problem hiding this comment.
should we return len in this function?
There was a problem hiding this comment.
yes, i agree. let's follow the write convention call of returning len on a successful write operation and negative values for error.
| if (byte_count != nbytes) | ||
| return -EMSGSIZE; | ||
|
|
||
| memcpy(data, &rxbuf[1], byte_count); |
There was a problem hiding this comment.
it unintentionally not flagged perhaps due to other headers including it but i've explicitly added string.h for correctness
| /* Read telemetry */ | ||
| ret = max17616_read_telemetry_all(max17616_dev, &telemetry); | ||
| if (ret) | ||
| pr_err("Failed to read telemetry: %d\n\r", ret); |
There was a problem hiding this comment.
we should somehow go to exit: for proper cleanup
There was a problem hiding this comment.
looking at max17616_read_telemetry_all, it doesn't really return error worthy of discontinuing the loop. modified the max17616_read_telemetry_all to catch read operation errors so it would warrant an exit and clean up here. great observations. thanks.
drivers/power/max17616/max17616.h
Outdated
| }; | ||
|
|
||
| enum max17616_status_byte { | ||
| MAX17616_STATUS_BIT_GENERAL, // Not supported |
There was a problem hiding this comment.
let's be consistent with comments /* */
There was a problem hiding this comment.
i agree. standardized comments.
644b67f to
d1ebf91
Compare
|
V14
|
amiclaus
left a comment
There was a problem hiding this comment.
minor comments, otherwise lgtm.
| int max17616_send_byte(struct max17616_dev *dev, uint8_t cmd) | ||
| { | ||
| uint8_t tx_buf[2] = {0}; | ||
|
|
There was a problem hiding this comment.
Added dev null check
| uint8_t rx_buf[2]; | ||
| uint8_t tx_buf[2] = {0}; | ||
| tx_buf[0] = cmd; | ||
|
|
There was a problem hiding this comment.
ditto: dev null check missing.
There was a problem hiding this comment.
Added dev null check
drivers/power/max17616/max17616.c
Outdated
| int ret; | ||
|
|
||
| ret = no_os_i2c_remove(dev->i2c_desc); | ||
| if (ret) |
There was a problem hiding this comment.
Ignore error on i2c removal
Add header and source files for max17616 driver. Signed-off-by: Carlos Jones <carlosjr.jones@analog.com>
Signed-off-by: Carlos Jones <carlosjr.jones@analog.com>
Add README.rst documentation file for max17616 alongside other documentation related files. Signed-off-by: Carlos Jones <carlosjr.jones@analog.com>
Add project files for both basic and IIO examples for max17616. Signed-off-by: Carlos Jones <carlosjr.jones@analog.com>
Add README.rst documentation file for project alongside other documentation related files. Signed-off-by: Carlos Jones <carlosjr.jones@analog.com>
Add unit test files for the max17616 driver. Signed-off-by: Carlos Jones <carlosjr.jones@analog.com>
d1ebf91 to
2a9af69
Compare
|
V15
|
Pull Request Description
The MAX17616/MAX17616A offers highly versatile and programmable protection boundaries for systems against input voltage faults and output overcurrent faults. Input-voltage faults (with positive polarity) are protected up to +80V (without Reverse Current Protection)/+75V (with Reverse Current Protection), by an internal nFET featuring low ON-resistance (20mΩ typ). The devices feature a programmable undervoltage-lockout (UVLO) thresholds by using external voltage- dividers. The MAX17616 features a programmable overvoltage-lockout (OVLO) while MAX17616A offers a programmable output voltage clamp function through the OVFB pin that features an output voltage limiting regulation during input transient surge events. Input undervoltage and overvoltage protection (MAX17616)/output voltage clamp function (MAX17616A) can be programmed across the entire 3V to 80V operating range.
PR Type
PR Checklist