Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches

Interfaces for counters. More...

Topics

 Counter Driver Backend API
 Counter capture APIs
 Counter capture APIs.
 Device-specific Counter API extensions
 Devicetree Counter Captures API
 Emulated counter
 Emulated counter backend API.

Files

file  counter.h
 Main header file for counter driver API.
file  counter-capture.h
 Counter capture flags for use in devicetree.

Data Structures

struct  counter_capture_dt_spec
 Container for counter capture information specified in devicetree. More...
struct  counter_alarm_cfg
 Alarm callback structure. More...
struct  counter_top_cfg
 Top value configuration structure. More...
struct  counter_config_info
 Structure with generic counter features. More...
struct  counter_alarm_cfg_64
 Alarm callback structure. More...
struct  counter_top_cfg_64
 Top value configuration structure. More...

Typedefs

typedef void(* counter_capture_cb_t) (const struct device *dev, uint8_t chan_id, counter_capture_flags_t flags, uint32_t ticks, void *user_data)
 Counter capture callback.
typedef void(* counter_alarm_callback_t) (const struct device *dev, uint8_t chan_id, uint32_t ticks, void *user_data)
 Alarm callback.
typedef void(* counter_top_callback_t) (const struct device *dev, void *user_data)
 Callback called when counter turns around.
typedef void(* counter_alarm_callback_64_t) (const struct device *dev, uint8_t chan_id, uint64_t ticks, void *user_data)
 Alarm callback.
typedef void(* counter_capture_cb_64_t) (const struct device *dev, uint8_t chan_id, counter_capture_flags_t flags, uint64_t ticks, void *user_data)
 Counter capture callback for 64 bits ticks.

Functions

bool counter_is_counting_up (const struct device *dev)
 Function to check if counter is counting up.
uint8_t counter_get_num_of_channels (const struct device *dev)
 Function to get number of alarm channels.
uint32_t counter_get_frequency (const struct device *dev)
uint64_t counter_get_frequency_64 (const struct device *dev)
 Function to get counter frequency in 64bits.
uint32_t counter_us_to_ticks (const struct device *dev, uint64_t us)
 Function to convert microseconds to ticks.
uint64_t counter_us_to_ticks_64 (const struct device *dev, uint64_t us)
 Function to convert microseconds to ticks with 64 bits.
uint64_t counter_ticks_to_us (const struct device *dev, uint32_t ticks)
 Function to convert ticks to microseconds.
uint64_t counter_ticks_to_us_64 (const struct device *dev, uint64_t ticks)
 Function to convert ticks with 64 bits to microseconds.
uint32_t counter_ns_to_ticks (const struct device *dev, uint64_t ns)
 Function to convert nanoseconds to ticks.
uint64_t counter_ns_to_ticks_64 (const struct device *dev, uint64_t ns)
 Function to convert nanoseconds to ticks with 64 bits.
uint64_t counter_ticks_to_ns (const struct device *dev, uint32_t ticks)
 Function to convert ticks to nanoseconds.
uint64_t counter_ticks_to_ns_64 (const struct device *dev, uint64_t ticks)
 Function to convert ticks with 64 bits to nanoseconds.
uint32_t counter_get_max_top_value (const struct device *dev)
 Function to retrieve maximum top value that can be set.
int counter_start (const struct device *dev)
 Start counter device in free running mode.
int counter_stop (const struct device *dev)
 Stop counter device.
int counter_get_value (const struct device *dev, uint32_t *ticks)
 Get current counter value.
int counter_reset (const struct device *dev)
 Reset the counter to the initial value.
int counter_set_value (const struct device *dev, uint32_t ticks)
 Set current counter value.
int counter_set_channel_alarm (const struct device *dev, uint8_t chan_id, const struct counter_alarm_cfg *alarm_cfg)
 Set a single shot alarm on a channel.
int counter_cancel_channel_alarm (const struct device *dev, uint8_t chan_id)
 Cancel an alarm on a channel.
int counter_set_top_value (const struct device *dev, const struct counter_top_cfg *cfg)
 Set counter top value.
uint32_t counter_get_pending_int (const struct device *dev)
 Function to get pending interrupts.
uint32_t counter_get_top_value (const struct device *dev)
 Function to retrieve current top value.
int counter_set_guard_period (const struct device *dev, uint32_t ticks, uint32_t flags)
 Set guard period in counter ticks.
uint32_t counter_get_guard_period (const struct device *dev, uint32_t flags)
 Return guard period.
uint64_t counter_get_max_top_value_64 (const struct device *dev)
 Function to retrieve maximum top value that can be set for 64 bits.
int counter_set_top_value_64 (const struct device *dev, const struct counter_top_cfg_64 *cfg)
 Set counter top value for 64 bits.
int counter_set_channel_alarm_64 (const struct device *dev, uint8_t chan_id, const struct counter_alarm_cfg_64 *alarm_cfg)
 Set a single shot alarm on a channel for 64 bits.
uint64_t counter_get_top_value_64 (const struct device *dev)
 Function to retrieve current top value for 64 bits.
int counter_set_guard_period_64 (const struct device *dev, uint64_t ticks, uint32_t flags)
 Set guard period in counter ticks for 64 bits.
uint64_t counter_get_guard_period_64 (const struct device *dev, uint32_t flags)
 Return guard period for 64 bits.
int counter_get_value_64 (const struct device *dev, uint64_t *ticks)
 Get current counter 64-bit value.
int counter_set_value_64 (const struct device *dev, uint64_t ticks)
 Set current counter 64-bit value.
int counter_set_calibration (const struct device *dev, int32_t calibration)
 Set counter calibration value.
int counter_get_calibration (const struct device *dev, int32_t *calibration)
 Get counter calibration value.

Counter capture flags

Used by counter_capture_configure.

typedef uint32_t counter_capture_flags_t
 Provides a type to hold Counter Capture configuration flags.
#define COUNTER_CAPTURE_CONTINUOUS   0
 Capture an event continuously until stopped.
#define COUNTER_CAPTURE_SINGLE_SHOT   BIT(2)
 Capture a single event.
#define COUNTER_CAPTURE_DT_SPEC_GET_BY_NAME(node_id, prop, name)
 Static initializer for a struct counter_capture_dt_spec.
#define COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_NAME(inst, prop, name)
 Static initializer for a struct counter_capture_dt_spec from a DT_DRV_COMPAT instance.
#define COUNTER_CAPTURE_DT_SPEC_GET_BY_NAME_OR(node_id, prop, name, default_value)
 Like COUNTER_CAPTURE_DT_SPEC_GET_BY_NAME(), with a fallback to a default value.
#define COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_NAME_OR(inst, prop, name, default_value)
 Like COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_NAME(), with a fallback to a default value.
#define COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX(node_id, prop, idx)
 Static initializer for a struct counter_capture_dt_spec.
#define COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_IDX(inst, prop, idx)
 Static initializer for a struct counter_capture_dt_spec from a DT_DRV_COMPAT instance.
#define COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX_OR(node_id, prop, idx, default_value)
 Like COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX(), with a fallback to a default value.
#define COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, idx, default_value)
 Like COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_IDX(), with a fallback to a default value.
#define COUNTER_CAPTURE_DT_SPEC_GET(node_id, prop)
 Equivalent to COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX(node_id, 0).
#define COUNTER_CAPTURE_DT_SPEC_INST_GET(inst, prop)
 Equivalent to COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_IDX(inst, 0).
#define COUNTER_CAPTURE_DT_SPEC_GET_OR(node_id, prop, default_value)
 Equivalent to COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX_OR(node_id, 0, default_value).
#define COUNTER_CAPTURE_DT_SPEC_INST_GET_OR(inst, prop, default_value)
 Equivalent to COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_IDX_OR(inst, 0, default_value).

Counter device capabilities

#define COUNTER_CONFIG_INFO_COUNT_UP   BIT(0)
 Counter count up flag.

Flags used by counter_top_cfg.

#define COUNTER_TOP_CFG_DONT_RESET   BIT(0)
 Flag preventing counter reset when top value is changed.
#define COUNTER_TOP_CFG_RESET_WHEN_LATE   BIT(1)
 Flag instructing counter to reset itself if changing top value results in counter going out of new top value bound.

Alarm configuration flags

Used in alarm configuration structure (counter_alarm_cfg).

#define COUNTER_ALARM_CFG_ABSOLUTE   BIT(0)
 Counter alarm absolute value flag.
#define COUNTER_ALARM_CFG_EXPIRE_WHEN_LATE   BIT(1)
 Alarm flag enabling immediate expiration when driver detects that absolute alarm was set too late.

Counter guard period flags

Used by counter_set_guard_period and counter_get_guard_period.

#define COUNTER_GUARD_PERIOD_LATE_TO_SET   BIT(0)
 Identifies guard period needed for detection of late setting of absolute alarm (see counter_set_channel_alarm).

Counter capture flags

The COUNTER_CAPTURE_* flags are used to configure capture edge selection with counter_capture_configure().

The flags are on the lower 8bits of the counter_capture_flags_t.

#define COUNTER_CAPTURE_RISING_EDGE   (1U << 0)
 Capture on rising edge.
#define COUNTER_CAPTURE_FALLING_EDGE   (1U << 1)
 Capture on falling edge.
#define COUNTER_CAPTURE_BOTH_EDGES   (COUNTER_CAPTURE_RISING_EDGE | COUNTER_CAPTURE_FALLING_EDGE)
 Capture on both rising and falling edges.

Detailed Description

Interfaces for counters.

Since
1.14
Version
1.1.0

Macro Definition Documentation

◆ COUNTER_ALARM_CFG_ABSOLUTE

#define COUNTER_ALARM_CFG_ABSOLUTE   BIT(0)

#include <zephyr/drivers/counter.h>

Counter alarm absolute value flag.

Ticks relation to counter value. If set ticks are treated as absolute value, else it is relative to the counter reading performed during the call.

◆ COUNTER_ALARM_CFG_EXPIRE_WHEN_LATE

#define COUNTER_ALARM_CFG_EXPIRE_WHEN_LATE   BIT(1)

#include <zephyr/drivers/counter.h>

Alarm flag enabling immediate expiration when driver detects that absolute alarm was set too late.

Alarm callback must be called from the same context as if it was set on time.

◆ COUNTER_CAPTURE_BOTH_EDGES

#define COUNTER_CAPTURE_BOTH_EDGES   (COUNTER_CAPTURE_RISING_EDGE | COUNTER_CAPTURE_FALLING_EDGE)

#include <zephyr/dt-bindings/counter/counter-capture.h>

Capture on both rising and falling edges.

◆ COUNTER_CAPTURE_CONTINUOUS

#define COUNTER_CAPTURE_CONTINUOUS   0

#include <zephyr/drivers/counter.h>

Capture an event continuously until stopped.

◆ COUNTER_CAPTURE_DT_SPEC_GET

#define COUNTER_CAPTURE_DT_SPEC_GET ( node_id,
prop )

#include <zephyr/drivers/counter.h>

Value:
#define COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX(node_id, prop, idx)
Static initializer for a struct counter_capture_dt_spec.
Definition counter.h:336

Equivalent to COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX(node_id, 0).

Parameters
node_idDevicetree node identifier.
proplowercase-and-underscores property name
Returns
Static initializer for a struct counter_capture_dt_spec for the property.
See also
COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX
COUNTER_CAPTURE_DT_SPEC_INST_GET

◆ COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX

#define COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX ( node_id,
prop,
idx )

#include <zephyr/drivers/counter.h>

