Skip to content

Commit

Permalink
mpsl: fem: add kconfig MPSL_FEM_INIT_PRIORITY
Browse files Browse the repository at this point in the history
The nrf2220 and nrf2240 devices require that mpsl_fem_init operation
happens before the initialization of I2C if the TWI interface is
used with these devices. This was achieved by hardcoded 49 value which
is less than default value of Kconfig option I2C_INIT_PRIORITY.
This commit removes the magic value form SYS_INIT(..., 49) and
introduces a new Kconfig option MPSL_FEM_INIT_PRIORITY.

The default value for MPSL_FEM_INIT_PRIORITY in case of nrf2220 or
nrf2240 with TWI is still hardcoded to 49 due to following limitations:

1) The Kconfig compiler does not allow compile-time calculation of
   default value like:

   config MPSL_FEM_INIT_PRIORITY
       default (I2C_INIT_PRIORITY-1) if ...

2) The third parameter of SYS_INIT must be a literal or come from
   a macro expanding to literal. It cannot expand to expression. So
   following is impossible:

    #define FEM_INIT_PRIO (CONFIG_I2C_INIT_PRIORITY - 1)

    SYS_INIT(mpsl_fem_init, POST_KERNEL, FEM_INIT_PRIO);

Providing Kconfig option MPSL_FEM_INIT_PRIORITY with appropriate
BUILD_ASSERT gives ability to have correct priority of FEM
initialization in case the Kconfig I2C_INIT_PRIORITY is changed.

For nrf21540_gpio, nrf21540_gpio_spi and simple_gpio the default value
is equal to KERNEL_INIT_PRIORITY_DEVICE (no change in default value and
behavior) is used. The SYS_INIT priority at which legacy forwarding of
pins happens (mpsl_fem_host_init sys init priority) is intentionally
not affected.

Signed-off-by: Andrzej Kuros <andrzej.kuros@nordicsemi.no>
  • Loading branch information
ankuns authored and rlubos committed May 9, 2024
1 parent f1ea890 commit 2218469
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
7 changes: 7 additions & 0 deletions subsys/mpsl/fem/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ config MPSL_FEM_USE_TWIM_STUB
(MPSL_FEM_NRF2240 && !MPSL_FEM_NRF2240_TWI_SUPPORT)
default y

config MPSL_FEM_INIT_PRIORITY
int "Init priority of the Front-End Module support code"
depends on MPSL_FEM
default 49 if (MPSL_FEM_NRF2220 && MPSL_FEM_NRF2220_TWI_SUPPORT) || \
(MPSL_FEM_NRF2240 && MPSL_FEM_NRF2240_TWI_SUPPORT)
default KERNEL_INIT_PRIORITY_DEVICE

module=MPSL_FEM
module-str=MPSL_FEM
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"
2 changes: 1 addition & 1 deletion subsys/mpsl/fem/nrf21540_gpio/mpsl_fem_nrf21540_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ static int mpsl_fem_init(void)
return fem_nrf21540_gpio_configure();
}

SYS_INIT(mpsl_fem_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);
SYS_INIT(mpsl_fem_init, POST_KERNEL, CONFIG_MPSL_FEM_INIT_PRIORITY);

#else /* !defined(CONFIG_MPSL_FEM_PIN_FORWARDER) */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,6 @@ static int mpsl_fem_init(void)
return fem_nrf21540_gpio_spi_configure();
}

SYS_INIT(mpsl_fem_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);
SYS_INIT(mpsl_fem_init, POST_KERNEL, CONFIG_MPSL_FEM_INIT_PRIORITY);

#endif /* !defined(CONFIG_MPSL_FEM_PIN_FORWARDER) */
8 changes: 7 additions & 1 deletion subsys/mpsl/fem/nrf2220/mpsl_fem_nrf2220.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ static int mpsl_fem_init(void)
return fem_nrf2220_configure();
}

SYS_INIT(mpsl_fem_init, POST_KERNEL, 49);
#if defined(CONFIG_I2C) && \
DT_NODE_HAS_PROP(DT_NODELABEL(nrf_radio_fem), twi_if)
BUILD_ASSERT(CONFIG_MPSL_FEM_INIT_PRIORITY < CONFIG_I2C_INIT_PRIORITY,
"The initialization of nRF2220 Front-End Module must happen before initialization of I2C");
#endif

SYS_INIT(mpsl_fem_init, POST_KERNEL, CONFIG_MPSL_FEM_INIT_PRIORITY);

#endif /* defined(CONFIG_MPSL_FEM_NRF2220) */
8 changes: 7 additions & 1 deletion subsys/mpsl/fem/nrf2240/mpsl_fem_nrf2240.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ static int mpsl_fem_init(void)
return fem_nrf2240_configure();
}

SYS_INIT(mpsl_fem_init, POST_KERNEL, 49);
#if defined(CONFIG_I2C) && \
DT_NODE_HAS_PROP(DT_NODELABEL(nrf_radio_fem), twi_if)
BUILD_ASSERT(CONFIG_MPSL_FEM_INIT_PRIORITY < CONFIG_I2C_INIT_PRIORITY,
"The initialization of nRF2240 Front-End Module must happen before initialization of I2C");
#endif

SYS_INIT(mpsl_fem_init, POST_KERNEL, CONFIG_MPSL_FEM_INIT_PRIORITY);

#endif /* defined(CONFIG_MPSL_FEM_NRF2240) */
2 changes: 1 addition & 1 deletion subsys/mpsl/fem/simple_gpio/mpsl_fem_simple_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static int mpsl_fem_init(void)
return fem_simple_gpio_configure();
}

SYS_INIT(mpsl_fem_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);
SYS_INIT(mpsl_fem_init, POST_KERNEL, CONFIG_MPSL_FEM_INIT_PRIORITY);

#else /* !defined(CONFIG_MPSL_FEM_PIN_FORWARDER) */

Expand Down

0 comments on commit 2218469

Please sign in to comment.