1 /*
2  * Copyright (c) 2020 - 2023, 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 /**@file nrf_802154_callouts.h
36  * @brief Provides function prototypes required by nRF 802.15.4 Radio Driver
37  *
38  * Functions whose prototypes are defined in this file are to be implemented
39  * by an application using the nRF 802.15.4 Radio Driver.
40  */
41 
42 /**
43  * @defgroup nrf_802154_callouts
44  * 802.15.4 radio driver callouts
45  * @{
46  *
47  */
48 
49 #ifndef NRF_802154_CALLOUTS_H_
50 #define NRF_802154_CALLOUTS_H_
51 
52 #include <stdint.h>
53 #include <stdbool.h>
54 
55 #include "nrf_802154_types.h"
56 
57 /**
58  * @brief Notifies that the CCA procedure has finished.
59  *
60  * @param[in]  channel_free  Indication if the channel is free.
61  */
62 extern void nrf_802154_cca_done(bool channel_free);
63 
64 /**
65  * @brief Notifies that the CCA procedure failed.
66  *
67  * @param[in]  error  Reason of the failure.
68  */
69 extern void nrf_802154_cca_failed(nrf_802154_cca_error_t error);
70 
71 /**
72  * @brief Notifies that the energy detection procedure finished.
73  *
74  * @note This function passes the EnergyLevel defined in the 802.15.4-2006 specification:
75  *       0x00 - 0xff, where 0x00 represents -75dBm (10dBm above the worst allowed sensitivity level,
76  *       which is -85dBm) and 0xff is the highest possible energy detection level, for which
77  *       the measurements are guaranteed map linearly to the real energy level in dBm.
78  *       To calculate the result in dBm, use @ref nrf_802154_dbm_from_energy_level_calculate.
79  *
80  * @param[in]  result  Maximum energy detected during the energy detection procedure.
81  */
82 extern void nrf_802154_energy_detected(uint8_t result);
83 
84 /**
85  * @brief Notifies that the energy detection procedure failed.
86  *
87  * @param[in]  error  Reason of the failure.
88  */
89 extern void nrf_802154_energy_detection_failed(nrf_802154_ed_error_t error);
90 
91 /**
92  * @brief Notifies about the start of the ACK frame transmission.
93  *
94  * @note If a call to this function is performed by the same CPU running core
95  * of nRF 802.15.4 Radio Driver (non serialized call to @ref nrf_802154_tx_ack_started)
96  * the function must be very short to prevent dropping frames by the driver.
97  * If a call to this function is performed by a CPU through a serialization layer
98  * the call can be slightly delayed. The call can happen even after an ACK frame
99  * is fully transmitted. It is guaranteed that a call to @ref nrf_802154_tx_ack_started
100  * occurs before a call to @ref nrf_802154_received_timestamp_raw related to
101  * the same received frame.
102  *
103  * @param[in]  p_data  Pointer to a buffer with PHR and PSDU of the ACK frame.
104  */
105 extern void nrf_802154_tx_ack_started(const uint8_t * p_data);
106 
107 /**
108  * @brief Notifies that a frame was received at a given time.
109  *
110  * This function works like @ref nrf_802154_received_raw and adds a timestamp to the parameter
111  * list.
112  *
113  * @note The received frame usually contains a timestamp. However, due to a race condition,
114  *       the timestamp may be invalid. This erroneous situation is indicated by
115  *       the @ref NRF_802154_NO_TIMESTAMP value of the @p time parameter.
116  *
117  * @param[in]  p_data  Pointer to a buffer that contains PHR and PSDU of the received frame.
118  *                     The first byte in the buffer is the length of the frame (PHR). The following
119  *                     bytes contain the frame itself (PSDU). The length byte (PHR) includes FCS.
120  *                     FCS is already verified by the hardware and may be modified by the hardware.
121  * @param[in]  power   RSSI of the received frame.
122  * @param[in]  lqi     LQI of the received frame.
123  * @param[in]  time    Timestamp taken when the last symbol of the frame was received, in
124  *                     microseconds (us), or @ref NRF_802154_NO_TIMESTAMP if the timestamp
125  *                     is invalid.
126  */
127 extern void nrf_802154_received_timestamp_raw(uint8_t * p_data,
128                                               int8_t    power,
129                                               uint8_t   lqi,
130                                               uint64_t  time);
131 
132 /**
133  * @brief Notifies that the reception of a frame failed.
134  *
135  * @param[in]  error  Error code that indicates the reason of the failure.
136  * @param[in]  id     Identifier of reception window the error occurred in.
137  *                    If the error is related to a delayed reception window requested through
138  *                    @ref nrf_802154_receive_at, the value of @p id equals the identifier
139  *                    of the scheduled reception window. Otherwise, the value of @p id equals
140  *                    @ref NRF_802154_RESERVED_IMM_RX_WINDOW_ID.
141  */
142 extern void nrf_802154_receive_failed(nrf_802154_rx_error_t error, uint32_t id);
143 
144 /**
145  * @brief Notifies that a frame was transmitted.
146  *
147  * @note If ACK was requested for the transmitted frame, this function is called after a proper ACK
148  *       is received. If ACK was not requested, this function is called just after transmission has
149  *       ended.
150  * @note The buffer pointed to by @ref nrf_802154_transmit_done_metadata_t.data.transmitted.p_ack
151  *       is not modified by the radio driver (and cannot be used to receive a frame) until
152  *       @ref nrf_802154_buffer_free_raw is called.
153  * @note The buffer pointed to by @ref nrf_802154_transmit_done_metadata_t.data.transmitted.p_ack
154  *       may be modified by the function handler (and other modules) until
155  *       @ref nrf_802154_buffer_free_raw is called.
156  * @note @ref nrf_802154_transmit_done_metadata_t.data.transmitted.time will have value of
157  *       @ref NRF_802154_NO_TIMESTAMP as timestamping is not supported for nRF53 family.
158  *
159  * @param[in]  p_frame      Pointer to a buffer that contains PHR and PSDU of the transmitted frame.
160  * @param[in]  p_metadata   Pointer to a metadata structure describing frame passed in @p p_frame.
161  */
162 extern void nrf_802154_transmitted_raw(uint8_t                                   * p_frame,
163                                        const nrf_802154_transmit_done_metadata_t * p_metadata);
164 
165 /**
166  * @brief Notifies that a frame was not transmitted due to a busy channel.
167  *
168  * This function is called if the transmission procedure fails.
169  *
170  * @note Frame data values in @ref nrf_802154_transmit_done_metadata_t.data are invalid for
171  *       @ref nrf_802154_transmit_failed callout.
172  *
173  * @param[in]  p_frame      Pointer to a buffer that contains PHR and PSDU of the frame that was not
174  *                          transmitted.
175  * @param[in]  error        Reason of the failure.
176  * @param[in]  p_metadata   Pointer to a metadata structure describing frame passed in @p p_frame.
177  */
178 extern void nrf_802154_transmit_failed(uint8_t                                   * p_frame,
179                                        nrf_802154_tx_error_t                       error,
180                                        const nrf_802154_transmit_done_metadata_t * p_metadata);
181 
182 #endif /* NRF_802154_CALLOUTS_H_ */
183 
184 /** @} */
185