RA Flexible Software Package Documentation  Release v6.1.0

 
Ethernet Generic PTP Timer (r_gptp)

Functions

fsp_err_t R_GPTP_Open (gptp_ctrl_t *const p_ctrl, gptp_cfg_t const *const p_cfg)
 
fsp_err_t R_GPTP_Close (gptp_ctrl_t *const p_ctrl)
 
fsp_err_t R_GPTP_TimerCfg (gptp_ctrl_t *const p_ctrl, uint8_t timer, gptp_timer_cfg_t const *const p_timer_cfg)
 
fsp_err_t R_GPTP_Start (gptp_ctrl_t *const p_ctrl, uint8_t timer)
 
fsp_err_t R_GPTP_Stop (gptp_ctrl_t *const p_ctrl, uint8_t timer)
 
fsp_err_t R_GPTP_TimerValueGet (gptp_ctrl_t *const p_ctrl, uint8_t timer, gptp_timer_value_t *const p_timer_value)
 
fsp_err_t R_GPTP_TimerOffsetSet (gptp_ctrl_t *const p_ctrl, uint8_t timer, int64_t offset)
 
fsp_err_t R_GPTP_TimerRateSet (gptp_ctrl_t *const p_ctrl, uint8_t timer, uint32_t rate)
 
fsp_err_t R_GPTP_PulseGeneratorSet (gptp_ctrl_t *const p_ctrl, uint8_t timer, gptp_pulse_generator_t *p_pulse)
 
fsp_err_t R_GPTP_CallbackSet (gptp_ctrl_t *const p_ctrl, void(*p_callback)(gptp_callback_args_t *), void *const p_context, gptp_callback_args_t *const p_callback_memory)
 

Detailed Description

Driver for the Ethernet peripheral on RA MCUs. This module implements the GPTP Interface.

Overview

Ethernet Generic PTP timer (GPTP) enables accurate synchronization of the clock in the control system.

This module supports two GPTP timer.

Features

The GPTP module has the following features:

Configuration

Build Time Configurations for r_gptp

The following build time configurations are defined in fsp_cfg/r_gptp_cfg.h:

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.

Configurations for Networking > Ethernet Generic PTP Timer (r_gptp)

This module can be added to the Stacks tab via New Stack > Networking > Ethernet Generic PTP Timer (r_gptp). Non-secure callable guard functions can be generated for this module by right clicking the module in the RA Configuration tool and checking the "Non-secure Callable" box.

ConfigurationOptionsDefaultDescription
General
NameName must be a valid C symbolg_gptp0 Module name.
CallbackName must be a valid C symbolNULL Callback provided when an ISR occurs

Clock Configuration

The GPTP clock is based on the ESWCLK frequency. You can set the PTPTIVCt (t = 0 or 1) register to timer increment value according to ESWCLK frequency.

Usage Notes

Examples

This is a basic example of minimal use of the GPTP in an application.

