Nordic Semiconductor nRF5 AirFuel SDK  version 2.2.0
ptu_wireless_debug.c File Reference

Source file for PTU UART test interface. More...

#include <string.h>
#include <stdio.h>
#include "wpt.h"
#include "nrf_soc.h"
#include "app_util_platform.h"
#include "ptu_sm.h"
#include "ptu_test_mux.h"
#include "ptu_registry.h"
#include "ptu_sensors.h"
#include "bsp.h"
#include "wireless_debug.h"
#include "nrf_gzll.h"
#include "nrf_assert.h"

Go to the source code of this file.

Macros

#define DEBUG_LINE_LENGTH   80
 
#define EVT_STRING_LENGTH_MAX   20
 
#define VTX_INCREMENT   1000
 
#define ITX_INCREMENT   100
 
#define TEMPERATURE_INCREMENT   10
 
#define PIPE_NUMBER   0
 
#define TX_PAYLOAD_LENGTH   32
 
#define UPDATE_INTERVAL   200
 

Functions

static void debug_print_string (const char *str)
 Function for writing a string to the debug packet. More...
 
static void m_set_load_variation_detected (void)
 Will syntesize a load representing a load variation to the sensors module. This will be set to true for 1.5 seconds.
 
static bool m_ptu_process_command_common (uint8_t cmd)
 Function for processing common test commands. More...
 
bool ptu_process_command_board (uint8_t cmd)
 Function for processing board related test commands. More...
 
void cmd_poll (void)
 Get and process uart commands.
 
void line_print (void)
 Print a DEBUG_LINE_LENGTH character long "horizontal line" to UART.
 
static bool debug_output_changed (void)
 Update m_debug_output variable. More...
 
void get_pru_data (int n, uint8_t *buf)
 Read PRU debug data. More...
 
void debug (void)
 Process debug commands.
 

Variables

static bool pru_changed [PTU_MAX_CONNECTIONS]
 
static char temp_string [DEBUG_LINE_LENGTH]
 
static debug_output_t m_debug_output
 
static char m_evt_evt_string [EVT_STRING_LENGTH_MAX] = ""
 
static ptu_tmux_override_t override_values
 
static bool m_simplified_beacon_print = false
 
static bool m_debug_print = false
 
static uint8_t debug_pkt [TX_PAYLOAD_LENGTH]
 
bool gzll_initialized
 

Detailed Description

Source file for PTU UART test interface.

Definition in file ptu_wireless_debug.c.

Macro Definition Documentation

#define DEBUG_LINE_LENGTH   80

Width of debug output table

Definition at line 34 of file ptu_wireless_debug.c.

#define EVT_STRING_LENGTH_MAX   20

Max length of event message string

Definition at line 35 of file ptu_wireless_debug.c.

#define VTX_INCREMENT   1000

Value by which the Vtx is incremented/decremented for each call to the simulated measurement function.

Definition at line 36 of file ptu_wireless_debug.c.

#define ITX_INCREMENT   100

Value by which the Itx is incremented/decremented for each call to the simulated measurement function.

Definition at line 37 of file ptu_wireless_debug.c.

#define TEMPERATURE_INCREMENT   10

Value by which the Temperature is incremented/decremented for each call to the simulated measurement function.

Definition at line 38 of file ptu_wireless_debug.c.

#define PIPE_NUMBER   0

Use pipe 0 for the wireless debug interface (WDI)

Definition at line 39 of file ptu_wireless_debug.c.

#define TX_PAYLOAD_LENGTH   32

Maximum PL length used by WDI

Definition at line 40 of file ptu_wireless_debug.c.

#define UPDATE_INTERVAL   200

ms between WDI packets

Definition at line 41 of file ptu_wireless_debug.c.

Function Documentation

static void debug_print_string ( const char *  str)
static

Function for writing a string to the debug packet.

Parameters
[in]strString to write

Definition at line 73 of file ptu_wireless_debug.c.

