hal_lld.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  1. /*
  2. SPC5 HAL - Copyright (C) 2013 STMicroelectronics
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file SPC560Pxx/hal_lld.h
  15. * @brief SPC560Pxx HAL subsystem low level driver header.
  16. * @pre This module requires the following macros to be defined in the
  17. * @p board.h file:
  18. * - SPC5_XOSC_CLK.
  19. * - SPC5_OSC_BYPASS (optionally).
  20. * .
  21. *
  22. * @addtogroup HAL
  23. * @{
  24. */
  25. #ifndef HAL_LLD_H
  26. #define HAL_LLD_H
  27. #include "registers.h"
  28. #include "spc5_registry.h"
  29. /*===========================================================================*/
  30. /* Driver constants. */
  31. /*===========================================================================*/
  32. /**
  33. * @brief Defines the support for realtime counters in the HAL.
  34. */
  35. #define HAL_IMPLEMENTS_COUNTERS FALSE
  36. /**
  37. * @name Platform identification
  38. * @{
  39. */
  40. #if defined(_SPC560PXX_LARGE_) || defined(__DOXYGEN__)
  41. #define PLATFORM_NAME "SPC56APxx Chassis and Safety"
  42. #else
  43. #define PLATFORM_NAME "SPC560Pxx Chassis and Safety"
  44. #endif
  45. /** @} */
  46. /**
  47. * @name Absolute Maximum Ratings
  48. * @{
  49. */
  50. /**
  51. * @brief Maximum XOSC clock frequency.
  52. */
  53. #define SPC5_XOSC_CLK_MAX 40000000
  54. /**
  55. * @brief Minimum XOSC clock frequency.
  56. */
  57. #define SPC5_XOSC_CLK_MIN 4000000
  58. /**
  59. * @brief Maximum FMPLLs input clock frequency.
  60. */
  61. #define SPC5_FMPLLIN_MIN 4000000
  62. /**
  63. * @brief Maximum FMPLLs input clock frequency.
  64. */
  65. #define SPC5_FMPLLIN_MAX 16000000
  66. /**
  67. * @brief Maximum FMPLLs VCO clock frequency.
  68. */
  69. #define SPC5_FMPLLVCO_MAX 512000000
  70. /**
  71. * @brief Maximum FMPLLs VCO clock frequency.
  72. */
  73. #define SPC5_FMPLLVCO_MIN 256000000
  74. /**
  75. * @brief Maximum FMPLL0 output clock frequency.
  76. */
  77. #define SPC5_FMPLL0_CLK_MAX 64000000
  78. /**
  79. * @brief Maximum FMPLL1 output clock frequency.
  80. * @note FMPLL1 is not present on all devices.
  81. */
  82. #define SPC5_FMPLL1_CLK_MAX 120000000
  83. /**
  84. * @brief Maximum FMPLL1 D1 output clock frequency.
  85. * @note FMPLL1 is not present on all devices.
  86. */
  87. #define SPC5_FMPLL1_D1_CLK_MAX 80000000
  88. /** @} */
  89. /**
  90. * @name Internal clock sources
  91. * @{
  92. */
  93. #define SPC5_IRC_CLK 16000000 /**< Internal RC oscillator.*/
  94. /** @} */
  95. /**
  96. * @name FMPLL registers bits definitions
  97. * @{
  98. */
  99. #define SPC5_FMPLL_IDF_MASK (15U << 26)
  100. #define SPC5_FMPLL_IDF(n) (((n) - 1) << 26)
  101. #define SPC5_FMPLL_ODF_MASK (3U << 24)
  102. #define SPC5_FMPLL_ODF_DIV2 (0U << 24)
  103. #define SPC5_FMPLL_ODF_DIV4 (1U << 24)
  104. #define SPC5_FMPLL_ODF_DIV8 (2U << 24)
  105. #define SPC5_FMPLL_ODF_DIV16 (3U << 24)
  106. #define SPC5_FMPLL_NDIV_MASK (127U << 16)
  107. #define SPC5_FMPLL_NDIV(n) ((n) << 16)
  108. #define SPC5_FMPLL_EN_PLL_SW (1U << 8)
  109. #define SPC5_FMPLL_PLL_FAIL_MASK (1U << 2)
  110. #define SPC5_FMPLL_STRB_BYPASS (1U << 31)
  111. #define SPC5_FMPLL_SPRD_SEL (1U << 29)
  112. #define SPC5_FMPLL_MOD_PERIOD_MASK (0x1FFFU << 16)
  113. #define SPC5_FMPLL_MOD_PERIOD(n) ((n) << 16)
  114. #define SPC5_FMPLL_FM_EN (1U << 15)
  115. #define SPC5_FMPLL_INC_STEP_MASK (0x7FFFU << 0)
  116. #define SPC5_FMPLL_INC_STEP(n) ((n) << 0)
  117. /** @} */
  118. /**
  119. * @name CMU registers bits definitions
  120. * @{
  121. */
  122. #define SPC5_CMU_CSR_SFM (1U << 23)
  123. #define SPC5_CMU_CSR_RCDIV_MASK (3U << 1)
  124. #define SPC5_CMU_CSR_RCDIV(n) ((n) << 1)
  125. #define SPC5_CMU_CSR_RCDIV_NODIV (0U << 1)
  126. #define SPC5_CMU_CSR_RCDIV_DIV2 (1U << 1)
  127. #define SPC5_CMU_CSR_RCDIV_DIV4 (2U << 1)
  128. #define SPC5_CMU_CSR_RCDIV_DIV8 (3U << 1)
  129. #define SPC5_CMU_CSR_CME (1U << 0)
  130. #define SPC5_CMU_ISR_FLCI (1U << 3)
  131. #define SPC5_CMU_ISR_FHHI (1U << 2)
  132. #define SPC5_CMU_ISR_FLLI (1U << 1)
  133. #define SPC5_CMU_ISR_OLRI (1U << 0)
  134. /** @} */
  135. /**
  136. * @name Clock selectors used in the various GCM SC registers
  137. * @{
  138. */
  139. #define SPC5_CGM_SS_MASK (15U << 24)
  140. #define SPC5_CGM_SS_IRC (0U << 24)
  141. #define SPC5_CGM_SS_XOSC (2U << 24)
  142. #define SPC5_CGM_SS_FMPLL0 (4U << 24)
  143. #define SPC5_CGM_SS_FMPLL1 (5U << 24)
  144. #define SPC5_CGM_SS_FMPLL1_D1 (8U << 24)
  145. /** @} */
  146. /**
  147. * @name Clock selectors used in the CGM_OCDS_SC register
  148. * @{
  149. */
  150. #define SPC5_CGM_OCDS_SELCTL_MASK (15U << 24)
  151. #define SPC5_CGM_OCDS_SELCTL_IRC (0U << 24)
  152. #define SPC5_CGM_OCDS_SELCTL_XOSC (1U << 24)
  153. #define SPC5_CGM_OCDS_SELCTL_FMPLL0 (2U << 24)
  154. #define SPC5_CGM_OCDS_SELCTL_FMPLL1 (3U << 24)
  155. /** @} */
  156. /**
  157. * @name Clock dividers used in the CGM_OCDS_SC register
  158. * @{
  159. */
  160. #define SPC5_CGM_OCDS_SELDIV_MASK (3U << 28)
  161. #define SPC5_CGM_OCDS_SELDIV_DIV1 (0U << 28)
  162. #define SPC5_CGM_OCDS_SELDIV_DIV2 (1U << 28)
  163. #define SPC5_CGM_OCDS_SELDIV_DIV4 (2U << 28)
  164. #define SPC5_CGM_OCDS_SELDIV_DIV8 (3U << 28)
  165. /** @} */
  166. /**
  167. * @name ME_GS register bits definitions
  168. * @{
  169. */
  170. #define SPC5_ME_GS_SYSCLK_MASK (15U << 0)
  171. #define SPC5_ME_GS_SYSCLK_IRC (0U << 0)
  172. #define SPC5_ME_GS_SYSCLK_XOSC (2U << 0)
  173. #define SPC5_ME_GS_SYSCLK_FMPLL0 (4U << 0)
  174. #define SPC5_ME_GS_SYSCLK_FMPLL1 (5U << 0)
  175. /** @} */
  176. /**
  177. * @name ME_ME register bits definitions
  178. * @{
  179. */
  180. #define SPC5_ME_ME_RESET (1U << 0)
  181. #define SPC5_ME_ME_TEST (1U << 1)
  182. #define SPC5_ME_ME_SAFE (1U << 2)
  183. #define SPC5_ME_ME_DRUN (1U << 3)
  184. #define SPC5_ME_ME_RUN0 (1U << 4)
  185. #define SPC5_ME_ME_RUN1 (1U << 5)
  186. #define SPC5_ME_ME_RUN2 (1U << 6)
  187. #define SPC5_ME_ME_RUN3 (1U << 7)
  188. #define SPC5_ME_ME_HALT0 (1U << 8)
  189. #define SPC5_ME_ME_STOP0 (1U << 10)
  190. /** @} */
  191. /**
  192. * @name ME_xxx_MC registers bits definitions
  193. * @{
  194. */
  195. #define SPC5_ME_MC_SYSCLK_MASK (15U << 0)
  196. #define SPC5_ME_MC_SYSCLK(n) ((n) << 0)
  197. #define SPC5_ME_MC_SYSCLK_IRC SPC5_ME_MC_SYSCLK(0)
  198. #define SPC5_ME_MC_SYSCLK_XOSC SPC5_ME_MC_SYSCLK(2)
  199. #define SPC5_ME_MC_SYSCLK_FMPLL0 SPC5_ME_MC_SYSCLK(4)
  200. #define SPC5_ME_MC_SYSCLK_FMPLL1 SPC5_ME_MC_SYSCLK(5)
  201. #define SPC5_ME_MC_SYSCLK_DISABLED SPC5_ME_MC_SYSCLK(15)
  202. #define SPC5_ME_MC_IRCON (1U << 4)
  203. #define SPC5_ME_MC_XOSC0ON (1U << 5)
  204. #define SPC5_ME_MC_PLL0ON (1U << 6)
  205. #define SPC5_ME_MC_PLL1ON (1U << 7)
  206. #define SPC5_ME_MC_CFLAON_MASK (3U << 16)
  207. #define SPC5_ME_MC_CFLAON(n) ((n) << 16)
  208. #define SPC5_ME_MC_CFLAON_PD (1U << 16)
  209. #define SPC5_ME_MC_CFLAON_LP (2U << 16)
  210. #define SPC5_ME_MC_CFLAON_NORMAL (3U << 16)
  211. #define SPC5_ME_MC_DFLAON_MASK (3U << 18)
  212. #define SPC5_ME_MC_DFLAON(n) ((n) << 18)
  213. #define SPC5_ME_MC_DFLAON_PD (1U << 18)
  214. #define SPC5_ME_MC_DFLAON_LP (2U << 18)
  215. #define SPC5_ME_MC_DFLAON_NORMAL (3U << 18)
  216. #define SPC5_ME_MC_MVRON (1U << 20)
  217. #define SPC5_ME_MC_PDO (1U << 23)
  218. /** @} */
  219. /**
  220. * @name ME_MCTL register bits definitions
  221. * @{
  222. */
  223. #define SPC5_ME_MCTL_KEY 0x5AF0U
  224. #define SPC5_ME_MCTL_KEY_INV 0xA50FU
  225. #define SPC5_ME_MCTL_MODE_MASK (15U << 28)
  226. #define SPC5_ME_MCTL_MODE(n) ((n) << 28)
  227. /** @} */
  228. /**
  229. * @name ME_RUN_PCx registers bits definitions
  230. * @{
  231. */
  232. #define SPC5_ME_RUN_PC_TEST (1U << 1)
  233. #define SPC5_ME_RUN_PC_SAFE (1U << 2)
  234. #define SPC5_ME_RUN_PC_DRUN (1U << 3)
  235. #define SPC5_ME_RUN_PC_RUN0 (1U << 4)
  236. #define SPC5_ME_RUN_PC_RUN1 (1U << 5)
  237. #define SPC5_ME_RUN_PC_RUN2 (1U << 6)
  238. #define SPC5_ME_RUN_PC_RUN3 (1U << 7)
  239. /** @} */
  240. /**
  241. * @name ME_LP_PCx registers bits definitions
  242. * @{
  243. */
  244. #define SPC5_ME_LP_PC_HALT0 (1U << 8)
  245. #define SPC5_ME_LP_PC_STOP0 (1U << 10)
  246. /** @} */
  247. /**
  248. * @name ME_PCTL registers bits definitions
  249. * @{
  250. */
  251. #define SPC5_ME_PCTL_RUN_MASK (7U << 0)
  252. #define SPC5_ME_PCTL_RUN(n) ((n) << 0)
  253. #define SPC5_ME_PCTL_LP_MASK (7U << 3)
  254. #define SPC5_ME_PCTL_LP(n) ((n) << 3)
  255. #define SPC5_ME_PCTL_DBG (1U << 6)
  256. /** @} */
  257. /*===========================================================================*/
  258. /* Driver pre-compile time settings. */
  259. /*===========================================================================*/
  260. /**
  261. * @brief Disables the clocks initialization in the HAL.
  262. */
  263. #if !defined(SPC5_NO_INIT) || defined(__DOXYGEN__)
  264. #define SPC5_NO_INIT FALSE
  265. #endif
  266. /**
  267. * @brief Disables the overclock checks.
  268. */
  269. #if !defined(SPC5_ALLOW_OVERCLOCK) || defined(__DOXYGEN__)
  270. #define SPC5_ALLOW_OVERCLOCK FALSE
  271. #endif
  272. /**
  273. * @brief Disables the watchdog on start.
  274. */
  275. #if !defined(SPC5_DISABLE_WATCHDOG) || defined(__DOXYGEN__)
  276. #define SPC5_DISABLE_WATCHDOG TRUE
  277. #endif
  278. /**
  279. * @brief FMPLL0 IDF divider value.
  280. * @note The default value is calculated for XOSC=40MHz and PHI=64MHz.
  281. */
  282. #if !defined(SPC5_FMPLL0_IDF_VALUE) || defined(__DOXYGEN__)
  283. #define SPC5_FMPLL0_IDF_VALUE 5
  284. #endif
  285. /**
  286. * @brief FMPLL0 NDIV divider value.
  287. * @note The default value is calculated for XOSC=40MHz and PHI=64MHz.
  288. */
  289. #if !defined(SPC5_FMPLL0_NDIV_VALUE) || defined(__DOXYGEN__)
  290. #define SPC5_FMPLL0_NDIV_VALUE 32
  291. #endif
  292. /**
  293. * @brief FMPLL0 ODF divider value.
  294. * @note The default value is calculated for XOSC=40MHz and PHI=64MHz.
  295. */
  296. #if !defined(SPC5_FMPLL0_ODF) || defined(__DOXYGEN__)
  297. #define SPC5_FMPLL0_ODF SPC5_FMPLL_ODF_DIV4
  298. #endif
  299. /**
  300. * @brief FMPLL0 CR register extra options.
  301. */
  302. #if !defined(SPC5_FMPLL0_OPTIONS) || defined(__DOXYGEN__)
  303. #define SPC5_FMPLL0_OPTIONS 0
  304. #endif
  305. /**
  306. * @brief FMPLL0 MR register initialization.
  307. */
  308. #if !defined(SPC5_FMPLL0_MR_INIT) || defined(__DOXYGEN__)
  309. #define SPC5_FMPLL0_MR_INIT 0
  310. #endif
  311. /**
  312. * @brief FMPLL1 IDF divider value.
  313. * @note The default value is calculated for XOSC=40MHz and PHI=120MHz.
  314. */
  315. #if !defined(SPC5_FMPLL1_IDF_VALUE) || defined(__DOXYGEN__)
  316. #define SPC5_FMPLL1_IDF_VALUE 5
  317. #endif
  318. /**
  319. * @brief FMPLL1 NDIV divider value.
  320. * @note The default value is calculated for XOSC=40MHz and PHI=120MHz.
  321. */
  322. #if !defined(SPC5_FMPLL1_NDIV_VALUE) || defined(__DOXYGEN__)
  323. #define SPC5_FMPLL1_NDIV_VALUE 60
  324. #endif
  325. /**
  326. * @brief FMPLL1 ODF divider value.
  327. * @note The default value is calculated for XOSC=40MHz and PHI=120MHz.
  328. */
  329. #if !defined(SPC5_FMPLL1_ODF) || defined(__DOXYGEN__)
  330. #define SPC5_FMPLL1_ODF SPC5_FMPLL_ODF_DIV4
  331. #endif
  332. /**
  333. * @brief FMPLL1 CR register extra options.
  334. */
  335. #if !defined(SPC5_FMPLL1_OPTIONS) || defined(__DOXYGEN__)
  336. #define SPC5_FMPLL1_OPTIONS 0
  337. #endif
  338. /**
  339. * @brief FMPLL1 MR register initialization.
  340. */
  341. #if !defined(SPC5_FMPLL1_MR_INIT) || defined(__DOXYGEN__)
  342. #define SPC5_FMPLL1_MR_INIT 0
  343. #endif
  344. /**
  345. * @brief Clock Out clock source.
  346. */
  347. #if !defined(SPC5_CLKOUT_SRC) || defined(__DOXYGEN__)
  348. #define SPC5_CLKOUT_SRC SPC5_CGM_OCDS_SELCTL_IRC
  349. #endif
  350. /**
  351. * @brief Clock Out clock divider value.
  352. * @note Possible values are 1, 2, 4 and 8.
  353. */
  354. #if !defined(SPC5_CLKOUT_DIV_VALUE) || defined(__DOXYGEN__)
  355. #define SPC5_CLKOUT_DIV_VALUE 2
  356. #endif
  357. /**
  358. * @brief AUX0 clock source.
  359. */
  360. #if !defined(SPC5_AUX0CLK_SRC) || defined(__DOXYGEN__)
  361. #define SPC5_AUX0CLK_SRC SPC5_CGM_SS_FMPLL1
  362. #endif
  363. /**
  364. * @brief Motor Control clock divider value.
  365. * @note Zero means disabled clock.
  366. */
  367. #if !defined(SPC5_MCONTROL_DIVIDER_VALUE) || defined(__DOXYGEN__)
  368. #define SPC5_MCONTROL_DIVIDER_VALUE 2
  369. #endif
  370. /**
  371. * @brief AUX1 clock source.
  372. * @note Not configurable, always selects FMPLL1.
  373. */
  374. #if !defined(SPC5_AUX1CLK_SRC) || defined(__DOXYGEN__)
  375. #define SPC5_AUX1CLK_SRC 0
  376. #endif
  377. /**
  378. * @brief FMPLL1 clock divider value.
  379. * @note Zero means disabled clock.
  380. */
  381. #if !defined(SPC5_FMPLL1_CLK_DIVIDER_VALUE) || defined(__DOXYGEN__)
  382. #define SPC5_FMPLL1_CLK_DIVIDER_VALUE 2
  383. #endif
  384. /**
  385. * @brief AUX2 clock source.
  386. */
  387. #if !defined(SPC5_AUX2CLK_SRC) || defined(__DOXYGEN__)
  388. #define SPC5_AUX2CLK_SRC SPC5_CGM_SS_FMPLL1
  389. #endif
  390. /**
  391. * @brief SP clock divider value.
  392. * @note Zero means disabled clock.
  393. */
  394. #if !defined(SPC5_SP_CLK_DIVIDER_VALUE) || defined(__DOXYGEN__)
  395. #define SPC5_SP_CLK_DIVIDER_VALUE 2
  396. #endif
  397. /**
  398. * @brief AUX3 clock source.
  399. */
  400. #if !defined(SPC5_AUX3CLK_SRC) || defined(__DOXYGEN__)
  401. #define SPC5_AUX3CLK_SRC SPC5_CGM_SS_FMPLL1
  402. #endif
  403. /**
  404. * @brief FR clock divider value.
  405. * @note Zero means disabled clock.
  406. */
  407. #if !defined(SPC5_FR_CLK_DIVIDER_VALUE) || defined(__DOXYGEN__)
  408. #define SPC5_FR_CLK_DIVIDER_VALUE 2
  409. #endif
  410. /**
  411. * @brief CMU0 CSR register initialization.
  412. */
  413. #if !defined(SPC5_CMU0_CSR_INIT) || defined(__DOXYGEN__)
  414. #define SPC5_CMU0_CSR_INIT 0
  415. #endif
  416. /**
  417. * @brief CMU0 HFREF register initialization.
  418. */
  419. #if !defined(SPC5_CMU0_HFREFR_INIT) || defined(__DOXYGEN__)
  420. #define SPC5_CMU0_HFREFR_INIT 4095
  421. #endif
  422. /**
  423. * @brief CMU0 LFREF register initialization.
  424. */
  425. #if !defined(SPC5_CMU0_LFREFR_INIT) || defined(__DOXYGEN__)
  426. #define SPC5_CMU0_LFREFR_INIT 0
  427. #endif
  428. /**
  429. * @brief CMU0 MDR register initialization.
  430. */
  431. #if !defined(SPC5_CMU0_MDR_INIT) || defined(__DOXYGEN__)
  432. #define SPC5_CMU0_MDR_INIT 0
  433. #endif
  434. /**
  435. * @brief CMU1 CSR register initialization.
  436. */
  437. #if !defined(SPC5_CMU1_CSR_INIT) || defined(__DOXYGEN__)
  438. #define SPC5_CMU1_CSR_INIT 0
  439. #endif
  440. /**
  441. * @brief CMU1 HFREF register initialization.
  442. */
  443. #if !defined(SPC5_CMU1_HFREFR_INIT) || defined(__DOXYGEN__)
  444. #define SPC5_CMU1_HFREFR_INIT 4095
  445. #endif
  446. /**
  447. * @brief CMU1 LFREF register initialization.
  448. */
  449. #if !defined(SPC5_CMU1_LFREFR_INIT) || defined(__DOXYGEN__)
  450. #define SPC5_CMU1_LFREFR_INIT 0
  451. #endif
  452. /**
  453. * @brief Active run modes in ME_ME register.
  454. * @note Modes RESET, SAFE, DRUN, and RUN0 modes are always enabled, there
  455. * is no need to specify them.
  456. */
  457. #if !defined(SPC5_ME_ME_BITS) || defined(__DOXYGEN__)
  458. #define SPC5_ME_ME_BITS (SPC5_ME_ME_RUN1 | \
  459. SPC5_ME_ME_RUN2 | \
  460. SPC5_ME_ME_RUN3 | \
  461. SPC5_ME_ME_HALT0 | \
  462. SPC5_ME_ME_STOP0)
  463. #endif
  464. /**
  465. * @brief TEST mode settings.
  466. */
  467. #if !defined(SPC5_ME_TEST_MC_BITS) || defined(__DOXYGEN__)
  468. #define SPC5_ME_TEST_MC_BITS (SPC5_ME_MC_SYSCLK_IRC | \
  469. SPC5_ME_MC_IRCON | \
  470. SPC5_ME_MC_XOSC0ON | \
  471. SPC5_ME_MC_PLL0ON | \
  472. SPC5_ME_MC_CFLAON_NORMAL | \
  473. SPC5_ME_MC_DFLAON_NORMAL | \
  474. SPC5_ME_MC_MVRON)
  475. #endif
  476. /**
  477. * @brief SAFE mode settings.
  478. */
  479. #if !defined(SPC5_ME_SAFE_MC_BITS) || defined(__DOXYGEN__)
  480. #define SPC5_ME_SAFE_MC_BITS (SPC5_ME_MC_PDO)
  481. #endif
  482. /**
  483. * @brief DRUN mode settings.
  484. */
  485. #if !defined(SPC5_ME_DRUN_MC_BITS) || defined(__DOXYGEN__)
  486. #define SPC5_ME_DRUN_MC_BITS (SPC5_ME_MC_SYSCLK_FMPLL0 | \
  487. SPC5_ME_MC_IRCON | \
  488. SPC5_ME_MC_XOSC0ON | \
  489. SPC5_ME_MC_PLL0ON | \
  490. SPC5_ME_MC_CFLAON_NORMAL | \
  491. SPC5_ME_MC_DFLAON_NORMAL | \
  492. SPC5_ME_MC_MVRON)
  493. #endif
  494. /**
  495. * @brief RUN0 mode settings.
  496. */
  497. #if !defined(SPC5_ME_RUN0_MC_BITS) || defined(__DOXYGEN__)
  498. #define SPC5_ME_RUN0_MC_BITS (SPC5_ME_MC_SYSCLK_FMPLL0 | \
  499. SPC5_ME_MC_IRCON | \
  500. SPC5_ME_MC_XOSC0ON | \
  501. SPC5_ME_MC_PLL0ON | \
  502. SPC5_ME_MC_CFLAON_NORMAL | \
  503. SPC5_ME_MC_DFLAON_NORMAL | \
  504. SPC5_ME_MC_MVRON)
  505. #endif
  506. /**
  507. * @brief RUN1 mode settings.
  508. */
  509. #if !defined(SPC5_ME_RUN1_MC_BITS) || defined(__DOXYGEN__)
  510. #define SPC5_ME_RUN1_MC_BITS (SPC5_ME_MC_SYSCLK_FMPLL0 | \
  511. SPC5_ME_MC_IRCON | \
  512. SPC5_ME_MC_XOSC0ON | \
  513. SPC5_ME_MC_PLL0ON | \
  514. SPC5_ME_MC_CFLAON_NORMAL | \
  515. SPC5_ME_MC_DFLAON_NORMAL | \
  516. SPC5_ME_MC_MVRON)
  517. #endif
  518. /**
  519. * @brief RUN2 mode settings.
  520. */
  521. #if !defined(SPC5_ME_RUN2_MC_BITS) || defined(__DOXYGEN__)
  522. #define SPC5_ME_RUN2_MC_BITS (SPC5_ME_MC_SYSCLK_FMPLL0 | \
  523. SPC5_ME_MC_IRCON | \
  524. SPC5_ME_MC_XOSC0ON | \
  525. SPC5_ME_MC_PLL0ON | \
  526. SPC5_ME_MC_CFLAON_NORMAL | \
  527. SPC5_ME_MC_DFLAON_NORMAL | \
  528. SPC5_ME_MC_MVRON)
  529. #endif
  530. /**
  531. * @brief RUN3 mode settings.
  532. */
  533. #if !defined(SPC5_ME_RUN3_MC_BITS) || defined(__DOXYGEN__)
  534. #define SPC5_ME_RUN3_MC_BITS (SPC5_ME_MC_SYSCLK_FMPLL0 | \
  535. SPC5_ME_MC_IRCON | \
  536. SPC5_ME_MC_XOSC0ON | \
  537. SPC5_ME_MC_PLL0ON | \
  538. SPC5_ME_MC_CFLAON_NORMAL | \
  539. SPC5_ME_MC_DFLAON_NORMAL | \
  540. SPC5_ME_MC_MVRON)
  541. #endif
  542. /**
  543. * @brief HALT0 mode settings.
  544. */
  545. #if !defined(SPC5_ME_HALT0_MC_BITS) || defined(__DOXYGEN__)
  546. #define SPC5_ME_HALT0_MC_BITS (SPC5_ME_MC_SYSCLK_FMPLL0 | \
  547. SPC5_ME_MC_IRCON | \
  548. SPC5_ME_MC_XOSC0ON | \
  549. SPC5_ME_MC_PLL0ON | \
  550. SPC5_ME_MC_CFLAON_NORMAL | \
  551. SPC5_ME_MC_DFLAON_NORMAL | \
  552. SPC5_ME_MC_MVRON)
  553. #endif
  554. /**
  555. * @brief STOP0 mode settings.
  556. */
  557. #if !defined(SPC5_ME_STOP0_MC_BITS) || defined(__DOXYGEN__)
  558. #define SPC5_ME_STOP0_MC_BITS (SPC5_ME_MC_SYSCLK_FMPLL0 | \
  559. SPC5_ME_MC_IRCON | \
  560. SPC5_ME_MC_XOSC0ON | \
  561. SPC5_ME_MC_PLL0ON | \
  562. SPC5_ME_MC_CFLAON_NORMAL | \
  563. SPC5_ME_MC_DFLAON_NORMAL | \
  564. SPC5_ME_MC_MVRON)
  565. #endif
  566. /**
  567. * @brief Peripheral mode 0 (run mode).
  568. * @note Do not change this setting, it is expected to be the "never run"
  569. * mode.
  570. */
  571. #if !defined(SPC5_ME_RUN_PC0_BITS) || defined(__DOXYGEN__)
  572. #define SPC5_ME_RUN_PC0_BITS 0
  573. #endif
  574. /**
  575. * @brief Peripheral mode 1 (run mode).
  576. * @note Do not change this setting, it is expected to be the "always run"
  577. * mode.
  578. */
  579. #if !defined(SPC5_ME_RUN_PC1_BITS) || defined(__DOXYGEN__)
  580. #define SPC5_ME_RUN_PC1_BITS (SPC5_ME_RUN_PC_TEST | \
  581. SPC5_ME_RUN_PC_SAFE | \
  582. SPC5_ME_RUN_PC_DRUN | \
  583. SPC5_ME_RUN_PC_RUN0 | \
  584. SPC5_ME_RUN_PC_RUN1 | \
  585. SPC5_ME_RUN_PC_RUN2 | \
  586. SPC5_ME_RUN_PC_RUN3)
  587. #endif
  588. /**
  589. * @brief Peripheral mode 2 (run mode).
  590. * @note Do not change this setting, it is expected to be the "only during
  591. * normal run" mode.
  592. */
  593. #if !defined(SPC5_ME_RUN_PC2_BITS) || defined(__DOXYGEN__)
  594. #define SPC5_ME_RUN_PC2_BITS (SPC5_ME_RUN_PC_DRUN | \
  595. SPC5_ME_RUN_PC_RUN0 | \
  596. SPC5_ME_RUN_PC_RUN1 | \
  597. SPC5_ME_RUN_PC_RUN2 | \
  598. SPC5_ME_RUN_PC_RUN3)
  599. #endif
  600. /**
  601. * @brief Peripheral mode 3 (run mode).
  602. * @note Not defined, available to application-specific modes.
  603. */
  604. #if !defined(SPC5_ME_RUN_PC3_BITS) || defined(__DOXYGEN__)
  605. #define SPC5_ME_RUN_PC3_BITS (SPC5_ME_RUN_PC_RUN0 | \
  606. SPC5_ME_RUN_PC_RUN1 | \
  607. SPC5_ME_RUN_PC_RUN2 | \
  608. SPC5_ME_RUN_PC_RUN3)
  609. #endif
  610. /**
  611. * @brief Peripheral mode 4 (run mode).
  612. * @note Not defined, available to application-specific modes.
  613. */
  614. #if !defined(SPC5_ME_RUN_PC4_BITS) || defined(__DOXYGEN__)
  615. #define SPC5_ME_RUN_PC4_BITS (SPC5_ME_RUN_PC_RUN0 | \
  616. SPC5_ME_RUN_PC_RUN1 | \
  617. SPC5_ME_RUN_PC_RUN2 | \
  618. SPC5_ME_RUN_PC_RUN3)
  619. #endif
  620. /**
  621. * @brief Peripheral mode 5 (run mode).
  622. * @note Not defined, available to application-specific modes.
  623. */
  624. #if !defined(SPC5_ME_RUN_PC5_BITS) || defined(__DOXYGEN__)
  625. #define SPC5_ME_RUN_PC5_BITS (SPC5_ME_RUN_PC_RUN0 | \
  626. SPC5_ME_RUN_PC_RUN1 | \
  627. SPC5_ME_RUN_PC_RUN2 | \
  628. SPC5_ME_RUN_PC_RUN3)
  629. #endif
  630. /**
  631. * @brief Peripheral mode 6 (run mode).
  632. * @note Not defined, available to application-specific modes.
  633. */
  634. #if !defined(SPC5_ME_RUN_PC6_BITS) || defined(__DOXYGEN__)
  635. #define SPC5_ME_RUN_PC6_BITS (SPC5_ME_RUN_PC_RUN0 | \
  636. SPC5_ME_RUN_PC_RUN1 | \
  637. SPC5_ME_RUN_PC_RUN2 | \
  638. SPC5_ME_RUN_PC_RUN3)
  639. #endif
  640. /**
  641. * @brief Peripheral mode 7 (run mode).
  642. * @note Not defined, available to application-specific modes.
  643. */
  644. #if !defined(SPC5_ME_RUN_PC7_BITS) || defined(__DOXYGEN__)
  645. #define SPC5_ME_RUN_PC7_BITS (SPC5_ME_RUN_PC_RUN0 | \
  646. SPC5_ME_RUN_PC_RUN1 | \
  647. SPC5_ME_RUN_PC_RUN2 | \
  648. SPC5_ME_RUN_PC_RUN3)
  649. #endif
  650. /**
  651. * @brief Peripheral mode 0 (low power mode).
  652. * @note Do not change this setting, it is expected to be the "never run"
  653. * mode.
  654. */
  655. #if !defined(SPC5_ME_LP_PC0_BITS) || defined(__DOXYGEN__)
  656. #define SPC5_ME_LP_PC0_BITS 0
  657. #endif
  658. /**
  659. * @brief Peripheral mode 1 (low power mode).
  660. * @note Do not change this setting, it is expected to be the "always run"
  661. * mode.
  662. */
  663. #if !defined(SPC5_ME_LP_PC1_BITS) || defined(__DOXYGEN__)
  664. #define SPC5_ME_LP_PC1_BITS (SPC5_ME_LP_PC_HALT0 | \
  665. SPC5_ME_LP_PC_STOP0)
  666. #endif
  667. /**
  668. * @brief Peripheral mode 2 (low power mode).
  669. * @note Do not change this setting, it is expected to be the "halt only"
  670. * mode.
  671. */
  672. #if !defined(SPC5_ME_LP_PC2_BITS) || defined(__DOXYGEN__)
  673. #define SPC5_ME_LP_PC2_BITS (SPC5_ME_LP_PC_HALT0)
  674. #endif
  675. /**
  676. * @brief Peripheral mode 3 (low power mode).
  677. * @note Do not change this setting, it is expected to be the "stop only"
  678. * mode.
  679. */
  680. #if !defined(SPC5_ME_LP_PC3_BITS) || defined(__DOXYGEN__)
  681. #define SPC5_ME_LP_PC3_BITS (SPC5_ME_LP_PC_STOP0)
  682. #endif
  683. /**
  684. * @brief Peripheral mode 4 (low power mode).
  685. * @note Not defined, available to application-specific modes.
  686. */
  687. #if !defined(SPC5_ME_LP_PC4_BITS) || defined(__DOXYGEN__)
  688. #define SPC5_ME_LP_PC4_BITS (SPC5_ME_LP_PC_HALT0 | \
  689. SPC5_ME_LP_PC_STOP0)
  690. #endif
  691. /**
  692. * @brief Peripheral mode 5 (low power mode).
  693. * @note Not defined, available to application-specific modes.
  694. */
  695. #if !defined(SPC5_ME_LP_PC5_BITS) || defined(__DOXYGEN__)
  696. #define SPC5_ME_LP_PC5_BITS (SPC5_ME_LP_PC_HALT0 | \
  697. SPC5_ME_LP_PC_STOP0)
  698. #endif
  699. /**
  700. * @brief Peripheral mode 6 (low power mode).
  701. * @note Not defined, available to application-specific modes.
  702. */
  703. #if !defined(SPC5_ME_LP_PC6_BITS) || defined(__DOXYGEN__)
  704. #define SPC5_ME_LP_PC6_BITS (SPC5_ME_LP_PC_HALT0 | \
  705. SPC5_ME_LP_PC_STOP0)
  706. #endif
  707. /**
  708. * @brief Peripheral mode 7 (low power mode).
  709. * @note Not defined, available to application-specific modes.
  710. */
  711. #if !defined(SPC5_ME_LP_PC7_BITS) || defined(__DOXYGEN__)
  712. #define SPC5_ME_LP_PC7_BITS (SPC5_ME_LP_PC_HALT0 | \
  713. SPC5_ME_LP_PC_STOP0)
  714. #endif
  715. /**
  716. * @brief Final run mode after initialization.
  717. * @note It can be selected between DRUN, RUN0...RUN3.
  718. */
  719. #if !defined(SPC5_FINAL_RUNMODE) || defined(__DOXYGEN__)
  720. #define SPC5_FINAL_RUNMODE SPC5_RUNMODE_RUN0
  721. #endif
  722. /**
  723. * @brief PIT channel 0 IRQ priority.
  724. * @note This PIT channel is allocated permanently for system tick
  725. * generation.
  726. */
  727. #if !defined(SPC5_PIT0_IRQ_PRIORITY) || defined(__DOXYGEN__)
  728. #define SPC5_PIT0_IRQ_PRIORITY 4
  729. #endif
  730. /**
  731. * @brief Clock initialization failure hook.
  732. * @note The default is to stop the system and let the RTC restart it.
  733. * @note The hook code must not return.
  734. */
  735. #if !defined(SPC5_CLOCK_FAILURE_HOOK) || defined(__DOXYGEN__)
  736. #define SPC5_CLOCK_FAILURE_HOOK() osalSysHalt("clock failure")
  737. #endif
  738. /*===========================================================================*/
  739. /* Derived constants and error checks. */
  740. /*===========================================================================*/
  741. /*
  742. * Configuration-related checks.
  743. */
  744. #if !defined(SPC560Pxx_MCUCONF)
  745. #error "Using a wrong mcuconf.h file, SPC560Pxx_MCUCONF not defined"
  746. #endif
  747. /* Check on the XOSC frequency.*/
  748. #if (SPC5_XOSC_CLK < SPC5_XOSC_CLK_MIN) || \
  749. (SPC5_XOSC_CLK > SPC5_XOSC_CLK_MAX)
  750. #error "invalid SPC5_XOSC_CLK value specified"
  751. #endif
  752. /* Check on SPC5_FMPLL0_IDF_VALUE.*/
  753. #if (SPC5_FMPLL0_IDF_VALUE < 1) || (SPC5_FMPLL0_IDF_VALUE > 15)
  754. #error "invalid SPC5_FMPLL0_IDF_VALUE value specified"
  755. #endif
  756. /* Check on SPC5_FMPLL0_NDIV_VALUE.*/
  757. #if (SPC5_FMPLL0_NDIV_VALUE < 32) || (SPC5_FMPLL0_NDIV_VALUE > 96)
  758. #error "invalid SPC5_FMPLL0_NDIV_VALUE value specified"
  759. #endif
  760. /* Check on SPC5_FMPLL0_ODF.*/
  761. #if (SPC5_FMPLL0_ODF == SPC5_FMPLL_ODF_DIV2)
  762. #define SPC5_FMPLL0_ODF_VALUE 2
  763. #elif (SPC5_FMPLL0_ODF == SPC5_FMPLL_ODF_DIV4)
  764. #define SPC5_FMPLL0_ODF_VALUE 4
  765. #elif (SPC5_FMPLL0_ODF == SPC5_FMPLL_ODF_DIV8)
  766. #define SPC5_FMPLL0_ODF_VALUE 8
  767. #elif (SPC5_FMPLL0_ODF == SPC5_FMPLL_ODF_DIV16)
  768. #define SPC5_FMPLL0_ODF_VALUE 16
  769. #else
  770. #error "invalid SPC5_FMPLL0_ODF value specified"
  771. #endif
  772. /**
  773. * @brief SPC5_FMPLL0_VCO_CLK clock point.
  774. */
  775. #define SPC5_FMPLL0_VCO_CLK \
  776. ((SPC5_XOSC_CLK / SPC5_FMPLL0_IDF_VALUE) * SPC5_FMPLL0_NDIV_VALUE)
  777. /* Check on FMPLL0 VCO output.*/
  778. #if (SPC5_FMPLL0_VCO_CLK < SPC5_FMPLLVCO_MIN) || \
  779. (SPC5_FMPLL0_VCO_CLK > SPC5_FMPLLVCO_MAX)
  780. #error "SPC5_FMPLL0_VCO_CLK outside acceptable range (SPC5_FMPLLVCO_MIN...SPC5_FMPLLVCO_MAX)"
  781. #endif
  782. /**
  783. * @brief SPC5_FMPLL0_CLK clock point.
  784. */
  785. #define SPC5_FMPLL0_CLK \
  786. (SPC5_FMPLL0_VCO_CLK / SPC5_FMPLL0_ODF_VALUE)
  787. /* Check on SPC5_FMPLL0_CLK.*/
  788. #if (SPC5_FMPLL0_CLK > SPC5_FMPLL0_CLK_MAX) && !SPC5_ALLOW_OVERCLOCK
  789. #error "SPC5_FMPLL0_CLK outside acceptable range (0...SPC5_FMPLL0_CLK_MAX)"
  790. #endif
  791. #if SPC5_HAS_FMPLL1
  792. /* Check on SPC5_FMPLL1_IDF_VALUE.*/
  793. #if (SPC5_FMPLL1_IDF_VALUE < 1) || (SPC5_FMPLL1_IDF_VALUE > 15)
  794. #error "invalid SPC5_FMPLL1_IDF_VALUE value specified"
  795. #endif
  796. /* Check on SPC5_FMPLL1_NDIV_VALUE.*/
  797. #if (SPC5_FMPLL1_NDIV_VALUE < 32) || (SPC5_FMPLL1_NDIV_VALUE > 96)
  798. #error "invalid SPC5_FMPLL1_NDIV_VALUE value specified"
  799. #endif
  800. /* Check on SPC5_FMPLL1_ODF.*/
  801. #if (SPC5_FMPLL1_ODF == SPC5_FMPLL_ODF_DIV2)
  802. #define SPC5_FMPLL1_ODF_VALUE 2
  803. #elif (SPC5_FMPLL1_ODF == SPC5_FMPLL_ODF_DIV4)
  804. #define SPC5_FMPLL1_ODF_VALUE 4
  805. #elif (SPC5_FMPLL1_ODF == SPC5_FMPLL_ODF_DIV8)
  806. #define SPC5_FMPLL1_ODF_VALUE 8
  807. #elif (SPC5_FMPLL1_ODF == SPC5_FMPLL_ODF_DIV16)
  808. #define SPC5_FMPLL1_ODF_VALUE 16
  809. #else
  810. #error "invalid SPC5_FMPLL1_ODF value specified"
  811. #endif
  812. /**
  813. * @brief SPC5_FMPLL1_VCO_CLK clock point.
  814. */
  815. #define SPC5_FMPLL1_VCO_CLK \
  816. ((SPC5_XOSC_CLK / SPC5_FMPLL1_IDF_VALUE) * SPC5_FMPLL1_NDIV_VALUE)
  817. /* Check on FMPLL1 VCO output.*/
  818. #if (SPC5_FMPLL1_VCO_CLK < SPC5_FMPLLVCO_MIN) || \
  819. (SPC5_FMPLL1_VCO_CLK > SPC5_FMPLLVCO_MAX)
  820. #error "SPC5_FMPLL1_VCO_CLK outside acceptable range (SPC5_FMPLLVCO_MIN...SPC5_FMPLLVCO_MAX)"
  821. #endif
  822. /**
  823. * @brief SPC5_FMPLL1_CLK clock point.
  824. */
  825. #define SPC5_FMPLL1_CLK \
  826. (SPC5_FMPLL1_VCO_CLK / SPC5_FMPLL1_ODF_VALUE)
  827. /* Check on SPC5_FMPLL1_CLK.*/
  828. #if (SPC5_FMPLL1_CLK > SPC5_FMPLL1_CLK_MAX) && !SPC5_ALLOW_OVERCLOCK
  829. #error "SPC5_FMPLL1_CLK outside acceptable range (0...SPC5_FMPLL1_CLK_MAX)"
  830. #endif
  831. /**
  832. * @brief SPC5_FMPLL1_D1_CLK clock point.
  833. */
  834. #define SPC5_FMPLL1_D1_CLK \
  835. (SPC5_FMPLL1_VCO_CLK / 6)
  836. /* Check on SPC5_FMPLL1_D1_CLK.*/
  837. #if (SPC5_FMPLL1_D1_CLK > SPC5_FMPLL1_D1_CLK_MAX) && !SPC5_ALLOW_OVERCLOCK
  838. #error "SPC5_FMPLL1_CLK outside acceptable range (0...SPC5_FMPLL1_D1_CLK_MAX)"
  839. #endif
  840. #endif /* SPC5_HAS_FMPLL1 */
  841. /**
  842. * @brief CLKOUT clock point.
  843. */
  844. #if (SPC5_CLKOUT_SRC == SPC5_CGM_OCDS_SELCTL_IRC) || defined(__DOXYGEN__)
  845. #define SPC5_CLKOUT_CLK SPC5_IRC_CLK
  846. #elif SPC5_CLKOUT_SRC == SPC5_CGM_OCDS_SELCTL_XOSC
  847. #define SPC5_CLKOUT_CLK SPC5_XOSC_CLK
  848. #elif SPC5_CLKOUT_SRC == SPC5_CGM_OCDS_SELCTL_FMPLL0
  849. #define SPC5_CLKOUT_CLK SPC5_FMPLL0_CLK
  850. #elif SPC5_CLKOUT_SRC == SPC5_CGM_OCDS_SELCTL_FMPLL1
  851. #define SPC5_CLKOUT_CLK SPC5_FMPLL1_CLK
  852. #else
  853. #error "invalid SPC5_CLKOUT_SRC value specified"
  854. #endif
  855. /* Check on the CLKOUT divider settings.*/
  856. #if SPC5_CLKOUT_DIV_VALUE == 1
  857. #define SPC5_CGM_OCDS_SELDIV SPC5_CGM_OCDS_SELDIV_DIV1
  858. #elif SPC5_CLKOUT_DIV_VALUE == 2
  859. #define SPC5_CGM_OCDS_SELDIV SPC5_CGM_OCDS_SELDIV_DIV2
  860. #elif SPC5_CLKOUT_DIV_VALUE == 4
  861. #define SPC5_CGM_OCDS_SELDIV SPC5_CGM_OCDS_SELDIV_DIV4
  862. #elif SPC5_CLKOUT_DIV_VALUE == 8
  863. #define SPC5_CGM_OCDS_SELDIV SPC5_CGM_OCDS_SELDIV_DIV8
  864. #else
  865. #error "invalid SPC5_CLKOUT_DIV_VALUE value specified"
  866. #endif
  867. #if SPC5_HAS_AC0 || defined(__DOXYGEN__)
  868. /**
  869. * @brief AUX0 clock point.
  870. */
  871. #if (SPC5_AUX0CLK_SRC == SPC5_CGM_SS_IRC) || defined(__DOXYGEN__)
  872. #define SPC5_AUX0_CLK SPC5_IRC_CLK
  873. #elif SPC5_AUX0CLK_SRC == SPC5_CGM_SS_XOSC
  874. #define SPC5_AUX0_CLK SPC5_XOSC_CLK
  875. #elif SPC5_AUX0CLK_SRC == SPC5_CGM_SS_FMPLL0
  876. #define SPC5_AUX0_CLK SPC5_FMPLL0_CLK
  877. #elif SPC5_AUX0CLK_SRC == SPC5_CGM_SS_FMPLL1
  878. #define SPC5_AUX0_CLK SPC5_FMPLL1_CLK
  879. #else
  880. #error "invalid SPC5_AUX0CLK_SRC value specified"
  881. #endif
  882. #if !SPC5_HAS_FMPLL1 && (SPC5_AUX0CLK_SRC == SPC5_CGM_SS_FMPLL1)
  883. #error "SPC5_AUX0CLK_SRC, FMPLL1 not present"
  884. #endif
  885. /* Check on the AUX0 divider 0 settings.*/
  886. #if SPC5_MCONTROL_DIVIDER_VALUE == 0
  887. #define SPC5_CGM_AC0_DC0 0
  888. #elif (SPC5_MCONTROL_DIVIDER_VALUE >= 1) && (SPC5_MCONTROL_DIVIDER_VALUE <= 16)
  889. #define SPC5_CGM_AC0_DC0 ((0x80U | (SPC5_MCONTROL_DIVIDER_VALUE - 1)) << 24)
  890. #else
  891. #error "invalid SPC5_MCONTROL_DIVIDER_VALUE value specified"
  892. #endif
  893. /**
  894. * @brief Motor Control clock point.
  895. */
  896. #if (SPC5_MCONTROL_DIVIDER_VALUE) != 0 || defined(__DOXYGEN)
  897. #define SPC5_MCONTROL_CLK (SPC5_AUX0_CLK / SPC5_MCONTROL_DIVIDER_VALUE)
  898. #else
  899. #define SPC5_MCONTROL_CLK 0
  900. #endif
  901. #endif /* #if SPC5_HAS_AC0 */
  902. #if SPC5_HAS_AC1 || defined(__DOXYGEN__)
  903. /**
  904. * @brief AUX1 clock point.
  905. */
  906. #if (SPC5_AUX1CLK_SRC == 0) || defined(__DOXYGEN__)
  907. #define SPC5_AUX1_CLK SPC5_FMPLL1_CLK
  908. #else
  909. #error "invalid SPC5_AUX1CLK_SRC value specified"
  910. #endif
  911. #if !SPC5_HAS_FMPLL1
  912. #error "SPC5_AUX1_CLK, FMPLL1 not present"
  913. #endif
  914. /* Check on the AUX1 divider 0 settings.*/
  915. #if SPC5_FMPLL1_CLK_DIVIDER_VALUE == 0
  916. #define SPC5_CGM_AC1_DC0 0
  917. #elif (SPC5_FMPLL1_CLK_DIVIDER_VALUE >= 1) && (SPC5_FMPLL1_CLK_DIVIDER_VALUE <= 16)
  918. #define SPC5_CGM_AC1_DC0 ((0x80U | (SPC5_FMPLL1_CLK_DIVIDER_VALUE - 1)) << 24)
  919. #else
  920. #error "invalid SPC5_FMPLL1_CLK_DIVIDER_VALUE value specified"
  921. #endif
  922. /**
  923. * @brief FMPLL1 clock point.
  924. */
  925. #if (SPC5_MCONTROL_DIVIDER_VALUE) != 0 || defined(__DOXYGEN)
  926. #define SPC5_FMPLL1_DIV_CLK (SPC5_AUX1_CLK / SPC5_FMPLL1_CLK_DIVIDER_VALUE)
  927. #else
  928. #define SPC5_FMPLL1_DIV_CLK 0
  929. #endif
  930. #endif /* SPC5_HAS_AC1 */
  931. #if SPC5_HAS_AC2 || defined(__DOXYGEN__)
  932. /**
  933. * @brief AUX2 clock point.
  934. */
  935. #if (SPC5_AUX2CLK_SRC == SPC5_CGM_SS_IRC) || defined(__DOXYGEN__)
  936. #define SPC5_AUX2_CLK SPC5_IRC_CLK
  937. #elif SPC5_AUX2CLK_SRC == SPC5_CGM_SS_XOSC
  938. #define SPC5_AUX2_CLK SPC5_XOSC_CLK
  939. #elif SPC5_AUX2CLK_SRC == SPC5_CGM_SS_FMPLL0
  940. #define SPC5_AUX2_CLK SPC5_FMPLL0_CLK
  941. #elif SPC5_AUX2CLK_SRC == SPC5_CGM_SS_FMPLL1
  942. #define SPC5_AUX2_CLK SPC5_FMPLL1_CLK
  943. #elif SPC5_AUX2CLK_SRC == SPC5_CGM_SS_FMPLL1_D1
  944. #define SPC5_AUX2_CLK SPC5_FMPLL1_D1_CLK
  945. #else
  946. #error "invalid SPC5_AUX2CLK_SRC value specified"
  947. #endif
  948. #if !SPC5_HAS_FMPLL1 && ((SPC5_AUX2CLK_SRC == SPC5_CGM_SS_FMPLL1) || \
  949. (SPC5_AUX2CLK_SRC == SPC5_CGM_SS_FMPLL1_D1))
  950. #error "SPC5_AUX2_CLK, FMPLL1 not present"
  951. #endif
  952. /* Check on the AUX2 divider 0 settings.*/
  953. #if SPC5_SP_CLK_DIVIDER_VALUE == 0
  954. #define SPC5_CGM_AC2_DC0 0
  955. #elif (SPC5_SP_CLK_DIVIDER_VALUE >= 1) && (SPC5_SP_CLK_DIVIDER_VALUE <= 16)
  956. #define SPC5_CGM_AC2_DC0 ((0x80U | (SPC5_SP_CLK_DIVIDER_VALUE - 1)) << 24)
  957. #else
  958. #error "invalid SPC5_SP_CLK_DIVIDER_VALUE value specified"
  959. #endif
  960. /**
  961. * @brief SP clock point.
  962. */
  963. #if (SPC5_SP_CLK_DIVIDER_VALUE) != 0 || defined(__DOXYGEN)
  964. #define SPC5_SP_CLK (SPC5_AUX2_CLK / SPC5_SP_CLK_DIVIDER_VALUE)
  965. #else
  966. #define SPC5_SP_CLK 0
  967. #endif
  968. #endif /* SPC5_HAS_AC2 */
  969. #if SPC5_HAS_AC3 || defined(__DOXYGEN__)
  970. /**
  971. * @brief AUX3 clock point.
  972. */
  973. #if (SPC5_AUX3CLK_SRC == SPC5_CGM_SS_IRC) || defined(__DOXYGEN__)
  974. #define SPC5_AUX3_CLK SPC5_IRC_CLK
  975. #elif SPC5_AUX3CLK_SRC == SPC5_CGM_SS_XOSC
  976. #define SPC5_AUX3_CLK SPC5_XOSC_CLK
  977. #elif SPC5_AUX3CLK_SRC == SPC5_CGM_SS_FMPLL0
  978. #define SPC5_AUX3_CLK SPC5_FMPLL0_CLK
  979. #elif SPC5_AUX3CLK_SRC == SPC5_CGM_SS_FMPLL1
  980. #define SPC5_AUX3_CLK SPC5_FMPLL1_CLK
  981. #elif SPC5_AUX3CLK_SRC == SPC5_CGM_SS_FMPLL1_D1
  982. #define SPC5_AUX3_CLK SPC5_FMPLL1_D1_CLK
  983. #else
  984. #error "invalid SPC5_AUX3CLK_SRC value specified"
  985. #endif
  986. #if !SPC5_HAS_FMPLL1 && ((SPC5_AUX2_CLK == SPC5_AUX3_CLK) || \
  987. (SPC5_AUX3CLK_SRC == SPC5_CGM_SS_FMPLL1_D1))
  988. #error "SPC5_AUX3_CLK, FMPLL1 not present"
  989. #endif
  990. /* Check on the AUX3 divider 0 settings.*/
  991. #if SPC5_FR_CLK_DIVIDER_VALUE == 0
  992. #define SPC5_CGM_AC3_DC0 0
  993. #elif (SPC5_FR_CLK_DIVIDER_VALUE >= 1) && (SPC5_FR_CLK_DIVIDER_VALUE <= 16)
  994. #define SPC5_CGM_AC3_DC0 ((0x80U | (SPC5_FR_CLK_DIVIDER_VALUE - 1)) << 24)
  995. #else
  996. #error "invalid SPC5_FR_CLK_DIVIDER_VALUE value specified"
  997. #endif
  998. /**
  999. * @brief FR clock point.
  1000. */
  1001. #if (SPC5_FR_CLK_DIVIDER_VALUE) != 0 || defined(__DOXYGEN)
  1002. #define SPC5_FR_CLK (SPC5_AUX3_CLK / SPC5_FR_CLK_DIVIDER_VALUE)
  1003. #else
  1004. #define SPC5_FR_CLK 0
  1005. #endif
  1006. #endif /* SPC5_HAS_AC3 */
  1007. /*===========================================================================*/
  1008. /* Driver data structures and types. */
  1009. /*===========================================================================*/
  1010. typedef enum {
  1011. SPC5_RUNMODE_TEST = 1,
  1012. SPC5_RUNMODE_SAFE = 2,
  1013. SPC5_RUNMODE_DRUN = 3,
  1014. SPC5_RUNMODE_RUN0 = 4,
  1015. SPC5_RUNMODE_RUN1 = 5,
  1016. SPC5_RUNMODE_RUN2 = 6,
  1017. SPC5_RUNMODE_RUN3 = 7,
  1018. SPC5_RUNMODE_HALT0 = 8,
  1019. SPC5_RUNMODE_STOP0 = 10
  1020. } spc5_runmode_t;
  1021. /*===========================================================================*/
  1022. /* Driver macros. */
  1023. /*===========================================================================*/
  1024. /*===========================================================================*/
  1025. /* External declarations. */
  1026. /*===========================================================================*/
  1027. #include "spc5_edma.h"
  1028. #ifdef __cplusplus
  1029. extern "C" {
  1030. #endif
  1031. void hal_lld_init(void);
  1032. void spc_clock_init(void);
  1033. bool halSPCSetRunMode(spc5_runmode_t mode);
  1034. void halSPCSetPeripheralClockMode(uint32_t n, uint32_t pctl);
  1035. #if !SPC5_NO_INIT
  1036. uint32_t halSPCGetSystemClock(void);
  1037. #endif
  1038. #ifdef __cplusplus
  1039. }
  1040. #endif
  1041. #endif /* HAL_LLD_H */
  1042. /** @} */