adf4153(4400).c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. /******************************************************************************
  2. * @file ADF4153.c
  3. * @brief Implementation of ADF4153 Driver for Microblaze processor.
  4. * @author Istvan Csomortani (istvan.csomortani@analog.com)
  5. *
  6. *******************************************************************************
  7. * Copyright 2013(c) Analog Devices, Inc.
  8. *
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * - Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. * - Neither the name of Analog Devices, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived
  21. * from this software without specific prior written permission.
  22. * - The use of this software may or may not infringe the patent rights
  23. * of one or more patent holders. This license does not release you
  24. * from the requirement that you obtain separate licenses from these
  25. * patent holders to use this software.
  26. * - Use of the software either in source or binary form, must be run
  27. * on or directly connected to an Analog Devices Inc. component.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED
  30. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY
  31. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  32. * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  33. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34. * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  35. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  36. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  37. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. ******************************************************************************/
  41. /*****************************************************************************/
  42. /****************************** Include Files ********************************/
  43. /*****************************************************************************/
  44. #include "adf4153.h"
  45. #include "zig_operate.h"
  46. #include "main.h"
  47. #include "pll_4113.h"
  48. extern void Pol_Delay_us(volatile uint32_t microseconds);
  49. typedef struct _adf4153_st{
  50. double PFD_Value;
  51. uint16_t MOD_Value;
  52. uint32_t FRAC_Value;
  53. uint16_t INT_Value;
  54. double N_Value;
  55. }adf4153_st;
  56. extern PLL_Setting_st Pll_3_5_H;
  57. extern PLL_Setting_st Pll_3_5_L;
  58. uint32_t pow2(uint32_t val,int32_t val2){
  59. for(uint8_t i = 0; i < val2 - 1; i++){
  60. val = val * val;
  61. }
  62. return val;
  63. }
  64. double round_up( double value, int pos )
  65. {
  66. double temp;
  67. temp = value * pow2( 10, pos ); // �썝�븯�뒗 �냼�닔�젏 �옄由ъ닔留뚰겮 10�쓽 �늻�듅�쓣 �븿
  68. temp = (int)(temp + 0.5); // 0.5瑜� �뜑�븳�썑 踰꾨┝�븯硫� 諛섏삱由쇱씠 �맖
  69. temp *= pow2( 10, -pos ); // �떎�떆 �썝�옒 �냼�닔�젏 �옄由ъ닔濡�
  70. return temp;
  71. }
  72. double N_Reg_Value_Calc(double val){
  73. return val / 1000;
  74. }
  75. uint32_t N_Divider_Reg_Create(uint16_t _FRAC,uint16_t _INT,uint8_t _FASTLOCK){
  76. uint32_t ret = 0;
  77. uint32_t shift_bit = 0x01;
  78. uint8_t control_bit = 0;
  79. uint8_t i = 0;
  80. #ifdef DEBUG_PRINT
  81. printf("FRAC : %d INT : %d \r\n",(int)_FRAC,_INT);
  82. #endif /* DEBUG_PRINT */
  83. for(i = 0; i < 2; i++){
  84. if(control_bit & 0x01)
  85. ret += shift_bit << i;
  86. control_bit = control_bit >> 1;
  87. }
  88. #ifdef DEBUG_PRINT
  89. printf("\r\nLINE : %d ret : %x\r\n",__LINE__,ret);
  90. #endif /* DEBUG_PRINT */
  91. for(i = 2; i < 14; i++){
  92. if(_FRAC & 0x01)
  93. ret += shift_bit << i;
  94. _FRAC = _FRAC >> 1;
  95. }
  96. #ifdef DEBUG_PRINT
  97. printf("\r\nLINE : %d ret : %x\r\n",__LINE__,ret);
  98. #endif /* DEBUG_PRINT */
  99. for(i = 14; i < 22; i++){
  100. if(_INT & 0x01)
  101. ret += shift_bit << i;
  102. _INT = _INT >> 1;
  103. }
  104. #ifdef DEBUG_PRINT
  105. printf("\r\nLINE : %d ret : %x\r\n",__LINE__,ret);
  106. #endif /* DEBUG_PRINT */
  107. if(_FASTLOCK & 0x01)
  108. ret += shift_bit << i;
  109. #ifdef DEBUG_PRINT
  110. printf("\r\nLINE : %d ret : %x\r\n",__LINE__,ret);
  111. #endif /* DEBUG_PRINT */
  112. return ret;
  113. }
  114. uint32_t R_Divider_Reg_Create(uint16_t _MOD,uint8_t _RCOUNTER,uint8_t _PRESCALER,uint8_t _RESERVED,uint8_t _MUXOUT,uint8_t LOAD_CONTROL){
  115. uint32_t ret = 0;
  116. uint32_t shift_bit = 0x01;
  117. uint8_t control_bit = 1;
  118. uint8_t i = 0;
  119. #ifdef DEBUG_PRINT
  120. printf("_MOD : %d INT : %d \r\n",_MOD,_RCOUNTER);
  121. #endif /* DEBUG_PRINT */
  122. #ifdef DEBUG_PRINT
  123. printf("\r\nLINE : %d ret : %x\r\n",__LINE__,ret);
  124. #endif /* DEBUG_PRINT */
  125. for(i = 0; i < 2; i++){
  126. if(control_bit & 0x01)
  127. ret += shift_bit << i;
  128. control_bit = control_bit >> 1;
  129. }
  130. #ifdef DEBUG_PRINT
  131. printf("\r\nLINE : %d ret : %x\r\n",__LINE__,ret);
  132. #endif /* DEBUG_PRINT */
  133. for(i = 2; i < 14; i++){
  134. if(_MOD & 0x01)
  135. ret += shift_bit << i;
  136. _MOD = _MOD >> 1;
  137. }
  138. for(i = 14; i < 18; i++){
  139. if(_RCOUNTER & 0x01)
  140. ret += shift_bit << i;
  141. _RCOUNTER = _RCOUNTER >> 1;
  142. }
  143. if(_PRESCALER & 0x01)
  144. ret += shift_bit << i++;
  145. if(_RESERVED & 0x01)
  146. ret += shift_bit << i++;
  147. for(i = 19; i < 22; i++){
  148. if(_MUXOUT & 0x01)
  149. ret += shift_bit << i;
  150. _MUXOUT = _MUXOUT >> 1;
  151. }
  152. if(LOAD_CONTROL & 0x01)
  153. ret += shift_bit << i++;
  154. return ret;
  155. }
  156. ADF4153_R_N_Reg_st ADF4153_Freq_Calc(uint32_t Freq,uint32_t REFin,uint8_t R_Counter,uint32_t chspacing){
  157. adf4153_st temp_adf4153;
  158. double temp = 0;
  159. ADF4153_R_N_Reg_st temp_reg;
  160. temp_adf4153.PFD_Value = REFin / (R_Counter * 100);
  161. temp_adf4153.MOD_Value = ((double)temp_adf4153.PFD_Value / chspacing) * 1000;
  162. temp_adf4153.N_Value = N_Reg_Value_Calc(((double)(Freq * 10) / (double)(temp_adf4153.PFD_Value / 1000)));
  163. temp_adf4153.INT_Value = temp_adf4153.N_Value ;
  164. if(Freq == 393432){
  165. printf("temp_adf4153.PFD_Value : %f \r\ntemp_adf4153.MOD_Value : %f \r\n temp_adf4153.N_Value : %f \r\n temp_adf4153.INT_Value : %f \r\n",temp_adf4153.PFD_Value,temp_adf4153.MOD_Value,temp_adf4153.N_Value,temp_adf4153.INT_Value);
  166. }
  167. #ifdef DEBUG_PRINT
  168. printf("\r\ntemp_adf4153.N_Value : %f temp_adf4153.INT_Value : %f temp_adf4153.MOD_Value : %f \r\n",temp_adf4153.N_Value,(double)temp_adf4153.INT_Value,(double)temp_adf4153.MOD_Value);
  169. #endif /* DEBUG_PRINT */
  170. temp = temp_adf4153.N_Value - (double)temp_adf4153.INT_Value;
  171. #ifdef DEBUG_PRINT
  172. printf("\r\n temp_adf4153.N_Value - (double)temp_adf4153.INT_Value) : %f temp * (double)temp_adf4153.MOD_Value : %f \r\n",temp,temp * (double)temp_adf4153.MOD_Value);
  173. #endif /* DEBUG_PRINT */
  174. temp_adf4153.FRAC_Value = (float)temp * temp_adf4153.MOD_Value;
  175. #ifdef DEBUG_PRINT
  176. printf("\r\ntemp_adf4153.N_Value : %x : %f ",temp_adf4153.N_Value,((double)(Freq / 1000) / (double)(temp_adf4153.PFD_Value / 1000)) / 1000);
  177. printf("temp_adf4153.MOD_Value : %x : %d \r\n",temp_adf4153.MOD_Value,temp_adf4153.MOD_Value);
  178. #endif /* DEBUG_PRINT */
  179. uint16_t tempmod = temp_adf4153.FRAC_Value;
  180. for(uint8_t i = 0; i < 12; i++){
  181. #ifdef DEBUG_PRINT
  182. if(temp_adf4153.MOD_Value & 0x800){
  183. printf("1");
  184. }else{
  185. printf("0");
  186. }
  187. #endif /* DEBUG_PRINT */
  188. tempmod = tempmod << 1;
  189. }
  190. #ifdef DEBUG_PRINT
  191. printf("\r\n");
  192. printf("temp_adf4153.FRAC_Value : %x : %d\r\n",temp_adf4153.FRAC_Value,temp_adf4153.FRAC_Value);
  193. #endif /* DEBUG_PRINT */
  194. uint16_t tempfrac = temp_adf4153.FRAC_Value;
  195. for(uint8_t i = 0; i < 12; i++){
  196. #ifdef DEBUG_PRINT
  197. if(tempfrac & 0x800){
  198. printf("1");
  199. }else{
  200. printf("0");
  201. }
  202. #endif /* DEBUG_PRINT */
  203. tempfrac = tempfrac << 1;
  204. }
  205. #ifdef DEBUG_PRINT
  206. printf("\r\n");
  207. #endif /* DEBUG_PRINT */
  208. #ifdef DEBUG_PRINT
  209. printf("temp_adf4153.INT_Value : %x : %d\r\n",temp_adf4153.INT_Value,temp_adf4153.INT_Value);
  210. #endif /* DEBUG_PRINT */
  211. uint16_t tempint = temp_adf4153.INT_Value;
  212. for(uint8_t i = 0; i < 9; i++){
  213. #ifdef DEBUG_PRINT
  214. if(tempint & 0x100){
  215. printf("1");
  216. }else{
  217. printf("0");
  218. }
  219. #endif /* DEBUG_PRINT */
  220. tempint = tempint << 1;
  221. }
  222. #ifdef DEBUG_PRINT
  223. printf("\r\n");
  224. printf("R0: %x R1: %x \r\n",N_Divider_Reg_Create(temp_adf4153.FRAC_Value,temp_adf4153.INT_Value,0),R_Divider_Reg_Create(temp_adf4153.MOD_Value,R_Counter,1,0,2,0));
  225. #endif /* DEBUG_PRINT */
  226. temp_reg.N_reg = N_Divider_Reg_Create(temp_adf4153.FRAC_Value,temp_adf4153.INT_Value,0);
  227. temp_reg.R_reg = R_Divider_Reg_Create(temp_adf4153.MOD_Value,R_Counter,1,0,2,0);
  228. return temp_reg;
  229. // R_Divider_Reg_Create(temp_adf4153.MOD_Value,R_Counter,1,0,1,0); //prescaler 1 : 8/9 0: 4/5
  230. }
  231. void ADF4153_Initialize(void){
  232. #if 0 // PYJ.2019.08.09_BEGIN --
  233. PLL_Setting_st Pll_test = {
  234. PLL_CLK_3_5G_GPIO_Port,
  235. PLL_CLK_3_5G_Pin,
  236. PLL_DATA_3_5G_GPIO_Port,
  237. PLL_DATA_3_5G_Pin,
  238. PLL_EN_3_5G_L_GPIO_Port,
  239. PLL_EN_3_5G_L_Pin,
  240. };
  241. PLL_Setting_st Pll_test2 = {
  242. PLL_CLK_3_5G_GPIO_Port,
  243. PLL_CLK_3_5G_Pin,
  244. PLL_DATA_3_5G_GPIO_Port,
  245. PLL_DATA_3_5G_Pin,
  246. PLL_EN_3_5G_H_GPIO_Port,
  247. PLL_EN_3_5G_H_Pin,
  248. };
  249. // ADF4153_Module_Ctrl(Pll_test,0x2B44B0,0x14BE81,0x0013C2,0x000003);
  250. ADF4153_R_N_Reg_st temp_reg;
  251. temp_reg = ADF4153_Freq_Calc(3465500000,ADF4153_40MHzREFIN,ADF4153_2RCOUNTER,ADF4153_CHANNEL_SPACING);
  252. ADF4153_Module_Ctrl(Pll_test,temp_reg.N_reg,temp_reg.R_reg,0x13c2,0x3);
  253. HAL_Delay(1);
  254. #ifdef DEBUG_PRINT
  255. printf("\r\nPLL_EN_3_5G_H_GPIO_Port\r\n");
  256. #endif /* DEBUG_PRINT */
  257. temp_reg = ADF4153_Freq_Calc(3934500000,ADF4153_40MHzREFIN,ADF4153_2RCOUNTER,ADF4153_CHANNEL_SPACING);
  258. ADF4153_Module_Ctrl(Pll_test2,temp_reg.N_reg,temp_reg.R_reg,0x13c2,0x3);
  259. // ADF4153_Module_Ctrl(Pll_test2,0x313840,0x14BE81,0x13C2,0x3);
  260. HAL_Delay(1);
  261. #endif // PYJ.2019.08.09_END --
  262. if( Flash_Save_data[INDEX_PLL_3_5G_LOW_H] == 0
  263. && Flash_Save_data[INDEX_PLL_3_5G_LOW_M] == 0
  264. &&Flash_Save_data[INDEX_PLL_3_5G_LOW_L] == 0)
  265. {
  266. Flash_Save_data[INDEX_PLL_3_5G_LOW_H] = ((34655 & 0xFF0000) >> 16);
  267. Flash_Save_data[INDEX_PLL_3_5G_LOW_M] = ((34655 & 0x00FF00) >> 8);
  268. Flash_Save_data[INDEX_PLL_3_5G_LOW_L] = (34655 & 0x0000FF);
  269. }
  270. if(Flash_Save_data[INDEX_PLL_3_5G_HIGH_H] == 0
  271. && Flash_Save_data[INDEX_PLL_3_5G_HIGH_M] == 0
  272. && Flash_Save_data[INDEX_PLL_3_5G_HIGH_L] == 0)
  273. {
  274. Flash_Save_data[INDEX_PLL_3_5G_HIGH_H] = ((39345 & 0xFF0000) >> 16);
  275. Flash_Save_data[INDEX_PLL_3_5G_HIGH_M] = ((39345 & 0x00FF00) >> 8);
  276. Flash_Save_data[INDEX_PLL_3_5G_HIGH_L] = (39345 & 0x0000FF);
  277. }
  278. }
  279. void ADF4153_Check(void){
  280. ADF4153_R_N_Reg_st temp_reg;
  281. if(HAL_GPIO_ReadPin(PLL_LD_3_5G_H_GPIO_Port, PLL_LD_3_5G_H_Pin) == GPIO_PIN_RESET
  282. && HAL_GPIO_ReadPin(PLL_ON_OFF_3_5G_H_GPIO_Port, PLL_ON_OFF_3_5G_H_Pin) == GPIO_PIN_SET){
  283. temp_reg = ADF4153_Freq_Calc(3934500000,ADF4153_40MHzREFIN,ADF4153_2RCOUNTER,ADF4153_CHANNEL_SPACING);
  284. ADF4153_Module_Ctrl(Pll_3_5_H,temp_reg.N_reg,temp_reg.R_reg,0x13c2,0x3);
  285. HAL_Delay(1);
  286. }
  287. if(HAL_GPIO_ReadPin(PLL_LD_3_5G_L_GPIO_Port, PLL_LD_3_5G_L_Pin) == GPIO_PIN_RESET
  288. && HAL_GPIO_ReadPin(PLL_ON_OFF_3_5G_L_GPIO_Port, PLL_ON_OFF_3_5G_L_Pin) == GPIO_PIN_SET){
  289. temp_reg = ADF4153_Freq_Calc(3465500000,ADF4153_40MHzREFIN,ADF4153_2RCOUNTER,ADF4153_CHANNEL_SPACING);
  290. ADF4153_Module_Ctrl(Pll_3_5_L,temp_reg.N_reg,temp_reg.R_reg,0x13c2,0x3);
  291. HAL_Delay(1);
  292. }
  293. }
  294. void ADF4153_Module_Ctrl(PLL_Setting_st pll,uint32_t R0,uint32_t R1,uint32_t R2,uint32_t R3){
  295. R3 = R3 & 0x0007FF;
  296. R2 = R2 & 0x00FFFF;
  297. R1 = R1 & 0xFFFFFF;
  298. R0 = R0 & 0xFFFFFF;
  299. // ADF4153_Freq_Calc(3461500000,40000000,2,5000);
  300. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET);
  301. HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_RESET);
  302. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_RESET);
  303. #ifdef DEBUG_PRINT
  304. printf("YJ :R0: %x R1: %x R2 : %x R3 : %x ",R0,R1,R2,R3);
  305. printf("\r\n");
  306. #endif /* DEBUG_PRINT */
  307. /* R3 Ctrl */
  308. for(int i =0; i < 11; i++){
  309. if(R3 & 0x000400){
  310. HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_SET);
  311. #ifdef DEBUG_PRINT
  312. printf("1");
  313. #endif /* DEBUG_PRINT */
  314. }
  315. else{
  316. HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_RESET);
  317. #ifdef DEBUG_PRINT
  318. printf("0");
  319. #endif /* DEBUG_PRINT */
  320. }
  321. Pol_Delay_us(10);
  322. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_SET);
  323. Pol_Delay_us(10);
  324. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET);
  325. R3 = (R3 << 1);
  326. }
  327. #ifdef DEBUG_PRINT
  328. printf("\r\n");
  329. #endif /* DEBUG_PRINT */
  330. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_SET);
  331. Pol_Delay_us(10);
  332. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_RESET);
  333. /* R2 Ctrl */
  334. for(int i =0; i < 16; i++){
  335. if(R2 & 0x008000){
  336. HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_SET);
  337. #ifdef DEBUG_PRINT
  338. printf("1");
  339. #endif /* DEBUG_PRINT */
  340. }
  341. else{
  342. HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_RESET);
  343. #ifdef DEBUG_PRINT
  344. printf("0");
  345. #endif /* DEBUG_PRINT */
  346. }
  347. Pol_Delay_us(10);
  348. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_SET);
  349. Pol_Delay_us(10);
  350. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET);
  351. R2 = ((R2 << 1) & 0x00FFFF);
  352. }
  353. #ifdef DEBUG_PRINT
  354. printf("\r\n");
  355. #endif /* DEBUG_PRINT */
  356. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_SET);
  357. Pol_Delay_us(10);
  358. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_RESET);
  359. /* R1 Ctrl */
  360. for(int i =0; i < 24; i++){
  361. if(R1 & 0x800000){
  362. HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_SET);
  363. #ifdef DEBUG_PRINT
  364. printf("1");
  365. #endif /* DEBUG_PRINT */
  366. }
  367. else{
  368. HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_RESET);
  369. #ifdef DEBUG_PRINT
  370. printf("0");
  371. #endif /* DEBUG_PRINT */
  372. }
  373. Pol_Delay_us(10);
  374. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_SET);
  375. Pol_Delay_us(10);
  376. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET);
  377. R1 = ((R1 << 1) & 0xFFFFFF);
  378. }
  379. #ifdef DEBUG_PRINT
  380. printf("\r\n");
  381. #endif /* DEBUG_PRINT */
  382. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_SET);
  383. Pol_Delay_us(10);
  384. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_RESET);
  385. /* R0 Ctrl */
  386. for(int i =0; i < 24; i++){
  387. if(R0 & 0x800000){
  388. HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_SET);
  389. #ifdef DEBUG_PRINT
  390. printf("1");
  391. #endif /* DEBUG_PRINT */
  392. }
  393. else{
  394. HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_RESET);
  395. #ifdef DEBUG_PRINT
  396. printf("0");
  397. #endif /* DEBUG_PRINT */
  398. }
  399. Pol_Delay_us(10);
  400. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_SET);
  401. Pol_Delay_us(10);
  402. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET);
  403. R0 = ((R0 << 1) & 0xFFFFFF);
  404. }
  405. #ifdef DEBUG_PRINT
  406. printf("\r\n");
  407. #endif /* DEBUG_PRINT */
  408. HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_RESET);
  409. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_SET);
  410. Pol_Delay_us(10);
  411. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_RESET);
  412. }