1 /*
2  * Copyright (c) 2018, Nordic Semiconductor ASA
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice, this
11  *    list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
18  *    contributors may be used to endorse or promote products derived from this
19  *    software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34 
35 /**
36  * @brief Module that defines the Timer Coordinator interface.
37  *
38  */
39 
40 #ifndef NRF_802154_TIMER_COORD_H_
41 #define NRF_802154_TIMER_COORD_H_
42 
43 #include <stdbool.h>
44 #include <stdint.h>
45 
46 #include "nrf_802154_sl_types.h"
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 /**
53  * @defgroup nrf_802154_timer_coord Timer Coordinator
54  * @{
55  * @ingroup nrf_802154
56  * @brief The Timer Coordinator interface.
57  *
58  * Timer Coordinator is responsible for synchronizing and coordinating operations of the Low Power
59  * timer that counts the absolute time and the High Precision timer that counts the time relative to
60  * a timeslot.
61  */
62 
63 /**
64  * @brief Initializes the Timer Coordinator module.
65  *
66  */
67 void nrf_802154_timer_coord_init(void);
68 
69 /**
70  * @brief Deinitializes the Timer Coordinator module.
71  *
72  */
73 void nrf_802154_timer_coord_uninit(void);
74 
75 /**
76  * @brief Starts the Timer Coordinator module.
77  *
78  * This function starts the HP timer and synchronizes it with the LP timer.
79  *
80  * Once started, Timer Coordinator resynchronizes automatically in a constant interval.
81  */
82 void nrf_802154_timer_coord_start(void);
83 
84 /**
85  * @brief Stops the Timer Coordinator module.
86  *
87  * This function stops the HP timer.
88  */
89 void nrf_802154_timer_coord_stop(void);
90 
91 /**
92  * @brief Prepares for getting a precise timestamp of the given event.
93  *
94  * @param[in] p_event   Pointer to structure describing a hardware event to be timestamped.
95  */
96 void nrf_802154_timer_coord_timestamp_prepare(const nrf_802154_sl_event_handle_t * p_event);
97 
98 /**
99  * @brief Gets the timestamp of the recently prepared event.
100  *
101  * If the timer coordinator is synchronized, the function returns true and the timestamp of
102  * the recently prepared event. Otherwise, the function returns false.
103  *
104  * @param[out]  p_timestamp  Precise absolute timestamp of the recently prepared event,
105  *                           in microseconds (us).
106  *
107  * @retval true   Timestamp is available.
108  * @retval false  Timestamp is unavailable.
109  */
110 bool nrf_802154_timer_coord_timestamp_get(uint64_t * p_timestamp);
111 
112 /**
113  *@}
114  **/
115 
116 #ifdef __cplusplus
117 }
118 #endif
119 
120 #endif /* NRF_802154_TIMER_COORD_H_ */
121