mxc_sys.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. /**
  2. * @file
  3. * @brief System level header file.
  4. */
  5. /*******************************************************************************
  6. * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a
  9. * copy of this software and associated documentation files (the "Software"),
  10. * to deal in the Software without restriction, including without limitation
  11. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12. * and/or sell copies of the Software, and to permit persons to whom the
  13. * Software is furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included
  16. * in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  21. * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
  22. * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  23. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  24. * OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. * Except as contained in this notice, the name of Maxim Integrated
  27. * Products, Inc. shall not be used except as stated in the Maxim Integrated
  28. * Products, Inc. Branding Policy.
  29. *
  30. * The mere transfer of this software does not imply any licenses
  31. * of trade secrets, proprietary technology, copyrights, patents,
  32. * trademarks, maskwork rights, or any other form of intellectual
  33. * property whatsoever. Maxim Integrated Products, Inc. retains all
  34. * ownership rights.
  35. *
  36. * $Date: 2019-04-15 09:35:40 -0500 (Mon, 15 Apr 2019) $
  37. * $Revision: 42499 $
  38. *
  39. ******************************************************************************/
  40. #ifndef _MXC_SYS_H_
  41. #define _MXC_SYS_H_
  42. #include "mxc_config.h"
  43. #include "uart_regs.h"
  44. #include "i2c_regs.h"
  45. #include "gcr_regs.h"
  46. #include "tmr_regs.h"
  47. #include "icc_regs.h"
  48. #include "spi17y_regs.h"
  49. #include "spimss_regs.h"
  50. #include "gpio.h"
  51. #include "flc_regs.h"
  52. #include "dma.h"
  53. #include "wdt_regs.h"
  54. #ifdef __cplusplus
  55. extern "C" {
  56. #endif
  57. #if defined ( __CC_ARM ) /* Suppressing the warning: "enum value is out of range of int" for Keil */
  58. #pragma push
  59. #pragma diag_suppress 66
  60. #endif /* __CC_ARM */
  61. /** @brief System reset0 enumeration. Used in SYS_PeriphReset0 function */
  62. typedef enum {
  63. SYS_RESET0_DMA = MXC_F_GCR_RSTR0_DMA, /**< Reset DMA */
  64. SYS_RESET0_WDT = MXC_F_GCR_RSTR0_WDT, /**< Reset WDT */
  65. SYS_RESET0_GPIO0 = MXC_F_GCR_RSTR0_GPIO0, /**< Reset GPIO0 */
  66. SYS_RESET0_TIMER0 = MXC_F_GCR_RSTR0_TIMER0, /**< Reset TIMER0 */
  67. SYS_RESET0_TIMER1 = MXC_F_GCR_RSTR0_TIMER1, /**< Reset TIMER1 */
  68. SYS_RESET0_TIMER2 = MXC_F_GCR_RSTR0_TIMER2, /**< Reset TIMER2 */
  69. SYS_RESET0_UART0 = MXC_F_GCR_RSTR0_UART0, /**< Reset UART0 */
  70. SYS_RESET0_UART1 = MXC_F_GCR_RSTR0_UART1, /**< Reset UART1 */
  71. SYS_RESET0_SPI0 = MXC_F_GCR_RSTR0_SPI0, /**< Reset SPI0 */
  72. SYS_RESET0_SPI1 = MXC_F_GCR_RSTR0_SPI1, /**< Reset SPI1 */
  73. SYS_RESET0_I2C0 = MXC_F_GCR_RSTR0_I2C0, /**< Reset I2C0 */
  74. SYS_RESET0_RTC = MXC_F_GCR_RSTR0_RTC, /**< Reset RTC */
  75. SYS_RESET0_SRST = MXC_F_GCR_RSTR0_SRST, /**< Soft reset */
  76. SYS_RESET0_PRST = MXC_F_GCR_RSTR0_PRST, /**< Peripheral reset */
  77. SYS_RESET0_SYSTEM = MXC_F_GCR_RSTR0_SYSTEM, /**< System reset */
  78. } sys_reset0_t;
  79. /** @brief System reset1 enumeration. Used in SYS_PeriphReset1 function */
  80. typedef enum {
  81. SYS_RESET1_I2C1 = MXC_F_GCR_RSTR1_I2C1, /**< Reset I2C1 */
  82. } sys_reset1_t;
  83. /** @brief System clock disable enumeration. Used in SYS_ClockDisable and SYS_ClockEnable functions */
  84. typedef enum {
  85. SYS_PERIPH_CLOCK_GPIO0 = MXC_F_GCR_PERCKCN0_GPIO0D, /**< Disable MXC_F_GCR_PERCKCN0_GPIO0D clock */
  86. SYS_PERIPH_CLOCK_DMA = MXC_F_GCR_PERCKCN0_DMAD, /**< Disable MXC_F_GCR_PERCKCN0_DMAD clock */
  87. SYS_PERIPH_CLOCK_SPI17Y = MXC_F_GCR_PERCKCN0_SPI0D, /**< Disable MXC_F_GCR_PERCKCN0_SPI0D clock */
  88. SYS_PERIPH_CLOCK_SPIMSS = MXC_F_GCR_PERCKCN0_SPI1D, /**< Disable MXC_F_GCR_PERCKCN0_SPI1D clock */
  89. SYS_PERIPH_CLOCK_UART0 = MXC_F_GCR_PERCKCN0_UART0D, /**< Disable MXC_F_GCR_PERCKCN0_UART0D clock */
  90. SYS_PERIPH_CLOCK_UART1 = MXC_F_GCR_PERCKCN0_UART1D, /**< Disable MXC_F_GCR_PERCKCN0_UART1D clock */
  91. SYS_PERIPH_CLOCK_I2C0 = MXC_F_GCR_PERCKCN0_I2C0D, /**< Disable MXC_F_GCR_PERCKCN0_I2C0D clock */
  92. SYS_PERIPH_CLOCK_T0 = MXC_F_GCR_PERCKCN0_T0D, /**< Disable MXC_F_GCR_PERCKCN0_T0D clock */
  93. SYS_PERIPH_CLOCK_T1 = MXC_F_GCR_PERCKCN0_T1D, /**< Disable MXC_F_GCR_PERCKCN0_T1D clock */
  94. SYS_PERIPH_CLOCK_T2 = MXC_F_GCR_PERCKCN0_T2D, /**< Disable MXC_F_GCR_PERCKCN0_T2D clock */
  95. SYS_PERIPH_CLOCK_I2C1 = MXC_F_GCR_PERCKCN0_I2C1D, /**< Disable MXC_F_GCR_PERCKCN0_I2C1D clock */
  96. } sys_periph_clock_t;
  97. /** @brief Clock source */
  98. typedef enum {
  99. SYS_CLOCK_NANORING = MXC_V_GCR_CLKCN_CLKSEL_NANORING, /**< 8KHz nanoring on MAX32660 */
  100. SYS_CLOCK_HFXIN = MXC_V_GCR_CLKCN_CLKSEL_HFXIN, /**< 32KHz on MAX32660 */
  101. SYS_CLOCK_HFXIN_DIGITAL = 0x9, /**< External Clock Input*/
  102. SYS_CLOCK_HIRC = MXC_V_GCR_CLKCN_CLKSEL_HIRC, /**< High Frequency Internal Oscillator */
  103. } sys_system_clock_t;
  104. typedef void* sys_cfg_t;
  105. typedef sys_cfg_t sys_cfg_i2c_t;
  106. typedef sys_cfg_t sys_cfg_flc_t;
  107. typedef sys_cfg_t sys_cfg_wdt_t;
  108. /** @brief Map control */
  109. typedef enum {
  110. MAP_A,
  111. MAP_B,
  112. MAP_C,
  113. } sys_map_t;
  114. /** @brief UART Flow control */
  115. typedef enum {
  116. UART_FLOW_DISABLE,
  117. UART_FLOW_ENABLE,
  118. } sys_uart_flow_t;
  119. /** @brief UART system configuration object */
  120. typedef struct {
  121. sys_map_t map;
  122. sys_uart_flow_t flow_flag;
  123. } sys_cfg_uart_t;
  124. /** @brief SPI17Y system configuration object */
  125. typedef struct {
  126. sys_map_t map;
  127. } sys_cfg_spi17y_t;
  128. /** @brief SPIMSS system configuration object */
  129. typedef struct {
  130. sys_map_t map;
  131. } sys_cfg_spimss_t;
  132. /** @brief I2S system configuration object */
  133. typedef struct {
  134. sys_map_t map;
  135. dma_reqsel_t dma_reqsel_tx;
  136. dma_reqsel_t dma_reqsel_rx;
  137. } sys_cfg_i2s_t;
  138. /** @brief TIMER system configuration object */
  139. typedef struct {
  140. int out_en;
  141. } sys_cfg_tmr_t;
  142. /** @brief Real Time Clock system configuration object */
  143. typedef struct {
  144. mxc_tmr_regs_t* tmr;
  145. } sys_cfg_rtc_t;
  146. /** @brief Pulse Train System Configuration Object */
  147. typedef gpio_cfg_t sys_cfg_pt_t;
  148. #if defined ( __CC_ARM ) /* Restore the warning: "enum is out of int range" for Keil */
  149. #pragma pop
  150. #endif /* __CC_ARM */
  151. /***** Function Prototypes *****/
  152. /**
  153. * @brief Selects the system clock and enables it once ready
  154. * @param clock Enumeration for desired clock.
  155. * @param tmr Optional tmr pointer for timeout. NULL if undesired.
  156. *
  157. * @returns #E_NO_ERROR is clock is succesfully selected
  158. */
  159. int SYS_Clock_Select(sys_system_clock_t clock, mxc_tmr_regs_t* tmr);
  160. /**
  161. * @brief Enables the selected peripheral clock.
  162. * @param clock Enumeration for desired clock.
  163. */
  164. void SYS_ClockEnable(sys_periph_clock_t clock);
  165. /**
  166. * @brief Disables the selected peripheral clock.
  167. * @param clock Enumeration for desired clock.
  168. */
  169. void SYS_ClockDisable(sys_periph_clock_t clock);
  170. /**
  171. * @brief Enables the external 32k oscillator.
  172. * @param sys_cfg system configuration object
  173. *
  174. * @returns #E_NO_ERROR is successful, appropriate error otherwise
  175. */
  176. int SYS_ClockEnable_X32K(sys_cfg_rtc_t *sys_cfg);
  177. /**
  178. * @brief Disables the external 32k oscillator.
  179. *
  180. * @returns #E_NO_ERROR is successful, appropriate error otherwise
  181. */
  182. int SYS_ClockDisable_X32K(void);
  183. /**
  184. * @brief System level initialization for UART module.
  185. * @param uart Pointer to UART module registers
  186. * @param sys_cfg System configuration object
  187. *
  188. * @returns #E_NO_ERROR if successful, appropriate error otherwise
  189. */
  190. int SYS_UART_Init(mxc_uart_regs_t *uart, const sys_cfg_uart_t* sys_cfg);
  191. /**
  192. * @brief System level shutdown for UART module
  193. * @param uart Pointer to UART module registers
  194. *
  195. * @return #E_NO_ERROR if successful, appropriate error otherwise
  196. */
  197. int SYS_UART_Shutdown(mxc_uart_regs_t *uart);
  198. /**
  199. * @brief System level initialization for I2C module.
  200. * @param i2c Pointer to I2C module registers
  201. * @param sys_cfg System configuration object
  202. *
  203. * @returns #E_NO_ERROR if successful, appropriate error otherwise
  204. */
  205. int SYS_I2C_Init(mxc_i2c_regs_t *i2c, const sys_cfg_i2c_t* sys_cfg);
  206. /**
  207. * @brief System level Shutdown for I2C module.
  208. * @param i2c Pointer to I2C module registers
  209. *
  210. * @returns #E_NO_ERROR if successful, appropriate error otherwise
  211. */
  212. int SYS_I2C_Shutdown(mxc_i2c_regs_t *i2c);
  213. /**
  214. * @brief Init DMA system settings
  215. *
  216. * @returns #E_NO_ERROR if successful, appropriate error otherwise
  217. */
  218. int SYS_DMA_Init(void);
  219. /**
  220. * @brief Shutdown DMA system specific settings
  221. *
  222. * @returns #E_NO_ERROR if successful, appropriate error otherwise
  223. */
  224. int SYS_DMA_Shutdown(void);
  225. /**
  226. * @brief Get the frequency of the I2C module source clock
  227. * @param spim Unused, pointer to I2C module registers
  228. *
  229. * @returns frequency in Hz
  230. */
  231. unsigned SYS_I2C_GetFreq(mxc_i2c_regs_t *i2c);
  232. /**
  233. * @brief Get the frequency of the Timer module source clock.
  234. * @params tmr Unused, pointer to timer module registers
  235. *
  236. * @returns frequency in Hz
  237. */
  238. unsigned SYS_TMR_GetFreq(mxc_tmr_regs_t *tmr);
  239. /**
  240. * @brief Reset the peripherals and/or CPU in the rstr0 register.
  241. * @param Enumeration for what to reset. Can reset multiple items at once.
  242. */
  243. void SYS_Reset0(sys_reset0_t reset);
  244. /**
  245. * @brief Reset the peripherals and/or CPU in the rstr1 register.
  246. * @param Enumeration for what to reset. Can reset multiple items at once.
  247. */
  248. void SYS_Reset1(sys_reset1_t reset);
  249. /**
  250. * @brief Clear Cache and Line buffer.
  251. */
  252. void SYS_Flash_Operation(void);
  253. /**
  254. * @brief Init TMR system settings
  255. * @param tmr Pointer to timer module registers
  256. * @param sys_cfg System configuration object
  257. *
  258. * @returns #E_NO_ERROR if successful, appropriate error otherwise
  259. */
  260. int SYS_TMR_Init(mxc_tmr_regs_t *tmr, const sys_cfg_tmr_t* sys_cfg);
  261. /**
  262. * @brief Init flash system settings
  263. * @param sys_cfg System configuration object
  264. *
  265. * @returns #E_NO_ERROR if successful, appropriate error otherwise
  266. */
  267. int SYS_FLC_Init(const sys_cfg_flc_t* sys_cfg);
  268. /**
  269. * @brief Shutdown flash system specific settings
  270. *
  271. * @returns #E_NO_ERROR if successful, appropriate error otherwise
  272. */
  273. int SYS_FLC_Shutdown(void);
  274. /**
  275. * @brief System level initialization for SPI17Y module.
  276. * @param spi pointer to spi module registers
  277. * @param sys_cfg System configuration object
  278. *
  279. * @returns E_NO_ERROR if successful, appropriate error otherwise
  280. */
  281. int SYS_SPI17Y_Init( mxc_spi17y_regs_t *spi, const sys_cfg_spi17y_t* sys_cfg);
  282. /**
  283. * @brief System level shutdown for SPI17Y module
  284. * @param pointer to spi module registers
  285. *
  286. * @returns E_NO_ERROR if successful, appropriate error otherwise
  287. */
  288. int SYS_SPI17Y_Shutdown(mxc_spi17y_regs_t *spi);
  289. /**
  290. * @brief System level initialization for SPIMSS module.
  291. * @param spi pointer to spi module registers
  292. * @param sys_cfg System configuration object
  293. *
  294. * @returns E_NO_ERROR if successful, appropriate error otherwise
  295. */
  296. int SYS_SPIMSS_Init(mxc_spimss_regs_t *spi, const sys_cfg_spimss_t* sys_cfg);
  297. /**
  298. * @brief System level shutdown for SPIMSS module
  299. * @param pointer to spi module registers
  300. *
  301. * @returns E_NO_ERROR if everything is successful
  302. */
  303. int SYS_SPIMSS_Shutdown(mxc_spimss_regs_t *spi);
  304. /**
  305. * @brief Shutdown Timer system specific settings
  306. * @param tmr pointer to timer module registers
  307. *
  308. * @returns #E_NO_ERROR if successful, appropriate error otherwise
  309. */
  310. int SYS_TMR_Shutdown(mxc_tmr_regs_t *tmr);
  311. /**
  312. * @brief System level initialization for I2S Module
  313. * @param sys_cfg System configuration object
  314. *
  315. * @returns #E_NO_ERROR if successful, appropriate error otherwise
  316. */
  317. int SYS_I2S_Init(const sys_cfg_i2s_t* sys_cfg);
  318. /**
  319. * @brief System level shutdown of I2S module
  320. *
  321. * @returns #E_NO_ERROR if everything is successful
  322. */
  323. int SYS_I2S_Shutdown(void);
  324. /**
  325. * @brief Get the frequency of the I2S module source clock
  326. * @param spimss Pointer to I2S module registers
  327. *
  328. * @returns frequency in Hz
  329. */
  330. int SYS_I2S_GetFreq(mxc_spimss_regs_t *spimss);
  331. /**
  332. * @brief Init system settings for RTC square wave output.
  333. * @param sys_cfg System configuration object
  334. *
  335. * @returns #E_NO_ERROR if successful, appropriate error otherwise
  336. */
  337. int SYS_RTC_SqwavInit(const sys_cfg_rtc_t* sys_cfg);
  338. /**
  339. * @brief System Tick Configuration Helper
  340. *
  341. * The function enables selection of the external clock source for
  342. * the System Tick Timer. It initializes the System Timer and its
  343. * interrupt, and starts the System Tick Timer. Counter is in free
  344. * running mode to generate periodic interrupts.
  345. *
  346. * @param ticks Number of ticks between two interrupts.
  347. * @param clk_src Selects between default SystemClock or External Clock.
  348. * - 0 Use external clock source
  349. * @param tmr Optional tmr pointer for timeout. NULL if undesired.
  350. * - 1 SystemClock
  351. *
  352. * @return #E_NO_ERROR Function succeeded, of #E_INVALID if an invalid value is requested
  353. */
  354. int SYS_SysTick_Config(uint32_t ticks, int clk_src, mxc_tmr_regs_t* tmr);
  355. /**
  356. * @brief Disable System Tick timer
  357. */
  358. void SYS_SysTick_Disable(void);
  359. /**
  360. * @brief Delay a requested number of SysTick Timer Ticks.
  361. * @param ticks Number of System Ticks to delay.
  362. * @note This delay function is based on the clock used for the SysTick
  363. * timer if the SysTick timer is enabled. If the SysTick timer is
  364. * not enabled, the current SysTick registers are saved and the
  365. * timer will use the SystemClock as the source for the delay. The
  366. * delay is measured in clock ticks and is not based on the SysTick
  367. * interval.
  368. *
  369. * @return #E_NO_ERROR if everything is successful
  370. */
  371. int SYS_SysTick_Delay(uint32_t ticks);
  372. /**
  373. * @brief Get the frequency of the SysTick Timer
  374. *
  375. * @return frequency in Hz
  376. */
  377. uint32_t SYS_SysTick_GetFreq(void);
  378. /**
  379. * @brief Delay a requested number of microseconds.
  380. * @param us Number of microseconds to delay.
  381. * @note Calls SYS_SysTick_Delay().
  382. */
  383. void SYS_SysTick_DelayUs(uint32_t us);
  384. /**
  385. * @brief Init WDT system settings
  386. * @param wdt watchdog registers
  387. * @param sys_cfg System configuration object
  388. */
  389. int SYS_WDT_Init(mxc_wdt_regs_t* wdt, const sys_cfg_wdt_t* sys_cfg);
  390. #ifdef __cplusplus
  391. }
  392. #endif
  393. #endif /* _MXC_SYS_H_*/