HPM SDK
HPMicro Software Development Kit
PTPC driver APIs

PTPC driver. More...

Data Structures

struct  ptpc_config_t
 Timer config. More...
 

Macros

#define PTPC_EVENT_COMPARE0_MASK   PTPC_INT_STS_COMP_INT_STS0_MASK
 
#define PTPC_EVENT_CAPTURE0_MASK   PTPC_INT_STS_CAPTURE_INT_STS0_MASK
 
#define PTPC_EVENT_PPS0_MASK   PTPC_INT_STS_PPS_INT_STS0_MASK
 
#define PTPC_EVENT_COMPARE1_MASK   PTPC_INT_STS_COMP_INT_STS1_MASK
 
#define PTPC_EVENT_CAPTURE1_MASK   PTPC_INT_STS_CAPTURE_INT_STS1_MASK
 
#define PTPC_EVENT_PPS1_MASK   PTPC_INT_STS_PPS_INT_STS1_MASK
 
#define PTPC_MAX_NS_COUNTER   (0x3B9ACA00UL)
 

Typedefs

typedef enum ptpc_ns_counter_rollover_type ptpc_ns_counter_rollover_type_t
 Counter types. More...
 
typedef enum ptpc_capture_trigger_type ptpc_capture_trigger_type_t
 Capture trigger types. More...
 
typedef enum ptpc_counting_mode ptpc_counting_mode
 Capture trigger types. More...
 

Enumerations

enum  ptpc_ns_counter_rollover_type { ptpc_ns_counter_rollover_binary = 0 , ptpc_ns_counter_rollover_digital = 1 }
 Counter types. More...
 
enum  ptpc_capture_trigger_type { ptpc_capture_trigger_none = 0 , ptpc_capture_trigger_on_rising_edge = PTPC_PTPC_CTRL0_CAPT_SNAP_POS_EN_MASK , ptpc_capture_trigger_on_failing_edge = PTPC_PTPC_CTRL0_CAPT_SNAP_NEG_EN_MASK , ptpc_capture_trigger_on_both_edges }
 Capture trigger types. More...
 
enum  ptpc_counting_mode { ptpc_counting_increment = 0 , ptpc_counting_decrement = 1 }
 Capture trigger types. More...
 

Functions

static void ptpc_set_ns_counter_rollover (PTPC_Type *ptr, uint8_t index, ptpc_ns_counter_rollover_type_t rollover)
 Configure ns counter rollover mode. More...
 
static void ptpc_enable_capture_keep (PTPC_Type *ptr, uint8_t index)
 Enable capture keep. More...
 
static void ptpc_disable_capture_keep (PTPC_Type *ptr, uint8_t index)
 Disable capture keep. More...
 
static void ptpc_set_ns_counter_update_type (PTPC_Type *ptr, uint8_t index, bool coarse_update)
 Update ns counter update type. More...
 
static void ptpc_set_ns_counter_step (PTPC_Type *ptr, uint8_t index, uint32_t ns_step)
 Set ns counter increment step. More...
 
static void ptpc_set_second_update (PTPC_Type *ptr, uint8_t index, uint32_t sec)
 Set Second portion update value. More...
 
hpm_stat_t ptpc_set_ns_update (PTPC_Type *ptr, uint8_t index, uint32_t ns, ptpc_counting_mode mode)
 Set ns portion update value. More...
 
static uint32_t ptpc_get_timestamp_second (PTPC_Type *ptr, uint8_t index)
 Get current timestamp Second portion. More...
 
static uint32_t ptpc_get_timestamp_ns (PTPC_Type *ptr, uint8_t index)
 Get timestamp ns portion. More...
 
static void ptpc_config_compare (PTPC_Type *ptr, uint8_t index, uint32_t sec, uint32_t ns)
 Config compare. More...
 
static void ptpc_update_timestamp_second (PTPC_Type *ptr, uint8_t index, uint32_t sec)
 Update Second portion. More...
 
