-
Notifications
You must be signed in to change notification settings - Fork 2.1k
drivers/slipmux: Rework SLIPDEV driver in preparation for Unicoap #21907
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
base: master
Are you sure you want to change the base?
Conversation
| while (1) { | ||
| event_t *event = event_wait(&queue); | ||
| event->handler(event); | ||
| } |
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.
This whole event queue contraption is rather odd but it will fit nicely with unicoap, trust me bro.
Murdock results❌ FAILED 376fd64 move module ifdef/is_used into helper functions Build failures (14)
Test failures (1)
Artifacts |
crasbe
left a comment
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.
Just some basic style and nitpick comments for now.
Also the static test has some ideas and you sometimes added yourself in the Copyright and sometimes in the Doxygen authorship, but not really consistently yet 🤔
| PSEUDOMODULES += slipdev_stdio | ||
| PSEUDOMODULES += slipdev_config | ||
| PSEUDOMODULES += slipdev_l2addr |
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.
We don't need these modules as slipmux_ PSEUDOMODULES anymore?
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.
We still do! And this actually one of the major reasons for this rewrite/refactoring: The ability to select _stdio or _coap (used to be _config) without having to use _net (used to not exist and was always included in the base slipdev)
The definitions moved into Makefile.include. I can't remember why I decided to move them out of the global pseudomodules.inc.mk. Either a mistake or some deeper reasoning? Will see in a bit.
Way too early :p but thanks anyways, I adopted the fixes.
Probably. I wasn't done-enough yet, to look at them.
No care was given to that yet. |
9e542dd to
33e529a
Compare
|
I think this is ready for actual review now. I would appreciate feedback specifically on the mutex handling. I am not super proud of it. |
|
If you want to, you can squash before the reviews start pouring in 🤔 |
a64fda5 to
25826ef
Compare
mguetschow
left a comment
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.
Great stuff! ❤️ Unfortunately it was a bit hard to review since Github didn't properly display the file renames (separate commit would have helped).
I've got mostly nitpicky things and haven't tested this yet.
Also Murdock fails because you probably have to change the Kconfig include from slipdev to slipmux somewhere.
| #if IS_USED(MODULE_SLIPMUX_NET_L2ADDR) | ||
| case NETOPT_ADDRESS_LONG: | ||
| assert(max_len == sizeof(eui64_t)); | ||
| netdev_eui64_get(netdev, value); | ||
| return sizeof(eui64_t); | ||
| #endif |
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.
What about this is slipmux-specific? why not use a generic l2addr module? I have the feeling there was some, maybe I'm wrong.
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.
No idea, I honestly didn't question it. It works tho! Tested it! :P
| /drivers/si70xx/ @basilfx | ||
| /drivers/slipdev/ @miri64 | ||
| /drivers/sx127x/ @aabadie @jia200x |
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.
| /drivers/si70xx/ @basilfx | |
| /drivers/slipdev/ @miri64 | |
| /drivers/sx127x/ @aabadie @jia200x | |
| /drivers/si70xx/ @basilfx | |
| /drivers/slipmux/ @Teufelchen1 | |
| /drivers/sx127x/ @aabadie @jia200x |
:P
mguetschow
left a comment
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.
Forgot the most important file :P
| if (len <= 0) { | ||
| return; |
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.
some DEBUG messages wouldn't harm :)
|
Btw, while editing the title I was thinking: does this really belong to |
Thanks!
Yes, I realized too late that this approach was shit (sorry!).
I don't know. 🙈 |
|
@mguetschow you are going to hate me 🙈
I did it again! (sort of) |
mguetschow
left a comment
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'm not 100% sure I'm happy with slipmux being an alias for all of the submodules. Is that common practice in RIOT? e.g. gnrc uses gnrc_default for such default configurations. But I won't die on that hill either.
| case SLIPMUX_STATE_SLEEP: | ||
| /* do nothing if we are supposed to sleep */ | ||
| /* and we should usually not be able to hit this case anyways */ | ||
| assert(0); |
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.
Is this really something we cannot recover from? Can it really only happen by programmer mistake?
| if (byte == SLIPMUX_END) { | ||
| dev->state = SLIPMUX_STATE_NONE; |
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.
Could it be that we need to handle escape end here?
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.
No. There is no need to handle escaping in data that we are not storing or processing in anyway.
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.
Well, but then an escaped END could be mistaken for a real one. But I guess we are in a bad situation anyway in this case, and might just hope for the best when encountering the first END?
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.
An escaped END(0xdb 0xdc) is not an END (0xC0)! It will not match / be mistaken.
| # enable stdout buffering for modules that benefit from sending out buffers in larger chunks | ||
| ifneq (,$(filter picolibc,$(USEMODULE))) | ||
| ifneq (,$(filter stdio_cdc_acm stdio_ethos slipmux_stdio stdio_semihosting stdio_tinyusb_cdc_acm,$(USEMODULE))) | ||
| ifneq (,$(filter stdio_cdc_acm stdio_ethos slipmux slipmux_stdio stdio_semihosting stdio_tinyusb_cdc_acm,$(USEMODULE))) |
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.
Hum, it's a bit unfortunate to add slipmux here, next to slipmux_stdio. Why would slipmux not just enable all three?
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.
This line does not enable modules but check which modules are enabled? I am a bit confused what your comment means.
Why would
slipmuxnot just enable all three?
It does? Just not in this file.
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.
Why would
slipmuxnot just enable all three?It does? Just not in this file.
Okay, sorry for the confusing comment. Let me rephrase: If slipmux enables all other three slipmux_* and in particular slipmux_stdio, why is it not enough to test for slipmux_stdio here and you have to explicitly test for slipmux?
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.
Because that expansion of slipmux into _net _coap _stdio happens in the drivers folder. Which is after stdio.inc.mk got evaluated. So you don't have access to that expansion yet. This means you have to check for both options that use the stdio eventually.
cc @benpicco
This is also why I did not fix the stupid name issue: Stdio modules usually are named stdio_%, only slipdev/slipmux disregard that. Having stdio_slipmux, slipmux_net and slipmux_coap makes little sense either. But i can not just set an alias because the alias would be evaluated too late as well.
To fix that, I would have to escalate this and handle the dependency resolution / name aliasing in RIOT/Makefile.dep . Possible, but also something that I try to avoid, touching the "master" files is a last resort. Personally I think the draw back in stdio.inc.mk is a fair trade for having the entire rest of "slipmux-dependency-logic" inside the slipmux module.
| if (IS_USED(MODULE_SLIPDEV)) { | ||
| extern void auto_init_slipdev(void); | ||
| auto_init_slipdev(); | ||
| } |
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.
Why could you remove this?
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.
It was not in use and hence got removed.
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.
Ah, and slipmux is now initialized via AUTO_INIT(slipmux_init, 0); in drivers/slipmux_dev/slipmux.c? And that is sufficient for GNRC, just LWIP sill needs an explicit slipmux initialization in pkg/lwip/init_devs/auto_init_slipmux.c?
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. Thats also why the priority is 0. So slipmux is done with the setup once lwip comes around and wants to do stuff with it.
drivers/slipmux_dev/slipmux.c
Outdated
| dev->state = SLIPMUX_STATE_NONE; | ||
| break; | ||
| default: | ||
| #if IS_USED(MODULE_SLIPMUX_STDIO) |
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 think I actually like this approach, makes the FSM code more readible as a side-effect :)
| #define SLIPDEV_STACKSIZE (THREAD_STACKSIZE_DEFAULT - 128) | ||
| #ifndef SLIPDEV_PRIO | ||
| # define SLIPDEV_PRIO (GNRC_NETIF_PRIO) | ||
| #endif |
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 think this is still open?
| $(info $(_give_space) You selected the submodule(s) `$(_SUBMODS)` manually in USEMODULE together with the module `slipmux`.) | ||
| $(info $(_give_space) The module `slipmux` enables all submodules by default.) |
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.
Do we really need this warning? slipmux is a new module name, right? So I would say it is sufficient to explicitly mention that fact in the documentation and rely on the user reading that (if they don't, well, their fault).
This would remove the rather complex-looking if cascade here :P
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.
Do we really need this warning?
No, it is a warning hence it is not strictly needed. But that is true for all warnings.
So I would say it is sufficient to explicitly mention that fact in the documentation and rely on the user reading that (if they don't, well, their fault).
Hm not sure. This module is indeed a bit odd and having a warning is rather cheap.
This would remove the rather complex-looking if cascade here :P
Hey, at least it is well documented and it's only complex-looking, not actually complex. :p
Yes I am also not 100% happy. I could go and rename the driver back to |
| @@ -1,5 +1,6 @@ | |||
| STDIO_MODULES = \ | |||
| slipdev_stdio \ | |||
| slipmux_stdio \ | |||
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.
If you do cause an API break here, you might as well make it consistent with the other stdio_% modules.
How about adding a
ifneq (,$(filter slipdev_stdio,$(USEMODULE)))
USEMODULE += stdio_slipmux
endif
so you don't silently break applications that use that?
Our main use case for the So if (Arg, but then you'd also have to provide |
benpicco
left a comment
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 do wonder a bit if we will see CoAP over USB next since a lot of the newer dev boards use stdio_cdc_acm 🤔
|
|
||
| # select default stdio provider if no other is selected | ||
| ifeq (,$(filter stdio_% slipdev_stdio,$(USEMODULE))) | ||
| ifeq (,$(filter stdio_% slipmux_stdio slipmux,$(USEMODULE))) |
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.
Why separately test for slipmux?
| netdev_register(&dev->netdev, NETDEV_SLIPDEV, index); | ||
|
|
||
| #if IS_USED(MODULE_GNRC) | ||
| gnrc_netif_raw_create(&_netif[index], _slipdev_stacks[index], SLIPDEV_STACKSIZE, |
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.
Why is this happening here now?
We used to keep networking stack specific code out of the drivers.
Contribution description
Hey hey 🦭
This refactors the current
slipdevdriver heavily and also renames it toslipmux.The networking aspect (plain
slip) is no longer the default but a submodule:slipmux_net.The "configuration" aspect (coap via uart) is no longer called
slipdev_configbutslipmux_coap. That moves it further from the slipmux draft but (I hope) closer to the average developer and sets the expectations clearer.Same for diagnostic but there it was already called
_stdiowhich was retained.There is a new "overall" module called
slipmuxwhich enables all three modes (slipmux_stdio,_coapand_net) for full slipmux functionality.The parser behavior got a slight change and differentiates between unknown frame types and IPv4/6 frames now. This should make it more robust when interfacing slipmux instead of slip. (Worry not, our slip tools still work as expected)
In addition, the coap handling got reworked to be ready for plug & play action with unicoap once #21582 is merged.
Testing procedure
Pick one of our examples that offer slip e.g.
examples/networking/gnrc/border_router/and see that it still behaves as advertised in the README. tl;dr:See the
slipdevthread running (pid 2) and then try to ping the border router from your linux console: