LibDriver BMP384
Loading...
Searching...
No Matches
driver_bmp384_fifo_test.c
Go to the documentation of this file.
1
36
38
39static bmp384_handle_t gs_handle;
40static volatile uint8_t gs_fifo_full_flag;
41static volatile uint8_t gs_fifo_watermark_flag;
42static uint8_t gs_buf[512];
43static bmp384_frame_t gs_frame[256];
44
53{
54 /* run irq handler */
55 if (bmp384_irq_handler(&gs_handle) != 0)
56 {
57 return 1;
58 }
59 else
60 {
61 return 0;
62 }
63}
64
70static void a_bmp384_interface_test_receive_callback(uint8_t type)
71{
72 switch (type)
73 {
75 {
76 if (gs_fifo_watermark_flag == 0)
77 {
78 uint16_t len;
79
80 len = 512;
81 /* read fifo */
82 if (bmp384_read_fifo(&gs_handle, (uint8_t *)gs_buf, (uint16_t *)&len) != 0)
83 {
84 bmp384_interface_debug_print("bmp384: read fifo failed.\n");
85
86 return;
87 }
88 bmp384_interface_debug_print("bmp384: read fifo with length %d.\n", len);
89 gs_fifo_watermark_flag = 1;
90 }
91
92 break;
93 }
95 {
96 uint16_t len;
97 uint16_t frame_len;
98
99 len = 512;
100 /* read fifo */
101 if (bmp384_read_fifo(&gs_handle, (uint8_t *)gs_buf, (uint16_t *)&len) != 0)
102 {
103 bmp384_interface_debug_print("bmp384: read fifo failed.\n");
104
105 return;
106 }
107 if (len > 4)
108 {
109 bmp384_interface_debug_print("bmp384: clear fifo with length %d.\n", len);
110 frame_len = 256;
111
112 /* parse fifo */
113 if (bmp384_fifo_parse(&gs_handle, (uint8_t *)gs_buf, len, (bmp384_frame_t *)gs_frame, (uint16_t *)&frame_len) != 0)
114 {
115 bmp384_interface_debug_print("bmp384: fifo parse failed.\n");
116
117 return;
118 }
119 else
120 {
121 bmp384_interface_debug_print("bmp384: fifo parse success and total frame is %d.\n", frame_len);
122 }
123 }
124 gs_fifo_full_flag = 1;
125
126 break;
127 }
129 {
130 break;
131 }
132 default :
133 {
134 break;
135 }
136 }
137}
138
149uint8_t bmp384_fifo_test(bmp384_interface_t interface, bmp384_address_t addr_pin, uint32_t times)
150{
151 uint8_t res;
152 uint32_t i;
153 bmp384_info_t info;
154
155 /* link functions */
167 DRIVER_BMP384_LINK_RECEIVE_CALLBACK(&gs_handle, a_bmp384_interface_test_receive_callback);
168
169 /* bmp384 info */
170 res = bmp384_info(&info);
171 if (res != 0)
172 {
173 bmp384_interface_debug_print("bmp384: get info failed.\n");
174
175 return 1;
176 }
177 else
178 {
179 /* print chip information */
180 bmp384_interface_debug_print("bmp384: chip is %s.\n", info.chip_name);
181 bmp384_interface_debug_print("bmp384: manufacturer is %s.\n", info.manufacturer_name);
182 bmp384_interface_debug_print("bmp384: interface is %s.\n", info.interface);
183 bmp384_interface_debug_print("bmp384: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
184 bmp384_interface_debug_print("bmp384: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
185 bmp384_interface_debug_print("bmp384: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
186 bmp384_interface_debug_print("bmp384: max current is %0.2fmA.\n", info.max_current_ma);
187 bmp384_interface_debug_print("bmp384: max temperature is %0.1fC.\n", info.temperature_max);
188 bmp384_interface_debug_print("bmp384: min temperature is %0.1fC.\n", info.temperature_min);
189 }
190
191 /* start fifo test */
192 bmp384_interface_debug_print("bmp384: start fifo test.\n");
193
194 /* set interface */
195 res = bmp384_set_interface(&gs_handle, interface);
196 if (res != 0)
197 {
198 bmp384_interface_debug_print("bmp384: set interface failed.\n");
199
200 return 1;
201 }
202
203 /* set addr pin */
204 res = bmp384_set_addr_pin(&gs_handle, addr_pin);
205 if (res != 0)
206 {
207 bmp384_interface_debug_print("bmp384: set addr pin failed.\n");
208
209 return 1;
210 }
211
212 /* bmp384 init */
213 res = bmp384_init(&gs_handle);
214 if (res != 0)
215 {
216 bmp384_interface_debug_print("bmp384: init failed.\n");
217
218 return 1;
219 }
220
221 /* set spi wire 4 */
222 res = bmp384_set_spi_wire(&gs_handle, BMP384_SPI_WIRE_4);
223 if (res != 0)
224 {
225 bmp384_interface_debug_print("bmp384: set spi wire failed.\n");
226 (void)bmp384_deinit(&gs_handle);
227
228 return 1;
229 }
230
231 /* enable iic watchdog timer */
233 if (res != 0)
234 {
235 bmp384_interface_debug_print("bmp384: set iic watchdog timer failed.\n");
236 (void)bmp384_deinit(&gs_handle);
237
238 return 1;
239 }
240
241 /* set iic watchdog period 40 ms */
243 if (res != 0)
244 {
245 bmp384_interface_debug_print("bmp384: set iic watchdog period failed.\n");
246 (void)bmp384_deinit(&gs_handle);
247
248 return 1;
249 }
250
251 /* enable fifo */
252 res = bmp384_set_fifo(&gs_handle, BMP384_BOOL_TRUE);
253 if (res != 0)
254 {
255 bmp384_interface_debug_print("bmp384: set fifo failed.\n");
256 (void)bmp384_deinit(&gs_handle);
257
258 return 1;
259 }
260
261 /* enable fifo stop on full */
263 if (res != 0)
264 {
265 bmp384_interface_debug_print("bmp384: set fifo stop on full failed.\n");
266 (void)bmp384_deinit(&gs_handle);
267
268 return 1;
269 }
270
271 /* set fifo watermark 500 */
272 res = bmp384_set_fifo_watermark(&gs_handle, 500);
273 if (res != 0)
274 {
275 bmp384_interface_debug_print("bmp384: set fifo watermark failed.\n");
276 (void)bmp384_deinit(&gs_handle);
277
278 return 1;
279 }
280
281 /* enable fifo sensor time on */
283 if (res != 0)
284 {
285 bmp384_interface_debug_print("bmp384: set fifo sensor time on failed.\n");
286 (void)bmp384_deinit(&gs_handle);
287
288 return 1;
289 }
291 if (res != 0)
292 {
293 bmp384_interface_debug_print("bmp384: set fifo sensor time on failed.\n");
294 (void)bmp384_deinit(&gs_handle);
295
296 return 1;
297 }
299 if (res != 0)
300 {
301 bmp384_interface_debug_print("bmp384: set fifo temperature on failed.\n");
302 (void)bmp384_deinit(&gs_handle);
303
304 return 1;
305 }
306 res = bmp384_set_fifo_subsampling(&gs_handle, 0);
307 if (res != 0)
308 {
309 bmp384_interface_debug_print("bmp384: set fifo subsampling failed.\n");
310 (void)bmp384_deinit(&gs_handle);
311
312 return 1;
313 }
315 if (res != 0)
316 {
317 bmp384_interface_debug_print("bmp384: set fifo data source failed.\n");
318 (void)bmp384_deinit(&gs_handle);
319
320 return 1;
321 }
322
323 /* set interrupt pin type push-pull */
325 if (res != 0)
326 {
327 bmp384_interface_debug_print("bmp384: set interrupt pin type failed.\n");
328 (void)bmp384_deinit(&gs_handle);
329
330 return 1;
331 }
332
333 /* set interrupt active level higher */
335 if (res != 0)
336 {
337 bmp384_interface_debug_print("bmp384: set interrupt active level failed.\n");
338 (void)bmp384_deinit(&gs_handle);
339
340 return 1;
341 }
342
343 /* disable latch interrupt pin and interrupt status */
345 if (res != 0)
346 {
347 bmp384_interface_debug_print("bmp384: set set latch interrupt pin and interrupt status failed.\n");
348 (void)bmp384_deinit(&gs_handle);
349
350 return 1;
351 }
352
353 /* enable interrupt fifo watermark */
355 if (res != 0)
356 {
357 bmp384_interface_debug_print("bmp384: set interrupt fifo watermark failed.\n");
358 (void)bmp384_deinit(&gs_handle);
359
360 return 1;
361 }
362
363 /* enable interrupt fifo full */
365 if (res != 0)
366 {
367 bmp384_interface_debug_print("bmp384: set interrupt fifo full failed.\n");
368 (void)bmp384_deinit(&gs_handle);
369
370 return 1;
371 }
372
373 /* disable interrupt data ready */
375 if (res != 0)
376 {
377 bmp384_interface_debug_print("bmp384: set interrupt data ready failed.\n");
378 (void)bmp384_deinit(&gs_handle);
379
380 return 1;
381 }
382
383 /* enable pressure */
384 res = bmp384_set_pressure(&gs_handle, BMP384_BOOL_TRUE);
385 if (res != 0)
386 {
387 bmp384_interface_debug_print("bmp384: set pressure failed.\n");
388 (void)bmp384_deinit(&gs_handle);
389
390 return 1;
391 }
392
393 /* enable temperature */
394 res = bmp384_set_temperature(&gs_handle, BMP384_BOOL_TRUE);
395 if (res != 0)
396 {
397 bmp384_interface_debug_print("bmp384: set temperature failed.\n");
398 (void)bmp384_deinit(&gs_handle);
399
400 return 1;
401 }
402
403 /* set pressure oversampling x32 */
405 if (res != 0)
406 {
407 bmp384_interface_debug_print("bmp384: set pressure oversampling failed.\n");
408 (void)bmp384_deinit(&gs_handle);
409
410 return 1;
411 }
412
413 /* set temperature oversampling x2 */
415 if (res != 0)
416 {
417 bmp384_interface_debug_print("bmp384: set temperature oversampling failed.\n");
418 (void)bmp384_deinit(&gs_handle);
419
420 return 1;
421 }
422
423 /* set odr 12.5Hz */
424 res = bmp384_set_odr(&gs_handle, BMP384_ODR_12P5_HZ);
425 if (res != 0)
426 {
427 bmp384_interface_debug_print("bmp384: set odr failed.\n");
428 (void)bmp384_deinit(&gs_handle);
429
430 return 1;
431 }
432
433 /* set filter coefficient 15 */
435 if (res != 0)
436 {
437 bmp384_interface_debug_print("bmp384: set filter coefficient failed.\n");
438 (void)bmp384_deinit(&gs_handle);
439
440 return 1;
441 }
442
443 /* set normal mode */
444 res = bmp384_set_mode(&gs_handle, BMP384_MODE_NORMAL_MODE);
445 if (res != 0)
446 {
447 bmp384_interface_debug_print("bmp384: set mode failed.\n");
448 (void)bmp384_deinit(&gs_handle);
449
450 return 1;
451 }
452
453 /* fifo watermark test */
454 bmp384_interface_debug_print("bmp384: fifo watermark test.\n");
455 for (i = 0; i < times; i++)
456 {
457 uint32_t num;
458
459 gs_fifo_watermark_flag = 0;
460 num = 0;
461 while(gs_fifo_watermark_flag == 0)
462 {
463 num++;
464 if (num > 5000)
465 {
466 bmp384_interface_debug_print("bmp384: fifo interrupt failed.\n");
467 (void)bmp384_deinit(&gs_handle);
468
469 return 1;
470 }
472 }
473 }
474
475 /* fifo full test */
476 bmp384_interface_debug_print("bmp384: fifo full test.\n");
477
478 for (i = 0; i < times; i++)
479 {
480 uint32_t num;
481
482 gs_fifo_watermark_flag = 2;
483 gs_fifo_full_flag = 0;
484 num = 0;
485 while (gs_fifo_full_flag == 0)
486 {
487 num++;
488 if (num > 5000)
489 {
490 bmp384_interface_debug_print("bmp384: fifo interrupt failed.\n");
491 (void)bmp384_deinit(&gs_handle);
492
493 return 1;
494 }
496 }
497 }
498
499 /* set sleep mode */
500 res = bmp384_set_mode(&gs_handle, BMP384_MODE_SLEEP_MODE);
501 if (res != 0)
502 {
503 bmp384_interface_debug_print("bmp384: set mode failed.\n");
504 (void)bmp384_deinit(&gs_handle);
505
506 return 1;
507 }
508
509 /* finish fifo test */
510 bmp384_interface_debug_print("bmp384: finish fifo test.\n");
511 (void)bmp384_deinit(&gs_handle);
512
513 return 0;
514}
driver bmp384 fifo test header file
uint8_t bmp384_deinit(bmp384_handle_t *handle)
close the chip
uint8_t bmp384_set_addr_pin(bmp384_handle_t *handle, bmp384_address_t addr_pin)
set the iic address pin
bmp384_interface_t
bmp384 interface enumeration definition
uint8_t bmp384_set_interface(bmp384_handle_t *handle, bmp384_interface_t interface)
set the interface
uint8_t bmp384_set_pressure(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the pressure
uint8_t bmp384_set_temperature(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the temperature
struct bmp384_frame_s bmp384_frame_t
bmp384 frame structure definition
uint8_t bmp384_set_pressure_oversampling(bmp384_handle_t *handle, bmp384_oversampling_t oversampling)
set the pressure oversampling
uint8_t bmp384_set_iic_watchdog_timer(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the iic watchdog timer
bmp384_address_t
bmp384 address enumeration definition
uint8_t bmp384_set_filter_coefficient(bmp384_handle_t *handle, bmp384_filter_coefficient_t coefficient)
set the filter coefficient
uint8_t bmp384_info(bmp384_info_t *info)
get chip's information
struct bmp384_info_s bmp384_info_t
bmp384 information structure definition
uint8_t bmp384_set_spi_wire(bmp384_handle_t *handle, bmp384_spi_wire_t wire)
set the spi wire
uint8_t bmp384_set_mode(bmp384_handle_t *handle, bmp384_mode_t mode)
set the chip mode
uint8_t bmp384_init(bmp384_handle_t *handle)
initialize the chip
uint8_t bmp384_set_iic_watchdog_period(bmp384_handle_t *handle, bmp384_iic_watchdog_period_t period)
set the iic watchdog period
uint8_t bmp384_irq_handler(bmp384_handle_t *handle)
irq handler
uint8_t bmp384_set_temperature_oversampling(bmp384_handle_t *handle, bmp384_oversampling_t oversampling)
set the temperature oversampling
struct bmp384_handle_s bmp384_handle_t
bmp384 handle structure definition
uint8_t bmp384_set_odr(bmp384_handle_t *handle, bmp384_odr_t odr)
set the output data rate
@ BMP384_MODE_NORMAL_MODE
@ BMP384_MODE_SLEEP_MODE
@ BMP384_FIFO_DATA_SOURCE_FILTERED
@ BMP384_SPI_WIRE_4
@ BMP384_BOOL_TRUE
@ BMP384_BOOL_FALSE
@ BMP384_INTERRUPT_STATUS_FIFO_WATERMARK
@ BMP384_INTERRUPT_STATUS_FIFO_FULL
@ BMP384_INTERRUPT_STATUS_DATA_READY
@ BMP384_INTERRUPT_PIN_TYPE_PUSH_PULL
@ BMP384_ODR_12P5_HZ
@ BMP384_FILTER_COEFFICIENT_15
@ BMP384_IIC_WATCHDOG_PERIOD_40_MS
@ BMP384_OVERSAMPLING_x32
@ BMP384_OVERSAMPLING_x2
@ BMP384_INTERRUPT_ACTIVE_LEVEL_HIGHER
uint8_t bmp384_fifo_parse(bmp384_handle_t *handle, uint8_t *buf, uint16_t buf_len, bmp384_frame_t *frame, uint16_t *frame_len)
parse the fifo data
uint8_t bmp384_set_fifo_pressure_on(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo pressure on
uint8_t bmp384_set_fifo_data_source(bmp384_handle_t *handle, bmp384_fifo_data_source_t source)
set the fifo data source
uint8_t bmp384_set_fifo_stop_on_full(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo stopping on full
uint8_t bmp384_set_fifo_sensortime_on(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo sensor time on
uint8_t bmp384_read_fifo(bmp384_handle_t *handle, uint8_t *buf, uint16_t *len)
read the fifo
uint8_t bmp384_set_fifo(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo
uint8_t bmp384_set_fifo_temperature_on(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo temperature on
uint8_t bmp384_set_fifo_watermark(bmp384_handle_t *handle, uint16_t watermark)
set the fifo watermark
uint8_t bmp384_set_fifo_subsampling(bmp384_handle_t *handle, uint8_t subsample)
set the fifo subsampling
uint8_t bmp384_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
void bmp384_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t bmp384_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus read
void bmp384_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t bmp384_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t bmp384_interface_iic_init(void)
interface iic bus init
uint8_t bmp384_interface_spi_init(void)
interface spi bus init
uint8_t bmp384_interface_spi_deinit(void)
interface spi bus deinit
uint8_t bmp384_interface_iic_deinit(void)
interface iic bus deinit
uint8_t bmp384_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus write
uint8_t bmp384_set_interrupt_pin_type(bmp384_handle_t *handle, bmp384_interrupt_pin_type_t pin_type)
set the interrupt pin type
uint8_t bmp384_set_interrupt_active_level(bmp384_handle_t *handle, bmp384_interrupt_active_level_t level)
set the interrupt active level
uint8_t bmp384_set_interrupt_data_ready(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the data ready interrupt
uint8_t bmp384_set_interrupt_fifo_full(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo full interrupt
uint8_t bmp384_set_interrupt_fifo_watermark(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo watermark interrupt
uint8_t bmp384_set_latch_interrupt_pin_and_interrupt_status(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable latching interrupt pin and interrupt status
uint8_t bmp384_fifo_test(bmp384_interface_t interface, bmp384_address_t addr_pin, uint32_t times)
fifo test
uint8_t bmp384_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]