[f51d3d]: ilg.gnuarmeclipse.templates.cortexm / templates / common / include / Timer-cpp.h  Maximize  Restore  History

Download this file

50 lines (38 with data), 904 Bytes

 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
48
49
//
// This file is part of the GNU ARM Eclipse distribution.
// Copyright (c) 2014 Liviu Ionescu.
//
#ifndef TIMER_H_
#define TIMER_H_
#include "cmsis_device.h"
// ----------------------------------------------------------------------------
class Timer
{
public:
typedef uint32_t ticks_t;
static constexpr ticks_t FREQUENCY_HZ = 1000u;
private:
static volatile ticks_t ms_delayCount;
public:
// Default constructor
Timer() = default;
inline void
start()
{
// Use SysTick as reference for the delay loops.
SysTick_Config(SystemCoreClock / FREQUENCY_HZ);
}
static void
sleep(ticks_t ticks);
inline static void
tick()
{
// Decrement to zero the counter used by the delay routine.
if (ms_delayCount != 0u)
{
--ms_delayCount;
}
}
};
// ----------------------------------------------------------------------------
#endif // TIMER_H_

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks