rf_phy_driver.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /**************************************************************************************************
  2. Phyplus Microelectronics Limited confidential and proprietary.
  3. All rights reserved.
  4. IMPORTANT: All rights of this software belong to Phyplus Microelectronics
  5. Limited ("Phyplus"). Your use of this Software is limited to those
  6. specific rights granted under the terms of the business contract, the
  7. confidential agreement, the non-disclosure agreement and any other forms
  8. of agreements as a customer or a partner of Phyplus. You may not use this
  9. Software unless you agree to abide by the terms of these agreements.
  10. You acknowledge that the Software may not be modified, copied,
  11. distributed or disclosed unless embedded on a Phyplus Bluetooth Low Energy
  12. (BLE) integrated circuit, either as a product or is integrated into your
  13. products. Other than for the aforementioned purposes, you may not use,
  14. reproduce, copy, prepare derivative works of, modify, distribute, perform,
  15. display or sell this Software and/or its documentation for any purposes.
  16. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  17. PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  18. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  19. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  20. PHYPLUS OR ITS SUBSIDIARIES BE LIABLE OR OBLIGATED UNDER CONTRACT,
  21. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  22. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  23. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  24. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  25. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  26. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  27. **************************************************************************************************/
  28. /*******************************************************************************
  29. * @file rf_phy_driver.h
  30. * @brief Contains all functions support for PHYPLUS RF_PHY_DRIVER
  31. * @version 1.0
  32. * @date 24. Aug. 2017
  33. * @author Zhongqi Yang
  34. *
  35. * Copyright(C) 2016, PhyPlus Semiconductor
  36. * All rights reserved.
  37. *
  38. *******************************************************************************/
  39. #ifndef __RF_PHY_DRIVER_H_
  40. #define __RF_PHY_DRIVER_H_
  41. /*******************************************************************************
  42. * INCLUDES
  43. */
  44. #include "ll_hw_drv.h"
  45. #include "common.h"
  46. #include "jump_function.h"
  47. extern void LOG_PATCH_DATA_TIME(void); // check lib version
  48. /*******************************************************************************
  49. * Global Var
  50. */
  51. extern volatile uint8_t g_rfPhyTpCal0; //** two point calibraion result0 **//
  52. extern volatile uint8_t g_rfPhyTpCal1; //** two point calibraion result1 **//
  53. extern volatile uint8_t g_rfPhyTpCal0_2Mbps; //** two point calibraion result0 **//
  54. extern volatile uint8_t g_rfPhyTpCal1_2Mbps; //** two point calibraion result1 **//
  55. extern volatile uint8_t g_rfPhyTxPower; //** rf pa output power setting [0x00 0x1f] **//
  56. extern volatile uint8_t g_rfPhyPktFmt; //** rf_phy pkt format config **//
  57. extern volatile uint32 g_rfPhyRxDcIQ; //** rx dc offset cal result **//
  58. extern volatile uint8_t g_rfPhyXtalCap; //** 16M Xtal trim cap for RF FreqOffset **//
  59. extern volatile int8_t g_rfPhyFreqOffSet;
  60. extern volatile uint8_t g_system_clk;
  61. extern volatile uint8_t g_rfPhyClkSel;
  62. /*******************************************************************************
  63. * MACRO
  64. */
  65. #define PHY_REG_RD(x) *(volatile uint32_t *)(x)
  66. #define PHY_REG_WT(x,y) *(volatile uint32_t *)(x) = (y)
  67. #define RF_CHN_TO_FREQ(x)
  68. #define DCDC_CONFIG_SETTING(x) subWriteReg(0x4000f014,18,15, x)
  69. #define GET_UART_WIDX *(volatile uint32_t *)(0x1fff1064)
  70. #define CLR_UART_WIDX *(volatile uint32_t *)(0x1fff1064)=0
  71. #define RF_PHY_TPCAL_CALC(tp0,tp1,chn) ((tp0)>(tp1) ?(((tp0<<5)-(tp0-tp1)*(chn)+16)>>5) : tp0 )
  72. //DTM STATE
  73. #define RF_PHY_DTM_IDL 0
  74. #define RF_PHY_DTM_CMD 1
  75. #define RF_PHY_DTM_EVT 2
  76. #define RF_PHY_DTM_TEST 3
  77. #define RF_PHY_DTM_SYNC_WORD 0x71764129
  78. #define RF_PHY_DTM_PRBS9_SEED 0xffffffff
  79. #define RF_PHY_DTM_CRC_WT 0x00555555
  80. //DTM MODE TYPE
  81. #define RF_PHY_DTM_MODE_RESET 0
  82. #define RF_PHY_DTM_MODE_TX_BURST 2
  83. #define RF_PHY_DTM_MODE_TX_CTMOD 4
  84. #define RF_PHY_DTM_MODE_TX_SINGLE 6
  85. #define RF_PHY_DTM_MODE_RX_PER 8
  86. #define RF_PHY_DTM_MODE_TEST_END 10
  87. #define RF_PHY_DTM_MODE_SET_LENGTH_UP2BIT 12
  88. #define RF_PHY_DTM_MODE_SET_PHY_1M 16
  89. #define RF_PHY_DTM_MODE_SET_PHY_2M 18
  90. #define RF_PHY_DTM_MODE_SET_PHY_500K 20
  91. #define RF_PHY_DTM_MODE_SET_PHY_125K 22
  92. #define RF_PHY_DTM_MODE_SET_PHY_ZB 24
  93. #define RF_PHY_DTM_MODE_ASSUME_TX_MOD_INDX_STANDARD 32
  94. #define RF_PHY_DTM_MODE_ASSUME_TX_MOD_INDX_STABLE 34
  95. #define RF_PHY_DTM_MODE_READ_SUPPORTED_TEST_CASE 36
  96. #define RF_PHY_DTM_MODE_READ_MAX_TX_OCTETS 38
  97. #define RF_PHY_DTM_MODE_READ_MAX_TX_TIME 40
  98. #define RF_PHY_DTM_MODE_READ_MAX_RX_OCTETS 42
  99. #define RF_PHY_DTM_MODE_READ_MAX_RX_TIME 44
  100. #define RF_PHY_DTM_MODE_SET_ACCCODE_0 114
  101. #define RF_PHY_DTM_MODE_SET_ACCCODE_1 116
  102. #define RF_PHY_DTM_MODE_SET_ACCCODE_2 118
  103. #define RF_PHY_DTM_MODE_SET_ACCCODE_3 120
  104. #define RF_PHY_DTM_MODE_SET_FREQ_FOFF 122
  105. #define RF_PHY_DTM_MODE_SET_TPCAL_MANUAL 124
  106. #define RF_PHY_DTM_MODE_SET_XTAL_CAP 126
  107. #define RF_PHY_DTM_MODE_SET_TX_POWER 128
  108. #define RF_PHY_DTM_MODE_GET_FOFF 130
  109. #define RF_PHY_DTM_MODE_GET_TPCAL 132
  110. #define RF_PHY_DTM_MODE_GET_RSSI 134
  111. #define RF_PHY_DTM_MODE_GET_CARR_SENS 136
  112. #define RF_PHY_DTM_MODE_GET_PER_AUTO 138
  113. #define RF_PHY_DTM_MODE_ATE_SET_PKTFMT 0xd0 //208
  114. #define RF_PHY_DTM_MODE_ATE_SET_TXPOWER 0xd1
  115. #define RF_PHY_DTM_MODE_ATE_TX_BURST 0xe0 //224
  116. #define RF_PHY_DTM_MODE_ATE_TX_MOD 0xe1
  117. #define RF_PHY_DTM_MODE_ATE_TX_CARR 0xe2
  118. #define RF_PHY_DTM_MODE_ATE_RX_AUTOGAIN 0xe3
  119. #define RF_PHY_DTM_MODE_ATE_RX_FIXGAIN 0xe4
  120. #define RF_PHY_DTM_MODE_ATE_RX_DEMOD 0xe5
  121. #define RF_PHY_DTM_MODE_ATE_RX2TX 0xe6
  122. #define RF_PHY_DTM_MODE_ATE_TX2RX 0xe7
  123. #define RF_PHY_DTM_MODE_ATE_RESET 0xef
  124. #define RF_PHY_DTM_MODE_ERROR 254
  125. /*******************************************************************************
  126. * CONSTANTS
  127. */
  128. #define PKT_FMT_ZIGBEE 0
  129. #define PKT_FMT_BLE1M 1
  130. #define PKT_FMT_BLE2M 2
  131. #define PKT_FMT_BLR500K 3
  132. #define PKT_FMT_BLR125K 4
  133. #define RF_PHY_TX_POWER_EXTRA_MAX 0x3f
  134. #define RF_PHY_TX_POWER_MAX 0x1f
  135. #define RF_PHY_TX_POWER_MIN 0x00
  136. #define RF_PHY_TX_POWER_5DBM 0x17
  137. #define RF_PHY_TX_POWER_4DBM 0x12
  138. #define RF_PHY_TX_POWER_3DBM 0x0f
  139. #define RF_PHY_TX_POWER_0DBM 0x0a
  140. #define RF_PHY_TX_POWER_N3DBM 0x06
  141. #define RF_PHY_TX_POWER_N5DBM 0x05
  142. #define RF_PHY_TX_POWER_N6DBM 0x04
  143. #define RF_PHY_TX_POWER_N10DBM 0x03
  144. #define RF_PHY_TX_POWER_N15DBM 0x02
  145. #define RF_PHY_TX_POWER_N20DBM 0x01
  146. #define RF_PHY_FREQ_FOFF_00KHZ 0
  147. #define RF_PHY_FREQ_FOFF_20KHZ 5
  148. #define RF_PHY_FREQ_FOFF_40KHZ 10
  149. #define RF_PHY_FREQ_FOFF_60KHZ 15
  150. #define RF_PHY_FREQ_FOFF_80KHZ 20
  151. #define RF_PHY_FREQ_FOFF_100KHZ 25
  152. #define RF_PHY_FREQ_FOFF_120KHZ 30
  153. #define RF_PHY_FREQ_FOFF_140KHZ 35
  154. #define RF_PHY_FREQ_FOFF_160KHZ 40
  155. #define RF_PHY_FREQ_FOFF_180KHZ 45
  156. #define RF_PHY_FREQ_FOFF_200KHZ 50
  157. #define RF_PHY_FREQ_FOFF_N20KHZ -5
  158. #define RF_PHY_FREQ_FOFF_N40KHZ -10
  159. #define RF_PHY_FREQ_FOFF_N60KHZ -15
  160. #define RF_PHY_FREQ_FOFF_N80KHZ -20
  161. #define RF_PHY_FREQ_FOFF_N100KHZ -25
  162. #define RF_PHY_FREQ_FOFF_N120KHZ -30
  163. #define RF_PHY_FREQ_FOFF_N140KHZ -35
  164. #define RF_PHY_FREQ_FOFF_N160KHZ -40
  165. #define RF_PHY_FREQ_FOFF_N180KHZ -45
  166. #define RF_PHY_FREQ_FOFF_N200KHZ -50
  167. #define RF_PHY_CLK_SEL_32M_DLL 0x00
  168. #define RF_PHY_CLK_SEL_16M_XTAL 0x01
  169. #define RF_PHY_CLK_SEL_32M_DBL 0x02
  170. /*******************************************************************************
  171. * FUNCION DEFINE
  172. */
  173. void rf_phy_ini (void);
  174. void rf_phy_ana_cfg (void);
  175. void rf_phy_bb_cfg (uint8_t pktFmt);
  176. void rf_phy_change_cfg(uint8_t pktFmt);
  177. void rf_phy_clk_cfg(uint8_t rfPhyClk);
  178. void rf_tpCal_cfg (uint8_t rfChn);
  179. uint8_t rf_tp_cal (uint8_t rfChn ,uint8_t fDev);
  180. void rf_rxDcoc_cfg (uint8_t rfChn ,uint8_t bwSet,volatile uint32* dcCal);
  181. void rf_tpCal_gen_cap_arrary(void);
  182. void rf_phy_direct_test (void);
  183. void rf_phy_dtm_cmd_parse(void);
  184. void rf_phy_dtm_evt_send (uint8_t dtmType);
  185. void rf_phy_dtm_trigged (void);
  186. void rf_phy_get_pktFoot (uint8* rssi, uint16* foff,uint8* carrSens);
  187. void rf_phy_set_txPower (uint8 txPower);
  188. void rf_phy_dtm_zigbee_pkt_gen(void);
  189. /**************************************************************************************
  190. * @fn rf_phy_dtm_ext_tx_singleTone
  191. *
  192. * @brief This function process for rf phy direct test, test mode interup
  193. *
  194. * input parameters
  195. *
  196. * @param txPower : rf tx power
  197. * rfChnIdx : rf channel = 2402+(rfChnIdx<<1)
  198. * rfFoff : rf freq offset = rfFoff*4KHz
  199. * testTimeUs : test loop active time(ms)
  200. *
  201. * output parameters
  202. *
  203. * @param none
  204. *
  205. * @return none
  206. */
  207. void rf_phy_dtm_ext_tx_singleTone(uint8_t txPower, uint8_t rfChnIdx,int8_t rfFoff ,uint32 testTimeUs);
  208. /**************************************************************************************
  209. * @fn rf_phy_dtm_ext_tx_modulation
  210. *
  211. * @brief This function process for rf phy direct test, test mode interup
  212. *
  213. * input parameters
  214. *
  215. * @param txPower : rf tx power
  216. * rfChnIdx : rf channel = 2402+(rfChnIdx<<1)
  217. * rfFoff : rf freq offset = rfFoff*4KHz
  218. * pktType : modulaiton data type, 0: prbs9, 1: 1111000: 2 10101010
  219. * testTimeUs : test loop active time(ms)
  220. *
  221. * output parameters
  222. *
  223. * @param none
  224. *
  225. * @return none
  226. */
  227. void rf_phy_dtm_ext_tx_modulation(uint8_t txPower, uint8_t rfChnIdx,int8_t rfFoff ,uint8_t pktType,uint32 testTimeUs);
  228. /**************************************************************************************
  229. * @fn rf_phy_dtm_ext_tx_mt_burst
  230. *
  231. * @brief This function process for rf phy direct test, test mode interup
  232. *
  233. * input parameters
  234. *
  235. * @param txPower : rf tx power
  236. * rfChnIdx : rf channel = 2402+(rfChnIdx<<1)
  237. * rfFoff : rf freq offset = rfFoff*4KHz
  238. * pktType : modulaiton data type, 0: prbs9, 1: 1111000: 2 10101010
  239. * pktLength : pkt length(Byte)
  240. * pkt interval = ceil((L+249)/625) * 625
  241. * txPktNum : burst pkt tx number
  242. *
  243. * output parameters
  244. *
  245. * @param none
  246. *
  247. * @return none
  248. */
  249. void rf_phy_dtm_ext_tx_mod_burst(uint8_t txPower, uint8_t rfChnIdx,int8_t rfFoff ,
  250. uint8_t pktType, uint8_t pktLength,uint32 txPktNum,uint32 txPktIntv);
  251. /**************************************************************************************
  252. * @fn rf_phy_dtm_ext_rx_demod_burst
  253. *
  254. * @brief This function process for rf phy direct test, test mode interup
  255. *
  256. * input parameters
  257. *
  258. * @param rfChnIdx : rf channel = 2402+(rfChnIdx<<1)
  259. * rfFoff : rf freq offset = rfFoff*4KHz
  260. * pktLength : pkt length(Byte)
  261. * rxWindow : rx demod window length(us)
  262. * rxTimeOut : rx on time (ms)
  263. *
  264. * output parameters
  265. *
  266. * @param rxEstFoff : rx demod estimated frequency offset
  267. * rxEstRssi : rx demod estimated rssi
  268. * rxEstCarrSens : rx demod estimated carrier sense
  269. * rxPktNum : rx demod received pkt number
  270. *
  271. * @return none
  272. */
  273. void rf_phy_dtm_ext_rx_demod_burst(uint8_t rfChnIdx,int8_t rfFoff,uint8_t pktLength,uint32 rxTimeOut,uint32 rxWindow,
  274. uint16_t* rxEstFoff,uint8_t* rxEstRssi,uint8_t* rxEstCarrSens,uint16_t* rxPktNum);
  275. /**************************************************************************************
  276. * @fn rf_phy_dtm_ext_acc_code_set
  277. *
  278. * @brief config the acc_code in rf phy dtm
  279. *
  280. * input parameters
  281. *
  282. * @param acc_code : sync word
  283. *
  284. * output parameters
  285. * @return none
  286. */
  287. void rf_phy_dtm_ext_acc_code_set(uint32 accCode);
  288. #endif