Contiki 3.x
radioeng.c
Go to the documentation of this file.
1 /**
2  * Copyright (c) 2014, Analog Devices, Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted (subject to the limitations in the
6  * disclaimer below) provided that the following conditions are met:
7  *
8  * - Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * - Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * distribution.
15  *
16  * - Neither the name of Analog Devices, Inc. nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
21  * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
22  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
23  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
32  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 /**
35  @file radioeng.c
36  @brief Radio Interface Engine Functions
37  @version v1.0
38  @author PAD CSE group, Analog Devices Inc
39  @date May 08th 2013
40 **/
41 
42 #include "aducrf101-include.h"
43 
44 // 1.0 of the Engine
45 #define RIE_ENGINE_MAJOR_VERSION 1UL
46 #define RIE_ENGINE_MINOR_VERSION 0UL
47 
48 
49 #define RADIO_SPI_CLK_FREQ 4000000 // 4 MHz SPI CLK for radio interface
50 #define SYSTEM_UCLK 16000000 // 16 MHz UCLK
51 // Default Radio Parameters
52 #define DEFAULT_CHNL_FREQ 915000000
53 #define FREQ_CNVRT_VAL 0.00252061538
54 // Defines for radio memory mapped areas
55 #define PACKETRAM_START 0x10
56 #define PACKETRAM_LEN 240
57 #define BBRAM_START 0x100
58 #define PR_var_tx_mode_ADR 0x00D
59 
60 // PrF Table 35
61 #define PARAM_TX_NORMAL_PACKET 0
62 #define PARAM_TX_PREAMBLE_FOREVER 2
63 #define PARAM_TX_CARRIER_FOREVER 3
64 
65 #define gpio_configure_sport_mode_0 0xA0
66 #define gpio_configure_default 0x00
67 #define MCR_pa_level_mcr_Adr 0x307
68 #define MCR_rssi_readback_Adr 0x312
69 #define MCR_gpio_configure_Adr 0x3fa
70 #define MCR_ext_uc_clk_divide_Adr 0x32e
71 #define MCR_interrupt_source_0_Adr 0x336
72 #define MCR_interrupt_source_1_Adr 0x337
73 
74 // Macros for manual GPIO checking of Radio MISO pin P2.0 (SPI0)
75 #define RADIO_MISO_IN GP2IN_IN0_BBA
76 // Macros for manual GPIO control of P2.3 (Radio SPI CS) (SPI0)
77 #define RADIO_CSN_DEASSERT (pADI_GP2->GPSET = GP2SET_SET3)
78 #define RADIO_CSN_ASSERT (pADI_GP2->GPCLR = GP2CLR_CLR3)
79 // Macros for Sending\Receiving single bytes via SPI
80 #define SEND_SPI(x) pADI_SPI0->SPITX = x
81 #define WAIT_SPI_RX while((pADI_SPI0->SPISTA & SPISTA_RXFSTA_MSK) == 0x0);
82 #define READ_SPI pADI_SPI0->SPIRX
83 
84 // Bit Manipulation Macros
85 #define MSKSET_VAL(byte,numbits,offset,value) ((byte & ~(((0x1 << numbits)-1) << offset)) | value)
86 
87 
88 
89 /*************************************************************************/
90 /* Local Types */
91 /*************************************************************************/
92 /*************************************************************************/
93 /* Radio Command Codes */
94 /*************************************************************************/
95 typedef enum
96 {
97  CMD_SYNC = 0xA2, // Synchronizatio
98  CMD_PHY_OFF = 0xB0, // Transition to state PHY_OFF
99  CMD_PHY_ON = 0xB1, // transition to state PHY_ON
100  CMD_PHY_RX = 0xB2, // transition to state PHY_RX
101  CMD_PHY_TX = 0xB5, // transition to state PHY_TX
102  CMD_PHY_SLEEP = 0xBA, // transition to state PHY_SLEEP
103  CMD_CONFIG_DEV = 0xBB, // Apply Radio Configuration
104  CMD_GET_RSSI = 0xBC, // Performs an RSSI measurement
105  CMD_HW_RESET = 0xC8, // Power Down radio
106  SPI_MEM_WR = 0x18, // Sequential SPI Write
107  SPI_MEM_RD = 0x38, // Sequential SPI Read
108  SPI_NOP = 0xFF // No operation
109 } Radio_CmdCodes;
110 /*************************************************************************/
111 /* Firmware States */
112 /*************************************************************************/
113 typedef enum
114 {
115  FW_INIT = 0x0F, // Radio Starting Up
116  FW_BUSY = 0x00, // Radio not completed current operation
117  FW_RSSI = 0x05, // Performing CMD_GET_RSSI
118  FW_OFF = 0x11, // Radio is OFF
119  FW_ON = 0x12, // Radio is ON
120  FW_RX = 0x13, // Radio is in receive mode
121  FW_TX = 0x14, // Radio is in transmit mode
122 
123 } RadioState;
124 /*************************************************************************/
125 /* Status Byte Masks */
126 /*************************************************************************/
127 #define STATUS_BYTE_FW_STATE (0x1F << 0)
128 #define STATUS_BYTE_CMD_READY (0x1 << 5)
129 #define STATUS_BYTE_IRQ_STATUS (0x1 << 6)
130 #define STATUS_BYTE_SPI_READY (0x1 << 7)
131 /*************************************************************************/
132 /* SPI Memory Access Defs */
133 /*************************************************************************/
134 #define SPI_MEMCMD_BYTE0_ADR_MSK (0x3 << 0)
135 #define SPI_MEMCMD_BYTE0_CMD_BITOFFSET 3
136 #define SPI_MEMCMD_BYTE0_CMD_MSK (0x1F << SPI_MEMCMD_BYTE0_CMD_BITOFFSET)
137 /*************************************************************************/
138 /* Radio Configuration Structure */
139 /*************************************************************************/
140 /**
141  \internal Hide from Doxegen
142  \var TyRadioConfiguration
143  **/
144 typedef struct
145 {
146  RIE_U8 interrupt_mask_0_r; // 0x100
147  RIE_U8 cfg_101_r; // 0x101
148  RIE_U8 cfg_102_r; // 0x102
149  RIE_U8 cfg_103_r; // 0x103
150  RIE_U8 cfg_104_r; // 0x104
151  RIE_U8 cfg_105_r; // 0x105
152  RIE_U8 cfg_106_r; // 0x106
153  RIE_U8 cfg_107_r; // 0x107
154  RIE_U8 cfg_108_r; // 0x108
155  RIE_U8 channel_freq_0_r; // 0x109
156  RIE_U8 channel_freq_1_r; // 0x10A
157  RIE_U8 channel_freq_2_r; // 0x10B
158  RIE_U8 cfg_10C_r; // 0x10C
159  RIE_U8 cfg_10D_r; // 0x10D
160  RIE_U8 cfg_10E_r; // 0x10E
161  RIE_U8 cfg_10F_r; // 0x10F
162  RIE_U8 cfg_110_r; // 0x110
163  RIE_U8 cfg_111_r; // 0x111
164  RIE_U8 cfg_112_r; // 0x112
165  RIE_U8 cfg_113_r; // 0x113
166  RIE_U8 radio_cfg_8_r; // 0x114
167  RIE_U8 radio_cfg_9_r; // 0x115
168  RIE_U8 cfg_116_r; // 0x116
169  RIE_U8 cfg_117_r; // 0x117
170  RIE_U8 image_reject_cal_phase_r; // 0x118
171  RIE_U8 image_reject_cal_amplitude_r; // 0x119
172  RIE_U8 cfg_11A_r; // 0x11A
173  RIE_U8 cfg_11B_r; // 0x11B
174  RIE_U8 symbol_mode_r; // 0x11C
175  RIE_U8 cfg_11D_r; // 0x11D
176  RIE_U8 cfg_11E_r; // 0x11E
177  RIE_U8 cfg_11F_r; // 0x11F
178  RIE_U8 cfg_120_r; // 0x120
179  RIE_U8 cfg_121_r; // 0x121
180  RIE_U8 cfg_122_r; // 0x122
181  RIE_U8 cfg_123_r; // 0x123
182  RIE_U8 tx_base_adr_r; // 0x124
183  RIE_U8 rx_base_adr_r; // 0x125
184  RIE_U8 packet_length_control_r; // 0x126
185  RIE_U8 packet_length_max_r; // 0x127
186  RIE_U8 cfg_128_r; // 0x128
187  RIE_U8 cfg_129_r; // 0x129
188  RIE_U8 cfg_12A_r; // 0x12A
189  RIE_U8 cfg_12B_r; // 0x12B
190  RIE_U8 cfg_12C_r; // 0x12C
191  RIE_U8 cfg_12D_r; // 0x12D
192  RIE_U8 cfg_12E_r; // 0x12E
193  RIE_U8 cfg_12F_r; // 0x12F
194  RIE_U8 cfg_130_r; // 0x130
195  RIE_U8 cfg_131_r; // 0x131
196  RIE_U8 cfg_132_r; // 0x132
197  RIE_U8 cfg_133_r; // 0x133
198  RIE_U8 cfg_134_r; // 0x134
199  RIE_U8 cfg_135_r; // 0x135
200  RIE_U8 cfg_136_r; // 0x136
201  RIE_U8 cfg_137_r; // 0x137
202  RIE_U8 cfg_138_r; // 0x138
203  RIE_U8 cfg_139_r; // 0x139
204  RIE_U8 cfg_13A_r; // 0x13A
205  RIE_U8 cfg_13B_r; // 0x13B
206  RIE_U8 cfg_13C_r; // 0x13C
207  RIE_U8 cfg_13D_r; // 0x13D
208  RIE_U8 cfg_13E_r; // 0x13E
209  RIE_U8 cfg_13F_r; // 0x13F
210 } TyRadioConfiguration;
211 /*************************************************************************/
212 /* Radio Configuration Constants */
213 /*************************************************************************/
214 #define interrupt_mask_0_interrupt_tx_eof (0x1 << 4)
215 #define interrupt_mask_0_interrupt_crc_correct (0x1 << 2)
216 
217 #define packet_length_control_length_offset_offset (0)
218 #define packet_length_control_length_offset_minus0 (0x4 << packet_length_control_length_offset_offset)
219 #define packet_length_control_data_mode_offset (3)
220 #define packet_length_control_data_mode_packet (0x0 << packet_length_control_data_mode_offset)
221 #define packet_length_control_crc_en_yes (0x1 << 5)
222 #define packet_length_control_packet_len_variable (0x0 << 6)
223 #define packet_length_control_packet_len_fixed (0x1 << 6)
224 #define packet_length_control_data_byte_lsb (0x0 << 7)
225 
226 #define symbol_mode_symbol_length_8_bit (0 << 0)
227 #define symbol_mode_data_whitening_disabled (0 << 3)
228 #define symbol_mode_data_whitening_enabled (1 << 3)
229 #define symbol_mode_eight_ten_enc_disabled (0 << 4 )
230 #define symbol_mode_prog_crc_en_disabled (0 << 5)
231 #define symbol_mode_manchester_enc_enabled (1 << 6)
232 
233 #define radio_cfg_8_pa_single_diff_sel_single_ended (0x0 << 7)
234 #define radio_cfg_8_pa_single_diff_sel_differential (0x1 << 7)
235 #define radio_cfg_8_pa_power_numbits (4)
236 #define radio_cfg_8_pa_power_offset (3)
237 #define radio_cfg_8_pa_power_setting_63 (0xF << radio_cfg_8_pa_power_offset)
238 #define radio_cfg_8_pa_ramp_numbits (3)
239 #define radio_cfg_8_pa_ramp_offset (0)
240 #define radio_cfg_8_pa_ramp_16 (0x5 << radio_cfg_8_pa_ramp_offset)
241 
242 #define radio_cfg_9_demod_scheme_offset (0)
243 #define radio_cfg_9_demod_scheme_FSK (0x0 << radio_cfg_9_demod_scheme_offset)
244 #define radio_cfg_9_mod_scheme_numbits (3)
245 #define radio_cfg_9_mod_scheme_offset (3)
246 #define radio_cfg_9_mod_scheme_2_level_FSK (0x0 << radio_cfg_9_mod_scheme_offset)
247 #define radio_cfg_9_mod_scheme_2_level_GFSK (0x1 << radio_cfg_9_mod_scheme_offset)
248 #define radio_cfg_9_ifbw_numbits (2)
249 #define radio_cfg_9_ifbw_offset (6)
250 #define radio_cfg_9_ifbw_100kHz (0x0 << radio_cfg_9_ifbw_offset)
251 #define radio_cfg_9_ifbw_150kHz (0x1 << radio_cfg_9_ifbw_offset)
252 #define radio_cfg_9_ifbw_200kHz (0x2 << radio_cfg_9_ifbw_offset)
253 #define radio_cfg_9_ifbw_300kHz (0x3 << radio_cfg_9_ifbw_offset)
254 
255 /*************************************************************************/
256 /* Local Variables */
257 /*************************************************************************/
258 static TyRadioConfiguration RadioConfiguration;
259 static RIE_BOOL bRadioConfigurationChanged = RIE_FALSE;
260 static RIE_BOOL bTestModeEnabled = RIE_FALSE;
261 static RIE_U32 DataRate = 38400;
262 static volatile RIE_BOOL bPacketTx = RIE_FALSE;
263 static volatile RIE_BOOL bPacketRx = RIE_FALSE;
264 
265 const RIE_U8 DR_38_4kbps_Dev20kHz_Configuration[] =
266 {
267  0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x00,0x76,0x62,0x21,
268 
269 // 0 1 2 3 4 5 6 7 8 9 A B
270  0x80,0x01,0xC8,0x20,0x0E,0x00,0x00,0x00,0xFD,0x00,0x0B,0x37,
271  0x16,0x07,
272 
273  0x40,0x0C,0x00,0x0C,0x00,0x00,
274  0x10,0x00,0xC3,0x36,0x10,0x10,0x24,0xF0,0x2A,0x00,0x2F,0x19,0x5E,0x46,0x5F,0x78,
275  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
276 };
277 
278 
279 const RIE_U8 DR_300_0kbps_Dev75_0kHz_Configuration[] =
280 {
281  0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x00,0x76,0x62,0x21,
282 
283 // 0 1 2 3 4 5 6 7 8 9 A B
284  0xB8,0x2B,0xEE,0x0B,0x70,0x00,0x03,0x00,0xFD,0xC0,0x0B,0x37,
285  0x16,0x07,
286 
287  0x40,0x0C,0x00,0x0C,0x00,0x00,
288  0x10,0x00,0xC3,0x36,0x10,0x10,0x24,0xF0,0x2A,0x00,0x2F,0x19,0x5E,0x46,0x5F,0x78,
289  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
290 };
291 
292 
293 
294 const RIE_U8 DR_1_0kbps_Dev10_0kHz_Configuration[] =
295 {
296  0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x00,0x76,0x62,0x21,
297 // 0 1 2 3 4 5 6 7 8 9 A B
298  0x0A,0x00,0x64,0x41,0x01,0x00,0x02,0x00,0xFD,0x00,0x0B,0x37,
299  0x16,0x07,
300 
301  0x40,0x0C,0x00,0x0C,0x00,0x00,
302  0x10,0x00,0xC3,0x36,0x10,0x10,0x24,0xF0,0x2A,0x00,0x2F,0x19,0x5E,0x46,0x5F,0x78,
303  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
304 };
305 
306 /*************************************************************************/
307 /* Local Functions */
308 /*************************************************************************/
309 static RIE_Responses RadioSPIXferByte (RIE_U8 ucByte,
310  RIE_U8 * pData);
311 static RIE_Responses RadioSendCommandBytes (RIE_U8 * pCmdBytes,
312  RIE_U8 NumBytes);
313 static RIE_Responses RadioSendCommandNoWait (Radio_CmdCodes CmdCode);
314 static RIE_Responses RadioSendCommandWait (Radio_CmdCodes CmdCode);
315 static RIE_Responses RadioMMapRead (RIE_U32 ulAdr,
316  RIE_U32 ulLen,
317  RIE_U8 * pData);
318 static RIE_Responses RadioMMapWrite (RIE_U32 ulAdr,
319  RIE_U32 ulLen,
320  RIE_U8 * pData);
321 static RIE_Responses RadioReadState (RadioState * pState);
322 static RIE_Responses RadioWaitOnState (RadioState FinalState);
323 static RIE_Responses RadioWaitForPowerUp (void);
324 static RIE_Responses RadioSyncComms (void);
325 static RIE_Responses SetRadioConfiguration (RIE_BaseConfigs BaseConfig);
326 static RIE_Responses RadioCommitRadioConfig (void);
327 static RIE_Responses RadioConfigure (void);
328 static RIE_Responses RadioToOnMode (void);
329 static RIE_Responses RadioToOffMode (void);
330 static RIE_Responses RadioWaitOnCmdLdr (void);
331 /*************************************************************************/
332 /* Functions Implementations - Start */
333 /*************************************************************************/
334 
335 /**
336  @fn RIE_Responses RadioGetAPIVersion(RIE_U32 *pVersion)
337  @brief Return the Radio Interface Engine API Version
338  @param pVersion :{}
339  pVersion Storage for Radio Interface Engine API version.
340  @code
341  RIE_U32 Version;
342  Response = RadioGetAPIVersion(&Version);
343  @endcode
344  @return RIE_Responses Error code.
345 **/
346 
348 {
349  RIE_Responses Response = RIE_Success;
350 
351  if (pVersion)
352  *pVersion = RIE_ENGINE_MINOR_VERSION | (RIE_ENGINE_MAJOR_VERSION << 8);
353  return Response;
354 }
355 
356 
357 /**
358  @fn RIE_U32 RadioSwitchConfig(RIE_BaseConfigs BaseConfig)
359  @brief Change the Radio to using specified configuration.
360  @param BaseConfig :{DR_1_0kbps_Dev10_0kHz, DR_38_4kbps_Dev20kHz, DR_300_0kbps_Dev75_0kHz}
361  - DR_1_0kbps_Dev10_0kHz Base configuration of 1 kbps datarate, 10.0 kHz frequency deviation.
362  - DR_38_4kbps_Dev20kHz Base configuration of 38.4 kbps datarate, 20 kHz frequency deviation.
363  - DR_300_0kbps_Dev75_0kHz Base configuration of 300 kbps datarate, 75 kHz frequency deviation.
364  @pre
365  RadioInit() must be called before this function is called.
366  @return RIE_Responses Error code.
367 **/
368 
370 {
371  RIE_Responses Response = RIE_Success;
372  if(Response == RIE_Success)
373  Response = RadioToOffMode();
374  if(Response == RIE_Success)
375  Response = SetRadioConfiguration(BaseConfig);
376  if(Response == RIE_Success)
377  Response = RadioCommitRadioConfig();
378  if(Response == RIE_Success)
379  Response = RadioToOnMode();
380  return Response;
381 }
382 
383 
384 /**
385  @fn RIE_U32 RadioInit(RIE_BaseConfigs BaseConfig)
386  @brief Initialise the Radio, using specified configuration.
387  @param BaseConfig :{DR_1_0kbps_Dev10_0kHz , DR_38_4kbps_Dev20kHz ,DR_300_0kbps_Dev75_0kHz }
388  - DR_1_0kbps_Dev10_0kHz Base configuration of 1 kbps datarate, 10.0 kHz frequency deviation.
389  - DR_38_4kbps_Dev20kHz Base configuration of 38.4 kbps datarate, 20 kHz frequency deviation.
390  - DR_300_0kbps_Dev75_0kHz Base configuration of 300 kbps datarate, 75 kHz frequency deviation.
391  @note
392  This must be called before any other function is called.
393  @return RIE_Responses Error code.
394 **/
395 
397 {
398  RIE_Responses Response = RIE_Success;
399 
400  // Disable the radio interrupt until we have initialised the radio
402 
403  // Initialise GPIO Port 2 for Radio Use
404  pADI_GP2->GPCON = GP2CON_CON0_SPI0MISO | GP2CON_CON1_SPI0SCLK |
405  GP2CON_CON2_SPI0MOSI | GP2CON_CON3_GPIO |
406  GP2CON_CON4_IRQ8 | GP2CON_CON5_GPIO |
407  GP2CON_CON6_GPIO | GP2CON_CON7_GPIOIRQ7;
408 
409  pADI_GP2->GPOEN = GP2OEN_OEN0_IN | GP2OEN_OEN1_IN |
410  GP2OEN_OEN2_IN | GP2OEN_OEN3_OUT |
411  GP2OEN_OEN4_IN | GP2OEN_OEN5_IN |
412  GP2OEN_OEN6_IN | GP2OEN_OEN7_IN;
413 
414  // Disable the PULL-Up on P2.4 which is connected to the radio
415  GP2PUL_PUL4_BBA = 0x0;
416 
417  // Configure the SPI Interface to the Radio and flush it
418  pADI_SPI0->SPIDIV = ((SYSTEM_UCLK/RADIO_SPI_CLK_FREQ)/2)-0x1;
419  pADI_SPI0->SPICON = SPICON_MASEN | // Master mode
420  SPICON_TIM | // Interrupt on transmit
421  SPICON_TFLUSH | // Flush FIFO
422  SPICON_RFLUSH | // Flush FIFO
423  SPICON_ENABLE;
424  pADI_SPI0->SPICON = SPICON_MASEN | // Master mode
425  SPICON_TIM | // Interrupt on transmit
426  SPICON_ENABLE;
427 
428  // Initialise the chip select line to starting position
429  RADIO_CSN_DEASSERT;
430 
431 
432  // Power it down and up again to return to a known state
433  // which will be PHY_OFF.
434  // This will clear any pre-existing radio interrupt before
435  // we enable the Cortex interrupt handling of it
436  if(Response == RIE_Success)
437  Response = RadioPowerOff();
438  // Configure a "high level" radio interrupt ...
439  pADI_INTERRUPT->EI2CFG = EI2CFG_IRQ8MDE_HIGHLEVEL | EI2CFG_IRQ8EN;
440  // ... and set it up in the NVIC so that our interrupt handler is called
441  // when the radio wants our attention. Clear any pre-existing condition
442  // before enabling the interrupt.
443  pADI_INTERRUPT->EICLR = EICLR_IRQ8;
447 
448  if(Response == RIE_Success)
449  Response = RadioWaitForPowerUp();
450  if(Response == RIE_Success)
451  Response = RadioSyncComms();
452  if(Response == RIE_Success)
453  Response = RadioToOffMode();
454  if(Response == RIE_Success)
455  Response = SetRadioConfiguration(BaseConfig);
456  if(Response == RIE_Success)
457  Response = RadioCommitRadioConfig();
458  if(Response == RIE_Success)
459  Response = RadioToOnMode();
460  return Response;
461 }
462 
463 /**
464  @fn RIE_U32 RadioDeInit(void)
465  @brief Deinitialise the Radio, and power it down.
466  @note
467  This can be called independently of all other functions to power down
468  the radio
469  @return RIE_Responses Error code.
470 **/
471 
473 {
474  RIE_Responses Response = RIE_Success;
475 
476  // Disable the radio interrupt
478 
479  // Initialise GPIO Port 2 for Radio Use
480  pADI_GP2->GPCON = GP2CON_CON0_SPI0MISO | GP2CON_CON1_SPI0SCLK |
481  GP2CON_CON2_SPI0MOSI | GP2CON_CON3_GPIO |
482  GP2CON_CON4_IRQ8 | GP2CON_CON5_GPIO |
483  GP2CON_CON6_GPIO | GP2CON_CON7_GPIOIRQ7;
484 
485  pADI_GP2->GPOEN = GP2OEN_OEN0_IN | GP2OEN_OEN1_IN |
486  GP2OEN_OEN2_IN | GP2OEN_OEN3_OUT |
487  GP2OEN_OEN4_IN | GP2OEN_OEN5_IN |
488  GP2OEN_OEN6_IN | GP2OEN_OEN7_IN;
489 
490  // Enable the pull-up as we are powering down the radion
491  GP2PUL_PUL4_BBA = 0x1;
492 
493  // Configure the SPI Interface to the Radio and flush it
494  pADI_SPI0->SPIDIV = ((SYSTEM_UCLK/RADIO_SPI_CLK_FREQ)/2)-0x1;
495  pADI_SPI0->SPICON = SPICON_MASEN | // Master mode
496  SPICON_TIM | // Interrupt on transmit
497  SPICON_TFLUSH | // Flush FIFO
498  SPICON_RFLUSH | // Flush FIFO
499  SPICON_ENABLE;
500  pADI_SPI0->SPICON = SPICON_MASEN | // Master mode
501  SPICON_TIM | // Interrupt on transmit
502  SPICON_ENABLE;
503 
504  // Initialise the chip select line to starting position
505  RADIO_CSN_DEASSERT;
506 
507  // Power it down
508  Response = RadioSendCommandNoWait(CMD_HW_RESET);
509 
510  return Response;
511 }
512 
513 /**
514  @fn RIE_Responses RadioPowerOff(void)
515  @brief Shutdown the radio and place it in its lowest power sleep mode.
516  @pre
517  RadioInit() must be called before this function is called.
518  @return RIE_Response Error code.
519 **/
520 
522 {
523  volatile RIE_U32 ulDelay;
524  RIE_Responses Response = RIE_Success;
525 
526  Response = RadioSendCommandNoWait(CMD_HW_RESET);
527 
528  // Delay for approximately 1 ms
529  ulDelay = 0x1000;
530  while (ulDelay--);
531 
532  return Response;
533 }
534 
535 /**
536  @fn RIE_Responses RadioTerminateRadioOp(void)
537  @brief Terminate a currently running radio RX or TX operation.
538  @pre RadioInit() must be called before this function is called.
539  @code
540  if (RIE_Response == RIE_Success)
541  RIE_Response = RadioRxPacketFixedLen(12);
542  // Delay for a while waiting for a packet
543  if (RIE_Response == RIE_Success)
544  {
545  // Abort the waiting
546  RIE_Response = RadioTerminateRadioOp();
547  }
548  @endcode
549  @return RIE_Responses Error code
550 **/
552 {
553  RIE_Responses Response = RIE_Success;
554 
555  Response = RadioToOnMode();
556 
557  return Response;
558 }
559 
560 /**
561  @fn RIE_Responses RadioSetFrequency(RIE_U32 Frequency)
562  @brief Set frequency for radio communications
563  @param Frequency :{431000000-928000000}
564  - This must be within the available bands of the radio:
565  - 431000000Hz to 464000000Hz and
566  - 862000000Hz to 928000000Hz.
567  @pre RadioInit() must be called before this function is called.
568  @code
569  if (RIE_Response == RIE_Success)
570  RIE_Response = RadioSetFrequency(915000000);
571  @endcode
572  @return RIE_Responses Error code
573 **/
575 {
576  RIE_Responses Response = RIE_Success;
577  RIE_U32 EncodedFrequency;
578 
579  bRadioConfigurationChanged = RIE_TRUE;
580 
581  EncodedFrequency = (RIE_U32)(Frequency * FREQ_CNVRT_VAL);
582  RadioConfiguration.channel_freq_0_r = (EncodedFrequency >> 0) & 0xFF;
583  RadioConfiguration.channel_freq_1_r = (EncodedFrequency >> 8) & 0xFF;
584  RadioConfiguration.channel_freq_2_r = (EncodedFrequency >> 16)& 0xFF;
585  if (Frequency >= 862000000)
586  {
587  RadioConfiguration.image_reject_cal_amplitude_r = 0x07;
588  RadioConfiguration.image_reject_cal_phase_r = 0x16;
589  }
590  else
591  {
592  RadioConfiguration.image_reject_cal_amplitude_r = 0x03;
593  RadioConfiguration.image_reject_cal_phase_r = 0x08;
594  }
595  return Response;
596 }
597 
598 /**
599  @fn RIE_Responses RadioSetModulationType(RIE_ModulationTypes ModulationType)
600  @brief Set the Radio Transmitter Modulation Type. Can be FSK_Modulation or GFSK_Modulation.
601  @param ModulationType :{DR_1_0kbps_Dev10_0kHz , DR_38_4kbps_Dev20kHz ,DR_300_0kbps_Dev75_0kHz }
602  - DR_1_0kbps_Dev10_0kHz Base configuration of 1 kbps datarate, 10.0 kHz frequency deviation.
603  - DR_38_4kbps_Dev20kHz Base configuration of 38.4 kbps datarate, 20 kHz frequency deviation.
604  - DR_300_0kbps_Dev75_0kHz Base configuration of 300 kbps datarate, 75 kHz frequency deviation.
605  @pre RadioInit() must be called before this function is called.
606  @code
607  Response = RadioSetModulationType(GFSK_Modulation);
608  @endcode
609  @note FSK_Modulation is used by default.
610  @return RIE_Responses Error code
611 **/
613 {
614  RIE_Responses Response = RIE_Success;
615  RIE_U8 ucNewCode;
616  RIE_U8 ucNewRegVal = RadioConfiguration.radio_cfg_9_r;
617 
618  switch (ModulationType)
619  {
620  case FSK_Modulation:
621  ucNewCode = radio_cfg_9_mod_scheme_2_level_FSK;
622  break;
623  case GFSK_Modulation:
624  ucNewCode = radio_cfg_9_mod_scheme_2_level_GFSK;
625  break;
626  default:
627  Response = RIE_UnsupportedRadioConfig;
628  break;
629  }
630  if(Response == RIE_Success)
631  {
632  ucNewRegVal = MSKSET_VAL(RadioConfiguration.radio_cfg_9_r,
633  radio_cfg_9_mod_scheme_numbits,
634  radio_cfg_9_mod_scheme_offset,
635  ucNewCode);
636  if (ucNewRegVal != RadioConfiguration.radio_cfg_9_r )
637  {
638  bRadioConfigurationChanged = RIE_TRUE;
639  RadioConfiguration.radio_cfg_9_r = ucNewRegVal;
640  }
641 
642  }
643  return Response;
644 }
645 
646 /**
647  @fn RIE_Responses RadioPayldManchesterEncode(RIE_BOOL bEnable)
648  @brief Enable or Disable Manchester Encoding of payload data.
649 
650  Manchester encoding can be used to ensure a dc-free (zero mean)
651  transmission.
652 
653  A Binary 0 is mapped to 10, and a Binary 1 is mapped to 01.
654 
655  Manchester encoding and decoding are applied to the payload data
656  and the CRC.
657 
658  @param bEnable :{RIE_FALSE,RIE_TRUE}
659  - RIE_TRUE if Manchester Encoding is to be enabled.
660  - RIE_FALSE if disabled.
661 
662  @pre RadioInit() must be called before this function is called.
663  @code
664  Response = RadioPayldManchesterEncode(RIE_TRUE);
665 
666  @endcode
667  @note Manchester Encoding is disabled by default.
668  @return RIE_Responses Error code
669 **/
671 {
672  RIE_Responses Response = RIE_Success;
673  RIE_U8 ucNewRegVal = RadioConfiguration.symbol_mode_r;
674 
675  switch (bEnable)
676  {
677  case RIE_FALSE:
678  ucNewRegVal &= ~symbol_mode_manchester_enc_enabled;
679  break;
680  case RIE_TRUE:
681  ucNewRegVal |= symbol_mode_manchester_enc_enabled;
682  break;
683  default:
684  Response = RIE_UnsupportedRadioConfig;
685  break;
686  }
687  if(Response == RIE_Success)
688  {
689  if (ucNewRegVal != RadioConfiguration.symbol_mode_r )
690  {
691  bRadioConfigurationChanged = RIE_TRUE;
692  RadioConfiguration.symbol_mode_r = ucNewRegVal;
693  }
694  }
695  return Response;
696 }
697 /**
698  @fn RIE_Responses RadioPayldDataWhitening(RIE_BOOL bEnable)
699  @brief Enable or Disable Data Whitening of payload data.
700 
701  Data whitening can be employed to avoid long runs of 1s or 0s
702  in the transmitted data stream.
703 
704  This ensures sufficient bit transitions in the packet, which
705  aids in receiver clock and data recovery because the encoding
706  breaks up long runs of 1s or 0s in the transmit packet.
707 
708  The data, excluding the preamble and sync word, is automatically
709  whitened before transmission by XORing the data with an 8-bit
710  pseudorandom sequence.
711 
712  At the receiver, the data is XORed with the same pseudorandom
713  sequence, thereby reversing the whitening.
714 
715  The linear feedback shift register polynomial used is x7 + x1 + 1.
716 
717  @param bEnable :{RIE_FALSE, RIE_TRUE}
718  - RIE_TRUE if Manchester Encoding is to be enabled.
719  - RIE_FALSE if disabled.
720 
721  @pre RadioInit() must be called before this function is called.
722  @code
723  Response = RadioPayldDataWhitening(RIE_TRUE);
724 
725  @endcode
726  @note Data Whitening is disabled by default.
727  @return RIE_Responses Error code
728 **/
730 {
731  RIE_Responses Response = RIE_Success;
732  RIE_U8 ucNewRegVal = RadioConfiguration.symbol_mode_r;
733 
734  switch (bEnable)
735  {
736  case RIE_FALSE:
737  ucNewRegVal &= ~symbol_mode_data_whitening_enabled;
738  break;
739  case RIE_TRUE:
740  ucNewRegVal |= symbol_mode_data_whitening_enabled;
741  break;
742  default:
743  Response = RIE_UnsupportedRadioConfig;
744  break;
745  }
746  if(Response == RIE_Success)
747  {
748  if (ucNewRegVal != RadioConfiguration.symbol_mode_r )
749  {
750  bRadioConfigurationChanged = RIE_TRUE;
751  RadioConfiguration.symbol_mode_r = ucNewRegVal;
752  }
753  }
754  return Response;
755 }
756 
757 /**
758  @fn RIE_Responses RadioTxPacketFixedLen(RIE_U8 Len, RIE_U8 *pData)
759  @brief Transmit a fixed length packet.
760  @param Len :{1-240} Length of packet to be transmitted.
761  @param pData :{} Data bytes to be transmitted.
762  @pre RadioInit() must be called before this function is called.
763  @code
764  if (RIE_Response == RIE_Success)
765  RIE_Response = RadioTxSetPA(DifferentialPA,PowerLevel15);
766  if (RIE_Response == RIE_Success)
767  RIE_Response = RadioTxPacketFixedLen(12, "HELLO WORLD");
768  while (!RadioTxPacketComplete());
769  @endcode
770  @return RIE_Responses Error code
771 **/
772 RIE_Responses RadioTxPacketFixedLen(RIE_U8 Len, RIE_U8 *pData)
773 {
774  RIE_Responses Response = RIE_Success;
775 
776  bPacketTx = RIE_FALSE;
777  if (Len > PACKETRAM_LEN)
778  Response = RIE_InvalidParamter;
779  if (Response == RIE_Success)
780  Response = RadioToOnMode();
781  if (Response == RIE_Success)
782  Response = RadioMMapWrite(PACKETRAM_START, Len, pData);
783  if (Response == RIE_Success)
784  {
785  RadioConfiguration.packet_length_max_r = Len;
786  RadioConfiguration.packet_length_control_r |= packet_length_control_packet_len_fixed;
787  }
788  if(Response == RIE_Success)
789  Response = RadioCommitRadioConfig();
790  if (Response == RIE_Success)
791  Response = RadioToOnMode();
792  if (Response == RIE_Success)
793  Response = RadioSendCommandWait(CMD_PHY_TX);
794 
795  return Response;
796 }
797 
798 /**
799  @fn RIE_Responses RadioTxPacketVariableLen(RIE_U8 Len, RIE_U8 *pData)
800  @brief Transmit a Variable length packet.
801  @param Len :{1-240} Length of packet to be transmitted.
802  @param pData :{} Data bytes to be transmitted.
803  @pre RadioInit() must be called before this function is called.
804  @code
805  if (RIE_Response == RIE_Success)
806  RIE_Response = RadioTxSetPA(DifferentialPA,PowerLevel15);
807  if (RIE_Response == RIE_Success)
808  RIE_Response = RadioTxPacketVariableLen(12, "HELLO WORLD");
809  while (!RadioTxPacketComplete());
810  @endcode
811  @return RIE_Responses Error code
812 **/
813 RIE_Responses RadioTxPacketVariableLen(RIE_U8 Len, RIE_U8 *pData)
814 {
815  RIE_Responses Response = RIE_Success;
816 
817  bPacketTx = RIE_FALSE;
818 
819  Len += 0x1;
820  if (Len > PACKETRAM_LEN)
821  Response = RIE_InvalidParamter;
822  if (Response == RIE_Success)
823  Response = RadioToOnMode();
824  if (Response == RIE_Success)
825  Response = RadioMMapWrite(PACKETRAM_START, 0x1, &Len);
826  if (Response == RIE_Success)
827  Response = RadioMMapWrite(PACKETRAM_START+0x1, Len-1, pData);
828  if (Response == RIE_Success)
829  {
830  RadioConfiguration.packet_length_max_r = PACKETRAM_LEN;
831  RadioConfiguration.packet_length_control_r &= ~packet_length_control_packet_len_fixed;
832  }
833  if(Response == RIE_Success)
834  Response = RadioCommitRadioConfig();
835  if (Response == RIE_Success)
836  Response = RadioToOnMode();
837  if (Response == RIE_Success)
838  Response = RadioSendCommandWait(CMD_PHY_TX);
839 
840  return Response;
841 }
842 
843 
844 /**
845  @fn RIE_BOOL RadioTxPacketComplete(void)
846  @brief Checks if a packet has finished transmitting
847  @pre RadioInit() must be called before this function is called.
848  @pre RadioRxPacketFixedLen() or equivalent should be called first.
849  @code
850  if (RIE_Response == RIE_Success)
851  RIE_Response = RadioTxSetPA(DifferentialPA,PowerLevel15);
852  if (RIE_Response == RIE_Success)
853  RIE_Response = RadioTxPacketFixedLen(12, "HELLO WORLD");
854  while (!RadioTxPacketComplete());
855  @endcode
856  @return RIE_BOOL RIE_TRUE if packet has finished transmitting, else RIE_FALSE
857 **/
859 {
860  return bPacketTx;
861 }
862 
863 /**
864  @fn RIE_Responses RadioTxSetPA(RIE_PATypes PAType,RIE_PAPowerLevel Power)
865  @brief Set PA Type and the Transmit Power Level for Radio Transmission.
866  @param PAType :{DifferentialPA, SingleEndedPA} Select Single Ended or Differential PA Type
867  @param Power :{PowerLevel0 ,PowerLevel1 ,PowerLevel2 ,PowerLevel3,
868  PowerLevel4 ,PowerLevel5 ,PowerLevel6 ,PowerLevel7,
869  PowerLevel8 ,PowerLevel9 ,PowerLevel10,PowerLevel11,
870  PowerLevel12,PowerLevel13,PowerLevel14,PowerLevel15}
871  @pre RadioInit() must be called before this function is called.
872  @code
873  Response = RadioTxSetPA(SingleEndedPA,PowerLevel8);
874  @endcode
875  @note Differential PA is enabled by default.
876  @note Max TX Power is used by default.
877  @return RIE_Responses Error code
878 **/
879 RIE_Responses RadioTxSetPA(RIE_PATypes PAType,RIE_PAPowerLevel Power)
880 {
881  RIE_Responses Response = RIE_Success;
882  RIE_U8 ucNewRegVal = 0x0;
883  unsigned long pa_level_mcr,pa_ramp, codes_per_bit,min_codes_per_bit;
884 
885  switch (PAType)
886  {
887  case DifferentialPA:
888  ucNewRegVal |= radio_cfg_8_pa_single_diff_sel_differential;
889  break;
890  case SingleEndedPA:
891  ucNewRegVal |= radio_cfg_8_pa_single_diff_sel_single_ended;
892  break;
893  default:
894  Response = RIE_UnsupportedRadioConfig;
895  break;
896  }
897  if(Response == RIE_Success)
898  {
899  switch (Power)
900  {
901  case PowerLevel0 :
902  case PowerLevel1 :
903  case PowerLevel2 :
904  case PowerLevel3 :
905  case PowerLevel4 :
906  case PowerLevel5 :
907  case PowerLevel6 :
908  case PowerLevel7 :
909  case PowerLevel8 :
910  case PowerLevel9 :
911  case PowerLevel10:
912  case PowerLevel11:
913  case PowerLevel12:
914  case PowerLevel13:
915  case PowerLevel14:
916  case PowerLevel15:
917  ucNewRegVal |= ((RIE_U8)Power << radio_cfg_8_pa_power_offset);
918  // Calculate the minimum allowable codes per bit
919  pa_level_mcr = (((RIE_U8)Power)* 4) + 0x3;
920  min_codes_per_bit = (pa_level_mcr * 2500)/(DataRate/100);
921  pa_ramp = 0x1;
922  codes_per_bit = 256;
923  while (codes_per_bit > min_codes_per_bit)
924  {
925  pa_ramp++;
926  codes_per_bit = 512 >> pa_ramp;
927  if (pa_ramp >= 7)
928  break; // This is the maximum
929  }
930  ucNewRegVal |= ((RIE_U8)pa_ramp << radio_cfg_8_pa_ramp_offset);
931  break;
932  default:
933  Response = RIE_UnsupportedRadioConfig;
934  break;
935  }
936  }
937 
938  if(Response == RIE_Success)
939  {
940  if (ucNewRegVal != RadioConfiguration.radio_cfg_8_r )
941  {
942  bRadioConfigurationChanged = RIE_TRUE;
943  RadioConfiguration.radio_cfg_8_r = ucNewRegVal;
944  }
945  }
946  return Response;
947 }
948 /**
949  @fn RIE_Responses RadioTxCarrier(void)
950  @brief Transmit a carrier tone
951  using the current radio configuration.
952  @pre RadioInit() must be called before this function is called.
953  @code
954  Response = RadioTxCarrier();
955  @endcode
956  @note Terminate this mode by calling RadioTerminateRadioOp();
957  @return RIE_Responses Error code
958 **/
960 {
961  RIE_Responses Response = RIE_Success;
962  RIE_U8 ParamTX = PARAM_TX_CARRIER_FOREVER;
963 
964  if(Response == RIE_Success)
965  Response = RadioCommitRadioConfig();
966  bTestModeEnabled = RIE_TRUE;
967  if (Response == RIE_Success)
968  Response = RadioToOnMode();
969  // Mode needs to be set, before entry to PHY_TX
970  if (Response == RIE_Success)
971  Response = RadioMMapWrite(PR_var_tx_mode_ADR,sizeof(ParamTX),&ParamTX);
972  if (Response == RIE_Success)
973  Response = RadioSendCommandWait(CMD_PHY_TX);
974  return Response;
975 }
976 /**
977  @fn RIE_Responses RadioTxPreamble(void)
978  @brief Transmit a pre-amble (alternating ones and zeros)
979  using the current radio configuration.
980  @pre RadioInit() must be called before this function is called.
981  @code
982  Response = RadioTxPreamble();
983  @endcode
984  @note Terminate this mode by calling RadioTerminateRadioOp();
985  @return RIE_Responses Error code
986 **/
988 {
989  RIE_Responses Response = RIE_Success;
990  RIE_U8 ParamTX = PARAM_TX_PREAMBLE_FOREVER;
991 
992  if(Response == RIE_Success)
993  Response = RadioCommitRadioConfig();
994  if (Response == RIE_Success)
995  Response = RadioToOnMode();
996  bTestModeEnabled = RIE_TRUE;
997  // Mode needs to be set, before entry to PHY_TX
998  if (Response == RIE_Success)
999  Response = RadioMMapWrite(PR_var_tx_mode_ADR,sizeof(ParamTX),&ParamTX);
1000  if (Response == RIE_Success)
1001  Response = RadioSendCommandWait(CMD_PHY_TX);
1002  return Response;
1003 }
1004 
1005 /**
1006  @fn RIE_Responses RadioRxPacketFixedLen(RIE_U8 Len)
1007  @brief Enter receive mode and wait for a packet to be received.
1008 
1009  Radio will stay in Receive Mode until
1010  1) A packet is received.
1011  2) User manually exits Receive Mode with a call to RadioTerminateRadioOp()
1012 
1013  @param Len :{1-240} Fixed Length of packet to be received.
1014  @pre RadioInit() must be called before this function is called.
1015  @return RIE_Responses Error code
1016 **/
1018 {
1019  RIE_Responses Response = RIE_Success;
1020 
1021  bPacketRx = RIE_FALSE;
1022  if (Len > PACKETRAM_LEN)
1023  Response = RIE_InvalidParamter;
1024 
1025  if (Response == RIE_Success)
1026  {
1027  RadioConfiguration.packet_length_max_r = Len;
1028  RadioConfiguration.packet_length_control_r |= packet_length_control_packet_len_fixed;
1029  }
1030  if(Response == RIE_Success)
1031  Response = RadioCommitRadioConfig();
1032  if (Response == RIE_Success)
1033  Response = RadioToOnMode();
1034  if (Response == RIE_Success)
1035  Response = RadioSendCommandWait(CMD_PHY_RX);
1036  return Response;
1037 }
1038 
1039 /**
1040  @fn RIE_Responses RadioRxPacketVariableLen(void)
1041  @brief Enter receive mode and wait for a packet to be received.
1042 
1043  Radio will stay in Receive Mode until
1044  1) A packet is received.
1045  2) User manually exits Receive Mode with a call to RadioTerminateRadioOp()
1046 
1047  @pre RadioInit() must be called before this function is called.
1048  @return RIE_Responses Error code
1049 **/
1051 {
1052  RIE_Responses Response = RIE_Success;
1053 
1054  bPacketRx = RIE_FALSE;
1055 
1056  if (Response == RIE_Success)
1057  {
1058  RadioConfiguration.packet_length_max_r = PACKETRAM_LEN;
1059  RadioConfiguration.packet_length_control_r &= ~packet_length_control_packet_len_fixed;
1060  }
1061  if(Response == RIE_Success)
1062  Response = RadioCommitRadioConfig();
1063  if (Response == RIE_Success)
1064  Response = RadioToOnMode();
1065  if (Response == RIE_Success)
1066  Response = RadioSendCommandWait(CMD_PHY_RX);
1067  return Response;
1068 }
1069 
1070 /**
1071  @fn RIE_BOOL RadioRxPacketAvailable(void)
1072  @brief Checks if a packet has been received.
1073  @pre RadioInit() must be called before this function is called.
1074  @pre RadioRxPacketFixedLen() or equivalent should be called first.
1075  @code
1076  if (RIE_Response == RIE_Success)
1077  RIE_Response = RadioRxPacketFixedLen(12);
1078  if (RIE_Response == RIE_Success)
1079  {
1080  while (!RadioRxPacketAvailable());
1081  }
1082  if (RIE_Response == RIE_Success)
1083  {
1084  unsigned char Buffer[0x20];
1085  RIE_U8 PktLen;
1086  RIE_S8 RSSI;
1087  RIE_Response = RadioRxPacketRead(sizeof(Buffer),&PktLen,Buffer,&RSSI);
1088  }
1089  @endcode
1090  @return RIE_BOOL RIE_TRUE if packet received, else RIE_FALSE
1091 **/
1093 {
1094  return bPacketRx;
1095 
1096 }
1097 
1098 /**
1099  @fn RIE_Responses RadioRxPacketRead(RIE_U8 BufferLen,RIE_U8 *pPktLen,RIE_U8 *pData,RIE_S8 *pRSSIdBm)
1100  @brief Read the packet that was received by the radio.
1101  @param BufferLen :{1-240} Size of passed in buffer
1102  @param pPktLen :{1-240} Storage for size of actual received packet
1103  @param pData :{} Received Packet will be stored here.
1104  @param pRSSIdBm :{} RSSI of received packet in dBm.
1105  @pre RadioInit() must be called before this function is called.
1106  @pre RadioRxPacketFixedLen() or equivalent should be called first.
1107  @code
1108  if (RIE_Response == RIE_Success)
1109  RIE_Response = RadioRxPacketFixedLen(12);
1110  if (RIE_Response == RIE_Success)
1111  {
1112  while (!RadioRxPacketAvailable());
1113  }
1114  if (RIE_Response == RIE_Success)
1115  {
1116  unsigned char Buffer[0x20];
1117  RIE_U8 PktLen;
1118  RIE_S8 RSSI;
1119  RIE_Response = RadioRxPacketRead(sizeof(Buffer),&PktLen,Buffer,&RSSI);
1120  }
1121  @endcode
1122  @note Check for the presence of a packet by calling RadioRxPacketAvailable();
1123  @return RIE_Responses Error code
1124 **/
1125 RIE_Responses RadioRxPacketRead(RIE_U8 BufferLen,RIE_U8 *pPktLen,RIE_U8 *pData,RIE_S8 *pRSSIdBm)
1126 {
1127  RIE_Responses Response = RIE_Success;
1128 
1129  if (RadioRxPacketAvailable())
1130  {
1131  RIE_U8 RdLen;
1132  if(RadioConfiguration.packet_length_control_r & packet_length_control_packet_len_fixed)
1133  {
1134  if (pPktLen)
1135  *pPktLen = RadioConfiguration.packet_length_max_r;
1136  RdLen = RadioConfiguration.packet_length_max_r;
1137  if (RdLen > BufferLen)
1138  RdLen = BufferLen;
1139  if (Response == RIE_Success)
1140  Response = RadioMMapRead(PACKETRAM_START,RdLen, pData);
1141  }
1142  else
1143  {
1144  if (Response == RIE_Success)
1145  Response = RadioMMapRead(PACKETRAM_START,0x1, &RdLen);
1146  RdLen -= 0x1;
1147  if (pPktLen)
1148  *pPktLen = RdLen;
1149  if (RdLen > BufferLen)
1150  RdLen = BufferLen;
1151  if (Response == RIE_Success)
1152  Response = RadioMMapRead(PACKETRAM_START+0x1,RdLen, pData);
1153  }
1154 
1155  if (pRSSIdBm)
1156  {
1157  if (Response == RIE_Success)
1158  Response = RadioMMapRead(MCR_rssi_readback_Adr,0x1, (RIE_U8 *)pRSSIdBm);
1159 
1160  *pRSSIdBm -= 107; // Convert to dBm
1161  }
1162 
1163  }
1164  else
1165  {
1166  if (pPktLen)
1167  *pPktLen = 0x0;
1168  }
1169 
1170  return Response;
1171 }
1172 
1173 /**
1174  @fn RIE_Responses RadioRxBERTestMode(void)
1175  @brief Enter receiver Bit Error Rate (BER) test mode where the
1176  clock and data appear on GPIO pins.
1177  Clock on P0.6 and Data on P2.6
1178  @pre RadioInit() must be called before this function is called.
1179  @code
1180  Response = RadioRxBERTestMode();
1181  @endcode
1182  @note Terminate this mode by calling RadioTerminateRadioOp();
1183  @return RIE_Responses Error code
1184 **/
1186 {
1187  RIE_Responses Response = RIE_Success;
1188  RIE_U8 Data;
1189  // Enables internal radio signals on external pins
1190  // but overrides some of the standard GPIO muxed
1191  // functionality (UART?)
1192  pADI_MISC->RFTST = 0x7E1;
1193 
1194  if(Response == RIE_Success)
1195  Response = RadioCommitRadioConfig();
1196 
1197  bTestModeEnabled = RIE_TRUE;
1198  // Enable the RX signals on GPIO pins
1199  Data = gpio_configure_sport_mode_0;
1200  if (Response == RIE_Success)
1201  Response = RadioMMapWrite(MCR_gpio_configure_Adr, 0x1, (RIE_U8 *)&Data);
1202 
1203  // disable ext_uc_clk on GP5
1204  Data = 0;
1205  if (Response == RIE_Success)
1206  Response = RadioMMapWrite(MCR_ext_uc_clk_divide_Adr,
1207  0x1,
1208  (RIE_U8 *)&Data);
1209  if (Response == RIE_Success)
1210  Response = RadioSendCommandWait(CMD_PHY_RX);
1211  return Response;
1212 }
1213 
1214 /**
1215  @internal Hide from Doxegen
1216  @fn RIE_Responses RadioCommitRadioConfig(void)
1217  @brief Configures the radio if any changes were made
1218  since the last time.
1219  @return RIE_Responses Error code
1220 **/
1221 static RIE_Responses RadioCommitRadioConfig(void)
1222 {
1223  RIE_Responses Response = RIE_Success;
1224 
1225  if(bTestModeEnabled)
1226  {
1227  RIE_U8 Data;
1228  Data = gpio_configure_default;
1229  if (Response == RIE_Success)
1230  Response = RadioMMapWrite(MCR_gpio_configure_Adr, 0x1, (RIE_U8 *)&Data);
1231  Data = 4;
1232  if (Response == RIE_Success)
1233  Response = RadioMMapWrite(MCR_ext_uc_clk_divide_Adr,
1234  0x1,
1235  (RIE_U8 *)&Data);
1236 
1237  Data = PARAM_TX_NORMAL_PACKET;
1238  if (Response == RIE_Success)
1239  Response = RadioMMapWrite(PR_var_tx_mode_ADR,sizeof(Data),&Data);
1240  bTestModeEnabled = RIE_FALSE;
1241  }
1242  if (bRadioConfigurationChanged)
1243  {
1244  Response = RadioConfigure();
1245  if(Response == RIE_Success)
1246  bRadioConfigurationChanged = RIE_FALSE;
1247  }
1248  return Response;
1249 }
1250 /**
1251  @fn RIE_Responses RadioReadState(RadioState *pState)
1252  @brief Read the current state
1253  @param pState Pointer to return storage of state
1254  @return RIE_Responses Error code
1255 **/
1256 static RIE_Responses RadioReadState(RadioState *pState)
1257 {
1258  RIE_Responses Response = RIE_Success;
1259  RIE_U8 StatusByte;
1260 
1262  RADIO_CSN_ASSERT;
1263  if (Response == RIE_Success)
1264  Response = RadioSPIXferByte(SPI_NOP,NULL);
1265  if (Response == RIE_Success)
1266  Response = RadioSPIXferByte(SPI_NOP,&StatusByte);
1267  RADIO_CSN_DEASSERT;
1269  if ((Response == RIE_Success) && pState)
1270  *pState = (RadioState)(StatusByte & STATUS_BYTE_FW_STATE);
1271  return Response;
1272 }
1273 
1274 /**
1275  @fn RIE_Responses RadioWaitOnState(RadioState FinalState)
1276  @brief Wait for Final State to be reached
1277  @param FinalState State to wait on
1278  @return RIE_Responses Error code
1279 **/
1280 static RIE_Responses RadioWaitOnState(RadioState FinalState)
1281 {
1282  RIE_Responses Response = RIE_Success;
1283  RadioState CurrState;
1284  do
1285  {
1286  Response = RadioReadState(&CurrState);
1287  }
1288  while((Response == RIE_Success) && (CurrState != FinalState));
1289  return Response;
1290 }
1291 
1292 /**
1293  @fn RIE_Responses RadioWaitOnCmdLdr(void)
1294  @brief Wait for Final State to be reached
1295  @param FinalState State to wait on
1296  @return RIE_Responses Error code
1297 **/
1298 static RIE_Responses RadioWaitOnCmdLdr(void)
1299 {
1300  RIE_Responses Response = RIE_Success;
1301  do
1302  {
1303  RIE_U8 StatusByte;
1305  RADIO_CSN_ASSERT;
1306  if (Response == RIE_Success)
1307  Response = RadioSPIXferByte(SPI_NOP,NULL);
1308  if (Response == RIE_Success)
1309  Response = RadioSPIXferByte(SPI_NOP,&StatusByte);
1310  RADIO_CSN_DEASSERT;
1312  if ((Response == RIE_Success))
1313  if(StatusByte & STATUS_BYTE_CMD_READY)
1314  break;
1315  }
1316  while((Response == RIE_Success));
1317  return Response;
1318 }
1319 
1320 /**
1321  @internal Hide from Doxegen
1322  @fn RIE_Responses RadioToOnMode(void)
1323  @brief Transition to On Mode
1324 
1325  Handle all possible states that the radio could be in
1326  and brings it back to PHY_ON state
1327  @param None
1328  @return RIE_Responses Error code
1329 **/
1330 static RIE_Responses RadioToOnMode(void)
1331 {
1332  RIE_Responses Response = RIE_Success;
1333  RadioState FwState;
1334 
1335  if (Response == RIE_Success)
1336  Response = RadioReadState(&FwState);
1337 
1338  while ((FwState != FW_ON) && (Response == RIE_Success))
1339  {
1340  switch (FwState)
1341  {
1342  case FW_BUSY:
1343  break;
1344  case FW_TX:
1345  if(Response == RIE_Success)
1346  Response = RadioSendCommandNoWait(CMD_PHY_ON);
1347  if (Response == RIE_Success)
1348  Response = RadioWaitOnState (FW_ON);
1349  break;
1350  case FW_RX:
1351  if(Response == RIE_Success)
1352  Response = RadioSendCommandNoWait(CMD_PHY_ON);
1353  if (Response == RIE_Success)
1354  Response = RadioWaitOnState (FW_ON);
1355  break;
1356  default:
1357  if(Response == RIE_Success)
1358  Response = RadioSendCommandNoWait(CMD_PHY_ON);
1359  if (Response == RIE_Success)
1360  Response = RadioWaitOnState (FW_ON);
1361  break;
1362  }
1363  if (Response == RIE_Success)
1364  Response = RadioReadState(&FwState);
1365  }
1366  return Response;
1367 }
1368 /**
1369  @internal Hide from Doxegen
1370  @fn RIE_Responses RadioToOffMode(void)
1371  @brief Transition to Off Mode
1372 
1373  Handle all possible states that the radio could be in
1374  and bring it back to PHY_OFF state.
1375 
1376  @param None
1377  @return RIE_Responses Error code
1378 **/
1379 static RIE_Responses RadioToOffMode(void)
1380 {
1381  RIE_Responses Response = RIE_Success;
1382  RadioState FwState;
1383 
1384  if (Response == RIE_Success)
1385  Response = RadioReadState(&FwState);
1386 
1387  while ((FwState != FW_OFF) && (Response == RIE_Success))
1388  {
1389  switch (FwState)
1390  {
1391  case FW_BUSY:
1392  break;
1393  case FW_TX:
1394  if(Response == RIE_Success)
1395  Response = RadioSendCommandNoWait(CMD_PHY_ON);
1396  if (Response == RIE_Success)
1397  Response = RadioWaitOnState (FW_ON);
1398  break;
1399  case FW_RX:
1400  if(Response == RIE_Success)
1401  Response = RadioSendCommandNoWait(CMD_PHY_ON);
1402  if (Response == RIE_Success)
1403  Response = RadioWaitOnState (FW_ON);
1404  break;
1405  default:
1406  if(Response == RIE_Success)
1407  Response = RadioSendCommandNoWait(CMD_PHY_OFF);
1408  if (Response == RIE_Success)
1409  Response = RadioWaitOnState (FW_OFF);
1410  break;
1411  }
1412  if (Response == RIE_Success)
1413  Response = RadioReadState(&FwState);
1414  }
1415  return Response;
1416 }
1417 /**
1418  @internal Hide from Doxegen
1419  @fn RIE_Responses RadioSyncComms (void)
1420  @brief Sync comms with the radio
1421  @param None
1422  @return RIE_Responses Error code
1423 **/
1424 static RIE_Responses RadioSyncComms (void)
1425 {
1426  RIE_Responses Response = RIE_Success;
1427  if (Response == RIE_Success)
1428  Response = RadioSendCommandWait(CMD_SYNC);
1429  if (Response == RIE_Success)
1430  Response = RadioWaitOnCmdLdr();
1431  return Response;
1432 }
1433 /**
1434  @fn RIE_Responses RadioWaitForPowerUp(void)
1435  @brief Wake Up the Part
1436 
1437  Assert SPI chip select which will wake up the radio if asleep
1438  Wait for MISO line to go high indicating SPI comms now possible
1439 
1440  @return RIE_Responses Error code
1441 **/
1442 static RIE_Responses RadioWaitForPowerUp(void)
1443 {
1444  RIE_Responses Response = RIE_Success;
1445  int i = 0x0;
1446  RADIO_CSN_ASSERT;
1447  while (!RADIO_MISO_IN && (i < 1000))
1448  i++;
1449  if (1000 == i)// Timed out waiting for MISO high?
1450  Response = RIE_RadioSPICommsFail;
1451  RADIO_CSN_DEASSERT;
1452  return Response;
1453 }
1454 
1455 /**
1456  \internal Hide from Doxegen
1457  \fn void Ext_Int8_Handler(void)
1458  \brief Radio Interrupt Handler
1459 **/
1460 extern void aducrf101_rx_packet_hook(void);
1461 void Ext_Int8_Handler (void)
1462 {
1463  RIE_Responses Response = RIE_Success;
1464  RIE_U8 ucInt0;
1465  RIE_U8 ucInt1;
1466 
1467  if (Response == RIE_Success)
1468  Response = RadioMMapRead(MCR_interrupt_source_0_Adr,0x1, &ucInt0);
1469  if (Response == RIE_Success)
1470  Response = RadioMMapRead(MCR_interrupt_source_1_Adr,0x1,&ucInt1);
1471  if (ucInt0 & interrupt_mask_0_interrupt_tx_eof)
1472  bPacketTx = RIE_TRUE;
1473  if (ucInt0 & interrupt_mask_0_interrupt_crc_correct) {
1474  bPacketRx = RIE_TRUE;
1476  }
1477  // Clear all the interrupts that we have just handleed
1478  if (Response == RIE_Success)
1479  Response = RadioMMapWrite(MCR_interrupt_source_0_Adr,0x1, &ucInt0);
1480  if (Response == RIE_Success)
1481  Response = RadioMMapWrite(MCR_interrupt_source_1_Adr,0x1,&ucInt1);
1482  // Clear the interrupt
1483  pADI_INTERRUPT->EICLR = EICLR_IRQ8;
1484 }
1485 /**
1486  \internal Hide from Doxegen
1487  \fn void RadioSPIXferByte(RIE_U8 ucByte,RIE_U8 *pData)
1488  \brief Transfer a byte via SPI to the radio and optionally return
1489  received byte.
1490  Chip Select is manually controlled elsewhere.
1491  \param ucByte Command or data byte to be transferred.
1492  \param pData NULL, or storage for response
1493  \return RIE_Responses Error code
1494 **/
1495 static RIE_Responses RadioSPIXferByte(RIE_U8 ucByte,RIE_U8 *pData)
1496 {
1497  RIE_Responses Response = RIE_Success;
1498 
1499  SEND_SPI(ucByte); // Send byte
1500  WAIT_SPI_RX; // wait for data received status bit
1501  if(pData)
1502  *pData = READ_SPI;
1503  else
1504  (void)READ_SPI;
1505  return Response;
1506 }
1507 /**
1508  \internal Hide from Doxegen
1509  \fn RIE_Responses RadioSendCommandBytes(RIE_U8 *pCmdBytes,RIE_U8 NumBytes)
1510  \brief Send a complete command to the radio.
1511 
1512  It is neccessary to disable the radio interrupt when doing this
1513  as a command in progress must finish before a radio interrupt
1514  can be handled.
1515 
1516  \param pCmdBytes Pointer to a number of bytes to be transferred.
1517  \param NumBytes Number of bytes to transfer
1518 
1519  \return RIE_Responses Error code
1520 **/
1521 static RIE_Responses RadioSendCommandBytes(RIE_U8 *pCmdBytes,RIE_U8 NumBytes)
1522 {
1523  RIE_Responses Response = RIE_Success;
1524 
1526  RADIO_CSN_ASSERT;
1527  while ((NumBytes--) && (Response == RIE_Success))
1528  Response = RadioSPIXferByte(*(pCmdBytes++),NULL); // Send Command
1529  RADIO_CSN_DEASSERT; // De-assert SPI chip select
1531 
1532  return Response;
1533 }
1534 /**
1535  \internal Hide from Doxegen
1536  \fn RIE_Responses RadioSendCommandNoWait (Radio_CmdCodes CmdCode )
1537  \brief Send a single byte command to the radio.
1538  \param CmdCode Command code to be sent
1539  \return RIE_Responses Error code
1540 **/
1541 static RIE_Responses RadioSendCommandNoWait (Radio_CmdCodes CmdCode )
1542 {
1543  RIE_U8 Command = (RIE_U8)CmdCode;
1544  return RadioSendCommandBytes(&Command,0x1);
1545 }
1546 /**
1547  \internal Hide from Doxegen
1548  \fn RIE_Responses RadioSendCommandWait (Radio_CmdCodes CmdCode )
1549  \brief Send a single byte command to the radio.
1550  \param CmdCode Command code to be sent
1551  \return RIE_Responses Error code
1552 **/
1553 static RIE_Responses RadioSendCommandWait (Radio_CmdCodes CmdCode )
1554 {
1555  RIE_Responses Response = RIE_Success;
1556  RIE_U8 Command = (RIE_U8)CmdCode;
1557 
1558  if (Response == RIE_Success)
1559  Response = RadioWaitOnCmdLdr();
1560  if (Response == RIE_Success)
1561  Response = RadioSendCommandBytes(&Command,0x1);
1562  return Response;
1563 }
1564 /**
1565  \fn RIE_Responses RadioMMapRead(RIE_U32 ulAdr, RIE_U32 ulLen, RIE_U8 *pData)
1566  \brief Read bytes from specified memory map address
1567  \param ulAdr Address to read at.
1568  \param ulLen Length of data to read.
1569  \param pData Pointer to location to stored read data.
1570  \return RIE_Responses Error code
1571 **/
1572 static RIE_Responses RadioMMapRead(RIE_U32 ulAdr, RIE_U32 ulLen, RIE_U8 *pData)
1573 {
1574  RIE_Responses Response = RIE_Success;
1575 
1577  RADIO_CSN_ASSERT;
1578 
1579  if(Response == RIE_Success) // Send first byte (SPI_MEMR_RD + Bytes)
1580  Response = RadioSPIXferByte(SPI_MEM_RD | ((ulAdr & 0x700) >> 8),NULL);
1581  if(Response == RIE_Success)// Send Second byte remainder of address
1582  Response = RadioSPIXferByte((RIE_U8)(ulAdr & 0xFF),NULL);
1583  if(Response == RIE_Success)
1584  Response = RadioSPIXferByte((RIE_U8)SPI_NOP,NULL);
1585  while(ulLen-- && (Response == RIE_Success))
1586  Response = RadioSPIXferByte(SPI_NOP,pData++);
1587  RADIO_CSN_DEASSERT;
1589 
1590  return Response;
1591 }
1592 /**
1593  \fn RIE_Responses RadioMMapWrite(RIE_U32 ulAdr, RIE_U32 ulLen, RIE_U8 *pData)
1594  \brief Read bytes from specified memory map address
1595  \param ulAdr Address to read at.
1596  \param ulLen Length of data to read.
1597  \param pData Pointer to location of data to write.
1598  \return RIE_Responses Error code
1599 **/
1600 static RIE_Responses RadioMMapWrite(RIE_U32 ulAdr,RIE_U32 ulLen,RIE_U8 * pData)
1601 {
1602  RIE_Responses Response = RIE_Success;
1603 
1605  RADIO_CSN_ASSERT;
1606  if(Response == RIE_Success) // Send first byte (SPI_MEMR_WR + Bytes)
1607  Response = RadioSPIXferByte(SPI_MEM_WR | ((ulAdr & 0x700) >> 8),NULL);
1608  if(Response == RIE_Success) // Send Second byte remainder of addrress
1609  Response = RadioSPIXferByte((RIE_U8)(ulAdr & 0xFF),NULL);
1610  while(ulLen-- && (Response == RIE_Success))
1611  Response = RadioSPIXferByte(*(pData++),NULL);
1612  RADIO_CSN_DEASSERT;
1614 
1615  return Response;
1616 }
1617 
1618 /**
1619  \internal Hide from Doxegen
1620  \fn void SetRadioConfiguration(void)
1621  \brief Create a default radio configuration that all base configurations
1622  are derived from.
1623 
1624  \return RIE_Responses Error code
1625 **/
1626 static RIE_Responses SetRadioConfiguration(RIE_BaseConfigs BaseConfig)
1627 {
1628  RIE_Responses Response = RIE_Success;
1629 
1630  bRadioConfigurationChanged = RIE_TRUE;
1631  switch (BaseConfig)
1632  {
1633  case DR_1_0kbps_Dev10_0kHz:
1634  memcpy((void *)&RadioConfiguration,
1635  (void *)DR_1_0kbps_Dev10_0kHz_Configuration,
1636  sizeof(TyRadioConfiguration));
1637  DataRate = 1000;
1638  break;
1639  case DR_38_4kbps_Dev20kHz:
1640  memcpy((void *)&RadioConfiguration,
1641  (void *)DR_38_4kbps_Dev20kHz_Configuration,
1642  sizeof(TyRadioConfiguration));
1643  DataRate = 38400;
1644  break;
1646  memcpy((void *)&RadioConfiguration,
1647  (void *)DR_300_0kbps_Dev75_0kHz_Configuration,
1648  sizeof(TyRadioConfiguration));
1649  DataRate = 300000;
1650  break;
1651  default:
1652  Response = RIE_UnsupportedRadioConfig;
1653  break;
1654  }
1655  return Response;
1656 }
1657 /**
1658  @internal Hide from Doxegen
1659  @fn RIE_Responses RadioConfigure (void)
1660  @brief Configure the Radio as per the current configuration
1661  @return RIE_Responses Error code
1662 **/
1663 RIE_Responses RadioConfigure (void)
1664 {
1665  RIE_Responses Response = RIE_Success;
1666  if(Response == RIE_Success)
1667  Response = RadioToOffMode();
1668  if(Response == RIE_Success) // Write the configuration to the radio memory
1669  Response = RadioMMapWrite(BBRAM_START,
1670  sizeof(TyRadioConfiguration),
1671  (RIE_U8 *)&RadioConfiguration);
1672  if(Response == RIE_Success) // Apply that configuration to the radio
1673  Response = RadioSendCommandWait(CMD_CONFIG_DEV);
1674  if(Response == RIE_Success)
1675  Response = RadioToOnMode();
1676  return Response;
1677 }
1678 
1679 
1680 /**
1681  @fn RIE_Responses RadioRadioGetRSSI (RIE_S8 *pRSSIdBm)
1682  @brief Return a Received Signal Strength Indicator value
1683  @param pRSSIdBm :{} detected RSSI in dBm.
1684  @pre RadioInit() must be called before this function is called.
1685  @code
1686  RIE_S8 RSSIdBm;
1687  if (RIE_Response == RIE_Success)
1688  RIE_Response = RadioRadioGetRSSI(&RSSIdBm);
1689  @endcode
1690  @return RIE_Responses Error code
1691 **/
1693 {
1694  RIE_Responses Response = RIE_Success;
1695 
1696  if(Response == RIE_Success)
1697  Response = RadioCommitRadioConfig();
1698  if (Response == RIE_Success)
1699  Response = RadioToOnMode();
1700  if (Response == RIE_Success)
1701  Response = RadioSendCommandWait(CMD_GET_RSSI);
1702  if (Response == RIE_Success)
1703  Response = RadioSyncComms(); //
1704  if (pRSSIdBm)
1705  {
1706  if (Response == RIE_Success)
1707  Response = RadioMMapRead(MCR_rssi_readback_Adr,0x1, (RIE_U8 *)pRSSIdBm);
1708  *pRSSIdBm -= 107; // Convert to dBm
1709  }
1710  return Response;
1711 }
1712 
1713 /**
1714  @fn RIE_Responses RadioTxSetPower(RIE_PAPowerLevel Power)
1715  @brief Set the Transmit Power Level for Radio Transmission.
1716  @param Power :{PowerLevel0 ,PowerLevel1 ,PowerLevel2 ,PowerLevel3,
1717  PowerLevel4 ,PowerLevel5 ,PowerLevel6 ,PowerLevel7,
1718  PowerLevel8 ,PowerLevel9 ,PowerLevel10,PowerLevel11,
1719  PowerLevel12,PowerLevel13,PowerLevel14,PowerLevel15}
1720  @pre RadioInit() must be called before this function is called.
1721  @code
1722  Response = RadioTxSetPower(PowerLevel8);
1723  @endcode
1724  @note Max TX Power is used by default.
1725  @return RIE_Responses Error code
1726 */
1727 RIE_Responses RadioTxSetPower (RIE_PAPowerLevel Power)
1728 {
1729  RIE_Responses Response = RIE_Success;
1730  RIE_U8 ucNewRegVal = RadioConfiguration.radio_cfg_8_r;
1731  unsigned long pa_level_mcr,pa_ramp, codes_per_bit,min_codes_per_bit;
1732 
1733  if (RadioConfiguration.radio_cfg_8_r & radio_cfg_8_pa_single_diff_sel_differential)
1734  ucNewRegVal = radio_cfg_8_pa_single_diff_sel_differential;
1735  else
1736  ucNewRegVal = radio_cfg_8_pa_single_diff_sel_single_ended;
1737 
1738  if(Response == RIE_Success)
1739  {
1740  switch (Power)
1741  {
1742  case PowerLevel0 :
1743  case PowerLevel1 :
1744  case PowerLevel2 :
1745  case PowerLevel3 :
1746  case PowerLevel4 :
1747  case PowerLevel5 :
1748  case PowerLevel6 :
1749  case PowerLevel7 :
1750  case PowerLevel8 :
1751  case PowerLevel9 :
1752  case PowerLevel10:
1753  case PowerLevel11:
1754  case PowerLevel12:
1755  case PowerLevel13:
1756  case PowerLevel14:
1757  case PowerLevel15:
1758  ucNewRegVal |= ((RIE_U8)Power << radio_cfg_8_pa_power_offset);
1759  // Calculate the minimum allowable codes per bit
1760  pa_level_mcr = (((RIE_U8)Power)* 4) + 0x3;
1761  min_codes_per_bit = (pa_level_mcr * 2500)/(DataRate/100);
1762  pa_ramp = 0x1;
1763  codes_per_bit = 256;
1764  while (codes_per_bit > min_codes_per_bit)
1765  {
1766  pa_ramp++;
1767  codes_per_bit = 512 >> pa_ramp;
1768  if (pa_ramp >= 7)
1769  break; // This is the maximum
1770  }
1771  ucNewRegVal |= ((RIE_U8)pa_ramp << radio_cfg_8_pa_ramp_offset);
1772  break;
1773  default:
1774  Response = RIE_UnsupportedRadioConfig;
1775  break;
1776  }
1777  }
1778 
1779  if(Response == RIE_Success)
1780  {
1781  if (ucNewRegVal != RadioConfiguration.radio_cfg_8_r )
1782  {
1783  // Write directly to the MCR in this case and avoid a reconfigure
1784  if (Response == RIE_Success)
1785  Response = RadioMMapWrite(MCR_pa_level_mcr_Adr, 0x1, (RIE_U8 *)&ucNewRegVal);
1786  RadioConfiguration.radio_cfg_8_r = ucNewRegVal;
1787  }
1788  }
1789  return Response;
1790 }
1791 
RIE_Responses RadioTxCarrier(void)
Transmit a carrier tone using the current radio configuration.
Definition: radioeng.c:959
RIE_BOOL
Definition: radioeng.h:110
RIE_BOOL RadioTxPacketComplete(void)
Checks if a packet has finished transmitting.
Definition: radioeng.c:858
__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
Enable External Interrupt.
Definition: core_cm0.h:535
RIE_Responses RadioTerminateRadioOp(void)
Terminate a currently running radio RX or TX operation.
Definition: radioeng.c:551
RIE_Responses RadioRxBERTestMode(void)
Enter receiver Bit Error Rate (BER) test mode where the clock and data appear on GPIO pins...
Definition: radioeng.c:1185
RIE_Responses RadioTxPreamble(void)
Transmit a pre-amble (alternating ones and zeros) using the current radio configuration.
Definition: radioeng.c:987
__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
Clear Pending Interrupt.
Definition: core_cm0.h:587
RIE_Responses RadioDeInit(void)
Deinitialise the Radio, and power it down.
Definition: radioeng.c:472
__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
Disable External Interrupt.
Definition: core_cm0.h:547
#define NULL
The null pointer.
RIE_Responses RadioRxPacketRead(RIE_U8 BufferLen, RIE_U8 *pPktLen, RIE_U8 *pData, RIE_S8 *pRSSIdBm)
Read the packet that was received by the radio.
Definition: radioeng.c:1125
void aducrf101_rx_packet_hook(void)
Trigger function called by ADI radio engine upon packet RX.
Definition: radio.c:405
RIE_BOOL RadioRxPacketAvailable(void)
Checks if a packet has been received.
Definition: radioeng.c:1092
RIE_Responses RadioSetModulationType(RIE_ModulationTypes ModulationType)
Set the Radio Transmitter Modulation Type.
Definition: radioeng.c:612
RIE_Responses
Definition: radioeng.h:131
RIE_Responses RadioPowerOff(void)
Shutdown the radio and place it in its lowest power sleep mode.
Definition: radioeng.c:521
RIE_Responses RadioRadioGetRSSI(RIE_S8 *pRSSIdBm)
Return a Received Signal Strength Indicator value.
Definition: radioeng.c:1692
RIE_Responses RadioSwitchConfig(RIE_BaseConfigs BaseConfig)
Change the Radio to using specified configuration.
Definition: radioeng.c:369
RIE_Responses RadioPayldManchesterEncode(RIE_BOOL bEnable)
Enable or Disable Manchester Encoding of payload data.
Definition: radioeng.c:670
RIE_Responses RadioSetFrequency(RIE_U32 Frequency)
Set frequency for radio communications.
Definition: radioeng.c:574
RIE_Responses RadioTxSetPower(RIE_PAPowerLevel Power)
Set the Transmit Power Level for Radio Transmission.
Definition: radioeng.c:1727
RIE_Responses RadioRxPacketFixedLen(RIE_U8 Len)
Enter receive mode and wait for a packet to be received.
Definition: radioeng.c:1017
RIE_Responses RadioGetAPIVersion(RIE_U32 *pVersion)
Return the Radio Interface Engine API Version.
Definition: radioeng.c:347
__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
Set Interrupt Priority.
Definition: core_cm0.h:602
RIE_PATypes
Definition: radioeng.h:90
RIE_Responses RadioRxPacketVariableLen(void)
Enter receive mode and wait for a packet to be received.
Definition: radioeng.c:1050
RIE_Responses RadioTxSetPA(RIE_PATypes PAType, RIE_PAPowerLevel Power)
Set PA Type and the Transmit Power Level for Radio Transmission.
Definition: radioeng.c:879
RIE_ModulationTypes
Definition: radioeng.h:79
RIE_Responses RadioTxPacketVariableLen(RIE_U8 Len, RIE_U8 *pData)
Transmit a Variable length packet.
Definition: radioeng.c:813
RIE_Responses RadioInit(RIE_BaseConfigs BaseConfig)
Initialise the Radio, using specified configuration.
Definition: radioeng.c:396
RIE_Responses RadioPayldDataWhitening(RIE_BOOL bEnable)
Enable or Disable Data Whitening of payload data.
Definition: radioeng.c:729
RIE_Responses RadioTxPacketFixedLen(RIE_U8 Len, RIE_U8 *pData)
Transmit a fixed length packet.
Definition: radioeng.c:772
RIE_BaseConfigs
Definition: radioeng.h:62