Synergy Software Package User's Manual

Driver for the General PWM Timer (GPT). More...

Data Structures

struct  gpt_output_pin_t
 
struct  gpt_instance_ctrl_t
 
struct  timer_on_gpt_cfg_t
 

Enumerations

enum  gpt_pin_level_t { GPT_PIN_LEVEL_LOW = 0, GPT_PIN_LEVEL_HIGH = 1, GPT_PIN_LEVEL_RETAINED = 2 }
 
enum  gpt_shortest_level_t { GPT_SHORTEST_LEVEL_OFF = 0, GPT_SHORTEST_LEVEL_ON = 1 }
 
enum  gpt_trigger_t {
  GPT_TRIGGER_NONE = 0, GPT_TRIGGER_GTIOCA_RISING_WHILE_GTIOCB_LOW = (1UL << 8), GPT_TRIGGER_GTIOCA_RISING_WHILE_GTIOCB_HIGH = (1UL << 9), GPT_TRIGGER_GTIOCA_FALLING_WHILE_GTIOCB_LOW = (1UL << 10),
  GPT_TRIGGER_GTIOCA_FALLING_WHILE_GTIOCB_HIGH = (1UL << 11), GPT_TRIGGER_GTIOCB_RISING_WHILE_GTIOCA_LOW = (1UL << 12), GPT_TRIGGER_GTIOCB_RISING_WHILE_GTIOCA_HIGH = (1UL << 13), GPT_TRIGGER_GTIOCB_FALLING_WHILE_GTIOCA_LOW = (1UL << 14),
  GPT_TRIGGER_GTIOCB_FALLING_WHILE_GTIOCA_HIGH = (1UL << 15), GPT_TRIGGER_SOURCE_REGISTER_ENABLE = (1UL << 31)
}
 
enum  gpt_output_t { GPT_OUTPUT_RETAINED = 0, GPT_OUTPUT_LOW = 1, GPT_OUTPUT_HIGH = 2, GPT_OUTPUT_TOGGLED = 3 }
 

Functions

ssp_err_t R_GPT_TimerOpen (timer_ctrl_t *const p_api_ctrl, timer_cfg_t const *const p_cfg)
 Powers on GPT, handles required initialization described in hardware manual. Implements timer_api_t::open. More...
 
ssp_err_t R_GPT_Stop (timer_ctrl_t *const p_api_ctrl)
 Stops timer. Implements timer_api_t::stop. More...
 
ssp_err_t R_GPT_Start (timer_ctrl_t *const p_api_ctrl)
 Starts timer. Implements timer_api_t::start. More...
 
ssp_err_t R_GPT_CounterGet (timer_ctrl_t *const p_api_ctrl, timer_size_t *const p_value)
 Sets counter value in provided p_value pointer. Implements timer_api_t::counterGet. More...
 
ssp_err_t R_GPT_Reset (timer_ctrl_t *const p_api_ctrl)
 Resets the counter value to 0. Implements timer_api_t::reset. More...
 
ssp_err_t R_GPT_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. More...
 
ssp_err_t R_GPT_DutyCycleSet (timer_ctrl_t *const p_api_ctrl, timer_size_t const duty_cycle, timer_pwm_unit_t const unit, uint8_t const pin)
 Sets status in provided p_status pointer. Implements pwm_api_t::dutyCycleSet. More...
 
ssp_err_t R_GPT_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_GPT_Close (timer_ctrl_t *const p_api_ctrl)
 Stops counter, disables output pins, and clears internal driver data. More...
 
ssp_err_t R_GPT_VersionGet (ssp_version_t *const p_version)
 Sets driver version based on compile time macros. More...
 

Detailed Description

Driver for the General PWM Timer (GPT).

Summary

Extends Timer Interface.

This module implements the Timer Interface using the General PWM Timer (GPT) peripherals GPT32EH, GPT32E, GPT32. It also provides an output compare extension to output the timer signal to the GTIOC pin.

Enumeration Type Documentation

◆ gpt_output_t

Output level used when selecting what happens at compare match or cycle end.

Enumerator
GPT_OUTPUT_RETAINED 

Output retained.

GPT_OUTPUT_LOW 

Output low.

GPT_OUTPUT_HIGH 

Output high.

GPT_OUTPUT_TOGGLED 

Output toggled.

◆ gpt_pin_level_t

Level of GPT pin

Enumerator
GPT_PIN_LEVEL_LOW 

