TMR

The Timer module contains functions to access an MCU’s timer/counters as well as input capture and output compare units. More information about accessing peripheral IO is in the Device Interface section.

The following is an example of how to use the timer in an OS environment:


Details

define TMR_VERSION

define TMR_IOC_IDENT_CHAR

define I_TMR_GETVERSION

define I_TMR_GETINFO

define I_TMR_SETATTR

define I_TMR_SETACTION

define I_TMR_SETCHANNEL

This request writes the value of the current output compare channel. The ctl argument is a pointer to the mcu_channel_t structure. For example:

  • cpp mcu_channel_t chan_req; chan_req.channel = 1; //write to OC channel 1 chan_req.value = 1000000; //write 1 million to the OC channel if ( ioctl(tmr_fd, I_TMR_SETCHANNEL, &chan_req ){ //There was an error return -1; }

define I_TMR_GETCHANNEL

This request reads the value of the current output compare channel. The ctl argument is a pointer to a mcu_channel_t structure. tmr_ioctl() will return zero on success. For example:

mcu_channel_t chan_req;
int oc_value;
chan_req.channel = 1;
if ( ioctl(tmr_fd, I_TMR_GETOC, &chan_req ){
     //There was an error
     return -1;
}
oc_value = chan_req.value;

define I_TMR_SET

This request writes the value of the timer. For example:

u32 value = 1000000;
ioctl(tmr_fd, I_TMR_SET, value);

define I_TMR_GET

This request reads the value of the timer. For example:

u32 value;
value = ioctl(tmr_fd, I_TMR_GET);

define I_TMR_ENABLE

define I_TMR_DISABLE

define I_TMR_TOTAL

enum @29
  • TMR_FLAG_SET_TIMER Configure the timer attributes
  • TMR_FLAG_IS_SOURCE_CPU Use the CPU as the source for the clock (timer mode)
  • TMR_FLAG_IS_SOURCE_IC0 Use input capture channel 0 for the clock source (counter mode)
  • TMR_FLAG_IS_SOURCE_IC1 Use input capture channel 1 for the clock source (counter mode)
  • TMR_FLAG_IS_SOURCE_IC2 Use input capture channel 2 for the clock source (counter mode)
  • TMR_FLAG_IS_SOURCE_IC3 Use input capture channel 3 for the clock source (counter mode)
  • TMR_FLAG_IS_SOURCE_EDGERISING Count rising edges
  • TMR_FLAG_IS_SOURCE_EDGEFALLING Count falling edges
  • TMR_FLAG_IS_SOURCE_EDGEBOTH Count both edges
  • TMR_FLAG_IS_SOURCE_COUNTDOWN Count down (not up)
  • TMR_FLAG_IS_AUTO_RELOAD Auto reload the timer
  • TMR_FLAG_SET_CHANNEL Configure channel characteristics
  • TMR_FLAG_IS_CHANNEL_EDGERISING Count rising edges
  • TMR_FLAG_IS_CHANNEL_EDGEFALLING Count falling edges
  • TMR_FLAG_IS_CHANNEL_EDGEBOTH Count both edges
  • TMR_FLAG_IS_CHANNEL_STOP_ON_RESET Stop when the timer resets
  • TMR_FLAG_IS_CHANNEL_RESET_ON_MATCH Reset when the timer finds a match
  • TMR_FLAG_IS_CHANNEL_STOP_ON_MATCH Stop when the timer finds a match
  • TMR_FLAG_IS_CHANNEL_SET_OUTPUT_ON_MATCH Set the output to 1 on a match
  • TMR_FLAG_IS_CHANNEL_CLEAR_OUTPUT_ON_MATCH Clear the output to 0 on a match
  • TMR_FLAG_IS_CHANNEL_TOGGLE_OUTPUT_ON_MATCH Toggle the output on a match
  • TMR_FLAG_IS_CHANNEL_PWM_MODE Put the timer in PWM mode
  • TMR_FLAG_SET_TRIGGER Set the trigger for the timer
  • TMR_FLAG_IS_SLAVE The trigger indicates slave behavior
  • TMR_FLAG_IS_MASTER The trigger indicates master mode
  • TMR_FLAG_IS_TRIGGER_RELOAD Trigger when timer reloads
  • TMR_FLAG_IS_TRIGGER_RESET Trigger when timer is re-initialized
  • TMR_FLAG_IS_TRIGGER_ENABLE Trigger when timer is enabled
  • TMR_FLAG_IS_TRIGGER_OC0 Trigger on output compare 0
  • TMR_FLAG_IS_TRIGGER_OC1 Trigger on output compare 1
  • TMR_FLAG_IS_TRIGGER_OC2 Trigger on output compare 2
  • TMR_FLAG_IS_TRIGGER_OC3 Trigger on output compare 3

struct::tmr_info_t

u32 o_flags

u32 o_events

u32 freq

u32 resd

struct::tmr_pin_assignment_t

mcu_pin_t channel

struct::tmr_attr_t

u32 o_flags

tmr_pin_assignment_t pin_assignment

u32 freq

The timer frequency

u32 period

If this value is non-zero, the timer will reset when it matches this value (if supported)

mcu_channel_t channel

u32 resd

X

Thanks for Coming!

Subscribe to news and updates