-
Notifications
You must be signed in to change notification settings - Fork 2.1k
drivers: add generic 1-Wire bus driver #14897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
pushed some minor doxygen and test app type fixes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice addition, I have some comments.
0xC2, 0x9C, 0x7E, 0x20, 0xA3, 0xFD, 0x1F, 0x41, | ||
0x00, 0x9D, 0x23, 0xBE, 0x46, 0xDB, 0x65, 0xF8, | ||
0x8C, 0x11, 0xAF, 0x32, 0xCA, 0x57, 0xE9, 0x74 | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess sys/checksum/crc8.c
was too slow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. Or at least I'd like to use this optimized version better then using the slower, generic solution...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO the implementation would still be better placed in sys/checksum
, so that other potential users could also use the implementation.
One could even leave the decision on using the fast or the small CRC8 implementation to the user like this:
static inline uint8_t crc8(const uint8_t *data, size_t len, uint8_t g_polynom, uint8_t seed)
{
if (IS_USED(MODULE_CRC8_FAST) && __builtin_constant_p(g_polynom)) {
switch (g_polynom) {
case CRC8_POLY_DALLAS:
return crc8_dallas(data, len, seed);
}
}
return crc8_generic(data, len, g_polynom, seed);
}
Here the crc8
function would pick the fast implementation over the generic if the module crc8_fast
is used and the value of g_polynom
is known at compile time (which is in all but the most obscure scenarios the case), so that the static inline
function is always replaced with either a call to crc8_generic()
or to the optimized crc implementation for the given polynomial (such as crc8_dallas()
).
addressed comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried the test on avr-rss2
which has a DS18B20 connected to PD7
.
Unfortunately the ATmega GPIO driver does not support GPIO_OD_PU
, but according to the documentation there is a pull-up on the board.
So I tried GPIO_IN
:
2020-08-31 15:29:53,752 # init 3 7 2
2020-08-31 15:29:53,755 # Initializing 1-Wire bus at GPIO_PIN(3, 7)
2020-08-31 15:29:53,760 # 1-Wire bus successfully initialized
2020-08-31 15:32:50,303 # Discovery finished, found 10 devices:
2020-08-31 15:32:50,304 # Dev # - ROM code
2020-08-31 15:32:50,306 # [ 0] 0000000000000000
2020-08-31 15:32:50,309 # [ 1] 0000000000000080
2020-08-31 15:32:50,312 # [ 2] 0000000000000040
2020-08-31 15:32:50,312 # [ 3] 00000000000000C0
2020-08-31 15:32:50,315 # [ 4] 0000000000000020
2020-08-31 15:32:50,318 # [ 5] 00000000000000A0
2020-08-31 15:32:50,320 # [ 6] 0000000000000060
2020-08-31 15:32:50,321 # [ 7] 00000000000000E0
2020-08-31 15:32:50,324 # [ 8] 0000000000000010
2020-08-31 15:32:50,327 # [ 9] 0000000000000090
Hm, just remembered (from
Probably the above is the case for the 'avr-rss2' board?! That would explain the failed device scan. Seems like I have to do some magic as well for the onewire driver?! Damn, not getting this off my hands so easily as it seems... |
I tried
which I can assure you is not correct either. AFAIU xtimer is not suitable for anything that requires exact timings - we'd have to use a dedicated periph timer for that. |
Pretty sure this is because of bad timings on AVR-based hardware... Will add a polling mode as done in the already merged |
If you try to build with |
|
Ok, so much for the quick and dirty fix... Will need to get home (where I have the fitting HW at hand) and see what I broke. Will post an update then. |
Hej,
|
Japp, as said, I screwed up with the quick-port of the polling mode. Need to investigate with HW at hand :-) |
no, its not. Will add a comment in the doc addressing this. |
I'll try to help with that. Can you post a baseline on how much overhead "xtimer_spin()" poses? and maybe also ztimer_spin() (which just landed some days ago). The latter takes at least 3us, but is fairly accurate after that, on nrf52840dk. |
will do once I have the hardware at my hands |
420cf10
to
1a34e63
Compare
Can you try |
Hmm |
Better is seems. ztimer is confusing now... |
ztimer_spin() got merged fairly recently, maybe rebase to master? |
@kaspar030. Yes got it. Will test later... |
Thanks @herjulf! Something seems quite off with ztimer on the arduino, I'll need to debug that. |
@kaspar030. Looking a ztimer... It should be possible to abstract even Mac Symbol Counter I hope? |
is that using timers / bitbanging? or is it using a uart? |
Simplest. bitbanging and busywaiting. DS1820 usually. BTW I forgot to say the MAC Symbol Counter (MSC) is 16uS counts. I can get timer interrupts in RIOT now but it's not connected to anything useful. Also a question... Still traveling for some days... |
onewire_t contains the line |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
This implementation suggests it's also possible to (ab)use UART for this. |
Thanks for pointing this possibility out. But the ultimate solution would be to keep the IRQ latency low. Remember seeing all the pushing and popping of registers for every IRQ. Well we do survive... |
I would like to take over this stale PR. Should I create a new PR, or is there a way to re-open it and assign it to me in such a way that I am edit the branch? |
I can re-open it, but I have no way to assign it to you. So I guess the best is to open a new PR and post a link to that here. |
Yes please share any new links... |
See #18051 |
If I understand correctly, the items that I need to addressed to get this PR merged are:
Have I missed anything? I will use the PR I opened (#18051) to do this work. |
Contribution description
This PR adds a generic driver for interfacing with devices that use the Dallas Integrated 1-Wire bus (e.g. the
ds18b20
temperature sensors). It allows to read/write specific devices, as well as scanning the bus for connected devices and to discover their ROM codes (addresses).I had this code laying around for some years now and finally found some time to clean it up...
A PR for a
ds18b20
device driver based on this PR will be opened separately.Testing procedure
Connect one or more 1-Wire devices (e.g.
ds18b20
sensors) to a board of your choice, flash the included test application (tests/driver_onewire
), and run theinit
anddiscover
shell commands.Issues/PRs references
none