2 * @brief 18xx/43xx Timer/PWM control functions
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * All rights reserved.
\r
9 * Software that is described herein is for illustrative purposes only
\r
10 * which provides customers with programming information regarding the
\r
11 * LPC products. This software is supplied "AS IS" without any warranties of
\r
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
13 * all warranties, express or implied, including all implied warranties of
\r
14 * merchantability, fitness for a particular purpose and non-infringement of
\r
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
16 * or liability for the use of the software, conveys no license or rights under any
\r
17 * patent, copyright, mask work right, or any other intellectual property rights in
\r
18 * or to any products. NXP Semiconductors reserves the right to make changes
\r
19 * in the software without notification. NXP Semiconductors also makes no
\r
20 * representation or warranty that such application will be suitable for the
\r
21 * specified use without further testing or modification.
\r
24 * Permission to use, copy, modify, and distribute this software and its
\r
25 * documentation is hereby granted, under NXP Semiconductors' and its
\r
26 * licensor's relevant copyrights in the software, without fee, provided that it
\r
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
28 * copyright, permission, and disclaimer notice must appear in all copies of
\r
32 #ifndef __TIMER_18XX_43XX_H_
\r
33 #define __TIMER_18XX_43XX_H_
\r
39 /** @defgroup TIMER_18XX_43XX CHIP: LPC18xx/43xx Timer driver
\r
40 * @ingroup CHIP_18XX_43XX_Drivers
\r
45 * @brief Initialize a timer
\r
46 * @param pTMR : Pointer to timer IP register address
\r
49 void Chip_TIMER_Init(LPC_TIMER_T *pTMR);
\r
52 * @brief Shutdown a timer
\r
53 * @param pTMR : Pointer to timer IP register address
\r
56 void Chip_TIMER_DeInit(LPC_TIMER_T *pTMR);
\r
59 * @brief Determine if a match interrupt is pending
\r
60 * @param pTMR : Pointer to timer IP register address
\r
61 * @param matchnum : Match interrupt number to check
\r
62 * @return false if the interrupt is not pending, otherwise true
\r
63 * Determine if the match interrupt for the passed timer and match
\r
64 * counter is pending.
\r
66 STATIC INLINE bool Chip_TIMER_MatchPending(LPC_TIMER_T *pTMR, int8_t matchnum)
\r
68 return IP_TIMER_MatchPending(pTMR, matchnum);
\r
72 * @brief Determine if a capture interrupt is pending
\r
73 * @param pTMR : Pointer to timer IP register address
\r
74 * @param capnum : Capture interrupt number to check
\r
75 * @return false if the interrupt is not pending, otherwise true
\r
76 * Determine if the capture interrupt for the passed capture pin is
\r
79 STATIC INLINE bool Chip_TIMER_CapturePending(LPC_TIMER_T *pTMR, int8_t capnum)
\r
81 return IP_TIMER_CapturePending(pTMR, capnum);
\r
85 * @brief Clears a (pending) match interrupt
\r
86 * @param pTMR : Pointer to timer IP register address
\r
87 * @param matchnum : Match interrupt number to clear
\r
89 * Clears a pending timer match interrupt.
\r
91 STATIC INLINE void Chip_TIMER_ClearMatch(LPC_TIMER_T *pTMR, int8_t matchnum)
\r
93 IP_TIMER_ClearMatch(pTMR, matchnum);
\r
97 * @brief Clears a (pending) capture interrupt
\r
98 * @param pTMR : Pointer to timer IP register address
\r
99 * @param capnum : Capture interrupt number to clear
\r
101 * Clears a pending timer capture interrupt.
\r
103 STATIC INLINE void Chip_TIMER_ClearCapture(LPC_TIMER_T *pTMR, int8_t capnum)
\r
105 IP_TIMER_ClearCapture(pTMR, capnum);
\r
109 * @brief Enables the timer (starts count)
\r
110 * @param pTMR : Pointer to timer IP register address
\r
112 * Enables the timer to start counting.
\r
114 STATIC INLINE void Chip_TIMER_Enable(LPC_TIMER_T *pTMR)
\r
116 IP_TIMER_Enable(pTMR);
\r
120 * @brief Disables the timer (stops count)
\r
121 * @param pTMR : Pointer to timer IP register address
\r
123 * Disables the timer to stop counting.
\r
125 STATIC INLINE void Chip_TIMER_Disable(LPC_TIMER_T *pTMR)
\r
127 IP_TIMER_Disable(pTMR);
\r
131 * @brief Returns the current timer count
\r
132 * @param pTMR : Pointer to timer IP register address
\r
133 * @return Current timer terminal count value
\r
134 * Returns the current timer terminal count.
\r
136 STATIC INLINE uint32_t Chip_TIMER_ReadCount(LPC_TIMER_T *pTMR)
\r
138 return IP_TIMER_ReadCount(pTMR);
\r
142 * @brief Returns the current prescale count
\r
143 * @param pTMR : Pointer to timer IP register address
\r
144 * @return Current timer prescale count value
\r
145 * Returns the current prescale count.
\r
147 STATIC INLINE uint32_t Chip_TIMER_ReadPrescale(LPC_TIMER_T *pTMR)
\r
149 return IP_TIMER_ReadPrescale(pTMR);
\r
153 * @brief Sets the prescaler value
\r
154 * @param pTMR : Pointer to timer IP register address
\r
155 * @param prescale : Prescale value to set the prescale register to
\r
157 * Sets the prescale count value.
\r
159 STATIC INLINE void Chip_TIMER_PrescaleSet(LPC_TIMER_T *pTMR, uint32_t prescale)
\r
161 IP_TIMER_PrescaleSet(pTMR, prescale);
\r
165 * @brief Sets a timer match value
\r
166 * @param pTMR : Pointer to timer IP register address
\r
167 * @param matchnum : Match timer to set match count for
\r
168 * @param matchval : Match value for the selected match count
\r
170 * Sets ones of the timer match values.
\r
172 STATIC INLINE void Chip_TIMER_SetMatch(LPC_TIMER_T *pTMR, int8_t matchnum, uint32_t matchval)
\r
174 IP_TIMER_SetMatch(pTMR, matchnum, matchval);
\r
178 * @brief Reads a capture register
\r
179 * @param pTMR : Pointer to timer IP register address
\r
180 * @param capnum : Capture register to read
\r
181 * @return The selected capture register value
\r
182 * Returns the selected capture register value.
\r
184 STATIC INLINE uint32_t Chip_TIMER_ReadCapture(LPC_TIMER_T *pTMR, int8_t capnum)
\r
186 return IP_TIMER_ReadCapture(pTMR, capnum);
\r
190 * @brief Resets the timer terminal and prescale counts to 0
\r
191 * @param pTMR : Pointer to timer IP register address
\r
194 STATIC INLINE void Chip_TIMER_Reset(LPC_TIMER_T *pTMR)
\r
196 IP_TIMER_Reset(pTMR);
\r
200 * @brief Enables a match interrupt that fires when the terminal count
\r
201 * matches the match counter value.
\r
202 * @param pTMR : Pointer to timer IP register address
\r
203 * @param matchnum : Match timer, 0 to 3
\r
206 STATIC INLINE void Chip_TIMER_MatchEnableInt(LPC_TIMER_T *pTMR, int8_t matchnum)
\r
208 IP_TIMER_MatchEnableInt(pTMR, matchnum);
\r
212 * @brief Disables a match interrupt for a match counter.
\r
213 * @param pTMR : Pointer to timer IP register address
\r
214 * @param matchnum : Match timer, 0 to 3
\r
217 STATIC INLINE void Chip_TIMER_MatchDisableInt(LPC_TIMER_T *pTMR, int8_t matchnum)
\r
219 IP_TIMER_MatchDisableInt(pTMR, matchnum);
\r
223 * @brief For the specific match counter, enables reset of the terminal count register when a match occurs
\r
224 * @param pTMR : Pointer to timer IP register address
\r
225 * @param matchnum : Match timer, 0 to 3
\r
228 STATIC INLINE void Chip_TIMER_ResetOnMatchEnable(LPC_TIMER_T *pTMR, int8_t matchnum)
\r
230 IP_TIMER_ResetOnMatchEnable(pTMR, matchnum);
\r
234 * @brief For the specific match counter, disables reset of the terminal count register when a match occurs
\r
235 * @param pTMR : Pointer to timer IP register address
\r
236 * @param matchnum : Match timer, 0 to 3
\r
239 STATIC INLINE void Chip_TIMER_ResetOnMatchDisable(LPC_TIMER_T *pTMR, int8_t matchnum)
\r
241 IP_TIMER_ResetOnMatchDisable(pTMR, matchnum);
\r
245 * @brief Enable a match timer to stop the terminal count when a
\r
246 * match count equals the terminal count.
\r
247 * @param pTMR : Pointer to timer IP register address
\r
248 * @param matchnum : Match timer, 0 to 3
\r
251 STATIC INLINE void Chip_TIMER_StopOnMatchEnable(LPC_TIMER_T *pTMR, int8_t matchnum)
\r
253 IP_TIMER_StopOnMatchEnable(pTMR, matchnum);
\r
257 * @brief Disable stop on match for a match timer. Disables a match timer
\r
258 * to stop the terminal count when a match count equals the terminal count.
\r
259 * @param pTMR : Pointer to timer IP register address
\r
260 * @param matchnum : Match timer, 0 to 3
\r
263 STATIC INLINE void Chip_TIMER_StopOnMatchDisable(LPC_TIMER_T *pTMR, int8_t matchnum)
\r
265 IP_TIMER_StopOnMatchDisable(pTMR, matchnum);
\r
269 * @brief Enables capture on on rising edge of selected CAP signal for the
\r
270 * selected capture register, enables the selected CAPn.capnum signal to load
\r
271 * the capture register with the terminal coount on a rising edge.
\r
272 * @param pTMR : Pointer to timer IP register address
\r
273 * @param capnum : Capture signal/register to use
\r
276 STATIC INLINE void Chip_TIMER_CaptureRisingEdgeEnable(LPC_TIMER_T *pTMR, int8_t capnum)
\r
278 IP_TIMER_CaptureRisingEdgeEnable(pTMR, capnum);
\r
282 * @brief Disables capture on on rising edge of selected CAP signal. For the
\r
283 * selected capture register, disables the selected CAPn.capnum signal to load
\r
284 * the capture register with the terminal coount on a rising edge.
\r
285 * @param pTMR : Pointer to timer IP register address
\r
286 * @param capnum : Capture signal/register to use
\r
289 STATIC INLINE void Chip_TIMER_CaptureRisingEdgeDisable(LPC_TIMER_T *pTMR, int8_t capnum)
\r
291 IP_TIMER_CaptureRisingEdgeDisable(pTMR, capnum);
\r
295 * @brief Enables capture on on falling edge of selected CAP signal. For the
\r
296 * selected capture register, enables the selected CAPn.capnum signal to load
\r
297 * the capture register with the terminal coount on a falling edge.
\r
298 * @param pTMR : Pointer to timer IP register address
\r
299 * @param capnum : Capture signal/register to use
\r
302 STATIC INLINE void Chip_TIMER_CaptureFallingEdgeEnable(LPC_TIMER_T *pTMR, int8_t capnum)
\r
304 IP_TIMER_CaptureFallingEdgeEnable(pTMR, capnum);
\r
308 * @brief Disables capture on on falling edge of selected CAP signal. For the
\r
309 * selected capture register, disables the selected CAPn.capnum signal to load
\r
310 * the capture register with the terminal coount on a falling edge.
\r
311 * @param pTMR : Pointer to timer IP register address
\r
312 * @param capnum : Capture signal/register to use
\r
315 STATIC INLINE void Chip_TIMER_CaptureFallingEdgeDisable(LPC_TIMER_T *pTMR, int8_t capnum)
\r
317 IP_TIMER_CaptureFallingEdgeDisable(pTMR, capnum);
\r
321 * @brief Enables interrupt on capture of selected CAP signal. For the
\r
322 * selected capture register, an interrupt will be generated when the enabled
\r
323 * rising or falling edge on CAPn.capnum is detected.
\r
324 * @param pTMR : Pointer to timer IP register address
\r
325 * @param capnum : Capture signal/register to use
\r
328 STATIC INLINE void Chip_TIMER_CaptureEnableInt(LPC_TIMER_T *pTMR, int8_t capnum)
\r
330 IP_TIMER_CaptureEnableInt(pTMR, capnum);
\r
334 * @brief Disables interrupt on capture of selected CAP signal
\r
335 * @param pTMR : Pointer to timer IP register address
\r
336 * @param capnum : Capture signal/register to use
\r
339 STATIC INLINE void Chip_TIMER_CaptureDisableInt(LPC_TIMER_T *pTMR, int8_t capnum)
\r
341 IP_TIMER_CaptureDisableInt(pTMR, capnum);
\r
345 * @brief Sets external match control (MATn.matchnum) pin control
\r
346 * @param pTMR : Pointer to timer IP register address
\r
347 * @param initial_state : Initial state of the pin, high(1) or low(0)
\r
348 * @param matchState : Selects the match state for the pin
\r
349 * @param matchnum : MATn.matchnum signal to use
\r
351 * For the pin selected with matchnum, sets the function of the pin that occurs on
\r
352 * a terminal count match for the match count.
\r
354 STATIC INLINE void Chip_TIMER_ExtMatchControlSet(LPC_TIMER_T *pTMR, int8_t initial_state,
\r
355 IP_TIMER_PIN_MATCH_STATE_T matchState, int8_t matchnum)
\r
357 IP_TIMER_ExtMatchControlSet(pTMR, initial_state, matchState, matchnum);
\r
361 * @brief Sets timer count source and edge with the selected passed from CapSrc
\r
362 * @param pTMR : Pointer to timer IP register address
\r
363 * @param capSrc : timer clock source and edge
\r
364 * @param capnum : CAPn.capnum pin to use (if used)
\r
366 * If CapSrc selected a CAPn pin, select the specific CAPn pin with the capnum value.
\r
368 STATIC INLINE void Chip_TIMER_TIMER_SetCountClockSrc(LPC_TIMER_T *pTMR,
\r
369 IP_TIMER_CAP_SRC_STATE_T capSrc,
\r
372 IP_TIMER_SetCountClockSrc(pTMR, capSrc, capnum);
\r
383 #endif /* __TIMER_18XX_43XX_H_ */
\r