Coiling jig experiment with buttons for coiling, annealing and testing.

Dependencies:   TextLCD

Committer:
yphilippou
Date:
Fri Dec 21 15:46:23 2018 +0000
Revision:
0:7795c79c9480
Buttons added.

Who changed what in which revision?

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