RZV Flexible Software Package Documentation
Release v3.0.0
|
|
Driver for the GTM peripherals on RZ MPUs. This module implements the Timer Interface.
The GTM module can be used to count events, generate a periodic interrupt.
The General timer has the following features:
RZ MPUs have two timer peripherals: the General PWM Timer (GPT) and the General Timer (GTM). When selecting between them, consider these factors:
GPT | GTM | |
---|---|---|
Available Channels | The number of GPT channels is device specific. All currently supported MPUs have at least 6 GPT channels. | All MPUs have 3 GTM channels. |
Timer Resolution | All MPUs have 32-bit GPT timer. | The GTM timers are 32-bit timers. |
Clock Source | The GPT runs off P0 clock with a configurable divider up to 1024. | The GTM runs off P0 clock. |
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 | MCU Specific Options | 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 | 1 | Specify the timer period based on the selected unit. Valid input value range: - When 'Raw Counts' is selected in 'Period Unit', set the value to 0x00000001~0x100000000 - When other item is selected in 'Period Unit', set the value to (1 / count clock) ~ (0x100000000 / count clock) If the input value is exceeded valid range, the ERROR will be shown in hal_data.c. |
General > Period Unit |
| Milliseconds | Unit of the period specified above |
General > Count Source | MCU Specific Options | GTM counter clock source. | |
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 > Underflow Interrupt Priority | Illegal interrupt priority level | 5 | Timer interrupt priority. |
Interrupts > Generate at Start |
| Disable | Controls enabling or disabling of generates OSTMnTINT interrupt at starts |
Extra Features > GTM Mode |
| Interval timer mode | GTM Count Mode (Interval timer mode or Free-running comparison mode) |
The Configuration editor will automatically calculate the period count value based on the selected period time, units.
When the selected unit is "Raw counts", the maximum allowed period setting varies depending on the selected clock source:
Clock source | Maximum period (counts) |
---|---|
P0 clock | 0x100000000 |
In this mode, the timer counts down from the value specified in the compare match register. An interrupt request is generated when the counter reaches 0x0000_0000.
In this mode, the counter counts up from 0x0000_0000 to 0xFFFF_FFFF. An interrupt request is output when the current value of the counter matches the value of the compare match register.
The period is updated after the next counter overflow or underflow after calling R_GTM_PeriodSet().
The GTM 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.
Examples of periodic signals that can be generated by this module are shown below:
This is a basic example of minimal use of the GTM in an application.
This is an example of a timer callback.
To use the GTM as a free running counter, select Free-Running Comparison Mode.
This is an example of updating the period.
Data Structures | |
struct | gtm_instance_ctrl_t |
struct | gtm_extended_cfg_t |
Enumerations | |
enum | gtm_giws_type_t |
enum | gtm_timer_mode_t |
struct gtm_instance_ctrl_t |
Channel control block. DO NOT INITIALIZE. Initialization occurs when timer_api_t::open is called.
struct gtm_extended_cfg_t |
Optional GTM extension data structure.
enum gtm_giws_type_t |
enum gtm_timer_mode_t |
fsp_err_t R_GTM_Close | ( | timer_ctrl_t *const | p_ctrl | ) |
Stops counter, disables interrupts, disables output pins, and clears internal driver data. Implements timer_api_t::close.
FSP_SUCCESS | Timer closed. |
FSP_ERR_ASSERTION | p_ctrl is NULL. |
FSP_ERR_NOT_OPEN | The instance control structure is not opened. |
fsp_err_t R_GTM_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 the maximum value. 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 0xFFFF. |
FSP_ERR_NOT_OPEN | The instance control structure is not opened. |
fsp_err_t R_GTM_DutyCycleSet | ( | timer_ctrl_t *const | p_ctrl, |
uint32_t const | duty_cycle_counts, | ||
uint32_t const | pin | ||
) |
Updates duty cycle. If the timer is counting, the new duty cycle is reflected after the next counter underflow. Implements timer_api_t::dutyCycleSet.
FSP_ERR_UNSUPPORTED |
fsp_err_t R_GTM_Reset | ( | timer_ctrl_t *const | p_ctrl | ) |
Resets the counter value to the period minus one. Implements timer_api_t::reset.
FSP_ERR_UNSUPPORTED | Selected function not supported by this module. |
fsp_err_t R_GTM_Start | ( | timer_ctrl_t *const | p_ctrl | ) |
Starts timer. Implements timer_api_t::start.
FSP_SUCCESS | Timer started. |
FSP_ERR_ASSERTION | p_ctrl is null. |
FSP_ERR_NOT_OPEN | The instance control structure is not opened. |
fsp_err_t R_GTM_Enable | ( | timer_ctrl_t *const | p_ctrl | ) |
Enables external event triggers that start, stop, clear, or capture the counter. Implements timer_api_t::enable.
FSP_ERR_UNSUPPORTED | Selected function not supported by this module. |
fsp_err_t R_GTM_Disable | ( | timer_ctrl_t *const | p_ctrl | ) |
Disables external event triggers that start, stop, clear, or capture the counter. Implements timer_api_t::disable.
FSP_ERR_UNSUPPORTED | Selected function not supported by this module. |
fsp_err_t R_GTM_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_GTM_StatusGet | ( | timer_ctrl_t *const | p_ctrl, |
timer_status_t *const | p_status | ||
) |
Retrieves the current state and counter value stores them in p_status. Implements timer_api_t::statusGet.
FSP_SUCCESS | Current status and counter value provided in p_status. |
FSP_ERR_ASSERTION | A required pointer is NULL. |
FSP_ERR_NOT_OPEN | The instance control structure is not opened. |
fsp_err_t R_GTM_Stop | ( | timer_ctrl_t *const | p_ctrl | ) |
Stops the timer. Implements timer_api_t::stop.
FSP_SUCCESS | Timer stopped. |
FSP_ERR_ASSERTION | p_ctrl was NULL. |
FSP_ERR_NOT_OPEN | The instance control structure is not opened. |
fsp_err_t R_GTM_Open | ( | timer_ctrl_t *const | p_ctrl, |
timer_cfg_t const *const | p_cfg | ||
) |
Initializes the GTM module instance. Implements timer_api_t::open.
The GTM hardware does not support one-shot functionality natively. The one-shot feature is therefore implemented in the GTM HAL layer. For a timer configured as a one-shot timer, the timer is stopped upon the first timer expiration.
The GTM implementation of the general timer can accept an optional gtm_extended_cfg_t extension parameter. For GTM, the extension specifies the clock to be used as timer source and the output pin configurations. If the extension parameter is not specified (NULL), the default clock P0CLK is used and the output pins are disabled.
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. |
FSP_ERR_ALREADY_OPEN | R_GTM_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 GTM. |
fsp_err_t R_GTM_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 | GTM compare match is not supported. |
fsp_err_t R_GTM_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_NO_CALLBACK_MEMORY | p_callback is non-secure and p_callback_memory is either secure or NULL. |