LibDriver LLCC68  1.0.0
LLCC68 full-featured driver
driver_llcc68_cad_test.c
Go to the documentation of this file.
1 
37 #include "driver_llcc68_cad_test.h"
38 
39 static llcc68_handle_t gs_handle;
49 {
50  if (llcc68_irq_handler(&gs_handle) != 0)
51  {
52  return 1;
53  }
54  else
55  {
56  return 0;
57  }
58 }
59 
67 uint8_t llcc68_cad_test(void)
68 {
69  uint8_t res;
70  uint32_t reg;
71  uint8_t modulation;
72  uint8_t config;
73  llcc68_bool_t enable;
74 
75  /* link interface function */
89 
90  /* start cad test */
91  llcc68_interface_debug_print("llcc68: start cad test.\n");
92 
93  /* init the llcc68 */
94  res = llcc68_init(&gs_handle);
95  if (res != 0)
96  {
97  llcc68_interface_debug_print("llcc68: init failed.\n");
98 
99  return 1;
100  }
101 
102  /* enter standby */
104  if (res != 0)
105  {
106  llcc68_interface_debug_print("llcc68: set standby failed.\n");
107  (void)llcc68_deinit(&gs_handle);
108 
109  return 1;
110  }
111 
112  /* disable stop timer on preamble */
114  if (res != 0)
115  {
116  llcc68_interface_debug_print("llcc68: stop timer on preamble failed.\n");
117  (void)llcc68_deinit(&gs_handle);
118 
119  return 1;
120  }
121 
122  /* set dc dc ldo */
124  if (res != 0)
125  {
126  llcc68_interface_debug_print("llcc68: set regulator mode failed.\n");
127  (void)llcc68_deinit(&gs_handle);
128 
129  return 1;
130  }
131 
132  /* set +17dBm power */
133  res = llcc68_set_pa_config(&gs_handle, 0x02, 0x03);
134  if (res != 0)
135  {
136  llcc68_interface_debug_print("llcc68: set pa config failed.\n");
137  (void)llcc68_deinit(&gs_handle);
138 
139  return 1;
140  }
141 
142  /* enter to stdby rc mode */
144  if (res != 0)
145  {
146  llcc68_interface_debug_print("llcc68: set rx tx fallback mode failed.\n");
147  (void)llcc68_deinit(&gs_handle);
148 
149  return 1;
150  }
151 
152  /* set dio irq */
153  res = llcc68_set_dio_irq_params(&gs_handle, 0x03FF, 0x03FF, 0x0000, 0x0000);
154  if (res != 0)
155  {
156  llcc68_interface_debug_print("llcc68: set dio irq params failed.\n");
157  (void)llcc68_deinit(&gs_handle);
158 
159  return 1;
160  }
161 
162  /* clear irq status */
163  res = llcc68_clear_irq_status(&gs_handle, 0x03FF);
164  if (res != 0)
165  {
166  llcc68_interface_debug_print("llcc68: clear irq status failed.\n");
167  (void)llcc68_deinit(&gs_handle);
168 
169  return 1;
170  }
171 
172  /* set lora mode */
174  if (res != 0)
175  {
176  llcc68_interface_debug_print("llcc68: set packet type failed.\n");
177  (void)llcc68_deinit(&gs_handle);
178 
179  return 1;
180  }
181 
182  /* +17dBm */
183  res = llcc68_set_tx_params(&gs_handle, 17, LLCC68_RAMP_TIME_10US);
184  if (res != 0)
185  {
186  llcc68_interface_debug_print("llcc68: set tx params failed.\n");
187  (void)llcc68_deinit(&gs_handle);
188 
189  return 1;
190  }
191 
192  /* sf9, 125khz, cr4/5, disable low data rate optimize */
195  if (res != 0)
196  {
197  llcc68_interface_debug_print("llcc68: set lora modulation params failed.\n");
198  (void)llcc68_deinit(&gs_handle);
199 
200  return 1;
201  }
202 
203  /* convert the frequency */
204  res = llcc68_frequency_convert_to_register(&gs_handle, 480100000, (uint32_t *)&reg);
205  if (res != 0)
206  {
207  llcc68_interface_debug_print("llcc68: convert to register failed.\n");
208  (void)llcc68_deinit(&gs_handle);
209 
210  return 1;
211  }
212 
213  /* set the frequency */
214  res = llcc68_set_rf_frequency(&gs_handle, reg);
215  if (res != 0)
216  {
217  llcc68_interface_debug_print("llcc68: set rf frequency failed.\n");
218  (void)llcc68_deinit(&gs_handle);
219 
220  return 1;
221  }
222 
223  /* set base address */
224  res = llcc68_set_buffer_base_address(&gs_handle, 0x00, 0x00);
225  if (res != 0)
226  {
227  llcc68_interface_debug_print("llcc68: set buffer base address failed.\n");
228  (void)llcc68_deinit(&gs_handle);
229 
230  return 1;
231  }
232 
233  /* 1 lora symb num */
234  res = llcc68_set_lora_symb_num_timeout(&gs_handle, 0);
235  if (res != 0)
236  {
237  llcc68_interface_debug_print("llcc68: set lora symb num timeout failed.\n");
238  (void)llcc68_deinit(&gs_handle);
239 
240  return 1;
241  }
242 
243  /* reset stats */
244  res = llcc68_reset_stats(&gs_handle, 0x0000, 0x0000, 0x0000);
245  if (res != 0)
246  {
247  llcc68_interface_debug_print("llcc68: reset stats failed.\n");
248  (void)llcc68_deinit(&gs_handle);
249 
250  return 1;
251  }
252 
253  /* clear device errors */
254  res = llcc68_clear_device_errors(&gs_handle);
255  if (res != 0)
256  {
257  llcc68_interface_debug_print("llcc68: clear device errors failed.\n");
258  (void)llcc68_deinit(&gs_handle);
259 
260  return 1;
261  }
262 
263  /* set the lora sync word */
264  res = llcc68_set_lora_sync_word(&gs_handle, 0x1424);
265  if (res != 0)
266  {
267  llcc68_interface_debug_print("llcc68: set lora sync word failed.\n");
268  (void)llcc68_deinit(&gs_handle);
269 
270  return 1;
271  }
272 
273  /* get tx modulation */
274  res = llcc68_get_tx_modulation(&gs_handle, (uint8_t *)&modulation);
275  if (res != 0)
276  {
277  llcc68_interface_debug_print("llcc68: get tx modulation failed.\n");
278  (void)llcc68_deinit(&gs_handle);
279 
280  return 1;
281  }
282  modulation |= 0x04;
283 
284  /* set the tx modulation */
285  res = llcc68_set_tx_modulation(&gs_handle, modulation);
286  if (res != 0)
287  {
288  llcc68_interface_debug_print("llcc68: set tx modulation failed.\n");
289  (void)llcc68_deinit(&gs_handle);
290 
291  return 1;
292  }
293 
294  /* set the rx gain */
295  res = llcc68_set_rx_gain(&gs_handle, 0x94);
296  if (res != 0)
297  {
298  llcc68_interface_debug_print("llcc68: set rx gain failed.\n");
299  (void)llcc68_deinit(&gs_handle);
300 
301  return 1;
302  }
303 
304  /* set the ocp */
305  res = llcc68_set_ocp(&gs_handle, 0x38);
306  if (res != 0)
307  {
308  llcc68_interface_debug_print("llcc68: set ocp failed.\n");
309  (void)llcc68_deinit(&gs_handle);
310 
311  return 1;
312  }
313 
314  /* get the tx clamp config */
315  res = llcc68_get_tx_clamp_config(&gs_handle, (uint8_t *)&config);
316  if (res != 0)
317  {
318  llcc68_interface_debug_print("llcc68: get tx clamp config failed.\n");
319  (void)llcc68_deinit(&gs_handle);
320 
321  return 1;
322  }
323  config |= 0x1E;
324 
325  /* set the tx clamp config */
326  res = llcc68_set_tx_clamp_config(&gs_handle, config);
327  if (res != 0)
328  {
329  llcc68_interface_debug_print("llcc68: set tx clamp config failed.\n");
330  (void)llcc68_deinit(&gs_handle);
331 
332  return 1;
333  }
334 
335  /* set cad params */
338  0);
339  if (res != 0)
340  {
341  llcc68_interface_debug_print("llcc68: set cad params failed.\n");
342  (void)llcc68_deinit(&gs_handle);
343 
344  return 1;
345  }
346 
347  /* run the cad */
348  res = llcc68_lora_cad(&gs_handle, &enable);
349  if (res != 0)
350  {
351  llcc68_interface_debug_print("llcc68: lora cad failed.\n");
352  (void)llcc68_deinit(&gs_handle);
353 
354  return 1;
355  }
356 
357  /* output the result */
358  if (enable == LLCC68_BOOL_TRUE)
359  {
360  llcc68_interface_debug_print("llcc68: cad detected.\n");
361  }
362  else
363  {
364  llcc68_interface_debug_print("llcc68: cad not detected.\n");
365  }
366 
367  /* finish cad test */
368  llcc68_interface_debug_print("llcc68: finish cad test.\n");
369 
370  /* deinit */
371  (void)llcc68_deinit(&gs_handle);
372 
373  return 0;
374 }
driver llcc68 cad test header file
uint8_t llcc68_irq_handler(llcc68_handle_t *handle)
irq handler
llcc68_bool_t
llcc68 bool enumeration definition
Definition: driver_llcc68.h:63
uint8_t llcc68_set_rf_frequency(llcc68_handle_t *handle, uint32_t reg)
set the rf frequency
uint8_t llcc68_set_lora_modulation_params(llcc68_handle_t *handle, llcc68_lora_sf_t sf, llcc68_lora_bandwidth_t bw, llcc68_lora_cr_t cr, llcc68_bool_t low_data_rate_optimize_enable)
set the modulation params in LoRa mode
uint8_t llcc68_set_pa_config(llcc68_handle_t *handle, uint8_t pa_duty_cycle, uint8_t hp_max)
set the pa config
uint8_t llcc68_clear_device_errors(llcc68_handle_t *handle)
clear the device errors
uint8_t llcc68_clear_irq_status(llcc68_handle_t *handle, uint16_t clear_irq_param)
clear the irq status
uint8_t llcc68_deinit(llcc68_handle_t *handle)
close the chip
uint8_t llcc68_reset_stats(llcc68_handle_t *handle, uint16_t pkt_received, uint16_t pkt_crc_error, uint16_t pkt_length_header_error)
reset the stats
uint8_t llcc68_set_stop_timer_on_preamble(llcc68_handle_t *handle, llcc68_bool_t enable)
stop timer on preamble
uint8_t llcc68_set_regulator_mode(llcc68_handle_t *handle, llcc68_regulator_mode_t mode)
set the regulator_mode
uint8_t llcc68_set_rx_tx_fallback_mode(llcc68_handle_t *handle, llcc68_rx_tx_fallback_mode_t mode)
set the rx tx fallback mode
uint8_t llcc68_set_lora_symb_num_timeout(llcc68_handle_t *handle, uint8_t symb_num)
set the lora symbol number timeout
uint8_t llcc68_set_tx_params(llcc68_handle_t *handle, int8_t dbm, llcc68_ramp_time_t t)
set the tx params
uint8_t llcc68_set_cad_params(llcc68_handle_t *handle, llcc68_lora_cad_symbol_num_t num, uint8_t cad_det_peak, uint8_t cad_det_min, llcc68_lora_cad_exit_mode_t mode, uint32_t timeout)
set the cad params
uint8_t llcc68_set_dio_irq_params(llcc68_handle_t *handle, uint16_t irq_mask, uint16_t dio1_mask, uint16_t dio2_mask, uint16_t dio3_mask)
set the dio irq params
uint8_t llcc68_set_standby(llcc68_handle_t *handle, llcc68_clock_source_t src)
enter to the standby mode
uint8_t llcc68_set_buffer_base_address(llcc68_handle_t *handle, uint8_t tx_base_addr, uint8_t rx_base_addr)
set the buffer base address
uint8_t llcc68_frequency_convert_to_register(llcc68_handle_t *handle, uint32_t freq, uint32_t *reg)
convert the frequency to the register raw data
uint8_t llcc68_lora_cad(llcc68_handle_t *handle, llcc68_bool_t *enable)
run the cad
uint8_t llcc68_set_packet_type(llcc68_handle_t *handle, llcc68_packet_type_t type)
set the packet type
uint8_t llcc68_init(llcc68_handle_t *handle)
initialize the chip
@ LLCC68_LORA_BANDWIDTH_125_KHZ
@ LLCC68_BOOL_TRUE
Definition: driver_llcc68.h:65
@ LLCC68_BOOL_FALSE
Definition: driver_llcc68.h:64
@ LLCC68_CLOCK_SOURCE_XTAL_32MHZ
Definition: driver_llcc68.h:83
@ LLCC68_LORA_SF_9
@ LLCC68_REGULATOR_MODE_DC_DC_LDO
Definition: driver_llcc68.h:92
@ LLCC68_RAMP_TIME_10US
@ LLCC68_LORA_CAD_SYMBOL_NUM_2
@ LLCC68_LORA_CR_4_5
@ LLCC68_PACKET_TYPE_LORA
@ LLCC68_RX_TX_FALLBACK_MODE_STDBY_XOSC
@ LLCC68_LORA_CAD_EXIT_MODE_ONLY
uint8_t llcc68_interface_reset_gpio_init(void)
interface reset gpio init
uint8_t llcc68_interface_busy_gpio_read(uint8_t *value)
interface busy gpio read
uint8_t llcc68_interface_busy_gpio_deinit(void)
interface busy gpio deinit
uint8_t llcc68_interface_spi_deinit(void)
interface spi bus deinit
uint8_t llcc68_interface_spi_write_read(uint8_t *in_buf, uint32_t in_len, uint8_t *out_buf, uint32_t out_len)
interface spi bus write read
uint8_t llcc68_interface_reset_gpio_deinit(void)
interface reset gpio deinit
void llcc68_interface_receive_callback(uint16_t type, uint8_t *buf, uint16_t len)
interface receive callback
void llcc68_interface_debug_print(const char *const fmt,...)
interface print format data
void llcc68_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t llcc68_interface_spi_init(void)
interface spi bus init
uint8_t llcc68_interface_busy_gpio_init(void)
interface busy gpio init
uint8_t llcc68_interface_reset_gpio_write(uint8_t data)
interface reset gpio write
uint8_t llcc68_set_lora_sync_word(llcc68_handle_t *handle, uint16_t sync_word)
set the lora sync word
uint8_t llcc68_set_ocp(llcc68_handle_t *handle, uint8_t ocp)
set the ocp
uint8_t llcc68_set_tx_clamp_config(llcc68_handle_t *handle, uint8_t config)
set the tx clamp config
uint8_t llcc68_set_rx_gain(llcc68_handle_t *handle, uint8_t gain)
set the rx gain
uint8_t llcc68_set_tx_modulation(llcc68_handle_t *handle, uint8_t modulation)
set the tx modulation
uint8_t llcc68_get_tx_modulation(llcc68_handle_t *handle, uint8_t *modulation)
get the tx modulation
uint8_t llcc68_get_tx_clamp_config(llcc68_handle_t *handle, uint8_t *config)
get the tx clamp config
uint8_t llcc68_cad_test(void)
send test
uint8_t llcc68_cad_test_irq_handler(void)
llcc68 cad test irq
llcc68 handle structure definition