1 //*****************************************************************************
2 //
3 // hw_types.h - Common types and macros.
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 Firmware Development Package.
37 //
38 //*****************************************************************************
39 
40 #ifndef __HW_TYPES_H__
41 #define __HW_TYPES_H__
42 
43 //*****************************************************************************
44 //
45 // Define a boolean type, and values for true and false.
46 //
47 //*****************************************************************************
48 typedef unsigned char tBoolean;
49 
50 #ifndef true
51 #define true 1
52 #endif
53 
54 #ifndef false
55 #define false 0
56 #endif
57 
58 //*****************************************************************************
59 //
60 // Macros for hardware access, both direct and via the bit-band region.
61 //
62 //*****************************************************************************
63 #define HWREG(x)                                                              \
64         (*((volatile unsigned long *)(x)))
65 #define HWREGH(x)                                                             \
66         (*((volatile unsigned short *)(x)))
67 #define HWREGB(x)                                                             \
68         (*((volatile unsigned char *)(x)))
69 #define HWREGBITW(x, b)                                                       \
70         HWREG(((unsigned long)(x) & 0xF0000000) | 0x02000000 |                \
71               (((unsigned long)(x) & 0x000FFFFF) << 5) | ((b) << 2))
72 #define HWREGBITH(x, b)                                                       \
73         HWREGH(((unsigned long)(x) & 0xF0000000) | 0x02000000 |               \
74                (((unsigned long)(x) & 0x000FFFFF) << 5) | ((b) << 2))
75 #define HWREGBITB(x, b)                                                       \
76         HWREGB(((unsigned long)(x) & 0xF0000000) | 0x02000000 |               \
77                (((unsigned long)(x) & 0x000FFFFF) << 5) | ((b) << 2))
78 
79 //*****************************************************************************
80 //
81 // Helper Macros for determining silicon revisions, etc.
82 //
83 // These macros will be used by Driverlib at "run-time" to create necessary
84 // conditional code blocks that will allow a single version of the Driverlib
85 // "binary" code to support multiple(all) Stellaris silicon revisions.
86 //
87 // It is expected that these macros will be used inside of a standard 'C'
88 // conditional block of code, e.g.
89 //
90 //     if(CLASS_IS_SANDSTORM)
91 //     {
92 //         do some Sandstorm-class specific code here.
93 //     }
94 //
95 // By default, these macros will be defined as run-time checks of the
96 // appropriate register(s) to allow creation of run-time conditional code
97 // blocks for a common DriverLib across the entire Stellaris family.
98 //
99 // However, if code-space optimization is required, these macros can be "hard-
100 // coded" for a specific version of Stellaris silicon.  Many compilers will
101 // then detect the "hard-coded" conditionals, and appropriately optimize the
102 // code blocks, eliminating any "unreachable" code.  This would result in
103 // a smaller Driverlib, thus producing a smaller final application size, but
104 // at the cost of limiting the Driverlib binary to a specific Stellaris
105 // silicon revision.
106 //
107 //*****************************************************************************
108 #ifndef CLASS_IS_SANDSTORM
109 #define CLASS_IS_SANDSTORM                                                    \
110         (((HWREG(SYSCTL_DID0) & SYSCTL_DID0_VER_M) == SYSCTL_DID0_VER_0) ||   \
111          ((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_VER_M | SYSCTL_DID0_CLASS_M)) == \
112           (SYSCTL_DID0_VER_1 | SYSCTL_DID0_CLASS_SANDSTORM)))
113 #endif
114 
115 #ifndef CLASS_IS_FURY
116 #define CLASS_IS_FURY                                                        \
117         ((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_VER_M | SYSCTL_DID0_CLASS_M)) == \
118          (SYSCTL_DID0_VER_1 | SYSCTL_DID0_CLASS_FURY))
119 #endif
120 
121 #ifndef CLASS_IS_DUSTDEVIL
122 #define CLASS_IS_DUSTDEVIL                                                   \
123         ((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_VER_M | SYSCTL_DID0_CLASS_M)) == \
124          (SYSCTL_DID0_VER_1 | SYSCTL_DID0_CLASS_DUSTDEVIL))
125 #endif
126 
127 #ifndef CLASS_IS_TEMPEST
128 #define CLASS_IS_TEMPEST                                                     \
129         ((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_VER_M | SYSCTL_DID0_CLASS_M)) == \
130          (SYSCTL_DID0_VER_1 | SYSCTL_DID0_CLASS_TEMPEST))
131 #endif
132 
133 #ifndef CLASS_IS_FIRESTORM
134 #define CLASS_IS_FIRESTORM                                                   \
135         ((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_VER_M | SYSCTL_DID0_CLASS_M)) == \
136          (SYSCTL_DID0_VER_1 | SYSCTL_DID0_CLASS_FIRESTORM))
137 #endif
138 
139 #ifndef CLASS_IS_BLIZZARD
140 #define CLASS_IS_BLIZZARD                                                    \
141         ((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_VER_M | SYSCTL_DID0_CLASS_M)) == \
142          (SYSCTL_DID0_VER_1 | SYSCTL_DID0_CLASS_BLIZZARD))
143 #endif
144 
145 #ifndef REVISION_IS_A0
146 #define REVISION_IS_A0                                                     \
147         ((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_MAJ_M | SYSCTL_DID0_MIN_M)) == \
148          (SYSCTL_DID0_MAJ_REVA | SYSCTL_DID0_MIN_0))
149 #endif
150 
151 #ifndef REVISION_IS_A1
152 #define REVISION_IS_A1                                                     \
153         ((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_MAJ_M | SYSCTL_DID0_MIN_M)) == \
154          (SYSCTL_DID0_MAJ_REVA | SYSCTL_DID0_MIN_0))
155 #endif
156 
157 #ifndef REVISION_IS_A2
158 #define REVISION_IS_A2                                                     \
159         ((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_MAJ_M | SYSCTL_DID0_MIN_M)) == \
160          (SYSCTL_DID0_MAJ_REVA | SYSCTL_DID0_MIN_2))
161 #endif
162 
163 #ifndef REVISION_IS_B0
164 #define REVISION_IS_B0                                                     \
165         ((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_MAJ_M | SYSCTL_DID0_MIN_M)) == \
166          (SYSCTL_DID0_MAJ_REVB | SYSCTL_DID0_MIN_0))
167 #endif
168 
169 #ifndef REVISION_IS_B1
170 #define REVISION_IS_B1                                                     \
171         ((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_MAJ_M | SYSCTL_DID0_MIN_M)) == \
172          (SYSCTL_DID0_MAJ_REVB | SYSCTL_DID0_MIN_1))
173 #endif
174 
175 #ifndef REVISION_IS_C0
176 #define REVISION_IS_C0                                                     \
177         ((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_MAJ_M | SYSCTL_DID0_MIN_M)) == \
178          (SYSCTL_DID0_MAJ_REVC | SYSCTL_DID0_MIN_0))
179 #endif
180 
181 #ifndef REVISION_IS_C1
182 #define REVISION_IS_C1                                                     \
183         ((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_MAJ_M | SYSCTL_DID0_MIN_M)) == \
184          (SYSCTL_DID0_MAJ_REVC | SYSCTL_DID0_MIN_1))
185 #endif
186 
187 #ifndef REVISION_IS_C2
188 #define REVISION_IS_C2                                                     \
189         ((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_MAJ_M | SYSCTL_DID0_MIN_M)) == \
190          (SYSCTL_DID0_MAJ_REVC | SYSCTL_DID0_MIN_2))
191 #endif
192 
193 #ifndef REVISION_IS_C3
194 #define REVISION_IS_C3                                                     \
195         ((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_MAJ_M | SYSCTL_DID0_MIN_M)) == \
196          (SYSCTL_DID0_MAJ_REVC | SYSCTL_DID0_MIN_3))
197 #endif
198 
199 #ifndef REVISION_IS_C5
200 #define REVISION_IS_C5                                                     \
201         ((HWREG(SYSCTL_DID0) & (SYSCTL_DID0_MAJ_M | SYSCTL_DID0_MIN_M)) == \
202          (SYSCTL_DID0_MAJ_REVC | SYSCTL_DID0_MIN_5))
203 #endif
204 
205 //*****************************************************************************
206 //
207 // Deprecated silicon class and revision detection macros.
208 //
209 //*****************************************************************************
210 #ifndef DEPRECATED
211 #define DEVICE_IS_SANDSTORM     CLASS_IS_SANDSTORM
212 #define DEVICE_IS_FURY          CLASS_IS_FURY
213 #define DEVICE_IS_REVA2         REVISION_IS_A2
214 #define DEVICE_IS_REVC1         REVISION_IS_C1
215 #define DEVICE_IS_REVC2         REVISION_IS_C2
216 #endif
217 
218 #endif // __HW_TYPES_H__
219