sys_mpu.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. /** @file sys_mpu.h
  2. * @brief System Mpu Header File
  3. * @date 29.May.2013
  4. * @version 03.05.02
  5. *
  6. * This file contains:
  7. * - Mpu Interface Functions
  8. * .
  9. * which are relevant for the memory protection unit driver.
  10. */
  11. /* (c) Texas Instruments 2009-2013, All rights reserved. */
  12. #ifndef __SYS_MPU_H__
  13. #define __SYS_MPU_H__
  14. #include "sys_common.h"
  15. /* USER CODE BEGIN (0) */
  16. /* USER CODE END */
  17. /** @def mpuREGION1
  18. * @brief Mpu region 1
  19. *
  20. * Alias for Mpu region 1
  21. */
  22. #define mpuREGION1 0U
  23. /** @def mpuREGION2
  24. * @brief Mpu region 2
  25. *
  26. * Alias for Mpu region 1
  27. */
  28. #define mpuREGION2 1U
  29. /** @def mpuREGION3
  30. * @brief Mpu region 3
  31. *
  32. * Alias for Mpu region 3
  33. */
  34. #define mpuREGION3 2U
  35. /** @def mpuREGION4
  36. * @brief Mpu region 4
  37. *
  38. * Alias for Mpu region 4
  39. */
  40. #define mpuREGION4 3U
  41. /** @def mpuREGION5
  42. * @brief Mpu region 5
  43. *
  44. * Alias for Mpu region 5
  45. */
  46. #define mpuREGION5 4U
  47. /** @def mpuREGION6
  48. * @brief Mpu region 6
  49. *
  50. * Alias for Mpu region 6
  51. */
  52. #define mpuREGION6 5U
  53. /** @def mpuREGION7
  54. * @brief Mpu region 7
  55. *
  56. * Alias for Mpu region 7
  57. */
  58. #define mpuREGION7 6U
  59. /** @def mpuREGION8
  60. * @brief Mpu region 8
  61. *
  62. * Alias for Mpu region 8
  63. */
  64. #define mpuREGION8 7U
  65. /** @def mpuREGION9
  66. * @brief Mpu region 9
  67. *
  68. * Alias for Mpu region 9
  69. */
  70. #define mpuREGION9 8U
  71. /** @def mpuREGION10
  72. * @brief Mpu region 10
  73. *
  74. * Alias for Mpu region 10
  75. */
  76. #define mpuREGION10 9U
  77. /** @def mpuREGION11
  78. * @brief Mpu region 11
  79. *
  80. * Alias for Mpu region 11
  81. */
  82. #define mpuREGION11 10U
  83. /** @def mpuREGION12
  84. * @brief Mpu region 12
  85. *
  86. * Alias for Mpu region 12
  87. */
  88. #define mpuREGION12 11U
  89. /** @enum mpuRegionAccessPermission
  90. * @brief Alias names for mpu region access permissions
  91. *
  92. * This enumeration is used to provide alias names for the mpu region access permission:
  93. * - MPU_PRIV_NA_USER_NA_EXEC no access in privileged mode, no access in user mode and execute
  94. * - MPU_PRIV_RW_USER_NA_EXEC read/write in privileged mode, no access in user mode and execute
  95. * - MPU_PRIV_RW_USER_RO_EXEC read/write in privileged mode, read only in user mode and execute
  96. * - MPU_PRIV_RW_USER_RW_EXEC read/write in privileged mode, read/write in user mode and execute
  97. * - MPU_PRIV_RO_USER_NA_EXEC read only in privileged mode, no access in user mode and execute
  98. * - MPU_PRIV_RO_USER_RO_EXEC read only in privileged mode, read only in user mode and execute
  99. * - MPU_PRIV_NA_USER_NA_NOEXEC no access in privileged mode, no access in user mode and no execution
  100. * - MPU_PRIV_RW_USER_NA_NOEXEC read/write in privileged mode, no access in user mode and no execution
  101. * - MPU_PRIV_RW_USER_RO_NOEXEC read/write in privileged mode, read only in user mode and no execution
  102. * - MPU_PRIV_RW_USER_RW_NOEXEC read/write in privileged mode, read/write in user mode and no execution
  103. * - MPU_PRIV_RO_USER_NA_NOEXEC read only in privileged mode, no access in user mode and no execution
  104. * - MPU_PRIV_RO_USER_RO_NOEXEC read only in privileged mode, read only in user mode and no execution
  105. *
  106. */
  107. enum mpuRegionAccessPermission
  108. {
  109. MPU_PRIV_NA_USER_NA_EXEC = 0x0000U, /**< Alias no access in privileged mode, no access in user mode and execute */
  110. MPU_PRIV_RW_USER_NA_EXEC = 0x0100U, /**< Alias no read/write in privileged mode, no access in user mode and execute */
  111. MPU_PRIV_RW_USER_RO_EXEC = 0x0200U, /**< Alias no read/write in privileged mode, read only in user mode and execute */
  112. MPU_PRIV_RW_USER_RW_EXEC = 0x0300U, /**< Alias no read/write in privileged mode, read/write in user mode and execute */
  113. MPU_PRIV_RO_USER_NA_EXEC = 0x0500U, /**< Alias no read only in privileged mode, no access in user mode and execute */
  114. MPU_PRIV_RO_USER_RO_EXEC = 0x0600U, /**< Alias no read only in privileged mode, read only in user mode and execute */
  115. MPU_PRIV_NA_USER_NA_NOEXEC = 0x1000U, /**< Alias no access in privileged mode, no access in user mode and no execution */
  116. MPU_PRIV_RW_USER_NA_NOEXEC = 0x1100U, /**< Alias no read/write in privileged mode, no access in user mode and no execution */
  117. MPU_PRIV_RW_USER_RO_NOEXEC = 0x1200U, /**< Alias no read/write in privileged mode, read only in user mode and no execution */
  118. MPU_PRIV_RW_USER_RW_NOEXEC = 0x1300U, /**< Alias no read/write in privileged mode, read/write in user mode and no execution */
  119. MPU_PRIV_RO_USER_NA_NOEXEC = 0x1500U, /**< Alias no read only in privileged mode, no access in user mode and no execution */
  120. MPU_PRIV_RO_USER_RO_NOEXEC = 0x1600U /**< Alias no read only in privileged mode, read only in user mode and no execution */
  121. };
  122. /** @enum mpuRegionType
  123. * @brief Alias names for mpu region type
  124. *
  125. * This enumeration is used to provide alias names for the mpu region type:
  126. * - MPU_STRONGLYORDERED_SHAREABLE Memory type strongly ordered and sharable
  127. * - MPU_DEVICE_SHAREABLE Memory type device and sharable
  128. * - MPU_NORMAL_OIWTNOWA_NONSHARED Memory type normal outer and inner write-through, no write allocate and non shared
  129. * - MPU_NORMAL_OIWTNOWA_SHARED Memory type normal outer and inner write-through, no write allocate and shared
  130. * - MPU_NORMAL_OIWBNOWA_NONSHARED Memory type normal outer and inner write-back, no write allocate and non shared
  131. * - MPU_NORMAL_OIWBNOWA_SHARED Memory type normal outer and inner write-back, no write allocate and shared
  132. * - MPU_NORMAL_OINC_NONSHARED Memory type normal outer and inner non-cachable and non shared
  133. * - MPU_NORMAL_OINC_SHARED Memory type normal outer and inner non-cachable and shared
  134. * - MPU_NORMAL_OIWBWA_NONSHARED Memory type normal outer and inner write-back, write allocate and non shared
  135. * - MPU_NORMAL_OIWBWA_SHARED Memory type normal outer and inner write-back, write allocate and shared
  136. * - MPU_DEVICE_NONSHAREABLE Memory type device and non sharable
  137. */
  138. enum mpuRegionType
  139. {
  140. MPU_STRONGLYORDERED_SHAREABLE = 0x0000U, /**< Memory type strongly ordered and sharable */
  141. MPU_DEVICE_SHAREABLE = 0x0001U, /**< Memory type device and sharable */
  142. MPU_NORMAL_OIWTNOWA_NONSHARED = 0x0002U, /**< Memory type normal outer and inner write-through, no write allocate and non shared */
  143. MPU_NORMAL_OIWBNOWA_NONSHARED = 0x0003U, /**< Memory type normal outer and inner write-back, no write allocate and non shared */
  144. MPU_NORMAL_OIWTNOWA_SHARED = 0x0006U, /**< Memory type normal outer and inner write-through, no write allocate and shared */
  145. MPU_NORMAL_OIWBNOWA_SHARED = 0x0007U, /**< Memory type normal outer and inner write-back, no write allocate and shared */
  146. MPU_NORMAL_OINC_NONSHARED = 0x0008U, /**< Memory type normal outer and inner non-cachable and non shared */
  147. MPU_NORMAL_OIWBWA_NONSHARED = 0x000BU, /**< Memory type normal outer and inner write-back, write allocate and non shared */
  148. MPU_NORMAL_OINC_SHARED = 0x000CU, /**< Memory type normal outer and inner non-cachable and shared */
  149. MPU_NORMAL_OIWBWA_SHARED = 0x000FU, /**< Memory type normal outer and inner write-back, write allocate and shared */
  150. MPU_DEVICE_NONSHAREABLE = 0x0010U /**< Memory type device and non sharable */
  151. };
  152. /** @enum mpuRegionSize
  153. * @brief Alias names for mpu region type
  154. *
  155. * This enumeration is used to provide alias names for the mpu region type:
  156. * - MPU_STRONGLYORDERED_SHAREABLE Memory type strongly ordered and sharable
  157. * - MPU_32_BYTES Memory size in bytes
  158. * - MPU_64_BYTES Memory size in bytes
  159. * - MPU_128_BYTES Memory size in bytes
  160. * - MPU_256_BYTES Memory size in bytes
  161. * - MPU_512_BYTES Memory size in bytes
  162. * - MPU_1_KB Memory size in kB
  163. * - MPU_2_KB Memory size in kB
  164. * - MPU_4_KB Memory size in kB
  165. * - MPU_8_KB Memory size in kB
  166. * - MPU_16_KB Memory size in kB
  167. * - MPU_32_KB Memory size in kB
  168. * - MPU_64_KB Memory size in kB
  169. * - MPU_128_KB Memory size in kB
  170. * - MPU_256_KB Memory size in kB
  171. * - MPU_512_KB Memory size in kB
  172. * - MPU_1_MB Memory size in MB
  173. * - MPU_2_MB Memory size in MB
  174. * - MPU_4_MB Memory size in MB
  175. * - MPU_8_MBv Memory size in MB
  176. * - MPU_16_MB Memory size in MB
  177. * - MPU_32_MB Memory size in MB
  178. * - MPU_64_MB Memory size in MB
  179. * - MPU_128_MB Memory size in MB
  180. * - MPU_256_MB Memory size in MB
  181. * - MPU_512_MB Memory size in MB
  182. * - MPU_1_GB Memory size in GB
  183. * - MPU_2_GB Memory size in GB
  184. * - MPU_4_GB Memory size in GB
  185. */
  186. enum mpuRegionSize
  187. {
  188. MPU_32_BYTES = 0x04U, /**< Memory size in bytes */
  189. MPU_64_BYTES = 0x05U, /**< Memory size in bytes */
  190. MPU_128_BYTES = 0x06U, /**< Memory size in bytes */
  191. MPU_256_BYTES = 0x07U, /**< Memory size in bytes */
  192. MPU_512_BYTES = 0x08U, /**< Memory size in bytes */
  193. MPU_1_KB = 0x09U, /**< Memory size in kB */
  194. MPU_2_KB = 0x0AU, /**< Memory size in kB */
  195. MPU_4_KB = 0x0BU, /**< Memory size in kB */
  196. MPU_8_KB = 0x0CU, /**< Memory size in kB */
  197. MPU_16_KB = 0x0DU, /**< Memory size in kB */
  198. MPU_32_KB = 0x0EU, /**< Memory size in kB */
  199. MPU_64_KB = 0x0FU, /**< Memory size in kB */
  200. MPU_128_KB = 0x10U, /**< Memory size in kB */
  201. MPU_256_KB = 0x11U, /**< Memory size in kB */
  202. MPU_512_KB = 0x12U, /**< Memory size in kB */
  203. MPU_1_MB = 0x13U, /**< Memory size in MB */
  204. MPU_2_MB = 0x14U, /**< Memory size in MB */
  205. MPU_4_MB = 0x15U, /**< Memory size in MB */
  206. MPU_8_MB = 0x16U, /**< Memory size in MB */
  207. MPU_16_MB = 0x17U, /**< Memory size in MB */
  208. MPU_32_MB = 0x18U, /**< Memory size in MB */
  209. MPU_64_MB = 0x19U, /**< Memory size in MB */
  210. MPU_128_MB = 0x1AU, /**< Memory size in MB */
  211. MPU_256_MB = 0x1BU, /**< Memory size in MB */
  212. MPU_512_MB = 0x1CU, /**< Memory size in MB */
  213. MPU_1_GB = 0x1DU, /**< Memory size in GB */
  214. MPU_2_GB = 0x1EU, /**< Memory size in GB */
  215. MPU_4_GB = 0x1FU /**< Memory size in GB */
  216. };
  217. /** @fn void _mpuInit_(void)
  218. * @brief Initialize Mpu
  219. *
  220. * This function initializes memory protection unit.
  221. */
  222. void _mpuInit_(void);
  223. /** @fn void _mpuEnable_(void)
  224. * @brief Enable Mpu
  225. *
  226. * This function enables memory protection unit.
  227. */
  228. void _mpuEnable_(void);
  229. /** @fn void _mpuDisable_(void)
  230. * @brief Disable Mpu
  231. *
  232. * This function disables memory protection unit.
  233. */
  234. void _mpuDisable_(void);
  235. /** @fn void _mpuEnableBackgroundRegion_(void)
  236. * @brief Enable Mpu background region
  237. *
  238. * This function enables background region of the memory protection unit.
  239. */
  240. void _mpuEnableBackgroundRegion_(void);
  241. /** @fn void _mpuDisableBackgroundRegion_(void)
  242. * @brief Disable Mpu background region
  243. *
  244. * This function disables background region of the memory protection unit.
  245. */
  246. void _mpuDisableBackgroundRegion_(void);
  247. /** @fn uint32 _mpuGetNumberOfRegions_(void)
  248. * @brief Returns number of implemented Mpu regions
  249. * @return Number of implemented mpu regions
  250. *
  251. * This function returns the number of implemented mpu regions.
  252. */
  253. uint32 _mpuGetNumberOfRegions_(void);
  254. /** @fn uint32 _mpuAreRegionsSeparate_(void)
  255. * @brief Returns the type of the implemented mpu regions
  256. * @return Mpu type of regions
  257. *
  258. * This function returns 0 when mpu regions are of type unified otherwise regions are of type separate.
  259. */
  260. uint32 _mpuAreRegionsSeparate_(void);
  261. /** @fn void _mpuSetRegion_(uint32 region)
  262. * @brief Set mpu region number
  263. *
  264. * This function selects one of the implemented mpu regions.
  265. */
  266. void _mpuSetRegion_(uint32 region);
  267. /** @fn uint32 _mpuGetRegion_(void)
  268. * @brief Returns the currently selected mpu region
  269. * @return Mpu region number
  270. *
  271. * This function returns currently selected mpu region number.
  272. */
  273. uint32 _mpuGetRegion_(void);
  274. /** @fn void _mpuSetRegionBaseAddress_(uint32 address)
  275. * @brief Set base address of currently selected mpu region
  276. * @note The base address must always aligned with region size
  277. *
  278. * This function sets the base address of currently selected mpu region.
  279. */
  280. void _mpuSetRegionBaseAddress_(uint32 address);
  281. /** @fn uint32 _mpuGetRegionBaseAddress_(void)
  282. * @brief Returns base address of currently selected mpu region
  283. * @return Current base address of selected mpu region
  284. *
  285. * This function returns the base address of currently selected mpu region.
  286. */
  287. uint32 _mpuGetRegionBaseAddress_(void);
  288. /** @fn void _mpuSetRegionTypeAndPermission_(uint32 type, uint32 permission)
  289. * @brief Set type of currently selected mpu region
  290. *
  291. * This function sets the type of currently selected mpu region.
  292. */
  293. void _mpuSetRegionTypeAndPermission_(uint32 type, uint32 permission);
  294. /** @fn uint32 _mpuGetRegionType_(void)
  295. * @brief Returns the type of currently selected mpu region
  296. * @return Current type of selected mpu region
  297. *
  298. * This function returns the type of currently selected mpu region.
  299. */
  300. uint32 _mpuGetRegionType_(void);
  301. /** @fn uint32 _mpuGetRegionPermission_(void)
  302. * @brief Returns permission of currently selected mpu region
  303. * @return Current type of selected mpu region
  304. *
  305. * This function returns permission of currently selected mpu region.
  306. */
  307. uint32 _mpuGetRegionPermission_(void);
  308. /** @fn void _mpuSetRegionSizeRegister_(uint32 value)
  309. * @brief Set mpu region size register value
  310. *
  311. * This function sets mpu region size register value.
  312. */
  313. void _mpuSetRegionSizeRegister_(uint32 value);
  314. #endif