Driver for the CMTW peripheral on RZ microprocessor. This module implements the Timer Interface.
Overview
Features
The CMTW module has the following features:
Supports periodic mode and one-shot mode.
Supports count source of PCLKL.
Supports Input capture function, Output compare function, and Compare match function.
Signal can be output to a pin.
Configurable period (counts per timer cycle).
Supports runtime reconfiguration of period.
APIs are provided to start, stop, and reset the counter.
APIs are provided to get the current period, source clock frequency, and count direction.
APIs are provided to get the current timer status and counter value.
Configuration
Build Time Configurations for r_cmtw
The following build time configurations are defined in fsp_cfg/r_cmtw_cfg.h:
Configuration
Options
Default
Description
Parameter Checking
Default (BSP)
Enabled
Disabled
Default (BSP)
If selected code for parameter checking is included in the build.
Multiplex Interrupt
Enabled
Disabled
Disabled
Enable multiplex interrupt for a single driver.
Configurations for Timers > Timer, Compare Match W (r_cmtw)
This module can be added to the Stacks tab via New Stack > Timers > Timer, Compare Match W (r_cmtw).
Configuration
Options
Default
Description
General > Name
Name must be a valid C symbol
g_timer0
Module name.
General > Channel
Channel number does not exist
0
Physical hardware channel.
General > Mode
Periodic
One-Shot
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
0x10000
Specify the timer period based on the selected unit.
General > Period Unit
Raw Counts
Nanoseconds
Microseconds
Milliseconds
Seconds
Hertz
Kilohertz
Raw Counts
Unit of the period specified above
General > Counter Size
32-bit
16-bit
32-bit
Size of the timer counter
General > Counter Clear Source
Compare Match
Disabled
Input Capture0
Input Capture1
Output Compare0
Output Compare1
Compare Match
Select the Counter Clear Source.
Output > TOC0 Output
Disabled
Start Level Low and Toggle Output
Start Level High and Toggle Output
Disabled
Configure TOC0 output.
Output > TOC1 Output
Disabled
Start Level Low and Toggle Output
Start Level High and Toggle Output
Disabled
Configure TOC1 output.
Output > TOC0 Output Enable
Output Disable
Output Enable
Output Disable
Configure TOC0 output enable.
Output > TOC1 Output Enable
Output Disable
Output Enable
Output Disable
Configure TOC1 output enable.
Input > TIC0 Capture Trigger
Rising Edge
Falling Edge
Both Edge
Rising Edge
Select the trigger edge.
Input > TIC1 Capture Trigger
Rising Edge
Falling Edge
Both Edge
Rising Edge
Select the trigger edge.
Input > TIC0 Input Enable
Input Disable
Input Enable
Input Disable
Configure TIC0 output enable.
Input > TIC1 Input Enable
Input Disable
Input Enable
Input Disable
Configure TIC1 output 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 > Compare Match Interrupt Priority
MCU Specific Options
Compare match interrupt priority.
Interrupts > Input Capture 0 Interrupt Priority
MCU Specific Options
Input capture 0 interrupt priority.
Interrupts > Input Capture 1 Interrupt Priority
MCU Specific Options
Input capture 1 interrupt priority.
Interrupts > Output Compare 0 Interrupt Priority
MCU Specific Options
Output capture 0 interrupt priority.
Interrupts > Output Compare 1 Interrupt Priority
MCU Specific Options
Output capture 1 interrupt priority.
Clock Configuration
The CMTW clock is based on the PCLKL. You can set the clock frequency using the Clocks tab of the FSP Configuration editor or by using the CGC Interface at run-time.
Pin Configuration
This module can use the TOC0 and TOC1 pins as output pins for output compare or one-shot signals.
For input capture, the input signal must be applied to the TIC0 or TIC1 pin.
Timer Period
The FSP Configuration editor will automatically calculate the period count value and source clock divider based on the selected period time, units, and clock speed.
Because the period interrupt occurs when the counter overflows, setting the period register to 0 results in an effective period of 1 count. For this reason all user-provided raw count values reflect the actual number of period counts (not the raw register values).
Usage Notes
One-Shot Mode
The CMTW 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 Direct Memory Access Controller (r_dmac).
One-Shot Mode Output
Examples of one-shot signals that can be generated by this module are shown below:
CMTW One-Shot Output
Output Compare
The TOC0 or TOC1 pin toggles each time the timer expires in output compare mode.
Examples of periodic signals that can be generated by this module are shown below:
CMTW Periodic Output
Examples
CMTW Basic Example
This is a basic example of minimal use of the CMTW in an application.
The CMTW hardware does not support one-shot functionality natively. The one-shot feature is therefore implemented in the CMTW HAL layer. For a timer configured as a one-shot timer, the timer is stopped upon the first timer expiration.
The CMTW implementation of the general timer can accept an optional cmtw_extended_cfg_t extension parameter.
Return values
FSP_SUCCESS
Initialization was successful and timer has started.
FSP_ERR_ASSERTION
A required input pointer is NULL or the period is not in the valid range of 1 to 0xFFFF in 16bit counter or 1 to 0xFFFFFFFF in 32bit counter.
FSP_ERR_ALREADY_OPEN
R_CMTW_Open has already been called for this p_ctrl.
FSP_ERR_IRQ_BSP_DISABLED
A required interrupt has not been enabled in the vector table.
FSP_ERR_IP_CHANNEL_NOT_PRESENT
Requested channel number is not available on CMTW.