static void ptpc_update_timestamp_ns (PTPC_Type *ptr, uint8_t index, uint32_t ns, ptpc_counting_mode mode)
 Update Ns portion. More...
 
static void ptpc_enable_timer (PTPC_Type *ptr, uint8_t index)
 Enable timer. More...
 
static void ptpc_disable_timer (PTPC_Type *ptr, uint8_t index)
 Disable timer. More...
 
static void ptpc_config_capture (PTPC_Type *ptr, uint8_t index, ptpc_capture_trigger_type_t trigger)
 Config capture trigger event. More...
 
static uint32_t ptpc_get_capture_ns (PTPC_Type *ptr, uint8_t index)
 Get snapped ns value. More...
 
static uint32_t ptpc_get_capture_second (PTPC_Type *ptr, uint8_t index)
 Get captured second. More...
 
static void ptpc_clear_irq_status (PTPC_Type *ptr, uint32_t mask)
 Clear interrupt status. More...
 
static uint32_t ptpc_get_irq_status (PTPC_Type *ptr)
 Get interrupt status. More...
 
static void ptpc_irq_disable (PTPC_Type *ptr, uint32_t mask)
 Disable interrupt with mask. More...
 
static void ptpc_irq_enable (PTPC_Type *ptr, uint32_t mask)
 Enable interrupt with mask. More...
 
hpm_stat_t ptpc_init (PTPC_Type *ptr, uint8_t index, ptpc_config_t *config)
 Initialize PTPC module. More...
 
hpm_stat_t ptpc_set_timer_output (PTPC_Type *ptr, uint8_t can_index, bool use_ptpc1)
 Set PTPC output destination. More...
 
void ptpc_get_default_config (PTPC_Type *ptr, ptpc_config_t *config)
 Get default config. More...
 
void ptpc_init_timer (PTPC_Type *ptr, uint8_t index)
 Initialize timer to count from 0. More...
 
hpm_stat_t ptpc_init_timer_with_initial (PTPC_Type *ptr, uint8_t index, uint32_t sec, uint32_t ns, ptpc_counting_mode mode)
 Initialize timer with initial values. More...
 
hpm_stat_t ptpc_update_timer (PTPC_Type *ptr, uint8_t index, uint32_t sec, uint32_t ns, ptpc_counting_mode mode)
 Update timestamp counter. More...
 
hpm_stat_t ptpc_set_pps (PTPC_Type *ptr, uint8_t index, uint8_t p)
 Set period of pulse generated per second. More...
 

Detailed Description

PTPC driver.

Macro Definition Documentation

◆ PTPC_EVENT_CAPTURE0_MASK

#define PTPC_EVENT_CAPTURE0_MASK   PTPC_INT_STS_CAPTURE_INT_STS0_MASK

◆ PTPC_EVENT_CAPTURE1_MASK

#define PTPC_EVENT_CAPTURE1_MASK   PTPC_INT_STS_CAPTURE_INT_STS1_MASK

◆ PTPC_EVENT_COMPARE0_MASK

#define PTPC_EVENT_COMPARE0_MASK   PTPC_INT_STS_COMP_INT_STS0_MASK

◆ PTPC_EVENT_COMPARE1_MASK

#define PTPC_EVENT_COMPARE1_MASK   PTPC_INT_STS_COMP_INT_STS1_MASK

◆ PTPC_EVENT_PPS0_MASK

#define PTPC_EVENT_PPS0_MASK   PTPC_INT_STS_PPS_INT_STS0_MASK

◆ PTPC_EVENT_PPS1_MASK

#define PTPC_EVENT_PPS1_MASK   PTPC_INT_STS_PPS_INT_STS1_MASK

◆ PTPC_MAX_NS_COUNTER

#define PTPC_MAX_NS_COUNTER   (0x3B9ACA00UL)

Typedef Documentation

◆ ptpc_capture_trigger_type_t

◆ ptpc_counting_mode

