libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
radio.c
Go to the documentation of this file.
1/** @addtogroup radio_file RADIO peripheral API
2 *
3 * @brief <b>Access functions for the NRF51 2.4 GHz Radio </b>
4 * @ingroup peripheral_apis
5 * LGPL License Terms @ref lgpl_license
6 * @author @htmlonly &copy; @endhtmlonly 2016
7 * Maxim Sloyko <maxims@google.com>
8 *
9 */
10
11/*
12 * This file is part of the unicore-mx project.
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#include <libopencm3/nrf/ficr.h>
30
31/**@{*/
32
33/** @brief Set radio mode.
34 *
35 * @details The function also performs all required overrides for BLE and NRF mode.
36 *
37 * @param[in] mode the new mode.
38 * */
40{
41 /* This is alias to memory register, thus volatile */
42 volatile uint32_t *override_pos = 0;
43 if ((RADIO_MODE_BLE_1MBIT == mode)
45 /* Need to use Override */
46 override_pos = &FICR_BLE_1MBIT0;
47 } else if ((RADIO_MODE_NRF_1MBIT == mode)
49 override_pos = &FICR_NRF_1MBIT0;
50 }
51
52 if (override_pos) {
53 uint8_t i;
54 for (i = 0; i <= 4; ++i, ++override_pos) {
55 RADIO_OVERRIDE(i) = *override_pos;
56 }
57
59 } else {
60 RADIO_OVERRIDE(4) &= ~RADIO_OVERRIDE4_ENABLE;
61 }
62
63 RADIO_MODE = mode;
64}
65/**@}*/
66
#define FICR_NRF_1MBIT0
Definition: 51/ficr.h:57
#define FICR_OVERRIDEEN
Definition: 51/ficr.h:53
#define FICR_OVERRIDEEN_NRF_1MBIT
Definition: 51/ficr.h:71
#define FICR_OVERRIDEEN_BLE_1MBIT
Definition: 51/ficr.h:72
#define FICR_BLE_1MBIT0
Definition: 51/ficr.h:65
radio_mode
Definition: 51/radio.h:40
@ RADIO_MODE_NRF_1MBIT
Definition: 51/radio.h:41
@ RADIO_MODE_BLE_1MBIT
Definition: 51/radio.h:44
#define RADIO_MODE
Definition: common/radio.h:72
#define RADIO_OVERRIDE4_ENABLE
Definition: common/radio.h:258
#define RADIO_OVERRIDE(n)
Definition: common/radio.h:98
void radio_set_mode(enum radio_mode mode)
Set radio mode.
Definition: radio.c:39