![]() |
RX Flexible Software Package Documentation
Release v1.0.0
|
|
Driver for the TMR peripheral on RX MCUs. This module implements the Timer Interface.
The TMR module has the following features:
RX MCUs have four timer peripherals: the General PWM Timer (GPT), the Compare Match Timer (CMT), the Compare Match Timer W (CMTW) and the 8-bit Timer (TMR). When selecting between them, consider these factors:
| GPT | CMT | CMTW | TMR | |
|---|---|---|---|---|
| Low Power Modes | The GPT can operate in sleep mode. | The CMT can operate in sleep mode. | The CMTW can operate in sleep mode. | The TMR can operate in sleep mode. |
| Available Channels | The number of GPT channels is device specific. All currently supported MCUs have at least 4 GPT channels. | The number of CMT channels is device specific. All MCUs have 4 CMT channels. | The number of CMTW channels is device specific. All MCUs have 2 CMTW channels. | All MCUs have 4 TMR channels. |
| Timer Resolution | All MCUs have at least one 32-bit GPT timer. | The CMT timers are 16-bit timers. | The CMTW timer have at least one 32-bit CMTW timer | The TMR timers are 8-bit timer or 16-bit timer. |
| Clock Source | The GPT runs off PCLKA with a configurable divider up to 1024. It can also be configured to count ELC events or external pulses. | The CMT runs off PCLKB. | The CMTW runs off PCLKB. | The TMR runs off PCLKB. |
| Configuration | Options | Default | Description |
|---|---|---|---|
| Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
| Pin Output Support |
| Disabled | If selected code for outputting a waveform to a pin is included in the build. |
| Configuration | Options | Default | Description |
|---|---|---|---|
| General > Name | Name must be a valid C symbol | g_timer0 | Module name. |
| General > Counter Size | MCU Specific Options | Counter size register bit width (8-bit or 16-bit)) | |
| General > Channel | Channel number must be a non-negative integer | 0 | Physical hardware channel. |
| General > Mode |
| Periodic | Mode selection. Note: One-shot mode is implemented in software. ISR's must be enabled for one shot even if callback is unused. |
| General > Period | Value must be non-negative | 0x100 | Specify the timer period based on the selected unit. |
| General > Period Unit |
| Raw Counts | Unit of the period specified above |
| Output > Duty Cycle Percent (only applicable in PWM mode) | Value must be between 0 and 100 | 50 | Specify the timer duty cycle percent. Only used in PWM mode. |
| Extra Features > ADC Trigger | MCU Specific Options | Select the ADC trigger enable. | |
| Interrupts > Callback | Name must be a valid C symbol | NULL | A user callback function. If this callback function is provided, it is called from the interrupt service routine (ISR) each time the timer period elapses. |
| Interrupts > Overflow Interrupt Priority | MCU Specific Options | Select the interrupt priority for overflow. | |
| Interrupts > Compare Match Interrupt Priority | MCU Specific Options | Select the interrupt priority for compare match. |
The TMR clock is based on the PCLKB frequency. You can set the clock frequency using the Clocks tab of the RX Configuration editor or by using the CGC Interface at run-time.
This module can use the TMOn pin as output pins for periodic, one-shot, or PWM signals.
The RX Configuration editor will automatically calculate the period count value and source clock divider based on the selected period time, units, and clock speed.
When the selected unit is "Raw counts", the maximum allowed period setting varies depending on the selected clock source:
| Clock source | 8-bit Timer Maximum period (counts) | 16-bit Timer Maximum period (counts) |
|---|---|---|
| PCLKB | 0xFF | 0xFFFF |
The TMR timer does not support one-shot mode natively. One-shot mode is achieved by stopping the timer in the interrupt service routine before the callback is called. If the interrupt is not serviced before the timer period expires again, the timer generates more than one event. The callback is only called once in this case, but multiple events may be generated if the timer is linked to the Transfer (r_dtc).
The output waveform in one-shot mode is one TMR clock cycle less than the configured period. The configured period must be at least 2 counts to generate an output pulse.
Examples of one-shot signals that can be generated by this module are shown below:
The TMOn pin toggles twice each time the timer expires in periodic mode. This is achieved by defining a PWM wave at a 50 percent duty cycle so that the period of the resulting square (from rising edge to rising edge) matches the period of the TMR timer. Since the periodic output is actually a PWM output, the time at the stop level is one cycle shorter than the time opposite the stop level for odd period values.
Examples of periodic signals that can be generated by this module are shown below:
This module does not support in three-phase PWM output. The PWM output signal is low at the beginning of the cycle and high at the end of the cycle.
Examples of PWM signals that can be generated by this module are shown below:
The TMR timer can trigger the start request in response to compare match A This feature not support on MCU RX74M.
The TMR timer can trigger the start of other peripherals. The Event Link Controller (r_elc) guide provides a list of all available peripherals.
Event counting can be done by selecting counting sources from TCCR, ELC events.
The TMR timer can be configured to start, count, and restart when an ELC event occurs.
Developers should be aware of the following limitations when using the TMR:
This is a basic example of minimal use of the TMR in an application.
This is an example of a timer callback.
To use the TMR as a free running counter, select periodic mode and set the the Period to 0xFF for a 8-bit timer or 0xFFFF for a 16-bit timer.
This is an example of updating the period.
This is an example of updating the duty cycle.
This is an example of using underflow from an even TMR channel as the count source for the next channel (in this case, TMR0 and TMR1).
Data Structures | |
| struct | tmr_instance_ctrl_t |
| struct | tmr_extended_cfg_t |
Enumerations | |
| enum | tmr_adc_trigger_t |
| enum | tmr_counter_size_t |
| struct tmr_instance_ctrl_t |
Channel control block. DO NOT INITIALIZE. Initialization occurs when timer_api_t::open is called.
Data Fields | |
| uint32_t | open |
| Whether or not channel is open. | |
| const timer_cfg_t * | p_cfg |
| Pointer to initial configurations. | |
| R_TMR_Type * | p_reg |
| Base register for this channel. | |
| uint32_t | period |
| Current timer period (counts) | |
| uint8_t | index |
| register array index for this channel. | |
| uint8_t | control_index |
| This field indicates the index of the odd-numbered channel that will be used as the lower byte in 16-bit mode. | |
| void(* | p_callback )(timer_callback_args_t *) |
| Pointer to callback that is called when a timer_event_t occurs. | |
| timer_callback_args_t * | p_callback_memory |
| Pointer to non-secure memory that can be used to pass arguments to a callback in non-secure memory. | |
| void * | p_context |
| Pointer to context to be passed into callback function. | |
| struct tmr_extended_cfg_t |
Optional TMR extension data structure.
| Data Fields | ||
|---|---|---|
| tmr_counter_size_t | counter_size | Selected timer 16-bit or 8-bit. |
| tmr_adc_trigger_t | adc_request_enable | A/D Converter Start Request. |
| uint8_t | output_compare_ipl | Output Compare match interrupt priority. |
| IRQn_Type | output_compare_irq | Output Compare match interrupt. |
| enum tmr_adc_trigger_t |
| enum tmr_counter_size_t |
| fsp_err_t R_TMR_Open | ( | timer_ctrl_t *const | p_ctrl, |
| timer_cfg_t const *const | p_cfg | ||
| ) |
Initializes the timer module and applies configurations. Implements timer_api_t::open.
TMR hardware does not support one-shot functionality natively. When using one-shot mode, the timer will be stopped in an ISR after the requested period has elapsed.
The TMR implementation of the general timer can accept a tmr_extended_cfg_t extension parameter.
Example:
| FSP_SUCCESS | Initialization was successful. |
| FSP_ERR_ASSERTION | A required input pointer is NULL or the source divider is invalid or channel does not support a 16bit counter size or the period was not in the valid range of 1 to 0xFF in 8bit counter or 1 to 0xFFFF in 16bit counter or an input parameter is invalid. |
| FSP_ERR_ALREADY_OPEN | Module is already open. |
| FSP_ERR_IRQ_BSP_DISABLED | timer_cfg_t::mode is TIMER_MODE_ONE_SHOT or timer_cfg_t::p_callback is not NULL, but ISR is not enabled. ISR must be enabled to use one-shot mode or callback. Or a required interrupt has not been enabled in the vector table. |
| FSP_ERR_IP_CHANNEL_NOT_PRESENT | The channel requested in the p_cfg parameter is not available on this device. |
| fsp_err_t R_TMR_Start | ( | timer_ctrl_t *const | p_ctrl | ) |
Starts timer. Implements timer_api_t::start.
| FSP_SUCCESS | Timer successfully started. |
| FSP_ERR_ASSERTION | p_ctrl was NULL. |
| FSP_ERR_NOT_OPEN | The instance is not opened. |
| fsp_err_t R_TMR_Stop | ( | timer_ctrl_t *const | p_ctrl | ) |
Stops timer. Implements timer_api_t::stop.
| FSP_SUCCESS | Timer successfully stopped. |
| FSP_ERR_ASSERTION | p_ctrl was NULL. |
| FSP_ERR_NOT_OPEN | The instance is not opened. |
| fsp_err_t R_TMR_Enable | ( | timer_ctrl_t *const | p_ctrl | ) |
Enables external event triggers that start, event count, or restart the counter. Implements timer_api_t::enable.
| FSP_ERR_UNSUPPORTED | API not supported by TMR. |
| fsp_err_t R_TMR_Disable | ( | timer_ctrl_t *const | p_ctrl | ) |
Disables external event triggers that start, event count or restart the counter. Implements timer_api_t::disable.
| FSP_ERR_UNSUPPORTED | API not supported by TMR. |
| fsp_err_t R_TMR_Reset | ( | timer_ctrl_t *const | p_ctrl | ) |
Resets the counter value to 0. Implements timer_api_t::reset.
| FSP_SUCCESS | Counter reset. |
| FSP_ERR_ASSERTION | p_ctrl is NULL |
| FSP_ERR_NOT_OPEN | The instance control structure is not opened. |
| fsp_err_t R_TMR_PeriodSet | ( | timer_ctrl_t *const | p_ctrl, |
| uint32_t const | period_counts | ||
| ) |
Updates period. The new period is updated immediately. Implements timer_api_t::periodSet.
| FSP_SUCCESS | Period value updated. |
| FSP_ERR_ASSERTION | A required pointer was NULL, or the period was not in the valid range of 1 to 0xFF in 8bit counter or 1 to 0xFFFF in 16bit counter. |
| FSP_ERR_NOT_OPEN | The instance control structure is not opened. |
| fsp_err_t R_TMR_DutyCycleSet | ( | timer_ctrl_t *const | p_ctrl, |
| uint32_t const | duty_cycle_counts, | ||
| uint32_t const | pin | ||
| ) |
Sets duty cycle on requested pin. Implements timer_api_t::dutyCycleSet.
Example:
| FSP_SUCCESS | Duty cycle updated. |
| FSP_ERR_ASSERTION | A required pointer was NULL, or the pin was invalid. |
| FSP_ERR_INVALID_ARGUMENT | Duty cycle was not in the valid range of 0 to period (counts) - 1 |
| FSP_ERR_NOT_OPEN | The instance control structure is not opened. |
| FSP_ERR_UNSUPPORTED | TMR_CFG_OUTPUT_SUPPORT_ENABLE is 0. |
| fsp_err_t R_TMR_CompareMatchSet | ( | timer_ctrl_t *const | p_ctrl, |
| uint32_t const | compare_match_value, | ||
| timer_compare_match_t const | match_channel | ||
| ) |
Placeholder for unsupported compareMatch function. Implements timer_api_t::compareMatchSet.
| FSP_ERR_UNSUPPORTED | TMR compare match is not supported. |
| fsp_err_t R_TMR_InfoGet | ( | timer_ctrl_t *const | p_ctrl, |
| timer_info_t *const | p_info | ||
| ) |
Gets timer information and store it in provided pointer p_info. Implements timer_api_t::infoGet.
| FSP_SUCCESS | Period, count direction, and frequency stored in p_info. |
| FSP_ERR_ASSERTION | A required pointer is NULL. |
| FSP_ERR_NOT_OPEN | The instance control structure is not opened. |
| fsp_err_t R_TMR_StatusGet | ( | timer_ctrl_t *const | p_ctrl, |
| timer_status_t *const | p_status | ||
| ) |
Get current timer status and store it in provided pointer p_status. Implements timer_api_t::statusGet.
| FSP_SUCCESS | Current timer state and counter value set successfully. |
| FSP_ERR_ASSERTION | p_ctrl or p_status was NULL. |
| FSP_ERR_NOT_OPEN | The instance is not opened. |
| fsp_err_t R_TMR_AdcTriggerSet | ( | timer_ctrl_t *const | p_ctrl, |
| tmr_adc_trigger_t | adc_request_enable | ||
| ) |
Set A/D converter start request compare match value.
| FSP_SUCCESS | Counter value updated. |
| FSP_ERR_ASSERTION | p_ctrl was NULL or channel unsupport Adc trigger. |
| FSP_ERR_NOT_OPEN | The instance is not opened. |
| FSP_ERR_IP_CHANNEL_NOT_PRESENT | The channel requested in the p_cfg parameter is not available on this device 16-bit timer. |
| FSP_ERR_UNSUPPORTED | The feature not available on this device. |
| fsp_err_t R_TMR_CallbackSet | ( | timer_ctrl_t *const | p_api_ctrl, |
| void(*)(timer_callback_args_t *) | p_callback, | ||
| void *const | p_context, | ||
| timer_callback_args_t *const | p_callback_memory | ||
| ) |
Updates the user callback with the option to provide memory for the callback argument structure. Implements timer_api_t::callbackSet.
| FSP_SUCCESS | Callback updated successfully. |
| FSP_ERR_ASSERTION | A required pointer is NULL. |
| FSP_ERR_NOT_OPEN | The control block has not been opened. |
| fsp_err_t R_TMR_Close | ( | timer_ctrl_t *const | p_ctrl | ) |
Stops counter, clears internal driver data. Implements timer_api_t::close.
| FSP_SUCCESS | Successful close. |
| FSP_ERR_ASSERTION | p_ctrl was NULL. |
| FSP_ERR_NOT_OPEN | The instance is not opened. |