lora: remove LORA_FREQUENCY_RESOLUTION_DEFAULT from LoRa configurations#13318
lora: remove LORA_FREQUENCY_RESOLUTION_DEFAULT from LoRa configurations#13318jia200x wants to merge 2 commits intoRIOT-OS:masterfrom
Conversation
|
@benpicco I added some static inline functions for that. Code size reduces a bit |
|
Great, now |
|
The driver is also weird in that you configure a frequency whereas with all other radio drivers you configure a channel (and the driver might convert it to a frequency if the hardware requires it). But that's already a good improvement! Please squash. |
The problem is, there are different PHY layers that use the LoRa modulation. In case of IEEE802.15.4 is easy because it's almost certain there's a IEEE802.15.4 user on top of a 2.4 GHz BPSK (so the channel is the tuple "(channel number, channel page)"). The closest concept to channels here is the tuple "(DR, frequency)", but only for LoRaWAN. |
The LORA_FREQUENCY_RESOLUTION_DEFAULT variable is the frequency step of the SX127x transceiver. This is not intended to be configured by the user, and it's not specific to LoRa. This commit moves this configuration to a SX127X_FREQUENCY_STEP macro.
a3b1437 to
202d1ea
Compare
|
@benpicco done! |
Not anymore since 802.15.4g-2012 / 802.15.4-2015 😢 |
Really? What are they using now? |
Just checked the 2015 standard, and yes, the new bands don't seem to have channel page (only for the bands present prior to the 2012 standard) |
Thanks! |
benpicco
left a comment
There was a problem hiding this comment.
Code looks good, I don't have hardware to test but I don't expect any changes in the outcome.
|
thanks! @aabadie are you ok with this change? |
leandrolanzieri
left a comment
There was a problem hiding this comment.
This does not seem to be working. On test/driver_sx127x I get wrong channels:
> channel get
2020-02-13 17:32:40,613 # channel get
2020-02-13 17:32:40,615 # Channel: 12661926
> channel set 868000000
2020-02-13 17:42:06,592 # channel set 868000000
2020-02-13 17:42:06,593 # New channel set
> channel get
2020-02-13 17:42:12,695 # channel get
2020-02-13 17:42:12,696 # Channel: 12361938
drivers/sx127x/sx127x_getset.c
Outdated
| */ | ||
| static inline uint32_t _freq_to_hw_value(uint32_t freq) | ||
| { | ||
| return (freq << 8) / 15625; |
There was a problem hiding this comment.
| return (freq << 8) / 15625; | |
| return (freq / 15625) << 8; |
I had no idea freq would be this big.
There was a problem hiding this comment.
Hmmmm this can produce an offset of 256 in the Hw value :(
Given a=int(freq / 15625) the integer division and b=(freq mod 15625)/15625 the decimal reminder (so freq/15625 == a+b, with 0<=b<1)
Then (1):
(freq/15625) * 2^8 == (a + b) * 2^8 == a*2^8 + b* 2^8
But (2):
int(freq/15625)*256 == a*256.
So (1) - (2) is b*256.
I tested it with real numbers:
>>> freq
16777215
>>> int(freq<<8)/(5**6)
274877.89056
>>> int(freq/(5**6))<<8
274688
There was a problem hiding this comment.
Hmm, how about
static inline uint32_t _freq_to_hw_value(uint32_t freq)
{
freq <<= 2;
unsigned pow = 6;
do {
freq /= 5;
freq <<= 1;
} while (--pow);
return freq;
}There was a problem hiding this comment.
This gets much better, but generates a difference of "2" in worst scenario (120 Hz in the carrier frequency).
I have the impression it shouldn't affect that much (it's 0.00001% of drift in the 868 MHz band).
drivers/sx127x/sx127x_getset.c
Outdated
| */ | ||
| static inline uint32_t _hw_value_to_freq(uint32_t frf) | ||
| { | ||
| return (frf * 15625) >> 8; |
There was a problem hiding this comment.
| return (frf * 15625) >> 8; | |
| return ((frf * 125) >> 8) * 125; |
|
I guess we might have to cast to |
It shouldn't be necessary. The max value of E.g: |
The LORA_FREQUENCY_RESOLUTION_DEFAULT variable is the frequency step of the SX127x transceiver. This is not intended to be configured by the user, and it's not specific to LoRa. This commit moves this configuration to a SX127X_FREQUENCY_STEP macro.
|
I tested the last push with LoRaWAN. Now it seems to work. |
| { | ||
| return (frf * 15625) >> 8; | ||
| unsigned pow = 6; | ||
| frf >>= 2; |
There was a problem hiding this comment.
better do the shift at the end so precision is not lost here.
|
@jia200x waiting for author action ;-) |
|
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. |
|
self-ping :) |

Contribution description
The
LORA_FREQUENCY_RESOLUTION_DEFAULTvariable is the frequency step of the SX127x transceiver. This is not intended to be configured by the user and it's not specific to LoRa.This PR moves thisconfiguration to a SX127X_FREQUENCY_STEP macro.
The immediate follow up of this PR is LoRa and LoRaWAN Kconfig configurations.
Testing procedure
It should be enough to check if
sx127xapplications (gnrc_lorawan, lorawan example) still compile.Issues/PRs references
None so far