LPCOpen Platform for LPC18XX/43XX microcontrollers: CHIP: LPC18xx/43xx 16/32-bit Timer driver

| LPCOpen Platform for LPC18XX/43XX microcontrollers 18XX43XX LPCOpen Platform for the NXP LPC18XX/43XX family of Microcontrollers

- Main Page
- Modules
- Data Structures
- Files

Data Structures | Macros | Enumerations | Functions
CHIP: LPC18xx/43xx 16/32-bit Timer driver
LPC18xx/43xx chip specific drivers

## Detailed Description

## Data Structures
struct | LPC_TIMER_T
| 32-bit Standard timer register block structure More...

## Macros
#define | TIMER_IR_CLR(n) _BIT(n)
#define | TIMER_MATCH_INT(n) (_BIT((n) & 0x0F))
#define | TIMER_CAP_INT(n) (_BIT((((n) & 0x0F) + 4)))
#define | TIMER_ENABLE ((uint32_t) (1 << 0))
#define | TIMER_RESET ((uint32_t) (1 << 1))
#define | TIMER_INT_ON_MATCH(n) (_BIT(((n) * 3)))
#define | TIMER_RESET_ON_MATCH(n) (_BIT((((n) * 3) + 1)))
#define | TIMER_STOP_ON_MATCH(n) (_BIT((((n) * 3) + 2)))
#define | TIMER_CAP_RISING(n) (_BIT(((n) * 3)))
#define | TIMER_CAP_FALLING(n) (_BIT((((n) * 3) + 1)))
#define | TIMER_INT_ON_CAP(n) (_BIT((((n) * 3) + 2)))

## Enumerations
enum | TIMER_PIN_MATCH_STATE_T { TIMER_EXTMATCH_DO_NOTHING = 0, TIMER_EXTMATCH_CLEAR = 1, TIMER_EXTMATCH_SET = 2, TIMER_EXTMATCH_TOGGLE = 3 }
| Standard timer initial match pin state and change state. More...
enum | TIMER_CAP_SRC_STATE_T { TIMER_CAPSRC_RISING_PCLK = 0, TIMER_CAPSRC_RISING_CAPN = 1, TIMER_CAPSRC_FALLING_CAPN = 2, TIMER_CAPSRC_BOTH_CAPN = 3 }
| Standard timer clock and edge for count source. More...

## Functions
void | Chip_TIMER_Init (LPC_TIMER_T *pTMR)
| Initialize a timer. More...
void | Chip_TIMER_DeInit (LPC_TIMER_T *pTMR)
| Shutdown a timer. More...
STATIC INLINE bool | Chip_TIMER_MatchPending (LPC_TIMER_T *pTMR, int8_t matchnum)
| Determine if a match interrupt is pending. More...
STATIC INLINE bool | Chip_TIMER_CapturePending (LPC_TIMER_T *pTMR, int8_t capnum)
| Determine if a capture interrupt is pending. More...
STATIC INLINE void | Chip_TIMER_ClearMatch (LPC_TIMER_T *pTMR, int8_t matchnum)
| Clears a (pending) match interrupt. More...
STATIC INLINE void | Chip_TIMER_ClearCapture (LPC_TIMER_T *pTMR, int8_t capnum)
| Clears a (pending) capture interrupt. More...
STATIC INLINE void | Chip_TIMER_Enable (LPC_TIMER_T *pTMR)
| Enables the timer (starts count) More...
STATIC INLINE void | Chip_TIMER_Disable (LPC_TIMER_T *pTMR)
| Disables the timer (stops count) More...
STATIC INLINE uint32_t | Chip_TIMER_ReadCount (LPC_TIMER_T *pTMR)
| Returns the current timer count. More...
STATIC INLINE uint32_t | Chip_TIMER_ReadPrescale (LPC_TIMER_T *pTMR)
| Returns the current prescale count. More...
STATIC INLINE void | Chip_TIMER_PrescaleSet (LPC_TIMER_T *pTMR, uint32_t prescale)
| Sets the prescaler value. More...
STATIC INLINE void | Chip_TIMER_SetMatch (LPC_TIMER_T *pTMR, int8_t matchnum, uint32_t matchval)
| Sets a timer match value. More...
STATIC INLINE uint32_t | Chip_TIMER_ReadCapture (LPC_TIMER_T *pTMR, int8_t capnum)
| Reads a capture register. More...
void | Chip_TIMER_Reset (LPC_TIMER_T *pTMR)
| Resets the timer terminal and prescale counts to 0. More...
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. More...
STATIC INLINE void | Chip_TIMER_MatchDisableInt (LPC_TIMER_T *pTMR, int8_t matchnum)
| Disables a match interrupt for a match counter. More...
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. More...
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. More...
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. More...
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 match count equals the terminal count. More...
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, enables the selected CAPn.capnum signal to load the capture register with the terminal coount on a rising edge. More...
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, disables the selected CAPn.capnum signal to load the capture register with the terminal coount on a rising edge. More...
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, enables the selected CAPn.capnum signal to load the capture register with the terminal coount on a falling edge. More...
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, disables the selected CAPn.capnum signal to load the capture register with the terminal coount on a falling edge. More...
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, an interrupt will be generated when the enabled rising or falling edge on CAPn.capnum is detected. More...
STATIC INLINE void | Chip_TIMER_CaptureDisableInt (LPC_TIMER_T *pTMR, int8_t capnum)
| Disables interrupt on capture of selected CAP signal. More...
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, sets the function of the pin that occurs on a terminal count match for the match count. More...
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, select the specific CAPn pin with the capnum value. More...