Value:
{ \
.dev = DEVICE_DT_GET(DT_COUNTER_CAPTURES_CTLR_BY_IDX(node_id, prop, idx)), \
.chan_id = (uint8_t)DT_COUNTER_CAPTURES_CHANNEL_BY_IDX(node_id, prop, idx), \
.flags = DT_COUNTER_CAPTURES_FLAGS_BY_IDX(node_id, prop, idx), \
}
#define DEVICE_DT_GET(node_id)
Get a device reference from a devicetree node identifier.
Definition device.h:317
#define DT_COUNTER_CAPTURES_FLAGS_BY_IDX(node_id, counter_capture_pha, idx)
Get a counter capture specifier's flags cell value at an index.
Definition counter-capture.h:282
#define DT_COUNTER_CAPTURES_CTLR_BY_IDX(node_id, counter_capture_pha, idx)
Get the node identifier for the counter controller from a counter-captures property at an index.
Definition counter-capture.h:56
#define DT_COUNTER_CAPTURES_CHANNEL_BY_IDX(node_id, counter_capture_pha, idx)
Get a counter capture specifier's channel cell value at an index.
Definition counter-capture.h:229
__UINT8_TYPE__ uint8_t
Definition stdint.h:88

Static initializer for a struct counter_capture_dt_spec.

This returns a static initializer for a struct counter_capture_dt_spec given a devicetree node identifier and an index.

Example devicetree fragment:

n: node {
counter-captures = <&counter1 1 COUNTER_CAPTURE_RISING_EDGE>,
<&counter2 3 COUNTER_CAPTURE_BOTH_EDGES>;
};

Example usage:

const struct counter_capture_dt_spec spec =
// Initializes 'spec' to:
// {
// .dev = DEVICE_DT_GET(DT_NODELABEL(counter2)),
// .chan_id = 3,
// .flags = COUNTER_CAPTURE_BOTH_EDGES,
// }
#define DT_NODELABEL(label)
Get a node identifier for a node label.
Definition devicetree.h:197
Container for counter capture information specified in devicetree.
Definition counter.h:171

The device (dev) must still be checked for readiness, e.g. using device_is_ready(). It is an error to use this macro unless the node exists, has the 'counter-captures' property, and that 'counter-captures' property specifies a counter controller, a channel and optionally flags.

Parameters
node_idDevicetree node identifier.
proplowercase-and-underscores property name
idxLogical index into 'counter-captures' property.
Returns
Static initializer for a struct counter_capture_dt_spec for the property.
See also
COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_IDX

◆ COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX_OR

#define COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX_OR ( node_id,
prop,
idx,
default_value )

#include <zephyr/drivers/counter.h>

Value:
COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
(COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX(node_id, prop, idx)), \
(default_value))
#define DT_NODE_HAS_PROP(node_id, prop)
Does a devicetree node have a property?
Definition devicetree.h:4080
#define COND_CODE_1(_flag, _if_1_code, _else_code)
Insert code depending on whether _flag expands to 1 or not.
Definition util_macro.h:209

Like COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX(), with a fallback to a default value.

If the devicetree node identifier 'node_id' refers to a node with a property 'counter-captures', this expands to COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX(node_id, idx). The default_value parameter is not expanded in this case. Otherwise, this expands to default_value.

Parameters
node_idDevicetree node identifier.
proplowercase-and-underscores property name
idxLogical index into 'counter-captures' property.
default_valueFallback value to expand to.
Returns
Static initializer for a struct counter_capture_dt_spec for the property, or default_value if the node or property do not exist.
See also
COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_IDX_OR

◆ COUNTER_CAPTURE_DT_SPEC_GET_BY_NAME

#define COUNTER_CAPTURE_DT_SPEC_GET_BY_NAME ( node_id,
prop,
name )

#include <zephyr/drivers/counter.h>

Value:
{ \
.dev = DEVICE_DT_GET(DT_COUNTER_CAPTURES_CTLR_BY_NAME(node_id, prop, name)), \
.chan_id = (uint8_t)DT_COUNTER_CAPTURES_CHANNEL_BY_NAME(node_id, prop, name), \
.flags = DT_COUNTER_CAPTURES_FLAGS_BY_NAME(node_id, prop, name), \
}
#define DT_COUNTER_CAPTURES_CTLR_BY_NAME(node_id, counter_capture_pha, name)
Get the node identifier for the counter controller from a counter-captures property by name.
Definition counter-capture.h:90
#define DT_COUNTER_CAPTURES_FLAGS_BY_NAME(node_id, counter_capture_pha, name)
Get a counter capture specifier's flags cell value by name.
Definition counter-capture.h:307
#define DT_COUNTER_CAPTURES_CHANNEL_BY_NAME(node_id, counter_capture_pha, name)
Get a counter capture specifier's channel cell value by name.
Definition counter-capture.h:250

Static initializer for a struct counter_capture_dt_spec.

This returns a static initializer for a struct counter_capture_dt_spec given a devicetree node identifier and a name.

Example devicetree fragment:

n: node {
counter-captures = <&counter1 1 COUNTER_CAPTURE_RISING_EDGE>,
<&counter2 3 COUNTER_CAPTURE_BOTH_EDGES>;
counter-capture-names = "alpha", "beta";
};

Example usage:

const struct counter_capture_dt_spec spec =
COUNTER_CAPTURE_DT_SPEC_GET_BY_NAME(DT_NODELABEL(n), counter_captures, alpha);
// Initializes 'spec' to:
// {
// .dev = DEVICE_DT_GET(DT_NODELABEL(counter1)),
// .chan_id = 1,
// .flags = COUNTER_CAPTURE_RISING_EDGE,
// }
#define COUNTER_CAPTURE_DT_SPEC_GET_BY_NAME(node_id, prop, name)
Static initializer for a struct counter_capture_dt_spec.
Definition counter.h:225

The device (dev) must still be checked for readiness, e.g. using device_is_ready(). It is an error to use this macro unless the node exists, has the 'counter-captures' property, and that 'counter-captures' property specifies a counter controller, a channel and optionally flags.

