erweitert um RGB LED

Committer:
corsa1600
Date:
Tue Apr 02 18:07:35 2019 +0000
Revision:
1:dc7c5869f9e1
Parent:
0:f0345f20337e
LED_Blink

Who changed what in which revision?

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