RA Flexible Software Package Documentation
Release v5.7.0
|
|
Driver for the TML peripherals on RA MCUs. This module implements the Timer Interface.
The TML module can be used to count or count input events. TML operates with the HOCO, MOCO, MOSC, LOCO/SOSC clock or the event input from the ELC, which is asynchronous to CPU operation.
The TML module has the following features:
RA MCUs have different timer peripherals: the General PWM Timer (GPT), the 32-bit Interval Timer (TML), Timer Array Unit (TAU), and the Asynchronous General Purpose Timer (AGT). Some MCUs have multiple timer modules. When selecting between them, consider these factors:
GPT | TML | AGT | TAU | |
---|---|---|---|---|
Low Power Modes | The GPT can operate in sleep mode. | The TML can operate in all low power modes. | The AGT can operate in all low power modes. | The TAU can not operate in all low power modes. |
Available Channels | The number of GPT channels is device specific. Currently supported MCUs have at least 7 GPT channels. | Currently supported MCUs have 4 TML channels. | Currently supported MCUs have 2 AGT channels. | Currently supported MCUs have 8 TAU channels. |
Timer Resolution | Currently supported MCUs have at least one 32-bit GPT timer. | The TML timers are 32-bit/16-bit/8-bit timers. | The AGT timers are 16-bit timers. | The TAU timers are 16-bit/8-bit timers. |
Clock Source | The GPT runs off PCLKD with a configurable divider up to 1024. It can also be configured to count ELC events or external pulses. | The TML runs off MOSC, LOCO/SOSC, HOCO, MOCO with a configurable divider up to 128 or ELC events. | The AGT runs off PCLKB, LOCO, or subclock. | The TAU runs off PCLK with a configurable divider up to 32768 |
Configuration | Options | Default | Description |
---|---|---|---|
Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
Critical Section Guarding |
| Disabled | Enable critical section guarding around peripheral configuration updates. This should be enabled if multiple instances of the R_TML module are being used. |
16-bit Capture Mode Support |
| Disabled | Controls whether 16-bit capture mode support is included in the build. This setting applies globally to all r_tml_instances. If 16-bit capture mode is not used by any instance, disable this setting to reduce ROM usage. |
Enable Single Channel |
| Disabled | Enable single channel to reduce code size. Assumes channel 0. |
Interrupt Support |
| Disabled | Enable support for interrupts. |
Configuration | Options | Default | Description |
---|---|---|---|
General | |||
Name | Name must be a valid C symbol | g_timer0 | Module name. |
Mode |
| 16-bit Counter Mode | Selection of Operating mode. |
Channel Selection | Channel number must exist on this MCU | 0 | Specify the hardware channel. |
ELC event | MCU Specific Options | Select the elc event. | |
Counter Mode Settings | |||
Period | Value must be positive integer | 0x10000 | Specify the timer period in units selected below. Set the period to 0x100 (8-bit) or 0x10000 (16-bit) or 0x100000000 (32-bit) raw counts for a free running timer. Since the maxmimum divider is 128... the raw counts period can be set up to the (max count+1)*128. [0x8000 (8-bit) or 0x800000 (16-bit), or 0x8000000000 (32-bit)]. |
Period Unit |
| Raw Counts | Unit of the period specified above. When the Counter Clock Source is the ELC, only Raw Counts can be selected here. |
Capture Mode Settings | |||
Capture Mode Settings > 16-Bit Counter Input Settings (when Capture source = Interrupt on compare match with ITLCMP01) | |||
Period | Value must be positive integer | 0x10000 | Specify the timer period in units selected below. Set the period to 0x10000 raw counts in the maximum period of 16-bit capture. |
Period Unit |
| Raw Counts | Unit of the period specified above. When the Capture Clock Source is the ELC, only Raw Counts can be selected here. |
Capture Trigger | MCU Specific Options | Selection of capture trigger. | |
Capture Clock Divider |
| fITL0 | Configure FDIV0 for the counter clock in 16-bit Capture Mode. |
Counter Status |
| Retained after the completion of capturing | Selection of the 16-bit counter (ITL000 + ITL001) clearing after capturing. |
Interrupt | |||
Callback function | Name must be a valid C symbol | NULL | A user callback function can be provided here. If this callback function is provided, it is called from the interrupt service routine (ISR) each time the IRQn triggers |
Priority | MCU Specific Options | Select the interrupt priority. |
The TML operating clock is based on the HOCO, MOCO, MOSC, or LOCO/SOSC. The operating frequency will be based on the source chosen and the divider selected. You can set the clock frequencies using the Clocks tab of the RA Configuration editor or change the clock divider for the capture mode channel by Capture Mode Settings->Capture Clock Divider.
In capture mode, the clock divider for the capture channel has to be selected in Capture Mode Settings->Capture Clock Divider. If ITLCMP01 is the capture trigger input, the clock divider for channels 2 + 3 is not available.
When no capture mode is active, the RA 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 period unit is "Raw counts", the maximum period setting is 0x8000000000/0x800000/0x8000 on a 32-bit/16-bit/8-bit timer. This will configure the timer with the maximum period and a count clock divisor of 128.
The period is updated after calling R_TML_PeriodSet().
When the 16-bit capture mode is to be used for channels 0 and 1, the counter value is stored in interval timer capture register 00 (ITLCAP00) in response to the selected capture trigger.
The TML timer can be configured to start count down or trigger capture when an ELC event occurs.
The TML timer can trigger the start of other peripherals. The Event Link Controller (r_elc) guide provides a list of all available peripherals.
This is a basic example of minimal use of the TML in an application.
This is an example of a timer callback.
This is an example of 8/16/32-bit Counter.
This is an example of using the TML to capture the counter value of configured channel.
This an example of updating the period.
Data Structures | |
struct | tml_extended_cfg_t |
struct | tml_instance_ctrl_t |
Enumerations | |
enum | tml_clock_t |
enum | tml_capture_trigger_t |
enum | tml_counter_status_t |
struct tml_extended_cfg_t |
User configuration structure, used in open function
Data Fields | ||
---|---|---|
tml_capture_trigger_t | capture_trigger | Select the capture source for capture channel. |
tml_counter_status_t | counter_status | Status of 16-bit counter (ITL000 + ITL001) after completion of capturing. |
struct tml_instance_ctrl_t |
TML instance control block.
Data Fields | |
uint32_t | open |
Used to determine if the channel is configured. | |
const timer_cfg_t * | p_cfg |
Pointer to the configuration block. | |
uint8_t | channel_mask |
Mask value of channel used. | |
void(* | p_callback )(timer_callback_args_t *) |
Pointer to callback that is called when a timer event occurs. | |
void const * | p_context |
Pointer to context to be passed into callback function. | |
enum tml_clock_t |
enum tml_counter_status_t |
Enumeration for status of 16-bit counter (ITL000 + ITL001) after completion of capturing
fsp_err_t R_TML_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.
TML hardware does not support one-shot functionality natively. If one shot mode is desired, the user code should stop the timer after the timer expires the first time in an ISR after the requested period has elapsed.
The TML implementation of the general timer can accept a tml_extended_cfg_t extension parameter.
Example:
FSP_SUCCESS | Initialization was successful and timer has started. |
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::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_INVALID_CHANNEL | Selected channel is invalid |
FSP_ERR_INVALID_MODE | The mode requested in the p_cfg parameter is incorrect. It must be the same for all instances. |
FSP_ERR_IN_USE | Channel is running |
fsp_err_t R_TML_Stop | ( | timer_ctrl_t *const | p_ctrl | ) |
Stops the counter and disable the capture. Implements timer_api_t::stop.
Example:
FSP_SUCCESS | Timer successfully stopped. |
FSP_ERR_ASSERTION | p_ctrl was NULL. |
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. |
fsp_err_t R_TML_Start | ( | timer_ctrl_t *const | p_ctrl | ) |
Starts the counter and enable the capture. Implements timer_api_t::start.
Example:
FSP_SUCCESS | Timer successfully started. |
FSP_ERR_ASSERTION | p_ctrl was NULL. |
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. |
fsp_err_t R_TML_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_IP_CHANNEL_NOT_PRESENT | The channel requested in the p_cfg parameter is not available on this device. |
fsp_err_t R_TML_Enable | ( | timer_ctrl_t *const | p_ctrl | ) |
Enable the interrupt generation from the selected channel timer_api_t::enable.
Example:
FSP_SUCCESS | External events successfully enabled. |
FSP_ERR_ASSERTION | p_ctrl was NULL. |
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. |
fsp_err_t R_TML_Disable | ( | timer_ctrl_t *const | p_ctrl | ) |
Disable the interrupt generation for this timer. Implements timer_api_t::disable.
Example:
FSP_SUCCESS | External events successfully disabled. |
FSP_ERR_ASSERTION | p_ctrl was NULL. |
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. |
fsp_err_t R_TML_PeriodSet | ( | timer_ctrl_t *const | p_ctrl, |
uint32_t const | period_counts | ||
) |
Sets period value provided. Only set this value when all timers are stop. Implements timer_api_t::periodSet.
Example:
FSP_SUCCESS | Period value written successfully. |
FSP_ERR_ASSERTION | p_ctrl was NULL. |
FSP_ERR_NOT_OPEN | The instance is not opened. |
FSP_ERR_IN_USE | Channel is running |
fsp_err_t R_TML_DutyCycleSet | ( | timer_ctrl_t *const | p_ctrl, |
uint32_t const | duty_cycle_counts, | ||
uint32_t const | pin | ||
) |
timer_api_t::dutyCycleSet is not supported on the TML.
FSP_ERR_UNSUPPORTED | Function not supported in this implementation. |
fsp_err_t R_TML_CompareMatchSet | ( | timer_ctrl_t *const | p_ctrl, |
uint32_t const | compare_match_value, | ||
timer_compare_match_t const | match_channel | ||
) |
timer_api_t::compareMatchSet is not supported on the TML.
FSP_ERR_UNSUPPORTED | Function not supported in this implementation. |
fsp_err_t R_TML_InfoGet | ( | timer_ctrl_t *const | p_ctrl, |
timer_info_t *const | p_info | ||
) |
Get timer configuration information and store it in provided pointer p_info. Implements timer_api_t::infoGet.
Example:
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_TML_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.
Example:
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_IP_CHANNEL_NOT_PRESENT | The channel requested in the p_cfg parameter is not available on this device. |
fsp_err_t R_TML_CallbackSet | ( | timer_ctrl_t *const | p_api_ctrl, |
void(*)(timer_callback_args_t *) | p_callback, | ||
void const *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_TML_Close | ( | timer_ctrl_t *const | p_ctrl | ) |
Stops counter, disables output pins, and 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. |
FSP_ERR_IP_CHANNEL_NOT_PRESENT | The channel requested in the p_cfg parameter is not available on this device. |
FSP_ERR_IN_USE | Channel is running |