Parameters
node_idDevicetree node identifier.
proplowercase-and-underscores property name
nameLowercase-and-underscores name of a counter-captures element as defined by the node's counter-capture-names property.
Returns
Static initializer for a struct counter_capture_dt_spec for the property.
See also
COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_NAME

◆ COUNTER_CAPTURE_DT_SPEC_GET_BY_NAME_OR

#define COUNTER_CAPTURE_DT_SPEC_GET_BY_NAME_OR ( node_id,
prop,
name,
default_value )

#include <zephyr/drivers/counter.h>

Value:
COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
(COUNTER_CAPTURE_DT_SPEC_GET_BY_NAME(node_id, prop, name)), \
(default_value))

Like COUNTER_CAPTURE_DT_SPEC_GET_BY_NAME(), with a fallback to a default value.

If the devicetree node identifier 'node_id' refers to a node with a property 'counter-captures', this expands to COUNTER_CAPTURE_DT_SPEC_GET_BY_NAME(node_id, prop, name). The default_value parameter is not expanded in this case. Otherwise, this expands to default_value.

Parameters
node_idDevicetree node identifier.
proplowercase-and-underscores property name
nameLowercase-and-underscores name of a counter-captures element as defined by the node's counter-capture-names property.
default_valueFallback value to expand to.
Returns
Static initializer for a struct counter_capture_dt_spec for the property, or default_value if the node or property do not exist.
See also
COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_NAME_OR

◆ COUNTER_CAPTURE_DT_SPEC_GET_OR

#define COUNTER_CAPTURE_DT_SPEC_GET_OR ( node_id,
prop,
default_value )

#include <zephyr/drivers/counter.h>

Value:
COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX_OR(node_id, prop, 0, default_value)
#define COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX_OR(node_id, prop, idx, default_value)
Like COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX(), with a fallback to a default value.
Definition counter.h:379

Equivalent to COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX_OR(node_id, 0, default_value).

Parameters
node_idDevicetree node identifier.
proplowercase-and-underscores property name
default_valueFallback value to expand to.
Returns
Static initializer for a struct counter_capture_dt_spec for the property.
See also
COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX_OR
COUNTER_CAPTURE_DT_SPEC_INST_GET_OR

◆ COUNTER_CAPTURE_DT_SPEC_INST_GET

#define COUNTER_CAPTURE_DT_SPEC_INST_GET ( inst,
prop )

#include <zephyr/drivers/counter.h>

Value:
#define COUNTER_CAPTURE_DT_SPEC_GET(node_id, prop)
Equivalent to COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX(node_id, 0).
Definition counter.h:413
#define DT_DRV_INST(inst)
Node identifier for an instance of a DT_DRV_COMPAT compatible.
Definition devicetree.h:4333

Equivalent to COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_IDX(inst, 0).

Parameters
instDT_DRV_COMPAT instance number
proplowercase-and-underscores property name
Returns
Static initializer for a struct counter_capture_dt_spec for the property.
See also
COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_IDX
COUNTER_CAPTURE_DT_SPEC_GET

◆ COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_IDX

#define COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_IDX ( inst,
prop,
idx )

#include <zephyr/drivers/counter.h>

Value:

Static initializer for a struct counter_capture_dt_spec from a DT_DRV_COMPAT instance.

Parameters
instDT_DRV_COMPAT instance number
proplowercase-and-underscores property name
idxLogical index into 'counter-captures' property.
Returns
Static initializer for a struct counter_capture_dt_spec for the property.
See also
COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX

◆ COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_IDX_OR

#define COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_IDX_OR ( inst,
prop,
idx,
default_value )

#include <zephyr/drivers/counter.h>

Value:
COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX_OR(DT_DRV_INST(inst), prop, idx, default_value)

Like COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_IDX(), with a fallback to a default value.

Parameters
instDT_DRV_COMPAT instance number
proplowercase-and-underscores property name
idxLogical index into 'counter-captures' property.
default_valueFallback value to expand to.
Returns
Static initializer for a struct counter_capture_dt_spec for the property, or default_value if the node or property do not exist.
See also
COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX_OR

◆ COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_NAME

#define COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_NAME ( inst,
prop,
name )

#include <zephyr/drivers/counter.h>

Value:

Static initializer for a struct counter_capture_dt_spec from a DT_DRV_COMPAT instance.

Parameters
instDT_DRV_COMPAT instance number
proplowercase-and-underscores property name
nameLowercase-and-underscores name of a counter-captures element as defined by the node's counter-capture-names property.
Returns
Static initializer for a struct counter_capture_dt_spec for the property.
See also
COUNTER_CAPTURE_DT_SPEC_GET_BY_NAME

◆ COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_NAME_OR

#define COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_NAME_OR ( inst,
prop,
name,
default_value )

#include <zephyr/drivers/counter.h>

Value:
COUNTER_CAPTURE_DT_SPEC_GET_BY_NAME_OR(DT_DRV_INST(inst), prop, name, default_value)
#define COUNTER_CAPTURE_DT_SPEC_GET_BY_NAME_OR(node_id, prop, name, default_value)
Like COUNTER_CAPTURE_DT_SPEC_GET_BY_NAME(), with a fallback to a default value.
Definition counter.h:270

Like COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_NAME(), with a fallback to a default value.

Parameters
instDT_DRV_COMPAT instance number
proplowercase-and-underscores property name
nameLowercase-and-underscores name of a counter-captures element as defined by the node's counter-capture-names property.
default_valueFallback value to expand to.
Returns
Static initializer for a struct counter_capture_dt_spec for the property, or default_value if the node or property do not exist.
See also
COUNTER_CAPTURE_DT_SPEC_GET_BY_NAME_OR

◆ COUNTER_CAPTURE_DT_SPEC_INST_GET_OR

#define COUNTER_CAPTURE_DT_SPEC_INST_GET_OR ( inst,
prop,
default_value )

#include <zephyr/drivers/counter.h>

