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