1 /*
2 * Copyright (c) 2018 Nordic Semiconductor ASA
3 * Copyright (c) 2018 Ioannis Glaropoulos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8 /* Use the NRF_RTC instance for coarse radio event scheduling */
9 #define NRF_RTC NRF_RTC0
10
11 /* HAL abstraction of event timer prescaler value */
12 #define HAL_EVENT_TIMER_PRESCALER_VALUE 4U
13
14 /* TXEN->TXIDLE + TXIDLE->TX in microseconds. */
15 #define HAL_RADIO_NRF51_TXEN_TXIDLE_TX_US 140
16 #define HAL_RADIO_NRF51_TXEN_TXIDLE_TX_NS 140000
17 /* RXEN->RXIDLE + RXIDLE->RX in microseconds. */
18 #define HAL_RADIO_NRF51_RXEN_RXIDLE_RX_US 138
19 #define HAL_RADIO_NRF51_RXEN_RXIDLE_RX_NS 138000
20
21 #define HAL_RADIO_NRF51_TX_CHAIN_DELAY_US 1 /* ceil(1.0) */
22 #define HAL_RADIO_NRF51_TX_CHAIN_DELAY_NS 1000 /* 1.0 */
23 #define HAL_RADIO_NRF51_RX_CHAIN_DELAY_US 3 /* ceil(3.0) */
24 #define HAL_RADIO_NRF51_RX_CHAIN_DELAY_NS 3000 /* 3.0 */
25
26 /* HAL abstraction of Radio bitfields */
27 #define HAL_RADIO_INTENSET_DISABLED_Msk RADIO_INTENSET_DISABLED_Msk
28 #define HAL_RADIO_SHORTS_TRX_END_DISABLE_Msk RADIO_SHORTS_END_DISABLE_Msk
29 #define HAL_RADIO_SHORTS_TRX_PHYEND_DISABLE_Msk RADIO_SHORTS_PHYEND_DISABLE_Msk
30
31 /* HAL abstraction of Radio IRQ number */
32 #define HAL_RADIO_IRQn RADIO_IRQn
33
hal_radio_reset(void)34 static inline void hal_radio_reset(void)
35 {
36 /* TODO: Add any required setup for each radio event
37 */
38 }
39
hal_radio_stop(void)40 static inline void hal_radio_stop(void)
41 {
42 /* TODO: Add any required cleanup of actions taken in hal_radio_reset()
43 */
44 }
45
hal_radio_ram_prio_setup(void)46 static inline void hal_radio_ram_prio_setup(void)
47 {
48 }
49
hal_radio_phy_mode_get(uint8_t phy,uint8_t flags)50 static inline uint32_t hal_radio_phy_mode_get(uint8_t phy, uint8_t flags)
51 {
52 ARG_UNUSED(flags);
53 uint32_t mode;
54
55 switch (phy) {
56 case BIT(0):
57 default:
58 mode = RADIO_MODE_MODE_Ble_1Mbit;
59 break;
60
61 case BIT(1):
62 mode = RADIO_MODE_MODE_Nrf_2Mbit;
63 break;
64 }
65
66 return mode;
67 }
68
hal_radio_tx_power_min_get(void)69 static inline uint32_t hal_radio_tx_power_min_get(void)
70 {
71 return RADIO_TXPOWER_TXPOWER_Neg30dBm;
72 }
73
hal_radio_tx_power_max_get(void)74 static inline uint32_t hal_radio_tx_power_max_get(void)
75 {
76 return RADIO_TXPOWER_TXPOWER_Pos4dBm;
77 }
78
hal_radio_tx_power_floor(int8_t tx_power_lvl)79 static inline uint32_t hal_radio_tx_power_floor(int8_t tx_power_lvl)
80 {
81 if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Pos4dBm) {
82 return RADIO_TXPOWER_TXPOWER_Pos4dBm;
83 }
84
85 if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_0dBm) {
86 return RADIO_TXPOWER_TXPOWER_0dBm;
87 }
88
89 if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg4dBm) {
90 return RADIO_TXPOWER_TXPOWER_Neg4dBm;
91 }
92
93 if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg8dBm) {
94 return RADIO_TXPOWER_TXPOWER_Neg8dBm;
95 }
96
97 if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg12dBm) {
98 return RADIO_TXPOWER_TXPOWER_Neg12dBm;
99 }
100
101 if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg16dBm) {
102 return RADIO_TXPOWER_TXPOWER_Neg16dBm;
103 }
104
105 if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg20dBm) {
106 return RADIO_TXPOWER_TXPOWER_Neg20dBm;
107 }
108
109 /* Note: The -30 dBm power level is deprecated so ignore it! */
110 return RADIO_TXPOWER_TXPOWER_Neg40dBm;
111 }
112
hal_radio_tx_ready_delay_us_get(uint8_t phy,uint8_t flags)113 static inline uint32_t hal_radio_tx_ready_delay_us_get(uint8_t phy, uint8_t flags)
114 {
115 ARG_UNUSED(phy);
116 ARG_UNUSED(flags);
117 return HAL_RADIO_NRF51_TXEN_TXIDLE_TX_US;
118 }
119
hal_radio_rx_ready_delay_us_get(uint8_t phy,uint8_t flags)120 static inline uint32_t hal_radio_rx_ready_delay_us_get(uint8_t phy, uint8_t flags)
121 {
122 ARG_UNUSED(phy);
123 ARG_UNUSED(flags);
124 return HAL_RADIO_NRF51_RXEN_RXIDLE_RX_US;
125 }
126
hal_radio_tx_chain_delay_us_get(uint8_t phy,uint8_t flags)127 static inline uint32_t hal_radio_tx_chain_delay_us_get(uint8_t phy, uint8_t flags)
128 {
129 ARG_UNUSED(phy);
130 ARG_UNUSED(flags);
131 return HAL_RADIO_NRF51_TX_CHAIN_DELAY_US;
132 }
133
hal_radio_rx_chain_delay_us_get(uint8_t phy,uint8_t flags)134 static inline uint32_t hal_radio_rx_chain_delay_us_get(uint8_t phy, uint8_t flags)
135 {
136 ARG_UNUSED(phy);
137 ARG_UNUSED(flags);
138 return HAL_RADIO_NRF51_RX_CHAIN_DELAY_US;
139 }
140
hal_radio_tx_ready_delay_ns_get(uint8_t phy,uint8_t flags)141 static inline uint32_t hal_radio_tx_ready_delay_ns_get(uint8_t phy, uint8_t flags)
142 {
143 ARG_UNUSED(phy);
144 ARG_UNUSED(flags);
145 return HAL_RADIO_NRF51_TXEN_TXIDLE_TX_NS;
146 }
147
hal_radio_rx_ready_delay_ns_get(uint8_t phy,uint8_t flags)148 static inline uint32_t hal_radio_rx_ready_delay_ns_get(uint8_t phy, uint8_t flags)
149 {
150 ARG_UNUSED(phy);
151 ARG_UNUSED(flags);
152 return HAL_RADIO_NRF51_RXEN_RXIDLE_RX_NS;
153 }
154
hal_radio_tx_chain_delay_ns_get(uint8_t phy,uint8_t flags)155 static inline uint32_t hal_radio_tx_chain_delay_ns_get(uint8_t phy, uint8_t flags)
156 {
157 ARG_UNUSED(phy);
158 ARG_UNUSED(flags);
159 return HAL_RADIO_NRF51_TX_CHAIN_DELAY_NS;
160 }
161
hal_radio_rx_chain_delay_ns_get(uint8_t phy,uint8_t flags)162 static inline uint32_t hal_radio_rx_chain_delay_ns_get(uint8_t phy, uint8_t flags)
163 {
164 ARG_UNUSED(phy);
165 ARG_UNUSED(flags);
166 return HAL_RADIO_NRF51_RX_CHAIN_DELAY_NS;
167 }
168