#include <drivers/inc/hpm_ptpc_drv.h>

Capture trigger types.

◆ ptpc_ns_counter_rollover_type_t

Enumeration Type Documentation

◆ ptpc_capture_trigger_type

#include <drivers/inc/hpm_ptpc_drv.h>

Capture trigger types.

Enumerator
ptpc_capture_trigger_none 
ptpc_capture_trigger_on_rising_edge 
ptpc_capture_trigger_on_failing_edge 
ptpc_capture_trigger_on_both_edges 

◆ ptpc_counting_mode

#include <drivers/inc/hpm_ptpc_drv.h>

Capture trigger types.

Enumerator
ptpc_counting_increment 

Increment the counter

ptpc_counting_decrement 

Decrement the counter

◆ ptpc_ns_counter_rollover_type

#include <drivers/inc/hpm_ptpc_drv.h>

Counter types.

Enumerator
ptpc_ns_counter_rollover_binary 

binary mode, resolution ~0.466ns, overflow at 0x7FFFFFFF

ptpc_ns_counter_rollover_digital 

digital mode, resolution 1ns, overflow at 0x3B9ACA00

Function Documentation

◆ ptpc_clear_irq_status()

static void ptpc_clear_irq_status ( PTPC_Type ptr,
uint32_t  mask 
)
inlinestatic

#include <drivers/inc/hpm_ptpc_drv.h>

Clear interrupt status.

Parameters
[in]ptrPTPC base address
[in]maskMask of interrupts to be cleared

◆ ptpc_config_capture()

static void ptpc_config_capture ( PTPC_Type ptr,
uint8_t  index,
ptpc_capture_trigger_type_t  trigger 
)
inlinestatic

#include <drivers/inc/hpm_ptpc_drv.h>

Config capture trigger event.

Parameters
[in]ptrPTPC base address
[in]indexTarget index
[in]triggerCapture trigger type

◆ ptpc_config_compare()

static void ptpc_config_compare ( PTPC_Type ptr,
uint8_t  index,
uint32_t  sec,
uint32_t  ns 
)
inlinestatic

#include <drivers/inc/hpm_ptpc_drv.h>

Config compare.

Parameters
[in]ptrPTPC base address
[in]indexTarget index
[in]secTarget second
[in]nsTarget ns

◆ ptpc_disable_capture_keep()

static void ptpc_disable_capture_keep ( PTPC_Type ptr,
uint8_t  index 
)
inlinestatic

#include <drivers/inc/hpm_ptpc_drv.h>

Disable capture keep.

Parameters
[in]ptrPTPC base address
[in]indexTarget index

◆ ptpc_disable_timer()

static void ptpc_disable_timer ( PTPC_Type ptr,
uint8_t  index 
)
inlinestatic

#include <drivers/inc/hpm_ptpc_drv.h>

Disable timer.

Parameters
[in]ptrPTPC base address
[in]indexTarget index

◆ ptpc_enable_capture_keep()

static void ptpc_enable_capture_keep ( PTPC_Type ptr,
uint8_t  index 
)
inlinestatic

#include <drivers/inc/hpm_ptpc_drv.h>

Enable capture keep.

Parameters
[in]ptrPTPC base address
[in]indexTarget index

◆ ptpc_enable_timer()

static void ptpc_enable_timer ( PTPC_Type ptr,
uint8_t  index 
)
inlinestatic

#include <drivers/inc/hpm_ptpc_drv.h>

Enable timer.

Parameters
[in]ptrPTPC base address
[in]indexTarget index

◆ ptpc_get_capture_ns()

static uint32_t ptpc_get_capture_ns ( PTPC_Type ptr,
uint8_t  index 
)
inlinestatic

#include <drivers/inc/hpm_ptpc_drv.h>

Get snapped ns value.

Parameters
[in]ptrPTPC base address
[in]indexTarget index
Returns
ns portion on capture

◆ ptpc_get_capture_second()

