software:firmware
MakAir Firmware
cpu_load.cpp File Reference

A CPU load estimation. More...

#include "../includes/cpu_load.h"
#include "Arduino.h"

Go to the source code of this file.

Macros

#define CPU_MAX_LOOP_PER_SECOND   8327007u
 

Functions

uint8_t readCpuLoadPercent (void)
 Get the value of the CPU load. More...
 
void cpuLoadCallback (void)
 
void osSystickHandler ()
 

Variables

volatile uint32_t idleCyclesCount = 0
 Access to idleCyclesCount needed by the COUNT_IDLE_CYCLE macro. More...
 
volatile uint8_t cpuLoadPercent = 0
 
uint16_t cpuLoadTimeCount = TIME_CPU_CYCLE_RESET
 
uint32_t cpuLoadLatestCycleCount = 0
 

Detailed Description

A CPU load estimation.

Author
Makers For Life

Definition in file cpu_load.cpp.

Macro Definition Documentation

◆ CPU_MAX_LOOP_PER_SECOND

#define CPU_MAX_LOOP_PER_SECOND   8327007u

Definition at line 35 of file cpu_load.cpp.

Function Documentation

◆ cpuLoadCallback()

void cpuLoadCallback ( void  )

Definition at line 41 of file cpu_load.cpp.

41  {
43  if (cpuLoadTimeCount == 0u) {
45  // Overflow won't be a problem, same type
46  uint32_t delta = idleCyclesCount - cpuLoadLatestCycleCount;
48  if (delta > CPU_MAX_LOOP_PER_SECOND) {
50  }
51  cpuLoadPercent = static_cast<uint8_t>(100u - (100u * delta) / CPU_MAX_LOOP_PER_SECOND);
52 
53  // Uncomment to tune CPU_MAX_LOOP_PER_SECOND value
54  // Serial.println(delta);
55  }
56 }
uint32_t cpuLoadLatestCycleCount
Definition: cpu_load.cpp:30
#define CPU_MAX_LOOP_PER_SECOND
Definition: cpu_load.cpp:35
volatile uint32_t idleCyclesCount
Access to idleCyclesCount needed by the COUNT_IDLE_CYCLE macro.
Definition: cpu_load.cpp:22
volatile uint8_t cpuLoadPercent
Definition: cpu_load.cpp:25
uint16_t cpuLoadTimeCount
Definition: cpu_load.cpp:28
#define TIME_CPU_CYCLE_RESET
Duration in ms after which the CPU cycle count is reset and the result is stored.
Definition: cpu_load.h:17

◆ osSystickHandler()

void osSystickHandler ( )

Definition at line 61 of file cpu_load.cpp.

61 { cpuLoadCallback(); }
void cpuLoadCallback(void)
Definition: cpu_load.cpp:41

◆ readCpuLoadPercent()

uint8_t readCpuLoadPercent ( void  )

Get the value of the CPU load.

Returns
CPU load in percent
Note
If this raises to 100%, there is some blocking code somewhere

Definition at line 39 of file cpu_load.cpp.

39 { return cpuLoadPercent; }

Variable Documentation

◆ cpuLoadLatestCycleCount

uint32_t cpuLoadLatestCycleCount = 0

Definition at line 30 of file cpu_load.cpp.

◆ cpuLoadPercent

volatile uint8_t cpuLoadPercent = 0

Definition at line 25 of file cpu_load.cpp.

◆ cpuLoadTimeCount

uint16_t cpuLoadTimeCount = TIME_CPU_CYCLE_RESET

Definition at line 28 of file cpu_load.cpp.

◆ idleCyclesCount

volatile uint32_t idleCyclesCount = 0

Access to idleCyclesCount needed by the COUNT_IDLE_CYCLE macro.

Definition at line 22 of file cpu_load.cpp.