Skip to content

Commit 9c17cd9

Browse files
committed
Race free sleep design
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
1 parent a39e9b1 commit 9c17cd9

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

hw_if/hal/src/common/hal_api_common.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ enum nrf_wifi_status hal_rpu_ps_wake(struct nrf_wifi_hal_dev_ctx *hal_dev_ctx)
5959
if (!hal_dev_ctx->rpu_fw_booted)
6060
return NRF_WIFI_STATUS_SUCCESS;
6161

62+
/* Cancel any pending sleep timer to prevent it from firing during the wake
63+
* operation or subsequent register/memory access.
64+
*
65+
* Note: Timer scheduling is done by the caller after releasing
66+
* the lock to prevent the timer from firing during subsequent
67+
* operations (register/memory reads/writes).
68+
*/
69+
nrf_wifi_osal_timer_kill(hal_dev_ctx->rpu_ps_timer);
70+
6271
if (hal_dev_ctx->rpu_ps_state == RPU_PS_STATE_AWAKE) {
6372
status = NRF_WIFI_STATUS_SUCCESS;
6473

@@ -121,9 +130,6 @@ enum nrf_wifi_status hal_rpu_ps_wake(struct nrf_wifi_hal_dev_ctx *hal_dev_ctx)
121130
#endif /* NRF_WIFI_RPU_RECOVERY_PS_STATE_DEBUG */
122131

123132
out:
124-
125-
nrf_wifi_osal_timer_schedule(hal_dev_ctx->rpu_ps_timer,
126-
NRF70_RPU_PS_IDLE_TIMEOUT_MS);
127133
return status;
128134
}
129135

hw_if/hal/src/common/hal_mem.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ static enum nrf_wifi_status rpu_mem_read_ram(struct nrf_wifi_hal_dev_ctx *hal_de
118118
out:
119119
nrf_wifi_osal_spinlock_irq_rel(hal_dev_ctx->rpu_ps_lock,
120120
&flags);
121+
122+
/* Schedule sleep timer after releasing the lock to prevent
123+
* it from firing during the critical section.
124+
*/
125+
if (status == NRF_WIFI_STATUS_SUCCESS) {
126+
nrf_wifi_osal_timer_schedule(hal_dev_ctx->rpu_ps_timer,
127+
NRF70_RPU_PS_IDLE_TIMEOUT_MS);
128+
}
121129
#endif /* NRF_WIFI_LOW_POWER */
122130

123131
return status;
@@ -169,6 +177,14 @@ static enum nrf_wifi_status rpu_mem_write_ram(struct nrf_wifi_hal_dev_ctx *hal_d
169177
out:
170178
nrf_wifi_osal_spinlock_irq_rel(hal_dev_ctx->rpu_ps_lock,
171179
&flags);
180+
181+
/* Schedule sleep timer after releasing the lock to prevent
182+
* it from firing during the critical section.
183+
*/
184+
if (status == NRF_WIFI_STATUS_SUCCESS) {
185+
nrf_wifi_osal_timer_schedule(hal_dev_ctx->rpu_ps_timer,
186+
NRF70_RPU_PS_IDLE_TIMEOUT_MS);
187+
}
172188
#endif /* NRF_WIFI_LOW_POWER */
173189

174190
return status;

hw_if/hal/src/common/hal_reg.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ enum nrf_wifi_status hal_rpu_reg_read(struct nrf_wifi_hal_dev_ctx *hal_dev_ctx,
9191
#ifdef NRF_WIFI_LOW_POWER
9292
nrf_wifi_osal_spinlock_irq_rel(hal_dev_ctx->rpu_ps_lock,
9393
&flags);
94+
95+
/* Schedule sleep timer after releasing the lock to prevent
96+
* it from firing during the critical section.
97+
*/
98+
if (status == NRF_WIFI_STATUS_SUCCESS) {
99+
nrf_wifi_osal_timer_schedule(hal_dev_ctx->rpu_ps_timer,
100+
NRF70_RPU_PS_IDLE_TIMEOUT_MS);
101+
}
94102
#endif /* NRF_WIFI_LOW_POWER */
95103

96104
return status;
@@ -151,6 +159,14 @@ enum nrf_wifi_status hal_rpu_reg_write(struct nrf_wifi_hal_dev_ctx *hal_dev_ctx,
151159
out:
152160
nrf_wifi_osal_spinlock_irq_rel(hal_dev_ctx->rpu_ps_lock,
153161
&flags);
162+
163+
/* Schedule sleep timer after releasing the lock to prevent
164+
* it from firing during the critical section.
165+
*/
166+
if (status == NRF_WIFI_STATUS_SUCCESS) {
167+
nrf_wifi_osal_timer_schedule(hal_dev_ctx->rpu_ps_timer,
168+
NRF70_RPU_PS_IDLE_TIMEOUT_MS);
169+
}
154170
#endif /* NRF_WIFI_LOW_POWER */
155171

156172
return status;

0 commit comments

Comments
 (0)