ADF7030-1 Device Drivers API Reference Manual  Alpha 0.0.1
Device Drivers for ADF7030-1 Transceiver
adf7030-1__patch.c
1 /*********************************************************************************
2 
3 Copyright(c) 2016 Analog Devices, Inc. All Rights Reserved.
4 
5 This software is proprietary and confidential. By using this software you agree
6 to the terms of the associated Analog Devices License Agreement.
7 
8 *********************************************************************************/
28 #ifndef _ADF7030_1__PATCH_C_
29 
30 #define _ADF7030_1__PATCH_C_
31 
32 #include <stddef.h>
33 #include <string.h>
34 #include <assert.h>
35 #include "system.h"
36 #include "common.h"
37 
38 #include <drivers/spi/adi_spi.h>
39 //#include <devices/rf/adf703x/adi_adf7030-1.h>
40 //#include <devices/rf/adf703x/adi_adf7030-1_reg.h>
41 #include <devices/rf/adf703x/adf7030-1__spi.h>
42 #include <devices/rf/adf703x/adf7030-1__mem.h>
43 #include <devices/rf/adf703x/adf7030-1__patch.h>
44 
45 
46 #ifdef __ICCARM__
47 /*
48 * IAR MISRA C 2004 error suppressions.
49 *
50 * Pm140 (rule 11.3): a cast should not be performed between a pointer type and an integral type
51 * The rule makes an exception for memory-mapped register accesses.
52 *
53 * Pm073 (rule 14.7): a function should have a single point of exit.
54 * Pm143 (rule 14.7): a function should have a single point of exit at the end of the function.
55 * Multiple returns are used for error handling.
56 */
57 #pragma diag_suppress=Pm073,Pm143
58 #endif /* __ICCARM__ */
59 
82  ADI_SPI_HANDLE hSPIDevice,
83  PATCH_DESCRIPTOR_Type * pPATCH
84 )
85 {
86  return(adf7030_1__XferPatch( hSPIDevice, pPATCH, PHY_MEM_WRITE, false));
87 }
88 
105 /* Read patch data from Radio PHY */
107  ADI_SPI_HANDLE hSPIDevice,
108  PATCH_DESCRIPTOR_Type * pPATCH
109 )
110 {
111  return(adf7030_1__XferPatch( hSPIDevice, pPATCH, PHY_MEM_READ, false));
112 }
113 
114 /*PATCH_DESCRIPTOR_Type PATCH_READBACK;
115 
116 memcpy(&PATCH_READBACK, &PATCH_LCPSM, sizeof(PATCH_DESCRIPTOR_Type));
117 
118 char buff[PATCH_READBACK.Size];
119 char *pOffset = buff;
120 
121 PATCH_READBACK.BLOCKS[0].pData = buff;
122 
123 for(uint32_t i = 1; i < PATCH_READBACK.nbBlock; i++){
124  pOffset += PATCH_READBACK.BLOCKS[i-1].Size;
125  PATCH_READBACK.BLOCKS[i].pData = pOffset;
126 }
127 
128 adf7030_1__ReadPatch(hSPIDevice, &PATCH_READBACK);
129 */
130 
131 
151  ADI_SPI_HANDLE hSPIDevice,
152  PATCH_DESCRIPTOR_Type * pPATCH
153 )
154 {
155  /* Write Inject sequence to radio PHY */
156  uint32_t InjectSeq = 0x20000000 + pPATCH->InjectSeq;
157 
158  if(adf7030_1__SPI_wr_word_b_a(hSPIDevice, 0x20000130, 1, &InjectSeq ) != SUCCESS)
159  {
160  return FAILURE;
161  }
162 
163  return SUCCESS;
164 }
165 
184  ADI_SPI_HANDLE hSPIDevice,
185  PATCH_DESCRIPTOR_Type * pPATCH
186 )
187 {
188  /* Write Eject sequence to radio PHY */
189  uint32_t EjectSeq = 0x20000000 + pPATCH->EjectSeq;
190 
191  if(adf7030_1__SPI_wr_word_b_a(hSPIDevice, 0x20000130, 1, &EjectSeq ) != SUCCESS)
192  {
193  return FAILURE;
194  }
195 
196  return SUCCESS;
197 }
198 
218  ADI_SPI_HANDLE hSPIDevice,
219  PATCH_DESCRIPTOR_Type * pPATCH
220 )
221 {
222  return(adf7030_1__XferPatch( hSPIDevice, pPATCH, PHY_MEM_READ, true));
223 }
224 
225 
245  ADI_SPI_HANDLE hSPIDevice,
246  version_info_t * pPathInfo,
247  uint32_t PhyAddr
248 )
249 {
251  int32_t PNTR_offset;
252 
253  /* Get good PNTRid from ADF7030_1_SPI_PNTR[] */
254  adf7030_1__SPI_FindMMapPointer( hSPIDevice, PhyAddr, &PNTR_id, &PNTR_offset);
255 
256  /* No valid PHY SPI pointer available, use 8bits access with no offset */
257  if(PNTR_id == 0)
258  {
259  /* Change the SPI custom pointer 0 */
260  if(adf7030_1__SPI_SetMMapCustomPntr0( hSPIDevice, PhyAddr ) != SUCCESS)
261  {
262  return FAILURE;
263  }
264 
265  /* Read from radio PHY */
266  if(adf7030_1__SPI_wr_byte_p_a( hSPIDevice, PNTR_CUSTOM0_ADDR, sizeof(version_info_t), (uint8_t *)pPathInfo) != SUCCESS)
267  {
268  return FAILURE;
269  }
270  }
271  /* Valid PHY SPI pointer available, use 8bits access with pointer offset */
272  else
273  {
274  /* Read from radio PHY */
275  if(adf7030_1__SPI_wr_byte_b_a( hSPIDevice, PNTR_id, PNTR_offset, sizeof(version_info_t), (uint8_t *)pPathInfo) != SUCCESS)
276  {
277  return FAILURE;
278  }
279  }
280 
281  return SUCCESS;
282 }
283 
284 
304  ADI_SPI_HANDLE hSPIDevice,
305  version_info_t * pPathInfo,
306  uint32_t PhyAddr
307 )
308 {
310  int32_t PNTR_offset;
311 
312  /* Get good PNTRid from ADF7030_1_SPI_PNTR[] */
313  adf7030_1__SPI_FindMMapPointer( hSPIDevice, PhyAddr, &PNTR_id, &PNTR_offset);
314 
315  /* No valid PHY SPI pointer available, use 8bits access with no offset */
316  if(PNTR_id == 0)
317  {
318  /* Change the SPI custom pointer 0 */
319  if(adf7030_1__SPI_SetMMapCustomPntr0( hSPIDevice, PhyAddr ) != SUCCESS)
320  {
321  return FAILURE;
322  }
323 
324  /* Read from radio PHY */
325  if(adf7030_1__SPI_rd_byte_p_a( hSPIDevice, PNTR_CUSTOM0_ADDR, sizeof(version_info_t), (uint8_t *)pPathInfo) != SUCCESS)
326  {
327  return FAILURE;
328  }
329  }
330  /* Valid PHY SPI pointer available, use 8bits access with pointer offset */
331  else
332  {
333  /* Read from radio PHY */
334  if(adf7030_1__SPI_rd_byte_b_a( hSPIDevice, PNTR_id, PNTR_offset, sizeof(version_info_t), (uint8_t *)pPathInfo) != SUCCESS)
335  {
336  return FAILURE;
337  }
338  }
339 
340  return SUCCESS;
341 }
342 
365  ADI_SPI_HANDLE hSPIDevice,
366  PATCH_DESCRIPTOR_Type * pPATCH,
367  bool READ_nWRITE,
368  bool CHECK_ONLY
369 )
370 {
371  for(uint32_t i = 0; i < pPATCH->nbBlock; i++)
372  {
373  /* Block Transfers Mode */
374 
375  uint32_t PHYAddr = pPATCH->BLOCKS[i].Addr;
376 
377  /* Crude check to skip transfert of Patch Informations */
378  if(PHYAddr == pPATCH->InfoAddr)
379  {
380  break;
381  }
382 
384  int32_t PNTR_offset;
385 
386  /* Get good PNTRid from ADF7030_1_SPI_PNTR[] */
387  adf7030_1__SPI_FindMMapPointer( hSPIDevice, PHYAddr, &PNTR_id, &PNTR_offset);
388 
389  /* Lets just use 8bits Mode SPI transfers for patch*/
390  {
391  /* Setup pointer to Host start of data */
392  uint8_t * pHostMem;
393  pHostMem = (uint8_t *)pPATCH->BLOCKS[i].pData;
394 
395  uint32_t size = pPATCH->BLOCKS[i].Size;
396 
397  /* No valid PHY SPI pointer available, use 8bits access with no offset */
398  if(PNTR_id == 0)
399  {
400  /* Change the SPI custom pointer 0 */
401  if(adf7030_1__SPI_SetMMapCustomPntr0( hSPIDevice, PHYAddr ) != SUCCESS)
402  {
403  return FAILURE;
404  }
405 
406  if(CHECK_ONLY)
407  {
408  /* Read from radio PHY */
409  if(adf7030_1__SPI_rd_cmp_byte_p_a( hSPIDevice, PNTR_CUSTOM0_ADDR, size, NULL, pHostMem) != SUCCESS)
410  {
411  return FAILURE;
412  }
413  }
414  else
415  {
416  /* Copy Host MEM memory block to PHY memory block via the SPI */
417  if(READ_nWRITE == true)
418  {
419  /* Read from radio PHY */
420  if(adf7030_1__SPI_rd_byte_p_a( hSPIDevice, PNTR_CUSTOM0_ADDR, size, pHostMem) != SUCCESS)
421  {
422  return FAILURE;
423  }
424  }else{
425  /* Write to radio PHY */
426  if(adf7030_1__SPI_wr_byte_p_a( hSPIDevice, PNTR_CUSTOM0_ADDR, size, pHostMem) != SUCCESS)
427  {
428  return FAILURE;
429  }
430  }
431  }
432  }
433  /* Valid PHY SPI pointer available, use 8bits access with pointer offset */
434  else
435  {
436  if(CHECK_ONLY)
437  {
438  /* Read from radio PHY */
439  if(adf7030_1__SPI_rd_cmp_byte_b_a( hSPIDevice, PNTR_id, PNTR_offset, size, NULL, pHostMem) != SUCCESS)
440  {
441  return FAILURE;
442  }
443  }
444  else
445  {
446  /* Copy Host MEM memory block to PHY memory block via the SPI */
447  if(READ_nWRITE == true)
448  {
449  /* Read from radio PHY */
450  if(adf7030_1__SPI_rd_byte_b_a( hSPIDevice, PNTR_id, PNTR_offset, size, pHostMem) != SUCCESS)
451  {
452  return FAILURE;
453  }
454  }else{
455  /* Write to radio PHY */
456  if(adf7030_1__SPI_wr_byte_b_a( hSPIDevice, PNTR_id, PNTR_offset, size, pHostMem) != SUCCESS)
457  {
458  return FAILURE;
459  }
460  }
461  }
462  }
463  }
464  }
465 
466  return SUCCESS;
467 }
468 
469 
470 #endif /* _ADF7030_1__PATCH_C_ */
471  /* End of group adf7030-1__patch PHY Patch Interface */ /* End of group adf7030-1 adf7030-1 Driver */
uint32_t adf7030_1__SPI_wr_byte_p_a(ADI_SPI_HANDLE hSPIDevice, ADI_ADF7030_1_RADIO_SPI_PNTR_TYPE pntrID, uint32_t num_xfrs, uint8_t *pDataIn)
Write a number of byte(s) from Host to memory of the adf7030-1 starting at location pointed by "pntr"...
uint32_t adf7030_1__XferPatch(ADI_SPI_HANDLE hSPIDevice, PATCH_DESCRIPTOR_Type *pPATCH, bool READ_nWRITE, bool CHECK_ONLY)
Generic Patch transfers function between Host and the Radio PHY.
uint32_t adf7030_1_ReadPatchInfo(ADI_SPI_HANDLE hSPIDevice, version_info_t *pPathInfo, uint32_t PhyAddr)
Function to read Patch Information from the PHY Radio.
uint32_t adf7030_1__VerifyPatch(ADI_SPI_HANDLE hSPIDevice, PATCH_DESCRIPTOR_Type *pPATCH)
Function call to verify the integrity of the patch.
uint16_t nbBlock
Total size of the Patch.
uint32_t adf7030_1__SPI_SetMMapCustomPntr0(ADI_SPI_HANDLE hSPIDevice, uint32_t Addr)
Change the SPI Radio mmap custom pointers 0 location.
uint32_t adf7030_1__SPI_rd_byte_p_a(ADI_SPI_HANDLE hSPIDevice, ADI_ADF7030_1_RADIO_SPI_PNTR_TYPE pntrID, uint32_t num_xfrs, uint8_t *pDataOut)
Read a number of bytes(s) from memory of the adf7030-1 to Host starting at location pointed by "pntr"...
uint32_t InfoAddr
Pointer to the Patch info structure in the host memory.
uint32_t adf7030_1__InjectPatch(ADI_SPI_HANDLE hSPIDevice, PATCH_DESCRIPTOR_Type *pPATCH)
Function call to re-enable the patch if needed.
uint32_t adf7030_1_WritePatchInfo(ADI_SPI_HANDLE hSPIDevice, version_info_t *pPathInfo, uint32_t PhyAddr)
Function to write Patch Information to the PHY Radio.
uint32_t adf7030_1__SPI_rd_cmp_byte_b_a(ADI_SPI_HANDLE hSPIDevice, ADI_ADF7030_1_RADIO_SPI_PNTR_TYPE pntrID, uint32_t AddrIn, uint32_t num_xfrs, uint8_t *pDataOut, uint8_t *pDataRef)
Read & Compare a number of bytes(s) from memory of the adf7030-1 to Host starting at location pointed...
const uint8_t * pData
Address of the memory bloc in the PHY memory space.
void adf7030_1__SPI_FindMMapPointer(ADI_SPI_HANDLE hSPIDevice, uint32_t Addr, ADI_ADF7030_1_RADIO_SPI_PNTR_TYPE *pPNTR_ID, int32_t *ByteOffset)
This function return the best Pointer id + offset for subsequent SPI transfert to the PHY "Addr" prov...
uint32_t adf7030_1__ReadPatch(ADI_SPI_HANDLE hSPIDevice, PATCH_DESCRIPTOR_Type *pPATCH)
Function call to readback the patch from Radio PHY.
const uint32_t Addr
If !NULL, force 32bits SPI transfer.
DATA_BLOCK_DESCRIPTOR_Type BLOCKS[]
Disable patch sequence.
ADI_ADF7030_1_RADIO_SPI_PNTR_TYPE
uint32_t adf7030_1__SPI_rd_byte_b_a(ADI_SPI_HANDLE hSPIDevice, ADI_ADF7030_1_RADIO_SPI_PNTR_TYPE pntrID, uint32_t AddrIn, uint32_t num_xfrs, uint8_t *pDataOut)
Read a number of bytes(s) from memory of the adf7030-1 to Host starting at location pointed by "pntr"...
uint32_t adf7030_1__SPI_wr_word_b_a(ADI_SPI_HANDLE hSPIDevice, uint32_t AddrIn, uint32_t num_xfrs, uint32_t *pDataIn)
Write a number of word(s) from Host to memory of the adf7030-1 Generic 32bits bloc address write to m...
uint32_t adf7030_1__WritePatch(ADI_SPI_HANDLE hSPIDevice, PATCH_DESCRIPTOR_Type *pPATCH)
Function call to write patch to Radio PHY.
uint32_t adf7030_1__SPI_wr_byte_b_a(ADI_SPI_HANDLE hSPIDevice, ADI_ADF7030_1_RADIO_SPI_PNTR_TYPE pntrID, uint32_t AddrIn, uint32_t num_xfrs, uint8_t *pDataIn)
Write a number of byte(s) from Host to memory of the adf7030-1 starting at location pointed by "pntr"...
uint32_t adf7030_1__SPI_rd_cmp_byte_p_a(ADI_SPI_HANDLE hSPIDevice, ADI_ADF7030_1_RADIO_SPI_PNTR_TYPE pntrID, uint32_t num_xfrs, uint8_t *pDataOut, uint8_t *pDataRef)
Read & Compare a number of bytes(s) from memory of the adf7030-1 to Host starting at location pointed...
uint16_t InjectSeq
Start location of the Patch info structure in the PHY.
uint32_t adf7030_1__EjectPatch(ADI_SPI_HANDLE hSPIDevice, PATCH_DESCRIPTOR_Type *pPATCH)
Function call to disnable the patch if needed.
uint16_t EjectSeq
Enable patch sequence.