Nordic Semiconductor nRF5 AirFuel SDK  version 2.2.0
pru_wireless_debug.c File Reference
#include <string.h>
#include <stdio.h>
#include "pru_hw_config.h"
#include "pru_test_mux.h"
#include "softdevice_handler.h"
#include "wireless_debug.h"
#include "nrf_gzll.h"
#include "pru_sensors.h"
#include "nrf_assert.h"
#include "bsp.h"

Go to the source code of this file.

Macros

#define EVT_STRING_LENGTH_MAX   20
 
#define DEBUG_LINE_LENGTH   80
 
#define VRECT_INCREMENT   500
 
#define IRECT_INCREMENT   100
 
#define VOUT_INCREMENT   500
 
#define IOUT_INCREMENT   100
 
#define TEMPERATURE_INCREMENT   5
 
#define PIPE_NUMBER   0
 
#define TX_PAYLOAD_LENGTH   32
 

Functions

void wpts_test_evt_handle_cb (ble_wpts_t *p_wpts, ble_wpts_evt_t *p_evt)
 Override weak wpts_test_evt_handle_cb() More...
 
static void debug_print_string (const char *str)
 Function for writing a string to the debug packet. More...
 
bool pru_process_command_board (uint8_t cmd)
 Function for processing board specific test commands. More...
 
bool m_pru_process_command_common (uint8_t cmd)
 Function for processing common test commands. More...
 
static void cmd_poll (void)
 Get and process uart commands.
 
static bool debug_output_changed (void)
 Update m_debug_output variable. More...
 
void debug (void)
 Process debug commands.
 

Variables

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 pru_tmux_override_t override_values
 
static pru_control_t m_latest_control_data_received
 
static bool m_transmission_stopped = false
 
static bool m_debug_print = false
 
static uint8_t debug_pkt [TX_PAYLOAD_LENGTH]
 
bool gzll_initialized
 

Macro Definition Documentation

#define EVT_STRING_LENGTH_MAX   20

Max length of event message string

Definition at line 27 of file pru_wireless_debug.c.

#define DEBUG_LINE_LENGTH   80

Width of debug output table

Definition at line 28 of file pru_wireless_debug.c.

#define VRECT_INCREMENT   500

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

Definition at line 29 of file pru_wireless_debug.c.

#define IRECT_INCREMENT   100

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

Definition at line 30 of file pru_wireless_debug.c.

#define VOUT_INCREMENT   500

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

Definition at line 31 of file pru_wireless_debug.c.

#define IOUT_INCREMENT   100

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

Definition at line 32 of file pru_wireless_debug.c.

#define TEMPERATURE_INCREMENT   5

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

Definition at line 33 of file pru_wireless_debug.c.

#define PIPE_NUMBER   0

Use pipe 0 for the wireless debug interface (WDI)

Definition at line 34 of file pru_wireless_debug.c.

#define TX_PAYLOAD_LENGTH   32

Maximum PL length used by WDI

Definition at line 35 of file pru_wireless_debug.c.

Function Documentation

void wpts_test_evt_handle_cb ( ble_wpts_t p_wpts,
ble_wpts_evt_t p_evt 
)

Override weak wpts_test_evt_handle_cb()

Parameters
p_wptsWPT Service
p_evtWPT Service event

Definition at line 62 of file pru_wireless_debug.c.

63 {
65  {
67  }
68 }
PRU Control structure.
Definition: wpt.h:79
ble_wpts_evt_type_t evt_type
Definition: ble_wpts.h:43
union ble_wpts_evt_t::@0 data
static pru_control_t m_latest_control_data_received
pru_control_t pru_control
Definition: ble_wpts.h:46
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 75 of file pru_wireless_debug.c.

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

Function for processing board specific 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.
bool m_pru_process_command_common ( uint8_t  cmd)

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 108 of file pru_wireless_debug.c.

