PushToGo on STM32F429-Disco Board
Dependencies: BSP_DISCO_F429ZI LCD_DISCO_F429ZI pushtogo usb
Diff: MCULoadMeasurement.h
- Revision:
- 1:64c1fd738059
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MCULoadMeasurement.h Sun Sep 09 19:03:27 2018 +0000 @@ -0,0 +1,53 @@ +#ifndef MCULOADMEASUREMENT_H_ +#define MCULOADMEASUREMENT_H_ + +#include "mbed.h" + +class MCULoadMeasurement +{ +protected: + Timer t; + Timer t_active; +public: + + MCULoadMeasurement() + { + t.start(); + t_active.start(); + } + virtual ~MCULoadMeasurement() + { + } + + virtual void reset() + { + t.reset(); + t_active.reset(); + } + + virtual float getCPUUsage() + { + return t_active.read() / t.read(); + } + + virtual void setMCUActive(bool active) + { + if (active) //idle task sched out + { + t_active.start(); + } + else //idle task sched in + { + t_active.stop(); + } + } + + static MCULoadMeasurement &getInstance() + { + static MCULoadMeasurement m; + return m; + } +}; + +#endif // MCULOADMEASUREMENT_H_ +