-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMillisUtils.h
More file actions
68 lines (55 loc) · 2.27 KB
/
MillisUtils.h
File metadata and controls
68 lines (55 loc) · 2.27 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* MillisUtils.h
*
* Copyright (C) 2016-2020 Armin Joachimsmeyer
* Email: [email protected]
*
* This file is part of Arduino-Utils https://github.com/ArminJo/Arduino-Utils.
*
* Arduino-Utils 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/gpl.html>.
*
*/
#ifndef _MILLIS_UTILS_H
#define _MILLIS_UTILS_H
#include <stdint.h>
#if defined(__AVR__)
//void speedTestWith1kCalls(void (*aFunctionUnderTest)(void));
/*
* storage for millis value to enable compensation for interrupt disable at signal acquisition etc.
*/
#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)
#define timer0_millis millis_timer_millis // The ATTinyCore + Digispark libraries use this variable name in wiring.c
#endif
#if defined(TIMSK0) && !defined(TIMSK) // some ATtinys and ATmega328
#define TIMSK TIMSK0
#endif
#if defined(ARDUINO_AVR_DIGISPARK)
// Digispark uses timer1 for millis()
#define TOIE TOIE1
#else
#define TOIE TOIE0 // Assume timer 0 for millis()
#endif
extern volatile unsigned long timer0_millis;
void delayAndCallFunctionEveryMillis(unsigned int aDelayMillis, void (*aDelayCallback)(void));
#if (defined(TIMSK) && defined(TOIE)) || (defined(TIMSK0) && defined(TOIE0))
void disableMillisInterrupt();
void enableMillisInterrupt(uint16_t aMillisToAddForCompensation = 0);
#endif
void addToMillis(uint16_t aMillisToAdd);
void speedTestWith1kCalls(Print *aSerial, void (*aFunctionUnderTest)(void));
#endif // defined(__AVR__)
void delayMilliseconds(unsigned int aMillis);
bool areMillisGone(unsigned int aMillis);
bool areMillisGone(unsigned int aMillis, unsigned long * aLastMillisPtr);
#endif // _MILLIS_UTILS_H