Wouter van Kleunen
/
nrf52_esb
NRF52_esb
Embed:
(wiki syntax)
Show/hide line numbers
micro_esb.h
00001 /* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved. 00002 * 00003 * The information contained herein is property of Nordic Semiconductor ASA. 00004 * Terms and conditions of usage are described in detail in NORDIC 00005 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 00006 * 00007 * Licensees are granted free, non-transferable use of the information. NO 00008 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 00009 * the file. 00010 * 00011 */ 00012 00013 #ifndef __MICRO_ESB_H 00014 #define __MICRO_ESB_H 00015 00016 #include <stdbool.h> 00017 #include <stdint.h> 00018 //#include "nrf.h" 00019 //#include "nrf51.h" 00020 //#include "nrf51_bitfields.h" 00021 #include "nrf_esb.h" 00022 00023 #define DEBUGPIN1 12 00024 #define DEBUGPIN2 13 00025 #define DEBUGPIN3 14 00026 #define DEBUGPIN4 15 00027 00028 #ifdef UESB_DEBUG 00029 #define DEBUG_PIN_SET(a) (NRF_GPIO->OUTSET = (1 << (a))) 00030 #define DEBUG_PIN_CLR(a) (NRF_GPIO->OUTCLR = (1 << (a))) 00031 #else 00032 #define DEBUG_PIN_SET(a) 00033 #define DEBUG_PIN_CLR(a) 00034 #endif 00035 00036 // Hard coded parameters - change if necessary 00037 #define UESB_CORE_MAX_PAYLOAD_LENGTH 32 00038 #define UESB_CORE_TX_FIFO_SIZE 8 00039 #define UESB_CORE_RX_FIFO_SIZE 8 00040 00041 #define UESB_SYS_TIMER NRF_TIMER2 00042 #define UESB_SYS_TIMER_IRQ_Handler TIMER2_IRQHandler 00043 00044 #define UESB_PPI_TIMER_START 4 00045 #define UESB_PPI_TIMER_STOP 5 00046 #define UESB_PPI_RX_TIMEOUT 6 00047 #define UESB_PPI_TX_START 7 00048 00049 // Interrupt flags 00050 #define UESB_INT_TX_SUCCESS_MSK 0x01 00051 #define UESB_INT_TX_FAILED_MSK 0x02 00052 #define UESB_INT_RX_DR_MSK 0x04 00053 00054 // Configuration parameter definitions 00055 typedef enum { 00056 UESB_PROTOCOL_SB, // Legacy ShockBurst mode - No ACK or retransmit functionality (CURRENTLY NOT IMPLEMENTED!) 00057 UESB_PROTOCOL_ESB, // Enhanced ShockBurst with fixed payload length 00058 UESB_PROTOCOL_ESB_DPL // Enhanced ShockBurst with dynamic payload length 00059 } uesb_protocol_t; 00060 00061 typedef enum { 00062 UESB_MODE_PTX, // Primary transmitter 00063 UESB_MODE_PRX // Primary receiver (CURRENTLY NOT IMPLEMENTED) 00064 } uesb_mode_t; 00065 00066 /* typedef enum { 00067 UESB_BITRATE_2MBPS = RADIO_MODE_MODE_Nrf_2Mbit, 00068 UESB_BITRATE_1MBPS = RADIO_MODE_MODE_Nrf_1Mbit, 00069 UESB_BITRATE_250KBPS = RADIO_MODE_MODE_Nrf_250Kbit 00070 } uesb_bitrate_t; */ 00071 00072 typedef enum { 00073 UESB_BITRATE_2MBPS = NRF_ESB_BITRATE_1MBPS, 00074 UESB_BITRATE_1MBPS = NRF_ESB_BITRATE_2MBPS, 00075 UESB_BITRATE_250KBPS = NRF_ESB_BITRATE_250KBPS 00076 } uesb_bitrate_t; 00077 00078 typedef enum { 00079 UESB_CRC_16BIT = RADIO_CRCCNF_LEN_Two, 00080 UESB_CRC_8BIT = RADIO_CRCCNF_LEN_One, 00081 UESB_CRC_OFF = RADIO_CRCCNF_LEN_Disabled 00082 } uesb_crc_t; 00083 00084 typedef enum { 00085 UESB_TX_POWER_4DBM = RADIO_TXPOWER_TXPOWER_Pos4dBm, 00086 UESB_TX_POWER_0DBM = RADIO_TXPOWER_TXPOWER_0dBm, 00087 UESB_TX_POWER_NEG4DBM = RADIO_TXPOWER_TXPOWER_Neg4dBm, 00088 UESB_TX_POWER_NEG8DBM = RADIO_TXPOWER_TXPOWER_Neg8dBm, 00089 UESB_TX_POWER_NEG12DBM = RADIO_TXPOWER_TXPOWER_Neg12dBm, 00090 UESB_TX_POWER_NEG16DBM = RADIO_TXPOWER_TXPOWER_Neg16dBm, 00091 UESB_TX_POWER_NEG20DBM = RADIO_TXPOWER_TXPOWER_Neg20dBm, 00092 UESB_TX_POWER_NEG30DBM = RADIO_TXPOWER_TXPOWER_Neg30dBm 00093 } uesb_tx_power_t; 00094 00095 typedef enum { 00096 UESB_TXMODE_AUTO, // Automatic TX mode - When the TX fifo is non-empty and the radio is idle packets will be sent automatically. 00097 UESB_TXMODE_MANUAL, // Manual TX mode - Packets will not be sent until uesb_start_tx() is called. Can be used to ensure consistent packet timing. 00098 UESB_TXMODE_MANUAL_START // Manual start TX mode - Packets will not be sent until uesb_start_tx() is called, but transmission will continue automatically until the TX FIFO is empty. 00099 } uesb_tx_mode_t; 00100 00101 // Internal state definition 00102 typedef enum { 00103 UESB_STATE_UNINITIALIZED, 00104 UESB_STATE_IDLE, 00105 UESB_STATE_PTX_TX, 00106 UESB_STATE_PTX_TX_ACK, 00107 UESB_STATE_PTX_RX_ACK, 00108 UESB_STATE_PRX, 00109 UESB_STATE_PRX_SEND_ACK, 00110 UESB_STATE_PRX_SEND_ACK_PAYLOAD 00111 } uesb_mainstate_t; 00112 00113 typedef void (*uesb_event_handler_t)(void); 00114 00115 // Main UESB configuration struct, contains all radio parameters 00116 typedef struct 00117 { 00118 uesb_protocol_t protocol; 00119 uesb_mode_t mode; 00120 uesb_event_handler_t event_handler; 00121 00122 // General RF parameters 00123 uesb_bitrate_t bitrate; 00124 uesb_crc_t crc; 00125 uint8_t rf_channel; 00126 uint8_t payload_length; 00127 uint8_t rf_addr_length; 00128 00129 uesb_tx_power_t tx_output_power; 00130 uint8_t tx_address[5]; 00131 uint8_t rx_address_p0[5]; 00132 uint8_t rx_address_p1[5]; 00133 uint8_t rx_address_p2; 00134 uint8_t rx_address_p3; 00135 uint8_t rx_address_p4; 00136 uint8_t rx_address_p5; 00137 uint8_t rx_address_p6; 00138 uint8_t rx_address_p7; 00139 uint8_t rx_pipes_enabled; 00140 00141 // ESB specific features 00142 uint8_t dynamic_payload_length_enabled; 00143 uint8_t dynamic_ack_enabled; 00144 uint16_t retransmit_delay; 00145 uint16_t retransmit_count; 00146 00147 // Control settings 00148 uesb_tx_mode_t tx_mode; 00149 00150 uint8_t radio_irq_priority; 00151 }uesb_config_t; 00152 00153 // Default radio parameters, roughly equal to nRF24L default parameters (except CRC which is set to 16-bit, and protocol set to DPL) 00154 #define UESB_DEFAULT_CONFIG {.mode = UESB_MODE_PTX, \ 00155 .protocol = UESB_PROTOCOL_ESB_DPL, \ 00156 .event_handler = 0, \ 00157 .rf_channel = 2, \ 00158 .payload_length = 61, \ 00159 .rf_addr_length = 5, \ 00160 .bitrate = UESB_BITRATE_2MBPS, \ 00161 .crc = UESB_CRC_16BIT, \ 00162 .tx_output_power = UESB_TX_POWER_0DBM, \ 00163 .rx_address_p0 = {0xE7, 0xE7, 0xE7, 0xE7, 0xE7}, \ 00164 .rx_address_p1 = {0xC2, 0xC2, 0xC2, 0xC2, 0xC2}, \ 00165 .rx_address_p2 = 0xC3, \ 00166 .rx_address_p3 = 0xC4, \ 00167 .rx_address_p4 = 0xC5, \ 00168 .rx_address_p5 = 0xC6, \ 00169 .rx_address_p6 = 0xC7, \ 00170 .rx_address_p7 = 0xC8, \ 00171 .rx_pipes_enabled = 0x3F, \ 00172 .dynamic_payload_length_enabled = 1, \ 00173 .dynamic_ack_enabled = 0, \ 00174 .retransmit_delay = 250, \ 00175 .retransmit_count = 3, \ 00176 .tx_mode = UESB_TXMODE_AUTO, \ 00177 .radio_irq_priority = 1} 00178 00179 enum uesb_event_type_t {UESB_EVENT_TX_SUCCESS, UESB_EVENT_TX_FAILED, UESB_EVENT_RX_RECEIVED}; 00180 00181 typedef enum {UESB_ADDRESS_PIPE0, UESB_ADDRESS_PIPE1, UESB_ADDRESS_PIPE2, UESB_ADDRESS_PIPE3, UESB_ADDRESS_PIPE4, UESB_ADDRESS_PIPE5, UESB_ADDRESS_PIPE6, UESB_ADDRESS_PIPE7} uesb_address_type_t; 00182 00183 typedef struct 00184 { 00185 enum uesb_event_type_t type; 00186 }uesb_event_t; 00187 00188 typedef struct 00189 { 00190 uint8_t length; 00191 uint8_t pipe; 00192 int8_t rssi; 00193 uint8_t noack; 00194 uint8_t data[UESB_CORE_MAX_PAYLOAD_LENGTH]; 00195 }uesb_payload_t; 00196 00197 typedef struct 00198 { 00199 uesb_payload_t *payload_ptr[UESB_CORE_TX_FIFO_SIZE]; 00200 uint32_t entry_point; 00201 uint32_t exit_point; 00202 uint32_t count; 00203 }uesb_payload_tx_fifo_t; 00204 00205 typedef struct 00206 { 00207 uesb_payload_t *payload_ptr[UESB_CORE_RX_FIFO_SIZE]; 00208 uint32_t entry_point; 00209 uint32_t exit_point; 00210 uint32_t count; 00211 }uesb_payload_rx_fifo_t; 00212 00213 uint32_t uesb_init(uesb_config_t *parameters); 00214 00215 uint32_t uesb_disable(void); 00216 00217 bool uesb_is_idle(void); 00218 00219 uint32_t uesb_write_tx_payload(uesb_payload_t *payload); 00220 00221 uint32_t uesb_write_tx_payload_noack(uesb_payload_t *payload); 00222 00223 uint32_t uesb_write_ack_payload(uesb_payload_t *payload); 00224 00225 uint32_t uesb_read_rx_payload(uesb_payload_t *payload); 00226 00227 uint32_t uesb_start_tx(void); 00228 00229 uint32_t uesb_start_rx(void); 00230 00231 uint32_t uesb_stop_rx(void); 00232 00233 uint32_t uesb_get_tx_attempts(uint32_t *attempts); 00234 00235 uint32_t uesb_flush_tx(void); 00236 00237 uint32_t uesb_flush_rx(void); 00238 00239 uint32_t uesb_get_clear_interrupts(uint32_t *interrupts); 00240 00241 uint32_t uesb_set_address(uesb_address_type_t address, const uint8_t *data_ptr); 00242 00243 uint32_t uesb_set_rf_channel(uint32_t channel); 00244 00245 uint32_t uesb_set_tx_power(uesb_tx_power_t tx_output_power); 00246 00247 #endif
Generated on Sun Jul 17 2022 00:47:52 by 1.7.2