-
Notifications
You must be signed in to change notification settings - Fork 0
/
Timer.h
118 lines (103 loc) · 3.13 KB
/
Timer.h
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* timer.h
*
* Created on: Mar 15, 2019
* @author Isaac Rex
*/
#ifndef TIMER_H_
#define TIMER_H_
#include <inc/tm4c123gh6pm.h>
#include <stdbool.h>
#include <stdint.h>
#include "driverlib/interrupt.h"
/**
* @brief Initialize and start the clock at 0. If the clock is
* already running on a call, reset the time count back to 0. Uses TIMER5.
*
*/
void timer_init(void);
/**
* @brief Stop the clock and free up TIMER5. Resets the value returned by
* getMillis() and get Micros().
*
*/
void timer_stop(void);
/**
* @brief Pauses the clock at the current value.
*
*/
void timer_pause(void);
/**
* @brief Resumes the clock after a call to pauseClock().
*
*/
void timer_resume(void);
/**
* @brief Returns the number milliseconds that have passed since startClock()
* was called. Value rolls over after about 49 days.
*
* @return unsigned int number of milliseconds since a call to
* timer_startClock()
*/
unsigned int timer_getMillis(void);
/**
* @brief Returns the number of microseconds passed since a call to
* startClock(). Value rolls over after about 71 minutes.
*
* @return unsigned int number of microseconds since a call to startClock()
*/
unsigned int timer_getMicros(void);
/**
* @brief Pauses execution for the specifeid number of microseconds.
*
* @param delay_time number of microseconds to pause for
*/
void timer_waitMillis(unsigned int delay_time);
/**
* @brief Pauses execution for the specifeid number of microseconds.
*
* @param delay_time number of microseconds to pause for
*/
void timer_waitMicros(unsigned int delay_time);
// TODO: Implement
/**
* @brief Sets up an interrupt to call the given function once every given
* milliseconds. Uses TIMER4 for the countdown. Function f executes inside an
* ISR, so keep the passed function as short as possible. Maximum interval time
* is TODO: calculate
*
* @param f the function to call
* @param millis the interval between calls
*/
void timer_fireEvery(void (*f)(void), int millis);
// TODO: Implement
/**
* @brief Sets up an interrupt to call the given function after the given number
* of milliseconds. Uses TIMER4 for the countdown, and thus can only be used
* when timer_fireEvery() and timer_fireFor() are not being used. Function f
* executes inside an ISR and should be kept as short as possible.
*
* @param f the function to call
* @param millis milliseconds until call
*/
void timer_fireOnce(void (*f)(void), int millis);
// TODO: Implement
/**
* @brief Sets up an interrupt to call the given function after the given number
* of milliseconds for the given number of times. Uses TIMER4 for the countdown,
* and thus can only be used when fireOnce() and fireEvery() are not being used.
* Function f executes inside an ISR and should be kept as short as possible.
* Maximum interval time is TODO: calculate
*
* @param f the function to call
* @param millis milliseconds until call
* @param times number of times to call f
*/
void timer_fireFor(void (*f)(void), int millis, int times);
/**
* @brief ISR handler to increment the timeout variable for tracking total
* milliseconds
*
*/
static void timer_clockTickHandler();
#endif /* TIMER_H_ */