libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
common/radio.h
Go to the documentation of this file.
1/** @addtogroup radio_defines
2 *
3 * @author @htmlonly &copy; @endhtmlonly 2016 Maxim Sloyko <maxims@google.com>
4 * @author @htmlonly &copy; @endhtmlonly 2021 Eduard Drusa <ventyl86 at netkosice dot sk>
5 *
6 **/
7
8/*
9 * This file is part of the libopencm3 project.
10 *
11 * Copyright (C) 2017-2018 Unicore MX project<dev(at)lists(dot)unicore-mx(dot)org>
12 * Copyright (C) 2021 Eduard Drusa <ventyl86(at)netkosice(dot)sk>
13 *
14 * This library is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public License
25 * along with this library. If not, see <http://www.gnu.org/licenses/>.
26 */
27
28#pragma once
29
33/**@{*/
34
35/* 2.4 GHz Radio */
36
37/* Tasks */
38
39#define RADIO_TASK_TXEN MMIO32(RADIO_BASE + 0x000)
40#define RADIO_TASK_RXEN MMIO32(RADIO_BASE + 0x004)
41#define RADIO_TASK_START MMIO32(RADIO_BASE + 0x008)
42#define RADIO_TASK_STOP MMIO32(RADIO_BASE + 0x00C)
43#define RADIO_TASK_DISABLE MMIO32(RADIO_BASE + 0x010)
44#define RADIO_TASK_RSSISTART MMIO32(RADIO_BASE + 0x014)
45#define RADIO_TASK_RSSISTOP MMIO32(RADIO_BASE + 0x018)
46#define RADIO_TASK_BCSTART MMIO32(RADIO_BASE + 0x01C)
47#define RADIO_TASK_BCSTOP MMIO32(RADIO_BASE + 0x020)
48
49/* Events */
50
51#define RADIO_EVENT_READY MMIO32(RADIO_BASE + 0x100)
52#define RADIO_EVENT_ADDRESS MMIO32(RADIO_BASE + 0x104)
53#define RADIO_EVENT_PAYLOAD MMIO32(RADIO_BASE + 0x108)
54#define RADIO_EVENT_END MMIO32(RADIO_BASE + 0x10C)
55#define RADIO_EVENT_DISABLED MMIO32(RADIO_BASE + 0x110)
56#define RADIO_EVENT_DEVMATCH MMIO32(RADIO_BASE + 0x114)
57#define RADIO_EVENT_DEVMISS MMIO32(RADIO_BASE + 0x118)
58#define RADIO_EVENT_RSSIEND MMIO32(RADIO_BASE + 0x11C)
59
60/* Registers */
61
62#define RADIO_SHORTS _PERIPH_SHORTS(RADIO_BASE)
63#define RADIO_INTENSET _PERIPH_INTENSET(RADIO_BASE)
64#define RADIO_INTENCLR _PERIPH_INTENCLR(RADIO_BASE)
65#define RADIO_CRCSTATUS MMIO32(RADIO_BASE + 0x400)
66#define RADIO_RXMATCH MMIO32(RADIO_BASE + 0x408)
67#define RADIO_RXCRC MMIO32(RADIO_BASE + 0x40C)
68#define RADIO_DAI MMIO32(RADIO_BASE + 0x410)
69#define RADIO_PACKETPTR MMIO32(RADIO_BASE + 0x504)
70#define RADIO_FREQUENCY MMIO32(RADIO_BASE + 0x508)
71#define RADIO_TXPOWER MMIO32(RADIO_BASE + 0x50C)
72#define RADIO_MODE MMIO32(RADIO_BASE + 0x510)
73#define RADIO_PCNF0 MMIO32(RADIO_BASE + 0x514)
74#define RADIO_PCNF1 MMIO32(RADIO_BASE + 0x518)
75#define RADIO_BASE0 MMIO32(RADIO_BASE + 0x51C)
76#define RADIO_BASE1 MMIO32(RADIO_BASE + 0x520)
77#define RADIO_PREFIX0 MMIO32(RADIO_BASE + 0x524)
78#define RADIO_PREFIX1 MMIO32(RADIO_BASE + 0x528)
79#define RADIO_TXADDRESS MMIO32(RADIO_BASE + 0x52C)
80#define RADIO_RXADDRESSES MMIO32(RADIO_BASE + 0x530)
81#define RADIO_CRCCNF MMIO32(RADIO_BASE + 0x534)
82#define RADIO_CRCPOLY MMIO32(RADIO_BASE + 0x538)
83#define RADIO_CRCINIT MMIO32(RADIO_BASE + 0x53C)
84#define RADIO_TEST MMIO32(RADIO_BASE + 0x540)
85#define RADIO_TIFS MMIO32(RADIO_BASE + 0x544)
86#define RADIO_RSSISAMPLE MMIO32(RADIO_BASE + 0x548)
87#define RADIO_STATE MMIO32(RADIO_BASE + 0x550)
88#define RADIO_DATAWHITEIV MMIO32(RADIO_BASE + 0x554)
89#define RADIO_BCC MMIO32(RADIO_BASE + 0x560)
90
91/* Device Address Base segment */
92#define RADIO_DAB(n) MMIO32(RADIO_BASE + 0x600 + 0x4 * (n))
93/* Device Address Prefix segment */
94#define RADIO_DAP(n) MMIO32(RADIO_BASE + 0x620 + 0x4 * (n))
95#define RADIO_DACNF MMIO32(RADIO_BASE + 0x640)
96
97/* Override Registers */
98#define RADIO_OVERRIDE(n) MMIO32(RADIO_BASE + 0x724 + 0x4 * (n))
99#define RADIO_POWER MMIO32(RADIO_BASE + 0xFFC)
100
101/* Register Details */
102
103/** @addtogroup radio_shorts Radio event -> task shortcuts
104 * @{
105 */
106#define RADIO_SHORTS_READY_START (1 << 0)
107#define RADIO_SHORTS_END_DISABLE (1 << 1)
108#define RADIO_SHORTS_DISABLED_TXEN (1 << 2)
109#define RADIO_SHORTS_DISABLED_RXEN (1 << 3)
110#define RADIO_SHORTS_ADDRESS_RSSISTART (1 << 4)
111#define RADIO_SHORTS_END_START (1 << 5)
112#define RADIO_SHORTS_ADDRESS_BCSTART (1 << 6)
113#define RADIO_SHORTS_DISABLED_RSSISTOP (1 << 8)
114
115/**@}*/
116
117/** @addtogroup radio_inten Radio interrupts
118 * @{
119 */
120#define RADIO_INTEN_READY (1 << 0)
121#define RADIO_INTEN_ADDRESS (1 << 1)
122#define RADIO_INTEN_PAYLOAD (1 << 2)
123#define RADIO_INTEN_END (1 << 3)
124#define RADIO_INTEN_DISABLED (1 << 4)
125#define RADIO_INTEN_DEVMATCH (1 << 5)
126#define RADIO_INTEN_DEVMISS (1 << 6)
127#define RADIO_INTEN_RSSIEND (1 << 7)
128#define RADIO_INTEN_BCMATCH (1 << 10)
129
130/**@}*/
131
132#define RADIO_PCNF0_LFLEN_SHIFT (0)
133#define RADIO_PCNF0_LFLEN_MASK (0xf << RADIO_PCNF0_LFLEN_SHIFT)
134#define RADIO_PCNF0_LFLEN_MASKED(V) (((V) << RADIO_PCNF0_LFLEN_SHIFT) \
135 & RADIO_PCNF0_LFLEN_MASK)
136
137#define RADIO_PCNF0_S0LEN_SHIFT (8)
138#define RADIO_PCNF0_S0LEN_MASK (1 << RADIO_PCNF0_S0LEN_SHIFT)
139#define RADIO_PCNF0_S0LEN_MASKED(V) (((V) << RADIO_PCNF0_S0LEN_SHIFT) \
140 & RADIO_PCNF0_S0LEN_MASK)
141
142#define RADIO_PCNF0_S1LEN_SHIFT (16)
143#define RADIO_PCNF0_S1LEN_MASK (0xf << RADIO_PCNF0_S1LEN_SHIFT)
144#define RADIO_PCNF0_S1LEN_MASKED(V) (((V) << RADIO_PCNF0_S1LEN_SHIFT) & \
145 RADIO_PCNF0_S1LEN_MASK)
146
147#define RADIO_PCNF1_MAXLEN_SHIFT (0)
148#define RADIO_PCNF1_MAXLEN_MASK (0xff << RADIO_PCNF1_MAXLEN_SHIFT)
149#define RADIO_PCNF1_MAXLEN_MASKED(V) (((V) << RADIO_PCNF1_MAXLEN_SHIFT) & \
150 RADIO_PCNF1_MAXLEN_MASK)
151
152#define RADIO_PCNF1_STATLEN_SHIFT (8)
153#define RADIO_PCNF1_STATLEN_MASK (0xff << RADIO_PCNF1_STATLEN_SHIFT)
154#define RADIO_PCNF1_STATLEN_MASKED(V) (((V) << RADIO_PCNF1_STATLEN_SHIFT) & \
155 RADIO_PCNF1_STATLEN_MASK)
156
157#define RADIO_PCNF1_BALEN_SHIFT (16)
158#define RADIO_PCNF1_BALEN_MASK (7 << RADIO_PCNF1_BALEN_SHIFT)
159#define RADIO_PCNF1_BALEN_MASKED(V) (((V) << RADIO_PCNF1_BALEN_SHIFT) & \
160 RADIO_PCNF1_BALEN_MASK)
161
162#define RADIO_PCNF1_ENDIAN_BIG (1 << 24)
163#define RADIO_PCNF1_WHITEEN (1 << 25)
164
165#define RADIO_PREFIX0_AP0_SHIFT (0)
166#define RADIO_PREFIX0_AP0_MASK (0xff << RADIO_PREFIX0_AP0_SHIFT)
167#define RADIO_PREFIX0_AP0_MASKED(V) (((V) << RADIO_PREFIX0_AP0_SHIFT) & \
168 RADIO_PREFIX0_AP0_MASK)
169
170#define RADIO_PREFIX0_AP1_SHIFT (8)
171#define RADIO_PREFIX0_AP1_MASK (0xff << RADIO_PREFIX0_AP1_SHIFT)
172#define RADIO_PREFIX0_AP1_MASKED(V) (((V) << RADIO_PREFIX0_AP1_SHIFT) & \
173 RADIO_PREFIX0_AP1_MASK)
174
175#define RADIO_PREFIX0_AP2_SHIFT (16)
176#define RADIO_PREFIX0_AP2_MASK (0xff << RADIO_PREFIX0_AP2_SHIFT)
177#define RADIO_PREFIX0_AP2_MASKED(V) (((V) << RADIO_PREFIX0_AP2_SHIFT) & \
178 RADIO_PREFIX0_AP2_MASK)
179
180#define RADIO_PREFIX0_AP3_SHIFT (24)
181#define RADIO_PREFIX0_AP3_MASK (0xff << RADIO_PREFIX0_AP3_SHIFT)
182#define RADIO_PREFIX0_AP3_MASKED(V) (((V) << RADIO_PREFIX0_AP3_SHIFT) & \
183 RADIO_PREFIX0_AP3_MASK)
184
185#define RADIO_PREFIX1_AP4_SHIFT (0)
186#define RADIO_PREFIX1_AP4_MASK (0xff << RADIO_PREFIX1_AP4_SHIFT)
187#define RADIO_PREFIX1_AP4_MASKED(V) (((V) << RADIO_PREFIX1_AP4_SHIFT) & \
188 RADIO_PREFIX1_AP4_MASK)
189
190#define RADIO_PREFIX1_AP5_SHIFT (8)
191#define RADIO_PREFIX1_AP5_MASK (0xff << RADIO_PREFIX1_AP5_SHIFT)
192#define RADIO_PREFIX1_AP5_MASKED(V) (((V) << RADIO_PREFIX1_AP5_SHIFT) & \
193 RADIO_PREFIX1_AP5_MASK)
194
195#define RADIO_PREFIX1_AP6_SHIFT (16)
196#define RADIO_PREFIX1_AP6_MASK (0xff << RADIO_PREFIX1_AP6_SHIFT)
197#define RADIO_PREFIX1_AP6_MASKED(V) (((V) << RADIO_PREFIX1_AP6_SHIFT) & \
198 RADIO_PREFIX1_AP6_MASK)
199
200#define RADIO_PREFIX1_AP7_SHIFT (24)
201#define RADIO_PREFIX1_AP7_MASK (0xff << RADIO_PREFIX1_AP7_SHIFT)
202#define RADIO_PREFIX1_AP7_MASKED(V) (((V) << RADIO_PREFIX1_AP7_SHIFT) & \
203 RADIO_PREFIX1_AP7_MASK)
204
205#define RADIO_PREFIX_AP(n) ((n) < 4 ? RADIO_PREFIX0 : RADIO_PREFIX1)
206#define RADIO_PREFIX_AP_SHIFT(n) (8 * (n & 3))
207#define RADIO_PREFIX_AP_MASK(n) (0xff << RADIO_PREFIX_AP_SHIFT(n))
208#define RADIO_PREFIX_AP_MASKED(n, V) (((V) << RADIO_PREFIX_AP_SHIFT(n)) & \
209 RADIO_PREFIX_AP_MASK(n))
210
211/* TODO: Get rid of this */
212#define RADIO_PREFIX_AP_SET(n, V) if ((n) < 4) {\
213 RADIO_PREFIX0 = (V); } \
214 else {\
215 RADIO_PREFIX1 = (V); }
216
217#define RADIO_TXADDRESSES_ADDR0 (1 << 0)
218#define RADIO_TXADDRESSES_ADDR1 (1 << 1)
219#define RADIO_TXADDRESSES_ADDR2 (1 << 2)
220#define RADIO_TXADDRESSES_ADDR3 (1 << 3)
221#define RADIO_TXADDRESSES_ADDR4 (1 << 4)
222#define RADIO_TXADDRESSES_ADDR5 (1 << 5)
223#define RADIO_TXADDRESSES_ADDR6 (1 << 6)
224#define RADIO_TXADDRESSES_ADDR7 (1 << 7)
225#define RADIO_TXADDRESSES_ADDR(n) (1 << (n))
226
227#define RADIO_CRCCNF_LEN_SHIFT (0)
228#define RADIO_CRCCNF_LEN_MASK (3 << RADIO_CRCCNF_LEN_SHIFT)
229#define RADIO_CRCCNF_LEN_MASKED(V) (((V) << RADIO_CRCCNF_LEN_SHIFT) & \
230 RADIO_CRCCNF_LEN_MASK)
231
232#define RADIO_CRCCNF_SKIPADDR (1 << 8)
233
234#define RADIO_TEST_CONSTCARRIER (1 << 0)
235#define RADIO_TEST_PLLLOCK (1 << 1)
236
237#define RADIO_DACNF_ENA(n) (1 << (n))
238#define RADIO_DACNF_ENA0 RADIO_DACNF_ENA(0)
239#define RADIO_DACNF_ENA1 RADIO_DACNF_ENA(1)
240#define RADIO_DACNF_ENA2 RADIO_DACNF_ENA(2)
241#define RADIO_DACNF_ENA3 RADIO_DACNF_ENA(3)
242#define RADIO_DACNF_ENA4 RADIO_DACNF_ENA(4)
243#define RADIO_DACNF_ENA5 RADIO_DACNF_ENA(5)
244#define RADIO_DACNF_ENA6 RADIO_DACNF_ENA(6)
245#define RADIO_DACNF_ENA7 RADIO_DACNF_ENA(7)
246
247#define RADIO_DACNF_TXADD(n) (1 << ((n) + 8))
248#define RADIO_DACNF_TXADD0 RADIO_DACNF_TXADD(0)
249#define RADIO_DACNF_TXADD1 RADIO_DACNF_TXADD(1)
250#define RADIO_DACNF_TXADD2 RADIO_DACNF_TXADD(2)
251#define RADIO_DACNF_TXADD3 RADIO_DACNF_TXADD(3)
252#define RADIO_DACNF_TXADD4 RADIO_DACNF_TXADD(4)
253#define RADIO_DACNF_TXADD5 RADIO_DACNF_TXADD(5)
254#define RADIO_DACNF_TXADD6 RADIO_DACNF_TXADD(6)
255#define RADIO_DACNF_TXADD7 RADIO_DACNF_TXADD(7)
256
257/* Override 4 register has special bit and the override value is masked. */
258#define RADIO_OVERRIDE4_ENABLE (1 << 31)
259#define RADIO_OVERRIDE4_OVERRIDE_MASK (0x0fffffff)
260
261#define RADIO_POWER_ENABLED (1)
262#define RADIO_POWER_DISABLED (0)
263
264/* Bluetooth Low Energy parameters */
265#define RADIO_BLE_TIFS (150)
266#define RADIO_BLE_CRCLEN (3)
267#define RADIO_BLE_CRCPOLY (0x65B)
268#define RADIO_BLE_CRCINIT (0x555555)
269
279};
280
291};
292
293/**@}*/
294
296
297void radio_configure_ble(void);
298void radio_disable_crc(void);
299void radio_disable(void);
300void radio_enable(void);
301void radio_set_crclen(uint8_t crc_len);
302void radio_set_lsbfirst(void);
303void radio_set_msbfirst(void);
304void radio_set_txpower(enum radio_txpower txpower);
305void radio_disable_whitening(void);
306void radio_enable_whitening(void);
307void radio_configure_packet(uint8_t lf_len_bits, uint8_t s0_len_bytes, uint8_t s1_len_bits);
308void radio_set_balen(uint8_t ba_len);
309void radio_set_frequency(uint8_t freq);
310void radio_set_datawhiteiv(uint8_t iv);
311void radio_set_addr(uint8_t addr_index, uint32_t base, uint8_t prefix);
312void radio_set_tx_address(uint8_t addr_index);
313void radio_set_packet_ptr(uint8_t *packet_ptr);
314void radio_enable_shorts(uint16_t shorts);
315void radio_disable_shorts(uint16_t shorts);
317void radio_enable_tx(void);
318void radio_enable_rx(void);
319void radio_set_maxlen(uint8_t maxlen);
320void radio_set_crc_skipaddr(bool is_skip_addr);
321
323
324
325
void radio_enable_shorts(uint16_t shorts)
void radio_clear_shorts(void)
void radio_disable_shorts(uint16_t shorts)
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
radio_txpower
Definition: common/radio.h:270
radio_state
Definition: common/radio.h:281
@ RADIO_TXPOWER_NEG_30DBM
Definition: common/radio.h:278
@ RADIO_TXPOWER_NEG_4DBM
Definition: common/radio.h:273
@ RADIO_TXPOWER_0DBM
Definition: common/radio.h:272
@ RADIO_TXPOWER_NEG_8DBM
Definition: common/radio.h:274
@ RADIO_TXPOWER_NEG_16DBM
Definition: common/radio.h:276
@ RADIO_TXPOWER_NEG_12DBM
Definition: common/radio.h:275
@ RADIO_TXPOWER_POS_4DBM
Definition: common/radio.h:271
@ RADIO_TXPOWER_NEG_20DBM
Definition: common/radio.h:277
@ RADIO_STATE_RXRU
Definition: common/radio.h:283
@ RADIO_STATE_RXDISABLE
Definition: common/radio.h:286
@ RADIO_STATE_TXDISABLE
Definition: common/radio.h:290
@ RADIO_STATE_RX
Definition: common/radio.h:285
@ RADIO_STATE_RXIDLE
Definition: common/radio.h:284
@ RADIO_STATE_DISABLED
Definition: common/radio.h:282
@ RADIO_STATE_TX
Definition: common/radio.h:289
@ RADIO_STATE_TXRU
Definition: common/radio.h:287
@ RADIO_STATE_TXIDLE
Definition: common/radio.h:288
void radio_set_crclen(uint8_t crc_len)
Set CRC length in number of bytes.
Definition: radio_common.c:79
void radio_set_packet_ptr(uint8_t *packet_ptr)
Definition: radio_common.c:231
void radio_disable(void)
Disable the peripheral.
Definition: radio_common.c:99
void radio_set_datawhiteiv(uint8_t iv)
Set Data Whitening Initialization Vector.
Definition: radio_common.c:188
void radio_configure_ble(void)
Configure the radio to be used in BLE mode.
Definition: radio_common.c:147
void radio_set_frequency(uint8_t freq)
Set radio frequency.
Definition: radio_common.c:179
void radio_set_tx_address(uint8_t addr_index)
Definition: radio_common.c:222
void radio_enable_whitening(void)
Enable on the air data whitening.
Definition: radio_common.c:64
void radio_set_maxlen(uint8_t maxlen)
Set maximum transmission length in number of bytes.
Definition: radio_common.c:120
void radio_enable(void)
Enable the peripheral.
Definition: radio_common.c:93
void radio_set_balen(uint8_t ba_len)
Set Base Address length.
Definition: radio_common.c:109
void radio_disable_whitening(void)
Disable on the air data whitening.
Definition: radio_common.c:70
void radio_configure_packet(uint8_t lf_len_bits, uint8_t s0_len_bytes, uint8_t s1_len_bits)
Configure the packet.
Definition: radio_common.c:167
void radio_set_crc_skipaddr(bool is_skip_addr)
Exclude access address from CRC calculation.
Definition: radio_common.c:132
void radio_enable_rx(void)
Definition: radio_common.c:243
void radio_set_lsbfirst(void)
Set bit transmission order to LSB first.
Definition: radio_common.c:49
void radio_set_txpower(enum radio_txpower txpower)
Set radio transmission power.
Definition: radio_common.c:43
void radio_set_addr(uint8_t addr_index, uint32_t base, uint8_t prefix)
Definition: radio_common.c:203
void radio_enable_tx(void)
Definition: radio_common.c:237
void radio_disable_crc(void)
Disable CRC calculation.
Definition: radio_common.c:87
void radio_set_msbfirst(void)
Set bit transmission order to MSB first.
Definition: radio_common.c:55