109 {
110  bool b_cmd_processed = true;
111  uint32_t err_code;
112 
114 
115  switch (cmd)
116  {
117  // Inc/dec , enable/disable commands
118 
119  case 'q':
120  debug_print_string("Power adjusted bit set\n\r");
122  break;
123 
124  case 'a':
125  debug_print_string("Power adjusted bit cleared\n\r");
127  break;
128 
129  case 'w':
131  sprintf(temp_string, "Inc IOUT -> %04X\n\r", override_values.iout);
133  break;
134 
135  case 's':
137  sprintf(temp_string, "Dec IOUT -> %04X\n\r", override_values.iout);
139  break;
140 
141  case 'e':
142  debug_print_string("NOT SUPPORTED\n\r");
143  break;
144 
145  case 'd':
146  debug_print_string("NOT SUPPORTED\n\r");
147  break;
148 
149  case 'r':
151  sprintf(temp_string, "Inc VOUT -> %04X\n\r", override_values.vout);
153  break;
154 
155  case 'f':
157  sprintf(temp_string, "Dec VOUT -> %04X\n\r", override_values.vout);
159  break;
160 
161  case 't':
162  debug_print_string("Wired charger on\n\r");
164  break;
165  case 'g':
166  debug_print_string("Wired charger off\n\r");
168  break;
169 
170  case 'y':
172  sprintf(temp_string, "Inc VRECT -> %4X\n\r", override_values.vrect);
174  break;
175  case 'h':
177  sprintf(temp_string, "Dec VRECT -> %04X\n\r", override_values.vrect);
179  break;
180 
181  case 'u':
183  sprintf(temp_string, "Inc IRECT -> %04X\n\r", override_values.irect);
185  break;
186  case 'j':
188  sprintf(temp_string, "Dec IRECT -> %04X\n\r", override_values.irect);
190  break;
191 
192  case 'i':
194  sprintf(temp_string, "Inc TEMP -> %04X\n\r", override_values.temperature);
196  break;
197  case 'k':
199  sprintf(temp_string, "Dec TEMP -> %04X\n\r", override_values.temperature);
201  break;
202 
203  case 'o':
204  debug_print_string("Test-mode enabled\n\r");
205  tmux_get_select(TMUX_SELECT_OVERRIDE);
206  tmux_set_select(TMUX_SELECT_OVERRIDE);
207  break;
208 
209  case 'p':
210  debug_print_string("SDK Version ");
212  debug_print_string("\n\r");
213  break;
214 
215  case 'l':
216  debug_print_string("Test-mode disabled\n\r");
217  tmux_get_select(TMUX_SELECT_NO_OVERRIDE);
218  tmux_set_select(TMUX_SELECT_NO_OVERRIDE);
219  break;
220 
221  // Single button commands
222  case 'z':
223  debug_print_string("Reset\r\n");
224  NVIC_SystemReset();
225  break;
226 
227  case 'x':
228  debug_print_string("Send Slave Security Request\n\r");
229 
230  ble_gap_sec_params_t sec_params;
231  memset(&sec_params, 0, sizeof(ble_gap_sec_params_t));
232  sec_params.mitm = 0;
233  sec_params.bond = 0;
234 
235  err_code = sd_ble_gap_authenticate(0, &sec_params); // Use 0 as we will only be connected to one device.
236  APP_ERROR_CHECK(err_code);
237 
238  break;
239 
240  case 'n':
241  debug_print_string("Charge complete\n\r");
243  break;
244 
245  case 'm':
246  debug_print_string("Charge incomplete\n\r");
248  break;
249 
250  case '1':
251  debug_print_string("Vrect to PRU_VRECT_UVLO\n\r");
253  break;
254 
255  case '2':
256  debug_print_string("Vrect to PRU_VRECT_BOOT\n\r");
258  break;
259 
260  case '3':
261  debug_print_string("Vrect to PRU_VRECT_MIN\n\r");
263  break;
264 
265  case '4':
266  debug_print_string("Vrect to PRU_VRECT_HIGH\n\r");
268  break;
269 
270  case '5':
271  debug_print_string("Vrect to PRU_VRECT_MAX\n\r");
273  break;
274 
275  case 'c':
276  case 'v':
278  {
279  debug_print_string("Stop packet transmission\n\r");
280  m_transmission_stopped = !m_transmission_stopped; // Need to do this before disabling the softdevice
281  (void)sd_softdevice_disable();
282  }
283 
284  else
285  {
286  debug_print_string("Start packet transmission\n\r");
288  nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;
289  SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL);
290  }
291  break;
292  case '6':
293  debug_print_string("\n\rpru\n\r");
294  break;
295  case '7':
296  case '8':
297  #ifdef DFU_SUPPORT
298  debug_print_string("Entering DFU mode ...\n\r");
299  dfu_start();
300  break;
301  #endif // DFU_SUPPORT
302 
303  case '9':
304  case ',':
305  case '.':
306  case '0':
307  default:
308  b_cmd_processed = false;
309  break;
310  }
311 
313 
314  return b_cmd_processed;
315 }
#define VOUT_INCREMENT
#define PRU_VRECT_MIN
Definition: pru_hw_config.h:25
#define PRU_VRECT_HIGH
Definition: pru_hw_config.h:27
#define VRECT_INCREMENT
#define PRU_VRECT_BOOT
Definition: pru_hw_config.h:23
static void debug_print_string(const char *str)
Function for writing a string to the debug packet.
void pru_tmux_override_values_set(pru_tmux_override_t *values)
Set override values.
Definition: pru_test_mux.c:146
#define PRU_VRECT_MAX
Definition: pru_hw_config.h:28
#define TEMPERATURE_INCREMENT
#define PRU_VRECT_UVLO
Definition: pru_hw_config.h:24
void pru_tmux_override_values_get(pru_tmux_override_t *values)
Get ovveride values.
Definition: pru_test_mux.c:152
void tmux_get_select(tmux_select_t select)
Select source for all **tmux**get() functions.
Definition: pru_test_mux.c:135
#define IRECT_INCREMENT
#define IOUT_INCREMENT
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
static char temp_string[DEBUG_LINE_LENGTH]
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 pru_tmux_override_t override_values
static bool m_transmission_stopped
static bool debug_output_changed ( void  )
static

