hal_lld.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  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 SPC560Dxx/hal_lld.h
  15. * @brief SPC560Dxx 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. #define PLATFORM_NAME "SPC560Dxx Car Body and Convenience"
  41. /** @} */
  42. /**
  43. * @name Absolute Maximum Ratings
  44. * @{
  45. */
  46. /**
  47. * @brief Maximum XOSC clock frequency.
  48. */
  49. #define SPC5_XOSC_CLK_MAX 16000000
  50. /**
  51. * @brief Minimum XOSC clock frequency.
  52. */
  53. #define SPC5_XOSC_CLK_MIN 4000000
  54. /**
  55. * @brief Maximum FMPLLs input clock frequency.
  56. */
  57. #define SPC5_FMPLLIN_MIN 4000000
  58. /**
  59. * @brief Maximum FMPLLs input clock frequency.
  60. */
  61. #define SPC5_FMPLLIN_MAX 48000000
  62. /**
  63. * @brief Maximum FMPLLs VCO clock frequency.
  64. */
  65. #define SPC5_FMPLLVCO_MAX 512000000
  66. /**
  67. * @brief Maximum FMPLLs VCO clock frequency.
  68. */
  69. #define SPC5_FMPLLVCO_MIN 256000000
  70. /**
  71. * @brief Maximum FMPLL0 output clock frequency.
  72. */
  73. #define SPC5_FMPLL0_CLK_MAX 48000000
  74. /** @} */
  75. /**
  76. * @name Internal clock sources
  77. * @{
  78. */
  79. #define SPC5_IRC_CLK 16000000 /**< Internal fast RC
  80. oscillator. */
  81. #define SPC5_SIRC_CLK 128000 /**< Internal RC slow
  82. oscillator. */
  83. /** @} */
  84. /**
  85. * @name FMPLL_CR register bits definitions
  86. * @{
  87. */
  88. #define SPC5_FMPLL_ODF_DIV2 (0U << 24)
  89. #define SPC5_FMPLL_ODF_DIV4 (1U << 24)
  90. #define SPC5_FMPLL_ODF_DIV8 (2U << 24)
  91. #define SPC5_FMPLL_ODF_DIV16 (3U << 24)
  92. /** @} */
  93. /**
  94. * @name ME_GS register bits definitions
  95. * @{
  96. */
  97. #define SPC5_ME_GS_SYSCLK_MASK (15U << 0)
  98. #define SPC5_ME_GS_SYSCLK_IRC (0U << 0)
  99. #define SPC5_ME_GS_SYSCLK_DIVIRC (1U << 0)
  100. #define SPC5_ME_GS_SYSCLK_XOSC (2U << 0)
  101. #define SPC5_ME_GS_SYSCLK_DIVXOSC (3U << 0)
  102. #define SPC5_ME_GS_SYSCLK_FMPLL0 (4U << 0)
  103. /** @} */
  104. /**
  105. * @name ME_ME register bits definitions
  106. * @{
  107. */
  108. #define SPC5_ME_ME_RESET (1U << 0)
  109. #define SPC5_ME_ME_TEST (1U << 1)
  110. #define SPC5_ME_ME_SAFE (1U << 2)
  111. #define SPC5_ME_ME_DRUN (1U << 3)
  112. #define SPC5_ME_ME_RUN0 (1U << 4)
  113. #define SPC5_ME_ME_RUN1 (1U << 5)
  114. #define SPC5_ME_ME_RUN2 (1U << 6)
  115. #define SPC5_ME_ME_RUN3 (1U << 7)
  116. #define SPC5_ME_ME_HALT0 (1U << 8)
  117. #define SPC5_ME_ME_STOP0 (1U << 10)
  118. #define SPC5_ME_ME_STANDBY0 (1U << 13)
  119. /** @} */
  120. /**
  121. * @name ME_xxx_MC registers bits definitions
  122. * @{
  123. */
  124. #define SPC5_ME_MC_SYSCLK_MASK (15U << 0)
  125. #define SPC5_ME_MC_SYSCLK(n) ((n) << 0)
  126. #define SPC5_ME_MC_SYSCLK_IRC SPC5_ME_MC_SYSCLK(0)
  127. #define SPC5_ME_MC_SYSCLK_DIVIRC SPC5_ME_MC_SYSCLK(1)
  128. #define SPC5_ME_MC_SYSCLK_XOSC SPC5_ME_MC_SYSCLK(2)
  129. #define SPC5_ME_MC_SYSCLK_DIVXOSC SPC5_ME_MC_SYSCLK(3)
  130. #define SPC5_ME_MC_SYSCLK_FMPLL0 SPC5_ME_MC_SYSCLK(4)
  131. #define SPC5_ME_MC_SYSCLK_DISABLED SPC5_ME_MC_SYSCLK(15)
  132. #define SPC5_ME_MC_IRCON (1U << 4)
  133. #define SPC5_ME_MC_XOSC0ON (1U << 5)
  134. #define SPC5_ME_MC_PLL0ON (1U << 6)
  135. #define SPC5_ME_MC_CFLAON_MASK (3U << 16)
  136. #define SPC5_ME_MC_CFLAON(n) ((n) << 16)
  137. #define SPC5_ME_MC_CFLAON_PD (1U << 16)
  138. #define SPC5_ME_MC_CFLAON_LP (2U << 16)
  139. #define SPC5_ME_MC_CFLAON_NORMAL (3U << 16)
  140. #define SPC5_ME_MC_DFLAON_MASK (3U << 18)
  141. #define SPC5_ME_MC_DFLAON(n) ((n) << 18)
  142. #define SPC5_ME_MC_DFLAON_PD (1U << 18)
  143. #define SPC5_ME_MC_DFLAON_LP (2U << 18)
  144. #define SPC5_ME_MC_DFLAON_NORMAL (3U << 18)
  145. #define SPC5_ME_MC_MVRON (1U << 20)
  146. #define SPC5_ME_MC_PDO (1U << 23)
  147. /** @} */
  148. /**
  149. * @name ME_MCTL register bits definitions
  150. * @{
  151. */
  152. #define SPC5_ME_MCTL_KEY 0x5AF0U
  153. #define SPC5_ME_MCTL_KEY_INV 0xA50FU
  154. #define SPC5_ME_MCTL_MODE_MASK (15U << 28)
  155. #define SPC5_ME_MCTL_MODE(n) ((n) << 28)
  156. /** @} */
  157. /**
  158. * @name ME_RUN_PCx registers bits definitions
  159. * @{
  160. */
  161. #define SPC5_ME_RUN_PC_TEST (1U << 1)
  162. #define SPC5_ME_RUN_PC_SAFE (1U << 2)
  163. #define SPC5_ME_RUN_PC_DRUN (1U << 3)
  164. #define SPC5_ME_RUN_PC_RUN0 (1U << 4)
  165. #define SPC5_ME_RUN_PC_RUN1 (1U << 5)
  166. #define SPC5_ME_RUN_PC_RUN2 (1U << 6)
  167. #define SPC5_ME_RUN_PC_RUN3 (1U << 7)
  168. /** @} */
  169. /**
  170. * @name ME_LP_PCx registers bits definitions
  171. * @{
  172. */
  173. #define SPC5_ME_LP_PC_HALT0 (1U << 8)
  174. #define SPC5_ME_LP_PC_STOP0 (1U << 10)
  175. #define SPC5_ME_LP_PC_STANDBY0 (1U << 13)
  176. /** @} */
  177. /**
  178. * @name ME_PCTL registers bits definitions
  179. * @{
  180. */
  181. #define SPC5_ME_PCTL_RUN_MASK (7U << 0)
  182. #define SPC5_ME_PCTL_RUN(n) ((n) << 0)
  183. #define SPC5_ME_PCTL_LP_MASK (7U << 3)
  184. #define SPC5_ME_PCTL_LP(n) ((n) << 3)
  185. #define SPC5_ME_PCTL_DBG (1U << 6)
  186. /** @} */
  187. /*===========================================================================*/
  188. /* Driver pre-compile time settings. */
  189. /*===========================================================================*/
  190. /**
  191. * @brief Disables the clocks initialization in the HAL.
  192. */
  193. #if !defined(SPC5_NO_INIT) || defined(__DOXYGEN__)
  194. #define SPC5_NO_INIT FALSE
  195. #endif
  196. /**
  197. * @brief Disables the overclock checks.
  198. */
  199. #if !defined(SPC5_ALLOW_OVERCLOCK) || defined(__DOXYGEN__)
  200. #define SPC5_ALLOW_OVERCLOCK FALSE
  201. #endif
  202. /**
  203. * @brief Disables the watchdog on start.
  204. */
  205. #if !defined(SPC5_DISABLE_WATCHDOG) || defined(__DOXYGEN__)
  206. #define SPC5_DISABLE_WATCHDOG TRUE
  207. #endif
  208. /**
  209. * @brief FMPLL0 IDF divider value.
  210. * @note The default value is calculated for XOSC=8MHz and PHI=48MHz.
  211. */
  212. #if !defined(SPC5_FMPLL0_IDF_VALUE) || defined(__DOXYGEN__)
  213. #define SPC5_FMPLL0_IDF_VALUE 1
  214. #endif
  215. /**
  216. * @brief FMPLL0 NDIV divider value.
  217. * @note The default value is calculated for XOSC=8MHz and PHI=48MHz.
  218. */
  219. #if !defined(SPC5_FMPLL0_NDIV_VALUE) || defined(__DOXYGEN__)
  220. #define SPC5_FMPLL0_NDIV_VALUE 48
  221. #endif
  222. /**
  223. * @brief FMPLL0 ODF divider value.
  224. * @note The default value is calculated for XOSC=8MHz and PHI=48MHz.
  225. */
  226. #if !defined(SPC5_FMPLL0_ODF) || defined(__DOXYGEN__)
  227. #define SPC5_FMPLL0_ODF SPC5_FMPLL_ODF_DIV8
  228. #endif
  229. /**
  230. * @brief XOSC divider value.
  231. * @note The allowed range is 1...32.
  232. */
  233. #if !defined(SPC5_XOSCDIV_VALUE) || defined(__DOXYGEN__)
  234. #define SPC5_XOSCDIV_VALUE 1
  235. #endif
  236. /**
  237. * @brief Fast IRC divider value.
  238. * @note The allowed range is 1...32.
  239. */
  240. #if !defined(SPC5_IRCDIV_VALUE) || defined(__DOXYGEN__)
  241. #define SPC5_IRCDIV_VALUE 1
  242. #endif
  243. /**
  244. * @brief Peripherals Set 1 clock divider value.
  245. * @note Zero means disabled clock.
  246. */
  247. #if !defined(SPC5_PERIPHERAL1_CLK_DIV_VALUE) || defined(__DOXYGEN__)
  248. #define SPC5_PERIPHERAL1_CLK_DIV_VALUE 2
  249. #endif
  250. /**
  251. * @brief Peripherals Set 2 clock divider value.
  252. * @note Zero means disabled clock.
  253. */
  254. #if !defined(SPC5_PERIPHERAL2_CLK_DIV_VALUE) || defined(__DOXYGEN__)
  255. #define SPC5_PERIPHERAL2_CLK_DIV_VALUE 2
  256. #endif
  257. /**
  258. * @brief Peripherals Set 3 clock divider value.
  259. * @note Zero means disabled clock.
  260. */
  261. #if !defined(SPC5_PERIPHERAL3_CLK_DIV_VALUE) || defined(__DOXYGEN__)
  262. #define SPC5_PERIPHERAL3_CLK_DIV_VALUE 2
  263. #endif
  264. /**
  265. * @brief Active run modes in ME_ME register.
  266. * @note Modes RESET, SAFE, DRUN, and RUN0 modes are always enabled, there
  267. * is no need to specify them.
  268. */
  269. #if !defined(SPC5_ME_ME_BITS) || defined(__DOXYGEN__)
  270. #define SPC5_ME_ME_BITS (SPC5_ME_ME_RUN1 | \
  271. SPC5_ME_ME_RUN2 | \
  272. SPC5_ME_ME_RUN3 | \
  273. SPC5_ME_ME_HALT0 | \
  274. SPC5_ME_ME_STOP0 | \
  275. SPC5_ME_ME_STANDBY0)
  276. #endif
  277. /**
  278. * @brief TEST mode settings.
  279. */
  280. #if !defined(SPC5_ME_TEST_MC_BITS) || defined(__DOXYGEN__)
  281. #define SPC5_ME_TEST_MC_BITS (SPC5_ME_MC_SYSCLK_IRC | \
  282. SPC5_ME_MC_IRCON | \
  283. SPC5_ME_MC_XOSC0ON | \
  284. SPC5_ME_MC_PLL0ON | \
  285. SPC5_ME_MC_CFLAON_NORMAL | \
  286. SPC5_ME_MC_DFLAON_NORMAL | \
  287. SPC5_ME_MC_MVRON)
  288. #endif
  289. /**
  290. * @brief SAFE mode settings.
  291. */
  292. #if !defined(SPC5_ME_SAFE_MC_BITS) || defined(__DOXYGEN__)
  293. #define SPC5_ME_SAFE_MC_BITS (SPC5_ME_MC_PDO)
  294. #endif
  295. /**
  296. * @brief DRUN mode settings.
  297. */
  298. #if !defined(SPC5_ME_DRUN_MC_BITS) || defined(__DOXYGEN__)
  299. #define SPC5_ME_DRUN_MC_BITS (SPC5_ME_MC_SYSCLK_FMPLL0 | \
  300. SPC5_ME_MC_IRCON | \
  301. SPC5_ME_MC_XOSC0ON | \
  302. SPC5_ME_MC_PLL0ON | \
  303. SPC5_ME_MC_CFLAON_NORMAL | \
  304. SPC5_ME_MC_DFLAON_NORMAL | \
  305. SPC5_ME_MC_MVRON)
  306. #endif
  307. /**
  308. * @brief RUN0 mode settings.
  309. */
  310. #if !defined(SPC5_ME_RUN0_MC_BITS) || defined(__DOXYGEN__)
  311. #define SPC5_ME_RUN0_MC_BITS (SPC5_ME_MC_SYSCLK_FMPLL0 | \
  312. SPC5_ME_MC_IRCON | \
  313. SPC5_ME_MC_XOSC0ON | \
  314. SPC5_ME_MC_PLL0ON | \
  315. SPC5_ME_MC_CFLAON_NORMAL | \
  316. SPC5_ME_MC_DFLAON_NORMAL | \
  317. SPC5_ME_MC_MVRON)
  318. #endif
  319. /**
  320. * @brief RUN1 mode settings.
  321. */
  322. #if !defined(SPC5_ME_RUN1_MC_BITS) || defined(__DOXYGEN__)
  323. #define SPC5_ME_RUN1_MC_BITS (SPC5_ME_MC_SYSCLK_FMPLL0 | \
  324. SPC5_ME_MC_IRCON | \
  325. SPC5_ME_MC_XOSC0ON | \
  326. SPC5_ME_MC_PLL0ON | \
  327. SPC5_ME_MC_CFLAON_NORMAL | \
  328. SPC5_ME_MC_DFLAON_NORMAL | \
  329. SPC5_ME_MC_MVRON)
  330. #endif
  331. /**
  332. * @brief RUN2 mode settings.
  333. */
  334. #if !defined(SPC5_ME_RUN2_MC_BITS) || defined(__DOXYGEN__)
  335. #define SPC5_ME_RUN2_MC_BITS (SPC5_ME_MC_SYSCLK_FMPLL0 | \
  336. SPC5_ME_MC_IRCON | \
  337. SPC5_ME_MC_XOSC0ON | \
  338. SPC5_ME_MC_PLL0ON | \
  339. SPC5_ME_MC_CFLAON_NORMAL | \
  340. SPC5_ME_MC_DFLAON_NORMAL | \
  341. SPC5_ME_MC_MVRON)
  342. #endif
  343. /**
  344. * @brief RUN3 mode settings.
  345. */
  346. #if !defined(SPC5_ME_RUN3_MC_BITS) || defined(__DOXYGEN__)
  347. #define SPC5_ME_RUN3_MC_BITS (SPC5_ME_MC_SYSCLK_FMPLL0 | \
  348. SPC5_ME_MC_IRCON | \
  349. SPC5_ME_MC_XOSC0ON | \
  350. SPC5_ME_MC_PLL0ON | \
  351. SPC5_ME_MC_CFLAON_NORMAL | \
  352. SPC5_ME_MC_DFLAON_NORMAL | \
  353. SPC5_ME_MC_MVRON)
  354. #endif
  355. /**
  356. * @brief HALT0 mode settings.
  357. */
  358. #if !defined(SPC5_ME_HALT0_MC_BITS) || defined(__DOXYGEN__)
  359. #define SPC5_ME_HALT0_MC_BITS (SPC5_ME_MC_SYSCLK_FMPLL0 | \
  360. SPC5_ME_MC_IRCON | \
  361. SPC5_ME_MC_XOSC0ON | \
  362. SPC5_ME_MC_PLL0ON | \
  363. SPC5_ME_MC_CFLAON_NORMAL | \
  364. SPC5_ME_MC_DFLAON_NORMAL | \
  365. SPC5_ME_MC_MVRON)
  366. #endif
  367. /**
  368. * @brief STOP0 mode settings.
  369. */
  370. #if !defined(SPC5_ME_STOP0_MC_BITS) || defined(__DOXYGEN__)
  371. #define SPC5_ME_STOP0_MC_BITS (SPC5_ME_MC_SYSCLK_FMPLL0 | \
  372. SPC5_ME_MC_IRCON | \
  373. SPC5_ME_MC_XOSC0ON | \
  374. SPC5_ME_MC_PLL0ON | \
  375. SPC5_ME_MC_CFLAON_NORMAL | \
  376. SPC5_ME_MC_DFLAON_NORMAL | \
  377. SPC5_ME_MC_MVRON)
  378. #endif
  379. /**
  380. * @brief STANDBY0 mode settings.
  381. */
  382. #if !defined(SPC5_ME_STANDBY0_MC_BITS) || defined(__DOXYGEN__)
  383. #define SPC5_ME_STANDBY0_MC_BITS (SPC5_ME_MC_SYSCLK_FMPLL0 | \
  384. SPC5_ME_MC_IRCON | \
  385. SPC5_ME_MC_XOSC0ON | \
  386. SPC5_ME_MC_PLL0ON | \
  387. SPC5_ME_MC_CFLAON_NORMAL | \
  388. SPC5_ME_MC_DFLAON_NORMAL | \
  389. SPC5_ME_MC_MVRON)
  390. #endif
  391. /**
  392. * @brief Peripheral mode 0 (run mode).
  393. * @note Do not change this setting, it is expected to be the "never run"
  394. * mode.
  395. */
  396. #if !defined(SPC5_ME_RUN_PC0_BITS) || defined(__DOXYGEN__)
  397. #define SPC5_ME_RUN_PC0_BITS 0
  398. #endif
  399. /**
  400. * @brief Peripheral mode 1 (run mode).
  401. * @note Do not change this setting, it is expected to be the "always run"
  402. * mode.
  403. */
  404. #if !defined(SPC5_ME_RUN_PC1_BITS) || defined(__DOXYGEN__)
  405. #define SPC5_ME_RUN_PC1_BITS (SPC5_ME_RUN_PC_TEST | \
  406. SPC5_ME_RUN_PC_SAFE | \
  407. SPC5_ME_RUN_PC_DRUN | \
  408. SPC5_ME_RUN_PC_RUN0 | \
  409. SPC5_ME_RUN_PC_RUN1 | \
  410. SPC5_ME_RUN_PC_RUN2 | \
  411. SPC5_ME_RUN_PC_RUN3)
  412. #endif
  413. /**
  414. * @brief Peripheral mode 2 (run mode).
  415. * @note Do not change this setting, it is expected to be the "only during
  416. * normal run" mode.
  417. */
  418. #if !defined(SPC5_ME_RUN_PC2_BITS) || defined(__DOXYGEN__)
  419. #define SPC5_ME_RUN_PC2_BITS (SPC5_ME_RUN_PC_DRUN | \
  420. SPC5_ME_RUN_PC_RUN0 | \
  421. SPC5_ME_RUN_PC_RUN1 | \
  422. SPC5_ME_RUN_PC_RUN2 | \
  423. SPC5_ME_RUN_PC_RUN3)
  424. #endif
  425. /**
  426. * @brief Peripheral mode 3 (run mode).
  427. * @note Not defined, available to application-specific modes.
  428. */
  429. #if !defined(SPC5_ME_RUN_PC3_BITS) || defined(__DOXYGEN__)
  430. #define SPC5_ME_RUN_PC3_BITS (SPC5_ME_RUN_PC_RUN0 | \
  431. SPC5_ME_RUN_PC_RUN1 | \
  432. SPC5_ME_RUN_PC_RUN2 | \
  433. SPC5_ME_RUN_PC_RUN3)
  434. #endif
  435. /**
  436. * @brief Peripheral mode 4 (run mode).
  437. * @note Not defined, available to application-specific modes.
  438. */
  439. #if !defined(SPC5_ME_RUN_PC4_BITS) || defined(__DOXYGEN__)
  440. #define SPC5_ME_RUN_PC4_BITS (SPC5_ME_RUN_PC_RUN0 | \
  441. SPC5_ME_RUN_PC_RUN1 | \
  442. SPC5_ME_RUN_PC_RUN2 | \
  443. SPC5_ME_RUN_PC_RUN3)
  444. #endif
  445. /**
  446. * @brief Peripheral mode 5 (run mode).
  447. * @note Not defined, available to application-specific modes.
  448. */
  449. #if !defined(SPC5_ME_RUN_PC5_BITS) || defined(__DOXYGEN__)
  450. #define SPC5_ME_RUN_PC5_BITS (SPC5_ME_RUN_PC_RUN0 | \
  451. SPC5_ME_RUN_PC_RUN1 | \
  452. SPC5_ME_RUN_PC_RUN2 | \
  453. SPC5_ME_RUN_PC_RUN3)
  454. #endif
  455. /**
  456. * @brief Peripheral mode 6 (run mode).
  457. * @note Not defined, available to application-specific modes.
  458. */
  459. #if !defined(SPC5_ME_RUN_PC6_BITS) || defined(__DOXYGEN__)
  460. #define SPC5_ME_RUN_PC6_BITS (SPC5_ME_RUN_PC_RUN0 | \
  461. SPC5_ME_RUN_PC_RUN1 | \
  462. SPC5_ME_RUN_PC_RUN2 | \
  463. SPC5_ME_RUN_PC_RUN3)
  464. #endif
  465. /**
  466. * @brief Peripheral mode 7 (run mode).
  467. * @note Not defined, available to application-specific modes.
  468. */
  469. #if !defined(SPC5_ME_RUN_PC7_BITS) || defined(__DOXYGEN__)
  470. #define SPC5_ME_RUN_PC7_BITS (SPC5_ME_RUN_PC_RUN0 | \
  471. SPC5_ME_RUN_PC_RUN1 | \
  472. SPC5_ME_RUN_PC_RUN2 | \
  473. SPC5_ME_RUN_PC_RUN3)
  474. #endif
  475. /**
  476. * @brief Peripheral mode 0 (low power mode).
  477. * @note Do not change this setting, it is expected to be the "never run"
  478. * mode.
  479. */
  480. #if !defined(SPC5_ME_LP_PC0_BITS) || defined(__DOXYGEN__)
  481. #define SPC5_ME_LP_PC0_BITS 0
  482. #endif
  483. /**
  484. * @brief Peripheral mode 1 (low power mode).
  485. * @note Do not change this setting, it is expected to be the "always run"
  486. * mode.
  487. */
  488. #if !defined(SPC5_ME_LP_PC1_BITS) || defined(__DOXYGEN__)
  489. #define SPC5_ME_LP_PC1_BITS (SPC5_ME_LP_PC_HALT0 | \
  490. SPC5_ME_LP_PC_STOP0 | \
  491. SPC5_ME_LP_PC_STANDBY0)
  492. #endif
  493. /**
  494. * @brief Peripheral mode 2 (low power mode).
  495. * @note Do not change this setting, it is expected to be the "halt only"
  496. * mode.
  497. */
  498. #if !defined(SPC5_ME_LP_PC2_BITS) || defined(__DOXYGEN__)
  499. #define SPC5_ME_LP_PC2_BITS (SPC5_ME_LP_PC_HALT0)
  500. #endif
  501. /**
  502. * @brief Peripheral mode 3 (low power mode).
  503. * @note Do not change this setting, it is expected to be the "stop only"
  504. * mode.
  505. */
  506. #if !defined(SPC5_ME_LP_PC3_BITS) || defined(__DOXYGEN__)
  507. #define SPC5_ME_LP_PC3_BITS (SPC5_ME_LP_PC_STOP0)
  508. #endif
  509. /**
  510. * @brief Peripheral mode 4 (low power mode).
  511. * @note Not defined, available to application-specific modes.
  512. */
  513. #if !defined(SPC5_ME_LP_PC4_BITS) || defined(__DOXYGEN__)
  514. #define SPC5_ME_LP_PC4_BITS (SPC5_ME_LP_PC_HALT0 | \
  515. SPC5_ME_LP_PC_STOP0)
  516. #endif
  517. /**
  518. * @brief Peripheral mode 5 (low power mode).
  519. * @note Not defined, available to application-specific modes.
  520. */
  521. #if !defined(SPC5_ME_LP_PC5_BITS) || defined(__DOXYGEN__)
  522. #define SPC5_ME_LP_PC5_BITS (SPC5_ME_LP_PC_HALT0 | \
  523. SPC5_ME_LP_PC_STOP0)
  524. #endif
  525. /**
  526. * @brief Peripheral mode 6 (low power mode).
  527. * @note Not defined, available to application-specific modes.
  528. */
  529. #if !defined(SPC5_ME_LP_PC6_BITS) || defined(__DOXYGEN__)
  530. #define SPC5_ME_LP_PC6_BITS (SPC5_ME_LP_PC_HALT0 | \
  531. SPC5_ME_LP_PC_STOP0)
  532. #endif
  533. /**
  534. * @brief Peripheral mode 7 (low power mode).
  535. * @note Not defined, available to application-specific modes.
  536. */
  537. #if !defined(SPC5_ME_LP_PC7_BITS) || defined(__DOXYGEN__)
  538. #define SPC5_ME_LP_PC7_BITS (SPC5_ME_LP_PC_HALT0 | \
  539. SPC5_ME_LP_PC_STOP0)
  540. #endif
  541. /**
  542. * @brief PIT channel 0 IRQ priority.
  543. * @note This PIT channel is allocated permanently for system tick
  544. * generation.
  545. */
  546. #if !defined(SPC5_PIT0_IRQ_PRIORITY) || defined(__DOXYGEN__)
  547. #define SPC5_PIT0_IRQ_PRIORITY 4
  548. #endif
  549. /**
  550. * @brief Clock initialization failure hook.
  551. * @note The default is to stop the system and let the RTC restart it.
  552. * @note The hook code must not return.
  553. */
  554. #if !defined(SPC5_CLOCK_FAILURE_HOOK) || defined(__DOXYGEN__)
  555. #define SPC5_CLOCK_FAILURE_HOOK() osalSysHalt("clock failure")
  556. #endif
  557. /*===========================================================================*/
  558. /* Derived constants and error checks. */
  559. /*===========================================================================*/
  560. /*
  561. * Configuration-related checks.
  562. */
  563. #if !defined(SPC560Dxx_MCUCONF)
  564. #error "Using a wrong mcuconf.h file, SPC560Dxx_MCUCONF not defined"
  565. #endif
  566. /* Check on the XOSC frequency.*/
  567. #if (SPC5_XOSC_CLK < SPC5_XOSC_CLK_MIN) || \
  568. (SPC5_XOSC_CLK > SPC5_XOSC_CLK_MAX)
  569. #error "invalid SPC5_XOSC_CLK value specified"
  570. #endif
  571. /* Check on the XOSC divider.*/
  572. #if (SPC5_XOSCDIV_VALUE < 1) || (SPC5_XOSCDIV_VALUE > 32)
  573. #error "invalid SPC5_XOSCDIV_VALUE value specified"
  574. #endif
  575. /* Check on the IRC divider.*/
  576. #if (SPC5_IRCDIV_VALUE < 1) || (SPC5_IRCDIV_VALUE > 32)
  577. #error "invalid SPC5_IRCDIV_VALUE value specified"
  578. #endif
  579. /* Check on SPC5_FMPLL0_IDF_VALUE.*/
  580. #if (SPC5_FMPLL0_IDF_VALUE < 1) || (SPC5_FMPLL0_IDF_VALUE > 15)
  581. #error "invalid SPC5_FMPLL0_IDF_VALUE value specified"
  582. #endif
  583. /* Check on SPC5_FMPLL0_NDIV_VALUE.*/
  584. #if (SPC5_FMPLL0_NDIV_VALUE < 32) || (SPC5_FMPLL0_NDIV_VALUE > 96)
  585. #error "invalid SPC5_FMPLL0_NDIV_VALUE value specified"
  586. #endif
  587. /* Check on SPC5_FMPLL0_ODF.*/
  588. #if (SPC5_FMPLL0_ODF == SPC5_FMPLL_ODF_DIV2)
  589. #define SPC5_FMPLL0_ODF_VALUE 2
  590. #elif (SPC5_FMPLL0_ODF == SPC5_FMPLL_ODF_DIV4)
  591. #define SPC5_FMPLL0_ODF_VALUE 4
  592. #elif (SPC5_FMPLL0_ODF == SPC5_FMPLL_ODF_DIV8)
  593. #define SPC5_FMPLL0_ODF_VALUE 8
  594. #elif (SPC5_FMPLL0_ODF == SPC5_FMPLL_ODF_DIV16)
  595. #define SPC5_FMPLL0_ODF_VALUE 16
  596. #else
  597. #error "invalid SPC5_FMPLL0_ODF value specified"
  598. #endif
  599. /**
  600. * @brief SPC5_FMPLL0_VCO_CLK clock point.
  601. */
  602. #define SPC5_FMPLL0_VCO_CLK \
  603. ((SPC5_XOSC_CLK / SPC5_FMPLL0_IDF_VALUE) * SPC5_FMPLL0_NDIV_VALUE)
  604. /* Check on FMPLL0 VCO output.*/
  605. #if (SPC5_FMPLL0_VCO_CLK < SPC5_FMPLLVCO_MIN) || \
  606. (SPC5_FMPLL0_VCO_CLK > SPC5_FMPLLVCO_MAX)
  607. #error "SPC5_FMPLL0_VCO_CLK outside acceptable range (SPC5_FMPLLVCO_MIN...SPC5_FMPLLVCO_MAX)"
  608. #endif
  609. /**
  610. * @brief SPC5_FMPLL0_CLK clock point.
  611. */
  612. #define SPC5_FMPLL0_CLK \
  613. (SPC5_FMPLL0_VCO_CLK / SPC5_FMPLL0_ODF_VALUE)
  614. /* Check on SPC5_FMPLL0_CLK.*/
  615. #if (SPC5_FMPLL0_CLK > SPC5_FMPLL0_CLK_MAX) && !SPC5_ALLOW_OVERCLOCK
  616. #error "SPC5_FMPLL0_CLK outside acceptable range (0...SPC5_FMPLL0_CLK_MAX)"
  617. #endif
  618. /* Check on the peripherals set 1 clock divider settings.*/
  619. #if SPC5_PERIPHERAL1_CLK_DIV_VALUE == 0
  620. #define SPC5_CGM_SC_DC0 0
  621. #elif (SPC5_PERIPHERAL1_CLK_DIV_VALUE >= 1) && \
  622. (SPC5_PERIPHERAL1_CLK_DIV_VALUE <= 16)
  623. #define SPC5_CGM_SC_DC0 (0x80 | (SPC5_PERIPHERAL1_CLK_DIV_VALUE - 1))
  624. #else
  625. #error "invalid SPC5_PERIPHERAL1_CLK_DIV_VALUE value specified"
  626. #endif
  627. /* Check on the peripherals set 2 clock divider settings.*/
  628. #if SPC5_PERIPHERAL2_CLK_DIV_VALUE == 0
  629. #define SPC5_CGM_SC_DC1 0
  630. #elif (SPC5_PERIPHERAL2_CLK_DIV_VALUE >= 1) && \
  631. (SPC5_PERIPHERAL2_CLK_DIV_VALUE <= 16)
  632. #define SPC5_CGM_SC_DC1 (0x80 | (SPC5_PERIPHERAL2_CLK_DIV_VALUE - 1))
  633. #else
  634. #error "invalid SPC5_PERIPHERAL2_CLK_DIV_VALUE value specified"
  635. #endif
  636. /* Check on the peripherals set 3 clock divider settings.*/
  637. #if SPC5_PERIPHERAL3_CLK_DIV_VALUE == 0
  638. #define SPC5_CGM_SC_DC2 0
  639. #elif (SPC5_PERIPHERAL3_CLK_DIV_VALUE >= 1) && \
  640. (SPC5_PERIPHERAL3_CLK_DIV_VALUE <= 16)
  641. #define SPC5_CGM_SC_DC2 (0x80 | (SPC5_PERIPHERAL3_CLK_DIV_VALUE - 1))
  642. #else
  643. #error "invalid SPC5_PERIPHERAL3_CLK_DIV_VALUE value specified"
  644. #endif
  645. /*===========================================================================*/
  646. /* Driver data structures and types. */
  647. /*===========================================================================*/
  648. typedef enum {
  649. SPC5_RUNMODE_TEST = 1,
  650. SPC5_RUNMODE_SAFE = 2,
  651. SPC5_RUNMODE_DRUN = 3,
  652. SPC5_RUNMODE_RUN0 = 4,
  653. SPC5_RUNMODE_RUN1 = 5,
  654. SPC5_RUNMODE_RUN2 = 6,
  655. SPC5_RUNMODE_RUN3 = 7,
  656. SPC5_RUNMODE_HALT0 = 8,
  657. SPC5_RUNMODE_STOP0 = 10
  658. } spc5_runmode_t;
  659. /*===========================================================================*/
  660. /* Driver macros. */
  661. /*===========================================================================*/
  662. /*===========================================================================*/
  663. /* External declarations. */
  664. /*===========================================================================*/
  665. #include "spc5_edma.h"
  666. #ifdef __cplusplus
  667. extern "C" {
  668. #endif
  669. void hal_lld_init(void);
  670. void spc_clock_init(void);
  671. bool halSPCSetRunMode(spc5_runmode_t mode);
  672. void halSPCSetPeripheralClockMode(uint32_t n, uint32_t pctl);
  673. #if !SPC5_NO_INIT
  674. uint32_t halSPCGetSystemClock(void);
  675. #endif
  676. #ifdef __cplusplus
  677. }
  678. #endif
  679. #endif /* HAL_LLD_H */
  680. /** @} */