22 #ifndef __NRF5_ESB_H__
23 #define __NRF5_ESB_H__
29 #if MAX_MESSAGE_SIZE > (32)
30 #error "Unsupported message size. (MAX_MESSAGE_SIZE)"
34 #if MY_NRF5_ESB_RX_BUFFER_SIZE < (4)
35 #error "MY_NRF5_ESB_RX_BUFFER_SIZE must be greater than 3."
46 #define NRF5_ESB_ACK_WAIT \
47 ((NRF5_ESB_RAMP_UP_TIME << 1) + (9 << NRF5_ESB_byte_time()))
51 #define NRF5_ESB_MAX_PACKET_TIME \
52 ((MAX_MESSAGE_SIZE+sizeof(nrf5_radio_packet_s)) << NRF5_ESB_byte_time())
55 #define NRF5_ESB_ARD (1500)
58 #define NRF5_ESB_ARC_ACK (3)
61 #define NRF5_ESB_ARC_NOACK (3)
64 #define NRF5_ESB_BC_ARC (3)
67 #define NRF5_ESB_NODE_ADDR (0)
68 #define NRF5_ESB_NODE_ADDR_MSK (0xffffff00UL)
71 #define NRF5_ESB_TX_ADDR (4)
72 #define NRF5_ESB_TX_ADDR_MSK (0xffffff00UL)
75 #define NRF5_ESB_BC_ADDR (7)
76 #define NRF5_ESB_BC_ADDR_MSK (0xffffffffUL)
79 #define NRF5_EBS_RADIO_INT_RX (RADIO_INTENSET_ADDRESS_Msk | RADIO_INTENSET_END_Msk | RADIO_INTENSET_DISABLED_Msk)
82 #define NRF5_EBS_RADIO_INT_TX (RADIO_INTENSET_ADDRESS_Msk | RADIO_INTENSET_DISABLED_Msk)
85 #define NRF5_ESB_SHORTS_RX \
86 (RADIO_SHORTS_READY_START_Msk | RADIO_SHORTS_END_START_Msk | \
87 RADIO_SHORTS_DISABLED_RXEN_Msk | \
88 RADIO_SHORTS_ADDRESS_RSSISTART_Msk | RADIO_SHORTS_DISABLED_RSSISTOP_Msk)
91 #define NRF5_ESB_SHORTS_TX \
92 (RADIO_SHORTS_READY_START_Msk | RADIO_SHORTS_END_START_Msk | \
93 RADIO_SHORTS_DISABLED_TXEN_Msk)
96 #define NRF5_ESB_SHORTS_RX_TX \
97 (RADIO_SHORTS_END_DISABLE_Msk | RADIO_SHORTS_DISABLED_TXEN_Msk | \
98 RADIO_SHORTS_READY_START_Msk)
101 #define NRF5_ESB_SHORTS_TX_RX \
102 (RADIO_SHORTS_END_DISABLE_Msk | RADIO_SHORTS_DISABLED_RXEN_Msk | \
103 RADIO_SHORTS_READY_START_Msk | \
104 RADIO_SHORTS_ADDRESS_RSSISTART_Msk | RADIO_SHORTS_DISABLED_RSSISTOP_Msk)
110 #define NRF5_ESB_PPI_LAST_CHANNEL (PPI_CH_NUM - 1)
111 #if (NRF5_RADIO_TIMER_IRQN != TIMER0_IRQn)
113 #define NRF5_ESB_PPI_TIMER_START (NRF5_ESB_PPI_LAST_CHANNEL - 1)
114 #define NRF5_ESB_PPI_TIMER_RADIO_DISABLE (NRF5_ESB_PPI_LAST_CHANNEL)
117 #define NRF5_ESB_USE_PREDEFINED_PPI
118 #define NRF5_ESB_PPI_TIMER_START (NRF5_ESB_PPI_LAST_CHANNEL)
119 #define NRF5_ESB_PPI_TIMER_RADIO_DISABLE 22
121 #define NRF5_ESB_PPI_BITS \
122 ((1 << NRF5_ESB_PPI_TIMER_START) | \
123 (1 << NRF5_ESB_PPI_TIMER_RADIO_DISABLE))
128 #define NRF5_ESB_RAMP_UP_TIME (140)
131 static bool NRF5_ESB_initialize();
132 static void NRF5_ESB_powerDown();
133 static void NRF5_ESB_powerUp();
134 static void NRF5_ESB_sleep();
135 static void NRF5_ESB_standBy();
136 static bool NRF5_ESB_sanityCheck();
138 static void NRF5_ESB_setNodeAddress(
const uint8_t address);
139 static uint8_t NRF5_ESB_getNodeID();
141 static void NRF5_ESB_startListening();
142 static bool NRF5_ESB_isDataAvailable();
143 static uint8_t NRF5_ESB_readMessage(
void *
data);
145 static bool NRF5_ESB_sendMessage(uint8_t recipient,
const void *buf, uint8_t len,
const bool noACK);
147 static int16_t NRF5_ESB_getSendingRSSI();
148 static int16_t NRF5_ESB_getReceivingRSSI();
151 static inline uint8_t NRF5_ESB_byte_time();
169 #ifdef MY_DEBUG_VERBOSE_NRF5_ESB
178 #ifdef MY_DEBUG_VERBOSE_NRF5_ESB
179 static uint32_t intcntr_addrmatch;
180 static uint32_t intcntr_ready;
181 static uint32_t intcntr_end;
182 static uint32_t intcntr_disabled;
183 static uint32_t intcntr_timer_cc3;