Skip to content

Commit 9e342f9

Browse files
ankunsrlubos
authored andcommitted
fem_al: replace gain with FEM type-specific tx_power_control
The MPSL FEM public API is changed. The `mpsl_fem_pa_gain_set` has been replaced by `mpsl_fem_pa_power_control_set`. There is no more possibility of setting "gain". The real gain of FEM depends on many factors including but not limited to input power of the FEM, frequency, temperature, supply voltage and the way the FEM is controlled. The fem_al API is changed so that the concept of generic "gain" of the front-end module is replaced by "tx_power_control" which is FEM type-specific. `fem_tx_power_control` type is introduced. `fem_tx_gain_set` is replaced by `fem_tx_power_control_set` `fem_default_tx_gain_get` is replaced by 'fem_default_tx_output_power_get' `fem_interface_api` is changed to reflect these changes along with implementations nrf21540.c and generic_fem.c. Signed-off-by: Andrzej Kuros <andrzej.kuros@nordicsemi.no>
1 parent 8c29e1f commit 9e342f9

File tree

6 files changed

+47
-44
lines changed

6 files changed

+47
-44
lines changed

doc/nrf/releases_and_maturity/migration/migration_guide_2.7.rst

+8-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,14 @@ Libraries
5656

5757
This section describes the changes related to libraries.
5858

59-
|no_changes_yet_note|
59+
FEM abstraction layer
60+
---------------------
61+
62+
.. toggle::
63+
64+
* For applications using :ref:`fem_al_lib`:
65+
The function :c:func:`fem_tx_power_control_set` replaces the function :c:func:`fem_tx_gain_set`.
66+
The function :c:func:`fem_default_tx_output_power_get` replaces the function :c:func:`fem_default_tx_gain_get`.
6067

6168
Recommended changes
6269
*******************

include/fem_al/fem_al.h

+17-10
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ enum fem_antenna {
3434
FEM_ANTENNA_2
3535
};
3636

37+
/**@brief Type holding Tx power control to be applied to front-end module.
38+
*
39+
* @note The value stored in this type is specific to the FEM type in use.
40+
*/
41+
typedef uint8_t fem_tx_power_control;
42+
3743
/**@brief Initialize the front-end module.
3844
*
3945
* @param[in] timer_instance Pointer to a 1-us resolution timer instance.
@@ -68,17 +74,18 @@ int fem_power_up(void);
6874
*/
6975
int fem_power_down(void);
7076

71-
/**@brief Configure Tx gain of the front-end module in arbitrary units.
77+
/**@brief Configure Tx power control of the front-end module.
7278
*
73-
* @param[in] gain Tx gain in arbitrary units specific for used front-end module implementation.
79+
* @param[in] tx_power_control Tx power control specific to the front-end module implementation.
7480
* For nRF21540 GPIO/SPI, this is a register value.
7581
* For nRF21540 GPIO, this is MODE pin value.
76-
* Check your front-end module product specification for gain value range.
82+
* Check your front-end module product specification for Tx power control value
83+
* range.
7784
*
7885
* @retval 0 If the operation was successful.
7986
* Otherwise, a (negative) error code is returned.
8087
*/
81-
int fem_tx_gain_set(uint32_t gain);
88+
int fem_tx_power_control_set(fem_tx_power_control tx_power_control);
8289

8390
/**@brief Get the default radio ramp-up time for reception or transmission with a given data rate
8491
* and modulation.
@@ -145,11 +152,11 @@ uint32_t fem_radio_tx_ramp_up_delay_get(bool fast, nrf_radio_mode_t mode);
145152
*/
146153
uint32_t fem_radio_rx_ramp_up_delay_get(bool fast, nrf_radio_mode_t mode);
147154

148-
/**@brief Set the front-end module gain and returns output power to be set on the radio peripheral
149-
* to get requested output power.
155+
/**@brief Set the front-end module Tx power control and returns output power
156+
* to be set on the radio peripheral to get requested output power.
150157
*
151158
* This function calculates power value for RADIO peripheral register and
152-
* sets front-end module gain value.
159+
* sets front-end module Tx power control value.
153160
*
154161
* @note If the exact value of @p power cannot be achieved, this function attempts to use less
155162
* power to not exceed the limits.
@@ -204,11 +211,11 @@ static inline int8_t fem_tx_output_power_max_get(uint16_t freq_mhz)
204211
return fem_tx_output_power_check(INT8_MAX, freq_mhz, true);
205212
}
206213

207-
/**@brief Get the front-end module default Tx gain.
214+
/**@brief Get the front-end module default Tx output power.
208215
*
209-
* @return The front-end module default Tx gain value.
216+
* @return The front-end module default Tx output power value.
210217
*/
211-
uint32_t fem_default_tx_gain_get(void);
218+
int8_t fem_default_tx_output_power_get(void);
212219

