-
Notifications
You must be signed in to change notification settings - Fork 2k
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
drivers/sx126x : r/NETOPT_RX_TIMEOUT/NETOPT_RX_SYMBOL_TIMEOUT #16599
Conversation
9ccd437
to
bfb8109
Compare
bfb8109
to
1398498
Compare
28c0ff4
to
521402b
Compare
521402b
to
8e9091b
Compare
Please rebase! |
8e9091b
to
1f3f934
Compare
Spurious commits are still present from dependency PR |
1f3f934
to
34f086f
Compare
Rebased to current master 👍🏼 |
Since I don't have a gateway I sued the following patch @jia200x provided: diff --git a/tests/driver_sx126x/main.c b/tests/driver_sx126x/main.c
index 313c95b4ed..f860c1a13a 100644
--- a/tests/driver_sx126x/main.c
+++ b/tests/driver_sx126x/main.c
@@ -30,6 +30,7 @@
#include "net/lora.h"
#include "net/netdev.h"
#include "net/netdev/lora.h"
+#include "mutex.h"
#include "sx126x.h"
#include "sx126x_params.h"
@@ -47,6 +48,8 @@ static char message[SX126X_MAX_PAYLOAD_LEN];
static sx126x_t sx126x;
+static mutex_t lock;
+
static void _event_cb(netdev_t *dev, netdev_event_t event)
{
if (event == NETDEV_EVENT_ISR) {
@@ -86,6 +89,10 @@ static void _event_cb(netdev_t *dev, netdev_event_t event)
puts("Transmission timeout");
break;
+ case NETDEV_EVENT_RX_TIMEOUT:
+ mutex_unlock(&lock);
+ break;
+
default:
printf("Unexpected netdev event received: %d\n", event);
break;
@@ -318,6 +325,21 @@ static const shell_command_t shell_commands[] = {
{ NULL, NULL, NULL }
};
+static void _measure_rx_timeout(netdev_t *netdev, uint8_t rx_timeout)
+{
+ netdev->driver->set(netdev, NETOPT_RX_SYMBOL_TIMEOUT, &rx_timeout, sizeof(rx_timeout));
+ netopt_state_t state = NETOPT_STATE_IDLE;
+ netdev->driver->set(netdev, NETOPT_STATE, &state, sizeof(state));
+ if (rx_timeout) {
+ printf("START (%i)\n", rx_timeout);
+ mutex_lock(&lock);
+ puts("STOP");
+ }
+ else {
+ puts("RX_CONTINUOUS");
+ }
+}
+
int main(void)
{
sx126x_setup(&sx126x, &sx126x_params[0], 0);
@@ -341,10 +363,19 @@ int main(void)
return 1;
}
+ mutex_init(&lock);
+ mutex_lock(&lock);
/* start the shell */
puts("Initialization successful - starting the shell now");
char line_buf[SHELL_DEFAULT_BUFSIZE];
+ uint8_t sf = LORA_SF11;
+ netdev->driver->get(netdev, NETOPT_SPREADING_FACTOR, &sf, sizeof(uint8_t));
+
+ _measure_rx_timeout(netdev, 10);
+ _measure_rx_timeout(netdev, 50);
+ _measure_rx_timeout(netdev, 0);
+
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
return 0;
} With this and only pyterm timings, it seems its accurate:
|
I consider this tested, @jia200x are your changes addressed? |
Hmmm the only weird thing I see from the output is the fact the timings are similar to the timings of SF7 (Ts=1.024 ms). T=10 took around 10ms and T=50 around 50. The strange thing is, I explicitly set SF11 in the patch. Maybe the command failed? It could also be something wrong with the function that calculates the timeout. |
Changing the SF, does not seem to affect the result..
|
drivers/include/sx126x.h
Outdated
assert(dev && (dev->mod_params.bw <= SX126X_LORA_BW_500) && \ | ||
(dev->mod_params.bw >= SX126X_LORA_BW_125)); | ||
|
||
/* Refer section 4.1.1.7 Time on air in SX1276/77/78/79 datasheet */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/* Refer section 4.1.1.7 Time on air in SX1276/77/78/79 datasheet */ | |
/* Refer section 4.1.1.7 Time on air in SX1276/77/78/79 datasheet */ |
Seems like its the wrong datasheet reference...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find the section either
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah well its the wrong datasheet, this is sx126x not 127x, I find it weird to have a reference to another driver datasheet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the correct datasheet be referenced?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was more about the math. Let me see if there are references in the sx126x datasheet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
drivers/sx126x/sx126x_netdev.c
Outdated
@@ -288,8 +288,9 @@ static int _set_state(sx126x_t *dev, netopt_state_t state) | |||
case NETOPT_STATE_RX: | |||
DEBUG("[sx126x] netdev: set NETOPT_STATE_RX state\n"); | |||
sx126x_cfg_rx_boosted(dev, true); | |||
if (dev->rx_timeout != 0) { | |||
sx126x_set_rx(dev, dev->rx_timeout); | |||
const int _timeout = (sx126x_symbol_to_msec(dev, dev->rx_timeout)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really const?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be safe, compile optimisation and adding some clarity. The variable should only be set via sx126x_symbol_to_msec
, wrong values will break the stack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const have no meaning here. It should be dropped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. Thanks, Jose for the clarification. Updated
Amended output:
diff --git a/drivers/sx126x/sx126x_netdev.c b/drivers/sx126x/sx126x_netdev.c
index da14679395..31edb09606 100644
--- a/drivers/sx126x/sx126x_netdev.c
+++ b/drivers/sx126x/sx126x_netdev.c
@@ -288,8 +288,9 @@ static int _set_state(sx126x_t *dev, netopt_state_t state)
case NETOPT_STATE_RX:
DEBUG("[sx126x] netdev: set NETOPT_STATE_RX state\n");
sx126x_cfg_rx_boosted(dev, true);
- const int _timeout = (sx126x_symbol_to_msec(dev, dev->rx_timeout));
+ int _timeout = (sx126x_symbol_to_msec(dev, dev->rx_timeout));
if (_timeout != 0) {
+ printf("[sx126x]: set timeout to %d\n", _timeout);
sx126x_set_rx(dev, _timeout);
}
else {
diff --git a/tests/driver_sx126x/Makefile b/tests/driver_sx126x/Makefile
index 68af3a584c..246dd6939c 100644
--- a/tests/driver_sx126x/Makefile
+++ b/tests/driver_sx126x/Makefile
@@ -6,5 +6,6 @@ USEMODULE += $(LORA_DRIVER)
USEMODULE += shell
USEMODULE += shell_commands
+USEMODULE += ztimer_usec
include $(RIOTBASE)/Makefile.include
diff --git a/tests/driver_sx126x/main.c b/tests/driver_sx126x/main.c
index 313c95b4ed..fa3be48cae 100644
--- a/tests/driver_sx126x/main.c
+++ b/tests/driver_sx126x/main.c
@@ -26,10 +26,12 @@
#include "msg.h"
#include "thread.h"
#include "shell.h"
+#include "ztimer.h"
#include "net/lora.h"
#include "net/netdev.h"
#include "net/netdev/lora.h"
+#include "mutex.h"
#include "sx126x.h"
#include "sx126x_params.h"
@@ -47,6 +49,8 @@ static char message[SX126X_MAX_PAYLOAD_LEN];
static sx126x_t sx126x;
+static mutex_t lock;
+
static void _event_cb(netdev_t *dev, netdev_event_t event)
{
if (event == NETDEV_EVENT_ISR) {
@@ -86,6 +90,10 @@ static void _event_cb(netdev_t *dev, netdev_event_t event)
puts("Transmission timeout");
break;
+ case NETDEV_EVENT_RX_TIMEOUT:
+ mutex_unlock(&lock);
+ break;
+
default:
printf("Unexpected netdev event received: %d\n", event);
break;
@@ -318,6 +326,21 @@ static const shell_command_t shell_commands[] = {
{ NULL, NULL, NULL }
};
+static void _measure_rx_timeout(netdev_t *netdev, uint8_t rx_timeout)
+{
+ netdev->driver->set(netdev, NETOPT_RX_SYMBOL_TIMEOUT, &rx_timeout, sizeof(rx_timeout));
+ netopt_state_t state = NETOPT_STATE_IDLE;
+ netdev->driver->set(netdev, NETOPT_STATE, &state, sizeof(state));
+ if (rx_timeout) {
+ printf("[%"PRIu32"us]: START (%i)\n", ztimer_now(ZTIMER_USEC), rx_timeout);
+ mutex_lock(&lock);
+ printf("[%"PRIu32"us]: STOP\n", ztimer_now(ZTIMER_USEC));
+ }
+ else {
+ printf("[%"PRIu32"us]: RX_CONTINOUS\n", ztimer_now(ZTIMER_USEC));
+ }
+}
+
int main(void)
{
sx126x_setup(&sx126x, &sx126x_params[0], 0);
@@ -341,10 +364,19 @@ int main(void)
return 1;
}
+ mutex_init(&lock);
+ mutex_lock(&lock);
/* start the shell */
puts("Initialization successful - starting the shell now");
char line_buf[SHELL_DEFAULT_BUFSIZE];
+ uint8_t sf = LORA_SF11;
+ netdev->driver->set(netdev, NETOPT_SPREADING_FACTOR, &sf, sizeof(uint8_t));
+
+ _measure_rx_timeout(netdev, 10);
+ _measure_rx_timeout(netdev, 50);
+ _measure_rx_timeout(netdev, 0);
+
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
return 0;
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK. I trust the results of @fjmolinas
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NACK. This one is not yet addressed: #16599 (comment)
please squash |
r/NETOPT_RX_TIMEOUT/NETOPT_RX_SYMBOL_TIMEOUT Use sx126x_symbol_to_msec() to calculate the RX timeout in ms.
4b5553d
to
4d890b1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-ACK
Contribution description
This PR adds
NETOPT_RX_SYMBOL_TIMEOUT
which is required by the sx126x radio and also removesNETOPT_RX_TIMEOUT
which is no longer required. The PR has been made as per discussions in thread #16579 , which would integrate aperiph
version ofsx1261
radio driver used in STMWL55JC SoC.Forced Radio Rx timeout timer to stop on preamble detection, else it breaks the current stack.
Testing procedure
The changes were already tested in #16579 using
Nucleo-WL55JC
and logs can be found in its description.Issues/PRs references
#16579
Depends on #16604