pkg/openthread: update for thread release 20180926#11204
Conversation
a59746d to
74a3cb9
Compare
|
awesome! |
|
Just tested on two IoT-LAB-M3 nodes :) |
|
@Hyungsin my biggest apologies. I just noticed I personally merged #11540 which also updates OpenThread to the same version. However, this PR still covers some points that were not included in #11540 (e.g ACK packet handling) Again, sorry for not checking the version :/ |
|
@jia200x, @miri64, it is frustrating to rebase this PR because another PR #11540, which handles the same (actually smaller) issue but posted 2 months after this, was reviewed and merged first. Surprisingly, it took only two days for the PR #11540 to be merged, but this PR got zero review for the last 8 months. @jia200x, I can rebase this but it would be good if you can test. Does it work for you? |
Sorry, I wasn't aware about this happening. We are aware of this problem and try to be more careful in the future (see #12543). I hand the review to @jia200x. |
74a3cb9 to
18cc126
Compare
maribu
left a comment
There was a problem hiding this comment.
I sadly do not have the background to properly review this. But I checked everything that does not need knowledge with openthread to be reviewed like code style and general concepts. This might speed up thinks a bit when a reviewer with the correct background takes a look.
|
|
||
| static kernel_pid_t _pid; | ||
| static otInstance *sInstance; | ||
| static bool otTaskPending = false; |
There was a problem hiding this comment.
Unless external packages enforce some code style for compatibility, we should try to stick to the RIOT coding convention for a consistency. See https://github.com/RIOT-OS/RIOT/blob/master/CODING_CONVENTIONS.md#naming
There was a problem hiding this comment.
we should update this in the file as well.
I would be ok to leave it as is in this PR and immediately after open another one for fixing this. What do you think?
| * @param[in] aT0 The reference time. | ||
| * @param[in] aDt The time delay in microseconds from @p aT0. | ||
| */ | ||
| void otPlatAlarmMicroStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt) |
There was a problem hiding this comment.
I have never worked with openthread so far, so please forgive if I'm asking nonsense.
The implementation in this PR would allow one timer in total to be set with otPlatAlamMicroStartAt() and one with the milliseconds version. (And the version in master would allow one in total.) This seems to be strange to me.
If I had to guess, I would say one timer per otInstance would make most sense. And one timer in total would make second-most sense to. Can someone with the required knowledge comment on this?
I think it should be possible to only provide one common internal implementation and offer otPlatAlarmMicroStartAt() and otPlatAlarmMilliStartAt() as static inline wrappers on top if this in order to safe some ROM.
There was a problem hiding this comment.
We need to call otPlatAlarmMilliFired(sInstance) when a millitimer is fired and otPlatAlarmMicroFired(sInstance) when a microtimer is fired. Without separation, I think it is hard to know what timer is fired. FYI, https://github.com/openthread/openthread/blob/master/src/core/common/timer.cpp
| } | ||
|
|
||
| /* OpenThread will call this to stop alarms */ | ||
| void otPlatAlarmMicroStop(otInstance *aInstance) |
There was a problem hiding this comment.
This should also be possible to combine with the milli version (e.g. by one being a static inline wrapper for the other). Of course only if not two timers in total is actually what openthread expects.
| } | ||
|
|
||
| /* OpenThread will call this for getting running time in microsecs */ | ||
| uint32_t otPlatAlarmMicroGetNow(void) |
There was a problem hiding this comment.
Providing this as static inline wrapper should safe some ROM.
There was a problem hiding this comment.
This is called by OpenThread, the symbol has to be exposed. So I guess it couldn't be static inline :/
|
|
||
| static otRadioFrame sTransmitFrame; | ||
| static otRadioFrame sReceiveFrame; | ||
| static otRadioFrame sAckFrame; |
There was a problem hiding this comment.
Again this is in misalignment with RIOT's coding convention. (As are the one above, that are not related to this PR.) If there is not technical reason for this, this should be renamed in order to comply with the coding convention.
There was a problem hiding this comment.
We have to adapt this file anyway in a further PR (lots of Camel Case here). Is it OK for you to leave it as is and we open a follow up right after we merge this?
|
|
||
| /* Called upon TX event */ | ||
| void send_pkt(otInstance *aInstance, netdev_t *dev, netdev_event_t event) | ||
| void sent_pkt(otInstance *aInstance, netdev_t *dev, netdev_event_t event) |
There was a problem hiding this comment.
Why this change in name?
Please see comment in declaration.
| case NETDEV_EVENT_TX_COMPLETE_DATA_PENDING: | ||
| DEBUG("openthread: NETDEV_EVENT_TX_COMPLETE_DATA_PENDING\n"); | ||
| otPlatRadioTxDone(aInstance, &sTransmitFrame, NULL, OT_ERROR_NONE); | ||
| _create_fake_ack_frame(true); |
There was a problem hiding this comment.
This seems odd to me. Maybe it is only because of the naming and me not being familiar with openthread. But I would expect ACKs to be created upon receiving a frame, not after sending one.
There was a problem hiding this comment.
Yes, this "fake" ack is created to report the result of a sent frame to the upper layer. This is not for responding to a received frame.
There was a problem hiding this comment.
This same technique is used in some of the official platform implementations of Openthread.
| uint8_t reversed_addr[IEEE802154_LONG_ADDRESS_LEN]; | ||
| for (unsigned i = 0; i < IEEE802154_LONG_ADDRESS_LEN; i++) { | ||
| reversed_addr[i] = (uint8_t) ((uint8_t *)aExtAddress)[IEEE802154_LONG_ADDRESS_LEN - 1 - i]; | ||
| reversed_addr[i] = aExtAddress->m8[IEEE802154_LONG_ADDRESS_LEN - 1 - i]; |
There was a problem hiding this comment.
This is network vs host byte order, right? If so, reversed_addr is a misleading name. (You could also take a look at the eui64_t type and see if it would be handy here.)
If the host byte order happens to be network byte order, this would not work. Maybe _set_long_addr() could be changed to always expect network byte order? (Or even eui64_t?)
There was a problem hiding this comment.
OpenThread uses IEEE addresses in little endian (see OpenThread radio API)
So we need to reverse in order to write it in the hardware. Maybe we could choose a better name for this variable or add comments?
| * @param[in] event just occurred netdev event | ||
| */ | ||
| void send_pkt(otInstance *aInstance, netdev_t *dev, netdev_event_t event); | ||
| void sent_pkt(otInstance *aInstance, netdev_t *dev, netdev_event_t event); |
There was a problem hiding this comment.
OK. Now (in context of the API doc I get the rename). Maybe even changing it to pkt_sent()?
There was a problem hiding this comment.
Yes. This is called after a packet transmission finishes. So may be pkt_sent is more appropriate.
| * @param[in] dev pointer to a netdev interface | ||
| * @param[in] tb pointer to the TX buffer designed for OpenThread | ||
| * @param[in] rb pointer to the RX buffer designed for Open_Thread | ||
| * @param[in] ab pointer to the ACK buffer designed for Open_Thread |
There was a problem hiding this comment.
Shouldn't it be "designated" instead of "designed"? If so, would you mind to sneak in a fix of the doc of tb and rb (as separate commit) into this PR?
There was a problem hiding this comment.
Either one makes sense to me. So I can change as you want.
Hi @Hyungsin. As @miri64 pointed out, we are aware of this situation and trying to fix it asap. Thanks anyway that besides this, you rebased it to the current master. I will run the tests ASAP and we would be ready to go. |
It is OK and Thanks for testing! |
|
@jia200x ping? |
jia200x
left a comment
There was a problem hiding this comment.
Some stuff I found while reviewing
| /* Interupt handler for OpenThread milli-timer event */ | ||
| static void _millitimer_cb(void* arg) { | ||
| (void)arg; | ||
| msg_t millitimer_msg; |
There was a problem hiding this comment.
This structure should be globally allocated. Otherwise the message will be lost.
| xtimer_set_msg(&ot_timer, dt, &ot_alarm_msg, thread_getpid()); | ||
| } | ||
| uint32_t dt = aDt * US_PER_MS; | ||
| xtimer_set(&ot_millitimer, dt); |
There was a problem hiding this comment.
I would say it's better to use xtimer_set_msg here.
| } | ||
|
|
||
| /* Interupt handler for OpenThread micro-timer event */ | ||
| static void _microtimer_cb(void* arg) { |
There was a problem hiding this comment.
same as above. This can be replaced by xtimer_set_msg
| case NETDEV_EVENT_TX_COMPLETE_DATA_PENDING: | ||
| DEBUG("openthread: NETDEV_EVENT_TX_COMPLETE_DATA_PENDING\n"); | ||
| otPlatRadioTxDone(aInstance, &sTransmitFrame, NULL, OT_ERROR_NONE); | ||
| _create_fake_ack_frame(true); |
There was a problem hiding this comment.
This same technique is used in some of the official platform implementations of Openthread.
|
@jia200x just resolved your comments. Thanks! |
|
@jia200x, maybe you'll find some time to have another look here ? |
|
I'm back into this, I'm running some tests now. |
| DEBUG("otPlatRadioAddSrcMatchShortEntry\n"); | ||
| (void)aInstance; | ||
| (void)aShortAddress; | ||
| bool pending = true; |
There was a problem hiding this comment.
This "fake" SrcAddressMatch table should do the trick (if a SED receives an ACK with FP, if there was no data for that address it will just timeout).
However, in order to be compliant with the OpenThread API, the otPlatRadioEnableSrcMatch should be implemented.
(see OpenThread radio API). Otherwise SED won't have a chance of receive a packet if SrcMatch is disabled
| uint8_t reversed_addr[IEEE802154_LONG_ADDRESS_LEN]; | ||
| for (unsigned i = 0; i < IEEE802154_LONG_ADDRESS_LEN; i++) { | ||
| reversed_addr[i] = (uint8_t) ((uint8_t *)aExtAddress)[IEEE802154_LONG_ADDRESS_LEN - 1 - i]; | ||
| reversed_addr[i] = aExtAddress->m8[IEEE802154_LONG_ADDRESS_LEN - 1 - i]; |
There was a problem hiding this comment.
OpenThread uses IEEE addresses in little endian (see OpenThread radio API)
So we need to reverse in order to write it in the hardware. Maybe we could choose a better name for this variable or add comments?
|
|
||
| static otRadioFrame sTransmitFrame; | ||
| static otRadioFrame sReceiveFrame; | ||
| static otRadioFrame sAckFrame; |
There was a problem hiding this comment.
We have to adapt this file anyway in a further PR (lots of Camel Case here). Is it OK for you to leave it as is and we open a follow up right after we merge this?
| } | ||
|
|
||
| /* OpenThread will call this for getting running time in microsecs */ | ||
| uint32_t otPlatAlarmMicroGetNow(void) |
There was a problem hiding this comment.
This is called by OpenThread, the symbol has to be exposed. So I guess it couldn't be static inline :/
|
ping @Hyungsin |
|
Should probably be updated to |
Ideally. |
|
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. |
Contribution description
This PR brings OpenThread version released on 20180926 to RIOT-OS.
@jia200x / @biboc, please review and test this.
Testing procedure
I checked that two samr21-xpro boards can be connected and ping to each other.
Issues/PRs references