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 notifications triggered directly by the nrf 802.15.4 radio driver.
38 *
39 */
40
41 #define NRF_802154_MODULE_ID NRF_802154_DRV_MODULE_ID_NOTIFICATION
42
43 #include "nrf_802154_notification.h"
44
45 #if NRF_802154_NOTIFICATION_IMPL == NRF_802154_NOTIFICATION_IMPL_DIRECT
46
47 #include <stdbool.h>
48 #include <stddef.h>
49 #include <stdint.h>
50
51 #include "nrf_802154.h"
52 #include "nrf_802154_co.h"
53 #include "nrf_802154_critical_section.h"
54 #include "nrf_802154_debug.h"
55 #include "nrf_802154_tx_work_buffer.h"
56
57 #define RAW_LENGTH_OFFSET 0
58 #define RAW_PAYLOAD_OFFSET 1
59
nrf_802154_notification_init(void)60 void nrf_802154_notification_init(void)
61 {
62 // Intentionally empty
63 }
64
nrf_802154_notify_received(uint8_t * p_data,int8_t power,uint8_t lqi)65 void nrf_802154_notify_received(uint8_t * p_data, int8_t power, uint8_t lqi)
66 {
67 nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
68
69 nrf_802154_co_received_raw(p_data, power, lqi);
70
71 nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
72 }
73
nrf_802154_notify_receive_failed(nrf_802154_rx_error_t error,uint32_t id,bool allow_drop)74 bool nrf_802154_notify_receive_failed(nrf_802154_rx_error_t error, uint32_t id, bool allow_drop)
75 {
76 (void)allow_drop;
77
78 nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
79
80 nrf_802154_co_receive_failed(error, id);
81
82 nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
83
84 return true;
85 }
86
nrf_802154_notify_transmitted(uint8_t * p_frame,nrf_802154_transmit_done_metadata_t * p_metadata)87 void nrf_802154_notify_transmitted(uint8_t * p_frame,
88 nrf_802154_transmit_done_metadata_t * p_metadata)
89 {
90 nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
91
92 // Update the transmitted frame contents and update frame status flags
93 nrf_802154_tx_work_buffer_original_frame_update(p_frame,
94 &p_metadata->frame_props);
95 // Notify
96 nrf_802154_co_transmitted_raw(p_frame, p_metadata);
97
98 nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
99 }
100
nrf_802154_notify_transmit_failed(uint8_t * p_frame,nrf_802154_tx_error_t error,const nrf_802154_transmit_done_metadata_t * p_metadata)101 void nrf_802154_notify_transmit_failed(uint8_t * p_frame,
102 nrf_802154_tx_error_t error,
103 const nrf_802154_transmit_done_metadata_t * p_metadata)
104 {
105 nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
106
107 // Notify
108 nrf_802154_co_transmit_failed(p_frame, error, p_metadata);
109
110 nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
111 }
112
nrf_802154_notify_energy_detected(const nrf_802154_energy_detected_t * p_result)113 void nrf_802154_notify_energy_detected(const nrf_802154_energy_detected_t * p_result)
114 {
115 nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
116
117 nrf_802154_co_energy_detected(p_result);
118
119 nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
120 }
121
nrf_802154_notify_energy_detection_failed(nrf_802154_ed_error_t error)122 void nrf_802154_notify_energy_detection_failed(nrf_802154_ed_error_t error)
123 {
124 nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
125
126 nrf_802154_co_energy_detection_failed(error);
127
128 nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
129 }
130
nrf_802154_notify_cca(bool is_free)131 void nrf_802154_notify_cca(bool is_free)
132 {
133 nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
134
135 nrf_802154_co_cca_done(is_free);
136
137 nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
138 }
139
nrf_802154_notify_cca_failed(nrf_802154_cca_error_t error)140 void nrf_802154_notify_cca_failed(nrf_802154_cca_error_t error)
141 {
142 nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
143
144 nrf_802154_co_cca_failed(error);
145
146 nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
147 }
148
149 #endif /* NRF_802154_NOTIFICATION_IMPL == NRF_802154_NOTIFICATION_IMPL_DIRECT */
150