1 //*****************************************************************************
2 //
3 // mpu.h - Defines and Macros for the memory protection unit.
4 //
5 // Copyright (c) 2005-2012 Texas Instruments Incorporated.  All rights reserved.
6 // Software License Agreement
7 //
8 //   Redistribution and use in source and binary forms, with or without
9 //   modification, are permitted provided that the following conditions
10 //   are met:
11 //
12 //   Redistributions of source code must retain the above copyright
13 //   notice, this list of conditions and the following disclaimer.
14 //
15 //   Redistributions in binary form must reproduce the above copyright
16 //   notice, this list of conditions and the following disclaimer in the
17 //   documentation and/or other materials provided with the
18 //   distribution.
19 //
20 //   Neither the name of Texas Instruments Incorporated nor the names of
21 //   its contributors may be used to endorse or promote products derived
22 //   from this software without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 //
36 // This is part of revision 9453 of the Stellaris Peripheral Driver Library.
37 //
38 //*****************************************************************************
39 
40 #ifndef __MPU_H__
41 #define __MPU_H__
42 
43 //*****************************************************************************
44 //
45 // If building with a C++ compiler, make all of the definitions in this header
46 // have a C binding.
47 //
48 //*****************************************************************************
49 #ifdef __cplusplus
50 extern "C"
51 {
52 #endif
53 
54 //*****************************************************************************
55 //
56 // Flags that can be passed to MPUEnable.
57 //
58 //*****************************************************************************
59 #define MPU_CONFIG_PRIV_DEFAULT     4
60 #define MPU_CONFIG_HARDFLT_NMI      2
61 #define MPU_CONFIG_NONE             0
62 
63 //*****************************************************************************
64 //
65 // Flags for the region size to be passed to MPURegionSet.
66 //
67 //*****************************************************************************
68 #define MPU_RGN_SIZE_32B            (4 << 1)
69 #define MPU_RGN_SIZE_64B            (5 << 1)
70 #define MPU_RGN_SIZE_128B           (6 << 1)
71 #define MPU_RGN_SIZE_256B           (7 << 1)
72 #define MPU_RGN_SIZE_512B           (8 << 1)
73 
74 #define MPU_RGN_SIZE_1K             (9 << 1)
75 #define MPU_RGN_SIZE_2K             (10 << 1)
76 #define MPU_RGN_SIZE_4K             (11 << 1)
77 #define MPU_RGN_SIZE_8K             (12 << 1)
78 #define MPU_RGN_SIZE_16K            (13 << 1)
79 #define MPU_RGN_SIZE_32K            (14 << 1)
80 #define MPU_RGN_SIZE_64K            (15 << 1)
81 #define MPU_RGN_SIZE_128K           (16 << 1)
82 #define MPU_RGN_SIZE_256K           (17 << 1)
83 #define MPU_RGN_SIZE_512K           (18 << 1)
84 
85 #define MPU_RGN_SIZE_1M             (19 << 1)
86 #define MPU_RGN_SIZE_2M             (20 << 1)
87 #define MPU_RGN_SIZE_4M             (21 << 1)
88 #define MPU_RGN_SIZE_8M             (22 << 1)
89 #define MPU_RGN_SIZE_16M            (23 << 1)
90 #define MPU_RGN_SIZE_32M            (24 << 1)
91 #define MPU_RGN_SIZE_64M            (25 << 1)
92 #define MPU_RGN_SIZE_128M           (26 << 1)
93 #define MPU_RGN_SIZE_256M           (27 << 1)
94 #define MPU_RGN_SIZE_512M           (28 << 1)
95 
96 #define MPU_RGN_SIZE_1G             (29 << 1)
97 #define MPU_RGN_SIZE_2G             (30 << 1)
98 #define MPU_RGN_SIZE_4G             (31 << 1)
99 
100 //*****************************************************************************
101 //
102 // Flags for the permissions to be passed to MPURegionSet.
103 //
104 //*****************************************************************************
105 #define MPU_RGN_PERM_EXEC           0x00000000
106 #define MPU_RGN_PERM_NOEXEC         0x10000000
107 #define MPU_RGN_PERM_PRV_NO_USR_NO  0x00000000
108 #define MPU_RGN_PERM_PRV_RW_USR_NO  0x01000000
109 #define MPU_RGN_PERM_PRV_RW_USR_RO  0x02000000
110 #define MPU_RGN_PERM_PRV_RW_USR_RW  0x03000000
111 #define MPU_RGN_PERM_PRV_RO_USR_NO  0x05000000
112 #define MPU_RGN_PERM_PRV_RO_USR_RO  0x06000000
113 
114 //*****************************************************************************
115 //
116 // Flags for the sub-region to be passed to MPURegionSet.
117 //
118 //*****************************************************************************
119 #define MPU_SUB_RGN_DISABLE_0       0x00000100
120 #define MPU_SUB_RGN_DISABLE_1       0x00000200
121 #define MPU_SUB_RGN_DISABLE_2       0x00000400
122 #define MPU_SUB_RGN_DISABLE_3       0x00000800
123 #define MPU_SUB_RGN_DISABLE_4       0x00001000
124 #define MPU_SUB_RGN_DISABLE_5       0x00002000
125 #define MPU_SUB_RGN_DISABLE_6       0x00004000
126 #define MPU_SUB_RGN_DISABLE_7       0x00008000
127 
128 //*****************************************************************************
129 //
130 // Flags to enable or disable a region, to be passed to MPURegionSet.
131 //
132 //*****************************************************************************
133 #define MPU_RGN_ENABLE              1
134 #define MPU_RGN_DISABLE             0
135 
136 //*****************************************************************************
137 //
138 // API Function prototypes
139 //
140 //*****************************************************************************
141 extern void MPUEnable(unsigned long ulMPUConfig);
142 extern void MPUDisable(void);
143 extern unsigned long MPURegionCountGet(void);
144 extern void MPURegionEnable(unsigned long ulRegion);
145 extern void MPURegionDisable(unsigned long ulRegion);
146 extern void MPURegionSet(unsigned long ulRegion, unsigned long ulAddr,
147                          unsigned long ulFlags);
148 extern void MPURegionGet(unsigned long ulRegion, unsigned long *pulAddr,
149                          unsigned long *pulFlags);
150 extern void MPUIntRegister(void (*pfnHandler)(void));
151 extern void MPUIntUnregister(void);
152 
153 //*****************************************************************************
154 //
155 // Mark the end of the C bindings section for C++ compilers.
156 //
157 //*****************************************************************************
158 #ifdef __cplusplus
159 }
160 #endif
161 
162 #endif //  __MPU_H__
163