Nordic Semiconductor nRF5 AirFuel SDK  version 2.2.0
ptu_power_ctl.c File Reference
#include <math.h>
#include "ptu_power_ctl.h"
#include "ptu_test_mux.h"
#include "ptu_registry.h"
#include "nrf_assert.h"

Go to the source code of this file.

Functions

API implementation
void ptu_power_ctrl_adjust (void)
 Perform power control adjustments.
 
uint32_t ptu_power_ctrl_set_poweramp_input (uint16_t level)
 Perform power control adjustments. More...
 
void ptu_power_ctrl_set_disable_power_amplifier_adjustments (bool val)
 Enable/Disable adjustments of power amplifier (I_TX_COIL). More...
 
void ptu_power_ctrl_set_itx_val (ptu_tester_command_t cmd)
 Handle PTU tester power adjustment command. More...
 

Static functions and variables

enum  power_transfer_substates_t { POWER_TRANSFER_SUBSTATE_1_OPTIMAL, POWER_TRANSFER_SUBSTATE_2_LOW, POWER_TRANSFER_SUBSTATE_3_HIGH }
 Definition of power transfer substates. More...
 
static bool m_itx_adj_disabled = false
 
static power_transfer_substates_t m_substate
 
static uint16_t m_conn_handle_dominant
 
static void m_find_vrect_high_and_min (ptu_reg_item_t const *p_reg_item, uint16_t *p_vrect_high, uint16_t *p_vrect_min)
 Inspect registry item and find the current value of VRECT_MIN and VRECT_HIGH. More...
 
static void m_update_power_amplifier_adjustment_step_size (ptu_reg_item_t const *p_reg_item, bool *p_reduced_positive_step_size, bool *p_reduced_negative_step_size)
 Inspect registry item and see if reduced step size is allowed for increase and/or decrease. More...
 
static void m_update_power_amplifier_adjustment_step_size_for_dominant_pru (ptu_reg_item_t const *p_dominant_pru_reg_item, bool *p_reduced_positive_step_size, bool *p_reduced_negative_step_size)
 Inspect registry item for dominant PRU and see if reduced step size is allowed for negative and positive changes. More...
 
static void m_pru_scan_all (bool *p_reduced_positive_step_size, bool *p_reduced_negative_step_size, bool *p_increased_step_size)
 Scan through dynamic and static parameters received from all connected PRUs. More...
 
static uint32_t m_get_step_size (bool reduced_step_size, bool increased_step_size)
 Find step size to be used given permissions to use reduced and/or increased step size. More...
 
static uint32_t m_poweramp_input_step_up (bool reduced_positive_step_size, bool increased_step_size)
 Increase PTU poweramp output. More...
 
static uint32_t m_poweramp_input_step_down (bool reduced_negative_step_size, bool increased_step_size)
 Decrease PTU poweramp output. More...
 

Enumeration Type Documentation

Definition of power transfer substates.

Enumerator
POWER_TRANSFER_SUBSTATE_1_OPTIMAL 

All PRUs in optimal substate

POWER_TRANSFER_SUBSTATE_2_LOW 

>= 1 PRU in low voltage substate

POWER_TRANSFER_SUBSTATE_3_HIGH 

>= 1 PRU in high voltage substate

Definition at line 28 of file ptu_power_ctl.c.

Function Documentation

static void m_find_vrect_high_and_min ( ptu_reg_item_t const *  p_reg_item,
uint16_t *  p_vrect_high,
uint16_t *  p_vrect_min 
)
static

Inspect registry item and find the current value of VRECT_MIN and VRECT_HIGH.

If the registry item has set the optional dynamic values of these variables, these should be used.

Parameters
[in]p_reg_itemPointer to registry item to inspect.
[out]p_vrect_highPointer to vrect_high value.
[out]p_vrect_minPointer to vrect_min value.

Definition at line 49 of file ptu_power_ctl.c.

