demo new haven display

Dependencies:   LCD Menu ButtonCtrl TimeManagement EventLog AddressMap emic2

ESCM 2000 Control and Display application provides interface for the LPC1768 processor boards with the ECSM 2000 system.

This application implements SW interface : - RX 485 Receive from physical system - RX 485 Interface to send toECOM / ESCM board - CAN Interface to send to ECOM / ESCM board - 4x40 LCD with menu controls - RTC configuration -EMIC2 Sound Card - GPIO Extender to push buttons etc

Committer:
foxbrianr
Date:
Thu Sep 12 11:28:26 2019 +0000
Revision:
5:65f21c0b6b79
Child:
6:010ceb99f7b0
beta1

Who changed what in which revision?

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