## Macro Definition Documentation

#define TIMER_CAP_FALLING | ( |  | n | ) | (_BIT((((n) * 3) + 1)))

Bit location for CAP.n on CRx falling edge, n = 0 to 3

Definition at line 85 of file timer_18xx_43xx.h.

#define TIMER_CAP_INT | ( |  | n | ) | (_BIT((((n) & 0x0F) + 4)))

Macro for getting a capture event interrupt bit

Definition at line 68 of file timer_18xx_43xx.h.

#define TIMER_CAP_RISING | ( |  | n | ) | (_BIT(((n) * 3)))

Bit location for CAP.n on CRx rising edge, n = 0 to 3

Definition at line 83 of file timer_18xx_43xx.h.

#define TIMER_ENABLE ((uint32_t) (1 << 0))

Timer/counter enable bit

Definition at line 71 of file timer_18xx_43xx.h.

#define TIMER_INT_ON_CAP | ( |  | n | ) | (_BIT((((n) * 3) + 2)))

Bit location for CAP.n on CRx interrupt enable, n = 0 to 3

Definition at line 87 of file timer_18xx_43xx.h.

#define TIMER_INT_ON_MATCH | ( |  | n | ) | (_BIT(((n) * 3)))

Bit location for interrupt on MRx match, n = 0 to 3

Definition at line 76 of file timer_18xx_43xx.h.

#define TIMER_IR_CLR | ( |  | n | ) | _BIT(n)

Macro to clear interrupt pending

Definition at line 63 of file timer_18xx_43xx.h.

#define TIMER_MATCH_INT | ( |  | n | ) | (_BIT((n) & 0x0F))

Macro for getting a timer match interrupt bit

Definition at line 66 of file timer_18xx_43xx.h.

#define TIMER_RESET ((uint32_t) (1 << 1))

Timer/counter reset bit

Definition at line 73 of file timer_18xx_43xx.h.

#define TIMER_RESET_ON_MATCH | ( |  | n | ) | (_BIT((((n) * 3) + 1)))

Bit location for reset on MRx match, n = 0 to 3

Definition at line 78 of file timer_18xx_43xx.h.

#define TIMER_STOP_ON_MATCH | ( |  | n | ) | (_BIT((((n) * 3) + 2)))

Bit location for stop on MRx match, n = 0 to 3

Definition at line 80 of file timer_18xx_43xx.h.

## Enumeration Type Documentation

enum TIMER_CAP_SRC_STATE_T

Standard timer clock and edge for count source.

Enumerator
TIMER_CAPSRC_RISING_PCLK | Timer ticks on PCLK rising edge
TIMER_CAPSRC_RISING_CAPN | Timer ticks on CAPn.x rising edge
TIMER_CAPSRC_FALLING_CAPN | Timer ticks on CAPn.x falling edge
TIMER_CAPSRC_BOTH_CAPN | Timer ticks on CAPn.x both edges

Definition at line 414 of file timer_18xx_43xx.h.

enum TIMER_PIN_MATCH_STATE_T

Standard timer initial match pin state and change state.

Enumerator
TIMER_EXTMATCH_DO_NOTHING | Timer match state does nothing on match pin
TIMER_EXTMATCH_CLEAR | Timer match state sets match pin low
TIMER_EXTMATCH_SET | Timer match state sets match pin high
TIMER_EXTMATCH_TOGGLE | Timer match state toggles match pin

Definition at line 389 of file timer_18xx_43xx.h.

## Function Documentation

STATIC INLINE void Chip_TIMER_CaptureDisableInt | ( | LPC_TIMER_T * | pTMR,
|  | int8_t | capnum
| ) |  |

Disables interrupt on capture of selected CAP signal.

