TEMU  2
The Terma Emulator
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Amba.h
Go to the documentation of this file.
1 //===------------------------------------------------------------*- C++ -*-===//
2 //
3 // T-EMU: The Terma Emulator
4 // (c) Terma 2015
5 // Authors: Mattias Holm <maho (at) terma.com>
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef TEMU_BUS_AMBA_H
10 #define TEMU_BUS_AMBA_H
11 
19 #include "temu-c/Support/Objsys.h"
20 #include <stdint.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 
27 // Vendor constants
28 static const uint32_t teAMBA_VendorGaisler = 0x01;
29 static const uint32_t teAMBA_VendorPender = 0x02;
30 static const uint32_t teAMBA_VendorEsa = 0x04;
31 static const uint32_t teAMBA_VendorAstrium = 0x06;
32 static const uint32_t teAMBA_VendorOpenChip = 0x07;
33 static const uint32_t teAMBA_VendorOpenCores = 0x08;
34 static const uint32_t teAMBA_VendorVarious = 0x09;
35 static const uint32_t teAMBA_VendorDlr = 0x0a;
36 static const uint32_t teAMBA_VendorEonic = 0x0b;
37 static const uint32_t teAMBA_VendorParisTech = 0x0c;
38 static const uint32_t teAMBA_VendorRadionor = 0x0f;
39 static const uint32_t teAMBA_VendorGleichmann = 0x10;
40 static const uint32_t teAMBA_VendorMenta = 0x11;
41 static const uint32_t teAMBA_VendorSun = 0x13; // Oracle ?
42 static const uint32_t teAMBA_VendorMovidia = 0x14;
43 static const uint32_t teAMBA_VendorOrbita = 0x17;
44 static const uint32_t teAMBA_VendorSiemens = 0x1a;
45 static const uint32_t teAMBA_VendorActel = 0xac;
46 static const uint32_t teAMBA_VendorCaltech = 0xca;
47 static const uint32_t teAMBA_VendorEmbeddit = 0xea;
48 
49 
51 typedef struct {
52  uint32_t IdentReg;
53  uint32_t UserDef[3];
54  uint32_t Bar[4];
56 
64 typedef struct temu_AhbIface {
65  temu_AhbPnpInfo* (*getAhbPnp)(void *Obj);
67 #define TEMU_AHB_IFACE_TYPE "AhbIface"
69 
70 
72 typedef struct {
73  uint32_t ConfigWord;
74  uint32_t Bar;
76 
77 
85 typedef struct temu_ApbIface {
86  temu_ApbPnpInfo* (*getApbPnp)(void *Obj);
88 #define TEMU_APB_IFACE_TYPE "ApbIface"
90 
91 
92 
93 static inline void
94 temu_ahbSetVendor(temu_AhbPnpInfo *Ahb, uint32_t Vendor)
95 {
96  Ahb->IdentReg = (Ahb->IdentReg & 0x00ffffff) | (Vendor << 24);
97 }
98 
99 
100 static inline void
101 temu_ahbSetDeviceId(temu_AhbPnpInfo *Ahb, uint32_t Device)
102 {
103  Ahb->IdentReg = (Ahb->IdentReg & 0xff000fff) | (Device << 12);
104 }
105 
106 static inline void
107 temu_ahbSetVersion(temu_AhbPnpInfo *Ahb, uint32_t Version)
108 {
109  Ahb->IdentReg = (Ahb->IdentReg & 0xfffffc1f) | (Version << 5);
110 }
111 
112 static inline void
113 temu_ahbSetIrq(temu_AhbPnpInfo *Ahb, uint32_t Irq)
114 {
115  Ahb->IdentReg = (Ahb->IdentReg & 0xffffffe0) | Irq;
116 }
117 
118 static inline uint32_t
119 temu_ahbGetIrq(temu_AhbPnpInfo *Ahb)
120 {
121  return Ahb->IdentReg & 0x1f;
122 }
123 
124 static inline void
125 temu_ahbSetUserDef(temu_AhbPnpInfo *Ahb, int Id, uint32_t User)
126 {
127  Ahb->UserDef[Id] = User;
128 }
129 
130 static inline void
131 temu_ahbSetAddr(temu_AhbPnpInfo *Ahb, int Id, uint32_t Addr)
132 {
133  Ahb->Bar[Id] = (Ahb->Bar[Id] & 0x000fffff) | (Addr & 0xfff00000);
134 }
135 
136 static inline void
137 temu_ahbSetCP(temu_AhbPnpInfo *Ahb, int Id, uint32_t CP)
138 {
139  Ahb->Bar[Id] = (Ahb->Bar[Id] & 0xfff0ffff) | (CP << 16);
140 }
141 
142 static inline void
143 temu_ahbSetMask(temu_AhbPnpInfo *Ahb, int Id, uint32_t Mask)
144 {
145  Ahb->Bar[Id] = (Ahb->Bar[Id] & 0xffff000f) | (Mask << 4);
146 }
147 
148 static inline void
149 temu_ahbSetType(temu_AhbPnpInfo *Ahb, int Id, uint32_t Type)
150 {
151  Ahb->Bar[Id] = (Ahb->Bar[Id] & 0xfffffff0) | Type;
152 }
153 
154 
155 
156 static inline void
157 temu_apbSetVendorId(temu_ApbPnpInfo *Apb, uint32_t Vendor)
158 {
159  Apb->ConfigWord = (Apb->ConfigWord & 0x00ffffff) | (Vendor << 24);
160 }
161 
162 static inline uint32_t
163 temu_apbGetVendorId(temu_ApbPnpInfo *Apb)
164 {
165  return (Apb->ConfigWord >> 24) & 0xff;
166 }
167 
168 static inline void
169 temu_apbSetDeviceId(temu_ApbPnpInfo *Apb, uint32_t Device)
170 {
171  Apb->ConfigWord = (Apb->ConfigWord & 0xff000fff) | (Device << 12);
172 }
173 
174 static inline uint32_t
175 temu_apbGetDeviceId(temu_ApbPnpInfo *Apb)
176 {
177  return (Apb->ConfigWord >> 12) & 0xfff;
178 }
179 
180 
181 static inline void
182 temu_apbSetVersion(temu_ApbPnpInfo *Apb, uint32_t Version)
183 {
184  Apb->ConfigWord = (Apb->ConfigWord & 0xfffffc1f) | (Version << 5);
185 }
186 
187 static inline uint32_t
188 temu_apbGetVersion(temu_ApbPnpInfo *Apb)
189 {
190  return (Apb->ConfigWord >> 5) & 0x1f;
191 }
192 
193 
194 static inline void
195 temu_apbSetIrq(temu_ApbPnpInfo *Apb, uint32_t Irq)
196 {
197  Apb->ConfigWord = (Apb->ConfigWord & 0xffffffe0) | Irq;
198 }
199 
200 static inline uint32_t
201 temu_apbGetIrq(temu_ApbPnpInfo *Apb)
202 {
203  return Apb->ConfigWord & 0x1f;
204 }
205 
206 static inline void
207 temu_apbSetAddr(temu_ApbPnpInfo *Apb, uint32_t Addr)
208 {
209  Apb->Bar = (Apb->Bar & 0x000fffff) | ((Addr & 0x000fff00) << 12);
210 }
211 
212 static inline void
213 temu_apbSetCP(temu_ApbPnpInfo *Apb, uint32_t CP)
214 {
215  Apb->Bar = (Apb->Bar & 0xfff0ffff) | (CP << 16);
216 }
217 
218 static inline void
219 temu_apbSetMask(temu_ApbPnpInfo *Apb, uint32_t Mask)
220 {
221  Apb->Bar = (Apb->Bar & 0xffff000f) | (Mask << 4);
222 }
223 
224 static inline void
225 temu_apbSetType(temu_ApbPnpInfo *Apb, uint32_t Type)
226 {
227  Apb->Bar = (Apb->Bar & 0xfffffff0) | Type;
228 }
229 
230 #ifdef __cplusplus
231 }
232 #endif
233 
234 #endif /* ! TEMU_BUS_SERIAL_H */
struct temu_ApbIface temu_ApbIface
AHB bus plug and play record.
Definition: Amba.h:51
uint32_t UserDef[3]
Definition: Amba.h:53
uint32_t ConfigWord
Definition: Amba.h:73
uint32_t Bar
Definition: Amba.h:74
#define TEMU_IFACE_REFERENCE_TYPE(N)
Definition: Objsys.h:129
struct temu_AhbIface temu_AhbIface
APB bus plug and play record.
Definition: Amba.h:72
uint32_t IdentReg
Definition: Amba.h:52
uint32_t Bar[4]
Definition: Amba.h:54