Skip to content

Commit 4651703

Browse files
Mirlenkonordicjm
authored andcommitted
mpsl: Use direct GPIO register access in coex
The Zephyr GPIO driver cannot be used from a Zero Latency Interrupt context, as its power management functions, e.g. pm_device_runtime_get attempt to take a semaphore. This can lead to system deadlocks when GPIOs are used from the ZLI. Signed-off-by: Aleksandr Mirlenko <[email protected]>
1 parent 52f7519 commit 4651703

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

subsys/mpsl/cx/nrf700x/mpsl_cx_nrf700x.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ static const struct gpio_dt_spec req_spec = GPIO_DT_SPEC_GET(CX_NODE, req_gp
6565
static const struct gpio_dt_spec status0_spec = GPIO_DT_SPEC_GET(CX_NODE, status0_gpios);
6666
static const struct gpio_dt_spec grant_spec = GPIO_DT_SPEC_GET(CX_NODE, grant_gpios);
6767

68+
/* Direct register access pointers for ISR-safe GPIO control from DT */
69+
static NRF_GPIO_Type *req_port =
70+
((NRF_GPIO_Type *)DT_REG_ADDR(DT_GPIO_CTLR(CX_NODE, req_gpios)));
71+
static NRF_GPIO_Type *status0_port =
72+
((NRF_GPIO_Type *)DT_REG_ADDR(DT_GPIO_CTLR(CX_NODE, status0_gpios)));
73+
static uint32_t req_pin_mask = BIT(DT_GPIO_PIN(CX_NODE, req_gpios));
74+
static uint32_t status0_pin_mask = BIT(DT_GPIO_PIN(CX_NODE, status0_gpios));
75+
6876
static mpsl_cx_cb_t callback;
6977
static struct gpio_callback grant_cb;
7078
static uint32_t grant_abs_pin;
@@ -166,7 +174,18 @@ static int sig_dir_level_calc(mpsl_cx_op_map_t ops)
166174
*/
167175
static int32_t gpio_drive_status0_to_dir(mpsl_cx_op_map_t ops)
168176
{
169-
return gpio_pin_set_dt(&status0_spec, sig_dir_level_calc(ops));
177+
if (status0_port == NULL) {
178+
return -NRF_EINVAL;
179+
}
180+
181+
int level = sig_dir_level_calc(ops);
182+
183+
if (level) {
184+
nrf_gpio_port_out_set(status0_port, status0_pin_mask);
185+
} else {
186+
nrf_gpio_port_out_clear(status0_port, status0_pin_mask);
187+
}
188+
return 0;
170189
}
171190

172191
/**
@@ -177,7 +196,16 @@ static int32_t gpio_drive_status0_to_dir(mpsl_cx_op_map_t ops)
177196
*/
178197
static int32_t gpio_drive_request(int active)
179198
{
180-
return gpio_pin_set_dt(&req_spec, active);
199+
if (req_port == NULL) {
200+
return -NRF_EINVAL;
201+
}
202+
203+
if (active) {
204+
nrf_gpio_port_out_set(req_port, req_pin_mask);
205+
} else {
206+
nrf_gpio_port_out_clear(req_port, req_pin_mask);
207+
}
208+
return 0;
181209
}
182210

183211
static int32_t request(const mpsl_cx_request_t *req_params)

0 commit comments

Comments
 (0)