Parameters

  pTMR | : Pointer to timer IP register address
  capnum | : Capture signal/register to use

Returns
  Nothing

Definition at line 381 of file timer_18xx_43xx.h.

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, an interrupt will be generated when the enabled rising or falling edge on CAPn.capnum is detected.

Parameters

  pTMR | : Pointer to timer IP register address
  capnum | : Capture signal/register to use

Returns
  Nothing

Definition at line 370 of file timer_18xx_43xx.h.

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, disables the selected CAPn.capnum signal to load the capture register with the terminal coount on a falling edge.

Parameters

  pTMR | : Pointer to timer IP register address
  capnum | : Capture signal/register to use

Returns
  Nothing

Definition at line 357 of file timer_18xx_43xx.h.

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, enables the selected CAPn.capnum signal to load the capture register with the terminal coount on a falling edge.

Parameters

  pTMR | : Pointer to timer IP register address
  capnum | : Capture signal/register to use

Returns
  Nothing

Definition at line 344 of file timer_18xx_43xx.h.

STATIC INLINE bool Chip_TIMER_CapturePending | ( | LPC_TIMER_T * | pTMR,
|  | int8_t | capnum
| ) |  |

Determine if a capture interrupt is pending.

Parameters

  pTMR | : Pointer to timer IP register address
  capnum | : Capture interrupt number to check

Returns
  false if the interrupt is not pending, otherwise true

Note
  Determine if the capture interrupt for the passed capture pin is pending.

Definition at line 124 of file timer_18xx_43xx.h.

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, disables the selected CAPn.capnum signal to load the capture register with the terminal coount on a rising edge.

Parameters

  pTMR | : Pointer to timer IP register address
  capnum | : Capture signal/register to use

Returns
  Nothing

Definition at line 331 of file timer_18xx_43xx.h.

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, enables the selected CAPn.capnum signal to load the capture register with the terminal coount on a rising edge.

Parameters

  pTMR | : Pointer to timer IP register address
  capnum | : Capture signal/register to use

Returns
  Nothing

Definition at line 318 of file timer_18xx_43xx.h.

STATIC INLINE void Chip_TIMER_ClearCapture | ( | LPC_TIMER_T * | pTMR,
|  | int8_t | capnum
| ) |  |

Clears a (pending) capture interrupt.

Parameters

  pTMR | : Pointer to timer IP register address
  capnum | : Capture interrupt number to clear

Returns
  Nothing

Note
  Clears a pending timer capture interrupt.

Definition at line 148 of file timer_18xx_43xx.h.

STATIC INLINE void Chip_TIMER_ClearMatch | ( | LPC_TIMER_T * | pTMR,
|  | int8_t | matchnum
| ) |  |

Clears a (pending) match interrupt.

Parameters

  pTMR | : Pointer to timer IP register address
  matchnum | : Match interrupt number to clear

Returns
  Nothing

Note
  Clears a pending timer match interrupt.

Definition at line 136 of file timer_18xx_43xx.h.

void Chip_TIMER_DeInit | ( | LPC_TIMER_T * | pTMR | ) |

Shutdown a timer.

Parameters

  pTMR | : Pointer to timer IP register address

Returns
  Nothing

Definition at line 78 of file timer_18xx_43xx.c.

STATIC INLINE void Chip_TIMER_Disable | ( | LPC_TIMER_T * | pTMR | ) |

Disables the timer (stops count)

Parameters

  pTMR | : Pointer to timer IP register address

Returns
  Nothing

Note
  Disables the timer to stop counting.

Definition at line 170 of file timer_18xx_43xx.h.

STATIC INLINE void Chip_TIMER_Enable | ( | LPC_TIMER_T * | pTMR | ) |

Enables the timer (starts count)

Parameters

  pTMR | : Pointer to timer IP register address

Returns
  Nothing

Note
  Enables the timer to start counting.

Definition at line 159 of file timer_18xx_43xx.h.

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, sets the function of the pin that occurs on a terminal count match for the match count.

Parameters

  pTMR | : Pointer to timer IP register address
  initial_state | : Initial state of the pin, high(1) or low(0)
  matchState | : Selects the match state for the pin
  matchnum | : MATn.matchnum signal to use

Returns
  Nothing

Note
  For the pin selected with matchnum, sets the function of the pin that occurs on a terminal count match for the match count.

Definition at line 104 of file timer_18xx_43xx.c.

void Chip_TIMER_Init | ( | LPC_TIMER_T * | pTMR | ) |

Initialize a timer.

Parameters

  pTMR | : Pointer to timer IP register address

Returns
  Nothing

Definition at line 72 of file timer_18xx_43xx.c.