74 {
75  size_t len = strlen(str);
76  ASSERT(len < (TX_PAYLOAD_LENGTH-1));
77  if(len < (TX_PAYLOAD_LENGTH-1))
78  {
79  strncpy((char *)&debug_pkt[1], str, len);
80  debug_pkt[len+1] = 0;
81  m_debug_print = true;
82  }
83 }
#define TX_PAYLOAD_LENGTH
static uint8_t debug_pkt[TX_PAYLOAD_LENGTH]
static bool m_debug_print
static bool m_ptu_process_command_common ( uint8_t  cmd)
static

Function for processing common test commands.

Parameters
[in]cmdCommand code to process.
Return values
trueCommand code was processed by this function.
falseCommand code was not processed by this function.

Definition at line 124 of file ptu_wireless_debug.c.

125 {
126  bool cmd_processed = true;
127  uint32_t err_code;
128 
130 
131  switch (cmd)
132  {
133  case 'z':
134  // Reset
135  debug_print_string("\n\rCommand: Reset\r\n");
136  NVIC_SystemReset();
137  break;
138 
139  case 'b':
140  // Beacon debug print
142  debug_print_string("\n\rCommand: Beacon debug print disabled\r\n");
143  else
144  debug_print_string("\n\rCommand: Beacon debug print enabled\r\n");
146  break;
147 
148  case 'y':
150  sprintf(temp_string, "\n\rCommand: Inc VTX -> %04X\r\n", override_values.vtx);
152  break;
153 
154  case 'h':
156  sprintf(temp_string, "\n\rCommand: Dec VTX -> %04X\r\n", override_values.vtx);
158  break;
159 
160  case 'u':
162  sprintf(temp_string, "\n\rCommand: Inc ITX -> %04X\r\n", override_values.itx);
164  break;
165 
166  case 'j':
168  sprintf(temp_string, "\n\rCommand: Dec ITX -> %04X\r\n", override_values.itx);
170  break;
171 
172  case 'i':
174  sprintf(temp_string, "\n\rCommand: Inc temperature -> %04X\r\n", override_values.temperature);
176  break;
177 
178  case 'k':
180  sprintf(temp_string, "\n\rCommand: Dec temperature -> %04X\r\n", override_values.temperature);
181  debug_print_string("\n\r");
182  break;
183 
184  case 'o':
185  debug_print_string("\n\rCommand: Test-mode enabled\n\r");
186  tmux_set_select(TMUX_SELECT_OVERRIDE);
187  tmux_get_select(TMUX_SELECT_OVERRIDE);
188  break;
189 
190  case 'p':
191  debug_print_string("SDK Version ");
193  debug_print_string("\n\r");
194  break;
195 
196  case 'l':
197  debug_print_string("\n\rCommand: Test-mode disabled\n\r");
198  tmux_set_select(TMUX_SELECT_NO_OVERRIDE);
199  tmux_get_select(TMUX_SELECT_NO_OVERRIDE);
200  break;
201 
202  case 'n':
203  debug_print_string("\n\rCommand: TX power set to -40dBm\n\r");
204  err_code = sd_ble_gap_tx_power_set(-40);
205  APP_ERROR_CHECK(err_code);
206  break;
207 
208  case 'm':
209  debug_print_string("\n\rCommand: TX power set to PTU_OUTPUT_TX_POWER\n\r");
210  err_code = sd_ble_gap_tx_power_set(PTU_OUTPUT_TX_POWER);
211  APP_ERROR_CHECK(err_code);
212  break;
213 
214  case 'v':
215  debug_print_string("\n\rCommand: Set Load Variation TRUE\n\r");
217  break;
218 
219 
220  case '2':
221  debug_print_string("\n\rCommand: Resonator ON\n\r");
223  break;
224 
225  case '3':
226  debug_print_string("\n\rCommand: Resonator OFF\n\r");
228  break;
229 
230  case '4':
232  sprintf(temp_string, "\n\rCommand: Inc poweramp level -> %04X\r\n", override_values.power_amp_level);
234  break;
235 
236  case '5':
238  sprintf(temp_string, "\n\rCommand: Dec poweramp level -> %04X\r\n", override_values.power_amp_level);
240  break;
241 
242  case '6':
243  debug_print_string("\n\rptu\n\r");
244  break;
245 
246  case '7':
247  sprintf(temp_string, "ptu_reg_n_entries_get=%02X\r\n", ptu_reg_n_entries_get());
249  break;
250 
251  case '8':
252  #ifdef DFU_SUPPORT
253  debug_print_string("Entering DFU mode ...\n\r");
254  dfu_start();
255  break;
256  #endif //DFU_SUPPORT
257 
258  default:
259  cmd_processed = false;
260  break;
261  }
262 
264 
265  return cmd_processed;
266 }
static void m_set_load_variation_detected(void)
Will syntesize a load representing a load variation to the sensors module. This will be set to true f...
void ptu_tmux_override_values_set(ptu_tmux_override_t *values)
Set override values.
Definition: ptu_test_mux.c:138
#define ITX_INCREMENT
uint8_t ptu_reg_n_entries_get(void)
Get the number of devices currently in registry. This will include all connected devices, as well as all devices which is currently being registered.
Definition: ptu_registry.c:268
#define VTX_INCREMENT
static ptu_tmux_override_t override_values
static void debug_print_string(const char *str)
Function for writing a string to the debug packet.
void ptu_tmux_override_values_get(ptu_tmux_override_t *values)
Get ovveride values.
Definition: ptu_test_mux.c:144
#define PTU_OUTPUT_TX_POWER
Definition: ptu_config.h:31
static bool m_simplified_beacon_print
uint16_t power_amp_level
Definition: ptu_test_mux.h:38
#define POWERAMP_TEST_VAR_STEP_SIZE
Definition: ptu_hw_config.h:57
#define TEMPERATURE_INCREMENT
void tmux_get_select(tmux_select_t select)
Select source for all **tmux**get() functions.
Definition: pru_test_mux.c:135
void tmux_set_select(tmux_select_t select)
Select whether override values shall be used when writing to **hal**set() functions.
Definition: pru_test_mux.c:140
void dfu_start(void)
Starts DFU mode. The function writes a special value to retention register to tell bootloader to star...
Definition: common.c:93
#define SDK_VERSION
Definition: wpt.h:30
static char temp_string[DEBUG_LINE_LENGTH]
bool ptu_process_command_board ( uint8_t  cmd)

