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 #ifndef NRF_802154_CSMA_CA_H__ 36 #define NRF_802154_CSMA_CA_H__ 37 38 #include <stdbool.h> 39 #include <stdint.h> 40 41 #include "nrf_802154_const.h" 42 #include "nrf_802154_types.h" 43 44 /** 45 * @defgroup nrf_802154_csma_ca 802.15.4 driver CSMA-CA support 46 * @{ 47 * @ingroup nrf_802154 48 * @brief CSMA-CA procedure. 49 */ 50 51 /** 52 * @brief Starts the CSMA-CA procedure for the transmission of a given frame. 53 * 54 * If the CSMA-CA procedure is successful and the frame is transmitted, 55 * the @ref nrf_802154_tx_started() function is called. If the procedure failed and the frame 56 * cannot be transmitted due to busy channel, the @ref nrf_802154_transmit_failed() function 57 * is called. 58 * 59 * @note CSMA-CA does not time out automatically when waiting for ACK. Waiting for ACK must be 60 * timed out by the next layer. The ACK timeout timer must start when 61 * the @ref nrf_802154_tx_started() function is called. 62 * 63 * @param[in] p_data Pointer to a buffer the contains PHR and PSDU of the frame that is 64 * to be transmitted. 65 * @param[in] p_metadata Pointer to metadata structure. Contains detailed properties of data 66 * to transmit. 67 * 68 * @retval true The function always returns true for compatibility reasons 69 */ 70 bool nrf_802154_csma_ca_start(uint8_t * p_data, 71 const nrf_802154_transmit_csma_ca_metadata_t * p_metadata); 72 73 /** 74 * @brief Aborts the ongoing CSMA-CA procedure. 75 * 76 * @note Do not call this function during the execution of @ref nrf_802154_csma_ca_start 77 * (from ISR with higher priority), as it will result in an unrecoverable runtime error. 78 * 79 * If CSMA-CA is not running during the call, this function does nothing and returns true. 80 * 81 * @param[in] term_lvl Termination level of this request. Selects procedures to abort. 82 * @param[in] req_orig Module that originates this request. 83 84 * @retval true CSMA-CA procedure is not running anymore. 85 * @retval false CSMA-CA cannot be stopped because of a too low termination level. 86 */ 87 bool nrf_802154_csma_ca_abort(nrf_802154_term_t term_lvl, req_originator_t req_orig); 88 89 /** 90 * @brief Handles a TX failed event. 91 * 92 * @param[in] p_frame Pointer to a buffer that contains PHR and PSDU of the frame 93 * that was not transmitted. 94 * @param[in] error Cause of failed transmission. 95 * 96 * @retval true TX failed event is to be propagated to the MAC layer. 97 * @retval false TX failed event is not to be propagated to the MAC layer. It is handled 98 * internally in the CSMA-CA module. 99 */ 100 bool nrf_802154_csma_ca_tx_failed_hook(uint8_t * p_frame, nrf_802154_tx_error_t error); 101 102 /** 103 * @brief Handles a TX started event. 104 * 105 * @param[in] p_frame Pointer to a buffer that contains PHR and PSDU of the frame 106 * that is being transmitted. 107 * 108 * @retval true TX started event is to be propagated to the MAC layer. 109 * @retval false TX started event is not to be propagated to the MAC layer. It is handled 110 * internally in the CSMA-CA module. 111 */ 112 bool nrf_802154_csma_ca_tx_started_hook(uint8_t * p_frame); 113 114 /** 115 *@} 116 **/ 117 118 #endif // NRF_802154_CSMA_CA_H__ 119