static uint32_t ptpc_get_capture_second ( PTPC_Type ptr,
uint8_t  index 
)
inlinestatic

#include <drivers/inc/hpm_ptpc_drv.h>

Get captured second.

Parameters
[in]ptrPTPC base address
[in]indexTarget index
Returns
second portion on capture

◆ ptpc_get_default_config()

void ptpc_get_default_config ( PTPC_Type ptr,
ptpc_config_t config 
)

#include <drivers/inc/hpm_ptpc_drv.h>

Get default config.

Parameters
[in]ptrPTPC base address
[out]configPointer of config struct

◆ ptpc_get_irq_status()

static uint32_t ptpc_get_irq_status ( PTPC_Type ptr)
inlinestatic

#include <drivers/inc/hpm_ptpc_drv.h>

Get interrupt status.

Parameters
[in]ptrPTPC base address
Returns
interrupt status mask

◆ ptpc_get_timestamp_ns()

static uint32_t ptpc_get_timestamp_ns ( PTPC_Type ptr,
uint8_t  index 
)
inlinestatic

#include <drivers/inc/hpm_ptpc_drv.h>

Get timestamp ns portion.

Parameters
[in]ptrPTPC base address
[in]indexTarget index
Returns
ns value

◆ ptpc_get_timestamp_second()

static uint32_t ptpc_get_timestamp_second ( PTPC_Type ptr,
uint8_t  index 
)
inlinestatic

#include <drivers/inc/hpm_ptpc_drv.h>

Get current timestamp Second portion.

Parameters
[in]ptrPTPC base address
[in]indexTarget index
Returns
Seconds value

◆ ptpc_init()

hpm_stat_t ptpc_init ( PTPC_Type ptr,
uint8_t  index,
ptpc_config_t config 
)

#include <drivers/inc/hpm_ptpc_drv.h>

Initialize PTPC module.

Parameters
[in]ptrPTPC base address
[in]indexTarget index
[in]configPointer to configuration struct
Returns
status_success if everything is okay

◆ ptpc_init_timer()

void ptpc_init_timer ( PTPC_Type ptr,
uint8_t  index 
)

#include <drivers/inc/hpm_ptpc_drv.h>

Initialize timer to count from 0.

Parameters
[in]ptrPTPC base address
[in]indexTarget index

◆ ptpc_init_timer_with_initial()

hpm_stat_t ptpc_init_timer_with_initial ( PTPC_Type ptr,
uint8_t  index,
uint32_t  sec,
uint32_t  ns,
ptpc_counting_mode  mode 
)

#include <drivers/inc/hpm_ptpc_drv.h>

Initialize timer with initial values.

Parameters
[in]ptrPTPC base address
[in]indexTarget index
[in]secSeconds
[in]nsNs
[in]modeCounting mode
Returns
status_success if everything is okay

◆ ptpc_irq_disable()

static void ptpc_irq_disable ( PTPC_Type ptr,
uint32_t  mask 
)
inlinestatic

#include <drivers/inc/hpm_ptpc_drv.h>

Disable interrupt with mask.

Parameters
[in]ptrPTPC base address
[in]maskMask of interrupts to be disabled

◆ ptpc_irq_enable()

static void ptpc_irq_enable ( PTPC_Type ptr,
uint32_t  mask 
)
inlinestatic

#include <drivers/inc/hpm_ptpc_drv.h>

Enable interrupt with mask.

Parameters
[in]ptrPTPC base address
[in]maskMask of interrupts to be enabled

◆ ptpc_set_ns_counter_rollover()

static void ptpc_set_ns_counter_rollover ( PTPC_Type ptr,
uint8_t  index,
ptpc_ns_counter_rollover_type_t  rollover 
)
inlinestatic

#include <drivers/inc/hpm_ptpc_drv.h>

Configure ns counter rollover mode.

Parameters
[in]ptrPTPC base address
[in]indexIndex of target counter
[in]rolloverRollover type