void gptp_basic_example (void)
{
fsp_err_t err = FSP_SUCCESS;
uint8_t timer = GPTP_EXAMPLE_TIMER_NUMBER;
gptp_timer_cfg_t timer_cfg = {.clock_period = GPTP_EXAMPLE_CLOCK_PERIOD};
int64_t offset = GPTP_EXAMPLE_OFFSET;
uint32_t rate = GPTP_EXAMPLE_RATE;
gptp_timer_value_t timer_value =
{
.time_sec_lower = 0,
.time_nsec = 0,
};
gptp_pulsed_output_cfg_t pulsed_output_cfg0 =
{
.pulse_num = 0,
.start_sec_upper = 0,
.start_sec_lower = 0,
.start_ns = 0,
.wide = 0,
.period_sec_upper = 0,
.period_sec_lower = 0,
.period_ns = 0,
};
gptp_pulsed_output_cfg_t pulsed_output_cfg1 =
{
.pulse_num = 1,
.start_sec_upper = 0,
.start_sec_lower = 0,
.start_ns = 0,
.wide = 0,
.period_sec_upper = 0,
.period_sec_lower = 0,
.period_ns = 0,
};
gptp_pulsed_output_cfg_t pulsed_output_cfg2 =
{
.pulse_num = 2,
.start_sec_upper = 0,
.start_sec_lower = 0,
.start_ns = 0,
.wide = 0,
.period_sec_upper = 0,
.period_sec_lower = 0,
.period_ns = 0,
};
gptp_pulsed_output_cfg_t pulsed_output_cfg3 =
{
.pulse_num = 3,
.start_sec_upper = 0,
.start_sec_lower = 0,
.start_ns = 0,
.wide = 0,
.period_sec_upper = 0,
.period_sec_lower = 0,
.period_ns = 0,
};
gptp_pulse_generator_t pulse_generator =
{
{&pulsed_output_cfg0, &pulsed_output_cfg1, &pulsed_output_cfg2, &pulsed_output_cfg3},
};
/* Open the gptp instance with initial configuration. */
err = R_GPTP_Open(&g_gptp0_ctrl, &g_gptp0_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
/* Set configuration of gptp timer. */
err = R_GPTP_TimerCfg(&g_gptp0_ctrl, timer, &timer_cfg);
assert(FSP_SUCCESS == err);
/* Start gptp timer. */
err = R_GPTP_Start(&g_gptp0_ctrl, timer);
assert(FSP_SUCCESS == err);
/* Get value of gptp timer. */
err = R_GPTP_TimerValueGet(&g_gptp0_ctrl, timer, &timer_value);
assert(FSP_SUCCESS == err);
/* Set offset of gptp timer. */
err = R_GPTP_TimerOffsetSet(&g_gptp0_ctrl, timer, offset);
assert(FSP_SUCCESS == err);
/* Set rate of gptp timer. */
err = R_GPTP_TimerRateSet(&g_gptp0_ctrl, timer, rate);
assert(FSP_SUCCESS == err);
/* Set pulse generator of gptp timer. */
err = R_GPTP_PulseGeneratorSet(&g_gptp0_ctrl, timer, &pulse_generator);
assert(FSP_SUCCESS == err);
/* Stop gptp timer. */
err = R_GPTP_Stop(&g_gptp0_ctrl, timer);
assert(FSP_SUCCESS == err);
/* Close the gptp instance. */
err = R_GPTP_Close(&g_gptp0_ctrl);
assert(FSP_SUCCESS == err);
}

Data Structures

struct  gptp_pulsed_output_cfg_t
 
struct  gptp_pulse_generator_t
 
struct  gptp_instance_ctrl_t
 

Data Structure Documentation

◆ gptp_pulsed_output_cfg_t

struct gptp_pulsed_output_cfg_t

Pulsed output configuration.

Data Fields
uint8_t pulse_num Pulse generator number.
uint16_t start_sec_upper Pulse start second(upper 16 bit).
uint32_t start_sec_lower Pulse start second(lower 32 bit).
uint32_t start_ns Pulse start nanosecond.
uint16_t wide Pulse width.
uint16_t period_sec_upper Pulse period second(upper 16 bit).
uint32_t period_sec_lower Pulse period second(lower 32 bit).
uint32_t period_ns Pulse period nanosecond.

◆ gptp_pulse_generator_t

struct gptp_pulse_generator_t

Pulse generator.

Data Fields
gptp_pulsed_output_cfg_t * p_pulsed_output_cfg_list[BSP_FEATURE_ESWM_GPTP_PULSE_GENERATOR_NUM] List of pointer to pulsed output configuration.

◆ gptp_instance_ctrl_t

struct gptp_instance_ctrl_t

GPTP control block. DO NOT INITIALIZE. Initialization occurs when gptp_api_t::open is called.

Data Fields

uint32_t open
 Indicates whether the open() API has been successfully called.
 
gptp_cfg_t const * p_cfg
 Pointer to initial configurations.
 
R_GPTP_Type * p_reg_gptp
 Pointer to GPTP timer register.
 
void(* p_callback )(gptp_callback_args_t *)
 Pointer to callback that is called.
 
gptp_callback_args_tp_callback_memory
 Pointer to non-secure memory that can be used to pass arguments to a callback in non-secure memory.
 
void const * p_context
 Pointer to context to be passed into callback function.
 

Function Documentation

◆ R_GPTP_Open()

fsp_err_t R_GPTP_Open ( gptp_ctrl_t *const  p_ctrl,
gptp_cfg_t const *const  p_cfg 
)

Initializes the gptp module and applies configurations.

Return values
FSP_SUCCESSModule opened successfully.
FSP_ERR_ASSERTIONPointer to GPTP control block or configuration structure is NULL.
FSP_ERR_ALREADY_OPENControl block has already been opened or channel is being used by another instance. Call close() then open() to reconfigure.
FSP_ERR_INVALID_POINTERPointer to arguments are NULL.

◆ R_GPTP_Close()

fsp_err_t R_GPTP_Close ( gptp_ctrl_t *const  p_ctrl)

Close the gptp module.

Return values
FSP_SUCCESSSuccessfully closed.
FSP_ERR_ASSERTIONPointer to GPTP control block is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened

◆ R_GPTP_TimerCfg()

fsp_err_t R_GPTP_TimerCfg ( gptp_ctrl_t *const  p_ctrl,
uint8_t  timer,
gptp_timer_cfg_t const *const  p_timer_cfg 
)

Configures the gptp timer parameters.

Return values
FSP_SUCCESSCommand successfully.
FSP_ERR_ASSERTIONPointer to control block is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_INVALID_ARGUMENTInvalid timer id.
FSP_ERR_INVALID_POINTERInvalid poiter to the timer cfg.

◆ R_GPTP_Start()

fsp_err_t R_GPTP_Start ( gptp_ctrl_t *const  p_ctrl,
uint8_t  timer 
)

Starts gptp timer.

Return values
FSP_SUCCESSTimer started..
FSP_ERR_ASSERTIONPointer to control block is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_INVALID_ARGUMENTInvalid timer id.

◆ R_GPTP_Stop()

fsp_err_t R_GPTP_Stop ( gptp_ctrl_t *const  p_ctrl,
uint8_t  timer 
)

Stops gptp timer.

Return values
FSP_SUCCESSTimer stopped.
FSP_ERR_ASSERTIONPointer to control block is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_INVALID_ARGUMENTInvalid timer id.

◆ R_GPTP_TimerValueGet()

fsp_err_t R_GPTP_TimerValueGet ( gptp_ctrl_t *const  p_ctrl,
uint8_t  timer,
gptp_timer_value_t *const  p_timer_value 
)

Gets the current time value to the timer with the specified gptp timer number.

Return values
FSP_SUCCESSSec upper, sec lower, and nano sec srored in p_timestamp.
FSP_ERR_ASSERTIONPointer to control block is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_INVALID_POINTERPointer to arguments are NULL.
FSP_ERR_INVALID_ARGUMENTInvalid input parameter.

◆ R_GPTP_TimerOffsetSet()

fsp_err_t R_GPTP_TimerOffsetSet ( gptp_ctrl_t *const  p_ctrl,
uint8_t  timer,
int64_t  offset 
)

Sets the offset correction for the specified gptp timer number.

Return values
FSP_SUCCESSTime offset set successfully.
FSP_ERR_ASSERTIONPointer to control block is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_INVALID_ARGUMENTInvalid input parameter.

◆ R_GPTP_TimerRateSet()

fsp_err_t R_GPTP_TimerRateSet ( gptp_ctrl_t *const  p_ctrl,
uint8_t  timer,
uint32_t  rate 
)

Sets clock rate correction for the specified timer.

Return values
FSP_SUCCESSTime rate set successfully.
FSP_ERR_ASSERTIONPointer to control block is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_INVALID_POINTERPointer to arguments are NULL.
FSP_ERR_INVALID_ARGUMENTInvalid input parameter.

◆ R_GPTP_PulseGeneratorSet()

fsp_err_t R_GPTP_PulseGeneratorSet ( gptp_ctrl_t *const  p_ctrl,
uint8_t  timer,
gptp_pulse_generator_t p_pulse 
)

Sets pulse generator.

Return values
FSP_SUCCESSPulse generator set successfully.
FSP_ERR_ASSERTIONPointer to control block is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_INVALID_POINTERPointer to arguments are NULL.
FSP_ERR_INVALID_ARGUMENTInvalid input parameter.

◆ R_GPTP_CallbackSet()

fsp_err_t R_GPTP_CallbackSet ( gptp_ctrl_t *const  p_ctrl,
void(*)(gptp_callback_args_t *)  p_callback,
void *const  p_context,
gptp_callback_args_t *const  p_callback_memory 
)

Updates the user callback with the option to provide memory for the callback argument structure. Implements gptp_api_t::callbackSet.

Return values
FSP_SUCCESSCallback updated successfully.
FSP_ERR_ASSERTIONA required pointer is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_NO_CALLBACK_MEMORYp_callback is non-secure and p_callback_memory is either secure or NULL.