system_mb9bf61x.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /************************************************************************/
  2. /* (C) Fujitsu Semiconductor Europe GmbH (FSEU) */
  3. /* */
  4. /* The following software deliverable is intended for and must only be */
  5. /* used for reference and in an evaluation laboratory environment. */
  6. /* It is provided on an as-is basis without charge and is subject to */
  7. /* alterations. */
  8. /* It is the user's obligation to fully test the software in its */
  9. /* environment and to ensure proper functionality, qualification and */
  10. /* compliance with component specifications. */
  11. /* */
  12. /* In the event the software deliverable includes the use of open */
  13. /* source components, the provisions of the governing open source */
  14. /* license agreement shall apply with respect to such software */
  15. /* deliverable. */
  16. /* FSEU does not warrant that the deliverables do not infringe any */
  17. /* third party intellectual property right (IPR). In the event that */
  18. /* the deliverables infringe a third party IPR it is the sole */
  19. /* responsibility of the customer to obtain necessary licenses to */
  20. /* continue the usage of the deliverable. */
  21. /* */
  22. /* To the maximum extent permitted by applicable law FSEU disclaims all */
  23. /* warranties, whether express or implied, in particular, but not */
  24. /* limited to, warranties of merchantability and fitness for a */
  25. /* particular purpose for which the deliverable is not designated. */
  26. /* */
  27. /* To the maximum extent permitted by applicable law, FSEU's liability */
  28. /* is restricted to intentional misconduct and gross negligence. */
  29. /* FSEU is not liable for consequential damages. */
  30. /* */
  31. /* (V1.5) */
  32. /************************************************************************/
  33. /** \file system_mb9bf61x.h
  34. **
  35. ** Headerfile for FM3 system parameters
  36. **
  37. ** User clock definitions can be done for the following clock settings:
  38. ** - CLOCK_SETUP : Execute the clock settings form the settings below in
  39. ** SystemInit()
  40. ** - __CLKMO : External clock frequency for main oscillion
  41. ** - __CLKSO : External clock frequency for sub oscillion
  42. ** - SCM_CTL : System Clock Mode Control Register
  43. ** - BSC_PSR : Base Clock Prescaler Register
  44. ** - APBC0_PSR : APB0 Prescaler Register
  45. ** - APBC1_PSR : APB1 Prescaler Register
  46. ** - APBC2_PSR : APB2 Prescaler Register
  47. ** - SWC_PSR : Software Watchdog Clock Prescaler Register
  48. ** - TTC_PSR : Trace Clock Prescaler Register
  49. ** - CSW_TMR : Clock Stabilization Wait Time Register
  50. ** - PSW_TMR : PLL Clock Stabilization Wait Time Setup Register
  51. ** - PLL_CTL1 : PLL Control Register 1
  52. ** - PLL_CTL2 : PLL Control Register 2
  53. **
  54. ** The register settings are check for correct values of reserved bits.
  55. ** Otherwise a preprocessor error is output and stops the build process.
  56. ** Furthermore the 'master clock' is retrieved from the register settings
  57. ** and the system clock (HCLK) is calculated from the Base Clock Prescaler
  58. ** Register (BSC_PSR). This value is used for the global CMSIS variable
  59. ** #SystemCoreClock. Also the absolute external, PLL and HCL freqeuncy is
  60. ** is checked. Note that not all possible wrong setting are checked! The
  61. ** user has to take care to fulfill the settings stated in the according
  62. ** device's data sheet!
  63. **
  64. ** User definition for Hardware Watchdog:
  65. ** - HWWD_DISABLE : Disables Hardware Watchdog in SystemInit()
  66. **
  67. ** User definition for CR Trimming:
  68. ** - CR_TRIM_SETUP : Enables CR trimming in SystemInit()
  69. **
  70. ** History:
  71. ** 2011-05-16 V1.0 MWi original version
  72. *****************************************************************************/
  73. #ifndef _SYSTEM_MB9BF61X_H_
  74. #define _SYSTEM_MB9BF61X_H_
  75. #ifdef __cplusplus
  76. extern "C" {
  77. #endif
  78. /******************************************************************************/
  79. /* Include files */
  80. /******************************************************************************/
  81. #include <stdint.h>
  82. /******************************************************************************/
  83. /* Global pre-processor symbols/macros ('define') */
  84. /******************************************************************************/
  85. /******************************************************************************/
  86. /* */
  87. /* START OF USER SETTINGS HERE */
  88. /* =========================== */
  89. /* */
  90. /* All lines with '<<<' can be set by user. */
  91. /* */
  92. /******************************************************************************/
  93. /**
  94. ******************************************************************************
  95. ** \brief Clock Setup Enable
  96. ** <i>(USER SETTING)</i>
  97. **
  98. ** - 0 = No clock setup done by system_mb9xfxxx.c
  99. ** - 1 = Clock setup done by system_mb9xfxxx.c
  100. ******************************************************************************/
  101. #define CLOCK_SETUP 1 // <<< Define clock setup here
  102. /**
  103. ******************************************************************************
  104. ** \brief External Main Clock Frequency (in Hz, [value]UL)
  105. ** <i>(USER SETTING)</i>
  106. ******************************************************************************/
  107. #define __CLKMO ( 4000000UL) // <<< External 4MHz Crystal
  108. /**
  109. ******************************************************************************
  110. ** \brief External Sub Clock Frequency (in Hz, [value]UL)
  111. ** <i>(USER SETTING)</i>
  112. ******************************************************************************/
  113. #define __CLKSO ( 32768UL) // <<< External 32KHz Crystal
  114. /**
  115. ******************************************************************************
  116. ** \brief System Clock Mode Control Register value definition
  117. ** <i>(USER SETTING)</i>
  118. **
  119. ** SCM_CTL
  120. **
  121. ** Bit#7-5 : RCS[2:0]
  122. ** - 0 = Internal high-speed CR oscillation (default)
  123. ** - 1 = Main oscillation clock
  124. ** - 2 = PLL oscillation clock
  125. ** - 3 = (not allowed)
  126. ** - 4 = Internal low-speed CR oscillation
  127. ** - 5 = Sub clock oscillation
  128. ** - 6 = (not allowed)
  129. ** - 7 = (not allowed)
  130. **
  131. ** Bit#4 : PLLE
  132. ** - 0 = Disable PLL (default)
  133. ** - 1 = Enable PLL
  134. **
  135. ** Bit#3 : SOSCE
  136. ** - 0 = Disable sub oscillation (default)
  137. ** - 1 = Enable sub oscillation
  138. **
  139. ** Bit#2 : (reserved)
  140. **
  141. ** Bit#1 : MOSCE
  142. ** - 0 = Disable main oscillation (default)
  143. ** - 1 = Enable main oscillation
  144. **
  145. ** Bit#0 : (reserved)
  146. ******************************************************************************/
  147. #define SCM_CTL_Val 0x00000052 // <<< Define SCM_CTL here
  148. /**
  149. ******************************************************************************
  150. ** \brief Base Clock Prescaler Register value definition
  151. ** <i>(USER SETTING)</i>
  152. **
  153. ** BSC_PSR
  154. **
  155. ** Bit#7-3 : (reserved)
  156. **
  157. ** Bit#2-0 : BSR[2:0]
  158. ** - 0 = HCLK = Master Clock
  159. ** - 1 = HCLK = Master Clock / 2
  160. ** - 2 = HCLK = Master Clock / 3
  161. ** - 3 = HCLK = Master Clock / 4
  162. ** - 4 = HCLK = Master Clock / 6
  163. ** - 5 = HCLK = Master Clock / 8
  164. ** - 6 = HCLK = Master Clock / 16
  165. ** - 7 = (reserved)
  166. ******************************************************************************/
  167. #define BSC_PSR_Val 0x00000000 // <<< Define BSC_PSR here
  168. /**
  169. ******************************************************************************
  170. ** \brief APB0 Prescaler Register value definition
  171. ** <i>(USER SETTING)</i>
  172. **
  173. ** APBC0_PSR
  174. **
  175. ** Bit#7-2 : (reserved)
  176. **
  177. ** Bit#1-0 : BSR[2:0]
  178. ** - 0 = PCLK0 = HCLK
  179. ** - 1 = PCLK0 = HCLK / 2
  180. ** - 2 = PCLK0 = HCLK / 4
  181. ** - 3 = PCLK0 = HCLK / 8
  182. ******************************************************************************/
  183. #define APBC0_PSR_Val 0x00000001 // <<< Define APBC0_PSR here
  184. /**
  185. ******************************************************************************
  186. ** \brief APB1 Prescaler Register value definition
  187. ** <i>(USER SETTING)</i>
  188. **
  189. ** APBC1_PSR
  190. **
  191. ** Bit#7 : APBC1EN
  192. ** - 0 = Disable PCLK1 output
  193. ** - 1 = Enables PCLK1 (default)
  194. **
  195. ** Bit#6-5 : (reserved)
  196. **
  197. ** Bit#4 : APBC1RST
  198. ** - 0 = APB1 bus reset, inactive (default)
  199. ** - 1 = APB1 bus reset, active
  200. **
  201. ** Bit#3-2 : (reserved)
  202. **
  203. ** Bit#1-0 : APBC1[2:0]
  204. ** - 0 = PCLK1 = HCLK
  205. ** - 1 = PCLK1 = HCLK / 2
  206. ** - 2 = PCLK1 = HCLK / 4
  207. ** - 3 = PCLK1 = HCLK / 8
  208. ******************************************************************************/
  209. #define APBC1_PSR_Val 0x00000081 // <<< Define APBC1_PSR here
  210. /**
  211. ******************************************************************************
  212. ** \brief APB2 Prescaler Register value definition
  213. ** <i>(USER SETTING)</i>
  214. **
  215. ** APBC2_PSR
  216. **
  217. ** Bit#7 : APBC2EN
  218. ** - 0 = Disable PCLK2 output
  219. ** - 1 = Enables PCLK2 (default)
  220. **
  221. ** Bit#6-5 : (reserved)
  222. **
  223. ** Bit#4 : APBC2RST
  224. ** - 0 = APB2 bus reset, inactive (default)
  225. ** - 1 = APB2 bus reset, active
  226. **
  227. ** Bit#3-2 : (reserved)
  228. **
  229. ** Bit#1-0 : APBC2[1:0]
  230. ** - 0 = PCLK2 = HCLK
  231. ** - 1 = PCLK2 = HCLK / 2
  232. ** - 2 = PCLK2 = HCLK / 4
  233. ** - 3 = PCLK2 = HCLK / 8
  234. ******************************************************************************/
  235. #define APBC2_PSR_Val 0x00000081 // <<< Define APBC2_PSR here
  236. /**
  237. ******************************************************************************
  238. ** \brief Software Watchdog Clock Prescaler Register value definition
  239. ** <i>(USER SETTING)</i>
  240. **
  241. ** SWC_PSR
  242. **
  243. ** Bit#7 : TESTB
  244. ** - 0 = (not allowed)
  245. ** - 1 = (always write "1" to this bit)
  246. **
  247. ** Bit#6-2 : (reserved)
  248. **
  249. ** Bit#1-0 : SWDS[2:0]
  250. ** - 0 = SWDGOGCLK = PCLK0
  251. ** - 1 = SWDGOGCLK = PCLK0 / 2
  252. ** - 2 = SWDGOGCLK = PCLK0 / 4
  253. ** - 3 = SWDGOGCLK = PCLK0 / 8
  254. ******************************************************************************/
  255. #define SWC_PSR_Val 0x00000003 // <<< Define SWC_PSR here
  256. /**
  257. ******************************************************************************
  258. ** \brief Trace Clock Prescaler Register value definition
  259. ** <i>(USER SETTING)</i>
  260. **
  261. ** TTC_PSR
  262. **
  263. ** Bit#7-1 : (reserved)
  264. **
  265. ** Bit#0 : TTC
  266. ** - 0 = TPIUCLK = HCLK
  267. ** - 1 = TPIUCLK = HCLK / 2
  268. ******************************************************************************/
  269. #define TTC_PSR_Val 0x00000000 // <<< Define TTC_PSR here
  270. /**
  271. ******************************************************************************
  272. ** \brief Clock Stabilization Wait Time Register value definition
  273. ** <i>(USER SETTING)</i>
  274. **
  275. ** CSW_TMR
  276. **
  277. ** Bit#7 : (reserved)
  278. **
  279. ** Bit#6-4 : SOWT[2:0]
  280. ** - 0 = ~10.3 ms (default)
  281. ** - 1 = ~20.5 ms
  282. ** - 2 = ~41 ms
  283. ** - 3 = ~82 ms
  284. ** - 4 = ~164 ms
  285. ** - 5 = ~327 ms
  286. ** - 6 = ~655 ms
  287. ** - 7 = ~1.31 s
  288. **
  289. ** Bit#3-0 : MOWT[3:0]
  290. ** - 0 = ~500 ns (default)
  291. ** - 1 = ~8 us
  292. ** - 2 = ~16 us
  293. ** - 3 = ~32 us
  294. ** - 4 = ~64 us
  295. ** - 5 = ~128 us
  296. ** - 6 = ~256 us
  297. ** - 7 = ~512 us
  298. ** - 8 = ~1.0 ms
  299. ** - 9 = ~2.0 ms
  300. ** - 10 = ~4.0 ms
  301. ** - 11 = ~8.0 ms
  302. ** - 12 = ~33.0 ms
  303. ** - 13 = ~131 ms
  304. ** - 14 = ~524 ms
  305. ** - 15 = ~2.0 s
  306. ******************************************************************************/
  307. #define CSW_TMR_Val 0x0000005C // <<< Define CSW_TMR here
  308. /**
  309. ******************************************************************************
  310. ** \brief PLL Clock Stabilization Wait Time Setup Register value definition
  311. ** <i>(USER SETTING)</i>
  312. **
  313. ** PSW_TMR
  314. **
  315. ** Bit#7-5 : (reserved)
  316. **
  317. ** Bit#4 : PINC
  318. ** - 0 = Selects CLKMO (main oscillation) (default)
  319. ** - 1 = (setting diabled)
  320. **
  321. ** Bit#3 : (reserved)
  322. **
  323. ** Bit#2-0 : POWT[2:0]
  324. ** - 0 = ~128 us (default)
  325. ** - 1 = ~256 us
  326. ** - 2 = ~512 us
  327. ** - 3 = ~1.02 ms
  328. ** - 4 = ~2.05 ms
  329. ** - 5 = ~4.10 ms
  330. ** - 6 = ~8.20 ms
  331. ** - 7 = ~16.40 ms
  332. ******************************************************************************/
  333. #define PSW_TMR_Val 0x00000000 // <<< Define PSW_TMR here
  334. /**
  335. ******************************************************************************
  336. ** \brief PLL Control Register 1 value definition
  337. ** <i>(USER SETTING)</i>
  338. **
  339. ** PLL_CTL1
  340. **
  341. ** Bit#7-4 : PLLK[3:0]
  342. ** - 0 = Division(PLLK) = 1/1 (default)
  343. ** - 1 = Division(PLLK) = 1/2
  344. ** - 2 = Division(PLLK) = 1/3
  345. ** - . . .
  346. ** - 15 = Division(PLLK) = 1/16
  347. **
  348. ** Bit#3-0 : PLLM[3:0]
  349. ** - 0 = Division(PLLM) = 1/1 (default)
  350. ** - 1 = Division(PLLM) = 1/2
  351. ** - 2 = Division(PLLM) = 1/3
  352. ** - . . .
  353. ** - 15 = Division(PLLM) = 1/16
  354. ******************************************************************************/
  355. #define PLL_CTL1_Val 0x00000001 // <<< Define PLL_CTL1 here
  356. /**
  357. ******************************************************************************
  358. ** \brief PLL Control Register 2 value definition
  359. ** <i>(USER SETTING)</i>
  360. **
  361. ** PLL_CTL2
  362. **
  363. ** Bit#7-6 : (reserved)
  364. **
  365. ** Bit#5-0 : PLLN[5:0]
  366. ** - 0 = Division(PLLN) = 1/1 (default)
  367. ** - 1 = Division(PLLN) = 1/2
  368. ** - 2 = Division(PLLN) = 1/3
  369. ** - . . .
  370. ** - 63 = Division(PLLN) = 1/64
  371. ******************************************************************************/
  372. #define PLL_CTL2_Val 0x00000023 // <<< Define PLL_CTL2 here
  373. /**
  374. ******************************************************************************
  375. ** \brief Hardware Watchdog disable definition
  376. ** <i>(USER SETTING)</i>
  377. **
  378. ** - 0 = Hardware Watchdog enable
  379. ** - 1 = Hardware Watchdog disable
  380. ******************************************************************************/
  381. #define HWWD_DISABLE 1 // <<< Define HW Watach dog enable here
  382. /**
  383. ******************************************************************************
  384. ** \brief Trimming CR
  385. ** <i>(USER SETTING)</i>
  386. **
  387. ** - 0 = CR is not trimmed at startup
  388. ** - 1 = CR is trimmed at startup
  389. ******************************************************************************/
  390. #define CR_TRIM_SETUP 1 // <<< Define CR trimming at startup enable here
  391. /******************************************************************************/
  392. /* */
  393. /* END OF USER SETTINGS HERE */
  394. /* ========================= */
  395. /* */
  396. /******************************************************************************/
  397. /******************************************************************************/
  398. /* Device dependent System Clock absolute maximum ranges */
  399. /******************************************************************************/
  400. /**
  401. ******************************************************************************
  402. ** \brief Internal High-Speed CR Oscillator Frequency (in Hz, [value]UL)
  403. ** <i>(USER SETTING)</i>
  404. ******************************************************************************/
  405. #define __CLKHC ( 4000000UL) /* Internal 4MHz CR Oscillator */
  406. /**
  407. ******************************************************************************
  408. ** \brief Internal Low-Speed CR Oscillator Frequency (in Hz, [value]UL)
  409. ** <i>(USER SETTING)</i>
  410. ******************************************************************************/
  411. #define __CLKLC ( 100000UL) /* Internal 100KHz CR Oscillator */
  412. /**
  413. ******************************************************************************
  414. ** \brief Any case minimum Main Clock frequency (in Hz, [value]UL)
  415. ** <i>(DEVICE DEPENDENT SETTING)</i>
  416. ******************************************************************************/
  417. #define __CLKMOMIN ( 4000000UL)
  418. /**
  419. ******************************************************************************
  420. ** \brief Maximum Main Clock frequency using external clock
  421. ** <i>(DEVICE DEPENDENT SETTING)</i>
  422. ******************************************************************************/
  423. #define __CLKMOMAX ( 50000000UL)
  424. /**
  425. ******************************************************************************
  426. ** \brief Any case minimum Sub Clock frequency
  427. ** <i>(DEVICE DEPENDENT SETTING)</i>
  428. ******************************************************************************/
  429. #define __CLKSOMIN ( 32000UL)
  430. /**
  431. ******************************************************************************
  432. ** \brief Maximum Sub Clock frequency using external clock
  433. ** <i>(DEVICE DEPENDENT SETTING)</i>
  434. ******************************************************************************/
  435. #define __CLKSOMAX ( 100000UL)
  436. /**
  437. ******************************************************************************
  438. ** \brief Absolute minimum PLL input frequency
  439. ** <i>(DEVICE DEPENDENT SETTING)</i>
  440. ******************************************************************************/
  441. #define __PLLCLKINMIN ( 4000000UL)
  442. /**
  443. ******************************************************************************
  444. ** \brief Absolute maximum PLL input frequency
  445. ** <i>(DEVICE DEPENDENT SETTING)</i>
  446. ******************************************************************************/
  447. #define __PLLCLKINMAX ( 16000000UL)
  448. /**
  449. ******************************************************************************
  450. ** \brief Absolute minimum PLL oscillation frequency
  451. ** <i>(DEVICE DEPENDENT SETTING)</i>
  452. ******************************************************************************/
  453. #define __PLLCLKMIN (200000000UL)
  454. /**
  455. ******************************************************************************
  456. ** \brief Absolute maximum PLL oscillation frequency
  457. ** <i>(DEVICE DEPENDENT SETTING)</i>
  458. ******************************************************************************/
  459. #define __PLLCLKMAX (300000000UL)
  460. /**
  461. ******************************************************************************
  462. ** \brief Absolute maximum System Clock frequency (HCLK)
  463. ** <i>(DEVICE DEPENDENT SETTING)</i>
  464. ******************************************************************************/
  465. #define __HCLKMAX (144000000UL)
  466. /**
  467. ******************************************************************************
  468. ** \brief Preprocessor macro for checking range (clock settings)
  469. ******************************************************************************/
  470. #define CHECK_RANGE(val, min, max) ((val < min) || (val > max))
  471. /**
  472. ******************************************************************************
  473. ** \brief Preprocessor macro for checking bits with mask (clock settings)
  474. ******************************************************************************/
  475. #define CHECK_RSVD(val, mask) (val & mask)
  476. /******************************************************************************/
  477. /* Check register settings */
  478. /******************************************************************************/
  479. #if (CHECK_RSVD((SCM_CTL_Val), ~0x000000FA))
  480. #error "SCM_CTL: Invalid values of reserved bits!"
  481. #endif
  482. #if ((SCM_CTL_Val & 0xE0) == 0x40) && ((SCM_CTL_Val & 0x10) != 0x10)
  483. #error "SCM_CTL: CLKPLL is selected but PLL is not enabled!"
  484. #endif
  485. #if (CHECK_RSVD((CSW_TMR_Val), ~0x0000007F))
  486. #error "CSW_TMR: Invalid values of reserved bits!"
  487. #endif
  488. #if ((SCM_CTL_Val & 0x10)) /* if PLL is used */
  489. #if (CHECK_RSVD((PSW_TMR_val), ~0x00000007))
  490. #error "PSW_TMR: Invalid values of reserved bits!"
  491. #endif
  492. #if (CHECK_RSVD((PLL_CTL1_Val), ~0x000000FF))
  493. #error "PLL_CTL1: Invalid values of reserved bits!"
  494. #endif
  495. #if (CHECK_RSVD((PLL_CTL2_Val), ~0x0000003F))
  496. #error "PLL_CTL2: Invalid values of reserved bits!"
  497. #endif
  498. #endif
  499. #if (CHECK_RSVD((BSC_PSR_Val), ~0x00000007))
  500. #error "BSC_PSR: Invalid values of reserved bits!"
  501. #endif
  502. #if (CHECK_RSVD((APBC0_PSR_Val), ~0x00000003))
  503. #error "APBC0_PSR: Invalid values of reserved bits!"
  504. #endif
  505. #if (CHECK_RSVD((APBC1_PSR_Val), ~0x00000083))
  506. #error "APBC1_PSR: Invalid values of reserved bits!"
  507. #endif
  508. #if (CHECK_RSVD((APBC2_PSR_Val), ~0x00000083))
  509. #error "APBC2_PSR: Invalid values of reserved bits!"
  510. #endif
  511. #if (CHECK_RSVD((SWC_PSR_Val), ~0x00000003))
  512. #error "SWC_PSR: Invalid values of reserved bits!"
  513. #endif
  514. #if (CHECK_RSVD((TTC_PSR_Val), ~0x00000001))
  515. #error "TTC_PSR: Invalid values of reserved bits!"
  516. #endif
  517. /******************************************************************************/
  518. /* Define clocks with checking settings */
  519. /******************************************************************************/
  520. /**
  521. ******************************************************************************
  522. ** \brief Calculate PLL K factor from settings
  523. ******************************************************************************/
  524. #define __PLLK (((PLL_CTL1_Val >> 4) & 0x0F) + 1)
  525. /**
  526. ******************************************************************************
  527. ** \brief Calculate PLL N factor from settings
  528. ******************************************************************************/
  529. #define __PLLN (((PLL_CTL2_Val ) & 0x3F) + 1)
  530. /**
  531. ******************************************************************************
  532. ** \brief Calculate PLL M factor from settings
  533. ******************************************************************************/
  534. #define __PLLM (((PLL_CTL1_Val ) & 0x0F) + 1)
  535. /**
  536. ******************************************************************************
  537. ** \brief Calculate PLL output frequency from settings
  538. ******************************************************************************/
  539. #define __PLLCLK ((__CLKMO * __PLLN) / __PLLK)
  540. /******************************************************************************/
  541. /* Determine core clock frequency according to settings */
  542. /******************************************************************************/
  543. /**
  544. ******************************************************************************
  545. ** \brief Define Master Clock from settings
  546. ******************************************************************************/
  547. #if (((SCM_CTL_Val >> 5) & 0x07) == 0)
  548. #define __MASTERCLK (__CLKHC)
  549. #elif (((SCM_CTL_Val >> 5) & 0x07) == 1)
  550. #define __MASTERCLK (__CLKMO)
  551. #elif (((SCM_CTL_Val >> 5) & 0x07) == 2)
  552. #define __MASTERCLK (__PLLCLK)
  553. #elif (((SCM_CTL_Val >> 5) & 0x07) == 4)
  554. #define __MASTERCLK (__CLKLC)
  555. #elif (((SCM_CTL_Val >> 5) & 0x07) == 5)
  556. #define __MASTERCLK (__CLKSO)
  557. #else
  558. #define __MASTERCLK (0UL)
  559. #endif
  560. /**
  561. ******************************************************************************
  562. ** \brief Define System Clock Frequency (Core Clock) from settings
  563. ******************************************************************************/
  564. #if ((BSC_PSR_Val & 0x07) == 0)
  565. #define __HCLK (__MASTERCLK / 1)
  566. #elif ((BSC_PSR_Val & 0x07) == 1)
  567. #define __HCLK (__MASTERCLK / 2)
  568. #elif ((BSC_PSR_Val & 0x07) == 2)
  569. #define __HCLK (__MASTERCLK / 3)
  570. #elif ((BSC_PSR_Val & 0x07) == 3)
  571. #define __HCLK (__MASTERCLK / 4)
  572. #elif ((BSC_PSR_Val & 0x07) == 4)
  573. #define __HCLK (__MASTERCLK / 6)
  574. #elif ((BSC_PSR_Val & 0x07) == 5)
  575. #define __HCLK (__MASTERCLK / 8)
  576. #elif ((BSC_PSR_Val & 0x07) == 6)
  577. #define __HCLK (__MASTERCLK /16)
  578. #else
  579. #define __HCLK (0UL)
  580. #endif
  581. /******************************************************************************/
  582. /* HCLK range check */
  583. /******************************************************************************/
  584. #if (CHECK_RANGE(__CLKMO, __CLKMOMIN, __CLKMOMAX) != 0)
  585. #error "Main Oscillator Clock (CLKMO) out of range!"
  586. #endif
  587. #if (CHECK_RANGE(__CLKSO, __CLKSOMIN, __CLKSOMAX) != 0)
  588. #error "Sub Oscillator Clock (CLKMO) out of range!"
  589. #endif
  590. #if (CHECK_RANGE((__CLKMO / __PLLK), __PLLCLKINMIN, __PLLCLKINMAX) != 0)
  591. #error "PLL input frequency out of range!"
  592. #endif
  593. #if (CHECK_RANGE(((__CLKMO * __PLLN * __PLLM) / __PLLK), __PLLCLKMIN, __PLLCLKMAX) != 0)
  594. #error "PLL oscillation frequency out of range!"
  595. #endif
  596. #if (CHECK_RANGE(__HCLK, 0, __HCLKMAX) != 0)
  597. #error "System Clock (HCLK) out of range!"
  598. #endif
  599. /******************************************************************************/
  600. /* Global function prototypes ('extern', definition in C source) */
  601. /******************************************************************************/
  602. extern uint32_t SystemCoreClock; // System Clock Frequency (Core Clock)
  603. extern void SystemInit (void); // Initialize the system
  604. extern void SystemCoreClockUpdate (void); // Update SystemCoreClock variable
  605. #ifdef __cplusplus
  606. }
  607. #endif
  608. #endif /* __SYSTEM_MB9BF61X_H */