213220
/**@brief Apply the workaround for the Errata 254, 255, 256, 257 when appropriate.
214221
*

lib/fem_al/fem_al.c

+12-23
Original file line numberDiff line numberDiff line change
@@ -198,37 +198,26 @@ int fem_rx_configure(uint32_t ramp_up_time)
198198
return 0;
199199
}
200200

201-
int fem_tx_gain_set(uint32_t gain)
201+
int fem_tx_power_control_set(fem_tx_power_control tx_power_control)
202202
{
203203
int32_t err;
204-
mpsl_fem_gain_t fem_gain = { 0 };
204+
mpsl_fem_pa_power_control_t fem_pa_power_control = 0;
205205

206206
/* Fallback to FEM specific function. It can be used for checking the valid output power
207207
* range.
208208
*/
209-
if (fem_api->tx_gain_validate) {
210-
err = fem_api->tx_gain_validate(gain);
209+
if (fem_api->tx_power_control_validate) {
210+
err = fem_api->tx_power_control_validate(tx_power_control);
211211
if (err) {
212212
return err;
213213
}
214214
}
215215

216-
if (!fem_api->tx_default_gain_get) {
217-
/* Should not happen. */
218-
__ASSERT(false, "Missing FEM specific function for getting default Tx gain");
219-
return -EFAULT;
220-
}
221-
222-
/* We need to pass valid gain db value for given front-end module to have possibility to set
223-
* gain value directly in arbitrary value defined in your front-end module
224-
* product specification. In this case the default Tx gain value will be used.
225-
*/
226-
fem_gain.gain_db = fem_api->tx_default_gain_get();
227-
fem_gain.private_setting = gain;
216+
fem_pa_power_control = tx_power_control;
228217

229-
err = mpsl_fem_pa_gain_set(&fem_gain);
218+
err = mpsl_fem_pa_power_control_set(fem_pa_power_control);
230219
if (err) {
231-
printk("Failed to set front-end module gain (err %d)\n", err);
220+
printk("Failed to set front-end module Tx power control (err %d)\n", err);
232221
return -EINVAL;
233222
}
234223

@@ -268,10 +257,10 @@ int8_t fem_tx_output_power_prepare(int8_t power, int8_t *radio_tx_power, uint16_
268257

269258
*radio_tx_power = power_split.radio_tx_power;
270259

271-
err = mpsl_fem_pa_gain_set(&power_split.fem);
260+
err = mpsl_fem_pa_power_control_set(power_split.fem_pa_power_control);
272261
if (err) {
273262
/* Should not happen */
274-
printk("Failed to set front-end module gain (err %d)\n", err);
263+
printk("Failed to set front-end module Tx power control (err %d)\n", err);
275264
__ASSERT_NO_MSG(false);
276265
}
277266

@@ -285,10 +274,10 @@ int8_t fem_tx_output_power_check(int8_t power, uint16_t freq_mhz, bool tx_power_
285274
return mpsl_fem_tx_power_split(power, &power_split, freq_mhz, tx_power_ceiling);
286275
}
287276

288-
uint32_t fem_default_tx_gain_get(void)
277+
int8_t fem_default_tx_output_power_get(void)
289278
{
290-
if (fem_api->tx_default_gain_get) {
291-
return fem_api->tx_default_gain_get();
279+
if (fem_api->default_tx_output_power_get) {
280+
return fem_api->default_tx_output_power_get();
292281
}
293282

294283
return 0;

lib/fem_al/fem_interface.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ extern "C" {
2828
struct fem_interface_api {
2929
int (*power_up)(void);
3030
int (*power_down)(void);
31-
int (*tx_gain_validate)(uint32_t gain);
32-
uint32_t (*tx_default_gain_get)(void);
31+
int (*tx_power_control_validate)(fem_tx_power_control tx_power_control);
32+
int8_t (*default_tx_output_power_get)(void);
3333
uint32_t (*default_active_delay_calculate)(bool rx, nrf_radio_mode_t mode);
3434
int (*antenna_select)(enum fem_antenna ant);
3535
};

lib/fem_al/generic_fem.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ static int generic_fem_power_down(void)
148148
return err;
149149
}
150150

151-
static uint32_t tx_default_gain_get(void)
151+
static int8_t default_tx_output_power_get(void)
152152
{
153153
return DT_PROP(DT_NODELABEL(nrf_radio_fem), tx_gain_db);
154154
}
@@ -188,7 +188,7 @@ static const struct fem_interface_api generic_fem_api = {
188188
.power_up = generic_fem_power_up,
189189
.power_down = generic_fem_power_down,
190190
.antenna_select = generic_fem_antenna_select,
191-
.tx_default_gain_get = tx_default_gain_get,
191+
.default_tx_output_power_get = default_tx_output_power_get,
192192
};
193193

194194
static int generic_fem_setup(void)

lib/fem_al/nrf21540.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,16 @@ static int nrf21540_init(void)
6464
return 0;
6565
}
6666

67-
static int tx_gain_validate(uint32_t gain)
67+
static int tx_power_control_validate(fem_tx_power_control tx_power_control)
6868
{
6969
if (IS_ENABLED(CONFIG_MPSL_FEM_NRF21540_GPIO_SPI)) {
70-
return (gain > NRF21540_TX_GAIN_MAX) ? -EINVAL : 0;
70+
return (tx_power_control > NRF21540_TX_GAIN_MAX) ? -EINVAL : 0;
7171
} else {
72-
return ((gain == 0) || (gain == 1)) ? 0 : -EINVAL;
72+
return ((tx_power_control == 0) || (tx_power_control == 1)) ? 0 : -EINVAL;
7373
}
7474
}
7575

76-
static uint32_t tx_default_gain_get(void)
76+
static int8_t default_tx_output_power_get(void)
7777
{
7878
return CONFIG_MPSL_FEM_NRF21540_TX_GAIN_DB;
7979
}
@@ -108,8 +108,8 @@ static int nrf21540_antenna_select(enum fem_antenna ant)
108108
#endif /* DT_NODE_HAS_PROP(NRF21540_NODE, ant_sel_gpios) */
109109

110110
static const struct fem_interface_api nrf21540_api = {
111-
.tx_gain_validate = tx_gain_validate,
112-
.tx_default_gain_get = tx_default_gain_get,
111+
.tx_power_control_validate = tx_power_control_validate,
112+
.default_tx_output_power_get = default_tx_output_power_get,
113113
.antenna_select = nrf21540_antenna_select
114114
};
115115

0 commit comments

Comments
 (0)