pkg/semtech-loramac: refactor API and make it thread-safe#8798
pkg/semtech-loramac: refactor API and make it thread-safe#8798jia200x merged 3 commits intoRIOT-OS:masterfrom
Conversation
4488dd0 to
a82b048
Compare
|
Hi @aabadie Nice approach! |
| if (strcmp("deveui", argv[2]) == 0) { | ||
| uint8_t deveui[LORAMAC_DEVEUI_LEN]; | ||
| semtech_loramac_get_deveui(deveui); | ||
| semtech_loramac_get_deveui(&loramac, deveui); |
There was a problem hiding this comment.
I would have preferred here the usage of IPC rather than direct calls + mutex. IMO:
- If there's a single entry point for all commands, there shouldn't be needs for mutex (e.g here)
- In can be integrated to netapi, since most of these commands are network options.
What do you think?
There was a problem hiding this comment.
Basically, this means reusing MSG_TYPE_LORAMAC_CMD
There was a problem hiding this comment.
I understand what you mean and I avoided it on purpose. That would have required other internal get/set functions, with switch/case depending on the parameters, very similar to netdev.
The actual approach is simpler and I think it ends up to the same result.
If the semtech-loramac API is later integrated into netif, then it will be possible to call it in the netapi. I need to rework my first attempt to achieve this.
There was a problem hiding this comment.
I understand what you mean and I avoided it on purpose. That would have required other internal get/set functions, with switch/case depending on the parameters, very similar to netdev.
Yes, unless it's done via snippets (this is, writing integrated LoRaMAC code in a function and calling it via LORAMAC_CMD, but might confuse end users...)
Do you think it's possible to do the same with Join, etc?
| kernel_pid_t semtech_loramac_pid; | ||
| kernel_pid_t semtech_loramac_handler_pid; | ||
|
|
||
| sx127x_t sx127x; |
There was a problem hiding this comment.
Do you think it could make sense to also isolate these kind of variables in a struct?
There was a problem hiding this comment.
(e.g this could come from the netdev_t pointer)
There was a problem hiding this comment.
The problem is that it is used by the radio adaption code as an extern variable. Using a get/set function for passing/retrieving the pointer as you initially did won't be better I think.
The best solution would be to pass it to all semtech-loramac function but then it will require massive patches in the upstream code.
There was a problem hiding this comment.
yeah, you are right. I forgot that :)
9dda9fd to
27ad634
Compare
| return datarate; | ||
| } | ||
|
|
||
| void semtech_loramac_set_rx2_params(semtech_loramac_t *mac, |
There was a problem hiding this comment.
I have a compilation error here because semtech_loramac_t *mac argument is not used.
| return datarate; | ||
| } | ||
|
|
||
| void semtech_loramac_set_rx2_params(semtech_loramac_channel_params_t params) |
There was a problem hiding this comment.
Can we declare it as static ? In the current state, this function is not threadsafe if user call it from its app.
There was a problem hiding this comment.
Good idea, and it saves a few bytes (24) in ROM. Changed
4669665 to
c53ece8
Compare
|
I don't know if it is related to this PR but I'm encountering issue with the following command : |
It is definitely a bug, and not only on this branch, I can reproduce it on master. |
|
@dylad unfortunately I don't have hardware to test. We bought a gateway by January and haven't received any news about it... codewise looks OK to me though |
Just confirmed this also happens with B-L072z-LRWAN1 (but this issue is not present in the master branch): |
Ok, with ABP join procedure. I know where it comes from and I'll fix it |
This is normal since it's based on this one ;) |
|
@aabadie the Mac busy msg vanished, but it hangs with ABP: I will investigate |
|
Do you have the same problem on master ? (ABP activation is not my main use case, so I didn't test it) |
I think I know what is the problem: there's no fallback when the mcps_confirm event is not "status ok" and no message is sent from the MAC thread to the caller thread. I worked on that problem recently and have a branch that fixes this partially. |
|
But I did not encounter this issue on my hardware, isn't it weird ? |
More or less. That can happen if the server reply is not in the receiving time frame of the end device. In general it works. |
|
Any news on this ? |
|
I will try to find some time between today and tomorrow |
|
There's problem with receiving data when using ABP activation (this is also the case in master). |
|
So now the question is : Should we fix it here ? or in another PR ? |
|
@dylad I'm OK with merging this one since the bug is not related to this PR. |
|
|
||
| static uint8_t _semtech_loramac_radio_payload[SX127X_RX_BUFFER_SIZE]; | ||
| static semtech_loramac_rx_data_t _semtech_loramac_rx_data; | ||
| LoRaMacPrimitives_t semtech_loramac_primitives; |
| kernel_pid_t semtech_loramac_pid; | ||
| kernel_pid_t semtech_loramac_handler_pid; | ||
|
|
||
| sx127x_t sx127x; |
There was a problem hiding this comment.
yeah, you are right. I forgot that :)
| if (strcmp("deveui", argv[2]) == 0) { | ||
| uint8_t deveui[LORAMAC_DEVEUI_LEN]; | ||
| semtech_loramac_get_deveui(deveui); | ||
| semtech_loramac_get_deveui(&loramac, deveui); |
There was a problem hiding this comment.
I understand what you mean and I avoided it on purpose. That would have required other internal get/set functions, with switch/case depending on the parameters, very similar to netdev.
Yes, unless it's done via snippets (this is, writing integrated LoRaMAC code in a function and calling it via LORAMAC_CMD, but might confuse end users...)
Do you think it's possible to do the same with Join, etc?
I don't think so. Because the join/tx are triggering a complex workflow in the MAC with timers etc. Using the |
Sounds reasonable. Ok, then GO. |
pkg/semtech-loramac: refactor API and make it thread-safe
Contribution description
This PR is a refactoring of the Semtech loramac package: the idea was initially to introduce a dedicated struct for handling the mac in a thread-safe way. The immediate consequence is a global API change of the package but thanks to this, any access to the internal mac can be protected using mutexes and data exchange is simplified between the upstream code and the RIOT adaption code (using ipc messages).
I also went a little further by refactoring other things:
There might things I overlooked so comments and tests are very welcome.
cc @jia200x and @dylad who might be interested.
Issues/PRs references
None