rf_phy_driver.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. extern volatile uint8_t g_dtmManualConfig;
  63. /*******************************************************************************
  64. * MACRO
  65. */
  66. #define PHY_REG_RD(x) *(volatile uint32_t *)(x)
  67. #define PHY_REG_WT(x,y) *(volatile uint32_t *)(x) = (y)
  68. #define RF_CHN_TO_FREQ(x)
  69. #define DCDC_CONFIG_SETTING(x) subWriteReg(0x4000f014,18,15, x)
  70. #define GET_UART_WIDX *(volatile uint32_t *)(0x1fff1064)
  71. #define CLR_UART_WIDX *(volatile uint32_t *)(0x1fff1064)=0
  72. #define RF_PHY_TPCAL_CALC(tp0,tp1,chn) ((tp0)>(tp1) ?(((tp0<<5)-(tp0-tp1)*(chn)+16)>>5) : tp0 )
  73. //DTM STATE
  74. #define RF_PHY_DTM_IDL 0
  75. #define RF_PHY_DTM_CMD 1
  76. #define RF_PHY_DTM_EVT 2
  77. #define RF_PHY_DTM_TEST 3
  78. #define RF_PHY_DTM_SYNC_WORD 0x71764129
  79. #define RF_PHY_DTM_PRBS9_SEED 0xffffffff
  80. #define RF_PHY_DTM_CRC_WT 0x00555555
  81. //DTM MODE TYPE
  82. #define RF_PHY_DTM_MODE_RESET 0
  83. #define RF_PHY_DTM_MODE_TX_BURST 2
  84. #define RF_PHY_DTM_MODE_TX_CTMOD 4
  85. #define RF_PHY_DTM_MODE_TX_SINGLE 6
  86. #define RF_PHY_DTM_MODE_RX_PER 8
  87. #define RF_PHY_DTM_MODE_TEST_END 10
  88. #define RF_PHY_DTM_MODE_SET_LENGTH_UP2BIT 12
  89. #define RF_PHY_DTM_MODE_SET_PHY_1M 16
  90. #define RF_PHY_DTM_MODE_SET_PHY_2M 18
  91. #define RF_PHY_DTM_MODE_SET_PHY_500K 20
  92. #define RF_PHY_DTM_MODE_SET_PHY_125K 22
  93. #define RF_PHY_DTM_MODE_SET_PHY_ZB 24
  94. #define RF_PHY_DTM_MODE_ASSUME_TX_MOD_INDX_STANDARD 32
  95. #define RF_PHY_DTM_MODE_ASSUME_TX_MOD_INDX_STABLE 34
  96. #define RF_PHY_DTM_MODE_READ_SUPPORTED_TEST_CASE 36
  97. #define RF_PHY_DTM_MODE_READ_MAX_TX_OCTETS 38
  98. #define RF_PHY_DTM_MODE_READ_MAX_TX_TIME 40
  99. #define RF_PHY_DTM_MODE_READ_MAX_RX_OCTETS 42
  100. #define RF_PHY_DTM_MODE_READ_MAX_RX_TIME 44
  101. #define RF_PHY_DTM_MODE_SET_RXXTAL_TAB 108
  102. #define RF_PHY_DTM_MODE_LOAD_RXXTAL 110
  103. #define RF_PHY_DTM_MODE_SET_RXXTAL_CAL 112
  104. #define RF_PHY_DTM_MODE_SET_ACCCODE_0 114
  105. #define RF_PHY_DTM_MODE_SET_ACCCODE_1 116
  106. #define RF_PHY_DTM_MODE_SET_ACCCODE_2 118
  107. #define RF_PHY_DTM_MODE_SET_ACCCODE_3 120
  108. #define RF_PHY_DTM_MODE_SET_FREQ_FOFF 122
  109. #define RF_PHY_DTM_MODE_SET_TPCAL_MANUAL 124
  110. #define RF_PHY_DTM_MODE_SET_XTAL_CAP 126
  111. #define RF_PHY_DTM_MODE_SET_TX_POWER 128
  112. #define RF_PHY_DTM_MODE_GET_FOFF 130
  113. #define RF_PHY_DTM_MODE_GET_TPCAL 132
  114. #define RF_PHY_DTM_MODE_GET_RSSI 134
  115. #define RF_PHY_DTM_MODE_GET_CARR_SENS 136
  116. #define RF_PHY_DTM_MODE_GET_PER_AUTO 138
  117. #define RF_PHY_DTM_MODE_ATE_SET_PKTFMT 0xd0 //208
  118. #define RF_PHY_DTM_MODE_ATE_SET_TXPOWER 0xd1
  119. #define RF_PHY_DTM_MODE_ATE_TX_BURST 0xe0 //224
  120. #define RF_PHY_DTM_MODE_ATE_TX_MOD 0xe1
  121. #define RF_PHY_DTM_MODE_ATE_TX_CARR 0xe2
  122. #define RF_PHY_DTM_MODE_ATE_RX_AUTOGAIN 0xe3
  123. #define RF_PHY_DTM_MODE_ATE_RX_FIXGAIN 0xe4
  124. #define RF_PHY_DTM_MODE_ATE_RX_DEMOD 0xe5
  125. #define RF_PHY_DTM_MODE_ATE_RX2TX 0xe6
  126. #define RF_PHY_DTM_MODE_ATE_TX2RX 0xe7
  127. #define RF_PHY_DTM_MODE_ATE_RESET 0xef
  128. #define RF_PHY_DTM_MODE_ERROR 254
  129. /*******************************************************************************
  130. * CONSTANTS
  131. */
  132. #define PKT_FMT_ZIGBEE 0
  133. #define PKT_FMT_BLE1M 1
  134. #define PKT_FMT_BLE2M 2
  135. #define PKT_FMT_BLR500K 3
  136. #define PKT_FMT_BLR125K 4
  137. #define RF_PHY_TX_POWER_EXTRA_MAX 0x3f
  138. #define RF_PHY_TX_POWER_MAX 0x1f
  139. #define RF_PHY_TX_POWER_MIN 0x00
  140. #define RF_PHY_TX_POWER_5DBM 0x17
  141. #define RF_PHY_TX_POWER_4DBM 0x12
  142. #define RF_PHY_TX_POWER_3DBM 0x0f
  143. #define RF_PHY_TX_POWER_0DBM 0x0a
  144. #define RF_PHY_TX_POWER_N3DBM 0x06
  145. #define RF_PHY_TX_POWER_N5DBM 0x05
  146. #define RF_PHY_TX_POWER_N6DBM 0x04
  147. #define RF_PHY_TX_POWER_N10DBM 0x03
  148. #define RF_PHY_TX_POWER_N15DBM 0x02
  149. #define RF_PHY_TX_POWER_N20DBM 0x01
  150. #define RF_PHY_FREQ_FOFF_00KHZ 0
  151. #define RF_PHY_FREQ_FOFF_20KHZ 5
  152. #define RF_PHY_FREQ_FOFF_40KHZ 10
  153. #define RF_PHY_FREQ_FOFF_60KHZ 15
  154. #define RF_PHY_FREQ_FOFF_80KHZ 20
  155. #define RF_PHY_FREQ_FOFF_100KHZ 25
  156. #define RF_PHY_FREQ_FOFF_120KHZ 30
  157. #define RF_PHY_FREQ_FOFF_140KHZ 35
  158. #define RF_PHY_FREQ_FOFF_160KHZ 40
  159. #define RF_PHY_FREQ_FOFF_180KHZ 45
  160. #define RF_PHY_FREQ_FOFF_200KHZ 50
  161. #define RF_PHY_FREQ_FOFF_N20KHZ -5
  162. #define RF_PHY_FREQ_FOFF_N40KHZ -10
  163. #define RF_PHY_FREQ_FOFF_N60KHZ -15
  164. #define RF_PHY_FREQ_FOFF_N80KHZ -20
  165. #define RF_PHY_FREQ_FOFF_N100KHZ -25
  166. #define RF_PHY_FREQ_FOFF_N120KHZ -30
  167. #define RF_PHY_FREQ_FOFF_N140KHZ -35
  168. #define RF_PHY_FREQ_FOFF_N160KHZ -40
  169. #define RF_PHY_FREQ_FOFF_N180KHZ -45
  170. #define RF_PHY_FREQ_FOFF_N200KHZ -50
  171. #define RF_PHY_CLK_SEL_32M_DLL 0x00
  172. #define RF_PHY_CLK_SEL_16M_XTAL 0x01
  173. #define RF_PHY_CLK_SEL_32M_DBL 0x02
  174. #define RF_PHY_DTM_MANUL_NULL 0x00
  175. #define RF_PHY_DTM_MANUL_FOFF 0x01
  176. #define RF_PHY_DTM_MANUL_TXPOWER 0x02
  177. #define RF_PHY_DTM_MANUL_XTAL_CAP 0x04
  178. #define RF_PHY_DTM_MANUL_MAX_GAIN 0x08
  179. #define RF_PHY_DTM_MANUL_ALL 0xFF
  180. /*******************************************************************************
  181. * FUNCION DEFINE
  182. */
  183. void rf_phy_ini (void);
  184. void rf_phy_ana_cfg (void);
  185. void rf_phy_bb_cfg (uint8_t pktFmt);
  186. void rf_phy_change_cfg(uint8_t pktFmt);
  187. void rf_phy_clk_cfg(uint8_t rfPhyClk);
  188. void rf_tpCal_cfg (uint8_t rfChn);
  189. uint8_t rf_tp_cal (uint8_t rfChn ,uint8_t fDev);
  190. void rf_rxDcoc_cfg (uint8_t rfChn ,uint8_t bwSet,volatile uint32* dcCal);
  191. void rf_tpCal_gen_cap_arrary(void);
  192. void rf_phy_direct_test (void);
  193. void rf_phy_dtm_cmd_parse(void);
  194. void rf_phy_dtm_evt_send (uint8_t dtmType);
  195. void rf_phy_dtm_trigged (void);
  196. void rf_phy_get_pktFoot (uint8* rssi, uint16* foff,uint8* carrSens);
  197. void rf_phy_set_txPower (uint8 txPower);
  198. void rf_phy_dtm_zigbee_pkt_gen(void);
  199. /**************************************************************************************
  200. * @fn rf_phy_dtm_ext_tx_singleTone
  201. *
  202. * @brief This function process for rf phy direct test, test mode interup
  203. *
  204. * input parameters
  205. *
  206. * @param txPower : rf tx power
  207. * rfChnIdx : rf channel = 2402+(rfChnIdx<<1)
  208. * rfFoff : rf freq offset = rfFoff*4KHz
  209. * testTimeUs : test loop active time(ms)
  210. *
  211. * output parameters
  212. *
  213. * @param none
  214. *
  215. * @return none
  216. */
  217. void rf_phy_dtm_ext_tx_singleTone(uint8_t txPower, uint8_t rfChnIdx,int8_t rfFoff ,uint32 testTimeUs);
  218. /**************************************************************************************
  219. * @fn rf_phy_dtm_ext_tx_modulation
  220. *
  221. * @brief This function process for rf phy direct test, test mode interup
  222. *
  223. * input parameters
  224. *
  225. * @param txPower : rf tx power
  226. * rfChnIdx : rf channel = 2402+(rfChnIdx<<1)
  227. * rfFoff : rf freq offset = rfFoff*4KHz
  228. * pktType : modulaiton data type, 0: prbs9, 1: 1111000: 2 10101010
  229. * testTimeUs : test loop active time(ms)
  230. *
  231. * output parameters
  232. *
  233. * @param none
  234. *
  235. * @return none
  236. */
  237. void rf_phy_dtm_ext_tx_modulation(uint8_t txPower, uint8_t rfChnIdx,int8_t rfFoff ,uint8_t pktType,uint32 testTimeUs);
  238. /**************************************************************************************
  239. * @fn rf_phy_dtm_ext_tx_mt_burst
  240. *
  241. * @brief This function process for rf phy direct test, test mode interup
  242. *
  243. * input parameters
  244. *
  245. * @param txPower : rf tx power
  246. * rfChnIdx : rf channel = 2402+(rfChnIdx<<1)
  247. * rfFoff : rf freq offset = rfFoff*4KHz
  248. * pktType : modulaiton data type, 0: prbs9, 1: 1111000: 2 10101010
  249. * pktLength : pkt length(Byte)
  250. * pkt interval = ceil((L+249)/625) * 625
  251. * txPktNum : burst pkt tx number
  252. *
  253. * output parameters
  254. *
  255. * @param none
  256. *
  257. * @return none
  258. */
  259. void rf_phy_dtm_ext_tx_mod_burst(uint8_t txPower, uint8_t rfChnIdx,int8_t rfFoff ,
  260. uint8_t pktType, uint8_t pktLength,uint32 txPktNum,uint32 txPktIntv);
  261. /**************************************************************************************
  262. * @fn rf_phy_dtm_ext_rx_demod_burst
  263. *
  264. * @brief This function process for rf phy direct test, test mode interup
  265. *
  266. * input parameters
  267. *
  268. * @param rfChnIdx : rf channel = 2402+(rfChnIdx<<1)
  269. * rfFoff : rf freq offset = rfFoff*4KHz
  270. * pktLength : pkt length(Byte)
  271. * rxWindow : rx demod window length(us)
  272. * rxTimeOut : rx on time (ms)
  273. *
  274. * output parameters
  275. *
  276. * @param rxEstFoff : rx demod estimated frequency offset
  277. * rxEstRssi : rx demod estimated rssi
  278. * rxEstCarrSens : rx demod estimated carrier sense
  279. * rxPktNum : rx demod received pkt number
  280. *
  281. * @return none
  282. */
  283. void rf_phy_dtm_ext_rx_demod_burst(uint8_t rfChnIdx,int8_t rfFoff,uint8_t pktLength,uint32 rxTimeOut,uint32 rxWindow,
  284. uint16_t* rxEstFoff,uint8_t* rxEstRssi,uint8_t* rxEstCarrSens,uint16_t* rxPktNum);
  285. /**************************************************************************************
  286. * @fn rf_phy_dtm_ext_acc_code_set
  287. *
  288. * @brief config the acc_code in rf phy dtm
  289. *
  290. * input parameters
  291. *
  292. * @param acc_code : sync word
  293. *
  294. * output parameters
  295. * @return none
  296. */
  297. void rf_phy_dtm_ext_acc_code_set(uint32 accCode);
  298. #endif