1 /*
2  * Copyright (c) 2024 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef NRFS_INTERNAL_CLOCK_H
8 #define NRFS_INTERNAL_CLOCK_H
9 
10 #include <zephyr/sys/util_macro.h>
11 #include <internal/services/nrfs_generic.h>
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 /**
18  * @brief Clock service event reason.
19  *
20  * @note The values are in bit position intervals so that they can be used as masked values.
21  */
22 typedef enum __NRFS_PACKED {
23 	NRFS_CLOCK_EVENT_REASON_LFCLK_ACCURACY_CHANGED = BIT(0),
24 	NRFS_CLOCK_EVENT_REASON_LFCLK_PRECISION_CHANGED = BIT(1),
25 	NRFS_CLOCK_EVENT_REASON_LFCLK_NO_CHANGE = BIT(2),
26 	NRFS_CLOCK_EVENT_REASON_ALL = 0xFF
27 } nrfs_clock_evt_reason_t;
28 
29 /** @brief Clock source option. */
30 typedef enum __NRFS_PACKED {
31 	NRFS_CLOCK_SRC_LFCLK_DEFAULT = 0,
32 	NRFS_CLOCK_SRC_LFCLK_XO_DEFAULT,
33 	NRFS_CLOCK_SRC_LFCLK_XO_DEFAULT_HP,
34 
35 	NRFS_CLOCK_SRC_LFCLK_LFLPRC,
36 	NRFS_CLOCK_SRC_LFCLK_LFRC,
37 
38 	NRFS_CLOCK_SRC_LFCLK_XO_PIXO,
39 	NRFS_CLOCK_SRC_LFCLK_XO_PIERCE,
40 	NRFS_CLOCK_SRC_LFCLK_XO_EXT_SINE,
41 	NRFS_CLOCK_SRC_LFCLK_XO_EXT_SQUARE,
42 
43 	NRFS_CLOCK_SRC_LFCLK_SYNTH,
44 
45 	NRFS_CLOCK_SRC_LFCLK_XO_PIERCE_HP,
46 	NRFS_CLOCK_SRC_LFCLK_XO_EXT_SINE_HP,
47 }nrfs_clock_src_t;
48 
49 /** @brief HSFLL120 Mode options. */
50 typedef enum __NRFS_PACKED {
51 	NRFS_CLOCK_HSFLL_MODE_OPEN = 0,
52 	NRFS_CLOCK_HSFLL_MODE_CLOSED,
53 }nrfs_clock_hsfll_mode_t;
54 
55 /** @brief Clock service notification data structure. */
56 typedef struct __NRFS_PACKED {
57 	nrfs_clock_evt_reason_t reason; /**< Reason for the event. */
58 	nrfs_clock_src_t        src;    /**< New clock source. */
59 } nrfs_clock_rsp_data_t;
60 
61 /** @brief Clock service notification structure. */
62 typedef struct __NRFS_PACKED {
63 	nrfs_hdr_t            hdr;  /**< Header of the message. */
64 	nrfs_ctx_t            ctx;  /**< Context of the message. */
65 	nrfs_clock_rsp_data_t data; /**< Data of the notification. */
66 } nrfs_clock_rsp_t;
67 
68 /** @brief Subscribe request structure. */
69 typedef struct __NRFS_PACKED {
70 	nrfs_hdr_t hdr;        /**< Header of the message. */
71 	nrfs_ctx_t ctx;        /**< Context of the message. */
72 	uint8_t    event_mask; /**< Events to be subscribed to. */
73 } nrfs_clock_subscribe_t;
74 
75 /** @brief Unsubscribe request structure. */
76 typedef struct __NRFS_PACKED {
77 	nrfs_hdr_t hdr; /**< Header of the message. */
78 	nrfs_ctx_t ctx; /**< Context of the message. */
79 } nrfs_clock_unsubscribe_t;
80 
81 /** @brief LFCLK source request structure. */
82 typedef struct __NRFS_PACKED {
83 	nrfs_hdr_t       hdr; /**< Header of the message. */
84 	nrfs_ctx_t       ctx; /**< Context of the message. */
85 	nrfs_clock_src_t src; /**< LFCLK source. */
86 } nrfs_clock_lfclk_src_req_t;
87 
88 /** @brief HSFLL mode request structure. */
89 typedef struct __NRFS_PACKED {
90 	nrfs_hdr_t hdr; /**< Header of the message. */
91 	nrfs_ctx_t ctx; /**< Context of the message. */
92 	nrfs_clock_hsfll_mode_t mode;
93 } nrfs_clock_hsfll_mode_req_t;
94 
95 /** @brief HSFLL mode notification structure. */
96 typedef struct __NRFS_PACKED {
97 	nrfs_hdr_t hdr; /**< Header of the message. */
98 	nrfs_ctx_t ctx; /**< Context of the message. */
99 	nrfs_clock_hsfll_mode_t data;
100 } nrfs_clock_hsfll_mode_rsp_t;
101 
102 #ifdef __cplusplus
103 }
104 #endif
105 
106 #endif /* NRFS_INTERNAL_CLOCK_H */
107