Value:
COUNTER_CAPTURE_DT_SPEC_GET_OR(DT_DRV_INST(inst), prop, default_value)
#define COUNTER_CAPTURE_DT_SPEC_GET_OR(node_id, prop, default_value)
Equivalent to COUNTER_CAPTURE_DT_SPEC_GET_BY_IDX_OR(node_id, 0, default_value).
Definition counter.h:445

Equivalent to COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_IDX_OR(inst, 0, default_value).

Parameters
instDT_DRV_COMPAT instance number
proplowercase-and-underscores property name
default_valueFallback value to expand to.
Returns
Static initializer for a struct counter_capture_dt_spec for the property.
See also
COUNTER_CAPTURE_DT_SPEC_INST_GET_BY_IDX_OR
COUNTER_CAPTURE_DT_SPEC_GET_OR

◆ COUNTER_CAPTURE_FALLING_EDGE

#define COUNTER_CAPTURE_FALLING_EDGE   (1U << 1)

#include <zephyr/dt-bindings/counter/counter-capture.h>

Capture on falling edge.

◆ COUNTER_CAPTURE_RISING_EDGE

#define COUNTER_CAPTURE_RISING_EDGE   (1U << 0)

#include <zephyr/dt-bindings/counter/counter-capture.h>

Capture on rising edge.

◆ COUNTER_CAPTURE_SINGLE_SHOT

#define COUNTER_CAPTURE_SINGLE_SHOT   BIT(2)

#include <zephyr/drivers/counter.h>

Capture a single event.

◆ COUNTER_CONFIG_INFO_COUNT_UP

#define COUNTER_CONFIG_INFO_COUNT_UP   BIT(0)

#include <zephyr/drivers/counter.h>

Counter count up flag.

◆ COUNTER_GUARD_PERIOD_LATE_TO_SET

#define COUNTER_GUARD_PERIOD_LATE_TO_SET   BIT(0)

#include <zephyr/drivers/counter.h>

Identifies guard period needed for detection of late setting of absolute alarm (see counter_set_channel_alarm).

◆ COUNTER_TOP_CFG_DONT_RESET

#define COUNTER_TOP_CFG_DONT_RESET   BIT(0)

#include <zephyr/drivers/counter.h>

Flag preventing counter reset when top value is changed.

If flags is set then counter is free running while top value is updated, otherwise counter is reset (see counter_set_top_value()).

◆ COUNTER_TOP_CFG_RESET_WHEN_LATE

#define COUNTER_TOP_CFG_RESET_WHEN_LATE   BIT(1)

#include <zephyr/drivers/counter.h>

Flag instructing counter to reset itself if changing top value results in counter going out of new top value bound.

See COUNTER_TOP_CFG_DONT_RESET.

Typedef Documentation

◆ counter_alarm_callback_64_t

typedef void(* counter_alarm_callback_64_t) (const struct device *dev, uint8_t chan_id, uint64_t ticks, void *user_data)

#include <zephyr/drivers/counter.h>

Alarm callback.

Parameters
devPointer to the device structure for the driver instance.
chan_idChannel ID.
ticksCounter value that triggered the alarm.
user_dataUser data.

◆ counter_alarm_callback_t

typedef void(* counter_alarm_callback_t) (const struct device *dev, uint8_t chan_id, uint32_t ticks, void *user_data)

#include <zephyr/drivers/counter.h>

Alarm callback.

Parameters
devPointer to the device structure for the driver instance.
chan_idChannel ID.
ticksCounter value that triggered the alarm.
user_dataUser data.

◆ counter_capture_cb_64_t

typedef void(* counter_capture_cb_64_t) (const struct device *dev, uint8_t chan_id, counter_capture_flags_t flags, uint64_t ticks, void *user_data)

#include <zephyr/drivers/counter.h>

Counter capture callback for 64 bits ticks.

Parameters
devPointer to the device structure for the driver instance
chan_idChannel ID
flagsConfiguration flags (COUNTER_CAPTURE_FLAGS)
ticksCounter value that triggered the capture in 64 bits
user_dataUser data

◆ counter_capture_cb_t

typedef void(* counter_capture_cb_t) (const struct device *dev, uint8_t chan_id, counter_capture_flags_t flags, uint32_t ticks, void *user_data)

#include <zephyr/drivers/counter.h>

Counter capture callback.

Parameters
devPointer to the device structure for the driver instance
chan_idChannel ID
flagsConfiguration flags (COUNTER_CAPTURE_FLAGS)
ticksCounter value that triggered the capture
user_dataUser data

◆ counter_capture_flags_t

#include <zephyr/drivers/counter.h>

Provides a type to hold Counter Capture configuration flags.

The lower 8 bits are used for standard flags. The upper 24 bits are reserved for SoC specific flags.

See also
COUNTER_CAPTURE_FLAGS.

◆ counter_top_callback_t

typedef void(* counter_top_callback_t) (const struct device *dev, void *user_data)

#include <zephyr/drivers/counter.h>

Callback called when counter turns around.

Parameters
devPointer to the device structure for the driver instance.
user_dataUser data provided in counter_set_top_value.

Function Documentation

◆ counter_cancel_channel_alarm()

int counter_cancel_channel_alarm ( const struct device * dev,
uint8_t chan_id )

#include <zephyr/drivers/counter.h>

Cancel an alarm on a channel.

Note
API is not thread safe.
Parameters
devPointer to the device structure for the driver instance.
chan_idChannel ID.
Return values
0on success.
-ENOTSUPRequest is not supported or the counter was not started yet.

◆ counter_get_calibration()

int counter_get_calibration ( const struct device * dev,
int32_t * calibration )

#include <zephyr/drivers/counter.h>

Get counter calibration value.

Parameters
devPointer to the device structure for the driver instance.
calibrationPointer to store the calibration value in ppb.
Return values
0If successful.
-ENOSYSif not supported by the driver.

◆ counter_get_frequency()

uint32_t counter_get_frequency ( const struct device * dev)

◆ counter_get_frequency_64()

uint64_t counter_get_frequency_64 ( const struct device * dev)