Pin level low.

GPT_PIN_LEVEL_HIGH 

Pin level high.

GPT_PIN_LEVEL_RETAINED 

Pin level retained.

◆ gpt_shortest_level_t

GPT PWM shortest pin level

Enumerator
GPT_SHORTEST_LEVEL_OFF 

1 extra PCLK in ON time. Minimum ON time will be limited to 2 PCLK raw counts.

GPT_SHORTEST_LEVEL_ON 

1 extra PCLK in OFF time. Minimum ON time will be limited to 1 PCLK raw counts.

◆ gpt_trigger_t

Sources can be used to start the timer, stop the timer, count up, or count down.

Enumerator
GPT_TRIGGER_NONE 

No action performed.

GPT_TRIGGER_GTIOCA_RISING_WHILE_GTIOCB_LOW 

Action performed when GTIOCA input rises while GTIOCB is low.

GPT_TRIGGER_GTIOCA_RISING_WHILE_GTIOCB_HIGH 

Action performed when GTIOCA input rises while GTIOCB is high.

GPT_TRIGGER_GTIOCA_FALLING_WHILE_GTIOCB_LOW 

Action performed when GTIOCA input falls while GTIOCB is low.

GPT_TRIGGER_GTIOCA_FALLING_WHILE_GTIOCB_HIGH 

Action performed when GTIOCA input falls while GTIOCB is high.

GPT_TRIGGER_GTIOCB_RISING_WHILE_GTIOCA_LOW 

Action performed when GTIOCB input rises while GTIOCA is low.

GPT_TRIGGER_GTIOCB_RISING_WHILE_GTIOCA_HIGH 

Action performed when GTIOCB input rises while GTIOCA is high.

GPT_TRIGGER_GTIOCB_FALLING_WHILE_GTIOCA_LOW 

Action performed when GTIOCB input falls while GTIOCA is low.

GPT_TRIGGER_GTIOCB_FALLING_WHILE_GTIOCA_HIGH 

Action performed when GTIOCB input falls while GTIOCA is high.

GPT_TRIGGER_SOURCE_REGISTER_ENABLE 

Enables settings in the Source Select Register.

Function Documentation

◆ R_GPT_Close()

ssp_err_t R_GPT_Close ( timer_ctrl_t *const  p_api_ctrl)

Stops counter, disables output pins, and clears internal driver data.

Return values
SSP_SUCCESSSuccessful close.
SSP_ERR_ASSERTIONThe parameter p_ctrl is NULL.
SSP_ERR_NOT_OPENThe channel is not opened.

Cleanup. Stop counter and disable output.

Unlock channel

Clear stored internal driver data

◆ R_GPT_CounterGet()

ssp_err_t R_GPT_CounterGet ( timer_ctrl_t *const  p_api_ctrl,
timer_size_t *const  p_value 
)

Sets counter value in provided p_value pointer. Implements timer_api_t::counterGet.

Return values
SSP_SUCCESSCounter value read, p_value is valid.
SSP_ERR_ASSERTIONThe p_ctrl or p_value parameter was null.
SSP_ERR_NOT_OPENThe channel is not opened.

Read counter value

◆ R_GPT_DutyCycleSet()

ssp_err_t R_GPT_DutyCycleSet ( timer_ctrl_t *const  p_api_ctrl,
timer_size_t const  duty_cycle,
timer_pwm_unit_t const  unit,
uint8_t const  pin 
)

Sets status in provided p_status pointer. Implements pwm_api_t::dutyCycleSet.

Return values
SSP_SUCCESSCounter value written successfully.
SSP_ERR_ASSERTIONThe p_ctrl parameter was null.
SSP_ERR_NOT_OPENThe channel is not opened.
SSP_ERR_INVALID_ARGUMENTThe pin value is out of range; Should be either 0 (for GTIOCA) or 1 (for GTIOCB).

Converted duty cycle to PCLK counts before it can be set in registers

Set duty cycle.

◆ R_GPT_InfoGet()

ssp_err_t R_GPT_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.

Return values
SSP_SUCCESSPeriod, count direction, frequency, and status value written to caller's structure successfully.
SSP_ERR_ASSERTIONThe p_ctrl or p_info parameter was null.
SSP_ERR_NOT_OPENThe channel is not opened.

Get and store period

Get and store clock frequency

Get and store clock counting direction

◆ R_GPT_PeriodSet()

