group::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

defineTMR_VERSION


defineTMR_IOC_IDENT_CHAR


defineI_TMR_GETVERSION


defineI_TMR_GETINFO


defineI_TMR_SETATTR


defineI_TMR_SETACTION


defineI_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; }

defineI_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;

defineI_TMR_SET

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

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

defineI_TMR_GET

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

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

defineI_TMR_ENABLE


defineI_TMR_DISABLE


defineI_TMR_TOTAL


enum@33

  • 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


date: “2019-06-27” layout: post title: struct::tmr_info_t katex: true

categories: struct

Methods

Details

public u32o_flags


public u32o_events


public u32freq


public u32resd



date: “2019-06-27” layout: post title: struct::tmr_pin_assignment_t katex: true

categories: struct

Methods

Details

publicmcu_pin_tchannel



date: “2019-06-27” layout: post title: struct::tmr_attr_t katex: true

categories: struct

Methods

Details

public u32o_flags


public tmr_pin_assignment_tpin_assignment


public u32freq

The timer frequency


public u32period

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


public mcu_channel_tchannel


public u32resd


X

Thanks for Coming!

Subscribe to news and updates