cpu.h 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. /*
  2. *********************************************************************************************************
  3. * uC/CPU
  4. * CPU CONFIGURATION & PORT LAYER
  5. *
  6. * (c) Copyright 2004-2015; Micrium, Inc.; Weston, FL
  7. *
  8. * All rights reserved. Protected by international copyright laws.
  9. *
  10. * uC/CPU is provided in source form to registered licensees ONLY. It is
  11. * illegal to distribute this source code to any third party unless you receive
  12. * written permission by an authorized Micrium representative. Knowledge of
  13. * the source code may NOT be used to develop a similar product.
  14. *
  15. * Please help us continue to provide the Embedded community with the finest
  16. * software available. Your honesty is greatly appreciated.
  17. *
  18. * You can find our product's user manual, API reference, release notes and
  19. * more information at https://doc.micrium.com.
  20. * You can contact us at www.micrium.com.
  21. *********************************************************************************************************
  22. */
  23. /*
  24. *********************************************************************************************************
  25. *
  26. * CPU PORT FILE
  27. *
  28. * ARM-Cortex-M4
  29. * IAR C Compiler
  30. *
  31. * Filename : cpu.h
  32. * Version : V1.30.02.00
  33. * Programmer(s) : JJL
  34. * BAN
  35. *********************************************************************************************************
  36. */
  37. /*
  38. *********************************************************************************************************
  39. * MODULE
  40. *
  41. * Note(s) : (1) This CPU header file is protected from multiple pre-processor inclusion through use of
  42. * the CPU module present pre-processor macro definition.
  43. *********************************************************************************************************
  44. */
  45. #ifndef CPU_MODULE_PRESENT /* See Note #1. */
  46. #define CPU_MODULE_PRESENT
  47. /*
  48. *********************************************************************************************************
  49. * CPU INCLUDE FILES
  50. *
  51. * Note(s) : (1) The following CPU files are located in the following directories :
  52. *
  53. * (a) \<Your Product Application>\cpu_cfg.h
  54. *
  55. * (b) (1) \<CPU-Compiler Directory>\cpu_def.h
  56. * (2) \<CPU-Compiler Directory>\<cpu>\<compiler>\cpu*.*
  57. *
  58. * where
  59. * <Your Product Application> directory path for Your Product's Application
  60. * <CPU-Compiler Directory> directory path for common CPU-compiler software
  61. * <cpu> directory name for specific CPU
  62. * <compiler> directory name for specific compiler
  63. *
  64. * (2) Compiler MUST be configured to include as additional include path directories :
  65. *
  66. * (a) '\<Your Product Application>\' directory See Note #1a
  67. *
  68. * (b) (1) '\<CPU-Compiler Directory>\' directory See Note #1b1
  69. * (2) '\<CPU-Compiler Directory>\<cpu>\<compiler>\' directory See Note #1b2
  70. *
  71. * (3) Since NO custom library modules are included, 'cpu.h' may ONLY use configurations from
  72. * CPU configuration file 'cpu_cfg.h' that do NOT reference any custom library definitions.
  73. *
  74. * In other words, 'cpu.h' may use 'cpu_cfg.h' configurations that are #define'd to numeric
  75. * constants or to NULL (i.e. NULL-valued #define's); but may NOT use configurations to
  76. * custom library #define's (e.g. DEF_DISABLED or DEF_ENABLED).
  77. *********************************************************************************************************
  78. */
  79. #include <intrinsics.h>
  80. #include <cpu_def.h>
  81. #include <cpu_cfg.h> /* See Note #3. */
  82. #ifdef __cplusplus
  83. extern "C" {
  84. #endif
  85. /*
  86. *********************************************************************************************************
  87. * CONFIGURE STANDARD DATA TYPES
  88. *
  89. * Note(s) : (1) Configure standard data types according to CPU-/compiler-specifications.
  90. *
  91. * (2) (a) (1) 'CPU_FNCT_VOID' data type defined to replace the commonly-used function pointer
  92. * data type of a pointer to a function which returns void & has no arguments.
  93. *
  94. * (2) Example function pointer usage :
  95. *
  96. * CPU_FNCT_VOID FnctName;
  97. *
  98. * FnctName();
  99. *
  100. * (b) (1) 'CPU_FNCT_PTR' data type defined to replace the commonly-used function pointer
  101. * data type of a pointer to a function which returns void & has a single void
  102. * pointer argument.
  103. *
  104. * (2) Example function pointer usage :
  105. *
  106. * CPU_FNCT_PTR FnctName;
  107. * void *p_obj
  108. *
  109. * FnctName(p_obj);
  110. *********************************************************************************************************
  111. */
  112. typedef void CPU_VOID;
  113. typedef char CPU_CHAR; /* 8-bit character */
  114. typedef unsigned char CPU_BOOLEAN; /* 8-bit boolean or logical */
  115. typedef unsigned char CPU_INT08U; /* 8-bit unsigned integer */
  116. typedef signed char CPU_INT08S; /* 8-bit signed integer */
  117. typedef unsigned short CPU_INT16U; /* 16-bit unsigned integer */
  118. typedef signed short CPU_INT16S; /* 16-bit signed integer */
  119. typedef unsigned int CPU_INT32U; /* 32-bit unsigned integer */
  120. typedef signed int CPU_INT32S; /* 32-bit signed integer */
  121. typedef unsigned long long CPU_INT64U; /* 64-bit unsigned integer */
  122. typedef signed long long CPU_INT64S; /* 64-bit signed integer */
  123. typedef float CPU_FP32; /* 32-bit floating point */
  124. typedef double CPU_FP64; /* 64-bit floating point */
  125. typedef volatile CPU_INT08U CPU_REG08; /* 8-bit register */
  126. typedef volatile CPU_INT16U CPU_REG16; /* 16-bit register */
  127. typedef volatile CPU_INT32U CPU_REG32; /* 32-bit register */
  128. typedef volatile CPU_INT64U CPU_REG64; /* 64-bit register */
  129. typedef void (*CPU_FNCT_VOID)(void); /* See Note #2a. */
  130. typedef void (*CPU_FNCT_PTR )(void *p_obj); /* See Note #2b. */
  131. /*
  132. *********************************************************************************************************
  133. * CPU WORD CONFIGURATION
  134. *
  135. * Note(s) : (1) Configure CPU_CFG_ADDR_SIZE, CPU_CFG_DATA_SIZE, & CPU_CFG_DATA_SIZE_MAX with CPU's &/or
  136. * compiler's word sizes :
  137. *
  138. * CPU_WORD_SIZE_08 8-bit word size
  139. * CPU_WORD_SIZE_16 16-bit word size
  140. * CPU_WORD_SIZE_32 32-bit word size
  141. * CPU_WORD_SIZE_64 64-bit word size
  142. *
  143. * (2) Configure CPU_CFG_ENDIAN_TYPE with CPU's data-word-memory order :
  144. *
  145. * (a) CPU_ENDIAN_TYPE_BIG Big- endian word order (CPU words' most significant
  146. * octet @ lowest memory address)
  147. * (b) CPU_ENDIAN_TYPE_LITTLE Little-endian word order (CPU words' least significant
  148. * octet @ lowest memory address)
  149. *********************************************************************************************************
  150. */
  151. /* Define CPU word sizes (see Note #1) : */
  152. #define CPU_CFG_ADDR_SIZE CPU_WORD_SIZE_32 /* Defines CPU address word size (in octets). */
  153. #define CPU_CFG_DATA_SIZE CPU_WORD_SIZE_32 /* Defines CPU data word size (in octets). */
  154. #define CPU_CFG_DATA_SIZE_MAX CPU_WORD_SIZE_64 /* Defines CPU maximum word size (in octets). */
  155. #define CPU_CFG_ENDIAN_TYPE CPU_ENDIAN_TYPE_LITTLE /* Defines CPU data word-memory order (see Note #2). */
  156. /*
  157. *********************************************************************************************************
  158. * CONFIGURE CPU ADDRESS & DATA TYPES
  159. *********************************************************************************************************
  160. */
  161. /* CPU address type based on address bus size. */
  162. #if (CPU_CFG_ADDR_SIZE == CPU_WORD_SIZE_32)
  163. typedef CPU_INT32U CPU_ADDR;
  164. #elif (CPU_CFG_ADDR_SIZE == CPU_WORD_SIZE_16)
  165. typedef CPU_INT16U CPU_ADDR;
  166. #else
  167. typedef CPU_INT08U CPU_ADDR;
  168. #endif
  169. /* CPU data type based on data bus size. */
  170. #if (CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_32)
  171. typedef CPU_INT32U CPU_DATA;
  172. #elif (CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_16)
  173. typedef CPU_INT16U CPU_DATA;
  174. #else
  175. typedef CPU_INT08U CPU_DATA;
  176. #endif
  177. typedef CPU_DATA CPU_ALIGN; /* Defines CPU data-word-alignment size. */
  178. typedef CPU_ADDR CPU_SIZE_T; /* Defines CPU standard 'size_t' size. */
  179. /*
  180. *********************************************************************************************************
  181. * CPU STACK CONFIGURATION
  182. *
  183. * Note(s) : (1) Configure CPU_CFG_STK_GROWTH in 'cpu.h' with CPU's stack growth order :
  184. *
  185. * (a) CPU_STK_GROWTH_LO_TO_HI CPU stack pointer increments to the next higher stack
  186. * memory address after data is pushed onto the stack
  187. * (b) CPU_STK_GROWTH_HI_TO_LO CPU stack pointer decrements to the next lower stack
  188. * memory address after data is pushed onto the stack
  189. *
  190. * (2) Configure CPU_CFG_STK_ALIGN_BYTES with the highest minimum alignement required for
  191. * cpu stacks.
  192. *
  193. * (a) ARM Procedure Calls Standard requires an 8 bytes stack alignment.
  194. *********************************************************************************************************
  195. */
  196. #define CPU_CFG_STK_GROWTH CPU_STK_GROWTH_HI_TO_LO /* Defines CPU stack growth order (see Note #1). */
  197. #define CPU_CFG_STK_ALIGN_BYTES (8u) /* Defines CPU stack alignment in bytes. (see Note #2). */
  198. typedef CPU_INT32U CPU_STK; /* Defines CPU stack data type. */
  199. typedef CPU_ADDR CPU_STK_SIZE; /* Defines CPU stack size data type. */
  200. /*
  201. *********************************************************************************************************
  202. * CRITICAL SECTION CONFIGURATION
  203. *
  204. * Note(s) : (1) Configure CPU_CFG_CRITICAL_METHOD with CPU's/compiler's critical section method :
  205. *
  206. * Enter/Exit critical sections by ...
  207. *
  208. * CPU_CRITICAL_METHOD_INT_DIS_EN Disable/Enable interrupts
  209. * CPU_CRITICAL_METHOD_STATUS_STK Push/Pop interrupt status onto stack
  210. * CPU_CRITICAL_METHOD_STATUS_LOCAL Save/Restore interrupt status to local variable
  211. *
  212. * (a) CPU_CRITICAL_METHOD_INT_DIS_EN is NOT a preferred method since it does NOT support
  213. * multiple levels of interrupts. However, with some CPUs/compilers, this is the only
  214. * available method.
  215. *
  216. * (b) CPU_CRITICAL_METHOD_STATUS_STK is one preferred method since it supports multiple
  217. * levels of interrupts. However, this method assumes that the compiler provides C-level
  218. * &/or assembly-level functionality for the following :
  219. *
  220. * ENTER CRITICAL SECTION :
  221. * (1) Push/save interrupt status onto a local stack
  222. * (2) Disable interrupts
  223. *
  224. * EXIT CRITICAL SECTION :
  225. * (3) Pop/restore interrupt status from a local stack
  226. *
  227. * (c) CPU_CRITICAL_METHOD_STATUS_LOCAL is one preferred method since it supports multiple
  228. * levels of interrupts. However, this method assumes that the compiler provides C-level
  229. * &/or assembly-level functionality for the following :
  230. *
  231. * ENTER CRITICAL SECTION :
  232. * (1) Save interrupt status into a local variable
  233. * (2) Disable interrupts
  234. *
  235. * EXIT CRITICAL SECTION :
  236. * (3) Restore interrupt status from a local variable
  237. *
  238. * (2) Critical section macro's most likely require inline assembly. If the compiler does NOT
  239. * allow inline assembly in C source files, critical section macro's MUST call an assembly
  240. * subroutine defined in a 'cpu_a.asm' file located in the following software directory :
  241. *
  242. * \<CPU-Compiler Directory>\<cpu>\<compiler>\
  243. *
  244. * where
  245. * <CPU-Compiler Directory> directory path for common CPU-compiler software
  246. * <cpu> directory name for specific CPU
  247. * <compiler> directory name for specific compiler
  248. *
  249. * (3) (a) To save/restore interrupt status, a local variable 'cpu_sr' of type 'CPU_SR' MAY need
  250. * to be declared (e.g. if 'CPU_CRITICAL_METHOD_STATUS_LOCAL' method is configured).
  251. *
  252. * (1) 'cpu_sr' local variable SHOULD be declared via the CPU_SR_ALLOC() macro which, if
  253. * used, MUST be declared following ALL other local variables.
  254. *
  255. * Example :
  256. *
  257. * void Fnct (void)
  258. * {
  259. * CPU_INT08U val_08;
  260. * CPU_INT16U val_16;
  261. * CPU_INT32U val_32;
  262. * CPU_SR_ALLOC(); MUST be declared after ALL other local variables
  263. * :
  264. * :
  265. * }
  266. *
  267. * (b) Configure 'CPU_SR' data type with the appropriate-sized CPU data type large enough to
  268. * completely store the CPU's/compiler's status word.
  269. *********************************************************************************************************
  270. */
  271. /* Configure CPU critical method (see Note #1) : */
  272. #define CPU_CFG_CRITICAL_METHOD CPU_CRITICAL_METHOD_STATUS_LOCAL
  273. typedef CPU_INT32U CPU_SR; /* Defines CPU status register size (see Note #3b). */
  274. /* Allocates CPU status register word (see Note #3a). */
  275. #if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
  276. #define CPU_SR_ALLOC() CPU_SR cpu_sr = (CPU_SR)0
  277. #else
  278. #define CPU_SR_ALLOC()
  279. #endif
  280. /* Save CPU status word & disable interrupts.*/
  281. #define CPU_INT_DIS() do { cpu_sr = __get_PRIMASK(); __disable_interrupt(); } while (0)
  282. #define CPU_INT_EN() do { __set_PRIMASK(cpu_sr); } while (0) /* Restore CPU status word. */
  283. #ifdef CPU_CFG_INT_DIS_MEAS_EN
  284. /* Disable interrupts, ... */
  285. /* & start interrupts disabled time measurement.*/
  286. #define CPU_CRITICAL_ENTER() do { CPU_INT_DIS(); \
  287. CPU_IntDisMeasStart(); } while (0)
  288. /* Stop & measure interrupts disabled time, */
  289. /* ... & re-enable interrupts. */
  290. #define CPU_CRITICAL_EXIT() do { CPU_IntDisMeasStop(); \
  291. CPU_INT_EN(); } while (0)
  292. #else
  293. #define CPU_CRITICAL_ENTER() do { CPU_INT_DIS(); } while (0) /* Disable interrupts. */
  294. #define CPU_CRITICAL_EXIT() do { CPU_INT_EN(); } while (0) /* Re-enable interrupts. */
  295. #endif
  296. /*
  297. *********************************************************************************************************
  298. * MEMORY BARRIERS CONFIGURATION
  299. *
  300. * Note(s) : (1) (a) Configure memory barriers if required by the architecture.
  301. *
  302. * CPU_MB Full memory barrier.
  303. * CPU_RMB Read (Loads) memory barrier.
  304. * CPU_WMB Write (Stores) memory barrier.
  305. *
  306. *********************************************************************************************************
  307. */
  308. #define CPU_MB() __DSB()
  309. #define CPU_RMB() __DSB()
  310. #define CPU_WMB() __DSB()
  311. /*
  312. *********************************************************************************************************
  313. * CPU COUNT ZEROS CONFIGURATION
  314. *
  315. * Note(s) : (1) (a) Configure CPU_CFG_LEAD_ZEROS_ASM_PRESENT to define count leading zeros bits
  316. * function(s) in :
  317. *
  318. * (1) 'cpu_a.asm', if CPU_CFG_LEAD_ZEROS_ASM_PRESENT #define'd in 'cpu.h'/
  319. * 'cpu_cfg.h' to enable assembly-optimized function(s)
  320. *
  321. * (2) 'cpu_core.c', if CPU_CFG_LEAD_ZEROS_ASM_PRESENT NOT #define'd in 'cpu.h'/
  322. * 'cpu_cfg.h' to enable C-source-optimized function(s) otherwise
  323. *
  324. * (b) Configure CPU_CFG_TRAIL_ZEROS_ASM_PRESENT to define count trailing zeros bits
  325. * function(s) in :
  326. *
  327. * (1) 'cpu_a.asm', if CPU_CFG_TRAIL_ZEROS_ASM_PRESENT #define'd in 'cpu.h'/
  328. * 'cpu_cfg.h' to enable assembly-optimized function(s)
  329. *
  330. * (2) 'cpu_core.c', if CPU_CFG_TRAIL_ZEROS_ASM_PRESENT NOT #define'd in 'cpu.h'/
  331. * 'cpu_cfg.h' to enable C-source-optimized function(s) otherwise
  332. *********************************************************************************************************
  333. */
  334. /* Configure CPU count leading zeros bits ... */
  335. #define CPU_CFG_LEAD_ZEROS_ASM_PRESENT /* ... assembly-version (see Note #1a). */
  336. /* Configure CPU count trailing zeros bits ... */
  337. #define CPU_CFG_TRAIL_ZEROS_ASM_PRESENT /* ... assembly-version (see Note #1b). */
  338. /*
  339. *********************************************************************************************************
  340. * FUNCTION PROTOTYPES
  341. *********************************************************************************************************
  342. */
  343. void CPU_IntDis (void);
  344. void CPU_IntEn (void);
  345. void CPU_IntSrcDis (CPU_INT08U pos);
  346. void CPU_IntSrcEn (CPU_INT08U pos);
  347. void CPU_IntSrcPendClr(CPU_INT08U pos);
  348. CPU_INT16S CPU_IntSrcPrioGet(CPU_INT08U pos);
  349. void CPU_IntSrcPrioSet(CPU_INT08U pos,
  350. CPU_INT08U prio);
  351. CPU_SR CPU_SR_Save (void);
  352. void CPU_SR_Restore (CPU_SR cpu_sr);
  353. void CPU_WaitForInt (void);
  354. void CPU_WaitForExcept(void);
  355. CPU_DATA CPU_RevBits (CPU_DATA val);
  356. void CPU_BitBandClr (CPU_ADDR addr,
  357. CPU_INT08U bit_nbr);
  358. void CPU_BitBandSet (CPU_ADDR addr,
  359. CPU_INT08U bit_nbr);
  360. /*
  361. *********************************************************************************************************
  362. * INTERRUPT SOURCES
  363. *********************************************************************************************************
  364. */
  365. #define CPU_INT_STK_PTR 0u
  366. #define CPU_INT_RESET 1u
  367. #define CPU_INT_NMI 2u
  368. #define CPU_INT_HFAULT 3u
  369. #define CPU_INT_MEM 4u
  370. #define CPU_INT_BUSFAULT 5u
  371. #define CPU_INT_USAGEFAULT 6u
  372. #define CPU_INT_RSVD_07 7u
  373. #define CPU_INT_RSVD_08 8u
  374. #define CPU_INT_RSVD_09 9u
  375. #define CPU_INT_RSVD_10 10u
  376. #define CPU_INT_SVCALL 11u
  377. #define CPU_INT_DBGMON 12u
  378. #define CPU_INT_RSVD_13 13u
  379. #define CPU_INT_PENDSV 14u
  380. #define CPU_INT_SYSTICK 15u
  381. #define CPU_INT_EXT0 16u
  382. /*
  383. *********************************************************************************************************
  384. * CPU REGISTERS
  385. *********************************************************************************************************
  386. */
  387. #define CPU_REG_NVIC_NVIC (*((CPU_REG32 *)(0xE000E004))) /* Int Ctrl'er Type Reg. */
  388. #define CPU_REG_NVIC_ST_CTRL (*((CPU_REG32 *)(0xE000E010))) /* SysTick Ctrl & Status Reg. */
  389. #define CPU_REG_NVIC_ST_RELOAD (*((CPU_REG32 *)(0xE000E014))) /* SysTick Reload Value Reg. */
  390. #define CPU_REG_NVIC_ST_CURRENT (*((CPU_REG32 *)(0xE000E018))) /* SysTick Current Value Reg. */
  391. #define CPU_REG_NVIC_ST_CAL (*((CPU_REG32 *)(0xE000E01C))) /* SysTick Calibration Value Reg. */
  392. #define CPU_REG_NVIC_SETEN(n) (*((CPU_REG32 *)(0xE000E100 + (n) * 4u))) /* IRQ Set En Reg. */
  393. #define CPU_REG_NVIC_CLREN(n) (*((CPU_REG32 *)(0xE000E180 + (n) * 4u))) /* IRQ Clr En Reg. */
  394. #define CPU_REG_NVIC_SETPEND(n) (*((CPU_REG32 *)(0xE000E200 + (n) * 4u))) /* IRQ Set Pending Reg. */
  395. #define CPU_REG_NVIC_CLRPEND(n) (*((CPU_REG32 *)(0xE000E280 + (n) * 4u))) /* IRQ Clr Pending Reg. */
  396. #define CPU_REG_NVIC_ACTIVE(n) (*((CPU_REG32 *)(0xE000E300 + (n) * 4u))) /* IRQ Active Reg. */
  397. #define CPU_REG_NVIC_PRIO(n) (*((CPU_REG32 *)(0xE000E400 + (n) * 4u))) /* IRQ Prio Reg. */
  398. #define CPU_REG_NVIC_CPUID (*((CPU_REG32 *)(0xE000ED00))) /* CPUID Base Reg. */
  399. #define CPU_REG_NVIC_ICSR (*((CPU_REG32 *)(0xE000ED04))) /* Int Ctrl State Reg. */
  400. #define CPU_REG_NVIC_VTOR (*((CPU_REG32 *)(0xE000ED08))) /* Vect Tbl Offset Reg. */
  401. #define CPU_REG_NVIC_AIRCR (*((CPU_REG32 *)(0xE000ED0C))) /* App Int/Reset Ctrl Reg. */
  402. #define CPU_REG_NVIC_SCR (*((CPU_REG32 *)(0xE000ED10))) /* System Ctrl Reg. */
  403. #define CPU_REG_NVIC_CCR (*((CPU_REG32 *)(0xE000ED14))) /* Cfg Ctrl Reg. */
  404. #define CPU_REG_NVIC_SHPRI1 (*((CPU_REG32 *)(0xE000ED18))) /* System Handlers 4 to 7 Prio. */
  405. #define CPU_REG_NVIC_SHPRI2 (*((CPU_REG32 *)(0xE000ED1C))) /* System Handlers 8 to 11 Prio. */
  406. #define CPU_REG_NVIC_SHPRI3 (*((CPU_REG32 *)(0xE000ED20))) /* System Handlers 12 to 15 Prio. */
  407. #define CPU_REG_NVIC_SHCSR (*((CPU_REG32 *)(0xE000ED24))) /* System Handler Ctrl & State Reg. */
  408. #define CPU_REG_NVIC_CFSR (*((CPU_REG32 *)(0xE000ED28))) /* Configurable Fault Status Reg. */
  409. #define CPU_REG_NVIC_HFSR (*((CPU_REG32 *)(0xE000ED2C))) /* Hard Fault Status Reg. */
  410. #define CPU_REG_NVIC_DFSR (*((CPU_REG32 *)(0xE000ED30))) /* Debug Fault Status Reg. */
  411. #define CPU_REG_NVIC_MMFAR (*((CPU_REG32 *)(0xE000ED34))) /* Mem Manage Addr Reg. */
  412. #define CPU_REG_NVIC_BFAR (*((CPU_REG32 *)(0xE000ED38))) /* Bus Fault Addr Reg. */
  413. #define CPU_REG_NVIC_AFSR (*((CPU_REG32 *)(0xE000ED3C))) /* Aux Fault Status Reg. */
  414. #define CPU_REG_NVIC_CPACR (*((CPU_REG32 *)(0xE000ED88))) /* Coprocessor Access Control Reg. */
  415. #define CPU_REG_NVIC_PFR0 (*((CPU_REG32 *)(0xE000ED40))) /* Processor Feature Reg 0. */
  416. #define CPU_REG_NVIC_PFR1 (*((CPU_REG32 *)(0xE000ED44))) /* Processor Feature Reg 1. */
  417. #define CPU_REG_NVIC_DFR0 (*((CPU_REG32 *)(0xE000ED48))) /* Debug Feature Reg 0. */
  418. #define CPU_REG_NVIC_AFR0 (*((CPU_REG32 *)(0xE000ED4C))) /* Aux Feature Reg 0. */
  419. #define CPU_REG_NVIC_MMFR0 (*((CPU_REG32 *)(0xE000ED50))) /* Memory Model Feature Reg 0. */
  420. #define CPU_REG_NVIC_MMFR1 (*((CPU_REG32 *)(0xE000ED54))) /* Memory Model Feature Reg 1. */
  421. #define CPU_REG_NVIC_MMFR2 (*((CPU_REG32 *)(0xE000ED58))) /* Memory Model Feature Reg 2. */
  422. #define CPU_REG_NVIC_MMFR3 (*((CPU_REG32 *)(0xE000ED5C))) /* Memory Model Feature Reg 3. */
  423. #define CPU_REG_NVIC_ISAFR0 (*((CPU_REG32 *)(0xE000ED60))) /* ISA Feature Reg 0. */
  424. #define CPU_REG_NVIC_ISAFR1 (*((CPU_REG32 *)(0xE000ED64))) /* ISA Feature Reg 1. */
  425. #define CPU_REG_NVIC_ISAFR2 (*((CPU_REG32 *)(0xE000ED68))) /* ISA Feature Reg 2. */
  426. #define CPU_REG_NVIC_ISAFR3 (*((CPU_REG32 *)(0xE000ED6C))) /* ISA Feature Reg 3. */
  427. #define CPU_REG_NVIC_ISAFR4 (*((CPU_REG32 *)(0xE000ED70))) /* ISA Feature Reg 4. */
  428. #define CPU_REG_NVIC_SW_TRIG (*((CPU_REG32 *)(0xE000EF00))) /* Software Trigger Int Reg. */
  429. #define CPU_REG_MPU_TYPE (*((CPU_REG32 *)(0xE000ED90))) /* MPU Type Reg. */
  430. #define CPU_REG_MPU_CTRL (*((CPU_REG32 *)(0xE000ED94))) /* MPU Ctrl Reg. */
  431. #define CPU_REG_MPU_REG_NBR (*((CPU_REG32 *)(0xE000ED98))) /* MPU Region Nbr Reg. */
  432. #define CPU_REG_MPU_REG_BASE (*((CPU_REG32 *)(0xE000ED9C))) /* MPU Region Base Addr Reg. */
  433. #define CPU_REG_MPU_REG_ATTR (*((CPU_REG32 *)(0xE000EDA0))) /* MPU Region Attrib & Size Reg. */
  434. #define CPU_REG_DBG_CTRL (*((CPU_REG32 *)(0xE000EDF0))) /* Debug Halting Ctrl & Status Reg. */
  435. #define CPU_REG_DBG_SELECT (*((CPU_REG32 *)(0xE000EDF4))) /* Debug Core Reg Selector Reg. */
  436. #define CPU_REG_DBG_DATA (*((CPU_REG32 *)(0xE000EDF8))) /* Debug Core Reg Data Reg. */
  437. #define CPU_REG_DBG_INT (*((CPU_REG32 *)(0xE000EDFC))) /* Debug Except & Monitor Ctrl Reg. */
  438. #define CPU_REG_SCB_FPCCR (*((CPU_REG32 *)(0xE000EF34))) /* Floating-Point Context Control Reg. */
  439. #define CPU_REG_SCB_FPCAR (*((CPU_REG32 *)(0xE000EF38))) /* Floating-Point Context Address Reg. */
  440. #define CPU_REG_SCB_FPDSCR (*((CPU_REG32 *)(0xE000EF3C))) /* FP Default Status Control Reg. */
  441. /*
  442. *********************************************************************************************************
  443. * CPU REGISTER BITS
  444. *********************************************************************************************************
  445. */
  446. /* ---------- SYSTICK CTRL & STATUS REG BITS ---------- */
  447. #define CPU_REG_NVIC_ST_CTRL_COUNTFLAG 0x00010000
  448. #define CPU_REG_NVIC_ST_CTRL_CLKSOURCE 0x00000004
  449. #define CPU_REG_NVIC_ST_CTRL_TICKINT 0x00000002
  450. #define CPU_REG_NVIC_ST_CTRL_ENABLE 0x00000001
  451. /* -------- SYSTICK CALIBRATION VALUE REG BITS -------- */
  452. #define CPU_REG_NVIC_ST_CAL_NOREF 0x80000000
  453. #define CPU_REG_NVIC_ST_CAL_SKEW 0x40000000
  454. /* -------------- INT CTRL STATE REG BITS ------------- */
  455. #define CPU_REG_NVIC_ICSR_NMIPENDSET 0x80000000
  456. #define CPU_REG_NVIC_ICSR_PENDSVSET 0x10000000
  457. #define CPU_REG_NVIC_ICSR_PENDSVCLR 0x08000000
  458. #define CPU_REG_NVIC_ICSR_PENDSTSET 0x04000000
  459. #define CPU_REG_NVIC_ICSR_PENDSTCLR 0x02000000
  460. #define CPU_REG_NVIC_ICSR_ISRPREEMPT 0x00800000
  461. #define CPU_REG_NVIC_ICSR_ISRPENDING 0x00400000
  462. #define CPU_REG_NVIC_ICSR_RETTOBASE 0x00000800
  463. /* ------------- VECT TBL OFFSET REG BITS ------------- */
  464. #define CPU_REG_NVIC_VTOR_TBLBASE 0x20000000
  465. /* ------------ APP INT/RESET CTRL REG BITS ----------- */
  466. #define CPU_REG_NVIC_AIRCR_ENDIANNESS 0x00008000
  467. #define CPU_REG_NVIC_AIRCR_SYSRESETREQ 0x00000004
  468. #define CPU_REG_NVIC_AIRCR_VECTCLRACTIVE 0x00000002
  469. #define CPU_REG_NVIC_AIRCR_VECTRESET 0x00000001
  470. /* --------------- SYSTEM CTRL REG BITS --------------- */
  471. #define CPU_REG_NVIC_SCR_SEVONPEND 0x00000010
  472. #define CPU_REG_NVIC_SCR_SLEEPDEEP 0x00000004
  473. #define CPU_REG_NVIC_SCR_SLEEPONEXIT 0x00000002
  474. /* ----------------- CFG CTRL REG BITS ---------------- */
  475. #define CPU_REG_NVIC_CCR_STKALIGN 0x00000200
  476. #define CPU_REG_NVIC_CCR_BFHFNMIGN 0x00000100
  477. #define CPU_REG_NVIC_CCR_DIV_0_TRP 0x00000010
  478. #define CPU_REG_NVIC_CCR_UNALIGN_TRP 0x00000008
  479. #define CPU_REG_NVIC_CCR_USERSETMPEND 0x00000002
  480. #define CPU_REG_NVIC_CCR_NONBASETHRDENA 0x00000001
  481. /* ------- SYSTEM HANDLER CTRL & STATE REG BITS ------- */
  482. #define CPU_REG_NVIC_SHCSR_USGFAULTENA 0x00040000
  483. #define CPU_REG_NVIC_SHCSR_BUSFAULTENA 0x00020000
  484. #define CPU_REG_NVIC_SHCSR_MEMFAULTENA 0x00010000
  485. #define CPU_REG_NVIC_SHCSR_SVCALLPENDED 0x00008000
  486. #define CPU_REG_NVIC_SHCSR_BUSFAULTPENDED 0x00004000
  487. #define CPU_REG_NVIC_SHCSR_MEMFAULTPENDED 0x00002000
  488. #define CPU_REG_NVIC_SHCSR_USGFAULTPENDED 0x00001000
  489. #define CPU_REG_NVIC_SHCSR_SYSTICKACT 0x00000800
  490. #define CPU_REG_NVIC_SHCSR_PENDSVACT 0x00000400
  491. #define CPU_REG_NVIC_SHCSR_MONITORACT 0x00000100
  492. #define CPU_REG_NVIC_SHCSR_SVCALLACT 0x00000080
  493. #define CPU_REG_NVIC_SHCSR_USGFAULTACT 0x00000008
  494. #define CPU_REG_NVIC_SHCSR_BUSFAULTACT 0x00000002
  495. #define CPU_REG_NVIC_SHCSR_MEMFAULTACT 0x00000001
  496. /* -------- CONFIGURABLE FAULT STATUS REG BITS -------- */
  497. #define CPU_REG_NVIC_CFSR_DIVBYZERO 0x02000000
  498. #define CPU_REG_NVIC_CFSR_UNALIGNED 0x01000000
  499. #define CPU_REG_NVIC_CFSR_NOCP 0x00080000
  500. #define CPU_REG_NVIC_CFSR_INVPC 0x00040000
  501. #define CPU_REG_NVIC_CFSR_INVSTATE 0x00020000
  502. #define CPU_REG_NVIC_CFSR_UNDEFINSTR 0x00010000
  503. #define CPU_REG_NVIC_CFSR_BFARVALID 0x00008000
  504. #define CPU_REG_NVIC_CFSR_STKERR 0x00001000
  505. #define CPU_REG_NVIC_CFSR_UNSTKERR 0x00000800
  506. #define CPU_REG_NVIC_CFSR_IMPRECISERR 0x00000400
  507. #define CPU_REG_NVIC_CFSR_PRECISERR 0x00000200
  508. #define CPU_REG_NVIC_CFSR_IBUSERR 0x00000100
  509. #define CPU_REG_NVIC_CFSR_MMARVALID 0x00000080
  510. #define CPU_REG_NVIC_CFSR_MSTKERR 0x00000010
  511. #define CPU_REG_NVIC_CFSR_MUNSTKERR 0x00000008
  512. #define CPU_REG_NVIC_CFSR_DACCVIOL 0x00000002
  513. #define CPU_REG_NVIC_CFSR_IACCVIOL 0x00000001
  514. /* ------------ HARD FAULT STATUS REG BITS ------------ */
  515. #define CPU_REG_NVIC_HFSR_DEBUGEVT 0x80000000
  516. #define CPU_REG_NVIC_HFSR_FORCED 0x40000000
  517. #define CPU_REG_NVIC_HFSR_VECTTBL 0x00000002
  518. /* ------------ DEBUG FAULT STATUS REG BITS ----------- */
  519. #define CPU_REG_NVIC_DFSR_EXTERNAL 0x00000010
  520. #define CPU_REG_NVIC_DFSR_VCATCH 0x00000008
  521. #define CPU_REG_NVIC_DFSR_DWTTRAP 0x00000004
  522. #define CPU_REG_NVIC_DFSR_BKPT 0x00000002
  523. #define CPU_REG_NVIC_DFSR_HALTED 0x00000001
  524. /* -------- COPROCESSOR ACCESS CONTROL REG BITS ------- */
  525. #define CPU_REG_NVIC_CPACR_CP10_FULL_ACCESS 0x00300000
  526. #define CPU_REG_NVIC_CPACR_CP11_FULL_ACCESS 0x00C00000
  527. /*
  528. *********************************************************************************************************
  529. * CPU REGISTER MASK
  530. *********************************************************************************************************
  531. */
  532. #define CPU_MSK_NVIC_ICSR_VECT_ACTIVE 0x000001FF
  533. /*
  534. *********************************************************************************************************
  535. * CONFIGURATION ERRORS
  536. *********************************************************************************************************
  537. */
  538. #ifndef CPU_CFG_ADDR_SIZE
  539. #error "CPU_CFG_ADDR_SIZE not #define'd in 'cpu.h' "
  540. #error " [MUST be CPU_WORD_SIZE_08 8-bit alignment]"
  541. #error " [ || CPU_WORD_SIZE_16 16-bit alignment]"
  542. #error " [ || CPU_WORD_SIZE_32 32-bit alignment]"
  543. #error " [ || CPU_WORD_SIZE_64 64-bit alignment]"
  544. #elif ((CPU_CFG_ADDR_SIZE != CPU_WORD_SIZE_08) && \
  545. (CPU_CFG_ADDR_SIZE != CPU_WORD_SIZE_16) && \
  546. (CPU_CFG_ADDR_SIZE != CPU_WORD_SIZE_32) && \
  547. (CPU_CFG_ADDR_SIZE != CPU_WORD_SIZE_64))
  548. #error "CPU_CFG_ADDR_SIZE illegally #define'd in 'cpu.h' "
  549. #error " [MUST be CPU_WORD_SIZE_08 8-bit alignment]"
  550. #error " [ || CPU_WORD_SIZE_16 16-bit alignment]"
  551. #error " [ || CPU_WORD_SIZE_32 32-bit alignment]"
  552. #error " [ || CPU_WORD_SIZE_64 64-bit alignment]"
  553. #endif
  554. #ifndef CPU_CFG_DATA_SIZE
  555. #error "CPU_CFG_DATA_SIZE not #define'd in 'cpu.h' "
  556. #error " [MUST be CPU_WORD_SIZE_08 8-bit alignment]"
  557. #error " [ || CPU_WORD_SIZE_16 16-bit alignment]"
  558. #error " [ || CPU_WORD_SIZE_32 32-bit alignment]"
  559. #error " [ || CPU_WORD_SIZE_64 64-bit alignment]"
  560. #elif ((CPU_CFG_DATA_SIZE != CPU_WORD_SIZE_08) && \
  561. (CPU_CFG_DATA_SIZE != CPU_WORD_SIZE_16) && \
  562. (CPU_CFG_DATA_SIZE != CPU_WORD_SIZE_32) && \
  563. (CPU_CFG_DATA_SIZE != CPU_WORD_SIZE_64))
  564. #error "CPU_CFG_DATA_SIZE illegally #define'd in 'cpu.h' "
  565. #error " [MUST be CPU_WORD_SIZE_08 8-bit alignment]"
  566. #error " [ || CPU_WORD_SIZE_16 16-bit alignment]"
  567. #error " [ || CPU_WORD_SIZE_32 32-bit alignment]"
  568. #error " [ || CPU_WORD_SIZE_64 64-bit alignment]"
  569. #endif
  570. #ifndef CPU_CFG_DATA_SIZE_MAX
  571. #error "CPU_CFG_DATA_SIZE_MAX not #define'd in 'cpu.h' "
  572. #error " [MUST be CPU_WORD_SIZE_08 8-bit alignment]"
  573. #error " [ || CPU_WORD_SIZE_16 16-bit alignment]"
  574. #error " [ || CPU_WORD_SIZE_32 32-bit alignment]"
  575. #error " [ || CPU_WORD_SIZE_64 64-bit alignment]"
  576. #elif ((CPU_CFG_DATA_SIZE_MAX != CPU_WORD_SIZE_08) && \
  577. (CPU_CFG_DATA_SIZE_MAX != CPU_WORD_SIZE_16) && \
  578. (CPU_CFG_DATA_SIZE_MAX != CPU_WORD_SIZE_32) && \
  579. (CPU_CFG_DATA_SIZE_MAX != CPU_WORD_SIZE_64))
  580. #error "CPU_CFG_DATA_SIZE_MAX illegally #define'd in 'cpu.h' "
  581. #error " [MUST be CPU_WORD_SIZE_08 8-bit alignment]"
  582. #error " [ || CPU_WORD_SIZE_16 16-bit alignment]"
  583. #error " [ || CPU_WORD_SIZE_32 32-bit alignment]"
  584. #error " [ || CPU_WORD_SIZE_64 64-bit alignment]"
  585. #endif
  586. #if (CPU_CFG_DATA_SIZE_MAX < CPU_CFG_DATA_SIZE)
  587. #error "CPU_CFG_DATA_SIZE_MAX illegally #define'd in 'cpu.h' "
  588. #error " [MUST be >= CPU_CFG_DATA_SIZE]"
  589. #endif
  590. #ifndef CPU_CFG_ENDIAN_TYPE
  591. #error "CPU_CFG_ENDIAN_TYPE not #define'd in 'cpu.h' "
  592. #error " [MUST be CPU_ENDIAN_TYPE_BIG ]"
  593. #error " [ || CPU_ENDIAN_TYPE_LITTLE]"
  594. #elif ((CPU_CFG_ENDIAN_TYPE != CPU_ENDIAN_TYPE_BIG ) && \
  595. (CPU_CFG_ENDIAN_TYPE != CPU_ENDIAN_TYPE_LITTLE))
  596. #error "CPU_CFG_ENDIAN_TYPE illegally #define'd in 'cpu.h' "
  597. #error " [MUST be CPU_ENDIAN_TYPE_BIG ]"
  598. #error " [ || CPU_ENDIAN_TYPE_LITTLE]"
  599. #endif
  600. #ifndef CPU_CFG_STK_GROWTH
  601. #error "CPU_CFG_STK_GROWTH not #define'd in 'cpu.h' "
  602. #error " [MUST be CPU_STK_GROWTH_LO_TO_HI]"
  603. #error " [ || CPU_STK_GROWTH_HI_TO_LO]"
  604. #elif ((CPU_CFG_STK_GROWTH != CPU_STK_GROWTH_LO_TO_HI) && \
  605. (CPU_CFG_STK_GROWTH != CPU_STK_GROWTH_HI_TO_LO))
  606. #error "CPU_CFG_STK_GROWTH illegally #define'd in 'cpu.h' "
  607. #error " [MUST be CPU_STK_GROWTH_LO_TO_HI]"
  608. #error " [ || CPU_STK_GROWTH_HI_TO_LO]"
  609. #endif
  610. #ifndef CPU_CFG_CRITICAL_METHOD
  611. #error "CPU_CFG_CRITICAL_METHOD not #define'd in 'cpu.h' "
  612. #error " [MUST be CPU_CRITICAL_METHOD_INT_DIS_EN ]"
  613. #error " [ || CPU_CRITICAL_METHOD_STATUS_STK ]"
  614. #error " [ || CPU_CRITICAL_METHOD_STATUS_LOCAL]"
  615. #elif ((CPU_CFG_CRITICAL_METHOD != CPU_CRITICAL_METHOD_INT_DIS_EN ) && \
  616. (CPU_CFG_CRITICAL_METHOD != CPU_CRITICAL_METHOD_STATUS_STK ) && \
  617. (CPU_CFG_CRITICAL_METHOD != CPU_CRITICAL_METHOD_STATUS_LOCAL))
  618. #error "CPU_CFG_CRITICAL_METHOD illegally #define'd in 'cpu.h' "
  619. #error " [MUST be CPU_CRITICAL_METHOD_INT_DIS_EN ]"
  620. #error " [ || CPU_CRITICAL_METHOD_STATUS_STK ]"
  621. #error " [ || CPU_CRITICAL_METHOD_STATUS_LOCAL]"
  622. #endif
  623. /*
  624. *********************************************************************************************************
  625. * MODULE END
  626. *
  627. * Note(s) : (1) See 'cpu.h MODULE'.
  628. *********************************************************************************************************
  629. */
  630. #ifdef __cplusplus
  631. }
  632. #endif
  633. #endif /* End of CPU module include. */