rcc.lst 26 KB

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