#include <zephyr/drivers/counter.h>

Function to get counter frequency in 64bits.

Parameters
[in]devPointer to the device structure for the driver instance.
Returns
Frequency of the counter in Hz, or zero if the counter does not have a fixed frequency.

◆ counter_get_guard_period()

uint32_t counter_get_guard_period ( const struct device * dev,
uint32_t flags )

#include <zephyr/drivers/counter.h>

Return guard period.

See also
counter_set_guard_period.
Parameters
devPointer to the device structure for the driver instance.
flagsSee COUNTER_GUARD_PERIOD_FLAGS.
Returns
Guard period given in counter ticks or 0 if function or flags are not supported.

◆ counter_get_guard_period_64()

uint64_t counter_get_guard_period_64 ( const struct device * dev,
uint32_t flags )

#include <zephyr/drivers/counter.h>

Return guard period for 64 bits.

See also
counter_set_guard_period_64.
Parameters
devPointer to the device structure for the driver instance.
flagsSee COUNTER_GUARD_PERIOD_FLAGS.
Returns
Guard period given in counter ticks or 0 if function or flags are not supported.

◆ counter_get_max_top_value()

uint32_t counter_get_max_top_value ( const struct device * dev)

#include <zephyr/drivers/counter.h>

Function to retrieve maximum top value that can be set.

Parameters
[in]devPointer to the device structure for the driver instance.
Warning
With CONFIG_COUNTER_64BITS_TICKS enabled this function returns only the lower 32 bits of the max top value. Use counter_get_max_top_value_64() to get the full 64 bit value if it is expected to exceed 32 bits.
Returns
Max top value.

◆ counter_get_max_top_value_64()

uint64_t counter_get_max_top_value_64 ( const struct device * dev)

#include <zephyr/drivers/counter.h>

Function to retrieve maximum top value that can be set for 64 bits.

Parameters
[in]devPointer to the device structure for the driver instance.
Returns
Max top value in 64 bits.

◆ counter_get_num_of_channels()

uint8_t counter_get_num_of_channels ( const struct device * dev)

#include <zephyr/drivers/counter.h>

Function to get number of alarm channels.

Parameters
[in]devPointer to the device structure for the driver instance.
Returns
Number of alarm channels.

◆ counter_get_pending_int()

uint32_t counter_get_pending_int ( const struct device * dev)

#include <zephyr/drivers/counter.h>

Function to get pending interrupts.

The purpose of this function is to return the interrupt status register for the device. This is especially useful when waking up from low power states to check the wake up source.

Parameters
devPointer to the device structure for the driver instance.
Return values
1if any counter interrupt is pending.
0if no counter interrupt is pending.

◆ counter_get_top_value()

uint32_t counter_get_top_value ( const struct device * dev)

#include <zephyr/drivers/counter.h>

Function to retrieve current top value.

Parameters
[in]devPointer to the device structure for the driver instance.
Returns
Top value.

◆ counter_get_top_value_64()

uint64_t counter_get_top_value_64 ( const struct device * dev)

#include <zephyr/drivers/counter.h>

Function to retrieve current top value for 64 bits.

Parameters
[in]devPointer to the device structure for the driver instance.
Returns
Top value in 64 bits.

◆ counter_get_value()

int counter_get_value ( const struct device * dev,
uint32_t * ticks )

#include <zephyr/drivers/counter.h>

Get current counter value.

Parameters
devPointer to the device structure for the driver instance.
ticksPointer to where to store the current counter value
Returns
0 on success, negative errno value on failure.

◆ counter_get_value_64()

int counter_get_value_64 ( const struct device * dev,
uint64_t * ticks )

#include <zephyr/drivers/counter.h>

Get current counter 64-bit value.

Parameters
devPointer to the device structure for the driver instance.
ticksPointer to where to store the current counter value in 64 bits.
Returns
0 on success, negative errno value on failure.

◆ counter_is_counting_up()

bool counter_is_counting_up ( const struct device * dev)

#include <zephyr/drivers/counter.h>

Function to check if counter is counting up.

Parameters
[in]devPointer to the device structure for the driver instance.
Return values
trueif counter is counting up.
falseif counter is counting down.

◆ counter_ns_to_ticks()

uint32_t counter_ns_to_ticks ( const struct device * dev,
uint64_t ns )

#include <zephyr/drivers/counter.h>

Function to convert nanoseconds to ticks.

Parameters
[in]devPointer to the device structure for the driver instance.
[in]nsNanoseconds.
Returns
Converted ticks. Ticks will be saturated if exceed 32 bits.

◆ counter_ns_to_ticks_64()

uint64_t counter_ns_to_ticks_64 ( const struct device * dev,
uint64_t ns )

#include <zephyr/drivers/counter.h>

Function to convert nanoseconds to ticks with 64 bits.

Parameters
[in]devPointer to the device structure for the driver instance.
[in]nsNanoseconds.
Returns
Converted ticks as a uint64_t.

◆ counter_reset()

int counter_reset ( const struct device * dev)

#include <zephyr/drivers/counter.h>

Reset the counter to the initial value.

Parameters
devPointer to the device structure for the driver instance.
Returns
0 on success, negative errno value on failure.

◆ counter_set_calibration()

int counter_set_calibration ( const struct device * dev,
int32_t calibration )

#include <zephyr/drivers/counter.h>

Set counter calibration value.

Calibration is specified in parts per billion (ppb). A positive value speeds up the counter, a negative value slows it down.

Parameters
devPointer to the device structure for the driver instance.
calibrationCalibration value in ppb.
Return values
0If successful.
-EINVALif calibration value is out of range.
-ENOSYSif not supported by the driver.

◆ counter_set_channel_alarm()

int counter_set_channel_alarm ( const struct device * dev,
uint8_t chan_id,
const struct counter_alarm_cfg * alarm_cfg )

#include <zephyr/drivers/counter.h>

Set a single shot alarm on a channel.

After expiration alarm can be set again, disabling is not needed. When alarm expiration handler is called, channel is considered available and can be set again in that context.

