Skip to content
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

pkg/semtech-loramac: rework interaction with the MAC #11541

Merged
merged 8 commits into from
May 29, 2019

Conversation

aabadie
Copy link
Contributor

@aabadie aabadie commented May 17, 2019

Contribution description

This is another attempt to fix #11530.
It follows the suggestion of @ParksProjets in #11535 (comment):

  • TX status is now only reported after an mcps confirm event
  • RX data are notified from mcps indication events
  • one needs an external thread to receive data from the MAC. This is much simpler but it consume a little more RAM if one wants to manage downlinks message outside of the MAC. The bonus point with this approach is the ability to correctly support class C devices.

I have tested this PR using OTAA, ABP activations and with CONFIRMED and UNCONFIRMED messages.

Everything is working as expected.

The only small thing is the link check which is not working correctly but it's already the case in master I think.

Finally, I also had to update the examples/lorawan application and doxygen documentation to avoid potential lock of autonomous application. Maybe examples/lorawan could be later refactored with downling messages better handled or adapted for class C devices.

Testing procedure

Run tests/pkg_semtech-loramac, send messages from the device, send messages from the network using CONFIRMED/UNCONFIRMED (cnf/uncnf option of loramac tx: everything should work, with this PR, the application doesn't block.

Issues/PRs references

fixes #11530, closes #11535 (cleaner alternative)

@aabadie aabadie added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Area: LoRa Area: LoRa radio support labels May 17, 2019
@aabadie aabadie requested a review from jia200x May 17, 2019 10:08
@aabadie aabadie force-pushed the pr/pkg/semtech-loramac-rx-thread branch from 5344c0e to f6290f3 Compare May 20, 2019 13:07
@aabadie aabadie requested a review from fjmolinas May 23, 2019 13:55
Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some initial comments.

@@ -839,7 +837,7 @@ uint8_t semtech_loramac_send(semtech_loramac_t *mac, uint8_t *data, uint8_t len)
return SEMTECH_LORAMAC_NOT_JOINED;
}

/* Correctly set the caller pid */
/* Correctly set the sender thread pid */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the comment should be inline with the variable names.

