M031Series.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. /**************************************************************************//**
  2. * @file m031series.h
  3. * @version V3.0
  4. * $Revision: 12 $
  5. * $Date: 18/08/16 4:06p $
  6. * @brief M031 Series Peripheral Access Layer Header File
  7. *
  8. * @note
  9. * SPDX-License-Identifier: Apache-2.0
  10. * Copyright (C) 2018 Nuvoton Technology Corp. All rights reserved.
  11. *****************************************************************************/
  12. /**
  13. \mainpage NuMicro M031 Driver Reference Guide
  14. *
  15. * <b>Introduction</b>
  16. *
  17. * This user manual describes the usage of M031 Series MCU device driver
  18. *
  19. * <b>Disclaimer</b>
  20. *
  21. * The Software is furnished "AS IS", without warranty as to performance or results, and
  22. * the entire risk as to performance or results is assumed by YOU. Nuvoton disclaims all
  23. * warranties, express, implied or otherwise, with regard to the Software, its use, or
  24. * operation, including without limitation any and all warranties of merchantability, fitness
  25. * for a particular purpose, and non-infringement of intellectual property rights.
  26. *
  27. * <b>Important Notice</b>
  28. *
  29. * Nuvoton Products are neither intended nor warranted for usage in systems or equipment,
  30. * any malfunction or failure of which may cause loss of human life, bodily injury or severe
  31. * property damage. Such applications are deemed, "Insecure Usage".
  32. *
  33. * Insecure usage includes, but is not limited to: equipment for surgical implementation,
  34. * atomic energy control instruments, airplane or spaceship instruments, the control or
  35. * operation of dynamic, brake or safety systems designed for vehicular use, traffic signal
  36. * instruments, all types of safety devices, and other applications intended to support or
  37. * sustain life.
  38. *
  39. * All Insecure Usage shall be made at customer's risk, and in the event that third parties
  40. * lay claims to Nuvoton as a result of customer's Insecure Usage, customer shall indemnify
  41. * the damages and liabilities thus incurred by Nuvoton.
  42. *
  43. * Please note that all data and specifications are subject to change without notice. All the
  44. * trademarks of products and companies mentioned in this datasheet belong to their respective
  45. * owners.
  46. *
  47. * <b>Copyright Notice</b>
  48. *
  49. * @copyright (C) 2018 Nuvoton Technology Corp. All rights reserved.
  50. */
  51. #ifndef __M031SERIES_H__
  52. #define __M031SERIES_H__
  53. /******************************************************************************/
  54. /* Processor and Core Peripherals */
  55. /******************************************************************************/
  56. /** @addtogroup CMSIS_Device CMSIS Definitions
  57. Configuration of the Cortex-M0 Processor and Core Peripherals
  58. @{
  59. */
  60. /*
  61. * ==========================================================================
  62. * ---------- Interrupt Number Definition -----------------------------------
  63. * ==========================================================================
  64. */
  65. /**
  66. * @details Interrupt Number Definition. The maximum of 32 Specific Interrupts are possible.
  67. */
  68. typedef enum IRQn
  69. {
  70. /****** Cortex-M0 Processor Exceptions Numbers ***************************************************/
  71. NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */
  72. HardFault_IRQn = -13, /*!< 3 Cortex-M0 Hard Fault Interrupt */
  73. SVCall_IRQn = -5, /*!< 11 Cortex-M0 SV Call Interrupt */
  74. PendSV_IRQn = -2, /*!< 14 Cortex-M0 Pend SV Interrupt */
  75. SysTick_IRQn = -1, /*!< 15 Cortex-M0 System Tick Interrupt */
  76. /****** ARMIKMCU Swift specific Interrupt Numbers ************************************************/
  77. BOD_IRQn = 0, /*!< Brown-Out Low Voltage Detected Interrupt */
  78. WDT_IRQn = 1, /*!< Watch Dog Timer Interrupt */
  79. EINT024_IRQn = 2, /*!< EINT0, EINT2 and EINT4 Interrupt */
  80. EINT135_IRQn = 3, /*!< EINT1, EINT3 and EINT5 Interrupt */
  81. GPIO_PAPB_IRQn = 4, /*!< GPIO_PAPBPGPH Interrupt */
  82. GPIO_PAPBPGPH_IRQn = 4, /*!< GPIO_PAPBPGPH Interrupt */
  83. GPIO_PCPDPEPF_IRQn = 5, /*!< GPIO_PCPDPEPF Interrupt */
  84. PWM0_IRQn = 6, /*!< PWM0 Interrupt */
  85. PWM1_IRQn = 7, /*!< PWM1 Interrupt */
  86. TMR0_IRQn = 8, /*!< TIMER0 Interrupt */
  87. TMR1_IRQn = 9, /*!< TIMER1 Interrupt */
  88. TMR2_IRQn = 10, /*!< TIMER2 Interrupt */
  89. TMR3_IRQn = 11, /*!< TIMER3 Interrupt */
  90. UART02_IRQn = 12, /*!< UART0 and UART2 Interrupt */
  91. UART1_IRQn = 13, /*!< UART1 and UART3 Interrupt */
  92. UART13_IRQn = 13, /*!< UART1 and UART3 Interrupt */
  93. SPI0_IRQn = 14, /*!< SPI0 Interrupt */
  94. QSPI0_IRQn = 15, /*!< QSPI0 Interrupt */
  95. ISP_IRQn = 16, /*!< ISP Interrupt */
  96. UART57_IRQn = 17, /*!< UART5 and UART7 Interrupt */
  97. I2C0_IRQn = 18, /*!< I2C0 Interrupt */
  98. I2C1_IRQn = 19, /*!< I2C1 Interrupt */
  99. BPWM0_IRQn = 20, /*!< BPWM0 Interrupt */
  100. BPWM1_IRQn = 21, /*!< BPWM1 Interrupt */
  101. USCI_IRQn = 22, /*!< USCI0 and USCI1 interrupt */
  102. USCI01_IRQn = 22, /*!< USCI0 and USCI1 interrupt */
  103. USBD_IRQn = 23, /*!< USB Device Interrupt */
  104. ACMP01_IRQn = 25, /*!< ACMP0/1 Interrupt */
  105. PDMA_IRQn = 26, /*!< PDMA Interrupt */
  106. UART46_IRQn = 27, /*!< UART4 and UART6 Interrupt */
  107. PWRWU_IRQn = 28, /*!< Power Down Wake Up Interrupt */
  108. ADC_IRQn = 29, /*!< ADC Interrupt */
  109. CKFAIL_IRQn = 30, /*!< Clock fail detect Interrupt */
  110. RTC_IRQn = 31, /*!< RTC Interrupt */
  111. } IRQn_Type;
  112. /*
  113. * ==========================================================================
  114. * ----------- Processor and Core Peripheral Section ------------------------
  115. * ==========================================================================
  116. */
  117. /* Configuration of the Cortex-M0 Processor and Core Peripherals */
  118. #define __MPU_PRESENT 0 /*!< armikcmu does not provide a MPU present or not */
  119. #define __NVIC_PRIO_BITS 2 /*!< armikcmu Supports 2 Bits for the Priority Levels */
  120. #define __Vendor_SysTickConfig 0 /*!< Set to 1 if different SysTick Config is used */
  121. /*@}*/ /* end of group CMSIS_Device */
  122. #include "core_cm0.h" /*!< Cortex-M0 processor and core peripherals */
  123. #include "system_M031Series.h" /*!< M031 System */
  124. #if defined ( __CC_ARM )
  125. #pragma anon_unions
  126. #endif
  127. /**
  128. * Initialize the system clock
  129. *
  130. * @param None
  131. * @return None
  132. *
  133. * @brief Setup the microcontroller system
  134. * Initialize the PLL and update the SystemFrequency variable
  135. */
  136. extern void SystemInit(void);
  137. /******************************************************************************/
  138. /* Device Specific Peripheral registers structures */
  139. /******************************************************************************/
  140. #include "acmp_reg.h"
  141. #include "adc_reg.h"
  142. #include "clk_reg.h"
  143. #include "crc_reg.h"
  144. #include "ebi_reg.h"
  145. #include "fmc_reg.h"
  146. #include "gpio_reg.h"
  147. #include "hdiv_reg.h"
  148. #include "i2c_reg.h"
  149. #include "pdma_reg.h"
  150. #include "pwm_reg.h"
  151. #include "bpwm_reg.h"
  152. #include "qspi_reg.h"
  153. #include "spi_reg.h"
  154. #include "sys_reg.h"
  155. #include "rtc_reg.h"
  156. #include "timer_reg.h"
  157. #include "uart_reg.h"
  158. #include "ui2c_reg.h"
  159. #include "usbd_reg.h"
  160. #include "uspi_reg.h"
  161. #include "uuart_reg.h"
  162. #include "wdt_reg.h"
  163. #include "wwdt_reg.h"
  164. /******************************************************************************/
  165. /* Peripheral memory map */
  166. /******************************************************************************/
  167. /** @addtogroup PERIPHERAL_BASE Peripheral Memory Base
  168. Memory Mapped Structure for Series Peripheral
  169. @{
  170. */
  171. /* Peripheral and SRAM base address */
  172. #define FLASH_BASE (( uint32_t)0x00000000)
  173. #define SRAM_BASE (( uint32_t)0x20000000)
  174. #define AHB_BASE (( uint32_t)0x40000000)
  175. #define APB1_BASE (( uint32_t)0x40000000)
  176. #define APB2_BASE (( uint32_t)0x40000000)
  177. /* Peripheral memory map */
  178. #define SYS_BASE (AHB_BASE + 0x00000) /*!< System Global Controller Base Address */
  179. #define CLK_BASE (AHB_BASE + 0x00200) /*!< System Clock Controller Base Address */
  180. #define INT_BASE (AHB_BASE + 0x00300) /*!< Interrupt Source Controller Base Address */
  181. #define NMI_BASE (AHB_BASE + 0x00300) /*!< Interrupt Source Controller Base Address */
  182. #define GPIO_BASE (AHB_BASE + 0x4000) /*!< GPIO Base Address */
  183. #define PA_BASE (GPIO_BASE ) /*!< GPIO PA Base Address */
  184. #define PB_BASE (GPIO_BASE + 0x0040) /*!< GPIO PB Base Address */
  185. #define PC_BASE (GPIO_BASE + 0x0080) /*!< GPIO PC Base Address */
  186. #define PD_BASE (GPIO_BASE + 0x00C0) /*!< GPIO PD Base Address */
  187. #define PE_BASE (GPIO_BASE + 0x0100) /*!< GPIO PE Base Address */
  188. #define PF_BASE (GPIO_BASE + 0x0140) /*!< GPIO PF Base Address */
  189. #define PG_BASE (GPIO_BASE + 0x0180) /*!< GPIO PG Base Address */
  190. #define PH_BASE (GPIO_BASE + 0x01C0) /*!< GPIO PH Base Address */
  191. #define GPIO_DBCTL_BASE (GPIO_BASE + 0x0440) /*!< GPIO De-bounce Cycle Control Base Address */
  192. #define GPIO_PIN_DATA_BASE (GPIO_BASE + 0x0800) /*!< GPIO Pin Data Input/Output Control Base Address */
  193. #define PDMA_BASE (AHB_BASE + 0x08000) /*!< PDMA Base Address */
  194. #define FMC_BASE (AHB_BASE + 0x0C000) /*!< Flash Memory Controller Base Address */
  195. #define EBI_BASE (AHB_BASE + 0x10000) /*!< EBI Base Address */
  196. #define HDIV_BASE (AHB_BASE + 0x14000) /*!< HDIV Base Address */
  197. #define CRC_BASE (AHB_BASE + 0x31000) /*!< CRC Base Address */
  198. #define WDT_BASE (APB1_BASE + 0x40000) /*!< Watch Dog Timer Base Address */
  199. #define WWDT_BASE (APB1_BASE + 0x40100) /*!< Window Watch Dog Timer Base Address */
  200. #define RTC_BASE (APB1_BASE + 0x41000) /*!< RTC Base Address */
  201. #define ADC_BASE (APB1_BASE + 0x43000) /*!< ADC Base Address */
  202. #define ACMP01_BASE (APB1_BASE + 0x45000) /*!< ACMP01 Base Address */
  203. #define TIMER0_BASE (APB1_BASE + 0x50000) /*!< Timer0 Base Address */
  204. #define TIMER1_BASE (APB1_BASE + 0x50020) /*!< Timer1 Base Address */
  205. #define TIMER2_BASE (APB2_BASE + 0x51000) /*!< Timer2 Base Address */
  206. #define TIMER3_BASE (APB2_BASE + 0x51020) /*!< Timer3 Base Address */
  207. #define PWM0_BASE (APB1_BASE + 0x58000) /*!< PWM0 Base Address */
  208. #define PWM1_BASE (APB2_BASE + 0x59000) /*!< PWM1 Base Address */
  209. #define BPWM0_BASE (APB1_BASE + 0x5A000) /*!< BPWM0 Base Address */
  210. #define BPWM1_BASE (APB2_BASE + 0x5B000) /*!< BPWM1 Base Address */
  211. #define QSPI0_BASE (APB1_BASE + 0x60000) /*!< QSPI0 Base Address */
  212. #define SPI0_BASE (APB1_BASE + 0x61000) /*!< SPI0 Base Address */
  213. #define UART0_BASE (APB1_BASE + 0x70000) /*!< UART0 Base Address */
  214. #define UART1_BASE (APB2_BASE + 0x71000) /*!< UART1 Base Address */
  215. #define UART2_BASE (APB2_BASE + 0x72000) /*!< UART2 Base Address */
  216. #define UART3_BASE (APB2_BASE + 0x73000) /*!< UART3 Base Address */
  217. #define UART4_BASE (APB2_BASE + 0x74000) /*!< UART4 Base Address */
  218. #define UART5_BASE (APB2_BASE + 0x75000) /*!< UART5 Base Address */
  219. #define UART6_BASE (APB2_BASE + 0x76000) /*!< UART6 Base Address */
  220. #define UART7_BASE (APB2_BASE + 0x77000) /*!< UART7 Base Address */
  221. #define I2C0_BASE (APB1_BASE + 0x80000) /*!< I2C0 Base Address */
  222. #define I2C1_BASE (APB2_BASE + 0x81000) /*!< I2C1 Base Address */
  223. #define USBD_BASE (AHB_BASE + 0xC0000) /*!< USBD1.1 Base Address */
  224. #define USCI0_BASE (APB1_BASE + 0xD0000) /*!< USCI0 Base Address */
  225. #define USCI1_BASE (APB2_BASE + 0xD1000) /*!< USCI1 Base Address */
  226. /**@}*/ /* PERIPHERAL */
  227. /******************************************************************************/
  228. /* Peripheral declaration */
  229. /******************************************************************************/
  230. /** @addtogroup PMODULE Peripheral Pointer
  231. The Declaration of Peripheral Pointer
  232. @{
  233. */
  234. #define PA ((GPIO_T *) PA_BASE) /*!< GPIO PORTA Configuration Struct */
  235. #define PB ((GPIO_T *) PB_BASE) /*!< GPIO PORTB Configuration Struct */
  236. #define PC ((GPIO_T *) PC_BASE) /*!< GPIO PORTC Configuration Struct */
  237. #define PD ((GPIO_T *) PD_BASE) /*!< GPIO PORTD Configuration Struct */
  238. #define PE ((GPIO_T *) PE_BASE) /*!< GPIO PORTE Configuration Struct */
  239. #define PF ((GPIO_T *) PF_BASE) /*!< GPIO PORTF Configuration Struct */
  240. #define PG ((GPIO_T *) PG_BASE) /*!< GPIO PORTG Configuration Struct */
  241. #define PH ((GPIO_T *) PH_BASE) /*!< GPIO PORTH Configuration Struct */
  242. #define GPIO ((GPIO_DBCTL_T *) GPIO_DBCTL_BASE) /*!< Interrupt De-bounce Cycle Control Configuration Struct */
  243. #define UART0 ((UART_T *) UART0_BASE) /*!< UART0 Configuration Struct */
  244. #define UART1 ((UART_T *) UART1_BASE) /*!< UART1 Configuration Struct */
  245. #define UART2 ((UART_T *) UART2_BASE) /*!< UART2 Configuration Struct */
  246. #define UART3 ((UART_T *) UART3_BASE) /*!< UART3 Configuration Struct */
  247. #define UART4 ((UART_T *) UART4_BASE) /*!< UART4 Configuration Struct */
  248. #define UART5 ((UART_T *) UART5_BASE) /*!< UART5 Configuration Struct */
  249. #define UART6 ((UART_T *) UART6_BASE) /*!< UART6 Configuration Struct */
  250. #define UART7 ((UART_T *) UART7_BASE) /*!< UART7 Configuration Struct */
  251. #define TIMER0 ((TIMER_T *) TIMER0_BASE) /*!< TIMER0 Configuration Struct */
  252. #define TIMER1 ((TIMER_T *) TIMER1_BASE) /*!< TIMER1 Configuration Struct */
  253. #define TIMER2 ((TIMER_T *) TIMER2_BASE) /*!< TIMER2 Configuration Struct */
  254. #define TIMER3 ((TIMER_T *) TIMER3_BASE) /*!< TIMER3 Configuration Struct */
  255. #define WDT ((WDT_T *) WDT_BASE) /*!< Watch Dog Timer Configuration Struct */
  256. #define WWDT ((WWDT_T *) WWDT_BASE) /*!< Window Watch Dog Timer Configuration Struct */
  257. #define SPI0 ((SPI_T *) SPI0_BASE) /*!< SPI0 Configuration Struct */
  258. #define QSPI0 ((QSPI_T *) QSPI0_BASE) /*!< QSPI0 Configuration Struct */
  259. #define I2C0 ((I2C_T *) I2C0_BASE) /*!< I2C0 Configuration Struct */
  260. #define I2C1 ((I2C_T *) I2C1_BASE) /*!< I2C1 Configuration Struct */
  261. #define ADC ((ADC_T *) ADC_BASE) /*!< ADC Configuration Struct */
  262. #define ACMP01 ((ACMP_T *) ACMP01_BASE) /*!< ACMP01 Configuration Struct */
  263. #define CLK ((CLK_T *) CLK_BASE) /*!< System Clock Controller Configuration Struct */
  264. #define SYS ((SYS_T *) SYS_BASE) /*!< System Global Controller Configuration Struct */
  265. #define SYSINT ((NMI_T *) INT_BASE) /*!< Interrupt Source Controller Configuration Struct */
  266. #define NMI ((NMI_T *) NMI_BASE) /*!< Interrupt Source Controller Configuration Struct */
  267. #define FMC ((FMC_T *) FMC_BASE) /*!< Flash Memory Controller */
  268. #define PWM0 ((PWM_T *) PWM0_BASE) /*!< PWM0 Configuration Struct */
  269. #define PWM1 ((PWM_T *) PWM1_BASE) /*!< PWM1 Configuration Struct */
  270. #define BPWM0 ((BPWM_T *) BPWM0_BASE) /*!< BPWM0 Configuration Struct */
  271. #define BPWM1 ((BPWM_T *) BPWM1_BASE) /*!< BPWM1 Configuration Struct */
  272. #define EBI ((EBI_T *) EBI_BASE) /*!< EBI Configuration Struct */
  273. #define HDIV ((HDIV_T *) HDIV_BASE) /*!< HDIV Configuration Struct */
  274. #define CRC ((CRC_T *) CRC_BASE) /*!< CRC Configuration Struct */
  275. #define USBD ((USBD_T *) USBD_BASE) /*!< CRC Configuration Struct */
  276. #define PDMA ((PDMA_T *) PDMA_BASE) /*!< PDMA Configuration Struct */
  277. #define UI2C0 ((UI2C_T *) USCI0_BASE) /*!< UI2C0 Configuration Struct */
  278. #define UI2C1 ((UI2C_T *) USCI1_BASE) /*!< UI2C1 Configuration Struct */
  279. #define USPI0 ((USPI_T *) USCI0_BASE) /*!< USPI0 Configuration Struct */
  280. #define USPI1 ((USPI_T *) USCI1_BASE) /*!< USPI1 Configuration Struct */
  281. #define UUART0 ((UUART_T *) USCI0_BASE) /*!< UUART0 Configuration Struct */
  282. #define UUART1 ((UUART_T *) USCI1_BASE) /*!< UUART1 Configuration Struct */
  283. #define RTC ((RTC_T *) RTC_BASE) /*!< RTC Configuration Struct */
  284. /**@}*/ /* end of group PMODULE */
  285. //=============================================================================
  286. /** @addtogroup IO_ROUTINE I/O Routines
  287. The Declaration of I/O Routines
  288. @{
  289. */
  290. typedef volatile unsigned char vu8;
  291. typedef volatile unsigned long vu32;
  292. typedef volatile unsigned short vu16;
  293. /**
  294. * @brief Get a 8-bit unsigned value from specified address
  295. * @param[in] addr Address to get 8-bit data from
  296. * @return 8-bit unsigned value stored in specified address
  297. */
  298. #define M8(addr) (*((vu8 *) (addr)))
  299. /**
  300. * @brief Get a 16-bit unsigned value from specified address
  301. * @param[in] addr Address to get 16-bit data from
  302. * @return 16-bit unsigned value stored in specified address
  303. * @note The input address must be 16-bit aligned
  304. */
  305. #define M16(addr) (*((vu16 *) (addr)))
  306. /**
  307. * @brief Get a 32-bit unsigned value from specified address
  308. * @param[in] addr Address to get 32-bit data from
  309. * @return 32-bit unsigned value stored in specified address
  310. * @note The input address must be 32-bit aligned
  311. */
  312. #define M32(addr) (*((vu32 *) (addr)))
  313. /**
  314. * @brief Set a 32-bit unsigned value to specified I/O port
  315. * @param[in] port Port address to set 32-bit data
  316. * @param[in] value Value to write to I/O port
  317. * @return None
  318. * @note The output port must be 32-bit aligned
  319. */
  320. #define outpw(port,value) (*((volatile unsigned int *)(port))=(value))
  321. /**
  322. * @brief Get a 32-bit unsigned value from specified I/O port
  323. * @param[in] port Port address to get 32-bit data from
  324. * @return 32-bit unsigned value stored in specified I/O port
  325. * @note The input port must be 32-bit aligned
  326. */
  327. #define inpw(port) ((*((volatile unsigned int *)(port))))
  328. /**
  329. * @brief Set a 16-bit unsigned value to specified I/O port
  330. * @param[in] port Port address to set 16-bit data
  331. * @param[in] value Value to write to I/O port
  332. * @return None
  333. * @note The output port must be 16-bit aligned
  334. */
  335. #define outps(port,value) (*((volatile unsigned short *)(port))=(value))
  336. /**
  337. * @brief Get a 16-bit unsigned value from specified I/O port
  338. * @param[in] port Port address to get 16-bit data from
  339. * @return 16-bit unsigned value stored in specified I/O port
  340. * @note The input port must be 16-bit aligned
  341. */
  342. #define inps(port) ((*((volatile unsigned short *)(port))))
  343. /**
  344. * @brief Set a 8-bit unsigned value to specified I/O port
  345. * @param[in] port Port address to set 8-bit data
  346. * @param[in] value Value to write to I/O port
  347. * @return None
  348. */
  349. #define outpb(port,value) (*((volatile unsigned char *)(port))=(value))
  350. /**
  351. * @brief Get a 8-bit unsigned value from specified I/O port
  352. * @param[in] port Port address to get 8-bit data from
  353. * @return 8-bit unsigned value stored in specified I/O port
  354. */
  355. #define inpb(port) ((*((volatile unsigned char *)(port))))
  356. /**
  357. * @brief Set a 32-bit unsigned value to specified I/O port
  358. * @param[in] port Port address to set 32-bit data
  359. * @param[in] value Value to write to I/O port
  360. * @return None
  361. * @note The output port must be 32-bit aligned
  362. */
  363. #define outp32(port,value) (*((volatile unsigned int *)(port))=(value))
  364. /**
  365. * @brief Get a 32-bit unsigned value from specified I/O port
  366. * @param[in] port Port address to get 32-bit data from
  367. * @return 32-bit unsigned value stored in specified I/O port
  368. * @note The input port must be 32-bit aligned
  369. */
  370. #define inp32(port) ((*((volatile unsigned int *)(port))))
  371. /**
  372. * @brief Set a 16-bit unsigned value to specified I/O port
  373. * @param[in] port Port address to set 16-bit data
  374. * @param[in] value Value to write to I/O port
  375. * @return None
  376. * @note The output port must be 16-bit aligned
  377. */
  378. #define outp16(port,value) (*((volatile unsigned short *)(port))=(value))
  379. /**
  380. * @brief Get a 16-bit unsigned value from specified I/O port
  381. * @param[in] port Port address to get 16-bit data from
  382. * @return 16-bit unsigned value stored in specified I/O port
  383. * @note The input port must be 16-bit aligned
  384. */
  385. #define inp16(port) ((*((volatile unsigned short *)(port))))
  386. /**
  387. * @brief Set a 8-bit unsigned value to specified I/O port
  388. * @param[in] port Port address to set 8-bit data
  389. * @param[in] value Value to write to I/O port
  390. * @return None
  391. */
  392. #define outp8(port,value) (*((volatile unsigned char *)(port))=(value))
  393. /**
  394. * @brief Get a 8-bit unsigned value from specified I/O port
  395. * @param[in] port Port address to get 8-bit data from
  396. * @return 8-bit unsigned value stored in specified I/O port
  397. */
  398. #define inp8(port) ((*((volatile unsigned char *)(port))))
  399. /*@}*/ /* end of group IO_ROUTINE */
  400. /******************************************************************************/
  401. /* Legacy Constants */
  402. /******************************************************************************/
  403. /** @addtogroup Legacy_Constants Legacy Constants
  404. Legacy Constants
  405. @{
  406. */
  407. #define E_SUCCESS (0)
  408. #ifndef NULL
  409. #define NULL (0) ///< NULL pointer
  410. #endif
  411. #define TRUE (1UL) ///< Boolean true, define to use in API parameters or return value
  412. #define FALSE (0UL) ///< Boolean false, define to use in API parameters or return value
  413. #define ENABLE (1UL) ///< Enable, define to use in API parameters
  414. #define DISABLE (0UL) ///< Disable, define to use in API parameters
  415. /* Define one bit mask */
  416. #define BIT0 (0x00000001UL) ///< Bit 0 mask of an 32 bit integer
  417. #define BIT1 (0x00000002UL) ///< Bit 1 mask of an 32 bit integer
  418. #define BIT2 (0x00000004UL) ///< Bit 2 mask of an 32 bit integer
  419. #define BIT3 (0x00000008UL) ///< Bit 3 mask of an 32 bit integer
  420. #define BIT4 (0x00000010UL) ///< Bit 4 mask of an 32 bit integer
  421. #define BIT5 (0x00000020UL) ///< Bit 5 mask of an 32 bit integer
  422. #define BIT6 (0x00000040UL) ///< Bit 6 mask of an 32 bit integer
  423. #define BIT7 (0x00000080UL) ///< Bit 7 mask of an 32 bit integer
  424. #define BIT8 (0x00000100UL) ///< Bit 8 mask of an 32 bit integer
  425. #define BIT9 (0x00000200UL) ///< Bit 9 mask of an 32 bit integer
  426. #define BIT10 (0x00000400UL) ///< Bit 10 mask of an 32 bit integer
  427. #define BIT11 (0x00000800UL) ///< Bit 11 mask of an 32 bit integer
  428. #define BIT12 (0x00001000UL) ///< Bit 12 mask of an 32 bit integer
  429. #define BIT13 (0x00002000UL) ///< Bit 13 mask of an 32 bit integer
  430. #define BIT14 (0x00004000UL) ///< Bit 14 mask of an 32 bit integer
  431. #define BIT15 (0x00008000UL) ///< Bit 15 mask of an 32 bit integer
  432. #define BIT16 (0x00010000UL) ///< Bit 16 mask of an 32 bit integer
  433. #define BIT17 (0x00020000UL) ///< Bit 17 mask of an 32 bit integer
  434. #define BIT18 (0x00040000UL) ///< Bit 18 mask of an 32 bit integer
  435. #define BIT19 (0x00080000UL) ///< Bit 19 mask of an 32 bit integer
  436. #define BIT20 (0x00100000UL) ///< Bit 20 mask of an 32 bit integer
  437. #define BIT21 (0x00200000UL) ///< Bit 21 mask of an 32 bit integer
  438. #define BIT22 (0x00400000UL) ///< Bit 22 mask of an 32 bit integer
  439. #define BIT23 (0x00800000UL) ///< Bit 23 mask of an 32 bit integer
  440. #define BIT24 (0x01000000UL) ///< Bit 24 mask of an 32 bit integer
  441. #define BIT25 (0x02000000UL) ///< Bit 25 mask of an 32 bit integer
  442. #define BIT26 (0x04000000UL) ///< Bit 26 mask of an 32 bit integer
  443. #define BIT27 (0x08000000UL) ///< Bit 27 mask of an 32 bit integer
  444. #define BIT28 (0x10000000UL) ///< Bit 28 mask of an 32 bit integer
  445. #define BIT29 (0x20000000UL) ///< Bit 29 mask of an 32 bit integer
  446. #define BIT30 (0x40000000UL) ///< Bit 30 mask of an 32 bit integer
  447. #define BIT31 (0x80000000UL) ///< Bit 31 mask of an 32 bit integer
  448. /* Byte Mask Definitions */
  449. #define BYTE0_Msk (0x000000FFUL) ///< Mask to get bit0~bit7 from a 32 bit integer
  450. #define BYTE1_Msk (0x0000FF00UL) ///< Mask to get bit8~bit15 from a 32 bit integer
  451. #define BYTE2_Msk (0x00FF0000UL) ///< Mask to get bit16~bit23 from a 32 bit integer
  452. #define BYTE3_Msk (0xFF000000UL) ///< Mask to get bit24~bit31 from a 32 bit integer
  453. #define GET_BYTE0(u32Param) (((u32Param) & BYTE0_Msk) ) /*!< Extract Byte 0 (Bit 0~ 7) from parameter u32Param */
  454. #define GET_BYTE1(u32Param) (((u32Param) & BYTE1_Msk) >> 8) /*!< Extract Byte 1 (Bit 8~15) from parameter u32Param */
  455. #define GET_BYTE2(u32Param) (((u32Param) & BYTE2_Msk) >> 16) /*!< Extract Byte 2 (Bit 16~23) from parameter u32Param */
  456. #define GET_BYTE3(u32Param) (((u32Param) & BYTE3_Msk) >> 24) /*!< Extract Byte 3 (Bit 24~31) from parameter u32Param */
  457. /* Chip Series number definitions */
  458. #define GET_CHIP_SERIES_NUM ((SYS->PDID & 0xF00) >> 8) /*!< Extract chip series number from PDID */
  459. #define CHIP_SERIES_NUM_B (0xBUL) /*!< Chip series number for M031_B */
  460. #define CHIP_SERIES_NUM_C (0xCUL) /*!< Chip series number for M031_C */
  461. #define CHIP_SERIES_NUM_D (0xDUL) /*!< Chip series number for M031_D */
  462. #define CHIP_SERIES_NUM_E (0xEUL) /*!< Chip series number for M031_E */
  463. #define CHIP_SERIES_NUM_G (0x6UL) /*!< Chip series number for M031_G */
  464. #define CHIP_SERIES_NUM_I (0x1UL) /*!< Chip series number for M031_I */
  465. /*@}*/ /* end of group Legacy_Constants */
  466. /******************************************************************************/
  467. /* Peripheral header files */
  468. /******************************************************************************/
  469. #include "nu_sys.h"
  470. #include "nu_clk.h"
  471. #include "nu_acmp.h"
  472. #include "nu_adc.h"
  473. #include "nu_crc.h"
  474. #include "nu_ebi.h"
  475. #include "nu_fmc.h"
  476. #include "nu_gpio.h"
  477. #include "nu_i2c.h"
  478. #include "nu_pdma.h"
  479. #include "nu_pwm.h"
  480. #include "nu_bpwm.h"
  481. #include "nu_qspi.h"
  482. #include "nu_spi.h"
  483. #include "nu_rtc.h"
  484. #include "nu_hdiv.h"
  485. #include "nu_timer.h"
  486. #include "nu_uart.h"
  487. #include "nu_usbd.h"
  488. #include "nu_usci_i2c.h"
  489. #include "nu_usci_spi.h"
  490. #include "nu_usci_uart.h"
  491. #include "nu_wdt.h"
  492. #include "nu_wwdt.h"
  493. #endif // __M031SERIES_H__
  494. /* Copyright (C) 2018 Nuvoton Technology Corp. All rights reserved. */