50 {
51  bool has_dynamic_vrect_min = BLE_WPTS_BITFIELD_READ(p_reg_item->prev_pru_dynamic.optional_fields,
54 
55  bool has_dynamic_vrect_high = BLE_WPTS_BITFIELD_READ(p_reg_item->prev_pru_dynamic.optional_fields,
58 
59  *p_vrect_high = has_dynamic_vrect_high ?
60  p_reg_item->prev_pru_dynamic.vrect_high_dyn :
61  p_reg_item->prev_pru_static.vrect_high_static;
62 
63  *p_vrect_min = has_dynamic_vrect_min ?
64  p_reg_item->prev_pru_dynamic.vrect_min_dyn :
65  p_reg_item->prev_pru_static.vrect_min_static;
66 }
#define BLE_WPTS_PRU_DYNAMIC_OPTION_VRECT_MIN_DYN_BITPOS
#define BLE_WPTS_PRU_DYNAMIC_OPTION_VRECT_HIGH_DYN_BITPOS
#define BLE_WPTS_PRU_DYNAMIC_OPTION_VRECT_MIN_DYN_BITMSK
#define BLE_WPTS_PRU_DYNAMIC_OPTION_VRECT_HIGH_DYN_BITMSK
#define BLE_WPTS_BITFIELD_READ(bitfield, msk, pos)
Read bitfield.
static void m_update_power_amplifier_adjustment_step_size ( ptu_reg_item_t const *  p_reg_item,
bool *  p_reduced_positive_step_size,
bool *  p_reduced_negative_step_size 
)
static

Inspect registry item and see if reduced step size is allowed for increase and/or decrease.

Will only set input parameters to true, never false.

Parameters
[in]p_reg_itemPointer to registry item to inspect.
[out]p_reduced_positive_step_sizePointer to bool saying whether positive step size should be reduced.
[out]p_reduced_negative_step_sizePointer to bool saying whether negative step size should be reduced.

Definition at line 74 of file ptu_power_ctl.c.

77 {
78  uint16_t vrect_high;
79  uint16_t vrect_min;
80 
81  m_find_vrect_high_and_min(p_reg_item, &vrect_high, &vrect_min);
82 
83  if(p_reg_item->prev_pru_dynamic.vrect > round(vrect_high * PTU_ALLOWED_REDUCED_POSITIVE_ITX_COIL_ADJUSTMENT_MULTIPLIER))
84  {
85  *p_reduced_positive_step_size = true;
86  }
87 
88  if(p_reg_item->prev_pru_dynamic.vrect < round(vrect_min * PTU_ALLOWED_REDUCED_NEGATIVE_ITX_COIL_ADJUSTMENT_MULTIPLIER))
89  {
90  *p_reduced_negative_step_size = true;
91  }
92 }
static void m_find_vrect_high_and_min(ptu_reg_item_t const *p_reg_item, uint16_t *p_vrect_high, uint16_t *p_vrect_min)
Inspect registry item and find the current value of VRECT_MIN and VRECT_HIGH.
Definition: ptu_power_ctl.c:49
#define PTU_ALLOWED_REDUCED_POSITIVE_ITX_COIL_ADJUSTMENT_MULTIPLIER
Definition: ptu_config.h:49
#define PTU_ALLOWED_REDUCED_NEGATIVE_ITX_COIL_ADJUSTMENT_MULTIPLIER
Definition: ptu_config.h:52
static void m_update_power_amplifier_adjustment_step_size_for_dominant_pru ( ptu_reg_item_t const *  p_dominant_pru_reg_item,
bool *  p_reduced_positive_step_size,
bool *  p_reduced_negative_step_size 
)
static

Inspect registry item for dominant PRU and see if reduced step size is allowed for negative and positive changes.

Will only set input parameters to true, never false.

Parameters
[in]p_dominant_pru_reg_itemPointer to dominant PRU registry item to inspect.
[out]p_reduced_positive_step_sizePointer to bool saying whether positive step size should be reduced.
[out]p_reduced_negative_step_sizePointer to bool saying whether negative step size should be reduced.

Definition at line 101 of file ptu_power_ctl.c.

104 {
105  uint16_t vrect = p_dominant_pru_reg_item->prev_pru_dynamic.vrect;
106  uint16_t vrect_set = p_dominant_pru_reg_item->prev_pru_static.vrect_set;
107 
108  // If V_RECT qualifies PTU for step size reduction
111  {
112  *p_reduced_negative_step_size = true;
113  *p_reduced_positive_step_size = true;
114  }
115 }
#define PTU_DOMINANT_PRU_LOWER_LIMIT_VRECTSET_MULTIPLIER_FOR_REDUCTION_IN_STEP_SIZE
Definition: ptu_config.h:60
#define PTU_DOMINANT_PRU_UPPER_LIMIT_VRECTSET_MULTIPLIER_FOR_REDUCTION_IN_STEP_SIZE
Definition: ptu_config.h:55
static void m_pru_scan_all ( bool *  p_reduced_positive_step_size,
bool *  p_reduced_negative_step_size,
bool *  p_increased_step_size 
)
static

Scan through dynamic and static parameters received from all connected PRUs.

Update following variables:

  • m_substate
  • m_conn_handle_dominant
  • p_reduced_positive_step_size and p_reduced_negative_step_size
Parameters
[out]p_reduced_positive_step_sizePointer to bool saying whether positive step size should be reduced
[out]p_reduced_negative_step_sizePointer to bool saying whether negative step size should be reduced
[out]p_increased_step_sizePointer to bool saying whether increased step size is allowed

Definition at line 129 of file ptu_power_ctl.c.

130 {
131  ptu_reg_item_t* registered_devices[PTU_MAX_CONNECTIONS];
132  uint8_t n_reg_devices = ptu_reg_registered_devices_get(registered_devices);
133  bool high_voltage_f = false;
134  bool low_voltage_f = false;
135  uint8_t l_putil_max = 0;
136  int8_t dominant_pru_index = -1;
137 
138  *p_reduced_positive_step_size = false;
139  *p_reduced_negative_step_size = false;
140  *p_increased_step_size = true;
141 
142  for(uint8_t i = 0; i < n_reg_devices; ++i)
143  {
144  m_update_power_amplifier_adjustment_step_size(registered_devices[i], p_reduced_positive_step_size, p_reduced_negative_step_size);
145 
146  if(registered_devices[i]->prev_pru_dynamic.putil > l_putil_max)
147  {
148  l_putil_max = registered_devices[i]->prev_pru_dynamic.putil;
149  dominant_pru_index = i;
150  }
151 
152  if(registered_devices[i]->prev_pru_static.pru_category < BLE_WPTS_PRU_CATEGORY_4)
153  {
154  *p_increased_step_size = false;
155  }
156 
157  // Note that the PRU Static bitfields vrect_min_static and vrect_high_static
158  // are updated to values from the last read PRU Dynamic characteristic if the
159  // respective optional fields are enabled.
160  if(registered_devices[i]->prev_pru_dynamic.vrect > registered_devices[i]->prev_pru_static.vrect_high_static - PTU_VRECT_HIGH_OFFSET)
161  {
162  high_voltage_f = true;
163  }
164 
165  else if(registered_devices[i]->prev_pru_dynamic.vrect < registered_devices[i]->prev_pru_static.vrect_min_static)
166  {
167  low_voltage_f = true;
168  }
169  }
170 
171  if(high_voltage_f)
172  {
174  }
175  else if(low_voltage_f)
176  {
178  }
179  else
180  {
182  }
183 
184  if(dominant_pru_index >= 0)
185  {
186  m_conn_handle_dominant = registered_devices[dominant_pru_index]->ble_wpts_c.conn_handle;
187 
188  m_update_power_amplifier_adjustment_step_size_for_dominant_pru(registered_devices[dominant_pru_index],
189  p_reduced_positive_step_size,
190  p_reduced_negative_step_size);
191  }
192 
193 }
Registry item.
Definition: ptu_registry.h:47
uint8_t putil
Definition: wpt.h:179
uint16_t conn_handle
Definition: ble_wpts_c.h:66
uint8_t ptu_reg_registered_devices_get(ptu_reg_item_t **registered_devices)
Get handles for all registered devices.
Definition: ptu_registry.c:254
ble_wpts_c_t ble_wpts_c
Definition: ptu_registry.h:52
#define BLE_WPTS_PRU_CATEGORY_4
static power_transfer_substates_t m_substate
Definition: ptu_power_ctl.c:38
#define PTU_VRECT_HIGH_OFFSET
Definition: ptu_hw_config.h:80
uint16_t vrect_high_static
Definition: wpt.h:97
pru_static_t prev_pru_static
Definition: ptu_registry.h:53
static void m_update_power_amplifier_adjustment_step_size_for_dominant_pru(ptu_reg_item_t const *p_dominant_pru_reg_item, bool *p_reduced_positive_step_size, bool *p_reduced_negative_step_size)
Inspect registry item for dominant PRU and see if reduced step size is allowed for negative and posit...
uint16_t vrect_min_static
Definition: wpt.h:96
pru_dynamic_t prev_pru_dynamic
Definition: ptu_registry.h:54
static void m_update_power_amplifier_adjustment_step_size(ptu_reg_item_t const *p_reg_item, bool *p_reduced_positive_step_size, bool *p_reduced_negative_step_size)
Inspect registry item and see if reduced step size is allowed for increase and/or decrease...
Definition: ptu_power_ctl.c:74
static uint16_t m_conn_handle_dominant
Definition: ptu_power_ctl.c:40
#define PTU_MAX_CONNECTIONS
Definition: ptu_config.h:29
static uint32_t m_get_step_size ( bool  reduced_step_size,
bool  increased_step_size 
)
static

Find step size to be used given permissions to use reduced and/or increased step size.

Parameters
reduced_step_sizeIs reduced step size allowed?
increased_step_sizeIs increased step size allowed?
Returns
Resulting POWERAMP step size

Definition at line 200 of file ptu_power_ctl.c.

201 {
202  if(reduced_step_size)
203  {
205  }
206 
207  else if(increased_step_size)
208  {
210  }
211 
213 }
#define PTU_POWERAMP_INPUT_STEP_SIZE_INCREASED
Definition: ptu_hw_config.h:79
#define PTU_POWERAMP_INPUT_STEP_SIZE_REDUCED
Definition: ptu_hw_config.h:76
#define PTU_POWERAMP_INPUT_STEP_SIZE
Definition: ptu_hw_config.h:75
static uint32_t m_poweramp_input_step_up ( bool  reduced_positive_step_size,
bool  increased_step_size 
)
static

Increase PTU poweramp output.

Parameters
reduced_positive_step_sizeIs step size reduced?
increased_step_sizeIs step size increased?
Returns
NRF_SUCCESS if successful, otherwise an error code will be returned.

Definition at line 221 of file ptu_power_ctl.c.

222 {
223  uint32_t err_code;
224  uint16_t level_to_set;
225  uint16_t current_level;
226  uint16_t step_size;
227 
228  err_code = ptu_tmux_poweramp_level_get(&current_level);
229 
230  if(err_code != NRF_SUCCESS)
231  {
232  return err_code;
233  }
234 
235  step_size = m_get_step_size(reduced_positive_step_size, increased_step_size);
236 
237  if (current_level + step_size > PTU_POWERAMP_INPUT_MAX)
238  {
239  level_to_set = PTU_POWERAMP_INPUT_MAX;
240  }
241 
242  else
243  {
244  level_to_set = current_level + step_size;
245  }
246 
247  return ptu_power_ctrl_set_poweramp_input(level_to_set);
248 }
#define PTU_POWERAMP_INPUT_MAX
Definition: ptu_hw_config.h:73
static uint32_t m_get_step_size(bool reduced_step_size, bool increased_step_size)
Find step size to be used given permissions to use reduced and/or increased step size.
uint32_t ptu_power_ctrl_set_poweramp_input(uint16_t level)
Perform power control adjustments.
uint32_t ptu_tmux_poweramp_level_get(uint16_t *p_level)
Test wrapper for ptu_hal_poweramp_level_get().
Definition: ptu_test_mux.c:86
static uint32_t m_poweramp_input_step_down ( bool  reduced_negative_step_size,
bool  increased_step_size 
)
static

Decrease PTU poweramp output.

Parameters
reduced_negative_step_sizeIs step size reduced?
increased_step_sizeIs step size increased?
Return values
NRF_SUCCESSif successful, otherwise an error code will be returned.

Definition at line 255 of file ptu_power_ctl.c.

256 {
257  uint32_t err_code;
258  uint16_t level_to_set;
259  uint16_t current_level;
260  uint16_t step_size;
261 
262  err_code = ptu_tmux_poweramp_level_get(&current_level);
263 
264  if(err_code != NRF_SUCCESS)
265  {
266  return err_code;
267  }
268 
269  step_size = m_get_step_size(reduced_negative_step_size, increased_step_size);
270 
271  if (((int32_t)current_level - (int32_t)step_size) < PTU_POWERAMP_INPUT_NOMINAL)
272  {
273  level_to_set = PTU_POWERAMP_INPUT_NOMINAL;
274  }
275 
276  else
277  {
278  level_to_set = current_level - step_size;
279  }
280 
281  return ptu_power_ctrl_set_poweramp_input(level_to_set);
282 }
static uint32_t m_get_step_size(bool reduced_step_size, bool increased_step_size)
Find step size to be used given permissions to use reduced and/or increased step size.
uint32_t ptu_power_ctrl_set_poweramp_input(uint16_t level)
Perform power control adjustments.
#define PTU_POWERAMP_INPUT_NOMINAL
Definition: ptu_hw_config.h:72
uint32_t ptu_tmux_poweramp_level_get(uint16_t *p_level)
Test wrapper for ptu_hal_poweramp_level_get().
Definition: ptu_test_mux.c:86

Variable Documentation

bool m_itx_adj_disabled = false
static

Have we been told by PRU to only adjust poweramp input by test commands?

Definition at line 36 of file ptu_power_ctl.c.

power_transfer_substates_t m_substate
static

Current substate. Updated by pru_scan_all()

Definition at line 38 of file ptu_power_ctl.c.

uint16_t m_conn_handle_dominant
static

Handle to dominant PRU. Updated by pru_scan_all()

Definition at line 40 of file ptu_power_ctl.c.