drivers/ltc4150: (Re-)implemented driver for the LTC4150 coulomb counter#10755
drivers/ltc4150: (Re-)implemented driver for the LTC4150 coulomb counter#10755miri64 merged 11 commits intoRIOT-OS:masterfrom
Conversation
|
Before you start to review: Let me fix the missing doc Travis complained about and squash |
|
I'm aware that commit "tests/driver_ltc4150: Workarround for msp430" could be squashed into commit "tests: Added test for ltc4150 driver". But I would actually prefer to keep them separated: That commit did not fix a bug in the test, but was a workarround for a bug in the msp430 toolchain (the missing fputs). Once the c lib of the msp430 toolchain gains support for fputs, it can be safely reverted to make the test source code shorter and more readable. For that reason I would like to keep that commit separate. |
|
@MichelRottleuthner: Could you kindly do the testing? I think @smlng does not have a MSB-A2 board at hand (but I'm not sure). |
|
I believe @MichelRottleuthner doesn't have one either, but I have 8 ;-). Once the fundamentals and and code design are cleared (e.g. by @MichelRottleuthner or @smlng) I'm happy to test this PR. |
drivers/ltc4150/ltc4150.c
Outdated
| return -EINVAL; | ||
| } | ||
|
|
||
| memset(dev, 0x00, sizeof(ltc4150_dev_t)); |
There was a problem hiding this comment.
Could you elaborate on that?
#10751 is about a potential security issue when sensitive data should be cleared but the compiler optimized out zeroing out the data. In this case it would be no problem at all if the compiler detects that e.g. dev->params is overwrite one line later anyway and skips zeroing out that data. And #10728 is about the use of memcpy, not about memset().
I would say this is a textbook example for when to use memset(): When you want to bring a structure into a defined state before using it. One could also using something like:
dev->params = *params;
dev->start_sec = 0;
dev->charged = 0;
dev->discharged = 0;But what happens when the structure is extended by one member? Using memset() would still work fine to initialize the whole structure, but the above could would only initialize parts of the struct.
There was a problem hiding this comment.
yep, true that ... leave as is.
However, please be consistent and style/usage, i.e. here you write memset(..., 0x00 ...) and below memset(..., 0, ...) ... I think the latter is nicer.
There was a problem hiding this comment.
However, please be consistent and style/usage, i.e. here you write memset(..., 0x00 ...) and below memset(..., 0, ...) ... I think the latter is nicer.
+1
| #define LTC4150_PARAM_SHUTDOWN (GPIO_PIN(0, 5)) | ||
| #endif | ||
| #ifndef LTC4150_PARAM_PULSES | ||
| #define LTC4150_PARAM_PULSES (45700) |
There was a problem hiding this comment.
didn't we agree on adding (at least) a U suffix in the previous PR?
drivers/ltc4150/ltc4150.c
Outdated
| ltc4150_dev_t *dev = _dev; | ||
|
|
||
| if ( | ||
| (dev->params.polarity == GPIO_UNDEF) || |
There was a problem hiding this comment.
personally I would not put this on a new line, as the indention stays the same, hence I think its fine to write this as:
if ((dev->params.polarity == GPIO_UNDEF) ||
(!gpio_read(dev->params.polarity))) {
|
@maribu just a remark: if you use the commit summary |
miri64
left a comment
There was a problem hiding this comment.
Tests work as expected, though I was confused due to text speaking about drawn charges, while the "Charging" column was raising constantly.
Ohh! Let me check |
|
@miri64: Fixed :-) I put the values in the wrong columns |
|
OK, this makes more sense, but my confusion stemmed more from the fact, that I connect "more power" with "more charge drawn", but that obviously isn't what the text meant (especially since it stresses "The expected result is that the required current increases with the system load". However, just from the stable I'm still not able to see exactly when the current is supposed to raise. Maybe add another Whenever the corresponding minute has passed? |
|
(I intentionally didn't look at the test's code yet) |
|
@miri64: I added the line between load levels and tried to make the description clearer. |
|
Ok, now I can see the raising current clearer. Maybe add a hint, that it is the right column the tester is supposed to look at. Also just from the description it wasn't clear to me, that the test cycles and not just ends after the 3rd level. |
|
@miri64: Addressed :-) |
|
I hadn't looked at the code as much, just tested and my comments were addressed. So I'm fine with squashing as well. |
|
(you should wait for @smlng's go though) |
|
@smlng: May I squash? |
|
sure, please squash |
The shell handlers of the old, depreciated and removed LTC4150 driver are still in place. This commit removes them
The LTC4150 is a coulomb counter (a.k.a. battery sensor or bidirectional current sensor) that is used in the MSBA2 board and available for little money as easy to use break out board.
Implemented an example `ltc4150_recorder_t` implementation as a proof of concept for the recorder API.
The msp430 toolchain is missing an `fputs()` implementation. This commit makes
them use the `printf("%s", str);` instead of `fputs(str, stdout);`, which is
semantically equivalent (but has more overhead).
|
Hmm, the "force-pushed" link is not clever enough to filter out changes due to rebasing against current master. I still have a back up here https://github.com/maribu/RIOT/tree/ltc4150-new-prior-squash for reference, which is neither squashed nor rebased (in other words: Contains the state prior force push). |
That's why I usually just squash (i.e. make a rebase against the merge-base with master) if it is not absolutely necessary [to rebase]. It's not about cleverness. The link is just an HTML-ized version of |
If merging of the old state into upstream can be done automatically, this approach would need to be only slightly adapted to be more clever: Use |
|
Welp, that's for @github to resolve ;-) |
|
Re-run the tests. Still working. |
|
@miri64, @MichelRottleuthner, @smlng: Thank you very much for your valuable feedback :-) |
Contribution description
This PR implements a driver for the LTC4150 coulomb counter. A driver for that device was previously part for RIOT, but was dropped because of quality shortcomings. This driver is written from scratch.
Testing procedure
The LTC4150 is integrated in the MSB-A2 board, thus using that board will be most convenient to use for testing. However, this chip is also cheaply available as breakout board from various vendors, which all seem to be based on the same open hardware PCB.
Testing:
tests/driver_ltc4150on the MSB-A2. I intended the program to be self-explaining - so I will not provide more information here to see if I indeed reached that goalexample/default. Try to read the data using thesaulshell commandIssues/PRs references
This PR competes with PR #9653 also opened by me. I personally favor this PR strongly over the old approach.