aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/ports/TIVA/TM4C123x/hal_lld.h
blob: ec8180614e56823a1369683711db1c621959b07d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
/*
    Copyright (C) 2014..2016 Marco Veeneman

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

/**
 * @file    Tiva/TM4C123x/hal_lld.h
 * @brief   TM4C123x HAL subsystem low level driver header.
 * @pre     This module requires the following macros to be defined in the
 *          @p board.h file:
 *          - TODO: add required macros
 *
 * @addtogroup HAL
 * @{
 */

#ifndef HAL_LLD_H
#define HAL_LLD_H

#include "tiva_registry.h"

/*===========================================================================*/
/* Driver constants.                                                         */
/*===========================================================================*/

/**
 * @name    Platform identification
 * @{
 */
 
#define PLATFORM_NAME           "Tiva C Series TM4C123x"

/**
 * @}
 */

/**
 * @name    RCC register bits definitions
 * @{
 */

#define TIVA_RCC_MOSCDIS            (0x01 << 0)

#define TIVA_RCC_OSCSRC_MASK        (0x03 << 4)
#define TIVA_RCC_OSCSRC_MOSC        (0x00 << 4)
#define TIVA_RCC_OSCSRC_PIOSC       (0x01 << 4)
#define TIVA_RCC_OSCSRC_PIOSC_4     (0x02 << 4)
#define TIVA_RCC_OSCSRC_LFIOSC      (0x03 << 4)

#define TIVA_RCC_XTAL_MASK          (0x1f << 6)
#define TIVA_RCC_XTAL_4000000       (0x06 << 6)
#define TIVA_RCC_XTAL_4096000       (0x07 << 6)
#define TIVA_RCC_XTAL_4915200       (0x08 << 6)
#define TIVA_RCC_XTAL_5000000       (0x09 << 6)
#define TIVA_RCC_XTAL_5120000       (0x0a << 6)
#define TIVA_RCC_XTAL_6000000       (0x0b << 6)
#define TIVA_RCC_XTAL_6144000       (0x0c << 6)
#define TIVA_RCC_XTAL_7372800       (0x0d << 6)
#define TIVA_RCC_XTAL_8000000       (0x0e << 6)
#define TIVA_RCC_XTAL_8192000       (0x0f << 6)
#define TIVA_RCC_XTAL_10000000      (0x10 << 6)
#define TIVA_RCC_XTAL_12000000      (0x11 << 6)
#define TIVA_RCC_XTAL_12288000      (0x12 << 6)
#define TIVA_RCC_XTAL_13560000      (0x13 << 6)
#define TIVA_RCC_XTAL_14318180      (0x14 << 6)
#define TIVA_RCC_XTAL_16000000      (0x15 << 6)
#define TIVA_RCC_XTAL_16384000      (0x16 << 6)
#define TIVA_RCC_XTAL_18000000      (0x17 << 6)
#define TIVA_RCC_XTAL_20000000      (0x18 << 6)
#define TIVA_RCC_XTAL_24000000      (0x19 << 6)
#define TIVA_RCC_XTAL_25000000      (0x1a << 6)

#define TIVA_RCC_BYPASS             (1 << 11)

#define TIVA_RCC_PWRDN              (1 << 13)

#define TIVA_RCC_PWMDIV_MASK        (0x07 << 17)
#define TIVA_RCC_PWMDIV_2           (0x00 << 17)
#define TIVA_RCC_PWMDIV_4           (0x01 << 17)
#define TIVA_RCC_PWMDIV_8           (0x02 << 17)
#define TIVA_RCC_PWMDIV_16          (0x03 << 17)
#define TIVA_RCC_PWMDIV_32          (0x04 << 17)
#define TIVA_RCC_PWMDIV_64          (0x07 << 17)

#define TIVA_RCC_USEPWMDIV          (1 << 20)

#define TIVA_RCC_USESYSDIV	        (1 << 22)

#define TIVA_RCC_SYSDIV_MASK	    (0x0f << 23)
#define TIVA_RCC_SYSDIV_1           (0x00 << 23)
#define TIVA_RCC_SYSDIV_2           (0x01 << 23)
#define TIVA_RCC_SYSDIV_3           (0x02 << 23)
#define TIVA_RCC_SYSDIV_4           (0x03 << 23)
#define TIVA_RCC_SYSDIV_5           (0x04 << 23)
#define TIVA_RCC_SYSDIV_6           (0x05 << 23)
#define TIVA_RCC_SYSDIV_7           (0x06 << 23)
#define TIVA_RCC_SYSDIV_8           (0x07 << 23)
#define TIVA_RCC_SYSDIV_9           (0x08 << 23)
#define TIVA_RCC_SYSDIV_10          (0x09 << 23)
#define TIVA_RCC_SYSDIV_11          (0x0a << 23)
#define TIVA_RCC_SYSDIV_12          (0x0b << 23)
#define TIVA_RCC_SYSDIV_13          (0x0c << 23)
#define TIVA_RCC_SYSDIV_14          (0x0d << 23)
#define TIVA_RCC_SYSDIV_15          (0x0e << 23)
#define TIVA_RCC_SYSDIV_16          (0x0f << 23)

