cpu.h 37 KB

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