1 /* 2 * Copyright (c) 2024 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef NRFS_CLOCK_H 8 #define NRFS_CLOCK_H 9 10 #include <internal/services/nrfs_clock.h> 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 /** @brief Clock service event types. */ 17 typedef enum __NRFS_PACKED { 18 NRFS_CLOCK_EVT_APPLIED, /** Request applied successfully. */ 19 NRFS_CLOCK_EVT_REJECT, /** Request rejected. */ 20 NRFS_CLOCK_EVT_CHANGE, /** Clock event changed. */ 21 } nrfs_clock_evt_type_t; 22 23 /** @brief Clock service event. */ 24 typedef struct { 25 nrfs_clock_evt_type_t type; /** Event type. */ 26 nrfs_clock_rsp_data_t data; /** Event data. */ 27 } nrfs_clock_evt_t; 28 29 /** @brief Clock service event handler type. */ 30 typedef void (*nrfs_clock_evt_handler_t)(nrfs_clock_evt_t const * p_evt, void * context); 31 32 /** 33 * @brief Function for initializing the clock service. 34 * 35 * @param[in] handler Function called as a response to the request. 36 * 37 * @retval NRFS_SUCCESS Service initialized successfully. 38 * @retval NRFS_ERR_INVALID_STATE Service was already initialized. 39 */ 40 nrfs_err_t nrfs_clock_init(nrfs_clock_evt_handler_t handler); 41 42 /** 43 * @brief Function for uninitializing the clock service. 44 * 45 * @warning Notifications from previous requests are dropped after service uninitialization. 46 */ 47 void nrfs_clock_uninit(void); 48 49 /** 50 * @brief Function for subscribing to events in the clock service. 51 * 52 * @note If subscription is already active, calling this function again 53 * will overwrite the subscription parameters. 54 * 55 * @param[in] event_mask Mask of events to be subscribed to. Use values of nrfs_clock_evt_reason_t. 56 * @param[in] p_context Opaque user data that will be passed to registered callback. 57 * 58 * @retval NRFS_SUCCESS Request sent successfully. 59 * @retval NRFS_ERR_INVALID_STATE Service is uninitialized. 60 * @retval NRFS_ERR_IPC Backend returned error during request sending. 61 */ 62 nrfs_err_t nrfs_clock_subscribe(uint8_t event_mask, void * p_context); 63 64 /** 65 * @brief Function for unsubscribing from events in the clock service. 66 * 67 * @retval NRFS_SUCCESS Request sent successfully. 68 * @retval NRFS_ERR_INVALID_STATE Service is uninitialized. 69 * @retval NRFS_ERR_IPC Backend returned error during request sending. 70 */ 71 nrfs_err_t nrfs_clock_unsubscribe(void); 72 73 /** 74 * @brief Function for setting LFCLK source. 75 * 76 * @param[in] src LFCLK source to be set. 77 * @param[in] p_context Opaque user data that will be passed to registered callback. 78 * 79 * @retval NRFS_SUCCESS Request sent successfully. 80 * @retval NRFS_ERR_INVALID_STATE Service is uninitialized. 81 * @retval NRFS_ERR_IPC Backend returned error during request sending. 82 */ 83 nrfs_err_t nrfs_clock_lfclk_src_set(nrfs_clock_src_t src, void * p_context); 84 85 /** 86 * @brief Function for setting LFCLK source with no response. 87 * 88 * @param[in] src LFCLK source to be set. 89 * @param[in] p_context Opaque user data that will be passed to registered callback. 90 * 91 * @retval NRFS_SUCCESS Request sent successfully. 92 * @retval NRFS_ERR_INVALID_STATE Service is uninitialized. 93 * @retval NRFS_ERR_IPC Backend returned error during request sending. 94 */ 95 nrfs_err_t nrfs_clock_lfclk_src_set_no_rsp(nrfs_clock_src_t src, void * p_context); 96 97 /** 98 * @brief Function for setting HSFLL_120 mode. 99 * 100 * @param[in] mode HSFLL mode to be set. 101 * @param[in] p_context Opaque user data that will be passed to registered callback. 102 * 103 * @retval NRFS_SUCCESS Request sent successfully. 104 * @retval NRFS_ERR_INVALID_STATE Service is uninitialized. 105 * @retval NRFS_ERR_IPC Backend returned error during request sending. 106 */ 107 nrfs_err_t nrfs_clock_hsfll_mode_set(nrfs_clock_hsfll_mode_t mode, void * p_context); 108 109 /** 110 * @brief Function for setting HSFLL_120 mode with no response. 111 * 112 * @param[in] mode HSFLL mode to be set. 113 * @param[in] p_context Opaque user data that will be passed to registered callback. 114 * 115 * @retval NRFS_SUCCESS Request sent successfully. 116 * @retval NRFS_ERR_INVALID_STATE Service is uninitialized. 117 * @retval NRFS_ERR_IPC Backend returned error during request sending. 118 */ 119 nrfs_err_t nrfs_clock_hsfll_mode_set_no_rsp(nrfs_clock_hsfll_mode_t mode, void * p_context); 120 121 #ifdef __cplusplus 122 } 123 #endif 124 125 #endif /* NRFS_CLOCK_H */ 126