STATIC INLINE void Chip_TIMER_MatchDisableInt | ( | LPC_TIMER_T * | pTMR,
|  | int8_t | matchnum
| ) |  |

Disables a match interrupt for a match counter.

Parameters

  pTMR | : Pointer to timer IP register address
  matchnum | : Match timer, 0 to 3

Returns
  Nothing

Definition at line 259 of file timer_18xx_43xx.h.

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.

Parameters

  pTMR | : Pointer to timer IP register address
  matchnum | : Match timer, 0 to 3

Returns
  Nothing

Definition at line 248 of file timer_18xx_43xx.h.

STATIC INLINE bool Chip_TIMER_MatchPending | ( | LPC_TIMER_T * | pTMR,
|  | int8_t | matchnum
| ) |  |

Determine if a match interrupt is pending.

Parameters

  pTMR | : Pointer to timer IP register address
  matchnum | : Match interrupt number to check

Returns
  false if the interrupt is not pending, otherwise true

Note
  Determine if the match interrupt for the passed timer and match counter is pending.

Definition at line 111 of file timer_18xx_43xx.h.

STATIC INLINE void Chip_TIMER_PrescaleSet | ( | LPC_TIMER_T * | pTMR,
|  | uint32_t | prescale
| ) |  |

Sets the prescaler value.

Parameters

  pTMR | : Pointer to timer IP register address
  prescale | : Prescale value to set the prescale register to

Returns
  Nothing

Note
  Sets the prescale count value.

Definition at line 204 of file timer_18xx_43xx.h.

STATIC INLINE uint32_t Chip_TIMER_ReadCapture | ( | LPC_TIMER_T * | pTMR,
|  | int8_t | capnum
| ) |  |

Reads a capture register.

Parameters

  pTMR | : Pointer to timer IP register address
  capnum | : Capture register to read

Returns
  The selected capture register value

Note
  Returns the selected capture register value.

Definition at line 229 of file timer_18xx_43xx.h.

STATIC INLINE uint32_t Chip_TIMER_ReadCount | ( | LPC_TIMER_T * | pTMR | ) |

Returns the current timer count.

Parameters

  pTMR | : Pointer to timer IP register address

Returns
  Current timer terminal count value

Note
  Returns the current timer terminal count.

Definition at line 181 of file timer_18xx_43xx.h.

STATIC INLINE uint32_t Chip_TIMER_ReadPrescale | ( | LPC_TIMER_T * | pTMR | ) |

Returns the current prescale count.

Parameters

  pTMR | : Pointer to timer IP register address

Returns
  Current timer prescale count value

Note
  Returns the current prescale count.

Definition at line 192 of file timer_18xx_43xx.h.

void Chip_TIMER_Reset | ( | LPC_TIMER_T * | pTMR | ) |

Resets the timer terminal and prescale counts to 0.

Parameters

  pTMR | : Pointer to timer IP register address

Returns
  Nothing

Definition at line 84 of file timer_18xx_43xx.c.

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.

Parameters

  pTMR | : Pointer to timer IP register address
  matchnum | : Match timer, 0 to 3

Returns
  Nothing

Definition at line 281 of file timer_18xx_43xx.h.

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.

Parameters

  pTMR | : Pointer to timer IP register address
  matchnum | : Match timer, 0 to 3

Returns
  Nothing

Definition at line 270 of file timer_18xx_43xx.h.

STATIC INLINE void Chip_TIMER_SetMatch | ( | LPC_TIMER_T * | pTMR,
|  | int8_t | matchnum,
|  | uint32_t | matchval
| ) |  |

Sets a timer match value.

Parameters

  pTMR | : Pointer to timer IP register address
  matchnum | : Match timer to set match count for
  matchval | : Match value for the selected match count

Returns
  Nothing

Note
  Sets one of the timer match values.

Definition at line 217 of file timer_18xx_43xx.h.

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 match count equals the terminal count.

Parameters

  pTMR | : Pointer to timer IP register address
  matchnum | : Match timer, 0 to 3

Returns
  Nothing

Definition at line 305 of file timer_18xx_43xx.h.

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.

Parameters

  pTMR | : Pointer to timer IP register address
  matchnum | : Match timer, 0 to 3

Returns
  Nothing

Definition at line 293 of file timer_18xx_43xx.h.

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, select the specific CAPn pin with the capnum value.

Parameters

  pTMR | : Pointer to timer IP register address
  capSrc | : timer clock source and edge
  capnum | : CAPn.capnum pin to use (if used)

Returns
  Nothing

Note
  If CapSrc selected a CAPn pin, select the specific CAPn pin with the capnum value.

Definition at line 430 of file timer_18xx_43xx.h.