Update m_debug_output variable.

Returns
true if debug output has changed.

Definition at line 340 of file pru_wireless_debug.c.

341 {
342  const pru_sensor_data_t * sensor_data;
343  bool changed = false;
344 
345  sensor_data = pru_sensors_data_get();
346 
348  {
349  changed = true;
351  }
352 
353  if(memcmp(&m_debug_output.sensor_data, sensor_data, sizeof(pru_sensor_data_t)) != 0)
354  {
355  changed = true;
356  memcpy(&m_debug_output.sensor_data, sensor_data, sizeof(pru_sensor_data_t));
357  }
358 
359  if(memcmp(&m_debug_output.control_data, &m_latest_control_data_received, sizeof(pru_control_t)))
360  {
361  changed = true;
362  memcpy(&m_debug_output.control_data, &m_latest_control_data_received, sizeof(pru_control_t));
363  }
364 
365  if(strlen(m_evt_evt_string) > 0)
366  {
367  changed = true;
368  }
369 
370  return changed;
371 }
static debug_output_t m_debug_output
PRU Control structure.
Definition: wpt.h:79
const pru_sensor_data_t * pru_sensors_data_get(void)
Get the latest data from the PRU sensors.
Definition: pru_sensors.c:146
Definition of PRU reporting data.
Definition: pru_sensors.h:26
static char m_evt_evt_string[EVT_STRING_LENGTH_MAX]
static pru_control_t m_latest_control_data_received
pru_sm_state_t pru_sm_execute(pru_sm_signal_type_t sig, pru_sm_state_vars_t *p_state)
Execute state machine.
Definition: pru_sm.c:71

Variable Documentation

char temp_string[DEBUG_LINE_LENGTH]
static

Debug string

Definition at line 48 of file pru_wireless_debug.c.

debug_output_t m_debug_output
static

Debug output collection

Definition at line 49 of file pru_wireless_debug.c.

char m_evt_evt_string[EVT_STRING_LENGTH_MAX] = ""
static

Event message string

Definition at line 50 of file pru_wireless_debug.c.

pru_tmux_override_t override_values
static

Local copy of override values

Definition at line 51 of file pru_wireless_debug.c.

pru_control_t m_latest_control_data_received
static

Local latest received control data

Definition at line 52 of file pru_wireless_debug.c.

bool m_transmission_stopped = false
static

Is transmission stopped?

Definition at line 53 of file pru_wireless_debug.c.

bool m_debug_print = false
static

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

Definition at line 54 of file pru_wireless_debug.c.

uint8_t debug_pkt[TX_PAYLOAD_LENGTH]
static

WDI packet

Definition at line 55 of file pru_wireless_debug.c.

bool gzll_initialized

true when gzll is initialized