summaryrefslogtreecommitdiffstats
path: root/bsps/arm/lpc176x/include/bsp/timer.h
blob: bb327eefcea1bbb7e04744593d7c363d988859e0 (plain) (blame)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/**
 * @file
 *
 * @ingroup lpc176x
 *
 * @brief Timer API for the lpc176x bsp.
 */

/*
 * Copyright (c) 2014 Taller Technologies.
 *
 * @author  Boretto Martin    (martin.boretto@tallertechnologies.com)
 * @author  Diaz Marcos (marcos.diaz@tallertechnologies.com)
 * @author  Lenarduzzi Federico  (federico.lenarduzzi@tallertechnologies.com)
 * @author  Daniel Chicco  (daniel.chicco@tallertechnologies.com)
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.org/license/LICENSE.
 */

#ifndef LIBBSP_ARM_LPC176X_TIMER_H
#define LIBBSP_ARM_LPC176X_TIMER_H

#include <bsp/timer-defs.h>

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/**
 * @brief resets timer counter and stops it.
 *
 * @param tnumber the device to be reseted
 * @return RTEMS_SUCCESSFUL if the timer was reseted successfuly.
 */
rtems_status_code lpc176x_timer_reset( lpc176x_timer_number tnumber );

/**
 * @brief Sets mode of the timer (timer, counter rising, counter falling
 *        or counter both edges)
 *
 * @param tnumber: the device to be setted
 * @param mode: the desired mode
 * @return RTEMS_SUCCESSFUL if the timer's mode was setted successfuly.
 */
rtems_status_code lpc176x_timer_set_mode(
  lpc176x_timer_number tnumber,
  lpc176x_timer_mode   mode
);

/**
 * @brief Starts the timer counter
 *
 * @param tnumber: the device to be started
 * @return RTEMS_SUCCESSFUL if the timer's was started successfuly.
 */
rtems_status_code lpc176x_timer_start( lpc176x_timer_number tnumber );

/**
 * @brief true if timer is started.
 *
 * @param tnumber: the timer number to check.
 * @param is_started: TRUE if the timer is running.
 * @return RTEMS_SUCCESSFUL if the started timer check was successfuly.
 */
rtems_status_code lpc176x_timer_is_started(
  lpc176x_timer_number tnumber,
  bool                *is_started
);

/**
 * @brief sets the resolution in microseconds of the timer
 *
 * @param tnumber: the device to be modified.
 * @param resolution: how many microseconds will mean each timer
 *                    counter unit.
 * @return RTEMS_SUCCESSFUL if the timer resolution was setted successfuly.
 */
rtems_status_code lpc176x_timer_set_resolution(
  lpc176x_timer_number tnumber,
  lpc176x_microseconds resolution
);

/**
 * @brief Configures the timer match
 *
 * @param tnumber: the device to be modified
 * @param match_port: which port of this timer will be setted
 * @param function: what the timer should do when match: stop timer, clear,
 *                  and/or interrupt
 * @param match_value: the value that the timer should match.
 * @return RTEMS_SUCCESSFUL if the timer was configured successfuly.
 */
rtems_status_code lpc176x_timer_match_config(
  lpc176x_timer_number   tnumber,
  lpc176x_match_port     match_port,
  lpc176x_match_function function,
  uint32_t               match_value
);

/**
 * @brief Configures the capture ports
 *
 * @param tnumber: the device to be modified
 * @param capture_port: which port of this timer will be setted
 * @param function: At which edge/s will the capture work, and
 *                  if it will interrupt
 */
rtems_status_code lpc176x_timer_capture_config(
  lpc176x_timer_number     tnumber,
  lpc176x_capture_port     capture_port,
  lpc176x_capture_function function
);

/**
 * @brief Configures the external match ports
 *
 * @param tnumber: the device to be modified
 * @param match_port: which match for this timer
 * @param function: what should do when match: set, clear toggle or nothing
 */
rtems_status_code lpc176x_timer_external_match_config(
  lpc176x_timer_number       tnumber,
  lpc176x_match_port         match_port,
  lpc176x_ext_match_function function
);

/**
 * @brief Gets the captured value
 *
 * @param tnumber: the device to be modified
 * @param capnumber: which capture port for this timer
 * @return the captured value
 */
uint32_t lpc176x_timer_get_capvalue(
  lpc176x_timer_number tnumber,
  lpc176x_capture_port capnumber
);

/**
 * @brief Gets the timer value
 *
 * @param tnumber: the device
 * @return the timer value
 */
uint32_t lpc176x_timer_get_timer_value( lpc176x_timer_number tnumber );

/**
 * @brief Sets the timer value
 *
 * @param tnumber: the timer to modify.
 * @param timer_value the value to set.
 */
rtems_status_code lpc176x_timer_set_timer_value(
  lpc176x_timer_number tnumber,
  uint32_t             lpc176x_timer_value
);

/**
 * @brief Timer generic isroutine.
 *
 * @param timernumber the number of timer.
 */
void lpc176x_timer_isr( void *lpc176x_timer_number );

/**
 * @brief Initializes timer in timer mode and resets counter but
 *        without starting it, and without any capture or
 *        match function.
 *
 * @param tnumber which timer
 * @return RTEMS_SUCCESSFUL when everything ok.
 */
rtems_status_code lpc176x_timer_init( lpc176x_timer_number tnumber );

/**
 * @brief Initializes timer in timer mode and resets counter but
 *        without starting it, and without any capture or
 *        match function.
 *
 * @param tnumber which timer to init
 * @param vector the functions to be used by the isr.
 * @return RTEMS_SUCCESSFUL when everything ok.
 */
rtems_status_code lpc176x_timer_init_with_interrupt(
  lpc176x_timer_number            tnumber,
  const lpc176x_isr_funct_vector *vector
);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* LIBBSP_ARM_LPC176X_TIMER_H */