ssp_err_t R_GPT_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.

Return values
SSP_SUCCESSPeriod value written successfully.
SSP_ERR_ASSERTIONThe p_ctrl parameter was null.
SSP_ERR_INVALID_ARGUMENTOne of the following is invalid:
  • p_period->unit: must be one of the options from timer_unit_t
  • p_period->value: must result in a period in the following range:
    • Lower bound: (1 / (PCLK frequency))
    • Upper bound: (0xFFFFFFFF * 1024 / (PCLK frequency))
SSP_ERR_NOT_OPENThe channel is not opened.

Delay must be converted to PCLK counts before it can be set in registers

Make sure period is valid.

Store current status, then stop timer before setting divisor register

Reset counter in case new cycle is less than current count value, then restore state (counting or stopped).

◆ R_GPT_Reset()

ssp_err_t R_GPT_Reset ( timer_ctrl_t *const  p_api_ctrl)

Resets the counter value to 0. Implements timer_api_t::reset.

Return values
SSP_SUCCESSCounter value written successfully.
SSP_ERR_ASSERTIONThe p_ctrl parameter was null.
SSP_ERR_NOT_OPENThe channel is not opened.

Write the counter value

◆ R_GPT_Start()

ssp_err_t R_GPT_Start ( timer_ctrl_t *const  p_api_ctrl)

Starts timer. Implements timer_api_t::start.

Return values
SSP_SUCCESSTimer successfully started.
SSP_ERR_ASSERTIONThe p_ctrl parameter was null.
SSP_ERR_NOT_OPENThe channel is not opened.

Start timer

◆ R_GPT_Stop()

ssp_err_t R_GPT_Stop ( timer_ctrl_t *const  p_api_ctrl)

Stops timer. Implements timer_api_t::stop.

Return values
SSP_SUCCESSTimer successfully stopped.
SSP_ERR_ASSERTIONThe p_ctrl parameter was null.
SSP_ERR_NOT_OPENThe channel is not opened.

Stop timer

◆ R_GPT_TimerOpen()

ssp_err_t R_GPT_TimerOpen ( timer_ctrl_t *const  p_api_ctrl,
timer_cfg_t const *const  p_cfg 
)

Powers on GPT, handles required initialization described in hardware manual. Implements timer_api_t::open.

The Open function configures a single GPT channel, starts the channel, and provides a handle for use with the GPT API Control and Close functions. This function must be called once prior to calling any other GPT 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.

GPT hardware does not support one-shot functionality natively. When using one-shot mode, the timer will be stopped in an ISR after the requested period has elapsed.

The GPT implementation of the general timer can accept a timer_on_gpt_cfg_t extension parameter.

Return values
SSP_SUCCESSInitialization was successful and timer has started.
SSP_ERR_ASSERTIONOne of the following parameters is incorrect. Either
  • p_cfg is NULL, OR
  • p_ctrl is NULL, OR
SSP_ERR_INVALID_ARGUMENTOne of the following parameters is invalid:
  • p_cfg->period: must be in the following range:
    • Lower bound: (1 / (PCLK frequency)
    • Upper bound: (0xFFFFFFFF * 1024 / (PCLK frequency))
  • p_cfg->p_callback not NULL, but ISR is not enabled. ISR must be enabled to use callback function. Enable channel's overflow ISR in bsp_irq_cfg.h.
SSP_ERR_IN_USEThe channel specified has already been opened. No configurations were changed. Call the associated Close function or use associated Control commands to reconfigure the channel.
SSP_ERR_IRQ_BSP_DISABLED- p_cfg->mode is TIMER_MODE_ONE_SHOT, but ISR is not enabled. ISR must be enabled to use one-shot mode.
SSP_ERR_IP_CHANNEL_NOT_PRESENT- The channel requested in the p_cfg parameter is not available on this device.
Note
This function is reentrant for different channels. It is not reentrant for the same channel.

Calculate period and store internal variables

Save the configuration

Calculate duty cycle

Verify channel is not already used

Power on GPT before setting any hardware registers. Make sure the counter is stopped before setting mode register, PCLK divisor register, and counter register.

◆ R_GPT_VersionGet()

ssp_err_t R_GPT_VersionGet ( ssp_version_t *const  p_version)

Sets driver version based on compile time macros.

Return values
SSP_SUCCESSSuccessful close.
SSP_ERR_ASSERTIONThe parameter p_version is NULL.