Basic TFT display program for CITY082

Dependencies:   mbed

Committer:
reedas
Date:
Tue Nov 19 10:04:48 2019 +0000
Revision:
1:402b32a1025f
Basic Hello World tft display library program

Who changed what in which revision?

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