#define TIVA_RCC_ACG		        (1 << 27)

/**
 * @}
 */

/**
 * @name    RCC2 register bits definitions
 * @{
 */

#define TIVA_RCC2_OSCSRC2_MASK      (0x07 << 4)
#define TIVA_RCC2_OSCSRC2_MOSC      (0x00 << 4)
#define TIVA_RCC2_OSCSRC2_PIOSC     (0x01 << 4)
#define TIVA_RCC2_OSCSRC2_PIOSC_4   (0x02 << 4)
#define TIVA_RCC2_OSCSRC2_LFIOSC    (0x03 << 4)
#define TIVA_RCC2_OSCSRC2_32768     (0x07 << 4)

#define TIVA_RCC2_BYPASS2           (1 << 11)

#define TIVA_RCC2_PWRDN2            (1 << 13)

#define TIVA_RCC2_USBPWRDN          (1 << 14)

#define TIVA_RCC2_SYSDIV2LSB        (1 << 22)

#define TIVA_RCC2_SYSDIV2_MASK      (0x3f << 23)

#define TIVA_RCC2_DIV400            (1 << 30)

#define TIVA_RCC2_USERCC2           (1 << 31)

/**
 * @}
 */

/**
 * @name    RIS register bits definitions
 * @{
 */

#define SYSCTL_RIS_PLLLRIS	            (1 << 6)

/**
 * @}
 */

/*===========================================================================*/
/* Driver pre-compile time settings.                                         */
/*===========================================================================*/

/**
 * @name    Configuration options
 * @{
 */

#if !defined(TIVA_OSCSRC)
#define TIVA_OSCSRC                     TIVA_RCC2_OSCSRC2_MOSC
#endif

#if !defined(TIVA_MOSC_ENABLE)
#define TIVA_MOSC_ENABLE                TRUE
#endif

#if !defined(TIVA_DIV400_VALUE)
#define TIVA_DIV400_VALUE               1
#endif

#if !defined(TIVA_SYSDIV_VALUE)
#define TIVA_SYSDIV_VALUE               2
#endif

#if !defined(TIVA_USESYSDIV_ENABLE)
#define TIVA_USESYSDIV_ENABLE           FALSE
#endif

#if !defined(TIVA_SYSDIV2LSB_ENABLE)
#define TIVA_SYSDIV2LSB_ENABLE          FALSE
#endif

#if !defined(TIVA_BYPASS_VALUE)
#define TIVA_BYPASS_VALUE               0
#endif

/**
 * @}
 */

/*===========================================================================*/
/* Derived constants and error checks.                                       */
/*===========================================================================*/

/*
 * Configuration-related checks.
 */
#if !defined(TM4C123x_MCUCONF)
#error "Using a wrong mcuconf.h file, TM4C123x_MCUCONF not defined"
#endif

/*
 * Oscillator-related checks.
 */
#if !(TIVA_OSCSRC == TIVA_RCC2_OSCSRC2_MOSC) &&                                 \
    !(TIVA_OSCSRC == TIVA_RCC2_OSCSRC2_PIOSC) &&                                \
    !(TIVA_OSCSRC == TIVA_RCC2_OSCSRC2_PIOSC_4) &&                              \
    !(TIVA_OSCSRC == TIVA_RCC2_OSCSRC2_LFIOSC) &&                               \
    !(TIVA_OSCSRC == TIVA_RCC2_OSCSRC2_32768)
#error "Invalid value for TIVA_OSCSRC defined"
#endif

