You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2020/09/16 00:32:42 UTC

[GitHub] [mynewt-core] vrahane commented on a change in pull request #2376: FWS-665 pressure sensor optimization

vrahane commented on a change in pull request #2376:
URL: https://github.com/apache/mynewt-core/pull/2376#discussion_r489092518



##########
File path: hw/drivers/sensors/bmp388/src/bmp388.c
##########
@@ -3366,6 +3366,215 @@ bmp388_stream_read(struct sensor *sensor,
     return rc;
 }
 
+int
+bmp388_hybrid_read(struct sensor *sensor,
+                   sensor_type_t sensor_type,
+                   sensor_data_func_t read_func,
+                   void *read_arg,
+                   uint32_t time_ms)
+{
+    int rc;
+    struct bmp388 *bmp388;
+    struct bmp388_cfg *cfg;
+    os_time_t time_ticks;
+    os_time_t stop_ticks = 0;
+    uint16_t try_count;
+    
+#if MYNEWT_VAL(BMP388_FIFO_ENABLE)
+    /* FIFO object to be assigned to device structure */
+    struct bmp3_fifo fifo;
+    /* Pressure and temperature array of structures with maximum frame size */
+    struct bmp3_data sensor_data[74];
+    /* Loop Variable */
+    uint8_t i;
+    uint16_t frame_length;
+    /* Enable fifo */
+    fifo.settings.mode = BMP3_ENABLE;
+    /* Enable Pressure sensor for fifo */
+    fifo.settings.press_en = BMP3_ENABLE;
+    /* Enable temperature sensor for fifo */
+    fifo.settings.temp_en = BMP3_ENABLE;
+    /* Enable fifo time */
+    fifo.settings.time_en = BMP3_ENABLE;
+    /* No subsampling for FIFO */
+    fifo.settings.down_sampling = BMP3_FIFO_NO_SUBSAMPLING;
+    fifo.sensortime_updated = false;
+    uint16_t current_fifo_len;
+#else
+    struct bmp3_data sensor_data;
+#endif
+
+    /* If the read isn't looking for pressure or temperature data, don't do anything. */
+    if ((!(sensor_type & SENSOR_TYPE_PRESSURE)) && (!(sensor_type & SENSOR_TYPE_TEMPERATURE))) {
+        BMP388_LOG_ERROR("unsupported sensor type for bmp388\n");
+        return SYS_EINVAL;
+    }
+
+    bmp388 = (struct bmp388 *)SENSOR_GET_DEVICE(sensor);
+    
+    cfg = &bmp388->cfg;
+
+    if (cfg->read_mode.mode != BMP388_READ_M_HYBRID) {
+        BMP388_LOG_ERROR("*****bmp388_hybrid_read mode is not hybrid\n");
+        return SYS_EINVAL;
+    }
+
+    if (bmp388->bmp388_cfg_complete == false)
+    {
+        /* no interrupt feature */
+        /* enable normal mode for fifo feature */
+        rc = bmp388_set_normal_mode(bmp388);
+        if (rc)
+        {
+            BMP388_LOG_ERROR("******bmp388_set_normal_mode failed %d\n", rc);
+            goto error;
+        }
+        bmp3_fifo_flush(&bmp388->bmp3_dev); 
+        bmp388->bmp388_cfg_complete = true;
+    }
+     
+    
+#if MYNEWT_VAL(BMP388_FIFO_ENABLE)
+    bmp388->bmp3_dev.fifo = &fifo;
+
+    fifo.data.req_frames = bmp388->bmp3_dev.fifo_watermark_level;
+#endif
+    
+    if (time_ms != 0)
+    {
+        if (time_ms > BMP388_MAX_STREAM_MS)
+            time_ms = BMP388_MAX_STREAM_MS;
+        rc = os_time_ms_to_ticks(time_ms, &time_ticks);
+        if (rc) {
+            goto error;
+        }
+        stop_ticks = os_time_get() + time_ticks;
+    }
+
+
+#if MYNEWT_VAL(BMP388_FIFO_ENABLE)
+    try_count = 0xFFFF;
+
+    do {
+        rc = bmp3_get_status(&bmp388->bmp3_dev);
+        rc = bmp3_get_fifo_length(&current_fifo_len, &bmp388->bmp3_dev);
+        delay_msec(2);
+#if FIFOPARSE_DEBUG
+        BMP388_LOG_ERROR("*****status %d\n", rc);
+#endif
+    } while ((--try_count > 0) && (rc != BMP3_OK));
+
+
+    if ((rc != BMP3_OK) || (try_count == 0))
+    {
+#if FIFOPARSE_DEBUG
+        BMP388_LOG_ERROR("*****status %d\n", rc);
+        BMP388_LOG_ERROR("*****try_count is %d\n", try_count);
+        BMP388_LOG_ERROR("*****fifo length is %d\n", current_fifo_len);
+#endif
+        BMP388_LOG_ERROR("*****BMP388 STATUS READ FAILED\n");
+        goto error;
+    }
+
+    rc = bmp3_get_fifo_data(&bmp388->bmp3_dev);
+    if(rc != BMP3_OK)
+    {
+        BMP388_LOG_ERROR("*****BMP388 FIFO READ FAILED\n");
+        goto error;
+    }
+    
+    if (fifo.settings.time_en)
+    {
+        fifo.no_need_sensortime = false;
+    } else {
+        fifo.no_need_sensortime = true;
+    }
+
+    rc = bmp3_extract_fifo_data(sensor_data, &bmp388->bmp3_dev);
+    
+    if (fifo.data.frame_not_available)
+    {
+        /* No valid frame read */
+        BMP388_LOG_ERROR("*****No valid Fifo Frames %d\n", rc);
+        goto error;
+    } else {
+#if BMP388_DEBUG
+        BMP388_LOG_ERROR("*****parsed_frames is %d\n", fifo.data.parsed_frames);
+#endif
+        frame_length = fifo.data.parsed_frames;
+
+        for(i = 0; i < frame_length; i++)
+        {
+            rc = bmp388_do_report(sensor, sensor_type, read_func, read_arg, &sensor_data[i]);
+            
+            if(rc)
+            {
+                BMP388_LOG_ERROR("*****BMP388_DO_REPORT FAILED %d\n", rc);
+                goto error;
+            }
+        }
+
+        if (fifo.sensortime_updated)
+        {
+            BMP388_LOG_ERROR("*****BMP388 SENSOR TIME %d\n", fifo.data.sensor_time);
+            fifo.sensortime_updated = false;
+        }
+    }
+
+#else /* FIFO NOT ENABLED */
+    if (bmp388->cfg.fifo_mode == BMP388_FIFO_M_BYPASS) {
+        /* make data is available */
+        try_count = 5; 
+
+
+        do {
+            rc = bmp3_get_status(&bmp388->bmp3_dev);
+            
+            if((bmp388->bmp3_dev.status.sensor.drdy_press) &&
+                    (bmp388->bmp3_dev.status.sensor.drdy_temp))
+            {
+                break;
+            }
+            
+            delay_msec(2);
+#if FIFOPARSE_DEBUG
+            BMP388_LOG_ERROR("*****status %d\n", rc);
+#endif
+        } while (--try_count > 0);
+
+        rc = bmp388_get_sensor_data(bmp388, &sensor_data);
+        if (rc) {
+            BMP388_LOG_ERROR("bmp388_get_sensor_data failed %d\n", rc);
+            goto error;
+        }
+
+        rc = bmp388_do_report(sensor, sensor_type, read_func, read_arg, &sensor_data);
+        if (rc) {
+            BMP388_LOG_ERROR("bmp388_do_report failed %d\n", rc);
+            goto error;
+        }
+
+    }
+#endif // #if MYNEWT_VAL(BMP388_FIFO_ENABLE)

Review comment:
       Please convert the C++ stye comment to C style comment




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org