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

LoRa improvements #24649

Merged
merged 4 commits into from May 4, 2020
Merged

Conversation

Mani-Sadhasivam
Copy link
Member

@Mani-Sadhasivam Mani-Sadhasivam commented Apr 23, 2020

  1. Got rid of counter API as it is found to be not fit for upcoming LoRaWAN support.
  2. Marked LoRa support as Experimental
  3. Switched to new timeout API

This PR is a spinoff from #23664

Signed-off-by: Manivannan Sadhasivam mani@kernel.org

@andysan
Copy link
Collaborator

andysan commented Apr 23, 2020

Thanks for pulling this out of the LoRaWAN PR, it's going the be helpful for #24616. Would it make sense to split the RTC code into a separate source file right away since you're rewriting most of it anyway? Saves me from doing it later. :)

I verified the assumptions in the new implementation against the documentation and one of the other board implementations in LoRaMAC-Node and it looks good to me.

@carlescufi
Copy link
Member

@andysan would you mind approving if you are happy with this?

@carlescufi
Copy link
Member

CC @KwonTae-young

Copy link
Member

@mniestroj mniestroj left a comment

Choose a reason for hiding this comment

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

If I am correct then Rtc in loramac-node is used only for implementing Timer in loramac-node. So now we have:
Timer (loramac-node) <-> Rtc (loramac-node) <-> k_timer (Zephyr)

In long term we should think about implementing Timer API instead of Rtc API, which will require less bloat. This however requires changes in loramac-node repository, because it is not possible now.

drivers/lora/sx1276.c Outdated Show resolved Hide resolved
drivers/lora/sx1276.c Show resolved Hide resolved
Copy link
Collaborator

@andysan andysan left a comment

Choose a reason for hiding this comment

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

This is really just an observation, but couldn't we just define ticks in LoRaMAC-node as being milliseconds and do away with all of the annoying time conversions? That way, tick2ms and ms2tick suddenly become unit operations. We would probably have to return k_ticks_to_ms_ceil32(1) as the minimum timeout in that case though.

{
return counter_us_to_ticks(dev_data.counter, (milliseconds / 1000));
saved_time = k_ms_to_ticks_ceil32(k_uptime_get_32());
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we want to deal with ticks anyway, why don't use the k_uptime_ticks API instead and store the saved time as an s64_t? The documentation actually states that k_uptime_get_32 uses the full precision clock, so there is normally no benefit to using the 64-bit version.

Copy link
Member

Choose a reason for hiding this comment

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

We could most probably get rid of ticks and only deal with real time. The k_timeout_t supports also us or ns timevalues.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is really just an observation, but couldn't we just define ticks in LoRaMAC-node as being milliseconds and do away with all of the annoying time conversions? That way, tick2ms and ms2tick suddenly become unit operations. We would probably have to return k_ticks_to_ms_ceil32(1) as the minimum timeout in that case though.

The idea is not to change the LoRaMac-node repository. If we start doing this then for sure the delta between upstream and downstream will increase and I don't want to have that :) We should live with what the repository provides. If we want to change something then we should do that in upstream repo and inherit here.

Copy link
Member Author

Choose a reason for hiding this comment

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

We could most probably get rid of ticks and only deal with real time. The k_timeout_t supports also us or ns timevalues.

Sorry no. It is like abusing the API exposed by LoRaMac-node repo. We already did that once with Rtc/timer but there we had no other choice. But for this case, since we have an API for getting the ticks, I'd like to stick to it.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we want to change something then we should do that in upstream repo and inherit here.

Maybe post an issue on the Semtech repo and ask if they are receptive to integrating with zephyr?

Copy link
Contributor

Choose a reason for hiding this comment

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

It will help with decisions down the road about how much to use the underlying zephyr kernel API's.

Copy link
Contributor

Choose a reason for hiding this comment

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

My thought is Semtech may have an interested to make their stack available across a larger base of devices and reduce their maintenance.

Copy link
Member Author

Choose a reason for hiding this comment

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

My thought is Semtech may have an interested to make their stack available across a larger base of devices and reduce their maintenance.

But Zephyr is not the only user of their stack...

Copy link
Collaborator

Choose a reason for hiding this comment

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

What I meant by defining ticks as ms wouldn't require a change in the LoRaMAC code. The only change it would involve would be the way we expose ticks to the library. It's no different from a real system that just happens to define a tick as 1 ms. This would avoid the weird conversions where we go from microseconds to ticks, and then from ticks to microseconds when scheduling alarms.

If we do that, RtcMs2Tick(x) and RtcTick2Ms(x) would just return x. Calls that take a tick as an argument could just rely on a tick in LoRa being defined as 1ms, or use RtcTick2Ms to document the fact (the call would get inlined).

Copy link
Member Author

Choose a reason for hiding this comment

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

For the record, I've switched to k_uptime_get_32() API

@sslupsky
Copy link
Contributor

Can someone comment on the minimum resources required to run this stack on zephyr? Would the stm32l04 mcu inside the Murata lora module be able to run the lora stack on zephyr? I am considering to build a new LoRaWAN firmware stack for the Arduino MKR WAN 1310 that runs on the Murata module. The module currently runs a version of the Semtech AT Slave application. However, Arduino has not updated it with the more recent 4.4.2 firmware releases from Semtech so it is terribly out of date and lacks support for time synchronization and fuota.

The RTC/Counter implementation doesn't fit for the upcoming LoRaWAN
as most of the Counter drivers in Zephyr works with 1s granularity
which is not enough for LoRaWAN stack. So, k_timer calls are used in
place of Counter's alarm and k_uptime_get() APIs are used in place of
Counter's time keeping.

While at it, lets also fixup the broken alarm implementation.

Signed-off-by: Manivannan Sadhasivam <mani@kernel.org>
The LoRa APIs are expected to undergo some change as the usecase get's
increased. So let's mark it as experimental until the APIs got
stabililized.

Signed-off-by: Manivannan Sadhasivam <mani@kernel.org>
@carlescufi
Copy link
Member

@mniestroj can you please take another look?

drivers/lora/sx1276.c Outdated Show resolved Hide resolved
Get rid of legacy timeout API and move to new timeout API for LoRa.
This involves changes to API, SX1276 driver and sample application.

Signed-off-by: Manivannan Sadhasivam <mani@kernel.org>
RtcTick2Ms function is required for upcoming LoRaWAN support. Hence,
add definition for it.

Signed-off-by: Manivannan Sadhasivam <mani@kernel.org>
Copy link
Member

@mniestroj mniestroj left a comment

Choose a reason for hiding this comment

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

LGTM

@carlescufi carlescufi merged commit f619cbc into zephyrproject-rtos:master May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: API Changes to public APIs area: LoRa area: Samples Samples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants