mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-14 17:17:42 +00:00
Merge branch 'eried:next' into next
This commit is contained in:
57
firmware/common/performance_counter.cpp
Normal file
57
firmware/common/performance_counter.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Bernd Herzog
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "performance_counter.hpp"
|
||||
#include "ch.h"
|
||||
|
||||
uint8_t get_cpu_utilisation_in_percent() {
|
||||
static systime_t last_time = 0;
|
||||
static systime_t last_idle_ticks = 0;
|
||||
|
||||
auto now = chTimeNow();
|
||||
auto idle_ticks = chThdGetTicks(chSysGetIdleThread());
|
||||
|
||||
if (last_time == 0) {
|
||||
last_time = now;
|
||||
last_idle_ticks = idle_ticks;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t time_elapsed = now - last_time;
|
||||
int32_t idle_elapsed = idle_ticks - last_idle_ticks;
|
||||
|
||||
int32_t working_ticks = time_elapsed - idle_elapsed;
|
||||
|
||||
if (working_ticks < 0)
|
||||
working_ticks = 0;
|
||||
|
||||
auto utilisation = working_ticks * 100 / time_elapsed;
|
||||
|
||||
last_time = now;
|
||||
last_idle_ticks = idle_ticks;
|
||||
|
||||
if (utilisation > 100) {
|
||||
return 100;
|
||||
}
|
||||
|
||||
return (uint8_t) utilisation;
|
||||
}
|
29
firmware/common/performance_counter.hpp
Normal file
29
firmware/common/performance_counter.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Bernd Herzog
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __PERFORMANCE_COUNTER_H__
|
||||
#define __PERFORMANCE_COUNTER_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint8_t get_cpu_utilisation_in_percent();
|
||||
|
||||
#endif /* __PERFORMANCE_COUNTER_H__ */
|
@@ -64,6 +64,11 @@ struct SharedMemory {
|
||||
JammerChannel jammer_channels[24];
|
||||
uint8_t data[512];
|
||||
} bb_data { { { { 0, 0 } }, 0, { 0 } } };
|
||||
|
||||
uint8_t volatile request_m4_performance_counter{ 0 };
|
||||
uint8_t volatile m4_cpu_usage{ 0 };
|
||||
uint16_t volatile m4_stack_usage{ 0 };
|
||||
uint16_t volatile m4_heap_usage{ 0 };
|
||||
};
|
||||
|
||||
extern SharedMemory& shared_memory;
|
||||
|
Reference in New Issue
Block a user