Prusa MINI Firmware overview
Timer Class Reference

#include <Timer.h>

Public Types

typedef void() callback_fn()
 

Public Member Functions

 Timer ()
 
virtual ~Timer ()
 
void init (uint32_t sig_id, uint32_t sim_freq, callback_fn *fn)
 
void start (uint32_t frequency)
 
void enable ()
 
bool enabled ()
 
void disable ()
 
void setCompare (uint32_t compare)
 
uint32_t getCount ()
 
uint32_t getCompare ()
 
uint32_t getOverruns ()
 
uint32_t getAvgError ()
 
intptr_t getID ()
 

Static Public Member Functions

static void handler (int sig, siginfo_t *si, void *uc)
 

Detailed Description

Marlin 3D Printer Firmware Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]

Based on Sprinter and grbl. Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm

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 3 of the License, 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. If not, see http://www.gnu.org/licenses/.

Member Typedef Documentation

◆ callback_fn

typedef void() Timer::callback_fn()

Constructor & Destructor Documentation

◆ Timer()

Timer::Timer ( )

◆ ~Timer()

virtual Timer::~Timer ( )
virtual

Member Function Documentation

◆ init()

void Timer::init ( uint32_t  sig_id,
uint32_t  sim_freq,
callback_fn fn 
)

◆ start()

void Timer::start ( uint32_t  frequency)

◆ enable()

void Timer::enable ( )

◆ enabled()

bool Timer::enabled ( )
43 {return active;}

◆ disable()

void Timer::disable ( )

◆ setCompare()

void Timer::setCompare ( uint32_t  compare)

◆ getCount()

uint32_t Timer::getCount ( )

◆ getCompare()

uint32_t Timer::getCompare ( )
47 {return compare;}

◆ getOverruns()

uint32_t Timer::getOverruns ( )
48 {return overruns;}

◆ getAvgError()

uint32_t Timer::getAvgError ( )
49 {return avg_error;}

◆ getID()

intptr_t Timer::getID ( )
51  {
52  return (*(intptr_t*)timerid);
53  }

◆ handler()

static void Timer::handler ( int  sig,
siginfo_t *  si,
void uc 
)
static
55  {
56  Timer* _this = (Timer*)si->si_value.sival_ptr;
57  _this->avg_error += (Clock::nanos() - _this->start_time) - _this->period; //high_resolution_clock is also limited in precision, but best we have
58  _this->avg_error /= 2; //very crude precision analysis (actually within +-500ns usually)
59  _this->start_time = Clock::nanos(); // wrap
60  _this->cbfn();
61  _this->overruns += timer_getoverrun(_this->timerid); // even at 50Khz this doesn't stay zero, again demonstrating the limitations
62  // using a realtime linux kernel would help somewhat
63  }
Here is the call graph for this function:
Clock::nanos
static uint64_t nanos()
Definition: Clock.h:47
Timer
Definition: Timer.h:33