rcc.lst 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. C51 COMPILER V9.60.7.0 RCC 11/21/2025 17:21:11 PAGE 1
  2. C51 COMPILER V9.60.7.0, COMPILATION OF MODULE RCC
  3. OBJECT MODULE PLACED IN .\Objects\rcc.obj
  4. COMPILER INVOKED BY: d:\Keil_v5\C51\BIN\C51.EXE ..\..\..\..\driver\src\rcc.c OBJECTADVANCED OPTIMIZE(9,SPEED) BROWSE ORD
  5. -ER NOAREGS MODC2 INCDIR(..\..\..\..\driver\inc;..\..\..\..\mcu;..\..\..\..\middleware\log;..\..\..\..\middleware\delay;.
  6. -.\..\..\..\middleware\rf_basis) DEBUG PRINT(.\Listings\rcc.lst) TABS(2) OBJECT(.\Objects\rcc.obj)
  7. line level source
  8. 1 /**
  9. 2 ************************************************************************
  10. 3 * @file rcc.c
  11. 4 * @author Panchip Team
  12. 5 * @version V0.5
  13. 6 * @date 2024-04-28
  14. 7 * @brief This file provides all the rcc firmware functions.
  15. 8 * @note
  16. 9 * Copyright (C) 2024 Panchip Technology Corp. All rights reserved.
  17. 10 ****************************************************************************
  18. 11 */
  19. 12
  20. 13 #include "rcc.h"
  21. 14
  22. 15 /** @addtogroup PAN262x_Std_Driver
  23. 16 * @{
  24. 17 */
  25. 18
  26. 19 /** @defgroup RCC
  27. 20 * @brief RCC driver modules
  28. 21 * @{
  29. 22 */
  30. 23
  31. 24 /** @defgroup RCC_Private_Functions
  32. 25 * @{
  33. 26 */
  34. 27
  35. 28 /**
  36. 29 * @brief Reset one or more peripheral.
  37. 30 * @param RCC_Periph: specifies the peripheral to be reset.
  38. 31 * This parameter can be any combination of the following values:
  39. 32 * @arg RCC_PERIPH_WDT: WDT peripheral
  40. 33 * @arg RCC_PERIPH_SPI: SPI peripheral
  41. 34 * @arg RCC_PERIPH_I2C: I2C peripheral
  42. 35 * @arg RCC_PERIPH_TIMER2: TIMER2 peripheral
  43. 36 * @arg RCC_PERIPH_TIMER1: TIMER1 peripheral
  44. 37 * @arg RCC_PERIPH_TIMER0: TIMER2 peripheral
  45. 38 * @arg RCC_PERIPH_UART: UART peripheral
  46. 39 * @arg RCC_PERIPH_PORT: PORT peripheral
  47. 40 * @arg RCC_PERIPH_USB: USB peripheral
  48. 41 * @arg RCC_PERIPH_PWM: PWM peripheral
  49. 42 * @arg RCC_PERIPH_ADC: ADC peripheral
  50. 43 * @arg RCC_PERIPH_RF: RF peripheral
  51. 44 * @retval None
  52. 45 */
  53. 46 void RCC_PeriphReset(u16 RCC_Periph)
  54. 47 {
  55. 48 1 RCC_Periph &= 0x0F7F; /**< Clear bit 7 of RCC_Periph to avoid to reset wdt peripheral */
  56. 49 1
  57. 50 1 if ((RCC_Periph & 0xFF) != 0)
  58. 51 1 {
  59. 52 2 RCC_SEL = PERRST0;
  60. 53 2 RCC_DAT |= (u8)RCC_Periph;
  61. C51 COMPILER V9.60.7.0 RCC 11/21/2025 17:21:11 PAGE 2
  62. 54 2 RCC_DAT &= ~((u8)RCC_Periph);
  63. 55 2 }
  64. 56 1 else
  65. 57 1 {
  66. 58 2 RCC_Periph >>= 8;
  67. 59 2
  68. 60 2 RCC_SEL = PERRST1;
  69. 61 2 RCC_DAT |= (u8)RCC_Periph;
  70. 62 2 RCC_DAT &= ~((u8)RCC_Periph);
  71. 63 2 }
  72. 64 1 }
  73. 65
  74. 66 /**
  75. 67 * @brief Enables or disables the peripheral clock.
  76. 68 * @param RCC_Periph: specifies the peripheral to gates its clock.
  77. 69 * This parameter can be any combination of the following values:
  78. 70 * @arg RCC_PERIPH_WDT: WDT clock
  79. 71 * @arg RCC_PERIPH_SPI: SPI clock
  80. 72 * @arg RCC_PERIPH_I2C: I2C clock
  81. 73 * @arg RCC_PERIPH_TIMER2: TIMER2 clock
  82. 74 * @arg RCC_PERIPH_TIMER1: TIMER1 clock
  83. 75 * @arg RCC_PERIPH_TIMER0: TIMER2 clock
  84. 76 * @arg RCC_PERIPH_UART: UART clock
  85. 77 * @arg RCC_PERIPH_PORT: PORT clock
  86. 78 * @arg RCC_PERIPH_USB: USB clock
  87. 79 * @arg RCC_PERIPH_PWM: PWM clock
  88. 80 * @arg RCC_PERIPH_ADC: ADC clock
  89. 81 * @arg RCC_PERIPH_RF: RF clock
  90. 82 * @param NewState: new state of the specified peripheral clock.
  91. 83 * This parameter can be: ENABLE or DISABLE.
  92. 84 * @retval None
  93. 85 */
  94. 86 void RCC_PeriphClockCmd(u16 RCC_Periph, u8 NewState)
  95. 87 {
  96. 88 1 if ((RCC_Periph & 0xFF) != 0)
  97. 89 1 {
  98. 90 2 RCC_SEL = PERCLKEN0;
  99. 91 2
  100. 92 2 if (NewState)
  101. 93 2 {
  102. 94 3 RCC_DAT |= (u8)RCC_Periph;
  103. 95 3 }
  104. 96 2 else
  105. 97 2 {
  106. 98 3 RCC_DAT &= ~((u8)RCC_Periph);
  107. 99 3 }
  108. 100 2 }
  109. 101 1 else
  110. 102 1 {
  111. 103 2 RCC_SEL = PERCLKEN1;
  112. 104 2
  113. 105 2 if (NewState)
  114. 106 2 {
  115. 107 3 RCC_DAT |= (u8)(RCC_Periph >> 8);
  116. 108 3 }
  117. 109 2 else
  118. 110 2 {
  119. 111 3 RCC_DAT &= ~((u8)(RCC_Periph >> 8));
  120. 112 3 }
  121. 113 2 }
  122. 114 1 }
  123. 115
  124. C51 COMPILER V9.60.7.0 RCC 11/21/2025 17:21:11 PAGE 3
  125. 116 /**
  126. 117 * @brief This function ENABLE or DISABLE the peripheral
  127. 118 * @param sel: peripheral
  128. 119 * @arg: RCH
  129. 120 * @arg: RCL
  130. 121 * @arg: XTH
  131. 122 * @arg: DPLL
  132. 123 * @param NewState: enable or disable
  133. 124 * @arg: DISABLE
  134. 125 * @arg: ENABLE
  135. 126 * @retval None
  136. 127 */
  137. 128 void RCC_Ctrl(u8 sel, u8 NewState)
  138. 129 {
  139. 130 1 u16 count = 0;
  140. 131 1
  141. 132 1 RCC_SEL = CLK_TOP_CTRL;
  142. 133 1
  143. 134 1 switch (sel)
  144. 135 1 {
  145. 136 2 case RCH:
  146. 137 2 if (NewState)
  147. 138 2 {
  148. 139 3 RCC_DAT |= RCH_EN;
  149. 140 3 ANA_RCH_SYNC;
  150. 141 3 RCC_SEL = RCH_CTRL0;
  151. 142 3 while ((RCC_DAT & RCH_RDY) == FALSE)
  152. 143 3 {
  153. 144 4 if(count++>65530)
  154. 145 4 {
  155. 146 5 MCU_REBOOT();
  156. 147 5 }
  157. 148 4 }
  158. 149 3 }
  159. 150 2 else
  160. 151 2 {
  161. 152 3 RCC_DAT &= ~RCH_EN;
  162. 153 3 ANA_RCH_SYNC;
  163. 154 3 }
  164. 155 2 break;
  165. 156 2
  166. 157 2 case RCL:
  167. 158 2 if (NewState)
  168. 159 2 {
  169. 160 3 RCC_DAT |= RCL_EN;
  170. 161 3 ANA_RCH_SYNC;
  171. 162 3 }
  172. 163 2 else
  173. 164 2 {
  174. 165 3 RCC_DAT &= ~RCL_EN;
  175. 166 3 ANA_RCH_SYNC;
  176. 167 3 }
  177. 168 2 break;
  178. 169 2
  179. 170 2 case XTH:
  180. 171 2 if (NewState)
  181. 172 2 {
  182. 173 3 u8 Temp;// = RCC_DAT|XTH_EN; /**< Stroe CLK_TOP_CTRL to Temp */
  183. 174 3
  184. 175 3 if((RCC_DAT&XTH_EN) != 0) //XTH is already opened
  185. 176 3 {
  186. 177 4 return;
  187. C51 COMPILER V9.60.7.0 RCC 11/21/2025 17:21:11 PAGE 4
  188. 178 4 }
  189. 179 3
  190. 180 3 Temp = RCC_DAT | XTH_EN; /**< Stroe CLK_TOP_CTRL to Temp */
  191. 181 3
  192. 182 3 if ((RCC_DAT & 0x80) != 0) /**< System clock is from XTH or DPLL_16M */
  193. 183 3 {
  194. 184 4 RCC_DAT |= RCH_EN; /**< Enable interal RCH clock */
  195. 185 4 ANA_RCH_SYNC;
  196. 186 4
  197. 187 4 /** Wait RCH_RDY flag until it becomes to 1 */
  198. 188 4 while ((GET_WREG(RCC, RCH_CTRL0) & RCH_RDY) == FALSE)
  199. 189 4 {
  200. 190 5 if(count++>65530)
  201. 191 5 {
  202. 192 6 MCU_REBOOT();
  203. 193 6 }
  204. 194 5 }
  205. 195 4 AND_WREG(RCC, CLK_TOP_CTRL, 0x3F); /**< Select RCH as system clock */
  206. 196 4 }
  207. 197 3
  208. 198 3 OR_WREG(RCC, XTH_CTRL, 0x0C); /**< Enable FAST_TRIM */
  209. 199 3 AND_WREG(RCC, XTH_CTRL, 0xEF); /**< Disable EN_XTAL_RDY */
  210. 200 3 OR_WREG(RCC, CLK_TOP_CTRL, XTH_EN); /**< Enable external XTAL clock */
  211. 201 3 OR_WREG(RCC, XTH_CTRL, 0x10); /**< Enable EN_XTAL_RDY */
  212. 202 3
  213. 203 3 /** Wait XTAL_RDY flag until it becomes to 1 */
  214. 204 3 while ((GET_WREG(RCC, XTH_CTRL) & XTH_RDY) == FALSE)
  215. 205 3 {
  216. 206 4 if(count++ > 65530)
  217. 207 4 {
  218. 208 5 MCU_REBOOT();
  219. 209 5 }
  220. 210 4 }
  221. 211 3
  222. 212 3 AND_WREG(RCC, XTH_CTRL, 0xFB); /**< Disable EN_FAST */
  223. 213 3 // SET_WREG(RCC, CLK_TOP_CTRL, Temp); /**< Restroe CLK_TOP_CTRL */
  224. 214 3 }
  225. 215 2 else
  226. 216 2 {
  227. 217 3 RCC_DAT &= ~XTH_EN;
  228. 218 3 }
  229. 219 2 break;
  230. 220 2
  231. 221 2 case DPLL:
  232. 222 2 if (NewState)
  233. 223 2 {
  234. 224 3 if((RCC_DAT&DPLL_EN) != 0) //DPLL is already opened
  235. 225 3 {
  236. 226 4 return;
  237. 227 4 }
  238. 228 3
  239. 229 3 RCC_DAT |= DPLL_EN;
  240. 230 3 RCC_SEL = DPLL_CTRL;
  241. 231 3 while ((RCC_DAT & DPLL_RDY) == FALSE)
  242. 232 3 {
  243. 233 4 if(count++>65530)
  244. 234 4 {
  245. 235 5 MCU_REBOOT();
  246. 236 5 }
  247. 237 4 }
  248. 238 3 }
  249. 239 2 else
  250. C51 COMPILER V9.60.7.0 RCC 11/21/2025 17:21:11 PAGE 5
  251. 240 2 {
  252. 241 3 RCC_DAT &= ~DPLL_EN;
  253. 242 3 }
  254. 243 2 break;
  255. 244 2 }
  256. 245 1 }
  257. 246
  258. 247 /**
  259. 248 * @brief Turn on external crystal oscillator in non-blocking mode.
  260. 249 *
  261. 250 * This function turns on the external crystal oscillator in non-blocking mode. The function
  262. 251 * returns immediately and the caller should check the status of the crystal oscillator using
  263. 252 * the appropriate status register.
  264. 253 *
  265. 254 * @return None.
  266. 255 */
  267. 256 void RCC_XTALTurnOnNoneBlock(void)
  268. 257 {
  269. 258 1 OR_WREG(RCC, XTH_CTRL, 0x0C); /**< Enable FAST_TRIM */
  270. 259 1 AND_WREG(RCC, XTH_CTRL, 0xEF); /**< Disable EN_XTAL_RDY */
  271. 260 1 OR_WREG(RCC, CLK_TOP_CTRL, XTH_EN); /**< Enable external XTAL clock */
  272. 261 1 OR_WREG(RCC, XTH_CTRL, 0x10); /**< Enable EN_XTAL_RDY */
  273. 262 1 }
  274. 263
  275. 264 /**
  276. 265 * @brief Get the status of clock source.
  277. 266 *
  278. 267 * This function returns the status of external crystal oscillator. If the oscillator is stable,
  279. 268 * the function returns @c TRUE, otherwise it returns @c FALSE.
  280. 269 *
  281. 270 * @param[in] ClockSource Specifies the clock source to check. Valid values are:
  282. 271 * - RCH: internal high-speed oscillator
  283. 272 * - RCL: internal low-speed oscillator
  284. 273 * - XTAL: external crystal oscillator
  285. 274 * - DPLL: digital phase-locked loop
  286. 275 *
  287. 276 * @return @c TRUE if the specified clock source is stable, @c FALSE otherwise.
  288. 277 *
  289. 278 */
  290. 279 bool RCC_GetClockReadyStatus(u8 ClockSource)
  291. 280 {
  292. 281 1 bool ReadyFlag = FALSE;
  293. 282 1
  294. 283 1 if (RCH == ClockSource)
  295. 284 1 {
  296. 285 2 ReadyFlag = (GET_WREG(RCC, RCH_CTRL0) & RCH_RDY) ? TRUE : FALSE;
  297. 286 2 }
  298. 287 1 else if (XTH == ClockSource)
  299. 288 1 {
  300. 289 2 ReadyFlag = (GET_WREG(RCC, XTH_CTRL) & XTH_RDY) ? TRUE : FALSE;
  301. 290 2 }
  302. 291 1 else if (DPLL == ClockSource)
  303. 292 1 {
  304. 293 2 ReadyFlag = (GET_WREG(RCC, DPLL_CTRL) & DPLL_RDY) ? TRUE : FALSE;
  305. 294 2 }
  306. 295 1
  307. 296 1 return ReadyFlag;
  308. 297 1 }
  309. 298
  310. 299 /**
  311. 300 * @brief Enable or disable external crystal oscillator fast ready function.
  312. 301 *
  313. C51 COMPILER V9.60.7.0 RCC 11/21/2025 17:21:11 PAGE 6
  314. 302 * This function enables or disables the external crystal oscillator fast ready function.
  315. 303 * If the function is enabled, the system will use the fast ready function to speed up the
  316. 304 * startup time of the external crystal oscillator. If the function is disabled, the system
  317. 305 * will use the normal startup time.
  318. 306 *
  319. 307 * @param[in] enable Specifies whether to enable or disable the fast ready function. Valid values
  320. 308 * are:
  321. 309 * - ENABLE: enable the fast ready function
  322. 310 * - DISABLE: disable the fast ready function
  323. 311 *
  324. 312 * @return None.
  325. 313 *
  326. 314 */
  327. 315 void RCC_XTALFastRdyEnable(u8 NewState)
  328. 316 {
  329. 317 1 if (NewState)
  330. 318 1 {
  331. 319 2 OR_WREG(RCC, XTH_CTRL, 0x04); /**< Enable EN_FAST */
  332. 320 2 }
  333. 321 1 else
  334. 322 1 {
  335. 323 2 AND_WREG(RCC, XTH_CTRL, 0xFB); /**< Disable EN_FAST */
  336. 324 2 }
  337. 325 1 }
  338. 326
  339. 327 /**
  340. 328 * @brief This function select clock source
  341. 329 * @param sel: peripheral
  342. 330 * @arg: RCH
  343. 331 * @arg: XTH
  344. 332 * @arg: DPLL
  345. 333 * @retval None
  346. 334 */
  347. 335 void RCC_Source(u8 sel)
  348. 336 {
  349. 337 1 RCC_SEL = CLK_TOP_CTRL;
  350. 338 1 RCC_DAT = ((RCC_DAT & CLK_SEL) | (sel << 6));
  351. 339 1 }
  352. 340
  353. 341 /**
  354. 342 * @brief This function select clock source
  355. 343 * @param Division: System clock division
  356. 344 * @arg: SYS_CLK_DIV_1
  357. 345 * @arg: SYS_CLK_DIV_2
  358. 346 * @arg: SYS_CLK_DIV_4
  359. 347 * @arg: SYS_CLK_DIV_6
  360. 348 * @retval None
  361. 349 */
  362. 350 void RCC_SysDiv(u8 Division)
  363. 351 {
  364. 352 1 RCC_SEL = CLK_TOP_CTRL;
  365. 353 1 RCC_DAT = ((RCC_DAT & SYS_DIV_Msk) | Division);
  366. 354 1 }
  367. 355
  368. 356 /**
  369. 357 * @brief This function calibrate RCH
  370. 358 * @param None
  371. 359 * @retval None
  372. 360 */
  373. 361 void RCC_RchCali(u8 rch_cap_trim, u8 rch_cal_code_cfg)
  374. 362 {
  375. 363 1 u8 trim = rch_cap_trim;
  376. C51 COMPILER V9.60.7.0 RCC 11/21/2025 17:21:11 PAGE 7
  377. 364 1 u8 cal = rch_cal_code_cfg;
  378. 365 1
  379. 366 1 RCC_SEL = RCH_CTRL0;
  380. 367 1 RCC_DAT = ((RCC_DAT & RCH_CAP_TRIM) | rch_cap_trim);
  381. 368 1
  382. 369 1 RCC_SEL = RCHCAL_2H;
  383. 370 1 RCC_DAT = ((rch_cal_code_cfg << 1) | (EN_RCHCAL_CODE)); // rch_cal_code_cfg 6BIT(1~6)
  384. 371 1 }
  385. 372
  386. 373 /**
  387. 374 * @brief This function calibrate RCH Disable
  388. 375 * @param None
  389. 376 * @retval None
  390. 377 */
  391. 378 void RCC_RchCaliDisable(void)
  392. 379 {
  393. 380 1 RCC_SEL = RCHCAL_2H;
  394. 381 1 RCC_DAT &= ~EN_RCHCAL_CODE;
  395. 382 1 }
  396. 383
  397. 384 /**
  398. 385 * @brief This function calibrate RCH automatic
  399. 386 * @param None
  400. 387 * @retval None
  401. 388 */
  402. 389 void RCC_RchCaliAuto(void)
  403. 390 {
  404. 391 1 RCC_SEL = RCHCAL_EN;
  405. 392 1 RCC_DAT |= EN_RCHCAL_AUTO;
  406. 393 1 }
  407. 394
  408. 395 /**
  409. 396 * @brief This function calibrate RCH
  410. 397 * @param None
  411. 398 * @retval None
  412. 399 */
  413. 400 void RCC_RclCali_EN(u8 NewState)
  414. 401 {
  415. 402 1 RCC_SEL = RCL_CTRL0;
  416. 403 1 if (NewState)
  417. 404 1 {
  418. 405 2 RCC_DAT |= RCL_CAL_EN;
  419. 406 2 }
  420. 407 1 else
  421. 408 1 {
  422. 409 2 RCC_DAT &= ~RCL_CAL_EN;
  423. 410 2 }
  424. 411 1 ANA_RCH_SYNC;
  425. 412 1 }
  426. 413
  427. 414 /**
  428. 415 * @brief This function calibrate rcl manually
  429. 416 *
  430. 417 * @param NewState
  431. 418 */
  432. 419 void RCC_RclCali_MANU(u8 NewState)
  433. 420 {
  434. 421 1 RCC_SEL = RCL_CTRL1;
  435. 422 1 if (NewState)
  436. 423 1 {
  437. 424 2 RCC_DAT |= 0x30;
  438. 425 2 }
  439. C51 COMPILER V9.60.7.0 RCC 11/21/2025 17:21:11 PAGE 8
  440. 426 1 else
  441. 427 1 {
  442. 428 2 RCC_DAT &= 0xCF;
  443. 429 2 }
  444. 430 1 ANA_RCH_SYNC;
  445. 431 1 }
  446. 432
  447. 433 /**
  448. 434 * @brief This function set LVR voltage level
  449. 435 *
  450. 436 * @param VoltLevel
  451. 437 * @arg LVR_VOLT_1V85
  452. 438 * @arg LVR_VOLT_2V
  453. 439 * @arg LVR_VOLT_2V2
  454. 440 * @arg LVR_VOLT_2V5
  455. 441 * @arg LVR_VOLT_2V65
  456. 442 * @arg LVR_VOLT_2V35
  457. 443 * @arg LVR_VOLT_2V8
  458. 444 * @retval None
  459. 445 */
  460. 446 void RCC_SetLvrVoltLevel(RCC_LvrVoltLevel_t VoltLevel)
  461. 447 {
  462. 448 1 u8 Level = (u8)1<<VoltLevel;
  463. 449 1
  464. 450 1 RCC_SEL = LVRH_SEL;
  465. 451 1 RCC_DAT = Level;
  466. 452 1 }
  467. 453
  468. 454 /**
  469. 455 * @brief This function enable or disable LVR
  470. 456 *
  471. 457 * @param NewState
  472. 458 * @arg ENABLE
  473. 459 * @arg DISABLE
  474. 460 * @retval None
  475. 461 */
  476. 462 void RCC_EnableLvr(u8 NewState)
  477. 463 {
  478. 464 1 RCC_SEL = LVRH_CTRL;
  479. 465 1
  480. 466 1 if (NewState)
  481. 467 1 {
  482. 468 2 RCC_DAT |= 0x02;
  483. 469 2 }
  484. 470 1 else
  485. 471 1 {
  486. 472 2 RCC_DAT &= ~0x02;
  487. 473 2 }
  488. 474 1
  489. 475 1 RCC_DAT &= ~0x01; /* Enable the reset function of LVR. */
  490. 476 1 ANA_RCH_SYNC;
  491. 477 1 }
  492. 478 /**
  493. 479 * @brief This function calibrate RCH
  494. 480 * @param None
  495. 481 * @retval None
  496. 482 */
  497. 483 void RCC_RclCali(u8 cali_per, u8 cali_h)
  498. 484 {
  499. 485 1 u8 reg_rcc;
  500. 486 1
  501. 487 1 reg_rcc = RCC_DAT;
  502. C51 COMPILER V9.60.7.0 RCC 11/21/2025 17:21:11 PAGE 9
  503. 488 1 reg_rcc &= RCL_CAL_PER_SEL;
  504. 489 1 reg_rcc |= cali_per;
  505. 490 1 RCC_DAT = reg_rcc;
  506. 491 1 ANA_RCH_SYNC;
  507. 492 1
  508. 493 1 reg_rcc &= RCL_CAL_H_SEL;
  509. 494 1 reg_rcc |= cali_h;
  510. 495 1 RCC_DAT = reg_rcc;
  511. 496 1 ANA_RCH_SYNC;
  512. 497 1 }
  513. 498
  514. 499 /**
  515. 500 * @brief This function mux clock to gpio
  516. 501 * @param None
  517. 502 * @retval None
  518. 503 */
  519. 504 void RCC_Mux(u8 source, u8 sel)
  520. 505 {
  521. 506 1 if (source == MUX_ANA)
  522. 507 1 {
  523. 508 2 ANA_SEL = ANA_TEST1;
  524. 509 2 ANA_DAT = sel;
  525. 510 2 }
  526. 511 1 if (source == MUX_DIG)
  527. 512 1 {
  528. 513 2 SYS_SEL = RCC_USB_CTRL;
  529. 514 2 SYS_DAT |= sel;
  530. 515 2 }
  531. 516 1
  532. 517 1 if (sel == DIG_MUX_DPLL48_DIV8)
  533. 518 1 {
  534. 519 2 RCC_SEL = DPLL_CTRL;
  535. 520 2 RCC_DAT = DPLL_TEST_EN;
  536. 521 2 }
  537. 522 1 }
  538. 523
  539. 524 /**
  540. 525 * @brief This function enter deepsleep mode
  541. 526 * @retval None
  542. 527 */
  543. 528 void RCC_PumpUp(void)
  544. 529 {
  545. 530 1 ANA_SEL = ANA_PWR_CTRL0;
  546. 531 1 ANA_DAT |= 0x08;
  547. 532 1 ANA_RCH_SYNC;
  548. 533 1 }
  549. 534
  550. 535 /**
  551. 536 * @brief Check if RCH has been calibrated to 15MHz based on the info parameter.
  552. 537 * @param None
  553. 538 * @return None
  554. 539 */
  555. 540 void RCC_RchCaliChk(void)
  556. 541 {
  557. 542 1 if (PAN_INFO_FLAG != 0x55AAAA55)
  558. 543 1 {
  559. 544 2 RCC_RchCali(0x20, 0x1A); /**< Calibrete freqence of RCH to 15MHz */
  560. 545 2 }
  561. 546 1 }
  562. 547
  563. 548 /**
  564. 549 * @brief This function initializes system clock
  565. C51 COMPILER V9.60.7.0 RCC 11/21/2025 17:21:11 PAGE 10
  566. 550 * @retval None
  567. 551 */
  568. 552 void RCC_SysClkInit(void)
  569. 553 {
  570. 554 1 ANA_IPOLY_ON(); /**< Turn on the ipoly power */
  571. 555 1 RCC_RchCaliChk();
  572. 556 1 RCC_Source(RCH); /**< Select XTH as system clock */
  573. 557 1 RCC_Ctrl(XTH, 1); /**< Enable XTH clock */
  574. 558 1 RCC_Ctrl(DPLL, 1); /**< Enable DPLL clock */
  575. 559 1 if(PAN_CHIP_VER == 0x01)
  576. 560 1 {
  577. 561 2 RCC_Source(XTH); /**< 2628 Select XTH as system clock */
  578. 562 2 }
  579. 563 1 if(PAN_CHIP_VER == 0x02)
  580. 564 1 {
  581. 565 2 RCC_Source(DPLL); /**< 2629 Select DPLL as system clock */
  582. 566 2 }
  583. 567 1 }
  584. 568
  585. 569 void RCC_LITE_SysClkInit(void)
  586. 570 {
  587. 571 1 // OR_WREG(RCC, PERCLKEN1, 0x01);
  588. 572 1 // RF_PMU |= EN_VBG_IPOLY;
  589. 573 1 ANA_IPOLY_ON();
  590. 574 1 RCC_SEL = CLK_TOP_CTRL;
  591. 575 1
  592. 576 1 if((RCC_DAT&XTH_EN) == 0)
  593. 577 1 {
  594. 578 2 RCC_SEL = XTH_CTRL;
  595. 579 2 RCC_DAT = 0x1F; /**< Enable FAST_TRIM */
  596. 580 2 RCC_DAT = 0x0F; /**< Disable EN_XTAL_RDY */
  597. 581 2 RCC_SEL = CLK_TOP_CTRL;
  598. 582 2 RCC_DAT |= XTH_EN;
  599. 583 2 RCC_SEL = XTH_CTRL;
  600. 584 2 RCC_DAT = 0x1F; /**< Enable EN_XTAL_RDY */
  601. 585 2
  602. 586 2 /** Wait XTAL_RDY flag until it becomes to 1 */
  603. 587 2 while (!(RCC_DAT&XTH_RDY));
  604. 588 2
  605. 589 2 RCC_DAT = 0x1B; /**< Disable EN_XTAL_RDY */
  606. 590 2 }
  607. 591 1
  608. 592 1 if((RCC_DAT&DPLL_EN) == 0)
  609. 593 1 {
  610. 594 2 RCC_SEL = CLK_TOP_CTRL;
  611. 595 2 RCC_DAT = 0x0F;
  612. 596 2
  613. 597 2 /* Waiting for dpll ready. */
  614. 598 2 RCC_SEL = DPLL_CTRL;
  615. 599 2 while(!(RCC_DAT & DPLL_RDY));
  616. 600 2 }
  617. 601 1 if(PAN_CHIP_VER == 0x01)
  618. 602 1 {
  619. 603 2 RCC_SEL = CLK_TOP_CTRL;
  620. 604 2 RCC_DAT = 0x8F;//Enable XTH clock, Enable DPLL clock, Select DPLL as system clock
  621. 605 2 }
  622. 606 1 if(PAN_CHIP_VER == 0x02)
  623. 607 1 {
  624. 608 2 RCC_SEL = CLK_TOP_CTRL;
  625. 609 2 RCC_DAT = 0xCF;//Enable XTH clock, Enable DPLL clock, Select DPLL as system clock
  626. 610 2 }
  627. 611 1 }
  628. C51 COMPILER V9.60.7.0 RCC 11/21/2025 17:21:11 PAGE 11
  629. 612
  630. 613 /**
  631. 614 * @}
  632. 615 */
  633. 616
  634. 617 /**
  635. 618 * @}
  636. 619 */
  637. 620
  638. 621 /**
  639. 622 * @}
  640. 623 */
  641. MODULE INFORMATION: STATIC OVERLAYABLE
  642. CODE SIZE = 1285 ----
  643. CONSTANT SIZE = ---- ----
  644. XDATA SIZE = ---- ----
  645. PDATA SIZE = ---- ----
  646. DATA SIZE = ---- 6
  647. IDATA SIZE = ---- ----
  648. BIT SIZE = ---- ----
  649. EDATA SIZE = ---- ----
  650. HDATA SIZE = ---- ----
  651. XDATA CONST SIZE = ---- ----
  652. FAR CONST SIZE = ---- ----
  653. END OF MODULE INFORMATION.
  654. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)