Contiki 3.x
ADF7023.c
1 /*
2  * Copyright (c) 2014, Analog Devices, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29  * OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 /**
32  * \author Dragos Bogdan <Dragos.Bogdan@Analog.com>, Ian Martin <martini@redwirellc.com>
33  */
34 
35 #include <stdio.h>
36 #include <assert.h>
37 #include <string.h> /* for memcmp(). */
38 #include <stdbool.h>
39 
40 #include "ADF7023.h"
41 #include "ADF7023_Config.h"
42 #include "Communication.h"
43 
44 #include "sfrs.h"
45 #include "sfrs-ext.h"
46 
47 #include "contiki.h" /* for clock_wait() and CLOCK_SECOND. */
48 
49 /******************************************************************************/
50 /*************************** Macros Definitions *******************************/
51 /******************************************************************************/
52 /*
53  #define ADF7023_CS_ASSERT CS_PIN_LOW
54  #define ADF7023_CS_DEASSERT CS_PIN_HIGH
55  #define ADF7023_MISO MISO_PIN
56  */
57 
58 #ifndef ARRAY_SIZE
59 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
60 #endif
61 
62 #undef BIT
63 #define BIT(n) (1 << (n))
64 
65 #define ADF7023_CS_ASSERT (P2 &= ~BIT(2))
66 #define ADF7023_CS_DEASSERT (P2 |= BIT(2))
67 #define ADF7023_MISO (P0 & BIT(3))
68 
69 #define ADF7023_SPI_BUS (CSI10)
70 
71 #define LOOP_LIMIT 100
72 
73 #ifndef ADF7023_VERBOSE
74 /* ADF7023_VERBOSE Values: */
75 /* 2 = Inidicate when breaking stuck while loops. */
76 /* 5 = Dump all received and transmitted packets. */
77 /* 7 = Dump the ADF7023 commands, interrupt and status words. */
78 /* 10 = Dump all SPI transactions. */
79 
80 #define ADF7023_VERBOSE 0
81 #endif
82 
83 #if (ADF7023_VERBOSE >= 2)
84 #define break_loop() if(++counter >= LOOP_LIMIT) { printf("Breaking stuck while loop at %s line %u." NEWLINE, __FILE__, __LINE__); break; }
85 #else
86 #define break_loop() if(++counter >= LOOP_LIMIT) break
87 #endif
88 
89 #define ADF7023_While(condition, body) do { \
90  int counter = 0; \
91  while(condition) { body; break_loop(); } \
92 } while(0)
93 
94 #undef MIN
95 #define MIN(x, y) (((x) < (y)) ? (x) : (y))
96 
97 /******************************************************************************/
98 /************************ Variables Definitions *******************************/
99 /******************************************************************************/
100 struct ADF7023_BBRAM ADF7023_BBRAMCurrent;
101 
102 #if (ADF7023_VERBOSE >= 7)
103 static unsigned char status_old = 0xff;
104 static unsigned char int0_old = 0xff;
105 #endif
106 
107 const char *ADF7023_state_lookup[] = {
108  /* 0x00 */ "Busy, performing a state transition",
109  /* 0x01 */ "(unknown)",
110  /* 0x02 */ "(unknown)",
111  /* 0x03 */ "(unknown)",
112  /* 0x04 */ "(unknown)",
113  /* 0x05 */ "Performing CMD_GET_RSSI",
114  /* 0x06 */ "PHY_SLEEP",
115  /* 0x07 */ "Performing CMD_IR_CAL",
116  /* 0x08 */ "Performing CMD_AES_DECRYPT_INIT",
117  /* 0x09 */ "Performing CMD_AES_DECRYPT",
118  /* 0x0A */ "Performing CMD_AES_ENCRYPT",
119  /* 0x0B */ "(unknown)",
120  /* 0x0C */ "(unknown)",
121  /* 0x0D */ "(unknown)",
122  /* 0x0E */ "(unknown)",
123  /* 0x0F */ "Initializing",
124  /* 0x10 */ "(unknown)",
125  /* 0x11 */ "PHY_OFF",
126  /* 0x12 */ "PHY_ON",
127  /* 0x13 */ "PHY_RX",
128  /* 0x14 */ "PHY_TX",
129 };
130 
131 const char *ADF7023_cmd_lookup[] = {
132  [CMD_SYNC] = "CMD_SYNC",
133  [CMD_PHY_OFF] = "CMD_PHY_OFF",
134  [CMD_PHY_ON] = "CMD_PHY_ON",
135  [CMD_PHY_RX] = "CMD_PHY_RX",
136  [CMD_PHY_TX] = "CMD_PHY_TX",
137  [CMD_PHY_SLEEP] = "CMD_PHY_SLEEP",
138  [CMD_CONFIG_DEV] = "CMD_CONFIG_DEV",
139  [CMD_GET_RSSI] = "CMD_GET_RSSI",
140  [CMD_BB_CAL] = "CMD_BB_CAL",
141  [CMD_HW_RESET] = "CMD_HW_RESET",
142  [CMD_RAM_LOAD_INIT] = "CMD_RAM_LOAD_INIT",
143  [CMD_RAM_LOAD_DONE] = "CMD_RAM_LOAD_DONE",
144  [CMD_IR_CAL] = "CMD_IR_CAL",
145  [CMD_AES_ENCRYPT] = "CMD_AES_ENCRYPT",
146  [CMD_AES_DECRYPT] = "CMD_AES_DECRYPT",
147  [CMD_AES_DECRYPT_INIT] = "CMD_AES_DECRYPT_INIT",
148  [CMD_RS_ENCODE_INIT] = "CMD_RS_ENCODE_INIT",
149  [CMD_RS_ENCODE] = "CMD_RS_ENCODE",
150  [CMD_RS_DECODE] = "CMD_RS_DECODE",
151 };
152 
153 static int spi_busy = 0;
154 static uint8_t tx_rec[255];
155 static uint8_t rx_rec[255];
156 static uint8_t tx_pos;
157 static uint8_t rx_pos;
158 
159 static void ADF7023_SetCommand_Assume_CMD_READY(unsigned char command);
160 
161 void
162 hexdump(const void *data, size_t len)
163 {
164  size_t n;
165  if(len <= 0) {
166  return;
167  }
168  printf("%02x", ((const unsigned char *)data)[0]);
169  for(n = 1; n < len; n++) {
170  printf(" %02x", ((const unsigned char *)data)[n]);
171  }
172 }
173 void
174 ADF7023_SPI_Begin(void)
175 {
176  assert(spi_busy == 0);
177  spi_busy++;
178 
179  tx_pos = 0;
180  rx_pos = 0;
181 
182  ADF7023_CS_ASSERT;
183 }
184 void
185 ADF7023_SPI_End(void)
186 {
187  assert(spi_busy > 0);
188  spi_busy--;
189  ADF7023_CS_DEASSERT;
190 
191 #if (ADF7023_VERBOSE >= 10)
192  printf("ADF7023_SPI_End(): wrote \"");
193  hexdump(tx_rec, tx_pos);
194  printf("\", read \"");
195  hexdump(rx_rec, rx_pos);
196  printf("\"." NEWLINE);
197 #endif
198 }
199 /***************************************************************************//**
200  * @brief Transfers one byte of data.
201  *
202  * @param writeByte - Write data.
203  * @param readByte - Read data.
204  *
205  * @return None.
206  *******************************************************************************/
207 void
208 ADF7023_WriteReadByte(unsigned char writeByte,
209  unsigned char *readByte)
210 {
211  unsigned char data = 0;
212 
213  data = writeByte;
214  SPI_Read(ADF7023_SPI_BUS, 0, &data, 1);
215  if(readByte) {
216  *readByte = data;
217  }
218 
219  assert(tx_pos < ARRAY_SIZE(tx_rec));
220  tx_rec[tx_pos] = writeByte;
221  tx_pos++;
222 
223  assert(rx_pos < ARRAY_SIZE(rx_rec));
224  rx_rec[rx_pos] = data;
225  rx_pos++;
226 }
227 void
228 ADF7023_Wait_for_CMD_READY(void)
229 {
230  unsigned char status;
231  int counter = 0;
232 
233  for(;;) {
234  break_loop();
235 
236  ADF7023_GetStatus(&status);
237 
238  if((status & STATUS_SPI_READY) == 0) {
239  /* The SPI bus is not ready. Continue polling the status word. */
240  continue;
241  }
242 
243  if(status & STATUS_CMD_READY) {
244  /* The SPI bus is ready and CMD_READY == 1. This is the state we want. */
245  break;
246  }
247 
248  if((status & STATUS_FW_STATE) == FW_STATE_PHY_OFF) {
249  /* SPI is ready, but CMD_READY == 0 and the radio is in state PHY_OFF. */
250  /* It seems that the ADF7023 gets stuck in this state sometimes (errata?), so transition to PHY_ON: */
251  ADF7023_SetCommand_Assume_CMD_READY(CMD_PHY_ON);
252  }
253  }
254 }
255 static void
256 ADF7023_Init_Procedure(void)
257 {
258  ADF7023_SPI_Begin();
259  ADF7023_While(!ADF7023_MISO, (void)0);
260  ADF7023_SPI_End();
261  ADF7023_Wait_for_CMD_READY();
262 }
263 /***************************************************************************//**
264  * @brief Initializes the ADF7023.
265  *
266  * @return retVal - Result of the initialization procedure.
267  * Example: 0 - if initialization was successful;
268  * -1 - if initialization was unsuccessful.
269  *******************************************************************************/
270 char
271 ADF7023_Init(void)
272 {
273  char retVal = 0;
274 
275  ADF7023_CS_DEASSERT;
276  PM2 &= ~BIT(2); /* Configure ADF7023_CS as an output. */
277 
278  ADF7023_BBRAMCurrent = ADF7023_BBRAMDefault;
279  SPI_Init(ADF7023_SPI_BUS,
280  0, /* MSB first. */
281  1000000, /* Clock frequency. */
282  0, /* Idle state for clock is a high level; active state is a low level. */
283  1); /* Serial output data changes on transition from idle clock state to active clock state. */
284 
285  ADF7023_Init_Procedure();
286 
287  ADF7023_SetCommand(CMD_HW_RESET);
288  clock_wait(MIN(CLOCK_SECOND / 1000, 1));
289  ADF7023_Init_Procedure();
290 
291  ADF7023_SetRAM_And_Verify(0x100, 64, (unsigned char *)&ADF7023_BBRAMCurrent);
292  ADF7023_SetCommand(CMD_CONFIG_DEV);
293 
294  return retVal;
295 }
296 /***************************************************************************//**
297  * @brief Reads the status word of the ADF7023.
298  *
299  * @param status - Status word.
300  *
301  * @return None.
302  *******************************************************************************/
303 void
304 ADF7023_GetStatus(unsigned char *status)
305 {
306  ADF7023_SPI_Begin();
307  ADF7023_WriteReadByte(SPI_NOP, 0);
308  ADF7023_WriteReadByte(SPI_NOP, status);
309  ADF7023_SPI_End();
310 
311 #if (ADF7023_VERBOSE >= 7)
312  if(*status != status_old) {
313  printf("ADF7023_GetStatus: SPI_READY=%u, IRQ_STATUS=%u, CMD_READY=%u, FW_STATE=0x%02x",
314  (*status >> 7) & 1,
315  (*status >> 6) & 1,
316  (*status >> 5) & 1,
317  *status & STATUS_FW_STATE
318  );
319  if((*status & STATUS_FW_STATE) < ARRAY_SIZE(ADF7023_state_lookup)) {
320  printf("=\"%s\"", ADF7023_state_lookup[*status & STATUS_FW_STATE]);
321  }
322  printf("." NEWLINE);
323  status_old = *status;
324  }
325 #endif
326 }
327 static void
328 ADF7023_SetCommand_Assume_CMD_READY(unsigned char command)
329 {
330 #if (ADF7023_VERBOSE >= 7)
331  assert(ADF7023_cmd_lookup[command] != NULL);
332  printf("Sending command 0x%02x = \"%s\"." NEWLINE, command, ADF7023_cmd_lookup[command]);
333 #endif
334  ADF7023_SPI_Begin();
335  ADF7023_WriteReadByte(command, 0);
336  ADF7023_SPI_End();
337 }
338 /***************************************************************************//**
339  * @brief Initiates a command.
340  *
341  * @param command - Command.
342  *
343  * @return None.
344  *******************************************************************************/
345 void
346 ADF7023_SetCommand(unsigned char command)
347 {
348  ADF7023_Wait_for_CMD_READY();
349  ADF7023_SetCommand_Assume_CMD_READY(command);
350 }
351 void
352 ADF7023_SetFwState_NoWait(unsigned char fwState)
353 {
354  switch(fwState) {
355  case FW_STATE_PHY_OFF:
356  ADF7023_SetCommand(CMD_PHY_OFF);
357  break;
358  case FW_STATE_PHY_ON:
359  ADF7023_SetCommand(CMD_PHY_ON);
360  break;
361  case FW_STATE_PHY_RX:
362  ADF7023_SetCommand(CMD_PHY_RX);
363  break;
364  case FW_STATE_PHY_TX:
365  ADF7023_SetCommand(CMD_PHY_TX);
366  break;
367  default:
368  ADF7023_SetCommand(CMD_PHY_SLEEP);
369  }
370 }
371 /***************************************************************************//**
372  * @brief Sets a FW state and waits until the device enters in that state.
373  *
374  * @param fwState - FW state.
375  *
376  * @return None.
377  *******************************************************************************/
378 void
379 ADF7023_SetFwState(unsigned char fwState)
380 {
381  unsigned char status = 0;
382  ADF7023_SetFwState_NoWait(fwState);
383  ADF7023_While((status & STATUS_FW_STATE) != fwState, ADF7023_GetStatus(&status));
384 }
385 /***************************************************************************//**
386  * @brief Reads data from the RAM.
387  *
388  * @param address - Start address.
389  * @param length - Number of bytes to write.
390  * @param data - Read buffer.
391  *
392  * @return None.
393  *******************************************************************************/
394 void
395 ADF7023_GetRAM(unsigned long address,
396  unsigned long length,
397  unsigned char *data)
398 {
399  ADF7023_SPI_Begin();
400  ADF7023_WriteReadByte(SPI_MEM_RD | ((address & 0x700) >> 8), 0);
401  ADF7023_WriteReadByte(address & 0xFF, 0);
402  ADF7023_WriteReadByte(SPI_NOP, 0);
403  while(length--) {
404  ADF7023_WriteReadByte(SPI_NOP, data++);
405  }
406  ADF7023_SPI_End();
407 }
408 /***************************************************************************//**
409  * @brief Writes data to RAM.
410  *
411  * @param address - Start address.
412  * @param length - Number of bytes to write.
413  * @param data - Write buffer.
414  *
415  * @return None.
416  *******************************************************************************/
417 void
418 ADF7023_SetRAM(unsigned long address,
419  unsigned long length,
420  unsigned char *data)
421 {
422  ADF7023_Wait_for_CMD_READY();
423 
424  ADF7023_SPI_Begin();
425  ADF7023_WriteReadByte(SPI_MEM_WR | ((address & 0x700) >> 8), 0);
426  ADF7023_WriteReadByte(address & 0xFF, 0);
427  while(length--) {
428  ADF7023_WriteReadByte(*(data++), 0);
429  }
430  ADF7023_SPI_End();
431 }
432 void
433 ADF7023_SetRAM_And_Verify(unsigned long address, unsigned long length, unsigned char *data)
434 {
435  unsigned char readback[256];
436 
437  ADF7023_SetRAM(address, length, data);
438 
439  assert(length <= sizeof(readback));
440  if(length > sizeof(readback)) {
441  return;
442  }
443  ADF7023_GetRAM(address, length, readback);
444 
445  if(memcmp(data, readback, length)) {
446  printf("ADF7023_SetRAM_And_Verify failed. Wrote:" NEWLINE);
447  hexdump(data, length);
448  printf(NEWLINE "Read:" NEWLINE);
449  hexdump(readback, length);
450  printf(NEWLINE);
451  }
452 }
453 unsigned char
454 ADF7023_Wait_for_SPI_READY(void)
455 {
456  unsigned char status = 0;
457  ADF7023_While((status & STATUS_SPI_READY) == 0, ADF7023_GetStatus(&status));
458  return status; /* Return the status -- why not? */
459 }
460 void
461 ADF7023_PHY_ON(void)
462 {
463  unsigned char status;
464  unsigned int counter = 0;
465 
466  for(;;) {
467  status = ADF7023_Wait_for_SPI_READY();
468 
469  switch(status & STATUS_FW_STATE) {
470  default:
471  ADF7023_SetCommand(CMD_PHY_ON);
472  break;
473 
474  case FW_STATE_BUSY:
475  /* Wait! */
476  break;
477 
478  case FW_STATE_PHY_ON:
479  /* This is the desired state. */
480  return;
481  }
482 
483  break_loop();
484  }
485 }
486 void
487 ADF7023_PHY_RX(void)
488 {
489  unsigned char status;
490  unsigned int counter = 0;
491 
492  for(;;) {
493  status = ADF7023_Wait_for_SPI_READY();
494 
495  switch(status & STATUS_FW_STATE) {
496  default:
497  /* Need to turn the PHY_ON. */
498  ADF7023_PHY_ON();
499  break;
500 
501  case FW_STATE_BUSY:
502  /* Wait! */
503  break;
504 
505  case FW_STATE_PHY_ON:
506  case FW_STATE_PHY_TX:
507  ADF7023_While((status & STATUS_CMD_READY) == 0, ADF7023_GetStatus(&status));
508  ADF7023_SetCommand(CMD_PHY_RX);
509  return;
510 
511  case FW_STATE_PHY_RX:
512  /* This is the desired state. */
513  return;
514  }
515 
516  break_loop();
517  }
518 }
519 void
520 ADF7023_PHY_TX(void)
521 {
522  unsigned char status;
523  unsigned int counter = 0;
524 
525  for(;;) {
526  status = ADF7023_Wait_for_SPI_READY();
527 
528  switch(status & STATUS_FW_STATE) {
529  default:
530  /* Need to turn the PHY_ON. */
531  ADF7023_PHY_ON();
532  break;
533 
534  case FW_STATE_BUSY:
535  /* Wait! */
536  break;
537 
538  case FW_STATE_PHY_ON:
539  case FW_STATE_PHY_RX:
540  ADF7023_While((status & STATUS_CMD_READY) == 0, ADF7023_GetStatus(&status));
541  ADF7023_SetCommand(CMD_PHY_TX);
542  return;
543  }
544 
545  break_loop();
546  }
547 }
548 static unsigned char
549 ADF7023_ReadInterruptSource(void)
550 {
551  unsigned char interruptReg;
552 
553  ADF7023_GetRAM(MCR_REG_INTERRUPT_SOURCE_0, 0x1, &interruptReg);
554 
555 #if (ADF7023_VERBOSE >= 7)
556  if(interruptReg != int0_old) {
557  printf("ADF7023_ReadInterruptSource: %u%u%u%u%u%u%u%u." NEWLINE,
558  (interruptReg >> 7) & 1,
559  (interruptReg >> 6) & 1,
560  (interruptReg >> 5) & 1,
561  (interruptReg >> 4) & 1,
562  (interruptReg >> 3) & 1,
563  (interruptReg >> 2) & 1,
564  (interruptReg >> 1) & 1,
565  (interruptReg >> 0) & 1
566  );
567  int0_old = interruptReg;
568  }
569 #endif
570  return interruptReg;
571 }
572 unsigned char
573 ADF7023_ReceivePacketAvailable(void)
574 {
575  unsigned char status;
576 
577  ADF7023_GetStatus(&status);
578  if((status & STATUS_SPI_READY) == 0) {
579  return false;
580  }
581 
582  if((status & STATUS_FW_STATE) != FW_STATE_PHY_RX) {
583  ADF7023_PHY_RX();
584  return false;
585  }
586 
587  if((status & STATUS_IRQ_STATUS) == 0) {
588  return false;
589  }
590 
591  return ADF7023_ReadInterruptSource() & BBRAM_INTERRUPT_MASK_0_INTERRUPT_CRC_CORRECT;
592 }
593 /***************************************************************************//**
594  * @brief Receives one packet.
595  *
596  * @param packet - Data buffer.
597  * @param length - Number of received bytes.
598  *
599  * @return None.
600  *******************************************************************************/
601 void
602 ADF7023_ReceivePacket(unsigned char *packet, unsigned char *payload_length)
603 {
604  unsigned char length;
605  unsigned char interruptReg = 0;
606 
607  ADF7023_While(!(interruptReg & BBRAM_INTERRUPT_MASK_0_INTERRUPT_CRC_CORRECT),
608  interruptReg = ADF7023_ReadInterruptSource());
609 
610  interruptReg = BBRAM_INTERRUPT_MASK_0_INTERRUPT_CRC_CORRECT;
611 
612  ADF7023_SetRAM(MCR_REG_INTERRUPT_SOURCE_0,
613  0x1,
614  &interruptReg);
615 
616  ADF7023_GetRAM(ADF7023_RX_BASE_ADR, 1, &length);
617 
618  *payload_length = length - 1 + LENGTH_OFFSET - 4;
619 
620  ADF7023_GetRAM(ADF7023_RX_BASE_ADR + 1, *payload_length, packet);
621 
622 #if (ADF7023_VERBOSE >= 5)
623  do {
624  unsigned char n;
625  printf("ADF7023_ReceivePacket, length=%u: ", *payload_length);
626  hexdump(packet, *payload_length);
627  printf(NEWLINE);
628  } while(false);
629 #endif
630 }
631 /***************************************************************************//**
632  * @brief Transmits one packet.
633  *
634  * @param packet - Data buffer.
635  * @param length - Number of bytes to transmit.
636  *
637  * @return None.
638  *******************************************************************************/
639 void
640 ADF7023_TransmitPacket(unsigned char *packet, unsigned char length)
641 {
642  unsigned char interruptReg = 0;
643  unsigned char status;
644  unsigned char length_plus_one;
645 
646  for(;;) {
647  ADF7023_GetStatus(&status);
648  if((status & STATUS_SPI_READY) == 0) {
649  continue;
650  }
651  if((status & STATUS_CMD_READY) == 0) {
652  continue;
653  }
654  break;
655  }
656 
657  length_plus_one = length + 1;
658  ADF7023_SetRAM_And_Verify(ADF7023_TX_BASE_ADR, 1, &length_plus_one);
659  ADF7023_SetRAM_And_Verify(ADF7023_TX_BASE_ADR + 1, length, packet);
660 
661 #if (ADF7023_VERBOSE >= 5)
662  do {
663  unsigned char n;
664  printf("ADF7023_TransmitPacket, length=%u: ", length);
665  hexdump(packet, length);
666  printf(NEWLINE);
667  } while(false);
668 #endif
669 
670  ADF7023_PHY_TX();
671 
672  ADF7023_While(!(interruptReg & BBRAM_INTERRUPT_MASK_0_INTERRUPT_TX_EOF),
673  ADF7023_GetRAM(MCR_REG_INTERRUPT_SOURCE_0, 0x1, &interruptReg));
674 
675  ADF7023_PHY_RX();
676 }
677 /***************************************************************************//**
678  * @brief Sets the channel frequency.
679  *
680  * @param chFreq - Channel frequency.
681  *
682  * @return None.
683  *******************************************************************************/
684 void
685 ADF7023_SetChannelFrequency(unsigned long chFreq)
686 {
687  chFreq = (unsigned long)(((float)chFreq / 26000000) * 65535);
688  ADF7023_BBRAMCurrent.channelFreq0 = (chFreq & 0x0000FF) >> 0;
689  ADF7023_BBRAMCurrent.channelFreq1 = (chFreq & 0x00FF00) >> 8;
690  ADF7023_BBRAMCurrent.channelFreq2 = (chFreq & 0xFF0000) >> 16;
691  ADF7023_SetRAM_And_Verify(0x100, 64, (unsigned char *)&ADF7023_BBRAMCurrent);
692 }
693 /***************************************************************************//**
694  * @brief Sets the data rate.
695  *
696  * @param dataRate - Data rate.
697  *
698  * @return None.
699  *******************************************************************************/
700 void
701 ADF7023_SetDataRate(unsigned long dataRate)
702 {
703  dataRate = (unsigned long)(dataRate / 100);
704  ADF7023_BBRAMCurrent.radioCfg0 =
705  BBRAM_RADIO_CFG_0_DATA_RATE_7_0((dataRate & 0x00FF) >> 0);
706  ADF7023_BBRAMCurrent.radioCfg1 &= ~BBRAM_RADIO_CFG_1_DATA_RATE_11_8(0xF);
707  ADF7023_BBRAMCurrent.radioCfg1 |=
708  BBRAM_RADIO_CFG_1_DATA_RATE_11_8((dataRate & 0x0F00) >> 8);
709  ADF7023_SetRAM_And_Verify(0x100, 64, (unsigned char *)&ADF7023_BBRAMCurrent);
710  ADF7023_SetFwState(FW_STATE_PHY_OFF);
711  ADF7023_SetCommand(CMD_CONFIG_DEV);
712 }
713 /***************************************************************************//**
714  * @brief Sets the frequency deviation.
715  *
716  * @param freqDev - Frequency deviation.
717  *
718  * @return None.
719  *******************************************************************************/
720 void
721 ADF7023_SetFrequencyDeviation(unsigned long freqDev)
722 {
723  freqDev = (unsigned long)(freqDev / 100);
724  ADF7023_BBRAMCurrent.radioCfg1 &=
725  ~BBRAM_RADIO_CFG_1_FREQ_DEVIATION_11_8(0xF);
726  ADF7023_BBRAMCurrent.radioCfg1 |=
727  BBRAM_RADIO_CFG_1_FREQ_DEVIATION_11_8((freqDev & 0x0F00) >> 8);
728  ADF7023_BBRAMCurrent.radioCfg2 =
729  BBRAM_RADIO_CFG_2_FREQ_DEVIATION_7_0((freqDev & 0x00FF) >> 0);
730  ADF7023_SetRAM_And_Verify(0x100, 64, (unsigned char *)&ADF7023_BBRAMCurrent);
731  ADF7023_SetFwState(FW_STATE_PHY_OFF);
732  ADF7023_SetCommand(CMD_CONFIG_DEV);
733 }
#define NULL
The null pointer.
#define BIT(x)
Useful to reference a single bit of a byte.
void clock_wait(clock_time_t t)
Wait for a given number of ticks.
Definition: clock.c:166
#define CLOCK_SECOND
A second, measured in system clock time.
Definition: clock.h:82