![]() |
Synergy Software Package User's Manual
|
Driver for the Asynchronous General Purpose Timer (AGT). More...
Data Structures | |
| struct | agt_instance_ctrl_t |
| struct | timer_on_agt_cfg_t |
Enumerations | |
| enum | agt_count_source_t { AGT_CLOCK_PCLKB = 0, AGT_CLOCK_PCLKB_DIV_8 = 1, AGT_CLOCK_PCLKB_DIV_2 = 3, AGT_CLOCK_LOCO = 4, AGT_CLOCK_AGT0_UNDERFLOW = 5, AGT_CLOCK_FSUB = 6 } |
Functions | |
| ssp_err_t | R_AGT_TimerOpen (timer_ctrl_t *const p_api_ctrl, timer_cfg_t const *const p_cfg) |
| Open the AGT channel as a timer, handles required initialization described in hardware manual. Implements timer_api_t::open. More... | |
| ssp_err_t | R_AGT_Close (timer_ctrl_t *const p_api_ctrl) |
| ssp_err_t | R_AGT_CounterGet (timer_ctrl_t *const p_api_ctrl, timer_size_t *const p_value) |
| ssp_err_t | R_AGT_PeriodSet (timer_ctrl_t *const p_api_ctrl, timer_size_t const period, timer_unit_t const unit) |
| ssp_err_t | R_AGT_DutyCycleSet (timer_ctrl_t *const p_api_ctrl, timer_size_t const duty_cycle, timer_pwm_unit_t const unit, uint8_t const pin) |
| ssp_err_t | R_AGT_Reset (timer_ctrl_t *const p_api_ctrl) |
| ssp_err_t | R_AGT_Start (timer_ctrl_t *const p_api_ctrl) |
| ssp_err_t | R_AGT_InfoGet (timer_ctrl_t *const p_api_ctrl, timer_info_t *const p_info) |
| Get timer information and store it in provided pointer p_info. Implements timer_api_t::infoGet. More... | |
| ssp_err_t | R_AGT_Stop (timer_ctrl_t *const p_api_ctrl) |
| ssp_err_t | R_AGT_VersionGet (ssp_version_t *const p_version) |
Driver for the Asynchronous General Purpose Timer (AGT).
Extends Timer Interface.
HAL High-Level Driver for accessing and configuring AGT timer modes.
The AGT timer functions are used by the Timer to provide timer services.
| enum agt_count_source_t |
Count source
| Enumerator | |
|---|---|
| AGT_CLOCK_PCLKB | Counter clock source is PCLKB when AGT_CLOCK_PCLKB, AGT_CLOCK_PCLKB_DIV_2, or AGT_CLOCK_PCLKB_DIV_8 is selected. The PCLKB divisor is selected automatically at runtime to the optimal value of PCLKB/1, PCLKB/2, or PCLKB/8. If the timer_cfg_t::unit is TIMER_UNIT_PERIOD_RAW_COUNTS, the timer_cfg_t::period should be the desired value in PCLKB counts, even if the value would exceed 16 bits. For example, if a period of 0x30000 counts is requested, a divisor of PCLKB/8 is be selected and the counter underflows after 0x6000 counts. |
| AGT_CLOCK_PCLKB_DIV_8 | Superseded: See AGT_CLOCK_PCLKB. |
| AGT_CLOCK_PCLKB_DIV_2 | Superseded: See AGT_CLOCK_PCLKB. |
| AGT_CLOCK_LOCO | Divided clock LOCO specified y bits CKS[2:0] in the AGTMR2 register. |
| AGT_CLOCK_AGT0_UNDERFLOW | Underflow event signal from AGT0. |
| AGT_CLOCK_FSUB | Divided clock fSUB specified by bits CKS[2:0] in the AGTMR2 register. |
| ssp_err_t R_AGT_Close | ( | timer_ctrl_t *const | p_api_ctrl | ) |
Stops counter, disables interrupts, disables output pins, and clears internal driver data. Implements timer_api_t::close.
| SSP_SUCCESS | The AGT Timer channel is successfully closed. |
| SSP_ERR_ASSERTION | The parameter p_ctrl is NULL. |
| SSP_ERR_NOT_OPEN | The AGT channel is not opened. |
Cleanup the device: Stop counter, disable interrupts, and power down if no other channels are in use.
Clear the TOE (output enable) bit
Clear the TEDGSEL bit
Unlock channel
| ssp_err_t R_AGT_CounterGet | ( | timer_ctrl_t *const | p_api_ctrl, |
| timer_size_t *const | p_value | ||
| ) |
Retrieve and store counter value in provided p_value pointer. Implements timer_api_t::counterGet.
| SSP_SUCCESS | Counter value read, p_value is valid. |
| SSP_ERR_ASSERTION | The p_ctrl or p_value parameter was null |
| SSP_ERR_NOT_OPEN | The channel is not opened. |
Read counter value
Increment retrieved counter value by one, as counter counts till zero
| ssp_err_t R_AGT_DutyCycleSet | ( | timer_ctrl_t *const | p_api_ctrl, |
| timer_size_t const | duty_cycle, | ||
| timer_pwm_unit_t const | unit, | ||
| uint8_t const | pin | ||
| ) |
Setting duty cycle is not supported by this driver. Implements timer_api_t::dutyCycleSet.
| SSP_SUCCESS | Once duty cycle set successfully. |
| SSP_ERR_INVALID_ARGUMENT | If any of the argument is invalid |
| SSP_ERR_NOT_OPEN | The channel is not opened. |
Set duty cycle.
| ssp_err_t R_AGT_InfoGet | ( | timer_ctrl_t *const | p_api_ctrl, |
| timer_info_t *const | p_info | ||
| ) |
Get timer information and store it in provided pointer p_info. Implements timer_api_t::infoGet.
| SSP_SUCCESS | Period, status, count direction, frequency value written to caller's structure successfully. |
| SSP_ERR_ASSERTION | The p_ctrl or p_period_counts parameter was null. |
| SSP_ERR_NOT_OPEN | The channel is not opened. |
| SSP_ERR_INVALID_HW_CONDITION | Invalid hardware setting is detected. |
Get and store period
Get and store clock frequency
AGT supports only counting down direction
| ssp_err_t R_AGT_PeriodSet | ( | timer_ctrl_t *const | p_api_ctrl, |
| timer_size_t const | period, | ||
| timer_unit_t const | unit | ||
| ) |
Sets period value provided. Implements timer_api_t::periodSet.
| SSP_SUCCESS | Period value written successfully. |
| SSP_ERR_ASSERTION | The p_ctrl parameter was null. |
| SSP_ERR_INVALID_ARG | One of the following is invalid:
|
| SSP_ERR_NOT_OPEN | The channel is not opened. |
Make sure period is valid, then set period
| ssp_err_t R_AGT_Reset | ( | timer_ctrl_t *const | p_api_ctrl | ) |
Resets the counter value to the period that was originally set. Implements timer_api_t::reset.
| SSP_SUCCESS | Counter value written successfully. |
| SSP_ERR_ASSERTION | The p_ctrl parameter was null. |
| SSP_ERR_NOT_OPEN | The channel is not opened. |
Save running status for restart, if already running.
Set AGT counter for given period value.
Restart the AGT channel if it was running.
| ssp_err_t R_AGT_Start | ( | timer_ctrl_t *const | p_api_ctrl | ) |
Starts timer. Implements timer_api_t::start.
| SSP_SUCCESS | Timer successfully started. |
| SSP_ERR_ASSERTION | The p_ctrl parameter is null. |
| SSP_ERR_NOT_OPEN | The channel is not opened. |
Start timer
| ssp_err_t R_AGT_Stop | ( | timer_ctrl_t *const | p_api_ctrl | ) |
Stops the AGT channel specified by the handle (control block). This API implements timer_api_t::stop. This API does not reset the channel or power it down.
| SSP_SUCCESS | Timer successfully stopped. |
| SSP_ERR_ASSERTION | The p_ctrl parameter was null. |
| SSP_ERR_NOT_OPEN | The channel is not opened. |
| ssp_err_t R_AGT_TimerOpen | ( | timer_ctrl_t *const | p_api_ctrl, |
| timer_cfg_t const *const | p_cfg | ||
| ) |
Open the AGT channel as a timer, handles required initialization described in hardware manual. Implements timer_api_t::open.
The Timer Open function configures a single AGT channel for timer mode with parameters specified in the timer Configuration structure. It also sets up the control block for use with subsequent AGT Timer APIs.
This function must be called once prior to calling any other AGT API functions. After a channel is opened, the Open function should not be called again for the same channel without first calling the associated Close function.
The AGT hardware does not support one-shot functionality natively. The one-shot feature is therefore implemented in the AGT HAL layer. For a timer configured as a one-shot timer, the timer is stopped upon the first timer expiration.
The AGT implementation of the general timer can accept an optional timer_on_agt_cfg_t extension parameter. For AGT, 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 PCLKB is used and the output pins are disabled.
The clock divider is selected based on the source clock frequency and the timer period supplied by the caller.
| SSP_SUCCESS | Initialization was successful and timer has started. |
| SSP_ERR_ASSERTION | One of the following parameters may be NULL: p_cfg, p_ctrl, or the configuration channel ID exceeds AGT_MAX_CH, or the configuration mode is invalid. |
| SSP_ERR_IN_USE | The channel specified has already been opened. |
| SSP_ERR_IRQ_BSP_DISABLED | A required interrupt has not been enabled in the BSP. |
Check agt count source to throw an error.
Verify channel is not already used
Power on the AGT channel.
Wait for counter to stop.
Clear AGTO output
Clear TEDGSEL bit to normal output.
Set the AGT mode based on agt_mode value.
Make sure period is valid, then set period
Start the timer if requested by user
All done.
| ssp_err_t R_AGT_VersionGet | ( | ssp_version_t *const | p_version | ) |
Sets driver version based on compile time macros. Implements timer_api_t::versionGet.
| SSP_SUCCESS | Successful close. |
| SSP_ERR_ASSERTION | The parameter p_version is NULL. |