Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SoftTimer.h « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 53d145f6da069fc26c146ad89affeaec3091cd69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * SoftTimer.h
 *
 *  Created on: 21 Jul 2017
 *      Author: David
 */

#ifndef SRC_SOFTTIMER_H_
#define SRC_SOFTTIMER_H_

#include "RepRapFirmware.h"


// Class to implement a software timer
class SoftTimer
{
public:
	typedef bool (*Callback)(void*, uint32_t&);
	typedef uint32_t Ticks;

	SoftTimer();

	// Schedule a callback at a particular tick count, returning true if it was not scheduled because it is already due or imminent
	bool ScheduleCallback(Ticks when, Callback cb, void* param);

	// Cancel any scheduled callbacks
	void CancelCallback();

	// Get the current tick count
	static Ticks GetTimerTicksNow();

	// Get the tick rate
	static Ticks GetTickRate();

	// ISR called from Platform. May sometimes get called prematurely.
	static void Interrupt();

private:
	SoftTimer *next;
	Ticks whenDue;
	Callback callback;
	void *cbParam;

	static SoftTimer * volatile pendingList;			// list of pending callbacks, soonest first
};

#endif /* SRC_SOFTTIMER_H_ */