#if TIVA_XTAL_VALUE == 4000000
#define TIVA_XTAL_              (0x06 << 6)
#elif TIVA_XTAL_VALUE == 4096000
#define TIVA_XTAL_              (0x07 << 6)
#elif TIVA_XTAL_VALUE == 4915200
#define TIVA_XTAL_              (0x08 << 6)
#elif TIVA_XTAL_VALUE == 5000000
#define TIVA_XTAL_              (0x09 << 6)
#elif TIVA_XTAL_VALUE == 5120000
#define TIVA_XTAL_              (0x0a << 6)
#elif TIVA_XTAL_VALUE == 6000000
#define TIVA_XTAL_              (0x0b << 6)
#elif TIVA_XTAL_VALUE == 6144000
#define TIVA_XTAL_              (0x0c << 6)
#elif TIVA_XTAL_VALUE == 7372800
#define TIVA_XTAL_              (0x0d << 6)
#elif TIVA_XTAL_VALUE == 8000000
#define TIVA_XTAL_              (0x0e << 6)
#elif TIVA_XTAL_VALUE == 8192000
#define TIVA_XTAL_              (0x0f << 6)
#elif TIVA_XTAL_VALUE == 10000000
#define TIVA_XTAL_              (0x10 << 6)
#elif TIVA_XTAL_VALUE == 12000000
#define TIVA_XTAL_              (0x11 << 6)
#elif TIVA_XTAL_VALUE == 12288000
#define TIVA_XTAL_              (0x12 << 6)
#elif TIVA_XTAL_VALUE == 13560000
#define TIVA_XTAL_              (0x13 << 6)
#elif TIVA_XTAL_VALUE == 14318180
#define TIVA_XTAL_              (0x14 << 6)
#elif TIVA_XTAL_VALUE == 16000000
#define TIVA_XTAL_              (0x15 << 6)
#elif TIVA_XTAL_VALUE == 16384000
#define TIVA_XTAL_              (0x16 << 6)
#elif TIVA_XTAL_VALUE == 18000000
#define TIVA_XTAL_              (0x17 << 6)
#elif TIVA_XTAL_VALUE == 20000000
#define TIVA_XTAL_              (0x18 << 6)
#elif TIVA_XTAL_VALUE == 24000000
#define TIVA_XTAL_              (0x19 << 6)
#elif TIVA_XTAL_VALUE == 25000000
#define TIVA_XTAL_              (0x1a << 6)
#else
#error "Invalid value for TIVA_XTAL_VALUE defined"
#endif

#if TIVA_MOSC_ENABLE == TRUE
#define TIVA_MOSCDIS            (0 << 0)
#define TIVA_XTAL               TIVA_XTAL_
#elif TIVA_MOSC_ENABLE == FALSE
#define TIVA_MOSCDIS            (1 << 0)
#define TIVA_XTAL               0
#else
#error "Invalid value for TIVA_MOSC_ENABLE defined"
#endif

#if TIVA_DIV400_VALUE == 1
#define TIVA_DIV400             (1 << 30)
#elif TIVA_DIV400_VALUE == 0
#define TIVA_DIV400             (0 << 30)
#else
#error "Invalid value for TIVA_DIV400_VALUE defined"
#endif

#if (TIVA_SYSDIV_VALUE >= 0x02) && (TIVA_SYSDIV_VALUE <= 0x3f)
#define TIVA_SYSDIV             (TIVA_SYSDIV_VALUE << 23)
#define TIVA_SYSDIV2            (TIVA_SYSDIV_VALUE << 23)
#else
#error "Invalid value for TIVA_SYSDIV_VALUE defined"
#endif

#if TIVA_USESYSDIV_ENABLE == TRUE
#define TIVA_USESYSDIV          (1 << 22)
#elif TIVA_USESYSDIV_ENABLE == FALSE
#define TIVA_USESYSDIV          (0 << 22)
#else
#error "Invalid value for TIVA_USESYSDIV_ENABLE defined"
#endif

#if TIVA_SYSDIV2LSB_ENABLE == TRUE
#define TIVA_SYSDIV2LSB         (1 << 22)
#elif TIVA_SYSDIV2LSB_ENABLE == FALSE
#define TIVA_SYSDIV2LSB         (0 << 22)
#else
#error "Invalid value for TIVA_SYSDIV2LSB_ENABLE defined"
#endif

#if TIVA_BYPASS_VALUE == 1
#define TIVA_SRC                16000000
#elif TIVA_BYPASS_VALUE == 0
#define TIVA_SRC                (200000000 + (TIVA_DIV400_VALUE * 200000000))
#else
#error "Invalid value for TIVA_BYPASS_VALUE defined"
#endif

#if (TIVA_OSCSRC == TIVA_RCC_OSCSRC_MOSC) && (TIVA_MOSC_ENABLE == FALSE)
#error "Main Oscillator selected but not enabled"
#endif

/*
 * System Clock calculation 
 */
#define TIVA_SYSCLK             (TIVA_SRC / (((TIVA_SYSDIV_VALUE << TIVA_DIV400_VALUE /*& TIVA_BYPASS_VALUE*/) | (TIVA_SYSDIV2LSB >> 22)) + 1))

/*===========================================================================*/
/* Driver data structures and types.                                         */
/*===========================================================================*/

/*===========================================================================*/
/* Driver macros.                                                            */
/*===========================================================================*/

/*===========================================================================*/
/* External declarations.                                                    */
/*===========================================================================*/

/* Various helpers.*/
#include "nvic.h"
#include "tiva_isr.h"
#include "tiva_udma.h"

#ifdef __cplusplus
extern "C" {
#endif
  void hal_lld_init(void);
  void tiva_clock_init(void);
#ifdef __cplusplus
}
#endif

#endif /* HAL_LLD_H */

/**
 * @}
 */