hal_lld.h 27 KB

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