1 /* 2 * Copyright (C) 2020 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 4. Any redistribution, use, or modification is done solely for 17 * personal benefit and not for any commercial purpose or for 18 * monetary gain. 19 * 20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN 24 * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Please inquire about commercial licensing options at 34 * [email protected] 35 * 36 */ 37 38 /* 39 * radio.h 40 */ 41 42 #ifndef RADIO_H 43 #define RADIO_H 44 45 #include "btstack_bool.h" 46 #include <stdint.h> 47 48 #if defined __cplusplus 49 extern "C" { 50 #endif 51 52 /* API_START */ 53 54 typedef struct { 55 void (*tx_done)(void); 56 void (*rx_done)(void); 57 } radio_callbacks_t; 58 59 typedef enum { 60 RADIO_TRANSITION_TX_ONLY, 61 RADIO_TRANSITION_TX_TO_RX, 62 } radio_transition_t; 63 64 typedef enum { 65 RADIO_RESULT_OK, 66 RADIO_RESULT_CRC_ERROR, 67 RADIO_RESULT_TIMEOUT, 68 } radio_result_t; 69 70 typedef void (*radio_callback_t)(radio_result_t result); 71 72 /** 73 * Init radio 74 */ 75 void radio_init(void); 76 77 /** 78 * Set Access Address 79 * @param access_address 80 */ 81 void radio_set_access_address(uint32_t access_address); 82 83 /** 84 * Enable RF CLock 85 * @param wait_until_ready if true, waits until HF clock is ready 86 */ 87 void radio_hf_clock_enable(bool wait_until_ready); 88 89 /** 90 * Disable RF CLock 91 */ 92 void radio_hf_clock_disable(void); 93 94 /** 95 * Set CRC Init value 96 * @param crc 24-bit init value 97 */ 98 void radio_set_crc_init(uint32_t crc); 99 100 /** 101 * Set Channel: frequency and whitening 102 * @param channel 0..39 103 */ 104 void radio_set_channel(uint8_t channel); 105 106 /** 107 * Transmit packet. 108 * @param callback 109 * @param transition - on RADIO_TRANSITION_TX_TO_RX, radio transitions to RX 110 * @param packet 111 * @param len 112 */ 113 void radio_transmit(radio_callback_t callback, radio_transition_t transition, const uint8_t * packet, uint16_t len); 114 115 /** 116 * Receive packet 117 * @note automatic transition to TX 118 * @param callback 119 * @param timeout_us if radio was disabled before (i.e. not in tx -> rx transition) 120 * @param buffer 121 * @param len 122 * @param rssi (out) 123 */ 124 void radio_receive(radio_callback_t callback, uint32_t timeout_us, uint8_t * buffer, uint16_t len, int8_t * rssi); 125 126 /** 127 * Stop active transmission, e.g. tx after rx 128 * @param callback 129 */ 130 void radio_stop(radio_callback_t callback); 131 132 /* API_END */ 133 134 #if defined __cplusplus 135 } 136 #endif 137 138 #endif // LL_H 139