![]() |
RX Flexible Software Package Documentation
Release v1.0.0
|
|
Driver for the CMT peripherals on RX MCU. This module implements the Timer Interface.
RX has two on-chip CMT units (unit 0 and unit 1), each consisting of a two-channel 16-bit timer.
The CMT has a 16-bit counter, and can generate interrupts at set intervals.
The CMT module has the following features:
When selecting CMT, consider these factors:
| GPT | CMTW | CMT | TMR | |
|---|---|---|---|---|
| Timer Resolution | All MCUs have at least one 32-bit GPT timer. | The CMTW timer have at least one 32-bit CMTW timer. | The CMT timers are 16-bit timers. | 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 CMTW runs off PCLKB. | The CMT runs off PCLKB with a configurable divider from 8 to 512. It can also be configured to count ELC events. | The TMR runs off PCLKB. |
| Low Power Modes | The GPT can operate in sleep mode. | The CMTW can operate in sleep mode. | The CMT can operate in in sleep mode. | The TMR can operate in sleep mode. |
| Configuration | Options | Default | Description |
|---|---|---|---|
| Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
| Configuration | Options | Default | Description |
|---|---|---|---|
| General > Name | Name must be a valid C symbol | g_timer0 | Module name. |
| General > Channel | Value must be a non-negative integer | 0 | Specify the hardware channel. |
| General > Mode |
| Periodic | Mode selection. Periodic: Generates periodic interrupts or square waves. One-shot: Generate a single interrupt or a pulse wave. Note: One-shot mode is implemented in software. ISRs must be enabled for one-shot even if callback is unused. |
| General > Period | Value must be non-negative | 0x10000 | Specify the timer period based on the selected unit. |
| General > Period Unit |
| Raw Counts | Unit of the period specified above |
| Interrupts > Callback | Name must be a valid C symbol | NULL | A user callback function can be specified here. If this callback function is provided, it will be called from the interrupt service routine (ISR) each time the timer period elapses |
| Interrupts > Compare Match Interrupt Priority | MCU Specific Options | Select the compare match interrupt priority. |
The CMT clock is based on the PCLKB frequency. You can set the PCLKB frequency using the Clocks tab of the RX Configuration editor or by using the CGC Interface at run-time.
When period unit is selected as "Raw Counts", the output waveform period is calculated based on default clock frequency PCLKB/8
The RX Configuration editor will automatically calculate the period count value and source clock divider based on the selected period time and units.
When the selected period unit is "Raw counts", the maximum period setting is 0x10000 on a 16-bit timer. This will configure the timer with the maximum period and a count clock divisor of 512.
The period is updated after the next counter overflow after calling R_CMT_PeriodSet(). To force them to update before the next counter overflow, call R_CMT_Reset() while the counter is running.
After a compare match interrupt is generated, the counter then reset to 0000h and stop.
Frequency dividing clock is selected from four frequency dividing clocks obtained by dividing the peripheral module clock (PCLKB), the CMCNT counter starts counting up using the selected clock. When the value in the counter and the value in the register match, a compare match interrupt (CMIn) is generated. The CMCNT counter then starts counting up again from 0000h.
Event counting can be done by selecting counting sources from CMCR, ELC events.
The cmt timer can be configured to start, count, restart when an ELC event occurs.
This is a basic example of minimal use of the cmt in an application.
This is an example of a timer callback.
To use the CMT as a free running counter, select periodic mode and set the the Period to 0xFFFF for a 16-bit timer.
This an example of updating the period.
Data Structures | |
| struct | cmt_instance_ctrl_t |
| struct cmt_instance_ctrl_t |
Channel control block. DO NOT INITIALIZE. Initialization occurs when timer_api_t::open is called.
| fsp_err_t R_CMT_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.
| FSP_SUCCESS | Initialization was successful. |
| FSP_ERR_ASSERTION | A required input pointer is NULL or the source divider 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. |
| FSP_ERR_IP_CHANNEL_NOT_PRESENT | The channel requested in the p_cfg parameter is not available on this device. |
| fsp_err_t R_CMT_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_CMT_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_CMT_Reset | ( | timer_ctrl_t *const | p_ctrl | ) |
Resets the counter value to 0. Implements timer_api_t::reset.
| FSP_SUCCESS | Counter value written successfully. |
| FSP_ERR_ASSERTION | p_ctrl was NULL. |
| FSP_ERR_NOT_OPEN | The instance is not opened. |
| fsp_err_t R_CMT_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 CMT. |
| fsp_err_t R_CMT_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 CMT. |
| fsp_err_t R_CMT_PeriodSet | ( | timer_ctrl_t *const | p_ctrl, |
| uint32_t const | period_counts | ||
| ) |
Updates period. The new period is updated immediately and the counter is reset to 0. Period unit is raw. Other units will be converted to raw before setting.
Implements timer_api_t::periodSet.
| FSP_SUCCESS | Period value written successfully. |
| FSP_ERR_ASSERTION | p_ctrl was NULL. |
| FSP_ERR_NOT_OPEN | The instance is not opened. |
| fsp_err_t R_CMT_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.
| FSP_ERR_UNSUPPORTED | API not supported by CMT. |
| fsp_err_t R_CMT_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 | CMT compare match is not supported. |
| fsp_err_t R_CMT_InfoGet | ( | timer_ctrl_t *const | p_ctrl, |
| timer_info_t *const | p_info | ||
| ) |
Get timer information and store it in provided pointer p_info. Implements timer_api_t::infoGet.
| FSP_SUCCESS | Period, count direction, frequency, and ELC event written to caller's structure successfully. |
| FSP_ERR_ASSERTION | p_ctrl or p_info was NULL. |
| FSP_ERR_NOT_OPEN | The instance is not opened. |
| fsp_err_t R_CMT_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_CMT_CounterSet | ( | timer_ctrl_t *const | p_ctrl, |
| uint32_t | counter | ||
| ) |
Set counter value.
| FSP_SUCCESS | Counter value updated. |
| FSP_ERR_ASSERTION | p_ctrl or p_status was NULL. |
| FSP_ERR_NOT_OPEN | The instance is not opened. |
| fsp_err_t R_CMT_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_CMT_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. |