Note
API is not thread safe.
Parameters
devPointer to the device structure for the driver instance.
chan_idChannel ID.
alarm_cfgAlarm configuration.
Return values
0on success.
-ENOTSUPRequest is not supported (device does not support interrupts or requested channel).
-EINVALAlarm settings are invalid.
-ETIMEAbsolute alarm was set too late.
-EBUSYAlarm is already active.

◆ counter_set_channel_alarm_64()

int counter_set_channel_alarm_64 ( const struct device * dev,
uint8_t chan_id,
const struct counter_alarm_cfg_64 * alarm_cfg )

#include <zephyr/drivers/counter.h>

Set a single shot alarm on a channel for 64 bits.

After expiration alarm can be set again, disabling is not needed. When alarm expiration handler is called, channel is considered available and can be set again in that context.

Note
API is not thread safe.
Parameters
devPointer to the device structure for the driver instance.
chan_idChannel ID.
alarm_cfgAlarm configuration.
Return values
0on success.
-ENOTSUPRequest is not supported (device does not support interrupts or requested channel).
-EINVALAlarm settings are invalid.
-ETIMEAbsolute alarm was set too late.
-EBUSYAlarm is already active.

◆ counter_set_guard_period()

int counter_set_guard_period ( const struct device * dev,
uint32_t ticks,
uint32_t flags )

#include <zephyr/drivers/counter.h>

Set guard period in counter ticks.

When setting an absolute alarm value close to the current counter value there is a risk that the counter will have counted past the given absolute value before the driver manages to activate the alarm. If this would go unnoticed then the alarm would only expire after the timer has wrapped and reached the given absolute value again after a full timer period. This could take a long time in case of a 32 bit timer. Setting a sufficiently large guard period will help the driver detect unambiguously whether it is late or not.

The guard period should be as many counter ticks as the driver will need at most to actually activate the alarm after the driver API has been called. If the driver finds that the counter has just passed beyond the given absolute tick value but is still close enough to fall within the guard period, it will assume that it is "late", i.e. that the intended expiry time has already passed. Depending on the COUNTER_ALARM_CFG_EXPIRE_WHEN_LATE flag the driver will either ignore the alarm or expire it immediately in such a case.

If, however, the counter is past the given absolute tick value but outside the guard period, then the driver will assume that this is intentional and let the counter wrap around to/from zero before it expires.

More precisely:

  • When counting upwards (see COUNTER_CONFIG_INFO_COUNT_UP), an alarm is rejected as "late" if the counter has advanced past the given absolute tick value by fewer than guard_period ticks: (now - target) % top_value < guard_period. Otherwise the alarm is accepted (target is still in the future, or far enough in the past to be considered an intentional future wrap).
  • When counting downwards, an alarm is "late" if: (target - now) % top_value < guard_period. Otherwise the alarm is accepted.

Examples:

  • counting upwards, now = 4950, top value = 5000, guard period = 100: late zone: (4950 - target) % 5000 < 100, i.e. target in [4851, 4950] accepted: target in [0, 4850] or [4951, 4999]
  • counting downwards, now = 50, top value = 5000, guard period = 100: late zone: (target - 50) % 5000 < 100, i.e. target in [50, 149] accepted: target in [0, 49] or [150, 4999]

If you need only short alarm periods, you can set the guard period very high (e.g. half of the counter top value) which will make it highly unlikely that the counter will ever unintentionally wrap.

The guard period is set to 0 on initialization (no protection).

Parameters
devPointer to the device structure for the driver instance.
ticksGuard period in counter ticks.
flagsSee COUNTER_GUARD_PERIOD_FLAGS.
Return values
0on success.
-ENOSYSFunction or flags are not supported.
-EINVALTicks value is invalid.

◆ counter_set_guard_period_64()

int counter_set_guard_period_64 ( const struct device * dev,
uint64_t ticks,
uint32_t flags )

#include <zephyr/drivers/counter.h>

Set guard period in counter ticks for 64 bits.

When setting an absolute alarm value close to the current counter value there is a risk that the counter will have counted past the given absolute value before the driver manages to activate the alarm. If this would go unnoticed then the alarm would only expire after the timer has wrapped and reached the given absolute value again after a full timer period. This could take a long time in case of a 32 bit timer. Setting a sufficiently large guard period will help the driver detect unambiguously whether it is late or not.

The guard period should be as many counter ticks as the driver will need at most to actually activate the alarm after the driver API has been called. If the driver finds that the counter has just passed beyond the given absolute tick value but is still close enough to fall within the guard period, it will assume that it is "late", i.e. that the intended expiry time has already passed. Depending on the COUNTER_ALARM_CFG_EXPIRE_WHEN_LATE flag the driver will either ignore the alarm or expire it immediately in such a case.

If, however, the counter is past the given absolute tick value but outside the guard period, then the driver will assume that this is intentional and let the counter wrap around to/from zero before it expires.

More precisely:

  • When counting upwards (see COUNTER_CONFIG_INFO_COUNT_UP), an alarm is rejected as "late" if the counter has advanced past the given absolute tick value by fewer than guard_period ticks: (now - target) % top_value < guard_period. Otherwise the alarm is accepted (target is still in the future, or far enough in the past to be considered an intentional future wrap).
  • When counting downwards, an alarm is "late" if: (target - now) % top_value < guard_period. Otherwise the alarm is accepted.

Examples:

  • counting upwards, now = 4950, top value = 5000, guard period = 100: late zone: (4950 - target) % 5000 < 100, i.e. target in [4851, 4950] accepted: target in [0, 4850] or [4951, 4999]
  • counting downwards, now = 50, top value = 5000, guard period = 100: late zone: (target - 50) % 5000 < 100, i.e. target in [50, 149] accepted: target in [0, 49] or [150, 4999]

If you need only short alarm periods, you can set the guard period very high (e.g. half of the counter top value) which will make it highly unlikely that the counter will ever unintentionally wrap.

