timer_11xx.h
Go to the documentation of this file.
1 /*
2  * @brief LPC11xx 16/32-bit Timer/PWM control functions
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2012
6  * All rights reserved.
7  *
8  * @par
9  * Software that is described herein is for illustrative purposes only
10  * which provides customers with programming information regarding the
11  * LPC products. This software is supplied "AS IS" without any warranties of
12  * any kind, and NXP Semiconductors and its licensor disclaim any and
13  * all warranties, express or implied, including all implied warranties of
14  * merchantability, fitness for a particular purpose and non-infringement of
15  * intellectual property rights. NXP Semiconductors assumes no responsibility
16  * or liability for the use of the software, conveys no license or rights under any
17  * patent, copyright, mask work right, or any other intellectual property rights in
18  * or to any products. NXP Semiconductors reserves the right to make changes
19  * in the software without notification. NXP Semiconductors also makes no
20  * representation or warranty that such application will be suitable for the
21  * specified use without further testing or modification.
22  *
23  * @par
24  * Permission to use, copy, modify, and distribute this software and its
25  * documentation is hereby granted, under NXP Semiconductors' and its
26  * licensor's relevant copyrights in the software, without fee, provided that it
27  * is used in conjunction with NXP Semiconductors microcontrollers. This
28  * copyright, permission, and disclaimer notice must appear in all copies of
29  * this code.
30  */
31 
32 #ifndef __TIMER_11XX_H_
33 #define __TIMER_11XX_H_
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
47 typedef struct {
54  __IO uint32_t MR[4];
58  __I uint32_t RESERVED0[12];
61 } LPC_TIMER_T;
62 
64 #define TIMER_IR_CLR(n) _BIT(n)
65 
67 #define TIMER_MATCH_INT(n) (_BIT((n) & 0x0F))
68 
69 #define TIMER_CAP_INT(n) (_BIT((((n) & 0x0F) + 4)))
70 
72 #define TIMER_ENABLE ((uint32_t) (1 << 0))
73 
74 #define TIMER_RESET ((uint32_t) (1 << 1))
75 
77 #define TIMER_INT_ON_MATCH(n) (_BIT(((n) * 3)))
78 
79 #define TIMER_RESET_ON_MATCH(n) (_BIT((((n) * 3) + 1)))
80 
81 #define TIMER_STOP_ON_MATCH(n) (_BIT((((n) * 3) + 2)))
82 
84 #define TIMER_CAP_RISING(n) (_BIT(((n) * 3)))
85 
86 #define TIMER_CAP_FALLING(n) (_BIT((((n) * 3) + 1)))
87 
88 #define TIMER_INT_ON_CAP(n) (_BIT((((n) * 3) + 2)))
89 
95 void Chip_TIMER_Init(LPC_TIMER_T *pTMR);
96 
102 void Chip_TIMER_DeInit(LPC_TIMER_T *pTMR);
103 
113 {
114  return (bool) ((pTMR->IR & TIMER_MATCH_INT(matchnum)) != 0);
115 }
116 
126 {
127  return (bool) ((pTMR->IR & TIMER_CAP_INT(capnum)) != 0);
128 }
129 
138 {
139  pTMR->IR = TIMER_IR_CLR(matchnum);
140 }
141 
150 {
151  pTMR->IR = (0x10 << capnum);
152 }
153 
161 {
162  pTMR->TCR |= TIMER_ENABLE;
163 }
164 
172 {
173  pTMR->TCR &= ~TIMER_ENABLE;
174 }
175 
183 {
184  return pTMR->TC;
185 }
186 
194 {
195  return pTMR->PC;
196 }
197 
206 {
207  pTMR->PR = prescale;
208 }
209 
219 {
220  pTMR->MR[matchnum] = matchval;
221 }
222 
231 {
232  return pTMR->CR[capnum];
233 }
234 
240 void Chip_TIMER_Reset(LPC_TIMER_T *pTMR);
241 
250 {
251  pTMR->MCR |= TIMER_INT_ON_MATCH(matchnum);
252 }
253 
261 {
262  pTMR->MCR &= ~TIMER_INT_ON_MATCH(matchnum);
263 }
264 
272 {
273  pTMR->MCR |= TIMER_RESET_ON_MATCH(matchnum);
274 }
275 
283 {
284  pTMR->MCR &= ~TIMER_RESET_ON_MATCH(matchnum);
285 }
286 
295 {
296  pTMR->MCR |= TIMER_STOP_ON_MATCH(matchnum);
297 }
298 
307 {
308  pTMR->MCR &= ~TIMER_STOP_ON_MATCH(matchnum);
309 }
310 
320 {
321  pTMR->CCR |= TIMER_CAP_RISING(capnum);
322 }
323 
333 {
334  pTMR->CCR &= ~TIMER_CAP_RISING(capnum);
335 }
336 
346 {
347  pTMR->CCR |= TIMER_CAP_FALLING(capnum);
348 }
349 
359 {
360  pTMR->CCR &= ~TIMER_CAP_FALLING(capnum);
361 }
362 
372 {
373  pTMR->CCR |= TIMER_INT_ON_CAP(capnum);
374 }
375 
383 {
384  pTMR->CCR &= ~TIMER_INT_ON_CAP(capnum);
385 }
386 
396 
409 void Chip_TIMER_ExtMatchControlSet(LPC_TIMER_T *pTMR, int8_t initial_state,
410  TIMER_PIN_MATCH_STATE_T matchState, int8_t matchnum);
411 
421 
432  TIMER_CAP_SRC_STATE_T capSrc,
433  int8_t capnum)
434 {
435  pTMR->CTCR = (uint32_t) capSrc | ((uint32_t) capnum) << 2;
436 }
437 
442 #ifdef __cplusplus
443 }
444 #endif
445 
446 #endif /* __TIMER_11XX_H_ */
LPC_TIMER_T::PWMC
__IO uint32_t PWMC
Definition: timer_11xx.h:60
LPC_TIMER_T::CR
__IO uint32_t CR[4]
Definition: timer_11xx.h:56
IP_TIMER_CAP_SRC_STATE
IP_TIMER_CAP_SRC_STATE
Standard timer clock and edge for count source.
Definition: timer_11xx.h:415
TIMER_EXTMATCH_CLEAR
@ TIMER_EXTMATCH_CLEAR
Definition: timer_11xx.h:392
TIMER_EXTMATCH_DO_NOTHING
@ TIMER_EXTMATCH_DO_NOTHING
Definition: timer_11xx.h:391
Chip_TIMER_StopOnMatchDisable
STATIC INLINE void Chip_TIMER_StopOnMatchDisable(LPC_TIMER_T *pTMR, int8_t matchnum)
Disable stop on match for a match timer. Disables a match timer to stop the terminal count when a mat...
Definition: timer_11xx.h:306
Chip_TIMER_StopOnMatchEnable
STATIC INLINE void Chip_TIMER_StopOnMatchEnable(LPC_TIMER_T *pTMR, int8_t matchnum)
Enable a match timer to stop the terminal count when a match count equals the terminal count.
Definition: timer_11xx.h:294
TIMER_CAPSRC_BOTH_CAPN
@ TIMER_CAPSRC_BOTH_CAPN
Definition: timer_11xx.h:419
uavcan::uint32_t
std::uint32_t uint32_t
Definition: std.hpp:26
TIMER_CAPSRC_RISING_CAPN
@ TIMER_CAPSRC_RISING_CAPN
Definition: timer_11xx.h:417
TIMER_INT_ON_MATCH
#define TIMER_INT_ON_MATCH(n)
Definition: timer_11xx.h:77
LPC_TIMER_T::MR
__IO uint32_t MR[4]
Definition: timer_11xx.h:54
TIMER_CAP_FALLING
#define TIMER_CAP_FALLING(n)
Definition: timer_11xx.h:86
Chip_TIMER_Init
void Chip_TIMER_Init(LPC_TIMER_T *pTMR)
Initialize a timer.
TIMER_CAP_RISING
#define TIMER_CAP_RISING(n)
Definition: timer_11xx.h:84
__IO
#define __IO
Definition: core_cm0.h:154
Chip_TIMER_CaptureRisingEdgeDisable
STATIC INLINE void Chip_TIMER_CaptureRisingEdgeDisable(LPC_TIMER_T *pTMR, int8_t capnum)
Disables capture on on rising edge of selected CAP signal. For the selected capture register,...
Definition: timer_11xx.h:332
IP_TIMER_PIN_MATCH_STATE
IP_TIMER_PIN_MATCH_STATE
Standard timer initial match pin state and change state.
Definition: timer_11xx.h:390
TIMER_RESET_ON_MATCH
#define TIMER_RESET_ON_MATCH(n)
Definition: timer_11xx.h:79
Chip_TIMER_PrescaleSet
STATIC INLINE void Chip_TIMER_PrescaleSet(LPC_TIMER_T *pTMR, uint32_t prescale)
Sets the prescaler value.
Definition: timer_11xx.h:205
TIMER_PIN_MATCH_STATE_T
enum IP_TIMER_PIN_MATCH_STATE TIMER_PIN_MATCH_STATE_T
Standard timer initial match pin state and change state.
Chip_TIMER_ReadCount
STATIC INLINE uint32_t Chip_TIMER_ReadCount(LPC_TIMER_T *pTMR)
Returns the current timer count.
Definition: timer_11xx.h:182
Chip_TIMER_CaptureEnableInt
STATIC INLINE void Chip_TIMER_CaptureEnableInt(LPC_TIMER_T *pTMR, int8_t capnum)
Enables interrupt on capture of selected CAP signal. For the selected capture register,...
Definition: timer_11xx.h:371
TIMER_MATCH_INT
#define TIMER_MATCH_INT(n)
Definition: timer_11xx.h:67
__I
#define __I
Definition: core_cm0.h:151
LPC_TIMER_T::CTCR
__IO uint32_t CTCR
Definition: timer_11xx.h:59
LPC_TIMER_T::IR
__IO uint32_t IR
Definition: timer_11xx.h:48
Chip_TIMER_MatchPending
STATIC INLINE bool Chip_TIMER_MatchPending(LPC_TIMER_T *pTMR, int8_t matchnum)
Determine if a match interrupt is pending.
Definition: timer_11xx.h:112
LPC_TIMER_T::PC
__IO uint32_t PC
Definition: timer_11xx.h:52
Chip_TIMER_ClearCapture
STATIC INLINE void Chip_TIMER_ClearCapture(LPC_TIMER_T *pTMR, int8_t capnum)
Clears a (pending) capture interrupt.
Definition: timer_11xx.h:149
INLINE
#define INLINE
Definition: lpc_types.h:205
Chip_TIMER_ClearMatch
STATIC INLINE void Chip_TIMER_ClearMatch(LPC_TIMER_T *pTMR, int8_t matchnum)
Clears a (pending) match interrupt.
Definition: timer_11xx.h:137
Chip_TIMER_TIMER_SetCountClockSrc
STATIC INLINE void Chip_TIMER_TIMER_SetCountClockSrc(LPC_TIMER_T *pTMR, TIMER_CAP_SRC_STATE_T capSrc, int8_t capnum)
Sets timer count source and edge with the selected passed from CapSrc. If CapSrc selected a CAPn pin,...
Definition: timer_11xx.h:431
Chip_TIMER_DeInit
void Chip_TIMER_DeInit(LPC_TIMER_T *pTMR)
Shutdown a timer.
TIMER_INT_ON_CAP
#define TIMER_INT_ON_CAP(n)
Definition: timer_11xx.h:88
LPC_TIMER_T::CCR
__IO uint32_t CCR
Definition: timer_11xx.h:55
LPC_TIMER_T
32-bit Standard timer register block structure
Definition: timer_11xx.h:47
Chip_TIMER_ResetOnMatchEnable
STATIC INLINE void Chip_TIMER_ResetOnMatchEnable(LPC_TIMER_T *pTMR, int8_t matchnum)
For the specific match counter, enables reset of the terminal count register when a match occurs.
Definition: timer_11xx.h:271
TIMER_CAPSRC_FALLING_CAPN
@ TIMER_CAPSRC_FALLING_CAPN
Definition: timer_11xx.h:418
Chip_TIMER_ResetOnMatchDisable
STATIC INLINE void Chip_TIMER_ResetOnMatchDisable(LPC_TIMER_T *pTMR, int8_t matchnum)
For the specific match counter, disables reset of the terminal count register when a match occurs.
Definition: timer_11xx.h:282
Chip_TIMER_Enable
STATIC INLINE void Chip_TIMER_Enable(LPC_TIMER_T *pTMR)
Enables the timer (starts count)
Definition: timer_11xx.h:160
TIMER_CAP_SRC_STATE_T
enum IP_TIMER_CAP_SRC_STATE TIMER_CAP_SRC_STATE_T
Standard timer clock and edge for count source.
LPC_TIMER_T::EMR
__IO uint32_t EMR
Definition: timer_11xx.h:57
TIMER_CAP_INT
#define TIMER_CAP_INT(n)
Definition: timer_11xx.h:69
TIMER_STOP_ON_MATCH
#define TIMER_STOP_ON_MATCH(n)
Definition: timer_11xx.h:81
LPC_TIMER_T::TC
__IO uint32_t TC
Definition: timer_11xx.h:50
LPC_TIMER_T::MCR
__IO uint32_t MCR
Definition: timer_11xx.h:53
Chip_TIMER_SetMatch
STATIC INLINE void Chip_TIMER_SetMatch(LPC_TIMER_T *pTMR, int8_t matchnum, uint32_t matchval)
Sets a timer match value.
Definition: timer_11xx.h:218
uavcan::int8_t
std::int8_t int8_t
Definition: std.hpp:29
Chip_TIMER_CapturePending
STATIC INLINE bool Chip_TIMER_CapturePending(LPC_TIMER_T *pTMR, int8_t capnum)
Determine if a capture interrupt is pending.
Definition: timer_11xx.h:125
Chip_TIMER_ReadPrescale
STATIC INLINE uint32_t Chip_TIMER_ReadPrescale(LPC_TIMER_T *pTMR)
Returns the current prescale count.
Definition: timer_11xx.h:193
Chip_TIMER_Disable
STATIC INLINE void Chip_TIMER_Disable(LPC_TIMER_T *pTMR)
Disables the timer (stops count)
Definition: timer_11xx.h:171
Chip_TIMER_ExtMatchControlSet
void Chip_TIMER_ExtMatchControlSet(LPC_TIMER_T *pTMR, int8_t initial_state, TIMER_PIN_MATCH_STATE_T matchState, int8_t matchnum)
Sets external match control (MATn.matchnum) pin control. For the pin selected with matchnum,...
CR
#define CR
Definition: sja1000_defs.h:42
LPC_TIMER_T::PR
__IO uint32_t PR
Definition: timer_11xx.h:51
TIMER_EXTMATCH_SET
@ TIMER_EXTMATCH_SET
Definition: timer_11xx.h:393
Chip_TIMER_Reset
void Chip_TIMER_Reset(LPC_TIMER_T *pTMR)
Resets the timer terminal and prescale counts to 0.
Chip_TIMER_CaptureFallingEdgeEnable
STATIC INLINE void Chip_TIMER_CaptureFallingEdgeEnable(LPC_TIMER_T *pTMR, int8_t capnum)
Enables capture on on falling edge of selected CAP signal. For the selected capture register,...
Definition: timer_11xx.h:345
TIMER_ENABLE
#define TIMER_ENABLE
Definition: timer_11xx.h:72
Chip_TIMER_CaptureFallingEdgeDisable
STATIC INLINE void Chip_TIMER_CaptureFallingEdgeDisable(LPC_TIMER_T *pTMR, int8_t capnum)
Disables capture on on falling edge of selected CAP signal. For the selected capture register,...
Definition: timer_11xx.h:358
Chip_TIMER_CaptureRisingEdgeEnable
STATIC INLINE void Chip_TIMER_CaptureRisingEdgeEnable(LPC_TIMER_T *pTMR, int8_t capnum)
Enables capture on on rising edge of selected CAP signal for the selected capture register,...
Definition: timer_11xx.h:319
Chip_TIMER_MatchEnableInt
STATIC INLINE void Chip_TIMER_MatchEnableInt(LPC_TIMER_T *pTMR, int8_t matchnum)
Enables a match interrupt that fires when the terminal count matches the match counter value.
Definition: timer_11xx.h:249
Chip_TIMER_ReadCapture
STATIC INLINE uint32_t Chip_TIMER_ReadCapture(LPC_TIMER_T *pTMR, int8_t capnum)
Reads a capture register.
Definition: timer_11xx.h:230
TIMER_CAPSRC_RISING_PCLK
@ TIMER_CAPSRC_RISING_PCLK
Definition: timer_11xx.h:416
TIMER_EXTMATCH_TOGGLE
@ TIMER_EXTMATCH_TOGGLE
Definition: timer_11xx.h:394
Chip_TIMER_CaptureDisableInt
STATIC INLINE void Chip_TIMER_CaptureDisableInt(LPC_TIMER_T *pTMR, int8_t capnum)
Disables interrupt on capture of selected CAP signal.
Definition: timer_11xx.h:382
LPC_TIMER_T::TCR
__IO uint32_t TCR
Definition: timer_11xx.h:49
Chip_TIMER_MatchDisableInt
STATIC INLINE void Chip_TIMER_MatchDisableInt(LPC_TIMER_T *pTMR, int8_t matchnum)
Disables a match interrupt for a match counter.
Definition: timer_11xx.h:260
TIMER_IR_CLR
#define TIMER_IR_CLR(n)
Definition: timer_11xx.h:64
STATIC
#define STATIC
Definition: lpc_types.h:140


uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:03