Function for processing board related test commands.

Parameters
[in]cmdCommand code to process.
Return values
trueCommand code was processed by this function.
falseCommand code was not processed by this function.
static bool debug_output_changed ( void  )
static

Update m_debug_output variable.

Returns
true if debug output has changed.

Definition at line 314 of file ptu_wireless_debug.c.

315 {
316  int i;
317  bool changed = false;
318  uint32_t err_code;
319  const ptu_sensor_data_t* sensor_data;
320  uint16_t current_powerlevel;
321  bool current_poweramp_status;
322  static bool prev_poweramp_status;
323  static uint32_t prev_powerlevel;
324  ptu_reg_item_t * p_reg_item;
325 
326  err_code = ptu_sensors_data_get(&sensor_data);
327  APP_ERROR_CHECK(err_code);
328 
329  if(m_simplified_beacon_print && m_debug_output.current_state == PTU_SM_STATE_POWER_SAVE)
330  {
331  (void)ptu_tmux_poweramp_enable_get(&current_poweramp_status);
332  (void)ptu_tmux_poweramp_level_get(&current_powerlevel);
333 
334  // Beacon status has changed
335  if((prev_poweramp_status != current_poweramp_status) || (prev_powerlevel != current_powerlevel))
336  {
337  if(current_poweramp_status && current_powerlevel == PTU_POWERAMP_INPUT_BEACON_SHORT)
338  debug_print_string("s");
339  else if(current_poweramp_status && current_powerlevel == PTU_POWERAMP_INPUT_BEACON_LONG)
340  {
341  debug_print_string("e\n\r");
342  debug_print_string("l");
343  }
344 
345  if(!current_poweramp_status)
346  debug_print_string("e\n\r");
347  }
348  prev_poweramp_status = current_poweramp_status;
349  prev_powerlevel = current_powerlevel;
350  }
351 
352 
353  if(m_debug_output.current_state != ptu_sm_execute(PTU_SM_SIGNAL_NULL, NULL))
354  {
355  changed = true;
356  m_debug_output.current_state = ptu_sm_execute(PTU_SM_SIGNAL_NULL, NULL);
357  }
358 
359  if(memcmp(&m_debug_output.sensor_data, sensor_data, sizeof(ptu_sensor_data_t)) != 0)
360  {
361  changed = true;
362  memcpy(&m_debug_output.sensor_data, sensor_data, sizeof(ptu_sensor_data_t));
363  m_debug_output.ptu_dbg_flags = (uint8_t)sensor_data->load_detected
364  | (uint8_t)sensor_data->load_var_detected << 1
365  | (uint8_t)sensor_data->rogue_obj_detected << 2;
366  }
367 
368  uint8_t registered_prus = 0;
369  for(i = 0; i < PTU_MAX_CONNECTIONS; i++)
370  {
371  pru_changed[i] = false;
372  (void)ptu_reg_item_get_from_index(i, &p_reg_item);
373 
374  if (p_reg_item->state == REG_ITEM_STATE_REGISTERED)
375  {
376  registered_prus |= 1 << i;
377  }
378  if(m_debug_output.reg_item_state[i] != p_reg_item->state)
379  {
380  if (p_reg_item->state == REG_ITEM_STATE_REGISTERED)
381  changed = pru_changed[i] = true;
382  m_debug_output.reg_item_state[i] = p_reg_item->state;
383  }
384 
385  if(m_debug_output.link_encrypted[i] != p_reg_item->link_encrypted)
386  {
387  if (p_reg_item->state == REG_ITEM_STATE_REGISTERED)
388  changed = pru_changed[i] = true;
389  m_debug_output.link_encrypted[i] = p_reg_item->link_encrypted;
390  }
391 
392  if(memcmp(&m_debug_output.dyn_params[i], &p_reg_item->prev_pru_dynamic, sizeof(pru_dynamic_t)) != 0)
393  {
394  if (p_reg_item->state == REG_ITEM_STATE_REGISTERED)
395  changed = pru_changed[i] = true;
396  memcpy(&m_debug_output.dyn_params[i], &p_reg_item->prev_pru_dynamic, sizeof(pru_dynamic_t));
397  }
398  }
399  if (m_debug_output.registered_prus != registered_prus)
400  {
401  m_debug_output.registered_prus = registered_prus;
402  changed = true;
403  }
404 
405  if(strlen(m_evt_evt_string) > 0)
406  {
407  changed = true;
408  }
409 
410  return changed;
411 }
static debug_output_t m_debug_output
Registry item.
Definition: ptu_registry.h:47
uint8_t link_encrypted
Definition: ptu_registry.h:68
#define PTU_POWERAMP_INPUT_BEACON_LONG
Definition: ptu_hw_config.h:60
uint32_t ptu_reg_item_get_from_index(uint8_t index, ptu_reg_item_t **item_p)
Get registry item from index in database. Index must be < PTU_MAX_CONNECTIONS.
Definition: ptu_registry.c:126
#define PTU_POWERAMP_INPUT_BEACON_SHORT
Definition: ptu_hw_config.h:59
static void debug_print_string(const char *str)
Function for writing a string to the debug packet.
static bool m_simplified_beacon_print
static bool pru_changed[PTU_MAX_CONNECTIONS]
uint32_t ptu_tmux_poweramp_enable_get(bool *enable)
Test wrapper for ptu_hal_poweramp_enable_get();.
Definition: ptu_test_mux.c:79
uint32_t ptu_sensors_data_get(const ptu_sensor_data_t **sensors_data)
Get the latest data read from the PTU sensors.
Definition: ptu_sensors.c:404
static char m_evt_evt_string[EVT_STRING_LENGTH_MAX]
pru_dynamic_t prev_pru_dynamic
Definition: ptu_registry.h:54
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
#define PTU_MAX_CONNECTIONS
Definition: ptu_config.h:29
ptu_reg_item_state_t state
Definition: ptu_registry.h:49
PRU Dynamic Parameter structure.
Definition: wpt.h:164
Definition of PTU sensor data.
Definition: ptu_hw_config.h:99
ptu_sm_state_t ptu_sm_execute(ptu_sm_signal_type_t signal, ptu_sm_state_vars_t *p_state)
State machine input signal handler.
Definition: ptu_sm.c:94
void get_pru_data ( int  n,
uint8_t *  buf 
)

