LibDriver BMP388
Loading...
Searching...
No Matches
driver_bmp388_fifo_test.c
Go to the documentation of this file.
1
37
39
40static bmp388_handle_t gs_handle;
41static volatile uint8_t gs_fifo_full_flag;
42static volatile uint8_t gs_fifo_watermark_flag;
43static uint8_t gs_buf[512];
44static bmp388_frame_t gs_frame[256];
45
54{
55 /* run irq handler */
56 if (bmp388_irq_handler(&gs_handle) != 0)
57 {
58 return 1;
59 }
60 else
61 {
62 return 0;
63 }
64}
65
71static void a_bmp388_interface_test_receive_callback(uint8_t type)
72{
73 switch (type)
74 {
76 {
77 if (gs_fifo_watermark_flag == 0)
78 {
79 uint16_t len;
80
81 len = 512;
82 /* read fifo */
83 if (bmp388_read_fifo(&gs_handle, (uint8_t *)gs_buf, (uint16_t *)&len) != 0)
84 {
85 bmp388_interface_debug_print("bmp388: read fifo failed.\n");
86
87 return;
88 }
89 bmp388_interface_debug_print("bmp388: read fifo with length %d.\n", len);
90 gs_fifo_watermark_flag = 1;
91 }
92
93 break;
94 }
96 {
97 uint16_t len;
98 uint16_t frame_len;
99
100 len = 512;
101 /* read fifo */
102 if (bmp388_read_fifo(&gs_handle, (uint8_t *)gs_buf, (uint16_t *)&len) != 0)
103 {
104 bmp388_interface_debug_print("bmp388: read fifo failed.\n");
105
106 return;
107 }
108 if (len > 4)
109 {
110 bmp388_interface_debug_print("bmp388: clear fifo with length %d.\n", len);
111 frame_len = 256;
112
113 /* parse fifo */
114 if (bmp388_fifo_parse(&gs_handle, (uint8_t *)gs_buf, len, (bmp388_frame_t *)gs_frame, (uint16_t *)&frame_len) != 0)
115 {
116 bmp388_interface_debug_print("bmp388: fifo parse failed.\n");
117
118 return;
119 }
120 else
121 {
122 bmp388_interface_debug_print("bmp388: fifo parse success and total frame is %d.\n", frame_len);
123 }
124 }
125 gs_fifo_full_flag = 1;
126
127 break;
128 }
130 {
131 break;
132 }
133 default :
134 {
135 break;
136 }
137 }
138}
139
150uint8_t bmp388_fifo_test(bmp388_interface_t interface, bmp388_address_t addr_pin, uint32_t times)
151{
152 uint8_t res;
153 uint32_t i;
154 bmp388_info_t info;
155
156 /* link functions */
168 DRIVER_BMP388_LINK_RECEIVE_CALLBACK(&gs_handle, a_bmp388_interface_test_receive_callback);
169
170 /* bmp388 info */
171 res = bmp388_info(&info);
172 if (res != 0)
173 {
174 bmp388_interface_debug_print("bmp388: get info failed.\n");
175
176 return 1;
177 }
178 else
179 {
180 /* print chip information */
181 bmp388_interface_debug_print("bmp388: chip is %s.\n", info.chip_name);
182 bmp388_interface_debug_print("bmp388: manufacturer is %s.\n", info.manufacturer_name);
183 bmp388_interface_debug_print("bmp388: interface is %s.\n", info.interface);
184 bmp388_interface_debug_print("bmp388: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
185 bmp388_interface_debug_print("bmp388: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
186 bmp388_interface_debug_print("bmp388: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
187 bmp388_interface_debug_print("bmp388: max current is %0.2fmA.\n", info.max_current_ma);
188 bmp388_interface_debug_print("bmp388: max temperature is %0.1fC.\n", info.temperature_max);
189 bmp388_interface_debug_print("bmp388: min temperature is %0.1fC.\n", info.temperature_min);
190 }
191
192 /* start fifo test */
193 bmp388_interface_debug_print("bmp388: start fifo test.\n");
194
195 /* set interface */
196 res = bmp388_set_interface(&gs_handle, interface);
197 if (res != 0)
198 {
199 bmp388_interface_debug_print("bmp388: set interface failed.\n");
200
201 return 1;
202 }
203
204 /* set addr pin */
205 res = bmp388_set_addr_pin(&gs_handle, addr_pin);
206 if (res != 0)
207 {
208 bmp388_interface_debug_print("bmp388: set addr pin failed.\n");
209
210 return 1;
211 }
212
213 /* bmp388 init */
214 res = bmp388_init(&gs_handle);
215 if (res != 0)
216 {
217 bmp388_interface_debug_print("bmp388: init failed.\n");
218
219 return 1;
220 }
221
222 /* set spi wire 4 */
223 res = bmp388_set_spi_wire(&gs_handle, BMP388_SPI_WIRE_4);
224 if (res != 0)
225 {
226 bmp388_interface_debug_print("bmp388: set spi wire failed.\n");
227 (void)bmp388_deinit(&gs_handle);
228
229 return 1;
230 }
231
232 /* enable iic watchdog timer */
234 if (res != 0)
235 {
236 bmp388_interface_debug_print("bmp388: set iic watchdog timer failed.\n");
237 (void)bmp388_deinit(&gs_handle);
238
239 return 1;
240 }
241
242 /* set iic watchdog period 40 ms */
244 if (res != 0)
245 {
246 bmp388_interface_debug_print("bmp388: set iic watchdog period failed.\n");
247 (void)bmp388_deinit(&gs_handle);
248
249 return 1;
250 }
251
252 /* enable fifo */
253 res = bmp388_set_fifo(&gs_handle, BMP388_BOOL_TRUE);
254 if (res != 0)
255 {
256 bmp388_interface_debug_print("bmp388: set fifo failed.\n");
257 (void)bmp388_deinit(&gs_handle);
258
259 return 1;
260 }
261
262 /* enable fifo stop on full */
264 if (res != 0)
265 {
266 bmp388_interface_debug_print("bmp388: set fifo stop on full failed.\n");
267 (void)bmp388_deinit(&gs_handle);
268
269 return 1;
270 }
271
272 /* set fifo watermark 500 */
273 res = bmp388_set_fifo_watermark(&gs_handle, 500);
274 if (res != 0)
275 {
276 bmp388_interface_debug_print("bmp388: set fifo watermark failed.\n");
277 (void)bmp388_deinit(&gs_handle);
278
279 return 1;
280 }
281
282 /* enable fifo sensor time on */
284 if (res != 0)
285 {
286 bmp388_interface_debug_print("bmp388: set fifo sensor time on failed.\n");
287 (void)bmp388_deinit(&gs_handle);
288
289 return 1;
290 }
292 if (res != 0)
293 {
294 bmp388_interface_debug_print("bmp388: set fifo sensor time on failed.\n");
295 (void)bmp388_deinit(&gs_handle);
296
297 return 1;
298 }
300 if (res != 0)
301 {
302 bmp388_interface_debug_print("bmp388: set fifo temperature on failed.\n");
303 (void)bmp388_deinit(&gs_handle);
304
305 return 1;
306 }
307 res = bmp388_set_fifo_subsampling(&gs_handle, 0);
308 if (res != 0)
309 {
310 bmp388_interface_debug_print("bmp388: set fifo subsampling failed.\n");
311 (void)bmp388_deinit(&gs_handle);
312
313 return 1;
314 }
316 if (res != 0)
317 {
318 bmp388_interface_debug_print("bmp388: set fifo data source failed.\n");
319 (void)bmp388_deinit(&gs_handle);
320
321 return 1;
322 }
323
324 /* set interrupt pin type push-pull */
326 if (res != 0)
327 {
328 bmp388_interface_debug_print("bmp388: set interrupt pin type failed.\n");
329 (void)bmp388_deinit(&gs_handle);
330
331 return 1;
332 }
333
334 /* set interrupt active level higher */
336 if (res != 0)
337 {
338 bmp388_interface_debug_print("bmp388: set interrupt active level failed.\n");
339 (void)bmp388_deinit(&gs_handle);
340
341 return 1;
342 }
343
344 /* disable latch interrupt pin and interrupt status */
346 if (res != 0)
347 {
348 bmp388_interface_debug_print("bmp388: set set latch interrupt pin and interrupt status failed.\n");
349 (void)bmp388_deinit(&gs_handle);
350
351 return 1;
352 }
353
354 /* enable interrupt fifo watermark */
356 if (res != 0)
357 {
358 bmp388_interface_debug_print("bmp388: set interrupt fifo watermark failed.\n");
359 (void)bmp388_deinit(&gs_handle);
360
361 return 1;
362 }
363
364 /* enable interrupt fifo full */
366 if (res != 0)
367 {
368 bmp388_interface_debug_print("bmp388: set interrupt fifo full failed.\n");
369 (void)bmp388_deinit(&gs_handle);
370
371 return 1;
372 }
373
374 /* disable interrupt data ready */
376 if (res != 0)
377 {
378 bmp388_interface_debug_print("bmp388: set interrupt data ready failed.\n");
379 (void)bmp388_deinit(&gs_handle);
380
381 return 1;
382 }
383
384 /* enable pressure */
385 res = bmp388_set_pressure(&gs_handle, BMP388_BOOL_TRUE);
386 if (res != 0)
387 {
388 bmp388_interface_debug_print("bmp388: set pressure failed.\n");
389 (void)bmp388_deinit(&gs_handle);
390
391 return 1;
392 }
393
394 /* enable temperature */
395 res = bmp388_set_temperature(&gs_handle, BMP388_BOOL_TRUE);
396 if (res != 0)
397 {
398 bmp388_interface_debug_print("bmp388: set temperature failed.\n");
399 (void)bmp388_deinit(&gs_handle);
400
401 return 1;
402 }
403
404 /* set pressure oversampling x32 */
406 if (res != 0)
407 {
408 bmp388_interface_debug_print("bmp388: set pressure oversampling failed.\n");
409 (void)bmp388_deinit(&gs_handle);
410
411 return 1;
412 }
413
414 /* set temperature oversampling x2 */
416 if (res != 0)
417 {
418 bmp388_interface_debug_print("bmp388: set temperature oversampling failed.\n");
419 (void)bmp388_deinit(&gs_handle);
420
421 return 1;
422 }
423
424 /* set odr 12.5Hz */
425 res = bmp388_set_odr(&gs_handle, BMP388_ODR_12P5_HZ);
426 if (res != 0)
427 {
428 bmp388_interface_debug_print("bmp388: set odr failed.\n");
429 (void)bmp388_deinit(&gs_handle);
430
431 return 1;
432 }
433
434 /* set filter coefficient 15 */
436 if (res != 0)
437 {
438 bmp388_interface_debug_print("bmp388: set filter coefficient failed.\n");
439 (void)bmp388_deinit(&gs_handle);
440
441 return 1;
442 }
443
444 /* set normal mode */
445 res = bmp388_set_mode(&gs_handle, BMP388_MODE_NORMAL_MODE);
446 if (res != 0)
447 {
448 bmp388_interface_debug_print("bmp388: set mode failed.\n");
449 (void)bmp388_deinit(&gs_handle);
450
451 return 1;
452 }
453
454 /* fifo watermark test */
455 bmp388_interface_debug_print("bmp388: fifo watermark test.\n");
456 for (i = 0; i < times; i++)
457 {
458 uint32_t num;
459
460 gs_fifo_watermark_flag = 0;
461 num = 0;
462 while(gs_fifo_watermark_flag == 0)
463 {
464 num++;
465 if (num > 5000)
466 {
467 bmp388_interface_debug_print("bmp388: fifo interrupt failed.\n");
468 (void)bmp388_deinit(&gs_handle);
469
470 return 1;
471 }
473 }
474 }
475
476 /* fifo full test */
477 bmp388_interface_debug_print("bmp388: fifo full test.\n");
478
479 for (i = 0; i < times; i++)
480 {
481 uint32_t num;
482
483 gs_fifo_watermark_flag = 2;
484 gs_fifo_full_flag = 0;
485 num = 0;
486 while (gs_fifo_full_flag == 0)
487 {
488 num++;
489 if (num > 5000)
490 {
491 bmp388_interface_debug_print("bmp388: fifo interrupt failed.\n");
492 (void)bmp388_deinit(&gs_handle);
493
494 return 1;
495 }
497 }
498 }
499
500 /* set sleep mode */
501 res = bmp388_set_mode(&gs_handle, BMP388_MODE_SLEEP_MODE);
502 if (res != 0)
503 {
504 bmp388_interface_debug_print("bmp388: set mode failed.\n");
505 (void)bmp388_deinit(&gs_handle);
506
507 return 1;
508 }
509
510 /* finish fifo test */
511 bmp388_interface_debug_print("bmp388: finish fifo test.\n");
512 (void)bmp388_deinit(&gs_handle);
513
514 return 0;
515}
driver bmp388 fifo test header file
uint8_t bmp388_set_odr(bmp388_handle_t *handle, bmp388_odr_t odr)
set the output data rate
uint8_t bmp388_set_pressure(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the pressure
bmp388_interface_t
bmp388 interface enumeration definition
uint8_t bmp388_init(bmp388_handle_t *handle)
initialize the chip
uint8_t bmp388_set_spi_wire(bmp388_handle_t *handle, bmp388_spi_wire_t wire)
set the spi wire
uint8_t bmp388_set_iic_watchdog_timer(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the iic watchdog timer
struct bmp388_handle_s bmp388_handle_t
bmp388 handle structure definition
uint8_t bmp388_set_pressure_oversampling(bmp388_handle_t *handle, bmp388_oversampling_t oversampling)
set the pressure oversampling
struct bmp388_frame_s bmp388_frame_t
bmp388 frame structure definition
uint8_t bmp388_set_temperature(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the temperature
uint8_t bmp388_set_filter_coefficient(bmp388_handle_t *handle, bmp388_filter_coefficient_t coefficient)
set the filter coefficient
uint8_t bmp388_irq_handler(bmp388_handle_t *handle)
irq handler
uint8_t bmp388_deinit(bmp388_handle_t *handle)
close the chip
uint8_t bmp388_set_interface(bmp388_handle_t *handle, bmp388_interface_t interface)
set the interface
uint8_t bmp388_set_iic_watchdog_period(bmp388_handle_t *handle, bmp388_iic_watchdog_period_t period)
set the iic watchdog period
uint8_t bmp388_set_mode(bmp388_handle_t *handle, bmp388_mode_t mode)
set the chip mode
uint8_t bmp388_set_temperature_oversampling(bmp388_handle_t *handle, bmp388_oversampling_t oversampling)
set the temperature oversampling
uint8_t bmp388_set_addr_pin(bmp388_handle_t *handle, bmp388_address_t addr_pin)
set the iic address pin
struct bmp388_info_s bmp388_info_t
bmp388 information structure definition
uint8_t bmp388_info(bmp388_info_t *info)
get chip's information
bmp388_address_t
bmp388 address enumeration definition
@ BMP388_OVERSAMPLING_x32
@ BMP388_OVERSAMPLING_x2
@ BMP388_SPI_WIRE_4
@ BMP388_FILTER_COEFFICIENT_15
@ BMP388_ODR_12P5_HZ
@ BMP388_INTERRUPT_ACTIVE_LEVEL_HIGHER
@ BMP388_BOOL_TRUE
@ BMP388_BOOL_FALSE
@ BMP388_INTERRUPT_STATUS_FIFO_FULL
@ BMP388_INTERRUPT_STATUS_DATA_READY
@ BMP388_INTERRUPT_STATUS_FIFO_WATERMARK
@ BMP388_FIFO_DATA_SOURCE_FILTERED
@ BMP388_MODE_SLEEP_MODE
@ BMP388_MODE_NORMAL_MODE
@ BMP388_INTERRUPT_PIN_TYPE_PUSH_PULL
@ BMP388_IIC_WATCHDOG_PERIOD_40_MS
uint8_t bmp388_read_fifo(bmp388_handle_t *handle, uint8_t *buf, uint16_t *len)
read the fifo
uint8_t bmp388_set_fifo_temperature_on(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo temperature on
uint8_t bmp388_fifo_parse(bmp388_handle_t *handle, uint8_t *buf, uint16_t buf_len, bmp388_frame_t *frame, uint16_t *frame_len)
parse the fifo data
uint8_t bmp388_set_fifo_watermark(bmp388_handle_t *handle, uint16_t watermark)
set the fifo watermark
uint8_t bmp388_set_fifo_subsampling(bmp388_handle_t *handle, uint8_t subsample)
set the fifo subsampling
uint8_t bmp388_set_fifo_data_source(bmp388_handle_t *handle, bmp388_fifo_data_source_t source)
set the fifo data source
uint8_t bmp388_set_fifo_stop_on_full(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo stopping on full
uint8_t bmp388_set_fifo_sensortime_on(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo sensor time on
uint8_t bmp388_set_fifo_pressure_on(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo pressure on
uint8_t bmp388_set_fifo(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo
uint8_t bmp388_interface_spi_init(void)
interface spi bus init
void bmp388_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t bmp388_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t bmp388_interface_iic_deinit(void)
interface iic bus deinit
uint8_t bmp388_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus read
uint8_t bmp388_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
void bmp388_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t bmp388_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus write
uint8_t bmp388_interface_spi_deinit(void)
interface spi bus deinit
uint8_t bmp388_interface_iic_init(void)
interface iic bus init
uint8_t bmp388_set_interrupt_fifo_full(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo full interrupt
uint8_t bmp388_set_interrupt_fifo_watermark(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo watermark interrupt
uint8_t bmp388_set_interrupt_data_ready(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the data ready interrupt
uint8_t bmp388_set_interrupt_active_level(bmp388_handle_t *handle, bmp388_interrupt_active_level_t level)
set the interrupt active level
uint8_t bmp388_set_interrupt_pin_type(bmp388_handle_t *handle, bmp388_interrupt_pin_type_t pin_type)
set the interrupt pin type
uint8_t bmp388_set_latch_interrupt_pin_and_interrupt_status(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable latching interrupt pin and interrupt status
uint8_t bmp388_fifo_test(bmp388_interface_t interface, bmp388_address_t addr_pin, uint32_t times)
fifo test
uint8_t bmp388_fifo_test_irq_handler(void)
fifo test irq handler
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]