]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC/ThirdParty/LPCOpen/lpc_core/lpc_chip/chip_18xx_43xx/timer_18xx_43xx.h
Update LPC18xx FreeRTOS+UDP demo to use LPCOpen USB and Ethernet drivers.
[freertos] / FreeRTOS-Plus / Demo / FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC / ThirdParty / LPCOpen / lpc_core / lpc_chip / chip_18xx_43xx / timer_18xx_43xx.h
1 /*\r
2  * @brief 18xx/43xx Timer/PWM control functions\r
3  *\r
4  * @note\r
5  * Copyright(C) NXP Semiconductors, 2012\r
6  * All rights reserved.\r
7  *\r
8  * @par\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
22  *\r
23  * @par\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
29  * this code.\r
30  */\r
31 \r
32 #ifndef __TIMER_18XX_43XX_H_\r
33 #define __TIMER_18XX_43XX_H_\r
34 \r
35 #ifdef __cplusplus\r
36 extern "C" {\r
37 #endif\r
38 \r
39 /** @defgroup TIMER_18XX_43XX CHIP: LPC18xx/43xx Timer driver\r
40  * @ingroup CHIP_18XX_43XX_Drivers\r
41  * @{\r
42  */\r
43 \r
44 /**\r
45  * @brief       Initialize a timer\r
46  * @param       pTMR    : Pointer to timer IP register address\r
47  * @return      Nothing\r
48  */\r
49 void Chip_TIMER_Init(LPC_TIMER_T *pTMR);\r
50 \r
51 /**\r
52  * @brief       Shutdown a timer\r
53  * @param       pTMR    : Pointer to timer IP register address\r
54  * @return      Nothing\r
55  */\r
56 void Chip_TIMER_DeInit(LPC_TIMER_T *pTMR);\r
57 \r
58 /**\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
65  */\r
66 STATIC INLINE bool Chip_TIMER_MatchPending(LPC_TIMER_T *pTMR, int8_t matchnum)\r
67 {\r
68         return IP_TIMER_MatchPending(pTMR, matchnum);\r
69 }\r
70 \r
71 /**\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
77  * pending.\r
78  */\r
79 STATIC INLINE bool Chip_TIMER_CapturePending(LPC_TIMER_T *pTMR, int8_t capnum)\r
80 {\r
81         return IP_TIMER_CapturePending(pTMR, capnum);\r
82 }\r
83 \r
84 /**\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
88  * @return      Nothing\r
89  * Clears a pending timer match interrupt.\r
90  */\r
91 STATIC INLINE void Chip_TIMER_ClearMatch(LPC_TIMER_T *pTMR, int8_t matchnum)\r
92 {\r
93         IP_TIMER_ClearMatch(pTMR, matchnum);\r
94 }\r
95 \r
96 /**\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
100  * @return      Nothing\r
101  * Clears a pending timer capture interrupt.\r
102  */\r
103 STATIC INLINE void Chip_TIMER_ClearCapture(LPC_TIMER_T *pTMR, int8_t capnum)\r
104 {\r
105         IP_TIMER_ClearCapture(pTMR, capnum);\r
106 }\r
107 \r
108 /**\r
109  * @brief       Enables the timer (starts count)\r
110  * @param       pTMR    : Pointer to timer IP register address\r
111  * @return      Nothing\r
112  * Enables the timer to start counting.\r
113  */\r
114 STATIC INLINE void Chip_TIMER_Enable(LPC_TIMER_T *pTMR)\r
115 {\r
116         IP_TIMER_Enable(pTMR);\r
117 }\r
118 \r
119 /**\r
120  * @brief       Disables the timer (stops count)\r
121  * @param       pTMR    : Pointer to timer IP register address\r
122  * @return      Nothing\r
123  * Disables the timer to stop counting.\r
124  */\r
125 STATIC INLINE void Chip_TIMER_Disable(LPC_TIMER_T *pTMR)\r
126 {\r
127         IP_TIMER_Disable(pTMR);\r
128 }\r
129 \r
130 /**\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
135  */\r
136 STATIC INLINE uint32_t Chip_TIMER_ReadCount(LPC_TIMER_T *pTMR)\r
137 {\r
138         return IP_TIMER_ReadCount(pTMR);\r
139 }\r
140 \r
141 /**\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
146  */\r
147 STATIC INLINE uint32_t Chip_TIMER_ReadPrescale(LPC_TIMER_T *pTMR)\r
148 {\r
149         return IP_TIMER_ReadPrescale(pTMR);\r
150 }\r
151 \r
152 /**\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
156  * @return      Nothing\r
157  * Sets the prescale count value.\r
158  */\r
159 STATIC INLINE void Chip_TIMER_PrescaleSet(LPC_TIMER_T *pTMR, uint32_t prescale)\r
160 {\r
161         IP_TIMER_PrescaleSet(pTMR, prescale);\r
162 }\r
163 \r
164 /**\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
169  * @return      Nothing\r
170  * Sets ones of the timer match values.\r
171  */\r
172 STATIC INLINE void Chip_TIMER_SetMatch(LPC_TIMER_T *pTMR, int8_t matchnum, uint32_t matchval)\r
173 {\r
174         IP_TIMER_SetMatch(pTMR, matchnum, matchval);\r
175 }\r
176 \r
177 /**\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
183  */\r
184 STATIC INLINE uint32_t Chip_TIMER_ReadCapture(LPC_TIMER_T *pTMR, int8_t capnum)\r
185 {\r
186         return IP_TIMER_ReadCapture(pTMR, capnum);\r
187 }\r
188 \r
189 /**\r
190  * @brief       Resets the timer terminal and prescale counts to 0\r
191  * @param       pTMR    : Pointer to timer IP register address\r
192  * @return      Nothing\r
193  */\r
194 STATIC INLINE void Chip_TIMER_Reset(LPC_TIMER_T *pTMR)\r
195 {\r
196         IP_TIMER_Reset(pTMR);\r
197 }\r
198 \r
199 /**\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
204  * @return      Nothing\r
205  */\r
206 STATIC INLINE void Chip_TIMER_MatchEnableInt(LPC_TIMER_T *pTMR, int8_t matchnum)\r
207 {\r
208         IP_TIMER_MatchEnableInt(pTMR, matchnum);\r
209 }\r
210 \r
211 /**\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
215  * @return      Nothing\r
216  */\r
217 STATIC INLINE void Chip_TIMER_MatchDisableInt(LPC_TIMER_T *pTMR, int8_t matchnum)\r
218 {\r
219         IP_TIMER_MatchDisableInt(pTMR, matchnum);\r
220 }\r
221 \r
222 /**\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
226  * @return      Nothing\r
227  */\r
228 STATIC INLINE void Chip_TIMER_ResetOnMatchEnable(LPC_TIMER_T *pTMR, int8_t matchnum)\r
229 {\r
230         IP_TIMER_ResetOnMatchEnable(pTMR, matchnum);\r
231 }\r
232 \r
233 /**\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
237  * @return      Nothing\r
238  */\r
239 STATIC INLINE void Chip_TIMER_ResetOnMatchDisable(LPC_TIMER_T *pTMR, int8_t matchnum)\r
240 {\r
241         IP_TIMER_ResetOnMatchDisable(pTMR, matchnum);\r
242 }\r
243 \r
244 /**\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
249  * @return      Nothing\r
250  */\r
251 STATIC INLINE void Chip_TIMER_StopOnMatchEnable(LPC_TIMER_T *pTMR, int8_t matchnum)\r
252 {\r
253         IP_TIMER_StopOnMatchEnable(pTMR, matchnum);\r
254 }\r
255 \r
256 /**\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
261  * @return      Nothing\r
262  */\r
263 STATIC INLINE void Chip_TIMER_StopOnMatchDisable(LPC_TIMER_T *pTMR, int8_t matchnum)\r
264 {\r
265         IP_TIMER_StopOnMatchDisable(pTMR, matchnum);\r
266 }\r
267 \r
268 /**\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
274  * @return      Nothing\r
275  */\r
276 STATIC INLINE void Chip_TIMER_CaptureRisingEdgeEnable(LPC_TIMER_T *pTMR, int8_t capnum)\r
277 {\r
278         IP_TIMER_CaptureRisingEdgeEnable(pTMR, capnum);\r
279 }\r
280 \r
281 /**\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
287  * @return      Nothing\r
288  */\r
289 STATIC INLINE void Chip_TIMER_CaptureRisingEdgeDisable(LPC_TIMER_T *pTMR, int8_t capnum)\r
290 {\r
291         IP_TIMER_CaptureRisingEdgeDisable(pTMR, capnum);\r
292 }\r
293 \r
294 /**\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
300  * @return      Nothing\r
301  */\r
302 STATIC INLINE void Chip_TIMER_CaptureFallingEdgeEnable(LPC_TIMER_T *pTMR, int8_t capnum)\r
303 {\r
304         IP_TIMER_CaptureFallingEdgeEnable(pTMR, capnum);\r
305 }\r
306 \r
307 /**\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
313  * @return      Nothing\r
314  */\r
315 STATIC INLINE void Chip_TIMER_CaptureFallingEdgeDisable(LPC_TIMER_T *pTMR, int8_t capnum)\r
316 {\r
317         IP_TIMER_CaptureFallingEdgeDisable(pTMR, capnum);\r
318 }\r
319 \r
320 /**\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
326  * @return      Nothing\r
327  */\r
328 STATIC INLINE void Chip_TIMER_CaptureEnableInt(LPC_TIMER_T *pTMR, int8_t capnum)\r
329 {\r
330         IP_TIMER_CaptureEnableInt(pTMR, capnum);\r
331 }\r
332 \r
333 /**\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
337  * @return      Nothing\r
338  */\r
339 STATIC INLINE void Chip_TIMER_CaptureDisableInt(LPC_TIMER_T *pTMR, int8_t capnum)\r
340 {\r
341         IP_TIMER_CaptureDisableInt(pTMR, capnum);\r
342 }\r
343 \r
344 /**\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
350  * @return      Nothing\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
353  */\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
356 {\r
357         IP_TIMER_ExtMatchControlSet(pTMR, initial_state, matchState, matchnum);\r
358 }\r
359 \r
360 /**\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
365  * @return      Nothing\r
366  * If CapSrc selected a CAPn pin, select the specific CAPn pin with the capnum value.\r
367  */\r
368 STATIC INLINE void Chip_TIMER_TIMER_SetCountClockSrc(LPC_TIMER_T *pTMR,\r
369                                                                                                          IP_TIMER_CAP_SRC_STATE_T capSrc,\r
370                                                                                                          int8_t capnum)\r
371 {\r
372         IP_TIMER_SetCountClockSrc(pTMR, capSrc, capnum);\r
373 }\r
374 \r
375 /**\r
376  * @}\r
377  */\r
378 \r
379 #ifdef __cplusplus\r
380 }\r
381 #endif\r
382 \r
383 #endif /* __TIMER_18XX_43XX_H_ */\r