source: rtems/c/src/lib/libbsp/arm/shared/include/arm-gic.h @ 936c8d6

4.115
Last change on this file since 936c8d6 was a91dc98b, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 26, 2013 at 1:06:32 PM

bsp/realview-pbx-a9: New BSP

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * Copyright (c) 2013 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <info@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.com/license/LICENSE.
13 */
14
15#ifndef LIBBSP_ARM_SHARED_ARM_GIC_H
16#define LIBBSP_ARM_SHARED_ARM_GIC_H
17
18#include <bsp/arm-gic-regs.h>
19
20#include <stdbool.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif /* __cplusplus */
25
26#define GIC_ID_TO_ONE_BIT_REG_INDEX(id) ((id) >> 5)
27#define GIC_ID_TO_ONE_BIT_REG_BIT(id) (1U << ((id) & 0x1fU))
28
29#define GIC_ID_TO_TWO_BITS_REG_INDEX(id) ((id) >> 4)
30#define GIC_ID_TO_TWO_BITS_REG_OFFSET(id) ((id) & 0xfU)
31
32static inline bool gic_id_is_enabled(volatile gic_dist *dist, uint32_t id)
33{
34  uint32_t i = GIC_ID_TO_ONE_BIT_REG_INDEX(id);
35  uint32_t bit = GIC_ID_TO_ONE_BIT_REG_BIT(id);
36
37  return (dist->icdiser[i] & bit) != 0;
38}
39
40static inline void gic_id_enable(volatile gic_dist *dist, uint32_t id)
41{
42  uint32_t i = GIC_ID_TO_ONE_BIT_REG_INDEX(id);
43  uint32_t bit = GIC_ID_TO_ONE_BIT_REG_BIT(id);
44
45  dist->icdiser[i] = bit;
46}
47
48static inline void gic_id_disable(volatile gic_dist *dist, uint32_t id)
49{
50  uint32_t i = GIC_ID_TO_ONE_BIT_REG_INDEX(id);
51  uint32_t bit = GIC_ID_TO_ONE_BIT_REG_BIT(id);
52
53  dist->icdicer[i] = bit;
54}
55
56static inline bool gic_id_is_pending(volatile gic_dist *dist, uint32_t id)
57{
58  uint32_t i = GIC_ID_TO_ONE_BIT_REG_INDEX(id);
59  uint32_t bit = GIC_ID_TO_ONE_BIT_REG_BIT(id);
60
61  return (dist->icdispr[i] & bit) != 0;
62}
63
64static inline void gic_id_set_pending(volatile gic_dist *dist, uint32_t id)
65{
66  uint32_t i = GIC_ID_TO_ONE_BIT_REG_INDEX(id);
67  uint32_t bit = GIC_ID_TO_ONE_BIT_REG_BIT(id);
68
69  dist->icdispr[i] = bit;
70}
71
72static inline void gic_id_clear_pending(volatile gic_dist *dist, uint32_t id)
73{
74  uint32_t i = GIC_ID_TO_ONE_BIT_REG_INDEX(id);
75  uint32_t bit = GIC_ID_TO_ONE_BIT_REG_BIT(id);
76
77  dist->icdicpr[i] = bit;
78}
79
80static inline bool gic_id_is_active(volatile gic_dist *dist, uint32_t id)
81{
82  uint32_t i = GIC_ID_TO_ONE_BIT_REG_INDEX(id);
83  uint32_t bit = GIC_ID_TO_ONE_BIT_REG_BIT(id);
84
85  return (dist->icdabr[i] & bit) != 0;
86}
87
88static inline void gic_id_set_priority(
89  volatile gic_dist *dist,
90  uint32_t id,
91  uint8_t priority
92)
93{
94  dist->icdipr[id] = priority;
95}
96
97static inline uint8_t gic_id_get_priority(volatile gic_dist *dist, uint32_t id)
98{
99  return dist->icdipr[id];
100}
101
102static inline void gic_id_set_targets(
103  volatile gic_dist *dist,
104  uint32_t id,
105  uint8_t targets
106)
107{
108  dist->icdiptr[id] = targets;
109}
110
111static inline uint8_t gic_id_get_targets(volatile gic_dist *dist, uint32_t id)
112{
113  return dist->icdiptr[id];
114}
115
116typedef enum {
117  GIC_LEVEL_SENSITIVE,
118  GIC_EDGE_TRIGGERED
119} gic_trigger_mode;
120
121static inline gic_trigger_mode gic_id_get_trigger_mode(
122  volatile gic_dist *dist,
123  uint32_t id
124)
125{
126  uint32_t i = GIC_ID_TO_TWO_BITS_REG_INDEX(id);
127  uint32_t o = GIC_ID_TO_TWO_BITS_REG_OFFSET(id) + 1;
128  uint32_t bit = 1U << o;
129
130  return dist->icdicfr[i] & bit;
131}
132
133static inline void gic_id_set_trigger_mode(
134  volatile gic_dist *dist,
135  uint32_t id,
136  gic_trigger_mode mode
137)
138{
139  uint32_t i = GIC_ID_TO_TWO_BITS_REG_INDEX(id);
140  uint32_t o = GIC_ID_TO_TWO_BITS_REG_OFFSET(id) + 1;
141  uint32_t bit = mode << o;
142  uint32_t mask = 1U << o;
143  uint32_t icdicfr = dist->icdicfr[i];
144
145  icdicfr &= ~mask;
146  icdicfr |= bit;
147
148  dist->icdicfr[i] = icdicfr;
149}
150
151typedef enum {
152  GIC_N_TO_N,
153  GIC_1_TO_N
154} gic_handling_model;
155
156static inline gic_handling_model gic_id_get_handling_model(
157  volatile gic_dist *dist,
158  uint32_t id
159)
160{
161  uint32_t i = GIC_ID_TO_TWO_BITS_REG_INDEX(id);
162  uint32_t o = GIC_ID_TO_TWO_BITS_REG_OFFSET(id);
163  uint32_t bit = 1U << o;
164
165  return dist->icdicfr[i] & bit;
166}
167
168static inline void gic_id_set_handling_model(
169  volatile gic_dist *dist,
170  uint32_t id,
171  gic_handling_model model
172)
173{
174  uint32_t i = GIC_ID_TO_TWO_BITS_REG_INDEX(id);
175  uint32_t o = GIC_ID_TO_TWO_BITS_REG_OFFSET(id);
176  uint32_t bit = model << o;
177  uint32_t mask = 1U << o;
178  uint32_t icdicfr = dist->icdicfr[i];
179
180  icdicfr &= ~mask;
181  icdicfr |= bit;
182
183  dist->icdicfr[i] = icdicfr;
184}
185
186#ifdef __cplusplus
187}
188#endif /* __cplusplus */
189
190#endif /* LIBBSP_ARM_SHARED_ARM_GIC_H */
Note: See TracBrowser for help on using the repository browser.