mix code vision 3. Using the previous algorithm to detect peaks as Nikoleta and Shiyao. Adding overlapping windows

Dependencies:   mpu9250_i2c biquadFilter peakdetection Eigen

Committer:
castlefei
Date:
Wed Nov 06 12:36:55 2019 +0000
Revision:
0:44701eab0261
my test to read date from MPU9250

Who changed what in which revision?

UserRevisionLine numberNew contents of line
castlefei 0:44701eab0261 1 /* mbed Microcontroller Library
castlefei 0:44701eab0261 2 * Copyright (c) 2018 ARM Limited
castlefei 0:44701eab0261 3 * SPDX-License-Identifier: Apache-2.0
castlefei 0:44701eab0261 4 */
castlefei 0:44701eab0261 5
castlefei 0:44701eab0261 6 #ifndef STATS_REPORT_H
castlefei 0:44701eab0261 7 #define STATS_REPORT_H
castlefei 0:44701eab0261 8
castlefei 0:44701eab0261 9 #include <inttypes.h>
castlefei 0:44701eab0261 10 #include "mbed.h"
castlefei 0:44701eab0261 11
castlefei 0:44701eab0261 12 /**
castlefei 0:44701eab0261 13 * System Reporting library. Provides runtime information on device:
castlefei 0:44701eab0261 14 * - CPU sleep, idle, and wake times
castlefei 0:44701eab0261 15 * - Heap and stack usage
castlefei 0:44701eab0261 16 * - Thread information
castlefei 0:44701eab0261 17 * - Static system information
castlefei 0:44701eab0261 18 */
castlefei 0:44701eab0261 19 class SystemReport {
castlefei 0:44701eab0261 20 mbed_stats_heap_t heap_stats;
castlefei 0:44701eab0261 21 mbed_stats_cpu_t cpu_stats;
castlefei 0:44701eab0261 22 mbed_stats_sys_t sys_stats;
castlefei 0:44701eab0261 23
castlefei 0:44701eab0261 24 mbed_stats_thread_t *thread_stats;
castlefei 0:44701eab0261 25 uint8_t thread_count;
castlefei 0:44701eab0261 26 uint8_t max_thread_count;
castlefei 0:44701eab0261 27 uint32_t sample_time_ms;
castlefei 0:44701eab0261 28
castlefei 0:44701eab0261 29 public:
castlefei 0:44701eab0261 30 /**
castlefei 0:44701eab0261 31 * SystemReport - Sample rate in ms is required to handle the CPU percent awake logic
castlefei 0:44701eab0261 32 */
castlefei 0:44701eab0261 33 SystemReport(uint32_t sample_rate) : max_thread_count(8), sample_time_ms(sample_rate)
castlefei 0:44701eab0261 34 {
castlefei 0:44701eab0261 35 thread_stats = new mbed_stats_thread_t[max_thread_count];
castlefei 0:44701eab0261 36
castlefei 0:44701eab0261 37 // Collect the static system information
castlefei 0:44701eab0261 38 mbed_stats_sys_get(&sys_stats);
castlefei 0:44701eab0261 39
castlefei 0:44701eab0261 40 printf("=============================== SYSTEM INFO ================================\r\n");
castlefei 0:44701eab0261 41 printf("Mbed OS Version: %" PRIu32 " \r\n", sys_stats.os_version);
castlefei 0:44701eab0261 42 printf("CPU ID: 0x%" PRIx32 " \r\n", sys_stats.cpu_id);
castlefei 0:44701eab0261 43 printf("Compiler ID: %d \r\n", sys_stats.compiler_id);
castlefei 0:44701eab0261 44 printf("Compiler Version: %" PRIu32 " \r\n", sys_stats.compiler_version);
castlefei 0:44701eab0261 45
castlefei 0:44701eab0261 46 for (int i = 0; i < MBED_MAX_MEM_REGIONS; i++) {
castlefei 0:44701eab0261 47 if (sys_stats.ram_size[i] != 0) {
castlefei 0:44701eab0261 48 printf("RAM%d: Start 0x%" PRIx32 " Size: 0x%" PRIx32 " \r\n", i, sys_stats.ram_start[i], sys_stats.ram_size[i]);
castlefei 0:44701eab0261 49 }
castlefei 0:44701eab0261 50 }
castlefei 0:44701eab0261 51 for (int i = 0; i < MBED_MAX_MEM_REGIONS; i++) {
castlefei 0:44701eab0261 52 if (sys_stats.rom_size[i] != 0) {
castlefei 0:44701eab0261 53 printf("ROM%d: Start 0x%" PRIx32 " Size: 0x%" PRIx32 " \r\n", i, sys_stats.rom_start[i], sys_stats.rom_size[i]);
castlefei 0:44701eab0261 54 }
castlefei 0:44701eab0261 55 }
castlefei 0:44701eab0261 56 }
castlefei 0:44701eab0261 57
castlefei 0:44701eab0261 58 ~SystemReport(void)
castlefei 0:44701eab0261 59 {
castlefei 0:44701eab0261 60 free(thread_stats);
castlefei 0:44701eab0261 61 }
castlefei 0:44701eab0261 62
castlefei 0:44701eab0261 63 /**
castlefei 0:44701eab0261 64 * Report on each Mbed OS Platform stats API
castlefei 0:44701eab0261 65 */
castlefei 0:44701eab0261 66 void report_state(void)
castlefei 0:44701eab0261 67 {
castlefei 0:44701eab0261 68 report_cpu_stats();
castlefei 0:44701eab0261 69 report_heap_stats();
castlefei 0:44701eab0261 70 report_thread_stats();
castlefei 0:44701eab0261 71
castlefei 0:44701eab0261 72 // Clear next line to separate subsequent report logs
castlefei 0:44701eab0261 73 printf("\r\n");
castlefei 0:44701eab0261 74 }
castlefei 0:44701eab0261 75
castlefei 0:44701eab0261 76 /**
castlefei 0:44701eab0261 77 * Report CPU idle and awake time in terms of percentage
castlefei 0:44701eab0261 78 */
castlefei 0:44701eab0261 79 void report_cpu_stats(void)
castlefei 0:44701eab0261 80 {
castlefei 0:44701eab0261 81 static uint64_t prev_idle_time = 0;
castlefei 0:44701eab0261 82
castlefei 0:44701eab0261 83 printf("================= CPU STATS =================\r\n");
castlefei 0:44701eab0261 84
castlefei 0:44701eab0261 85 // Collect and print cpu stats
castlefei 0:44701eab0261 86 mbed_stats_cpu_get(&cpu_stats);
castlefei 0:44701eab0261 87
castlefei 0:44701eab0261 88 uint64_t diff = (cpu_stats.idle_time - prev_idle_time);
castlefei 0:44701eab0261 89 uint8_t idle = (diff * 100) / (sample_time_ms * 1000); // usec;
castlefei 0:44701eab0261 90 uint8_t usage = 100 - ((diff * 100) / (sample_time_ms * 1000)); // usec;;
castlefei 0:44701eab0261 91 prev_idle_time = cpu_stats.idle_time;
castlefei 0:44701eab0261 92
castlefei 0:44701eab0261 93 printf("Idle: %d%% Usage: %d%% \r\n", idle, usage);
castlefei 0:44701eab0261 94 }
castlefei 0:44701eab0261 95
castlefei 0:44701eab0261 96 /**
castlefei 0:44701eab0261 97 * Report current heap stats. Current heap refers to the current amount of
castlefei 0:44701eab0261 98 * allocated heap. Max heap refers to the highest amount of heap allocated
castlefei 0:44701eab0261 99 * since reset.
castlefei 0:44701eab0261 100 */
castlefei 0:44701eab0261 101 void report_heap_stats(void)
castlefei 0:44701eab0261 102 {
castlefei 0:44701eab0261 103 printf("================ HEAP STATS =================\r\n");
castlefei 0:44701eab0261 104
castlefei 0:44701eab0261 105 // Collect and print heap stats
castlefei 0:44701eab0261 106 mbed_stats_heap_get(&heap_stats);
castlefei 0:44701eab0261 107
castlefei 0:44701eab0261 108 printf("Current heap: %" PRIu32 "\r\n", heap_stats.current_size);
castlefei 0:44701eab0261 109 printf("Max heap size: %" PRIu32 "\r\n", heap_stats.max_size);
castlefei 0:44701eab0261 110 }
castlefei 0:44701eab0261 111
castlefei 0:44701eab0261 112 /**
castlefei 0:44701eab0261 113 * Report active thread stats
castlefei 0:44701eab0261 114 */
castlefei 0:44701eab0261 115 void report_thread_stats(void)
castlefei 0:44701eab0261 116 {
castlefei 0:44701eab0261 117 printf("================ THREAD STATS ===============\r\n");
castlefei 0:44701eab0261 118
castlefei 0:44701eab0261 119 // Collect and print running thread stats
castlefei 0:44701eab0261 120 int count = mbed_stats_thread_get_each(thread_stats, max_thread_count);
castlefei 0:44701eab0261 121
castlefei 0:44701eab0261 122 for (int i = 0; i < count; i++) {
castlefei 0:44701eab0261 123 printf("ID: 0x%" PRIx32 " \r\n", thread_stats[i].id);
castlefei 0:44701eab0261 124 printf("Name: %s \r\n", thread_stats[i].name);
castlefei 0:44701eab0261 125 printf("State: %" PRIu32 " \r\n", thread_stats[i].state);
castlefei 0:44701eab0261 126 printf("Priority: %" PRIu32 " \r\n", thread_stats[i].priority);
castlefei 0:44701eab0261 127 printf("Stack Size: %" PRIu32 " \r\n", thread_stats[i].stack_size);
castlefei 0:44701eab0261 128 printf("Stack Space: %" PRIu32 " \r\n", thread_stats[i].stack_space);
castlefei 0:44701eab0261 129 }
castlefei 0:44701eab0261 130 }
castlefei 0:44701eab0261 131 };
castlefei 0:44701eab0261 132
castlefei 0:44701eab0261 133 #endif // STATS_REPORT_H