Simple implementation of goal counter for table football using laser diode and phototransistor.

Dependencies:   GoalCounter WS2812 PixelArray

Committer:
nxf46245
Date:
Mon Jan 14 17:48:30 2019 +0000
Revision:
6:a93ee22232f2
Parent:
0:24f846b68c77
Code cleaning, added winner animation

Who changed what in which revision?

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