system_mb9bf56xr.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /*******************************************************************************
  2. * Copyright (C) 2013 Spansion LLC. All Rights Reserved.
  3. *
  4. * This software is owned and published by:
  5. * Spansion LLC, 915 DeGuigne Dr. Sunnyvale, CA 94088-3453 ("Spansion").
  6. *
  7. * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
  8. * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
  9. *
  10. * This software contains source code for use with Spansion
  11. * components. This software is licensed by Spansion to be adapted only
  12. * for use in systems utilizing Spansion components. Spansion shall not be
  13. * responsible for misuse or illegal use of this software for devices not
  14. * supported herein. Spansion is providing this software "AS IS" and will
  15. * not be responsible for issues arising from incorrect user implementation
  16. * of the software.
  17. *
  18. * SPANSION MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
  19. * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
  20. * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
  21. * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
  22. * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
  23. * WARRANTY OF NONINFRINGEMENT.
  24. * SPANSION SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
  25. * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
  26. * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
  27. * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
  28. * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
  29. * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
  30. * SAVINGS OR PROFITS,
  31. * EVEN IF SPANSION HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  32. * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
  33. * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
  34. * FROM, THE SOFTWARE.
  35. *
  36. * This software may be replicated in part or whole for the licensed use,
  37. * with the restriction that this Disclaimer and Copyright notice must be
  38. * included with each copy of this software, whether used in part or whole,
  39. * at all times.
  40. */
  41. /******************************************************************************/
  42. /** \file system_mb9bf56xr.h
  43. **
  44. ** Headerfile for FM4 system parameters
  45. **
  46. ** History:
  47. ** 2013-01-21 0.1 MWi AI: Unification to be done
  48. ** 2013-02-06 0.2 MWi CMSIS coding restored; unifying still to be done
  49. ** 2013-06-28 0.3 EH Added Trace Buffer enable definition
  50. ** 2013-08-15 0.4 EH Changed APB1 Prescaler value
  51. ******************************************************************************/
  52. #ifndef _SYSTEM_MB9ABXXX_H_
  53. #define _SYSTEM_MB9ABXXX_H_
  54. #ifdef __cplusplus
  55. extern "C" {
  56. #endif
  57. /******************************************************************************/
  58. /* Include files */
  59. /******************************************************************************/
  60. #include <stdint.h>
  61. /******************************************************************************/
  62. /* Global pre-processor symbols/macros ('define') */
  63. /******************************************************************************/
  64. /******************************************************************************/
  65. /* */
  66. /* START OF USER SETTINGS HERE */
  67. /* =========================== */
  68. /* */
  69. /* All lines with '<<<' can be set by user. */
  70. /* */
  71. /******************************************************************************/
  72. /**
  73. ******************************************************************************
  74. ** \brief Clock Setup Enable
  75. ** <i>(USER SETTING)</i>
  76. **
  77. ** - 0 = No clock setup done by system_mb9xfxxx.c
  78. ** - 1 = Clock setup done by system_mb9xfxxx.c
  79. ******************************************************************************/
  80. #define CLOCK_SETUP 1 // <<< Define clock setup here
  81. /**
  82. ******************************************************************************
  83. ** \brief External Main Clock Frequency (in Hz, [value]ul)
  84. ** <i>(USER SETTING)</i>
  85. ******************************************************************************/
  86. #define __CLKMO ( 4000000ul) // <<< External 4MHz Crystal
  87. /**
  88. ******************************************************************************
  89. ** \brief External Sub Clock Frequency (in Hz, [value]ul)
  90. ** <i>(USER SETTING)</i>
  91. ******************************************************************************/
  92. #define __CLKSO ( 32768ul) // <<< External 32KHz Crystal
  93. /**
  94. ******************************************************************************
  95. ** \brief System Clock Mode Control Register value definition
  96. ** <i>(USER SETTING)</i>
  97. **
  98. ** SCM_CTL
  99. **
  100. ** Bit#7-5 : RCS[2:0]
  101. ** - 0 = Internal high-speed CR oscillation (default)
  102. ** - 1 = Main oscillation clock
  103. ** - 2 = PLL oscillation clock
  104. ** - 3 = (not allowed)
  105. ** - 4 = Internal low-speed CR oscillation
  106. ** - 5 = Sub clock oscillation
  107. ** - 6 = (not allowed)
  108. ** - 7 = (not allowed)
  109. **
  110. ** Bit#4 : PLLE
  111. ** - 0 = Disable PLL (default)
  112. ** - 1 = Enable PLL
  113. **
  114. ** Bit#3 : SOSCE
  115. ** - 0 = Disable sub oscillation (default)
  116. ** - 1 = Enable sub oscillation
  117. **
  118. ** Bit#2 : (reserved)
  119. **
  120. ** Bit#1 : MOSCE
  121. ** - 0 = Disable main oscillation (default)
  122. ** - 1 = Enable main oscillation
  123. **
  124. ** Bit#0 : (reserved)
  125. ******************************************************************************/
  126. #define SCM_CTL_Val 0x00000052ul // <<< Define SCM_CTL here
  127. /**
  128. ******************************************************************************
  129. ** \brief Base Clock Prescaler Register value definition
  130. ** <i>(USER SETTING)</i>
  131. **
  132. ** BSC_PSR
  133. **
  134. ** Bit#7-3 : (reserved)
  135. **
  136. ** Bit#2-0 : BSR[2:0]
  137. ** - 0 = HCLK = Master Clock
  138. ** - 1 = HCLK = Master Clock / 2
  139. ** - 2 = HCLK = Master Clock / 3
  140. ** - 3 = HCLK = Master Clock / 4
  141. ** - 4 = HCLK = Master Clock / 6
  142. ** - 5 = HCLK = Master Clock / 8
  143. ** - 6 = HCLK = Master Clock / 16
  144. ** - 7 = (reserved)
  145. ******************************************************************************/
  146. #define BSC_PSR_Val 0x00000000ul // <<< Define BSC_PSR here
  147. /**
  148. ******************************************************************************
  149. ** \brief APB0 Prescaler Register value definition
  150. ** <i>(USER SETTING)</i>
  151. **
  152. ** APBC0_PSR
  153. **
  154. ** Bit#7-2 : (reserved)
  155. **
  156. ** Bit#1-0 : BSR[2:0]
  157. ** - 0 = PCLK0 = HCLK
  158. ** - 1 = PCLK0 = HCLK / 2
  159. ** - 2 = PCLK0 = HCLK / 4
  160. ** - 3 = PCLK0 = HCLK / 8
  161. ******************************************************************************/
  162. #define APBC0_PSR_Val 0x00000001UL // <<< Define APBC0_PSR here
  163. /**
  164. ******************************************************************************
  165. ** \brief APB1 Prescaler Register value definition
  166. ** <i>(USER SETTING)</i>
  167. **
  168. ** APBC1_PSR
  169. **
  170. ** Bit#7 : APBC1EN
  171. ** - 0 = Disable PCLK1 output
  172. ** - 1 = Enables PCLK1 (default)
  173. **
  174. ** Bit#6-5 : (reserved)
  175. **
  176. ** Bit#4 : APBC1RST
  177. ** - 0 = APB1 bus reset, inactive (default)
  178. ** - 1 = APB1 bus reset, active
  179. **
  180. ** Bit#3-2 : (reserved)
  181. **
  182. ** Bit#1-0 : APBC1[2:0]
  183. ** - 0 = PCLK1 = HCLK
  184. ** - 1 = PCLK1 = HCLK / 2
  185. ** - 2 = PCLK1 = HCLK / 4
  186. ** - 3 = PCLK1 = HCLK / 8
  187. ******************************************************************************/
  188. #define APBC1_PSR_Val 0x00000080ul // <<< Define APBC1_PSR here
  189. /**
  190. ******************************************************************************
  191. ** \brief APB2 Prescaler Register value definition
  192. ** <i>(USER SETTING)</i>
  193. **
  194. ** APBC2_PSR
  195. **
  196. ** Bit#7 : APBC2EN
  197. ** - 0 = Disable PCLK2 output
  198. ** - 1 = Enables PCLK2 (default)
  199. **
  200. ** Bit#6-5 : (reserved)
  201. **
  202. ** Bit#4 : APBC2RST
  203. ** - 0 = APB2 bus reset, inactive (default)
  204. ** - 1 = APB2 bus reset, active
  205. **
  206. ** Bit#3-2 : (reserved)
  207. **
  208. ** Bit#1-0 : APBC2[1:0]
  209. ** - 0 = PCLK2 = HCLK
  210. ** - 1 = PCLK2 = HCLK / 2
  211. ** - 2 = PCLK2 = HCLK / 4
  212. ** - 3 = PCLK2 = HCLK / 8
  213. ******************************************************************************/
  214. #define APBC2_PSR_Val 0x00000081ul // <<< Define APBC2_PSR here
  215. /**
  216. ******************************************************************************
  217. ** \brief Software Watchdog Clock Prescaler Register value definition
  218. ** <i>(USER SETTING)</i>
  219. **
  220. ** SWC_PSR
  221. **
  222. ** Bit#7 : TESTB
  223. ** - 0 = (not allowed)
  224. ** - 1 = (always write "1" to this bit)
  225. **
  226. ** Bit#6-2 : (reserved)
  227. **
  228. ** Bit#1-0 : SWDS[2:0]
  229. ** - 0 = SWDGOGCLK = PCLK0
  230. ** - 1 = SWDGOGCLK = PCLK0 / 2
  231. ** - 2 = SWDGOGCLK = PCLK0 / 4
  232. ** - 3 = SWDGOGCLK = PCLK0 / 8
  233. ******************************************************************************/
  234. #define SWC_PSR_Val 0x00000003ul // <<< Define SWC_PSR here
  235. /**
  236. ******************************************************************************
  237. ** \brief Trace Clock Prescaler Register value definition
  238. ** <i>(USER SETTING)</i>
  239. **
  240. ** TTC_PSR
  241. **
  242. ** Bit#7-1 : (reserved)
  243. **
  244. ** Bit#0 : TTC
  245. ** - 0 = TPIUCLK = HCLK
  246. ** - 1 = TPIUCLK = HCLK / 2
  247. ******************************************************************************/
  248. #define TTC_PSR_Val 0x00000000ul // <<< Define TTC_PSR here
  249. /**
  250. ******************************************************************************
  251. ** \brief Clock Stabilization Wait Time Register value definition
  252. ** <i>(USER SETTING)</i>
  253. **
  254. ** CSW_TMR
  255. **
  256. ** Bit#7 : (reserved)
  257. **
  258. ** Bit#6-4 : SOWT[2:0]
  259. ** - 0 = ~10.3 ms (default)
  260. ** - 1 = ~20.5 ms
  261. ** - 2 = ~41 ms
  262. ** - 3 = ~82 ms
  263. ** - 4 = ~164 ms
  264. ** - 5 = ~327 ms
  265. ** - 6 = ~655 ms
  266. ** - 7 = ~1.31 s
  267. **
  268. ** Bit#3-0 : MOWT[3:0]
  269. ** - 0 = ~500 ns (default)
  270. ** - 1 = ~8 us
  271. ** - 2 = ~16 us
  272. ** - 3 = ~32 us
  273. ** - 4 = ~64 us
  274. ** - 5 = ~128 us
  275. ** - 6 = ~256 us
  276. ** - 7 = ~512 us
  277. ** - 8 = ~1.0 ms
  278. ** - 9 = ~2.0 ms
  279. ** - 10 = ~4.0 ms
  280. ** - 11 = ~8.0 ms
  281. ** - 12 = ~33.0 ms
  282. ** - 13 = ~131 ms
  283. ** - 14 = ~524 ms
  284. ** - 15 = ~2.0 s
  285. ******************************************************************************/
  286. #define CSW_TMR_Val 0x0000005Cul // <<< Define CSW_TMR here
  287. /**
  288. ******************************************************************************
  289. ** \brief PLL Clock Stabilization Wait Time Setup Register value definition
  290. ** <i>(USER SETTING)</i>
  291. **
  292. ** PSW_TMR
  293. **
  294. ** Bit#7-5 : (reserved)
  295. **
  296. ** Bit#4 : PINC
  297. ** - 0 = Selects CLKMO (main oscillation) (default)
  298. ** - 1 = (setting diabled)
  299. **
  300. ** Bit#3 : (reserved)
  301. **
  302. ** Bit#2-0 : POWT[2:0]
  303. ** - 0 = ~128 us (default)
  304. ** - 1 = ~256 us
  305. ** - 2 = ~512 us
  306. ** - 3 = ~1.02 ms
  307. ** - 4 = ~2.05 ms
  308. ** - 5 = ~4.10 ms
  309. ** - 6 = ~8.20 ms
  310. ** - 7 = ~16.40 ms
  311. ******************************************************************************/
  312. #define PSW_TMR_Val 0x00000000ul // <<< Define PSW_TMR here
  313. /**
  314. ******************************************************************************
  315. ** \brief PLL Control Register 1 value definition
  316. ** <i>(USER SETTING)</i>
  317. **
  318. ** PLL_CTL1
  319. **
  320. ** Bit#7-4 : PLLK[3:0]
  321. ** - 0 = Division(PLLK) = 1/1 (default)
  322. ** - 1 = Division(PLLK) = 1/2
  323. ** - 2 = Division(PLLK) = 1/3
  324. ** - . . .
  325. ** - 15 = Division(PLLK) = 1/16
  326. **
  327. ** Bit#3-0 : PLLM[3:0]
  328. ** - 0 = Division(PLLM) = 1/1 (default)
  329. ** - 1 = Division(PLLM) = 1/2
  330. ** - 2 = Division(PLLM) = 1/3
  331. ** - . . .
  332. ** - 15 = Division(PLLM) = 1/16
  333. ******************************************************************************/
  334. #define PLL_CTL1_Val 0x00000001ul // <<< Define PLL_CTL1 here
  335. /**
  336. ******************************************************************************
  337. ** \brief PLL Control Register 2 value definition
  338. ** <i>(USER SETTING)</i>
  339. **
  340. ** PLL_CTL2
  341. **
  342. ** Bit#7-6 : (reserved)
  343. **
  344. ** Bit#5-0 : PLLN[5:0]
  345. ** - 0 = Division(PLLN) = 1/1 (default)
  346. ** - 1 = Division(PLLN) = 1/2
  347. ** - 2 = Division(PLLN) = 1/3
  348. ** - . . .
  349. ** - 63 = Division(PLLN) = 1/64
  350. ******************************************************************************/
  351. #define PLL_CTL2_Val 0x00000027ul // <<< Define PLL_CTL2 here
  352. /**
  353. ******************************************************************************
  354. ** \brief Hardware Watchdog disable definition
  355. ** <i>(USER SETTING)</i>
  356. **
  357. ** - 0 = Hardware Watchdog enable
  358. ** - 1 = Hardware Watchdog disable
  359. ******************************************************************************/
  360. #define HWWD_DISABLE 1 // <<< Define HW Watach dog enable here
  361. /**
  362. ******************************************************************************
  363. ** \brief Trimming CR
  364. ** <i>(USER SETTING)</i>
  365. **
  366. ** - 0 = CR is not trimmed at startup
  367. ** - 1 = CR is trimmed at startup
  368. ******************************************************************************/
  369. #define CR_TRIM_SETUP 1 // <<< Define CR trimming at startup enable here
  370. /**
  371. ******************************************************************************
  372. ** brief Trace Buffer enable definition
  373. ** <i>(USER SETTING)</i>
  374. **
  375. ** - 0 = Trace Buffer disable
  376. ** - 1 = Trace Buffer enable
  377. ******************************************************************************/
  378. #define TRACE_BUFFER_ENABLE 1 // <<< Define Trace Buffer enable here
  379. /******************************************************************************/
  380. /* */
  381. /* END OF USER SETTINGS HERE */
  382. /* ========================= */
  383. /* */
  384. /******************************************************************************/
  385. /******************************************************************************/
  386. /* Device dependent System Clock absolute maximum ranges */
  387. /******************************************************************************/
  388. /**
  389. ******************************************************************************
  390. ** \brief Internal High-Speed CR Oscillator Frequency (in Hz, [value]ul)
  391. ** <i>(USER SETTING)</i>
  392. ******************************************************************************/
  393. #define __CLKHC ( 4000000ul) /* Internal 4MHz CR Oscillator */
  394. /**
  395. ******************************************************************************
  396. ** \brief Internal Low-Speed CR Oscillator Frequency (in Hz, [value]ul)
  397. ** <i>(USER SETTING)</i>
  398. ******************************************************************************/
  399. #define __CLKLC ( 100000ul) /* Internal 100KHz CR Oscillator */
  400. /**
  401. ******************************************************************************
  402. ** \brief Any case minimum Main Clock frequency (in Hz, [value]ul)
  403. ** <i>(DEVICE DEPENDENT SETTING)</i>
  404. ******************************************************************************/
  405. #define __CLKMOMIN ( 4000000ul)
  406. /**
  407. ******************************************************************************
  408. ** \brief Maximum Main Clock frequency using external clock (in Hz, [value]ul)
  409. ** <i>(DEVICE DEPENDENT SETTING)</i>
  410. ******************************************************************************/
  411. #define __CLKMOMAX ( 48000000ul)
  412. /**
  413. ******************************************************************************
  414. ** \brief Any case minimum Sub Clock frequency (in Hz, [value]ul)
  415. ** <i>(DEVICE DEPENDENT SETTING)</i>
  416. ******************************************************************************/
  417. #define __CLKSOMIN ( 32000ul)
  418. /**
  419. ******************************************************************************
  420. ** \brief Maximum Sub Clock frequency using external clock (in Hz, [value]ul)
  421. ** <i>(DEVICE DEPENDENT SETTING)</i>
  422. ******************************************************************************/
  423. #define __CLKSOMAX ( 100000ul)
  424. /**
  425. ******************************************************************************
  426. ** \brief Absolute minimum PLL input frequency (in Hz, [value]ul)
  427. ** <i>(DEVICE DEPENDENT SETTING)</i>
  428. ******************************************************************************/
  429. #define __PLLCLKINMIN ( 4000000ul)
  430. /**
  431. ******************************************************************************
  432. ** \brief Absolute maximum PLL input frequency (in Hz, [value]ul)
  433. ** <i>(DEVICE DEPENDENT SETTING)</i>
  434. ******************************************************************************/
  435. #define __PLLCLKINMAX ( 16000000ul)
  436. /**
  437. ******************************************************************************
  438. ** \brief Absolute minimum PLL oscillation frequency (in Hz, [value]ul)
  439. ** <i>(DEVICE DEPENDENT SETTING)</i>
  440. ******************************************************************************/
  441. #define __PLLCLKMIN (200000000ul)
  442. /**
  443. ******************************************************************************
  444. ** \brief Absolute maximum PLL oscillation frequency (in Hz, [value]ul)
  445. ** <i>(DEVICE DEPENDENT SETTING)</i>
  446. ******************************************************************************/
  447. #define __PLLCLKMAX (320000000ul)
  448. /**
  449. ******************************************************************************
  450. ** \brief Absolute maximum System Clock frequency (HCLK) (in Hz, [value]ul)
  451. ** <i>(DEVICE DEPENDENT SETTING)</i>
  452. ******************************************************************************/
  453. #define __HCLKMAX (160000000ul)
  454. /**
  455. ******************************************************************************
  456. ** \brief Preprocessor macro for checking range (clock settings).
  457. **
  458. ** \return 0 Within range
  459. ** \return 1 Out of range
  460. ******************************************************************************/
  461. #define CHECK_RANGE(val, min, max) (((val) < (min)) || ((val) > (max)))
  462. /**
  463. ******************************************************************************
  464. ** \brief Preprocessor macro for checking bits with mask (clock settings).
  465. ** Prevents from setting reserved bits by mistake.
  466. **
  467. ** \return 0 All bits within mask
  468. ** \return 1 One or more bits out of mask
  469. ******************************************************************************/
  470. #define CHECK_RSVD(val, mask) ((val) & (mask))
  471. /******************************************************************************/
  472. /* Check register settings */
  473. /******************************************************************************/
  474. #if (CHECK_RSVD((SCM_CTL_Val), ~0x000000FAul))
  475. #error "SCM_CTL: Invalid values of reserved bits!"
  476. #endif
  477. #if ((SCM_CTL_Val & 0xE0ul) == 0x40ul) && ((SCM_CTL_Val & 0x10ul) != 0x10ul)
  478. #error "SCM_CTL: CLKPLL is selected but PLL is not enabled!"
  479. #endif
  480. #if (CHECK_RSVD((CSW_TMR_Val), ~0x0000007Ful))
  481. #error "CSW_TMR: Invalid values of reserved bits!"
  482. #endif
  483. #if ((SCM_CTL_Val & 0x10ul)) /* if PLL is used */
  484. #if (CHECK_RSVD((PSW_TMR_Val), ~0x00000017ul))
  485. #error "PSW_TMR: Invalid values of reserved bits!"
  486. #endif
  487. #if (CHECK_RSVD((PLL_CTL1_Val), ~0x000000FFul))
  488. #error "PLL_CTL1: Invalid values of reserved bits!"
  489. #endif
  490. #if (CHECK_RSVD((PLL_CTL2_Val), ~0x0000003Ful))
  491. #error "PLL_CTL2: Invalid values of reserved bits!"
  492. #endif
  493. #endif
  494. #if (CHECK_RSVD((BSC_PSR_Val), ~0x00000007ul))
  495. #error "BSC_PSR: Invalid values of reserved bits!"
  496. #endif
  497. #if (CHECK_RSVD((APBC0_PSR_Val), ~0x00000003ul))
  498. #error "APBC0_PSR: Invalid values of reserved bits!"
  499. #endif
  500. #if (CHECK_RSVD((APBC1_PSR_Val), ~0x00000093ul))
  501. #error "APBC1_PSR: Invalid values of reserved bits!"
  502. #endif
  503. #if (CHECK_RSVD((APBC2_PSR_Val), ~0x00000093ul))
  504. #error "APBC2_PSR: Invalid values of reserved bits!"
  505. #endif
  506. #if (CHECK_RSVD((SWC_PSR_Val), ~0x00000003ul))
  507. #error "SWC_PSR: Invalid values of reserved bits!"
  508. #endif
  509. #if (CHECK_RSVD((TTC_PSR_Val), ~0x00000003ul))
  510. #error "TTC_PSR: Invalid values of reserved bits!"
  511. #endif
  512. /******************************************************************************/
  513. /* Define clocks with checking settings */
  514. /******************************************************************************/
  515. /**
  516. ******************************************************************************
  517. ** \brief Calculate PLL K factor from settings
  518. ******************************************************************************/
  519. #define __PLLK (((PLL_CTL1_Val >> 4ul) & 0x0Ful) + 1ul)
  520. /**
  521. ******************************************************************************
  522. ** \brief Calculate PLL N factor from settings
  523. ******************************************************************************/
  524. #define __PLLN (((PLL_CTL2_Val ) & 0x3Ful) + 1ul)
  525. /**
  526. ******************************************************************************
  527. ** \brief Calculate PLL M factor from settings
  528. ******************************************************************************/
  529. #define __PLLM (((PLL_CTL1_Val ) & 0x0Ful) + 1ul)
  530. /**
  531. ******************************************************************************
  532. ** \brief Calculate PLL output frequency from settings
  533. ******************************************************************************/
  534. #define __PLLCLK ((__CLKMO * __PLLN) / __PLLK)
  535. /******************************************************************************/
  536. /* Determine core clock frequency according to settings */
  537. /******************************************************************************/
  538. /**
  539. ******************************************************************************
  540. ** \brief Define Master Clock from settings
  541. ******************************************************************************/
  542. #if (((SCM_CTL_Val >> 5ul) & 0x07UL) == 0ul)
  543. #define __MASTERCLK (__CLKHC)
  544. #elif (((SCM_CTL_Val >> 5ul) & 0x07UL) == 1ul)
  545. #define __MASTERCLK (__CLKMO)
  546. #elif (((SCM_CTL_Val >> 5ul) & 0x07UL) == 2ul)
  547. #define __MASTERCLK (__PLLCLK)
  548. #elif (((SCM_CTL_Val >> 5ul) & 0x07UL) == 4ul)
  549. #define __MASTERCLK (__CLKLC)
  550. #elif (((SCM_CTL_Val >> 5ul) & 0x07UL) == 5ul)
  551. #define __MASTERCLK (__CLKSO)
  552. #else
  553. #define __MASTERCLK (0UL)
  554. #endif
  555. /**
  556. ******************************************************************************
  557. ** \brief Define System Clock Frequency (Core Clock) from settings
  558. ******************************************************************************/
  559. #if ((BSC_PSR_Val & 0x07UL) == 0ul)
  560. #define __HCLK (__MASTERCLK / 1ul)
  561. #elif ((BSC_PSR_Val & 0x07UL) == 1ul)
  562. #define __HCLK (__MASTERCLK / 2ul)
  563. #elif ((BSC_PSR_Val & 0x07UL) == 2ul)
  564. #define __HCLK (__MASTERCLK / 3ul)
  565. #elif ((BSC_PSR_Val & 0x07UL) == 3ul)
  566. #define __HCLK (__MASTERCLK / 4ul)
  567. #elif ((BSC_PSR_Val & 0x07UL) == 4ul)
  568. #define __HCLK (__MASTERCLK / 6ul)
  569. #elif ((BSC_PSR_Val & 0x07UL) == 5ul)
  570. #define __HCLK (__MASTERCLK / 8ul)
  571. #elif ((BSC_PSR_Val & 0x07UL) == 6ul)
  572. #define __HCLK (__MASTERCLK /16ul)
  573. #else
  574. #define __HCLK (0ul)
  575. #endif
  576. /******************************************************************************/
  577. /* HCLK range check */
  578. /******************************************************************************/
  579. #if (CHECK_RANGE(__CLKMO, __CLKMOMIN, __CLKMOMAX))
  580. #error "Main Oscillator Clock (CLKMO) out of range!"
  581. #endif
  582. #if (CHECK_RANGE(__CLKSO, __CLKSOMIN, __CLKSOMAX))
  583. #error "Sub Oscillator Clock (CLKMO) out of range!"
  584. #endif
  585. #if (CHECK_RANGE((__CLKMO / __PLLK), __PLLCLKINMIN, __PLLCLKINMAX))
  586. #error "PLL input frequency out of range!"
  587. #endif
  588. #if (CHECK_RANGE(((__CLKMO * __PLLN * __PLLM) / __PLLK), __PLLCLKMIN, __PLLCLKMAX))
  589. #error "PLL oscillation frequency out of range!"
  590. #endif
  591. #if (CHECK_RANGE(__HCLK, 0UL, __HCLKMAX))
  592. #error "System Clock (HCLK) out of range!"
  593. #endif
  594. /******************************************************************************/
  595. /* Global function prototypes ('extern', definition in C source) */
  596. /******************************************************************************/
  597. extern uint32_t SystemCoreClock; // System Clock Frequency (Core Clock)
  598. extern void SystemInit (void); // Initialize the system
  599. extern void SystemCoreClockUpdate (void); // Update SystemCoreClock variable
  600. #ifdef __cplusplus
  601. }
  602. #endif
  603. #endif /* _SYSTEM_MB9ABXXX_H_ */