rfLPC
A low level library for using NXP's LPC17xx SoC. Config is given for MBED prototyping board

All four timers provides the same functionality. More...

Enumerations

enum  rflpc_timer_t {
  RFLPC_TIMER0,
  RFLPC_TIMER1,
  RFLPC_TIMER2,
  RFLPC_TIMER3,
  RFLPC_TIMER_PWM
}
 Value to use for the timer value in functions. More...
 
enum  rflpc_timer_match_t {
  RFLPC_TIMER_MATCH0,
  RFLPC_TIMER_MATCH1,
  RFLPC_TIMER_MATCH2,
  RFLPC_TIMER_MATCH3
}
 Match registers for interrupt generation. More...
 
enum  {
  RFLPC_TIMER_IRQ_ON_MATCH = 1,
  RFLPC_TIMER_RESET_ON_MATCH = 2,
  RFLPC_TIMER_STOP_ON_MATCH = 4
}
 Options for interrupt generation. More...
 

Functions

void rflpc_timer_enable (rflpc_timer_t timer)
 Power and clock the given timer. More...
 
void rflpc_timer_disable (rflpc_timer_t timer)
 disable the given timer More...
 
int rflpc_timer_running (rflpc_timer_t timer)
 Query the running state of the timer. More...
 
void rflpc_timer_set_clock (rflpc_timer_t timer, rflpc_clock_divider_t divider)
 Sets the cpu clock divider for a given timer. More...
 
void rflpc_timer_set_callback (rflpc_timer_t timer, rflpc_irq_handler_t callback)
 Sets the timer interrupt callback. More...
 
void rflpc_timer_start (rflpc_timer_t timer)
 starts the given timer. More...
 
void rflpc_timer_stop (rflpc_timer_t timer)
 Stops the timer. More...
 
void rflpc_timer_reset (rflpc_timer_t timer)
 Resets the timer. More...
 
uint32_t rflpc_timer_get_counter (rflpc_timer_t timer)
 Returns the timer counter value. More...
 
uint32_t rflpc_timer_get_pre_scale_counter (rflpc_timer_t timer)
 Returns the prescale counter value. More...
 
uint32_t rflpc_timer_get_pre_scale_register (rflpc_timer_t timer)
 Returns the value of the prescale register. More...
 
void rflpc_timer_set_counter (rflpc_timer_t timer, uint32_t value)
 Sets the timer counter value. More...
 
void rflpc_timer_set_pre_scale_counter (rflpc_timer_t timer, uint32_t value)
 Sets the prescale counter value. More...
 
void rflpc_timer_set_pre_scale_register (rflpc_timer_t timer, uint32_t value)
 Sets the value of the prescale register. More...
 
void rflpc_timer_set_match_value (rflpc_timer_t timer, rflpc_timer_match_t match_register, uint32_t match_value)
 Set the match register value for a given timer. More...
 
void rflpc_timer_set_irq_on_match (rflpc_timer_t timer, rflpc_timer_match_t match_register, uint32_t options)
 Enable IRQ generation when the timer counter reaches the value of a match register. More...
 
void rflpc_timer_reset_irq (rflpc_timer_t timer, rflpc_timer_match_t match_register)
 Reset the irq for a given match register. More...
 
int rflpc_timer_test_irq (rflpc_timer_t timer, rflpc_timer_match_t match_register)
 Check if an interrupt has been generated for a given match register. More...
 

Detailed Description

All four timers provides the same functionality.

The prescale counter is incremented at each timer clock tick. When the prescale counter reaches the prescale register value, the counter is incremented. The value of the counter can then be used as time value or match against four match registers to trigger an interrupt.

Enumeration Type Documentation

anonymous enum

Options for interrupt generation.

Enumerator
RFLPC_TIMER_IRQ_ON_MATCH 

Trigger an interrupt when counter matches the match register.

RFLPC_TIMER_RESET_ON_MATCH 

Reset the timer when counter matches the match register.

RFLPC_TIMER_STOP_ON_MATCH 

Stop the timer when the counter matches the match register.

Definition at line 69 of file timer.h.

Match registers for interrupt generation.

Enumerator
RFLPC_TIMER_MATCH0 

Match register 0.

RFLPC_TIMER_MATCH1 

Match register 1.

RFLPC_TIMER_MATCH2 

Match register 2.

RFLPC_TIMER_MATCH3 