◆ ptpc_set_ns_counter_step()

static void ptpc_set_ns_counter_step ( PTPC_Type ptr,
uint8_t  index,
uint32_t  ns_step 
)
inlinestatic

#include <drivers/inc/hpm_ptpc_drv.h>

Set ns counter increment step.

Parameters
[in]ptrPTPC base address
[in]indexTarget index
[in]ns_stepIncrement step

◆ ptpc_set_ns_counter_update_type()

static void ptpc_set_ns_counter_update_type ( PTPC_Type ptr,
uint8_t  index,
bool  coarse_update 
)
inlinestatic

#include <drivers/inc/hpm_ptpc_drv.h>

Update ns counter update type.

Parameters
[in]ptrPTPC base address
[in]indexIndex of target counter
[in]coarse_updateCounter will be increment by 1 on

◆ ptpc_set_ns_update()

hpm_stat_t ptpc_set_ns_update ( PTPC_Type ptr,
uint8_t  index,
uint32_t  ns,
ptpc_counting_mode  mode 
)

#include <drivers/inc/hpm_ptpc_drv.h>

Set ns portion update value.

Parameters
[in]ptrPTPC base address
[in]indexTarget index
[in]nsNs value (31 bits, 0x3B9ACA00 max)
[in]modeCounting mode
Returns
status_success if everything is okay

◆ ptpc_set_pps()

hpm_stat_t ptpc_set_pps ( PTPC_Type ptr,
uint8_t  index,
uint8_t  p 
)

#include <drivers/inc/hpm_ptpc_drv.h>

Set period of pulse generated per second.

Parameters
[in]ptrPTPC base address
[in]indexTarget index
[in]p(2^power Hz, from [0 - 15])
Returns
true if requested frequency can be set
false if requested frequency can not be set

◆ ptpc_set_second_update()

static void ptpc_set_second_update ( PTPC_Type ptr,
uint8_t  index,
uint32_t  sec 
)
inlinestatic

#include <drivers/inc/hpm_ptpc_drv.h>

Set Second portion update value.

Parameters
[in]ptrPTPC base address
[in]indexTarget index
[in]secSecond value

◆ ptpc_set_timer_output()

hpm_stat_t ptpc_set_timer_output ( PTPC_Type ptr,
uint8_t  can_index,
bool  use_ptpc1 
)

#include <drivers/inc/hpm_ptpc_drv.h>

Set PTPC output destination.

Parameters
[in]ptrPTPC base address
[in]can_indexTarget CAN instance
[in]use_ptpc1Use PTPC1 if set to true, otherwise PTPC0
Returns
status_success if everything is okay

◆ ptpc_update_timer()

hpm_stat_t ptpc_update_timer ( PTPC_Type ptr,
uint8_t  index,
uint32_t  sec,
uint32_t  ns,
ptpc_counting_mode  mode 
)

#include <drivers/inc/hpm_ptpc_drv.h>

Update timestamp counter.

Parameters
[in]ptrPTPC base address
[in]indexTarget index
[in]secSeconds
[in]nsNs
[in]modeCounting mode
Returns
status_success if everything is okay

◆ ptpc_update_timestamp_ns()

static void ptpc_update_timestamp_ns ( PTPC_Type ptr,
uint8_t  index,
uint32_t  ns,
ptpc_counting_mode  mode 
)
inlinestatic

#include <drivers/inc/hpm_ptpc_drv.h>

Update Ns portion.

Parameters
[in]ptrPTPC base address
[in]indexTarget index
[in]nsTarget ns
[in]modeCounting mode

◆ ptpc_update_timestamp_second()

static void ptpc_update_timestamp_second ( PTPC_Type ptr,
uint8_t  index,
uint32_t  sec 
)
inlinestatic

#include <drivers/inc/hpm_ptpc_drv.h>

Update Second portion.

Parameters
[in]ptrPTPC base address
[in]indexTarget index
[in]secTarget second