The guard period is set to 0 on initialization (no protection).

Parameters
devPointer to the device structure for the driver instance.
ticksGuard period in counter ticks of 64 bits.
flagsSee COUNTER_GUARD_PERIOD_FLAGS.
Return values
0on success.
-ENOSYSFunction or flags are not supported.
-EINVALTicks value is invalid.

◆ counter_set_top_value()

int counter_set_top_value ( const struct device * dev,
const struct counter_top_cfg * cfg )

#include <zephyr/drivers/counter.h>

Set counter top value.

Function sets top value and optionally resets the counter to 0 or top value depending on counter direction. On turnaround, counter can be reset and optional callback is periodically called. Top value can only be changed when there is no active channel alarm.

COUNTER_TOP_CFG_DONT_RESET prevents counter reset. When counter is running while top value is updated, it is possible that counter progresses outside the new top value. In that case, error is returned and optionally driver can reset the counter (see COUNTER_TOP_CFG_RESET_WHEN_LATE).

Warning
With CONFIG_COUNTER_64BITS_TICKS enabled this function sets the lower 32 bits of the max top value. Use counter_set_top_value_64() to get the full 64 bit value if it is expected to exceed 32 bits.
Parameters
devPointer to the device structure for the driver instance.
cfgConfiguration. Cannot be NULL.
Return values
0on success.
-ENOTSUPRequest is not supported (e.g. top value cannot be changed or counter cannot/must be reset during top value update).
-EBUSYAny alarm is active.
-ETIMECOUNTER_TOP_CFG_DONT_RESET was set and new top value is smaller than current counter value (counter counting up).

◆ counter_set_top_value_64()

int counter_set_top_value_64 ( const struct device * dev,
const struct counter_top_cfg_64 * cfg )

#include <zephyr/drivers/counter.h>

Set counter top value for 64 bits.

Function sets top value and optionally resets the counter to 0 or top value depending on counter direction. On turnaround, counter can be reset and optional callback is periodically called. Top value can only be changed when there is no active channel alarm.

COUNTER_TOP_CFG_DONT_RESET prevents counter reset. When counter is running while top value is updated, it is possible that counter progresses outside the new top value. In that case, error is returned and optionally driver can reset the counter (see COUNTER_TOP_CFG_RESET_WHEN_LATE).

Parameters
devPointer to the device structure for the driver instance.
cfgConfiguration. Cannot be NULL.
Return values
0on success.
-ENOTSUPRequest is not supported (e.g. top value cannot be changed or counter cannot/must be reset during top value update).
-EBUSYAny alarm is active.
-ETIMECOUNTER_TOP_CFG_DONT_RESET was set and new top value is smaller than current counter value (counter counting up).

◆ counter_set_value()

int counter_set_value ( const struct device * dev,
uint32_t ticks )

#include <zephyr/drivers/counter.h>

Set current counter value.

Parameters
devPointer to the device structure for the driver instance.
ticksTick value to set
Returns
0 on success, negative errno value on failure.

◆ counter_set_value_64()

int counter_set_value_64 ( const struct device * dev,
uint64_t ticks )

#include <zephyr/drivers/counter.h>

Set current counter 64-bit value.

Parameters
devPointer to the device structure for the driver instance.
ticksTick value to set in 64 bits
Returns
0 on success, negative errno value on failure.

◆ counter_start()

int counter_start ( const struct device * dev)

#include <zephyr/drivers/counter.h>

Start counter device in free running mode.

Parameters
devPointer to the device structure for the driver instance.
Returns
0 on success, negative errno value on failure.

◆ counter_stop()

int counter_stop ( const struct device * dev)

#include <zephyr/drivers/counter.h>

Stop counter device.

Parameters
devPointer to the device structure for the driver instance.
Return values
0on success.
-ENOTSUPDevice doesn't support stopping the counter.

◆ counter_ticks_to_ns()

uint64_t counter_ticks_to_ns ( const struct device * dev,
uint32_t ticks )

#include <zephyr/drivers/counter.h>

Function to convert ticks to nanoseconds.

Parameters
[in]devPointer to the device structure for the driver instance.
[in]ticksTicks.
Returns
Converted nanoseconds.

◆ counter_ticks_to_ns_64()

uint64_t counter_ticks_to_ns_64 ( const struct device * dev,
uint64_t ticks )

#include <zephyr/drivers/counter.h>

Function to convert ticks with 64 bits to nanoseconds.

Parameters
[in]devPointer to the device structure for the driver instance.
[in]ticksTicks in 64 bits.
Returns
Converted nanoseconds.

◆ counter_ticks_to_us()

uint64_t counter_ticks_to_us ( const struct device * dev,
uint32_t ticks )

#include <zephyr/drivers/counter.h>

Function to convert ticks to microseconds.

Parameters
[in]devPointer to the device structure for the driver instance.
[in]ticksTicks.
Returns
Converted microseconds.

◆ counter_ticks_to_us_64()

uint64_t counter_ticks_to_us_64 ( const struct device * dev,
uint64_t ticks )

#include <zephyr/drivers/counter.h>

Function to convert ticks with 64 bits to microseconds.

Parameters
[in]devPointer to the device structure for the driver instance.
[in]ticksTicks in 64 bits.
Returns
Converted microseconds.

◆ counter_us_to_ticks()

uint32_t counter_us_to_ticks ( const struct device * dev,
uint64_t us )

#include <zephyr/drivers/counter.h>

Function to convert microseconds to ticks.

Parameters
[in]devPointer to the device structure for the driver instance.
[in]usMicroseconds.
Returns
Converted ticks. Ticks will be saturated if exceed 32 bits.

◆ counter_us_to_ticks_64()

uint64_t counter_us_to_ticks_64 ( const struct device * dev,
uint64_t us )

#include <zephyr/drivers/counter.h>

Function to convert microseconds to ticks with 64 bits.

Parameters
[in]devPointer to the device structure for the driver instance.
[in]usMicroseconds.
Returns
Converted ticks as a uint64_t