1 /*
2 * Copyright (c) 2017, 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 * @file
37 * This file implements requests to the driver triggered directly by the MAC layer.
38 *
39 */
40
41 #include "nrf_802154_request.h"
42
43 #if NRF_802154_REQUEST_IMPL == NRF_802154_REQUEST_IMPL_DIRECT
44
45 #include <stdbool.h>
46 #include <stdint.h>
47
48 #include "nrf_802154_core.h"
49 #include "mac_features/nrf_802154_delayed_trx.h"
50 #include "mac_features/nrf_802154_csma_ca.h"
51 #include "hal/nrf_radio.h"
52
53 #define REQUEST_FUNCTION_PARMS(func_core, ...) \
54 bool result; \
55 \
56 result = func_core(__VA_ARGS__); \
57 \
58 return result;
59
60 #define REQUEST_FUNCTION(func_core) \
61 bool result; \
62 \
63 result = func_core(); \
64 \
65 return result;
66
nrf_802154_request_init(void)67 void nrf_802154_request_init(void)
68 {
69 // Intentionally empty
70 }
71
nrf_802154_request_sleep(nrf_802154_term_t term_lvl)72 bool nrf_802154_request_sleep(nrf_802154_term_t term_lvl)
73 {
74 REQUEST_FUNCTION_PARMS(nrf_802154_core_sleep, term_lvl)
75 }
76
nrf_802154_request_receive(nrf_802154_term_t term_lvl,req_originator_t req_orig,nrf_802154_notification_func_t notify_function,bool notify_abort,uint32_t id)77 bool nrf_802154_request_receive(nrf_802154_term_t term_lvl,
78 req_originator_t req_orig,
79 nrf_802154_notification_func_t notify_function,
80 bool notify_abort,
81 uint32_t id)
82 {
83 REQUEST_FUNCTION_PARMS(nrf_802154_core_receive,
84 term_lvl,
85 req_orig,
86 notify_function,
87 notify_abort,
88 id)
89 }
90
nrf_802154_request_transmit(nrf_802154_term_t term_lvl,req_originator_t req_orig,uint8_t * p_data,nrf_802154_transmit_params_t * p_params,nrf_802154_notification_func_t notify_function)91 bool nrf_802154_request_transmit(nrf_802154_term_t term_lvl,
92 req_originator_t req_orig,
93 uint8_t * p_data,
94 nrf_802154_transmit_params_t * p_params,
95 nrf_802154_notification_func_t notify_function)
96 {
97 REQUEST_FUNCTION_PARMS(nrf_802154_core_transmit,
98 term_lvl,
99 req_orig,
100 p_data,
101 p_params,
102 notify_function)
103 }
104
nrf_802154_request_ack_timeout_handle(const nrf_802154_ack_timeout_handle_params_t * p_param)105 bool nrf_802154_request_ack_timeout_handle(const nrf_802154_ack_timeout_handle_params_t * p_param)
106 {
107 REQUEST_FUNCTION_PARMS(nrf_802154_core_ack_timeout_handle, p_param);
108 }
109
nrf_802154_request_energy_detection(nrf_802154_term_t term_lvl,uint32_t time_us)110 bool nrf_802154_request_energy_detection(nrf_802154_term_t term_lvl, uint32_t time_us)
111 {
112 REQUEST_FUNCTION_PARMS(nrf_802154_core_energy_detection, term_lvl, time_us)
113 }
114
nrf_802154_request_cca(nrf_802154_term_t term_lvl)115 bool nrf_802154_request_cca(nrf_802154_term_t term_lvl)
116 {
117 REQUEST_FUNCTION_PARMS(nrf_802154_core_cca, term_lvl)
118 }
119
120 #if NRF_802154_CARRIER_FUNCTIONS_ENABLED
121
nrf_802154_request_continuous_carrier(nrf_802154_term_t term_lvl)122 bool nrf_802154_request_continuous_carrier(nrf_802154_term_t term_lvl)
123 {
124 REQUEST_FUNCTION_PARMS(nrf_802154_core_continuous_carrier, term_lvl)
125 }
126
nrf_802154_request_modulated_carrier(nrf_802154_term_t term_lvl,const uint8_t * p_data)127 bool nrf_802154_request_modulated_carrier(nrf_802154_term_t term_lvl,
128 const uint8_t * p_data)
129 {
130 REQUEST_FUNCTION_PARMS(nrf_802154_core_modulated_carrier, term_lvl, p_data)
131 }
132
133 #endif // NRF_802154_CARRIER_FUNCTIONS_ENABLED
134
nrf_802154_request_buffer_free(uint8_t * p_data)135 bool nrf_802154_request_buffer_free(uint8_t * p_data)
136 {
137 REQUEST_FUNCTION_PARMS(nrf_802154_core_notify_buffer_free, p_data)
138 }
139
nrf_802154_request_antenna_update(void)140 bool nrf_802154_request_antenna_update(void)
141 {
142 REQUEST_FUNCTION(nrf_802154_core_antenna_update)
143 }
144
nrf_802154_request_channel_update(req_originator_t req_orig)145 bool nrf_802154_request_channel_update(req_originator_t req_orig)
146 {
147 REQUEST_FUNCTION_PARMS(nrf_802154_core_channel_update, req_orig)
148 }
149
nrf_802154_request_cca_cfg_update(void)150 bool nrf_802154_request_cca_cfg_update(void)
151 {
152 REQUEST_FUNCTION(nrf_802154_core_cca_cfg_update)
153 }
154
nrf_802154_request_rssi_measure(void)155 bool nrf_802154_request_rssi_measure(void)
156 {
157 REQUEST_FUNCTION(nrf_802154_core_rssi_measure)
158 }
159
nrf_802154_request_rssi_measurement_get(int8_t * p_rssi)160 bool nrf_802154_request_rssi_measurement_get(int8_t * p_rssi)
161 {
162 REQUEST_FUNCTION_PARMS(nrf_802154_core_last_rssi_measurement_get, p_rssi)
163 }
164
are_frame_properties_valid(const nrf_802154_transmitted_frame_props_t * p_props)165 static inline bool are_frame_properties_valid(const nrf_802154_transmitted_frame_props_t * p_props)
166 {
167 return p_props->dynamic_data_is_set || !(p_props->is_secured);
168 }
169
170 #if NRF_802154_DELAYED_TRX_ENABLED
nrf_802154_request_transmit_raw_at(uint8_t * p_data,uint64_t tx_time,const nrf_802154_transmit_at_metadata_t * p_metadata)171 bool nrf_802154_request_transmit_raw_at(uint8_t * p_data,
172 uint64_t tx_time,
173 const nrf_802154_transmit_at_metadata_t * p_metadata)
174 {
175 REQUEST_FUNCTION_PARMS(nrf_802154_delayed_trx_transmit, p_data, tx_time, p_metadata);
176 }
177
nrf_802154_request_transmit_at_cancel(void)178 bool nrf_802154_request_transmit_at_cancel(void)
179 {
180 REQUEST_FUNCTION(nrf_802154_delayed_trx_transmit_cancel);
181 }
182
nrf_802154_request_receive_at(uint64_t rx_time,uint32_t timeout,uint8_t channel,uint32_t id)183 bool nrf_802154_request_receive_at(uint64_t rx_time,
184 uint32_t timeout,
185 uint8_t channel,
186 uint32_t id)
187 {
188 REQUEST_FUNCTION_PARMS(nrf_802154_delayed_trx_receive, rx_time, timeout, channel, id);
189 }
190
nrf_802154_request_receive_at_cancel(uint32_t id)191 bool nrf_802154_request_receive_at_cancel(uint32_t id)
192 {
193 REQUEST_FUNCTION_PARMS(nrf_802154_delayed_trx_receive_cancel, id);
194 }
195
196 #endif
197
nrf_802154_request_csma_ca_start(uint8_t * p_data,const nrf_802154_transmit_csma_ca_metadata_t * p_metadata)198 bool nrf_802154_request_csma_ca_start(uint8_t * p_data,
199 const nrf_802154_transmit_csma_ca_metadata_t * p_metadata)
200 {
201 REQUEST_FUNCTION_PARMS(nrf_802154_csma_ca_start, p_data, p_metadata);
202 }
203
204 #endif /* NRF_802154_REQUEST_IMPL == NRF_802154_REQUEST_IMPL_DIRECT */
205