Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
TivaCpuLoad.hxx
Go to the documentation of this file.
1
35#ifndef _FREERTOS_DRIVERS_TI_TIVACPULOAD_HXX_
36#define _FREERTOS_DRIVERS_TI_TIVACPULOAD_HXX_
37
38#include "driverlib/timer.h"
39#include "driverlib/interrupt.h"
40#include "inc/hw_ints.h"
42
45{
47 static constexpr auto TIMER_BASE = TIMER4_BASE;
49 static constexpr unsigned TIMER = TIMER_A;
51 static constexpr auto TIMER_PERIPH = SYSCTL_PERIPH_TIMER4;
53 static constexpr auto TIMER_INTERRUPT = INT_TIMER4A;
55 static constexpr unsigned TIMER_PERIOD = 80000000 / 127;
56};
57
60template<class HW>
62public:
65 setup();
66 }
67
69 static void setup()
70 {
71 MAP_SysCtlPeripheralEnable(HW::TIMER_PERIPH);
72 MAP_TimerDisable(HW::TIMER_BASE, HW::TIMER);
73 MAP_TimerClockSourceSet(HW::TIMER_BASE, TIMER_CLOCK_SYSTEM);
74 MAP_TimerConfigure(HW::TIMER_BASE, TIMER_CFG_PERIODIC);
75
76 MAP_TimerLoadSet(HW::TIMER_BASE, HW::TIMER, HW::TIMER_PERIOD);
77
78 MAP_IntDisable(HW::TIMER_INTERRUPT);
79 // We interrupt all other interrupts in order to ensure we measure
80 // correct cpu usage.
81 MAP_IntPrioritySet(HW::TIMER_INTERRUPT, 0);
82 MAP_TimerIntEnable(HW::TIMER_BASE, TIMER_TIMA_TIMEOUT);
83 MAP_TimerEnable(HW::TIMER_BASE, HW::TIMER);
84 MAP_IntEnable(HW::TIMER_INTERRUPT);
85 }
86
88 void interrupt_handler(unsigned p)
89 {
90 MAP_TimerIntClear(HW::TIMER_BASE, TIMER_TIMA_TIMEOUT);
91 cpuload_tick(p);
92 }
93
96 CpuLoad load_;
97};
98
99
100
101#endif // _FREERTOS_DRIVERS_TI_TIVACPULOAD_HXX_
Driver to collect CPU load information (in freertos) using a Tiva hardware timer.
static void setup()
Creates the timer configuration for the tick interrupt.
TivaCpuLoad()
Constructor.
CpuLoad load_
The singleton implementation we delegate collecting the CPULoad information.
void interrupt_handler(unsigned p)
Call this function from extern "C" void timer4a_interrupt_handler().
Default hardware structure for the TivaCpuLoad driver.
static constexpr auto TIMER_BASE
Timer address base to use.
static constexpr unsigned TIMER_PERIOD
Period in clock cycles to tick upon for the Cpu Load calculation.
static constexpr unsigned TIMER
Which side of the timer we should be using.
static constexpr auto TIMER_INTERRUPT
Interrupt ID belonging to the given timer.
static constexpr auto TIMER_PERIPH
Peripheral constant to enable the clock output on.