Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
counter.h File Reference

Public API for counter and timer drivers. More...

#include <zephyr/types.h>
#include <stddef.h>
#include <device.h>
#include <stdbool.h>
#include <syscalls/counter.h>

Go to the source code of this file.

Data Structures

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_driver_api
 

Macros

#define COUNTER_CONFIG_INFO_COUNT_UP   BIT(0)
 Counter count up flag. More...
 
#define COUNTER_TOP_CFG_DONT_RESET   BIT(0)
 Flag preventing counter reset when top value is changed. More...
 
#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. More...
 
#define COUNTER_ALARM_CFG_ABSOLUTE   BIT(0)
 Counter alarm absolute value flag. More...
 
#define COUNTER_ALARM_CFG_EXPIRE_WHEN_LATE   BIT(1)
 Alarm flag enabling immediate expiration when driver detects that absolute alarm was set too late. More...
 
#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). More...
 

Typedefs

typedef void(* counter_alarm_callback_t) (const struct device *dev, uint8_t chan_id, uint32_t ticks, void *user_data)
 Alarm callback. More...
 
typedef void(* counter_top_callback_t) (const struct device *dev, void *user_data)
 Callback called when counter turns around. More...
 
typedef int(* counter_api_start) (const struct device *dev)
 
typedef int(* counter_api_stop) (const struct device *dev)
 
typedef int(* counter_api_get_value) (const struct device *dev, uint32_t *ticks)
 
typedef int(* counter_api_set_alarm) (const struct device *dev, uint8_t chan_id, const struct counter_alarm_cfg *alarm_cfg)
 
typedef int(* counter_api_cancel_alarm) (const struct device *dev, uint8_t chan_id)
 
typedef int(* counter_api_set_top_value) (const struct device *dev, const struct counter_top_cfg *cfg)
 
typedef uint32_t(* counter_api_get_pending_int) (const struct device *dev)
 
typedef uint32_t(* counter_api_get_top_value) (const struct device *dev)
 
typedef uint32_t(* counter_api_get_guard_period) (const struct device *dev, uint32_t flags)
 
typedef int(* counter_api_set_guard_period) (const struct device *dev, uint32_t ticks, uint32_t flags)
 

Functions

bool counter_is_counting_up (const struct device *dev)
 Function to check if counter is counting up. More...
 
uint8_t counter_get_num_of_channels (const struct device *dev)
 Function to get number of alarm channels. More...
 
uint32_t counter_get_frequency (const struct device *dev)
 Function to get counter frequency. More...
 
uint32_t counter_us_to_ticks (const struct device *dev, uint64_t us)
 Function to convert microseconds to ticks. More...
 
uint64_t counter_ticks_to_us (const struct device *dev, uint32_t ticks)
 Function to convert ticks to microseconds. More...
 
uint32_t counter_get_max_top_value (const struct device *dev)
 Function to retrieve maximum top value that can be set. More...
 
int counter_start (const struct device *dev)
 Start counter device in free running mode. More...
 
int counter_stop (const struct device *dev)
 Stop counter device. More...
 
int counter_get_value (const struct device *dev, uint32_t *ticks)
 Get current counter value. More...
 
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. More...
 
int counter_cancel_channel_alarm (const struct device *dev, uint8_t chan_id)
 Cancel an alarm on a channel. More...
 
int counter_set_top_value (const struct device *dev, const struct counter_top_cfg *cfg)
 Set counter top value. More...
 
int counter_get_pending_int (const struct device *dev)
 Function to get pending interrupts. More...
 
uint32_t counter_get_top_value (const struct device *dev)
 Function to retrieve current top value. More...
 
int counter_set_guard_period (const struct device *dev, uint32_t ticks, uint32_t flags)
 Set guard period in counter ticks. More...
 
uint32_t counter_get_guard_period (const struct device *dev, uint32_t flags)
 Return guard period. More...
 

Detailed Description

Public API for counter and timer drivers.