Zephyr API Documentation 4.3.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
ets.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 Dipak Shetty
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_BLUETOOTH_SERVICES_ETS_H_
8#define ZEPHYR_INCLUDE_BLUETOOTH_SERVICES_ETS_H_
9
17
18#include <stdint.h>
19#include <stdbool.h>
20#include <zephyr/sys/util.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
43
51
53#define BT_ETS_FLAG_TICK_COUNTER BIT(0)
54
56#define BT_ETS_FLAG_UTC BIT(1)
57
59#define BT_ETS_FLAG_RESOLUTION_MASK (BIT(2) | BIT(3))
60
62#define BT_ETS_FLAG_TZ_DST_USED BIT(4)
63
65#define BT_ETS_FLAG_CURRENT_TIMELINE BIT(5)
66
68#define BT_ETS_FLAG_RESERVED_MASK (BIT(6) | BIT(7))
69
71
85
93
95#define BT_ETS_TIME_SOURCE_UNKNOWN 0
97#define BT_ETS_TIME_SOURCE_NTP 1
99#define BT_ETS_TIME_SOURCE_GPS 2
101#define BT_ETS_TIME_SOURCE_RADIO 3
103#define BT_ETS_TIME_SOURCE_MANUAL 4
105#define BT_ETS_TIME_SOURCE_ATOMIC 5
107#define BT_ETS_TIME_SOURCE_CELLULAR 6
109#define BT_ETS_TIME_SOURCE_NOT_SYNCHRONIZED 7
110
112
129
131#define BT_ETS_SUPPORTED_FLAGS_MASK \
132 ((IS_ENABLED(CONFIG_BT_ETS_SUPPORT_TICK_COUNTER) ? BT_ETS_FLAG_TICK_COUNTER : 0) | \
133 (IS_ENABLED(CONFIG_BT_ETS_SUPPORT_UTC) ? BT_ETS_FLAG_UTC : 0) | \
134 (IS_ENABLED(CONFIG_BT_ETS_SUPPORT_TZ_DST) ? BT_ETS_FLAG_TZ_DST_USED : 0) | \
135 (IS_ENABLED(CONFIG_BT_ETS_RESOLUTION_1_SEC) ? 0 \
136 : IS_ENABLED(CONFIG_BT_ETS_RESOLUTION_100_MS) ? BIT(2) \
137 : IS_ENABLED(CONFIG_BT_ETS_RESOLUTION_1_MS) ? BIT(3) \
138 : IS_ENABLED(CONFIG_BT_ETS_RESOLUTION_100_US) ? (BIT(2) | BIT(3)) \
139 : 0) | \
140 BT_ETS_FLAG_CURRENT_TIMELINE)
141
149
151#define BT_ETS_CLOCK_STATUS_NEEDS_SET BIT(0)
153#define BT_ETS_CLOCK_STATUS_RFU_MASK 0xFE
154
156
163
165#define BT_ETS_CLOCK_CAP_DST_AUTO BIT(0)
167#define BT_ETS_CLOCK_CAP_TZ_AUTO BIT(1)
169#define BT_ETS_CLOCK_CAP_RFU_MASK 0xFC
170
172
176#define BT_ETS_CLOCK_CAPABILITIES_VALUE \
177 ((IS_ENABLED(CONFIG_BT_ETS_CLOCK_CAP_DST_AUTO) ? BT_ETS_CLOCK_CAP_DST_AUTO : 0) | \
178 (IS_ENABLED(CONFIG_BT_ETS_CLOCK_CAP_TZ_AUTO) ? BT_ETS_CLOCK_CAP_TZ_AUTO : 0))
179
183struct bt_ets_cb {
196
208 int (*read_clock_status)(uint8_t *status);
209
224
233 void (*indication_changed)(bool enabled);
234};
235
247int bt_ets_init(const struct bt_ets_cb *cb);
248
263int bt_ets_indicate(const struct bt_ets_elapsed_time *elapsed_time, uint8_t clock_status);
264
291int bt_ets_time_to_unix_ms(const struct bt_ets_elapsed_time *et_time, int64_t *unix_ms);
292
328int bt_ets_time_from_unix_ms(struct bt_ets_elapsed_time *et_time, int64_t unix_ms, uint8_t time_src,
330
331#ifdef __cplusplus
332}
333#endif
334
338
339#endif /* ZEPHYR_INCLUDE_BLUETOOTH_SERVICES_ETS_H_ */
bt_ets_time_resolution
Time resolution values for bits 2-3 of flags field.
Definition ets.h:75
bt_ets_write_result
Write result codes for write_elapsed_time callback.
Definition ets.h:119
int bt_ets_time_from_unix_ms(struct bt_ets_elapsed_time *et_time, int64_t unix_ms, uint8_t time_src, int8_t tz_dst_offset)
Encode Unix milliseconds into ETS formatted time.
int bt_ets_time_to_unix_ms(const struct bt_ets_elapsed_time *et_time, int64_t *unix_ms)
Decode ETS formatted time into milliseconds since Unix epoch.
int bt_ets_indicate(const struct bt_ets_elapsed_time *elapsed_time, uint8_t clock_status)
Send indication to subscribed clients.
int bt_ets_init(const struct bt_ets_cb *cb)
Initialize Elapsed Time Service.
@ BT_ETS_RESOLUTION_100_MS
100 milliseconds resolution.
Definition ets.h:79
@ BT_ETS_RESOLUTION_1_SEC
1 second resolution.
Definition ets.h:77
@ BT_ETS_RESOLUTION_1_MS
1 millisecond resolution.
Definition ets.h:81
@ BT_ETS_RESOLUTION_100_US
100 microseconds resolution.
Definition ets.h:83
@ BT_ETS_WRITE_OUT_OF_RANGE
Time value is out of acceptable range.
Definition ets.h:125
@ BT_ETS_WRITE_TIME_SOURCE_TOO_LOW
Time source quality is too low.
Definition ets.h:123
@ BT_ETS_WRITE_INCORRECT_FORMAT
Incorrect time format (flags mismatch).
Definition ets.h:127
@ BT_ETS_WRITE_SUCCESS
Write accepted successfully.
Definition ets.h:121
time_t time(time_t *tloc)
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__INT64_TYPE__ int64_t
Definition stdint.h:75
__INT8_TYPE__ int8_t
Definition stdint.h:72
Elapsed Time Service callback structure.
Definition ets.h:183
enum bt_ets_write_result(* write_elapsed_time)(const struct bt_ets_elapsed_time *time)
Write elapsed time callback (OPTIONAL).
Definition ets.h:223
void(* indication_changed)(bool enabled)
Indication subscription changed callback (OPTIONAL).
Definition ets.h:233
int(* read_clock_status)(uint8_t *status)
Read clock status (BT_ETS_CLOCK_STATUS) callback (MANDATORY).
Definition ets.h:208
int(* read_elapsed_time)(struct bt_ets_elapsed_time *time)
Read elapsed time callback (MANDATORY).
Definition ets.h:195
Elapsed Time data structure as defined in GATT Specification Supplement Section 3....
Definition ets.h:29
uint8_t flags
Flags field.
Definition ets.h:31
int8_t tz_dst_offset
Combined Time Zone Daylight Saving Time offset from UTC in 15-minute units (signed).
Definition ets.h:41
uint8_t time_value[6]
The actual time value in the resolution as defined by the flags.
Definition ets.h:37
uint8_t time_sync_src
Time synchronization source type.
Definition ets.h:39
Misc utilities.