Read PRU debug data.

Parameters
nPRU index
[in]bufPointer to debug buffer

Definition at line 417 of file ptu_wireless_debug.c.

418 {
419  buf[0] = (uint8_t)(m_debug_output.dyn_params[n].vrect >> 8);
420  buf[1] = (uint8_t)m_debug_output.dyn_params[n].vrect;
421  buf[2] = (uint8_t)(m_debug_output.dyn_params[n].irect >> 8);
422  buf[3] = (uint8_t)m_debug_output.dyn_params[n].irect;
423  buf[4] = (uint8_t)(m_debug_output.dyn_params[n].vout >> 8);
424  buf[5] = (uint8_t)m_debug_output.dyn_params[n].vout;
425  buf[6] = (uint8_t)(m_debug_output.dyn_params[n].iout >> 8);
426  buf[7] = (uint8_t)m_debug_output.dyn_params[n].iout;
427  buf[8] = (uint8_t)(m_debug_output.dyn_params[n].prect >> 8);
428  buf[9] = (uint8_t)m_debug_output.dyn_params[n].prect;
429  buf[10]= (uint8_t)m_debug_output.dyn_params[n].putil;
430  buf[11]= (uint8_t)(m_debug_output.dyn_params[n].temperature >> 8);
431  buf[12]= (uint8_t)m_debug_output.dyn_params[n].temperature;
432  buf[13]= (uint8_t)m_debug_output.dyn_params[n].alerts.charge_complete | (uint8_t)m_debug_output.link_encrypted[n] << 1;
433 }
static debug_output_t m_debug_output

Variable Documentation

bool pru_changed[PTU_MAX_CONNECTIONS]
static

Set to true if PRU params changed

Definition at line 58 of file ptu_wireless_debug.c.

char temp_string[DEBUG_LINE_LENGTH]
static

Debug string

Definition at line 59 of file ptu_wireless_debug.c.

debug_output_t m_debug_output
static

Debug output collection

Definition at line 60 of file ptu_wireless_debug.c.

char m_evt_evt_string[EVT_STRING_LENGTH_MAX] = ""
static

Event message string

Definition at line 61 of file ptu_wireless_debug.c.

ptu_tmux_override_t override_values
static

Local copy of override values

Definition at line 62 of file ptu_wireless_debug.c.

bool m_simplified_beacon_print = false
static

Simplify print flag. Used to decide if beacon debug data should be short.

Definition at line 63 of file ptu_wireless_debug.c.

bool m_debug_print = false
static

Used to signal that we are sending a string over air.

Definition at line 64 of file ptu_wireless_debug.c.

uint8_t debug_pkt[TX_PAYLOAD_LENGTH]
static

WDI packet

Definition at line 65 of file ptu_wireless_debug.c.

bool gzll_initialized

true when gzll is initialized