-
Notifications
You must be signed in to change notification settings - Fork 18
sat: timeout: Add timeouts for sat transmission #230
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
base: main
Are you sure you want to change the base?
Changes from all commits
0603b09
055e7f6
003d79b
b3fa937
41ddcbf
81ef957
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| /* Hubble */ | ||
| #include <hubble/port/sat_radio.h> | ||
| #include <hubble/sat/packet.h> | ||
| #include <hubble/port/sat_radio.h> | ||
|
Comment on lines
25
to
+27
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. duplicate include? |
||
|
|
||
| /* DMM */ | ||
| #if defined(USE_DMM_OVRDE) | ||
|
|
@@ -61,6 +62,8 @@ | |
| #error "Device not supported" | ||
| #endif | ||
|
|
||
| #define _TIME_S_TO_TICK(_time_s) ((_time_s * 1000U) / portTICK_PERIOD_MS) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit curious on is this preferred over |
||
|
|
||
| /** | ||
| * This semaphore is used to protect a packet transmission and avoid | ||
| * race conditions. | ||
|
|
@@ -231,7 +234,11 @@ int hubble_sat_board_packet_send(const struct hubble_sat_packet_frames *packet) | |
| { | ||
| int8_t frame = -1; | ||
|
|
||
| xSemaphoreTake(_transmit_sem, portMAX_DELAY); | ||
| if (xSemaphoreTake(_transmit_sem, | ||
| _TIME_S_TO_TICK(HUBBLE_SAT_TRANSMISSION_TIMEOUT_S)) != | ||
| pdTRUE) { | ||
| return -ETIMEDOUT; | ||
| } | ||
|
|
||
| for (uint8_t i = 0; i < packet->total_number_of_symbols; i++) { | ||
| int16_t step; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,11 +18,14 @@ | |
| #include <stdint.h> | ||
| #include <errno.h> | ||
|
|
||
| #define RADIO_NODE DT_NODELABEL(radio) | ||
| #define RADIO_NODE DT_NODELABEL(radio) | ||
|
|
||
| /* From NRF52840_PS_v1.2 6.20.15.8 Time between TXEN -> READ is 140us */ | ||
| #define WAIT_SYMBOL_OFF_US (HUBBLE_WAIT_SYMBOL_OFF_US - 140) | ||
| #define WAIT_SYMBOL_US (HUBBLE_WAIT_SYMBOL_US + 140) | ||
| #define WAIT_SYMBOL_OFF_US (HUBBLE_WAIT_SYMBOL_OFF_US - 140) | ||
| #define WAIT_SYMBOL_US (HUBBLE_WAIT_SYMBOL_US + 140) | ||
|
|
||
| /* Max time for semaphore symbol to wait before failing. */ | ||
| #define WAIT_SYMBOL_TIMEOUT_US K_USEC(2 * (WAIT_SYMBOL_OFF_US + WAIT_SYMBOL_US)) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the 2 here arbitrary? Or is it related to the 2 uses in
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how to feel about the use of constant
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is arbitrary, just two times the expected time, could be even less. Let me re-struct it and make it consistent |
||
|
|
||
| static uint32_t _radio_shorts; | ||
|
|
||
|
|
@@ -168,9 +171,14 @@ int hubble_sat_soc_disable(void) | |
|
|
||
| int hubble_sat_soc_packet_send(const struct hubble_sat_packet_frames *packet) | ||
| { | ||
| int ret; | ||
| int8_t frame = -1; | ||
|
|
||
| k_sem_take(&_transmit_sem, K_FOREVER); | ||
| ret = k_sem_take(&_transmit_sem, | ||
| K_SECONDS(HUBBLE_SAT_TRANSMISSION_TIMEOUT_S)); | ||
| if (ret != 0) { | ||
| return ret; | ||
| } | ||
|
|
||
| k_sem_reset(&_symbol_sem); | ||
|
|
||
|
|
@@ -186,15 +194,18 @@ int hubble_sat_soc_packet_send(const struct hubble_sat_packet_frames *packet) | |
|
|
||
| hubble_nrf_lib_frequency_set(packet->frame[frame].channel, | ||
| packet->frame[frame].data[data_pos]); | ||
| k_sem_take(&_symbol_sem, K_FOREVER); | ||
| ret = k_sem_take(&_symbol_sem, WAIT_SYMBOL_TIMEOUT_US); | ||
| if (ret != 0) { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| _ppi_disable(); | ||
| _timer_disable(); | ||
|
|
||
| k_sem_give(&_transmit_sem); | ||
|
|
||
| return 0; | ||
| return ret; | ||
| } | ||
|
|
||
| #ifdef CONFIG_HUBBLE_SAT_NETWORK_DTM_MODE | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,13 +27,16 @@ | |
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
|
|
||
| #define RADIO_NODE DT_NODELABEL(radio) | ||
| #define RADIO_NODE DT_NODELABEL(radio) | ||
|
|
||
| /* From nRF54L15 PS: Time between TXEN -> READY is ~40us with fast ramp-up */ | ||
| #define WAIT_SYMBOL_OFF_US (HUBBLE_WAIT_SYMBOL_OFF_US - 40) | ||
| #define WAIT_SYMBOL_US (HUBBLE_WAIT_SYMBOL_US + 40) | ||
| #define WAIT_SYMBOL_OFF_US (HUBBLE_WAIT_SYMBOL_OFF_US - 40) | ||
| #define WAIT_SYMBOL_US (HUBBLE_WAIT_SYMBOL_US + 40) | ||
|
|
||
| #define NRF_DPPIC NRF_DPPIC10 | ||
| /* Max time for semaphore symbol to wait before failing. */ | ||
| #define WAIT_SYMBOL_TIMEOUT_US K_USEC(2 * (WAIT_SYMBOL_OFF_US + WAIT_SYMBOL_US)) | ||
|
|
||
| #define NRF_DPPIC NRF_DPPIC10 | ||
| #define RADIO_ENABLE_TX_ON_CC0_PPI 9U | ||
|
Comment on lines
+39
to
40
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another weird case from the formatter :(
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, super annoying. I can try to revert it and see if CI complains |
||
| #define RADIO_DISABLE_ON_CC1_PPI 12U | ||
|
|
||
|
|
@@ -216,9 +219,15 @@ int hubble_sat_soc_enable(void) | |
|
|
||
| int hubble_sat_soc_packet_send(const struct hubble_sat_packet_frames *packet) | ||
| { | ||
| int ret; | ||
| int8_t frame = -1; | ||
|
|
||
| k_sem_take(&_transmit_sem, K_FOREVER); | ||
| ret = k_sem_take(&_transmit_sem, | ||
| K_SECONDS(HUBBLE_SAT_TRANSMISSION_TIMEOUT_S)); | ||
| if (ret != 0) { | ||
| return ret; | ||
| } | ||
|
|
||
| k_sem_reset(&_symbol_sem); | ||
|
|
||
| _dppi_enable(); | ||
|
|
@@ -233,15 +242,18 @@ int hubble_sat_soc_packet_send(const struct hubble_sat_packet_frames *packet) | |
|
|
||
| hubble_nrf_lib_frequency_set(packet->frame[frame].channel, | ||
| packet->frame[frame].data[data_pos]); | ||
| k_sem_take(&_symbol_sem, K_FOREVER); | ||
| ret = k_sem_take(&_symbol_sem, WAIT_SYMBOL_TIMEOUT_US); | ||
| if (ret != 0) { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| _dppi_disable(); | ||
| _timer_disable(); | ||
|
|
||
| k_sem_give(&_transmit_sem); | ||
|
|
||
| return 0; | ||
| return ret; | ||
| } | ||
|
|
||
| #ifdef CONFIG_HUBBLE_SAT_NETWORK_DTM_MODE | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,6 +104,7 @@ static void _timer_cb(sl_rail_handle_t rail_handle) | |
| static int _radio_cw_start(uint8_t channel, uint16_t step, uint32_t delay, | ||
| uint32_t duration_us) | ||
| { | ||
| int ret; | ||
| sl_rail_status_t status; | ||
| sl_rail_time_t anchor; | ||
|
|
||
|
|
@@ -126,21 +127,24 @@ static int _radio_cw_start(uint8_t channel, uint16_t step, uint32_t delay, | |
| return _sl_status_to_errno(status); | ||
| } | ||
|
|
||
| k_sem_take(&_symbol_sem, K_FOREVER); | ||
| ret = k_sem_take(&_symbol_sem, (2 * duration_us)); | ||
|
|
||
| status = sl_rail_stop_tx_stream(_rail_handle); | ||
| if (status != SL_RAIL_STATUS_NO_ERROR) { | ||
| return _sl_status_to_errno(status); | ||
| } | ||
|
|
||
| if (ret != 0) { | ||
|
Comment on lines
134
to
+137
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we preserve the error from k_sem_take here? But I'm not sure if this makes it hard to read / maintain. |
||
| return ret; | ||
| } | ||
|
|
||
| status = sl_rail_set_timer(_rail_handle, anchor + duration_us + delay, | ||
| SL_RAIL_TIME_ABSOLUTE, &_timer_cb); | ||
| if (status != SL_RAIL_STATUS_NO_ERROR) { | ||
| return _sl_status_to_errno(status); | ||
| } | ||
|
|
||
| k_sem_take(&_symbol_sem, K_FOREVER); | ||
| return 0; | ||
| return k_sem_take(&_symbol_sem, (2 * delay)); | ||
| } | ||
|
|
||
| static int _radio_channel_set(uint8_t channel) | ||
|
|
@@ -255,10 +259,15 @@ int hubble_sat_board_disable(void) | |
|
|
||
| int hubble_sat_board_packet_send(const struct hubble_sat_packet_frames *packet) | ||
| { | ||
| int ret = 0; | ||
| int ret; | ||
| int8_t frame = -1; | ||
|
|
||
| k_sem_take(&_transmit_sem, K_FOREVER); | ||
| ret = k_sem_take(&_transmit_sem, | ||
| K_SECONDS(HUBBLE_SAT_TRANSMISSION_TIMEOUT_S)); | ||
| if (ret != 0) { | ||
| return ret; | ||
| } | ||
|
|
||
| k_sem_reset(&_symbol_sem); | ||
|
|
||
| for (uint8_t i = 0; i < packet->total_number_of_symbols; i++) { | ||
|
|
||
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 kind of feeling something off about this so I asked Claude and checked with ESP-IDF source:
->
portTICK_PERIOD_MS= 1000 / 100 = 10where tick rate Hz is 100 by default. I also doubled check the
buildfolder and the default ofCONFIG_FREERTOS_HZis indeed 100.So say we have symbol off = 800 us -> (800 / 1000U) / 10 = 0
or symbol on = 8000 us -> ( 8000 / 1000 ) / 10 = 0
So either case it still fails.
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.
Yep, good point, we should have at least 1 tick as min.