source: rtems/c/src/lib/libbsp/arm/beagle/include/bsp.h @ 1c0663b4

4.115
Last change on this file since 1c0663b4 was d4edbdbc, checked in by Sebastian Huber <sebastian.huber@…>, on 03/20/15 at 13:09:26

Replace www.rtems.com with www.rtems.org

  • Property mode set to 100644
File size: 8.5 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup arm_beagle
5 *
6 * @brief Global BSP definitions.
7 */
8
9/*
10 * Copyright (c) 2012 Claas Ziemke. All rights reserved.
11 *
12 *  Claas Ziemke
13 *  Kernerstrasse 11
14 *  70182 Stuttgart
15 *  Germany
16 *  <claas.ziemke@gmx.net>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.org/license/LICENSE.
21 *
22 * Modified by Ben Gras <beng@shrike-systems.com> to add lots
23 * of beagleboard/beaglebone definitions, delete lpc32xx specific
24 * ones, and merge with some other header files.
25 */
26
27#ifndef LIBBSP_ARM_BEAGLE_BSP_H
28#define LIBBSP_ARM_BEAGLE_BSP_H
29
30#include <bspopts.h>
31#include <stdint.h>
32#include <bsp/start.h>
33#include <bsp/default-initial-extension.h>
34
35#include <rtems.h>
36#include <rtems/irq-extension.h>
37
38#include <libcpu/omap3.h>
39#include <libcpu/am335x.h>
40
41#define BSP_FEATURE_IRQ_EXTENSION
42
43/* UART base clock frequency */
44#define UART_CLOCK     48000000
45
46/* Access memory-mapped I/O devices */
47#define mmio_read(a)    (*(volatile uint32_t *)(a))
48#define mmio_write(a,v) (*(volatile uint32_t *)(a) = (v))
49#define mmio_set(a,v)   mmio_write((a), mmio_read((a)) | (v))
50#define mmio_clear(a,v) mmio_write((a), mmio_read((a)) & ~(v))
51
52#define REG16(x)(*((volatile uint16_t *)(x)))
53#define REG(x)(*((volatile uint32_t *)(x)))
54#define BIT(x)(0x1 << x)
55
56#define udelay(u) rtems_task_wake_after(1 + ((u)/rtems_configuration_get_microseconds_per_tick()))
57
58/* Write a uint32_t value to a memory address. */
59static inline void
60write32(uint32_t address, uint32_t value)
61{
62    REG(address) = value;
63}
64
65/* Read an uint32_t from a memory address */
66static inline uint32_t
67read32(uint32_t address)
68{
69    return REG(address);
70}
71
72/* Set a 32 bits value depending on a mask */
73static inline void
74set32(uint32_t address, uint32_t mask, uint32_t value)
75{
76    uint32_t val;
77    val = read32(address);
78    /* clear the bits */
79    val &= ~(mask);
80    /* apply the value using the mask */
81    val |= (value & mask);
82    write32(address, val);
83}
84
85/* Write a uint16_t value to a memory address. */
86static inline void
87write16(uint32_t address, uint16_t value)
88{
89    REG16(address) = value;
90}
91
92/* Read an uint16_t from a memory address */
93static inline uint16_t
94read16(uint32_t address)
95{
96    return REG16(address);
97}
98
99/* Data synchronization barrier */
100static inline void dsb(void)
101{
102    asm volatile("dsb" : : : "memory");
103}
104
105/* Instruction synchronization barrier */
106static inline void isb(void)
107{
108    asm volatile("isb" : : : "memory");
109}
110
111/* flush data cache */
112static inline void flush_data_cache(void)
113{
114    asm volatile("mov r0, #0; mcr p15, #0, r0, c7, c10, #4" : : : "memory");
115}
116
117#define __arch_getb(a)      (*(volatile unsigned char *)(a))
118#define __arch_getw(a)      (*(volatile unsigned short *)(a))
119#define __arch_getl(a)      (*(volatile unsigned int *)(a))
120
121#define __arch_putb(v,a)    (*(volatile unsigned char *)(a) = (v))
122#define __arch_putw(v,a)    (*(volatile unsigned short *)(a) = (v))
123#define __arch_putl(v,a)    (*(volatile unsigned int *)(a) = (v))
124
125#define writeb(v,c) ({ unsigned char  __v = v; __arch_putb(__v,c); __v; })
126#define writew(v,c) ({ unsigned short __v = v; __arch_putw(__v,c); __v; })
127#define writel(v,c) ({ unsigned int __v = v; __arch_putl(__v,c); __v; })
128
129#define readb(c)  ({ unsigned char  __v = __arch_getb(c); __v; })
130#define readw(c)  ({ unsigned short __v = __arch_getw(c); __v; })
131#define readl(c)  ({ unsigned int __v = __arch_getl(c); __v; })
132
133#define SYSTEM_CLOCK_12       12000000
134#define SYSTEM_CLOCK_13       13000000
135#define SYSTEM_CLOCK_192      19200000
136#define SYSTEM_CLOCK_96       96000000
137
138#if !defined(IS_DM3730) && !defined(IS_AM335X)
139#error Unrecognized BSP configured.
140#endif
141
142#if IS_DM3730
143#define BSP_DEVICEMEM_START 0x48000000
144#define BSP_DEVICEMEM_END   0x5F000000
145#endif
146
147#if IS_AM335X
148#define BSP_DEVICEMEM_START 0x44000000
149#define BSP_DEVICEMEM_END   0x57000000
150#endif
151
152/* per-target uart config */
153#if IS_AM335X
154#define BSP_CONSOLE_UART        1
155#define BSP_CONSOLE_UART_BASE   BEAGLE_BASE_UART_1
156#define BSP_CONSOLE_UART_IRQ    OMAP3_UART1_IRQ
157#define BEAGLE_BASE_UART_1      0x44E09000
158#define BEAGLE_BASE_UART_2      0x48022000
159#define BEAGLE_BASE_UART_3      0x48024000
160#endif
161
162/* per-target uart config */
163#if IS_DM3730
164#define BSP_CONSOLE_UART        3
165#define BSP_CONSOLE_UART_BASE   BEAGLE_BASE_UART_3
166#define BSP_CONSOLE_UART_IRQ    OMAP3_UART3_IRQ
167#define BEAGLE_BASE_UART_1      0x4806A000
168#define BEAGLE_BASE_UART_2      0x4806C000
169#define BEAGLE_BASE_UART_3      0x49020000
170#endif
171
172/* i2c stuff */
173typedef struct {
174    uint32_t rx_or_tx;
175    uint32_t stat;
176    uint32_t ctrl;
177    uint32_t clk_hi;
178    uint32_t clk_lo;
179    uint32_t adr;
180    uint32_t rxfl;
181    uint32_t txfl;
182    uint32_t rxb;
183    uint32_t txb;
184    uint32_t s_tx;
185    uint32_t s_txfl;
186} beagle_i2c;
187
188/* sctlr */
189/* Read System Control Register */
190static inline uint32_t read_sctlr()
191{
192    uint32_t ctl;
193
194    asm volatile("mrc p15, 0, %[ctl], c1, c0, 0 @ Read SCTLR\n\t"
195        : [ctl] "=r" (ctl));
196    return ctl;
197}
198
199/* Write System Control Register */
200static inline void write_sctlr(uint32_t ctl)
201{
202    asm volatile("mcr p15, 0, %[ctl], c1, c0, 0 @ Write SCTLR\n\t"
203        : : [ctl] "r" (ctl));
204    isb();
205}
206
207/* Read Auxiliary Control Register */
208static inline uint32_t read_actlr()
209{
210    uint32_t ctl;
211
212    asm volatile("mrc p15, 0, %[ctl], c1, c0, 1 @ Read ACTLR\n\t"
213            : [ctl] "=r" (ctl));
214    return ctl;
215}
216
217/* Write Auxiliary Control Register */
218static inline void write_actlr(uint32_t ctl)
219{
220    asm volatile("mcr p15, 0, %[ctl], c1, c0, 1 @ Write ACTLR\n\t"
221        : : [ctl] "r" (ctl));
222    isb();
223}
224
225/* Write Translation Table Base Control Register */
226static inline void write_ttbcr(uint32_t bcr)
227{
228        asm volatile("mcr p15, 0, %[bcr], c2, c0, 2 @ Write TTBCR\n\t"
229                        : : [bcr] "r" (bcr));
230
231        isb();
232}
233
234/* Read Domain Access Control Register */
235static inline uint32_t read_dacr()
236{
237        uint32_t dacr;
238
239        asm volatile("mrc p15, 0, %[dacr], c3, c0, 0 @ Read DACR\n\t"
240                        : [dacr] "=r" (dacr));
241
242        return dacr;
243}
244
245
246/* Write Domain Access Control Register */
247static inline void write_dacr(uint32_t dacr)
248{
249        asm volatile("mcr p15, 0, %[dacr], c3, c0, 0 @ Write DACR\n\t"
250                        : : [dacr] "r" (dacr));
251
252        isb();
253}
254
255static inline void refresh_tlb(void)
256{
257    dsb();
258
259    /* Invalidate entire unified TLB */
260    asm volatile("mcr p15, 0, %[zero], c8, c7, 0 @ TLBIALL\n\t"
261        : : [zero] "r" (0));
262
263    /* Invalidate all instruction caches to PoU.
264     * Also flushes branch target cache. */
265    asm volatile("mcr p15, 0, %[zero], c7, c5, 0"
266        : : [zero] "r" (0));
267
268    /* Invalidate entire branch predictor array */
269    asm volatile("mcr p15, 0, %[zero], c7, c5, 6"
270        : : [zero] "r" (0)); /* flush BTB */
271
272    dsb();
273    isb();
274}
275
276/* Read Translation Table Base Register 0 */
277static inline uint32_t read_ttbr0()
278{
279    uint32_t bar;
280
281    asm volatile("mrc p15, 0, %[bar], c2, c0, 0 @ Read TTBR0\n\t"
282        : [bar] "=r" (bar));
283
284    return bar & ARM_TTBR_ADDR_MASK;
285}
286
287
288/* Read Translation Table Base Register 0 */
289static inline uint32_t read_ttbr0_unmasked()
290{
291    uint32_t bar;
292
293    asm volatile("mrc p15, 0, %[bar], c2, c0, 0 @ Read TTBR0\n\t"
294        : [bar] "=r" (bar));
295
296    return bar;
297}
298
299/* Write Translation Table Base Register 0 */
300static inline void write_ttbr0(uint32_t bar)
301{
302    dsb();
303    isb();
304    /* In our setup TTBR contains the base address *and* the flags
305       but other pieces of the kernel code expect ttbr to be the
306       base address of the l1 page table. We therefore add the
307       flags here and remove them in the read_ttbr0 */
308    uint32_t v  =  (bar  & ARM_TTBR_ADDR_MASK ) | ARM_TTBR_FLAGS_CACHED;
309    asm volatile("mcr p15, 0, %[bar], c2, c0, 0 @ Write TTBR0\n\t"
310        : : [bar] "r" (v));
311
312    refresh_tlb();
313}
314
315/* Behaviour on fatal error; default: test-friendly.
316 * set breakpoint to bsp_fatal_extension.
317 */
318/* Enabling BSP_PRESS_KEY_FOR_RESET prevents noninteractive testing */
319/*#define  BSP_PRESS_KEY_FOR_RESET     1 */
320#define    BSP_PRINT_EXCEPTION_CONTEXT 1
321    /* human-readable exception info */
322#define    BSP_RESET_BOARD_AT_EXIT 1
323    /* causes qemu to exit, signaling end of test */
324
325
326/**
327 * @defgroup arm_beagle Beaglebone, Beagleboard Support
328 *
329 * @ingroup bsp_arm
330 *
331 * @brief Beaglebones and beagleboards support package
332 *
333 */
334
335/**
336 * @brief Beagleboard specific set up of the MMU.
337 *
338 * Provide in the application to override.
339 */
340BSP_START_TEXT_SECTION void beagle_setup_mmu_and_cache(void);
341
342#endif /* LIBBSP_ARM_BEAGLE_BSP_H */
Note: See TracBrowser for help on using the repository browser.