@@ -110,6 +110,7 @@ typedef struct {
typedef struct {
mutex_t lock; /**< loramac access lock */
uint8_t caller_pid; /**< pid of caller thread */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it makes more sense if this is tx_pid if I understand right this thread is in charge of join procedure and sending packets, so tx. Would be more inline with rx_pid (receiver thread)

tests/pkg_semtech-loramac/main.c Outdated Show resolved Hide resolved
@@ -95,12 +95,6 @@
* return 1;
* }
*
* /* 5. wait for any potentially received data */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document starting and usage of a receiving thread.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@fjmolinas
Copy link
Contributor

Tested it does work and no deadlock, I confirm it fixes #11530. @ParksProjets can you confirm it fixes the issue on your side?

@aabadie
Copy link
Contributor Author

aabadie commented May 24, 2019

@fjmolinas, I found a problem with the link_check feature. The current refactoring is breaking it. I know how to fix it simply but now that I'm thinking of it, I'd like to try a deeper refactoring of the interaction between the MAC events (MCPS confirm/indication, MLME confirm/indication) and the event loop. I hope this will simplify a bit more all this mess.

@aabadie
Copy link
Contributor Author

aabadie commented May 24, 2019

@fjmolinas, I've reworked this the PR the way we discussed IRL and now everything is working (including link_check info and received ACKs).

@aabadie aabadie changed the title pkg/semtech-loramac: rework TX/RX interaction with the MAC pkg/semtech-loramac: rework interaction with the MAC May 24, 2019
Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested that your changes regarding link_check and ack are working. A minor comment on a border case.

* }
* ```
* - Finally, this thread can be started after the join procedure
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a requirement?

_semtech_loramac_send(mac, NULL, 0);
mac->port = prev_port;
}
else if (indication->RxData) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a border case where if a downlink is received when a cnf messaged is sent the indication-AckReceived doesn't go up to the application. Although this doesn't matter in class A, in class B or C this could be mixed. If using if instead of elseif this would work

@aabadie aabadie force-pushed the pr/pkg/semtech-loramac-rx-thread branch from 90d8087 to 79fca24 Compare May 28, 2019 16:13
Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aabadie Everyhting is looking good. I see all my comments have been addressed, can you squas?

tests/pkg_semtech-loramac/main.c Outdated Show resolved Hide resolved
@aabadie aabadie force-pushed the pr/pkg/semtech-loramac-rx-thread branch from 79fca24 to d7737a5 Compare May 29, 2019 07:08
@aabadie
Copy link
Contributor Author

aabadie commented May 29, 2019

I see all my comments have been addressed, can you squash?

Done!

@aabadie
Copy link
Contributor Author

aabadie commented May 29, 2019

Note that this PR will conflicts with #8855 once merged but I prefer this one being merged first.

@fjmolinas
Copy link
Contributor

@aabadie somehow before the squash I oversaw that waspmote doesn't fit anymore. I still think this is a good change but reducing supported boards doesn't seem great. Anyway for reducing stack-sizes for constrained boards? Or removing features from the test for constrained boards?

@fjmolinas
Copy link
Contributor

Note that this PR will conflicts with #8855 once merged but I prefer this one being merged first.

Noted!

@aabadie
Copy link
Contributor Author

aabadie commented May 29, 2019

Anyway for reducing stack-sizes for constrained boards? Or removing features from the test for constrained boards?

I think I already tried both:

  • reducing stack size was somehow crashing sometimes
  • removing features: I tried to make link_check optional but it was not enough.

For me it's a problem of missing RAM, and waspmote was already very short. Adding a second thread is too much for it.

@aabadie
Copy link
Contributor Author

aabadie commented May 29, 2019

What about simply disabling RX thread ?

@fjmolinas
Copy link
Contributor

What about simply disabling RX thread ?

I think that would be an acceptable compromise. The previous support had a bug so if fixing it adds some memory usage then I think it's okay to drop some feature support for waspmote, which was already buggy in master. :)

@aabadie aabadie force-pushed the pr/pkg/semtech-loramac-rx-thread branch 4 times, most recently from 79d5fac to 8003567 Compare May 29, 2019 08:28
@aabadie aabadie force-pushed the pr/pkg/semtech-loramac-rx-thread branch from 8003567 to c721efe Compare May 29, 2019 08:29
@aabadie
Copy link
Contributor Author

aabadie commented May 29, 2019

@fjmolinas, I made all RX related code optional using a pseudo-module semtech_loramac_rx. Link check is also excluded because it relies on RX.

@aabadie aabadie force-pushed the pr/pkg/semtech-loramac-rx-thread branch from c721efe to 9da50dd Compare May 29, 2019 08:40
@fjmolinas
Copy link
Contributor

fjmolinas commented May 29, 2019

@aabadie everything is good! This commit need to be discarded though tests/pkg_semtech-loramac: waspmote-pro doesn't fit anymore. Once that is done, we are all good!

@aabadie aabadie force-pushed the pr/pkg/semtech-loramac-rx-thread branch from 9da50dd to 56fb257 Compare May 29, 2019 14:25
@aabadie
Copy link
Contributor Author

aabadie commented May 29, 2019

This commit need to be discarded though

Done!

Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK! Lets wait for murdock ot be green!

@fjmolinas
Copy link
Contributor

Go!

@fjmolinas fjmolinas merged commit ba84ad4 into RIOT-OS:master May 29, 2019
@aabadie
Copy link
Contributor Author

aabadie commented May 29, 2019

Great! Thanks a lot for reviewing @fjmolinas :)
Now I have to rebase the other ones ;)

@aabadie aabadie deleted the pr/pkg/semtech-loramac-rx-thread branch May 30, 2019 16:40
fjmolinas added a commit to fjmolinas/RIOT that referenced this pull request Jul 19, 2019
- with RIOT-OS#11541 TX notification are only sent after mcps confirm event
  this will send a SEMTECH_LORAMAC_TX_DONE instaed of
  SEMTECH_LORAMAC_TX_OK.
fjmolinas added a commit to fjmolinas/RIOT that referenced this pull request Jul 19, 2019
- with RIOT-OS#11541 TX notification are only sent after mcps confirm event
  this will send a SEMTECH_LORAMAC_TX_DONE instead of
  SEMTECH_LORAMAC_TX_OK.
fjmolinas added a commit to fjmolinas/RIOT that referenced this pull request Jul 19, 2019
- with RIOT-OS#11541 TX notification are only sent after mcps confirm event
  this will send a SEMTECH_LORAMAC_TX_DONE instead of
  SEMTECH_LORAMAC_TX_OK.

(cherry picked from commit cdf687c)
fjmolinas added a commit to fjmolinas/RIOT that referenced this pull request Aug 4, 2019
- with RIOT-OS#11541 TX notification are only sent after mcps confirm event
  this will send a SEMTECH_LORAMAC_TX_DONE instead of
  SEMTECH_LORAMAC_TX_OK.
olegart pushed a commit to unwireddevices/RIOT that referenced this pull request Sep 10, 2019
- with RIOT-OS#11541 TX notification are only sent after mcps confirm event
  this will send a SEMTECH_LORAMAC_TX_DONE instead of
  SEMTECH_LORAMAC_TX_OK.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: LoRa Area: LoRa radio support CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pkg/semtech_loramac: deadlock with UNCONFIRMED messages
2 participants