Match register 3.

Definition at line 59 of file timer.h.

Value to use for the timer value in functions.

Enumerator
RFLPC_TIMER0 

Timer 0.

RFLPC_TIMER1 

Timer 1.

RFLPC_TIMER2 

Timer 2.

RFLPC_TIMER3 

Timer 3.

RFLPC_TIMER_PWM 

PWM Timer.

Definition at line 48 of file timer.h.

Function Documentation

void rflpc_timer_disable ( rflpc_timer_t  timer)

disable the given timer

Parameters
timer
void rflpc_timer_enable ( rflpc_timer_t  timer)

Power and clock the given timer.

Parameters
timer
uint32_t rflpc_timer_get_counter ( rflpc_timer_t  timer)

Returns the timer counter value.

This value is incremented each time the prescale counter matches the prescale register.

Parameters
timer
Returns
uint32_t rflpc_timer_get_pre_scale_counter ( rflpc_timer_t  timer)

Returns the prescale counter value.

This value is incremented at each clock cycle.

Parameters
timer
Returns
uint32_t rflpc_timer_get_pre_scale_register ( rflpc_timer_t  timer)

Returns the value of the prescale register.

This register contains the number of clock cycle needed to increment the timer counter. That is, at each clock cycle, the prescale counter is incrementer and when it reaches the prescale register, the timer counter is incremented.

Parameters
timer
Returns
void rflpc_timer_reset ( rflpc_timer_t  timer)

Resets the timer.

Parameters
timer
void rflpc_timer_reset_irq ( rflpc_timer_t  timer,
rflpc_timer_match_t  match_register 
)

Reset the irq for a given match register.

Parameters
timer
match_register
int rflpc_timer_running ( rflpc_timer_t  timer)

Query the running state of the timer.

Parameters
timer
Returns
1 if running, 0 otherwise
void rflpc_timer_set_callback ( rflpc_timer_t  timer,
rflpc_irq_handler_t  callback 
)

Sets the timer interrupt callback.

Also enables timer interrupt to be received.

Parameters
timer
callback
void rflpc_timer_set_clock ( rflpc_timer_t  timer,
rflpc_clock_divider_t  divider 
)

Sets the cpu clock divider for a given timer.

Parameters
timer
divider
See also
rflpc_clock_divider_t
void rflpc_timer_set_counter ( rflpc_timer_t  timer,
uint32_t  value 
)

Sets the timer counter value.

This value is incremented each time the prescale counter matches the prescale register.

Parameters
timer
value
void rflpc_timer_set_irq_on_match ( rflpc_timer_t  timer,
rflpc_timer_match_t  match_register,
uint32_t  options 
)

Enable IRQ generation when the timer counter reaches the value of a match register.

Parameters
timer
match_register
optionsa bitwise ORed value of RFLPC_TIMER_IRQ_ON_MATCH, RFLPC_TIMER_RESET_ON_MATCH and RFLPC_TIMER_STOP_ON_MATCH
Returns
void rflpc_timer_set_match_value ( rflpc_timer_t  timer,
rflpc_timer_match_t  match_register,
uint32_t  match_value 
)

Set the match register value for a given timer.

Interrupt can be generated when timer counter reaches a match register's value

Parameters
timer
match_register
match_value
Returns
void rflpc_timer_set_pre_scale_counter ( rflpc_timer_t  timer,
uint32_t  value 
)

Sets the prescale counter value.

This value is incremented at each clock cycle.

Parameters
timer
value
void rflpc_timer_set_pre_scale_register ( rflpc_timer_t  timer,
uint32_t  value 
)

Sets the value of the prescale register.

This register contains the number of clock cycle needed to increment the timer counter. That is, at each clock cycle, the prescale counter is incrementer and when it reaches the prescale register, the timer counter is incremented.

Parameters
timer
value
void rflpc_timer_start ( rflpc_timer_t  timer)

starts the given timer.

This does not modify timer register value. It just starts to count

Parameters
timer
void rflpc_timer_stop ( rflpc_timer_t  timer)

Stops the timer.

Does not modify timer registers value

Parameters
timer
int rflpc_timer_test_irq ( rflpc_timer_t  timer,
rflpc_timer_match_t  match_register 
)

Check if an interrupt has been generated for a given match register.

Parameters
timer
match_register
Returns
true if an interrupt is pending for the given match register