Zephyr API Documentation 4.4.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
counter.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Nordic Semiconductor ASA
3 * Copyright (c) 2016 Intel Corporation
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
13
14#ifndef ZEPHYR_INCLUDE_DRIVERS_COUNTER_H_
15#define ZEPHYR_INCLUDE_DRIVERS_COUNTER_H_
16
25
26#include <errno.h>
27
28#include <zephyr/types.h>
29#include <stddef.h>
30#include <zephyr/device.h>
31#include <zephyr/sys_clock.h>
32#include <stdbool.h>
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
43
47#define COUNTER_CONFIG_INFO_COUNT_UP BIT(0)
48
50
56
63#define COUNTER_TOP_CFG_DONT_RESET BIT(0)
64
71#define COUNTER_TOP_CFG_RESET_WHEN_LATE BIT(1)
72
74
81
88#define COUNTER_ALARM_CFG_ABSOLUTE BIT(0)
89
96#define COUNTER_ALARM_CFG_EXPIRE_WHEN_LATE BIT(1)
97
99
107
112#define COUNTER_GUARD_PERIOD_LATE_TO_SET BIT(0)
113
115
123typedef void (*counter_alarm_callback_t)(const struct device *dev, uint8_t chan_id, uint32_t ticks,
124 void *user_data);
125
159
165typedef void (*counter_top_callback_t)(const struct device *dev, void *user_data);
166
187
194#ifdef CONFIG_COUNTER_64BITS_FREQ
196#else
198#endif
202#ifdef CONFIG_COUNTER_64BITS_TICKS
203 union {
204 uint64_t max_top_value_64;
205 struct {
206#ifdef CONFIG_BIG_ENDIAN
207 uint32_t reserved;
209#else
211 uint32_t reserved;
212#endif /* CONFIG_BIG_ENDIAN */
213 };
214 };
215#else
217#endif /* CONFIG_COUNTER_64BITS_TICKS */
228};
229
237typedef void (*counter_alarm_callback_64_t)(const struct device *dev, uint8_t chan_id,
238 uint64_t ticks, void *user_data);
239
273
294
299
301typedef int (*counter_api_start)(const struct device *dev);
303typedef int (*counter_api_stop)(const struct device *dev);
305typedef int (*counter_api_get_value)(const struct device *dev, uint32_t *ticks);
307typedef int (*counter_api_reset)(const struct device *dev);
309typedef int (*counter_api_set_value)(const struct device *dev, uint32_t ticks);
311typedef int (*counter_api_set_alarm)(const struct device *dev, uint8_t chan_id,
312 const struct counter_alarm_cfg *alarm_cfg);
314typedef int (*counter_api_cancel_alarm)(const struct device *dev, uint8_t chan_id);
316typedef int (*counter_api_set_top_value)(const struct device *dev,
317 const struct counter_top_cfg *cfg);
319typedef uint32_t (*counter_api_get_pending_int)(const struct device *dev);
321typedef uint32_t (*counter_api_get_top_value)(const struct device *dev);
325typedef int (*counter_api_set_guard_period)(const struct device *dev, uint32_t ticks,
328typedef uint32_t (*counter_api_get_freq)(const struct device *dev);
330typedef uint64_t (*counter_api_get_freq_64)(const struct device *dev);
331
333typedef int (*counter_api_get_value_64)(const struct device *dev, uint64_t *ticks);
335typedef int (*counter_api_set_value_64)(const struct device *dev, uint64_t ticks);
337typedef int (*counter_api_set_alarm_64)(const struct device *dev, uint8_t chan_id,
338 const struct counter_alarm_cfg_64 *alarm_cfg);
342typedef int (*counter_api_set_guard_period_64)(const struct device *dev, uint64_t ticks,
345typedef uint64_t (*counter_api_get_top_value_64)(const struct device *dev);
347typedef int (*counter_api_set_top_value_64)(const struct device *dev,
348 const struct counter_top_cfg_64 *cfg);
350typedef bool (*counter_api_is_counting_up)(const struct device *dev);
351
449
452
461__syscall bool counter_is_counting_up(const struct device *dev);
462
463static inline bool z_impl_counter_is_counting_up(const struct device *dev)
464{
465 const struct counter_config_info *config = (const struct counter_config_info *)dev->config;
466 const struct counter_driver_api *api = (struct counter_driver_api *)dev->api;
467
468 return api->is_counting_up ? api->is_counting_up(dev)
469 : config->flags & COUNTER_CONFIG_INFO_COUNT_UP;
470}
471
479__syscall uint8_t counter_get_num_of_channels(const struct device *dev);
480
481static inline uint8_t z_impl_counter_get_num_of_channels(const struct device *dev)
482{
483 const struct counter_config_info *config = (const struct counter_config_info *)dev->config;
484
485 return config->channels;
486}
487
488__syscall uint32_t counter_get_frequency(const struct device *dev);
489
490#ifdef CONFIG_COUNTER_64BITS_FREQ
501static inline uint32_t z_impl_counter_get_frequency(const struct device *dev)
502{
503 const struct counter_config_info *config = (const struct counter_config_info *)dev->config;
504 const struct counter_driver_api *api = (struct counter_driver_api *)dev->api;
505
506 if (api->get_freq) {
507 return api->get_freq(dev);
508 } else {
509 return config->freq > UINT32_MAX ? UINT32_MAX : (uint32_t)config->freq;
510 }
511}
512
513#else
514
523static inline uint32_t z_impl_counter_get_frequency(const struct device *dev)
524{
525 const struct counter_config_info *config = (const struct counter_config_info *)dev->config;
526 const struct counter_driver_api *api = (struct counter_driver_api *)dev->api;
527
528 return api->get_freq ? api->get_freq(dev) : config->freq;
529}
530#endif
531
540__syscall uint64_t counter_get_frequency_64(const struct device *dev);
541
542static inline uint64_t z_impl_counter_get_frequency_64(const struct device *dev)
543{
544#ifdef CONFIG_COUNTER_64BITS_FREQ
545 const struct counter_config_info *config = (const struct counter_config_info *)dev->config;
546 const struct counter_driver_api *api = (struct counter_driver_api *)dev->api;
547
548 if (api->get_freq_64) {
549 return api->get_freq_64(dev);
550 } else if (api->get_freq) {
551 return (uint64_t)api->get_freq(dev);
552 } else {
553 return config->freq;
554 }
555#else
556 ARG_UNUSED(dev);
557 return -ENOTSUP;
558#endif
559}
560
561#ifdef CONFIG_COUNTER_64BITS_FREQ
562#define z_counter_get_frequency z_impl_counter_get_frequency_64
563#else
564#define z_counter_get_frequency z_impl_counter_get_frequency
565#endif
566
575__syscall uint32_t counter_us_to_ticks(const struct device *dev, uint64_t us);
576
577static inline uint32_t z_impl_counter_us_to_ticks(const struct device *dev, uint64_t us)
578{
579 uint64_t ticks = (us * z_counter_get_frequency(dev)) / USEC_PER_SEC;
580
581 return (ticks > (uint64_t)UINT32_MAX) ? UINT32_MAX : ticks;
582}
583
592__syscall uint64_t counter_us_to_ticks_64(const struct device *dev, uint64_t us);
593
594static inline uint64_t z_impl_counter_us_to_ticks_64(const struct device *dev, uint64_t us)
595{
596 return (us * z_counter_get_frequency(dev)) / USEC_PER_SEC;
597}
598
607__syscall uint64_t counter_ticks_to_us(const struct device *dev, uint32_t ticks);
608
609static inline uint64_t z_impl_counter_ticks_to_us(const struct device *dev, uint32_t ticks)
610{
611 return ((uint64_t)ticks * USEC_PER_SEC) / z_counter_get_frequency(dev);
612}
613
622__syscall uint64_t counter_ticks_to_us_64(const struct device *dev, uint64_t ticks);
623
624static inline uint64_t z_impl_counter_ticks_to_us_64(const struct device *dev, uint64_t ticks)
625{
626 return (ticks * USEC_PER_SEC) / z_counter_get_frequency(dev);
627}
628
637__syscall uint32_t counter_ns_to_ticks(const struct device *dev, uint64_t ns);
638
639static inline uint32_t z_impl_counter_ns_to_ticks(const struct device *dev, uint64_t ns)
640{
641 uint64_t ticks = (ns * z_counter_get_frequency(dev)) / NSEC_PER_SEC;
642
643 return (ticks > (uint64_t)UINT32_MAX) ? UINT32_MAX : ticks;
644}
645
654__syscall uint64_t counter_ns_to_ticks_64(const struct device *dev, uint64_t ns);
655
656static inline uint64_t z_impl_counter_ns_to_ticks_64(const struct device *dev, uint64_t ns)
657{
658 return (ns * z_counter_get_frequency(dev)) / NSEC_PER_SEC;
659}
660
669__syscall uint64_t counter_ticks_to_ns(const struct device *dev, uint32_t ticks);
670
671static inline uint64_t z_impl_counter_ticks_to_ns(const struct device *dev, uint32_t ticks)
672{
673 return ((uint64_t)ticks * NSEC_PER_SEC) / z_counter_get_frequency(dev);
674}
675
684__syscall uint64_t counter_ticks_to_ns_64(const struct device *dev, uint64_t ticks);
685
686static inline uint64_t z_impl_counter_ticks_to_ns_64(const struct device *dev, uint64_t ticks)
687{
688 return (ticks * NSEC_PER_SEC) / z_counter_get_frequency(dev);
689}
690
702__syscall uint32_t counter_get_max_top_value(const struct device *dev);
703
704static inline uint32_t z_impl_counter_get_max_top_value(const struct device *dev)
705{
706 const struct counter_config_info *config = (const struct counter_config_info *)dev->config;
707
708 return config->max_top_value;
709}
710
719__syscall int counter_start(const struct device *dev);
720
721static inline int z_impl_counter_start(const struct device *dev)
722{
723 const struct counter_driver_api *api = (struct counter_driver_api *)dev->api;
724
725 return api->start(dev);
726}
727
737__syscall int counter_stop(const struct device *dev);
738
739static inline int z_impl_counter_stop(const struct device *dev)
740{
741 const struct counter_driver_api *api = (struct counter_driver_api *)dev->api;
742
743 return api->stop(dev);
744}
745
754__syscall int counter_get_value(const struct device *dev, uint32_t *ticks);
755
756static inline int z_impl_counter_get_value(const struct device *dev, uint32_t *ticks)
757{
758 const struct counter_driver_api *api = (struct counter_driver_api *)dev->api;
759
760 return api->get_value(dev, ticks);
761}
762
770__syscall int counter_reset(const struct device *dev);
771
772static inline int z_impl_counter_reset(const struct device *dev)
773{
774 const struct counter_driver_api *api = (struct counter_driver_api *)dev->api;
775
776 if (!api->reset) {
777 return -ENOSYS;
778 }
779
780 return api->reset(dev);
781}
782
791__syscall int counter_set_value(const struct device *dev, uint32_t ticks);
792
793static inline int z_impl_counter_set_value(const struct device *dev, uint32_t ticks)
794{
795 const struct counter_driver_api *api = (struct counter_driver_api *)dev->api;
796
797 if (!api->set_value) {
798 return -ENOSYS;
799 }
800
801 return api->set_value(dev, ticks);
802}
803
824__syscall int counter_set_channel_alarm(const struct device *dev, uint8_t chan_id,
825 const struct counter_alarm_cfg *alarm_cfg);
826
827static inline int z_impl_counter_set_channel_alarm(const struct device *dev, uint8_t chan_id,
828 const struct counter_alarm_cfg *alarm_cfg)
829{
830 const struct counter_driver_api *api = (struct counter_driver_api *)dev->api;
831
832 if (chan_id >= counter_get_num_of_channels(dev)) {
833 return -ENOTSUP;
834 }
835
836 return api->set_alarm(dev, chan_id, alarm_cfg);
837}
838
851__syscall int counter_cancel_channel_alarm(const struct device *dev, uint8_t chan_id);
852
853static inline int z_impl_counter_cancel_channel_alarm(const struct device *dev, uint8_t chan_id)
854{
855 const struct counter_driver_api *api = (struct counter_driver_api *)dev->api;
856
857 if (chan_id >= counter_get_num_of_channels(dev)) {
858 return -ENOTSUP;
859 }
860
861 return api->cancel_alarm(dev, chan_id);
862}
863
892__syscall int counter_set_top_value(const struct device *dev, const struct counter_top_cfg *cfg);
893
894static inline int z_impl_counter_set_top_value(const struct device *dev,
895 const struct counter_top_cfg *cfg)
896{
897 const struct counter_driver_api *api = (struct counter_driver_api *)dev->api;
898
899 if (cfg->ticks > counter_get_max_top_value(dev)) {
900 return -EINVAL;
901 }
902
903 return api->set_top_value(dev, cfg);
904}
905
919__syscall uint32_t counter_get_pending_int(const struct device *dev);
920
921static inline uint32_t z_impl_counter_get_pending_int(const struct device *dev)
922{
923 const struct counter_driver_api *api = (struct counter_driver_api *)dev->api;
924
925 return api->get_pending_int(dev);
926}
927
935__syscall uint32_t counter_get_top_value(const struct device *dev);
936
937static inline uint32_t z_impl_counter_get_top_value(const struct device *dev)
938{
939 const struct counter_driver_api *api = (struct counter_driver_api *)dev->api;
940
941 return api->get_top_value(dev);
942}
943
996__syscall int counter_set_guard_period(const struct device *dev, uint32_t ticks, uint32_t flags);
997
998static inline int z_impl_counter_set_guard_period(const struct device *dev, uint32_t ticks,
1000{
1001 const struct counter_driver_api *api = (struct counter_driver_api *)dev->api;
1002
1003 if (!api->set_guard_period) {
1004 return -ENOSYS;
1005 }
1006
1007 return api->set_guard_period(dev, ticks, flags);
1008}
1009
1022
1023static inline uint32_t z_impl_counter_get_guard_period(const struct device *dev, uint32_t flags)
1024{
1025 const struct counter_driver_api *api = (struct counter_driver_api *)dev->api;
1026
1027 return (api->get_guard_period) ? api->get_guard_period(dev, flags) : 0;
1028}
1029
1037__syscall uint64_t counter_get_max_top_value_64(const struct device *dev);
1038
1039static inline uint64_t z_impl_counter_get_max_top_value_64(const struct device *dev)
1040{
1041#ifdef CONFIG_COUNTER_64BITS_TICKS
1042 const struct counter_config_info *config = (const struct counter_config_info *)dev->config;
1043
1044 return config->max_top_value_64;
1045#else
1046 ARG_UNUSED(dev);
1047 return -ENOTSUP;
1048#endif
1049}
1050
1075__syscall int counter_set_top_value_64(const struct device *dev,
1076 const struct counter_top_cfg_64 *cfg);
1077
1078static inline int z_impl_counter_set_top_value_64(const struct device *dev,
1079 const struct counter_top_cfg_64 *cfg)
1080{
1081#ifdef CONFIG_COUNTER_64BITS_TICKS
1082 const struct counter_driver_api *api = (struct counter_driver_api *)dev->api;
1083
1084 if (cfg->ticks > counter_get_max_top_value_64(dev)) {
1085 return -EINVAL;
1086 }
1087
1088 return api->set_top_value_64(dev, cfg);
1089#else
1090 ARG_UNUSED(dev);
1091 ARG_UNUSED(cfg);
1092 return -ENOTSUP;
1093#endif
1094}
1095
1116__syscall int counter_set_channel_alarm_64(const struct device *dev, uint8_t chan_id,
1117 const struct counter_alarm_cfg_64 *alarm_cfg);
1118
1119static inline int z_impl_counter_set_channel_alarm_64(const struct device *dev, uint8_t chan_id,
1120 const struct counter_alarm_cfg_64 *alarm_cfg)
1121{
1122#ifdef CONFIG_COUNTER_64BITS_TICKS
1123 const struct counter_driver_api *api = (struct counter_driver_api *)dev->api;
1124
1125 if (chan_id >= counter_get_num_of_channels(dev)) {
1126 return -ENOTSUP;
1127 }
1128
1129 return api->set_alarm_64(dev, chan_id, alarm_cfg);
1130#else
1131 ARG_UNUSED(dev);
1132 ARG_UNUSED(chan_id);
1133 ARG_UNUSED(alarm_cfg);
1134 return -ENOTSUP;
1135#endif
1136}
1137
1145__syscall uint64_t counter_get_top_value_64(const struct device *dev);
1146
1147static inline uint64_t z_impl_counter_get_top_value_64(const struct device *dev)
1148{
1149#ifdef CONFIG_COUNTER_64BITS_TICKS
1150 const struct counter_driver_api *api = (struct counter_driver_api *)dev->api;
1151
1152 return api->get_top_value_64(dev);
1153#else
1154 ARG_UNUSED(dev);
1155 return 0;
1156#endif
1157}
1158
1211__syscall int counter_set_guard_period_64(const struct device *dev, uint64_t ticks, uint32_t flags);
1212
1213static inline int z_impl_counter_set_guard_period_64(const struct device *dev, uint64_t ticks,
1215{
1216#ifdef CONFIG_COUNTER_64BITS_TICKS
1217 const struct counter_driver_api *api = (struct counter_driver_api *)dev->api;
1218
1219 if (!api->set_guard_period_64) {
1220 return -ENOSYS;
1221 }
1222
1223 return api->set_guard_period_64(dev, ticks, flags);
1224#else
1225 ARG_UNUSED(dev);
1226 ARG_UNUSED(ticks);
1227 ARG_UNUSED(flags);
1228 return -ENOTSUP;
1229#endif
1230}
1231
1244
1245static inline uint64_t z_impl_counter_get_guard_period_64(const struct device *dev, uint32_t flags)
1246{
1247#ifdef CONFIG_COUNTER_64BITS_TICKS
1248 const struct counter_driver_api *api = (struct counter_driver_api *)dev->api;
1249
1250 return (api->get_guard_period_64) ? api->get_guard_period_64(dev, flags) : 0;
1251#else
1252 ARG_UNUSED(dev);
1253 ARG_UNUSED(flags);
1254 return -ENOTSUP;
1255#endif
1256}
1257
1266__syscall int counter_get_value_64(const struct device *dev, uint64_t *ticks);
1267
1268static inline int z_impl_counter_get_value_64(const struct device *dev, uint64_t *ticks)
1269{
1270#ifdef CONFIG_COUNTER_64BITS_TICKS
1271 const struct counter_driver_api *api = (struct counter_driver_api *)dev->api;
1272
1273 if (!api->get_value_64) {
1274 return -ENOSYS;
1275 }
1276
1277 return api->get_value_64(dev, ticks);
1278#else
1279 ARG_UNUSED(dev);
1280 ARG_UNUSED(ticks);
1281 return -ENOTSUP;
1282#endif
1283}
1284
1293__syscall int counter_set_value_64(const struct device *dev, uint64_t ticks);
1294
1295static inline int z_impl_counter_set_value_64(const struct device *dev, uint64_t ticks)
1296{
1297#ifdef CONFIG_COUNTER_64BITS_TICKS
1298 const struct counter_driver_api *api = (struct counter_driver_api *)dev->api;
1299
1300 if (!api->set_value_64) {
1301 return -ENOSYS;
1302 }
1303
1304 return api->set_value_64(dev, ticks);
1305#else
1306 ARG_UNUSED(dev);
1307 ARG_UNUSED(ticks);
1308 return -ENOTSUP;
1309#endif
1310}
1311
1312#ifdef __cplusplus
1313}
1314#endif
1315
1319
1320#include <zephyr/syscalls/counter.h>
1321
1322#endif /* ZEPHYR_INCLUDE_DRIVERS_COUNTER_H_ */
System error numbers.
#define NSEC_PER_SEC
number of nanoseconds per second
Definition clock.h:113
#define USEC_PER_SEC
number of microseconds per second
Definition clock.h:110
uint32_t(* counter_api_get_top_value)(const struct device *dev)
Callback API to retrieve the current top value.
Definition counter.h:321
int(* counter_api_set_top_value_64)(const struct device *dev, const struct counter_top_cfg_64 *cfg)
Callback API to set the counter top value (64 bits).
Definition counter.h:347
uint64_t(* counter_api_get_top_value_64)(const struct device *dev)
Callback API to retrieve the current top value (64 bits).
Definition counter.h:345
int(* counter_api_set_value)(const struct device *dev, uint32_t ticks)
Callback API to set the current counter value.
Definition counter.h:309
int(* counter_api_stop)(const struct device *dev)
Callback API to stop the counter.
Definition counter.h:303
bool(* counter_api_is_counting_up)(const struct device *dev)
Callback API to check if the counter is counting up.
Definition counter.h:350
int(* counter_api_set_alarm_64)(const struct device *dev, uint8_t chan_id, const struct counter_alarm_cfg_64 *alarm_cfg)
Callback API to set a single shot alarm on a channel (64 bits).
Definition counter.h:337
int(* counter_api_set_guard_period_64)(const struct device *dev, uint64_t ticks, uint32_t flags)
Callback API to set the guard period in ticks (64 bits).
Definition counter.h:342
uint64_t(* counter_api_get_guard_period_64)(const struct device *dev, uint32_t flags)
Callback API to retrieve the guard period in ticks (64 bits).
Definition counter.h:340
int(* counter_api_set_guard_period)(const struct device *dev, uint32_t ticks, uint32_t flags)
Callback API to set the guard period in ticks.
Definition counter.h:325
uint64_t(* counter_api_get_freq_64)(const struct device *dev)
Callback API to get the counter frequency in Hz (64 bits).
Definition counter.h:330
int(* counter_api_set_value_64)(const struct device *dev, uint64_t ticks)
Callback API to set the current counter value (64 bits).
Definition counter.h:335
uint32_t(* counter_api_get_guard_period)(const struct device *dev, uint32_t flags)
Callback API to retrieve the guard period in ticks.
Definition counter.h:323
uint32_t(* counter_api_get_pending_int)(const struct device *dev)
Callback API to get pending counter interrupts.
Definition counter.h:319
uint32_t(* counter_api_get_freq)(const struct device *dev)
Callback API to get the counter frequency in Hz.
Definition counter.h:328
int(* counter_api_set_top_value)(const struct device *dev, const struct counter_top_cfg *cfg)
Callback API to set the counter top value.
Definition counter.h:316
int(* counter_api_reset)(const struct device *dev)
Callback API to reset the counter to the initial value.
Definition counter.h:307
int(* counter_api_start)(const struct device *dev)
Callback API to start the counter.
Definition counter.h:301
int(* counter_api_cancel_alarm)(const struct device *dev, uint8_t chan_id)
Callback API to cancel an alarm on a channel.
Definition counter.h:314
int(* counter_api_get_value_64)(const struct device *dev, uint64_t *ticks)
Callback API to get the current counter value (64 bits).
Definition counter.h:333
int(* counter_api_get_value)(const struct device *dev, uint32_t *ticks)
Callback API to get the current counter value.
Definition counter.h:305
int(* counter_api_set_alarm)(const struct device *dev, uint8_t chan_id, const struct counter_alarm_cfg *alarm_cfg)
Callback API to set a single shot alarm on a channel.
Definition counter.h:311
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.
uint8_t counter_get_num_of_channels(const struct device *dev)
Function to get number of alarm channels.
int counter_start(const struct device *dev)
Start counter device in free running mode.
uint32_t counter_get_top_value(const struct device *dev)
Function to retrieve current top value.
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.
uint32_t counter_get_pending_int(const struct device *dev)
Function to get pending interrupts.
uint64_t counter_ticks_to_us_64(const struct device *dev, uint64_t ticks)
Function to convert ticks with 64 bits to microseconds.
int counter_reset(const struct device *dev)
Reset the counter to the initial value.
uint64_t counter_ns_to_ticks_64(const struct device *dev, uint64_t ns)
Function to convert nanoseconds to ticks with 64 bits.
int counter_set_top_value(const struct device *dev, const struct counter_top_cfg *cfg)
Set counter top value.
int counter_get_value_64(const struct device *dev, uint64_t *ticks)
Get current counter 64-bit value.
int counter_set_top_value_64(const struct device *dev, const struct counter_top_cfg_64 *cfg)
Set counter top value for 64 bits.
uint64_t counter_us_to_ticks_64(const struct device *dev, uint64_t us)
Function to convert microseconds to ticks with 64 bits.
void(* counter_top_callback_t)(const struct device *dev, void *user_data)
Callback called when counter turns around.
Definition counter.h:165
void(* counter_alarm_callback_t)(const struct device *dev, uint8_t chan_id, uint32_t ticks, void *user_data)
Alarm callback.
Definition counter.h:123
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.
uint64_t counter_get_guard_period_64(const struct device *dev, uint32_t flags)
Return guard period for 64 bits.
uint64_t counter_get_frequency_64(const struct device *dev)
Function to get counter frequency in 64bits.
void(* counter_alarm_callback_64_t)(const struct device *dev, uint8_t chan_id, uint64_t ticks, void *user_data)
Alarm callback.
Definition counter.h:237
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_guard_period(const struct device *dev, uint32_t flags)
Return guard period.
int counter_set_value(const struct device *dev, uint32_t ticks)
Set current counter value.
uint32_t counter_get_frequency(const struct device *dev)
int counter_get_value(const struct device *dev, uint32_t *ticks)
Get current counter value.
#define COUNTER_CONFIG_INFO_COUNT_UP
Counter count up flag.
Definition counter.h:47
int counter_set_value_64(const struct device *dev, uint64_t ticks)
Set current counter 64-bit value.
uint64_t counter_get_top_value_64(const struct device *dev)
Function to retrieve current top value for 64 bits.
uint64_t counter_ticks_to_us(const struct device *dev, uint32_t ticks)
Function to convert ticks to microseconds.
int counter_set_guard_period(const struct device *dev, uint32_t ticks, uint32_t flags)
Set guard period in counter ticks.
uint32_t counter_us_to_ticks(const struct device *dev, uint64_t us)
Function to convert microseconds to ticks.
bool counter_is_counting_up(const struct device *dev)
Function to check if counter is counting up.
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_ticks_to_ns(const struct device *dev, uint32_t ticks)
Function to convert ticks to nanoseconds.
int counter_cancel_channel_alarm(const struct device *dev, uint8_t chan_id)
Cancel an alarm on a channel.
uint32_t counter_ns_to_ticks(const struct device *dev, uint64_t ns)
Function to convert nanoseconds to ticks.
int counter_stop(const struct device *dev)
Stop counter device.
uint32_t counter_get_max_top_value(const struct device *dev)
Function to retrieve maximum top value that can be set.
#define EINVAL
Invalid argument.
Definition errno.h:60
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define ENOTSUP
Unsupported value.
Definition errno.h:114
flags
Definition parser.h:97
#define bool
Definition stdbool.h:13
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
#define UINT32_MAX
Definition stdint.h:29
Alarm callback structure.
Definition counter.h:242
void * user_data
User data returned in callback.
Definition counter.h:267
uint32_t flags
Alarm flags (see COUNTER_ALARM_FLAGS).
Definition counter.h:271
counter_alarm_callback_64_t callback
Callback called on alarm (cannot be NULL).
Definition counter.h:263
uint64_t ticks
Number of ticks that triggers the alarm.
Definition counter.h:259
Alarm callback structure.
Definition counter.h:128
uint32_t ticks
Number of ticks that triggers the alarm.
Definition counter.h:149
uint32_t flags
Alarm flags (see COUNTER_ALARM_FLAGS).
Definition counter.h:157
void * user_data
User data returned in callback.
Definition counter.h:153
counter_alarm_callback_t callback
Callback called on alarm (cannot be NULL).
Definition counter.h:132
Structure with generic counter features.
Definition counter.h:190
uint32_t max_top_value
Maximal (default) top value on which counter is reset (cleared or reloaded).
Definition counter.h:216
uint32_t freq
Frequency of the source clock if synchronous events are counted.
Definition counter.h:197
uint8_t flags
Flags (see COUNTER_FLAGS).
Definition counter.h:221
uint8_t channels
Number of channels that can be used for setting alarm.
Definition counter.h:227
<span class="mlabel">Driver Operations</span> Counter driver operations
Definition counter.h:355
counter_api_get_top_value get_top_value
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition counter.h:395
counter_api_set_top_value set_top_value
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition counter.h:387
counter_api_set_alarm set_alarm
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition counter.h:379
counter_api_get_value get_value
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition counter.h:367
counter_api_reset reset
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition counter.h:371
counter_api_get_pending_int get_pending_int
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition counter.h:391
counter_api_stop stop
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition counter.h:363
counter_api_set_guard_period set_guard_period
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition counter.h:403
counter_api_set_value set_value
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition counter.h:375
counter_api_start start
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition counter.h:359
counter_api_get_guard_period get_guard_period
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition counter.h:399
counter_api_cancel_alarm cancel_alarm
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition counter.h:383
counter_api_is_counting_up is_counting_up
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition counter.h:411
counter_api_get_freq get_freq
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition counter.h:407
Top value configuration structure.
Definition counter.h:276
void * user_data
User data passed to callback function (not valid if callback is NULL).
Definition counter.h:288
counter_top_callback_t callback
Callback function (can be NULL).
Definition counter.h:284
uint32_t flags
Flags (see COUNTER_TOP_FLAGS).
Definition counter.h:292
uint64_t ticks
Top value.
Definition counter.h:280
Top value configuration structure.
Definition counter.h:169
uint32_t ticks
Top value.
Definition counter.h:173
uint32_t flags
Flags (see COUNTER_TOP_FLAGS).
Definition counter.h:185
counter_top_callback_t callback
Callback function (can be NULL).
Definition counter.h:177
void * user_data
User data passed to callback function (not valid if callback is NULL).
Definition counter.h:181
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:519
const void * config
Address of device instance config information.
Definition device.h:517