4 #include "libs/nuts_bolts.h"
5 #include "libs/Module.h"
6 #include "libs/Kernel.h"
7 #include "SlowTicker.h"
10 SlowTicker
* global_slow_ticker
;
12 SlowTicker::SlowTicker(){
13 global_slow_ticker
= this;
14 LPC_SC
->PCONP
|= (1 << 22); // Power Ticker ON
15 LPC_TIM2
->MR0
= 1000000; // Initial dummy value for Match Register
16 LPC_TIM2
->MCR
= 3; // Match on MR0, reset on MR0
17 LPC_TIM2
->TCR
= 1; // Enable interrupt
18 NVIC_EnableIRQ(TIMER2_IRQn
); // Enable interrupt handler
21 void SlowTicker::set_frequency( int frequency
){
22 LPC_TIM2
->MR0
= int(floor((SystemCoreClock
/4)/frequency
)); // SystemCoreClock/4 = Timer increments in a second
23 LPC_TIM2
->TCR
= 3; // Reset
24 LPC_TIM2
->TCR
= 1; // Reset
27 void SlowTicker::tick(){
28 for (int i
=0; i
<this->hooks
.size(); i
++){
29 this->hooks
.at(i
)->call();
33 extern "C" void TIMER2_IRQHandler (void){
34 if((LPC_TIM2
->IR
>> 0) & 1){ // If interrupt register set for MR0
35 LPC_TIM2
->IR
|= 1 << 0; // Reset it
36 global_slow_ticker
->tick();