summaryrefslogtreecommitdiff
path: root/firmware/system.h
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/system.h')
-rw-r--r--firmware/system.h267
1 files changed, 267 insertions, 0 deletions
diff --git a/firmware/system.h b/firmware/system.h
new file mode 100644
index 0000000000..bacf90ad66
--- /dev/null
+++ b/firmware/system.h
@@ -0,0 +1,267 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Alan Korr
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#ifndef __SYSTEM_H__
21#define __SYSTEM_H__
22#include <sh7034.h>
23
24#define KB *1024
25#define MB *1024 KB
26#define GB *1024 MB
27
28#define Hz *1
29#define KHz *1000 Hz
30#define MHz *1000 KHz
31
32#define ns *1
33#define us *1000 ns
34#define ms *1000 us
35
36/*
37 * 11.059,200 MHz => 90.4224537037037037037037037037037... ns
38 * 12.000,000 MHz => 83.3333333333333333333333333333333... ns
39 */
40
41#define PHI ((int)(12.000000 MHz))
42#define BAUDRATE 9600
43
44//#define PHI ((int)(11.059200 MHz))
45//#define BAUDRATE 115200 /* 115200 - 9600 */
46
47#define SI(a) \
48 (*((volatile int *)a)) /* single integer access - 32-bit */
49#define HI(a) \
50 (*((volatile short *)a)) /* half integer access - 16-bit */
51#define QI(a) \
52 (*((volatile char *)a)) /* quarter integer access - 8-bit */
53
54#define nop \
55 asm volatile ("nop")
56
57#define __set_mask_constant(mask,address) \
58 asm \
59 ("or.b\t%0,@(r0,gbr)" \
60 : \
61 : /* %0 */ "I"((char)(mask)), \
62 /* %1 */ "z"(address-GBR))
63
64#define __clear_mask_constant(mask,address) \
65 asm \
66 ("and.b\t%0,@(r0,gbr)" \
67 : \
68 : /* %0 */ "I"((char)~(mask)), \
69 /* %1 */ "z"(address-GBR))
70
71#define __toggle_mask_constant(mask,address) \
72 asm \
73 ("xor.b\t%0,@(r0,gbr)" \
74 : \
75 : /* %0 */ "I"((char)(mask)), \
76 /* %1 */ "z"(address-GBR))
77
78#define __test_mask_constant(mask,address) \
79 ({ \
80 int result; \
81 asm \
82 ("tst.b\t%1,@(r0,gbr)\n\tmovt\t%0" \
83 : "=r"(result) \
84 : "I"((char)(mask)),"z"(address-GBR)); \
85 result; \
86 })
87
88#define __set_bit_constant(bit,address) \
89 asm \
90 ("or.b\t%0,@(r0,gbr)" \
91 : \
92 : /* %0 */ "I"((char)(1<<(bit))), \
93 /* %1 */ "z"(address-GBR))
94
95#define __clear_bit_constant(bit,address) \
96 asm \
97 ("and.b\t%0,@(r0,gbr)" \
98 : \
99 : /* %0 */ "I"((char)~(1<<(bit))), \
100 /* %1 */ "z"(address-GBR))
101
102#define __toggle_bit_constant(bit,address) \
103 asm \
104 ("xor.b\t%0,@(r0,gbr)" \
105 : \
106 : /* %0 */ "I"((char)(1<<(bit))), \
107 /* %1 */ "z"(address-GBR))
108
109#define __test_bit_constant(bit,address) \
110 ({ \
111 int result; \
112 asm \
113 ("tst.b\t%1,@(r0,gbr)\n\tmovt\t%0" \
114 : "=r"(result) \
115 : "I"((char)(1<<(bit))),"z"(address-GBR)); \
116 result; \
117 })
118
119#define __set_mask(mask,address) /* FIXME */
120#define __test_mask(mask,address) 0 /* FIXME */
121#define __clear_mask(mask,address) /* FIXME */
122#define __toggle_mask(mask,address) /* FIXME */
123
124#define __set_bit(bit,address) /* FIXME */
125#define __test_bit(bit,address) 0 /* FIXME */
126#define __clear_bit(bit,address) /* FIXME */
127#define __toggle_bit(bit,address) /* FIXME */
128
129#define set_mask(mask,address) \
130 if (__builtin_constant_p (mask)) \
131 __set_mask_constant (mask,address); \
132 else \
133 __set_mask (mask,address)
134
135#define clear_mask(mask,address) \
136 if (__builtin_constant_p (mask)) \
137 __clear_mask_constant (mask,address); \
138 else \
139 __clear_mask (mask,address)
140
141#define toggle_mask(mask,address) \
142 if (__builtin_constant_p (mask)) \
143 __toggle_mask_constant (mask,address); \
144 else \
145 __toggle_mask (mask,address)
146
147#define test_mask(mask,address) \
148 ( \
149 (__builtin_constant_p (mask)) \
150 ? (int)__test_mask_constant (mask,address) \
151 : (int)__test_mask (mask,address) \
152 )
153
154
155#define set_bit(bit,address) \
156 if (__builtin_constant_p (bit)) \
157 __set_bit_constant (bit,address); \
158 else \
159 __set_bit (bit,address)
160
161#define clear_bit(bit,address) \
162 if (__builtin_constant_p (bit)) \
163 __clear_bit_constant (bit,address); \
164 else \
165 __clear_bit (bit,address)
166
167#define toggle_bit(bit,address) \
168 if (__builtin_constant_p (bit)) \
169 __toggle_bit_constant (bit,address); \
170 else \
171 __toggle_bit (bit,address)
172
173#define test_bit(bit,address) \
174 ( \
175 (__builtin_constant_p (bit)) \
176 ? (int)__test_bit_constant (bit,address) \
177 : (int)__test_bit (bit,address) \
178 )
179
180
181extern char __swap_bit[256];
182
183#define swap_bit(byte) \
184 __swap_bit[byte]
185
186static inline short swabHI (short value)
187 /*
188 result[15..8] = value[ 7..0];
189 result[ 7..0] = value[15..8];
190 */
191 {
192 short result;
193 asm volatile ("swap.b\t%1,%0" : "=r"(result) : "r"(value));
194 return result;
195 }
196
197static inline int swawSI (int value)
198 /*
199 result[31..16] = value[15.. 0];
200 result[15.. 0] = value[31..16];
201 */
202 {
203 int result;
204 asm volatile ("swap.w\t%1,%0" : "=r"(result) : "r"(value));
205 return result;
206 }
207
208static inline int swabSI (int value) // should be avoided as much as possible
209 /*
210 result[31..24] = value[ 7.. 0];
211 result[23..16] = value[15.. 8];
212 result[15.. 8] = value[23..16];
213 result[ 7.. 0] = value[31..24];
214 */
215 {
216 return swabHI(swawSI(swabSI(value)));
217 }
218
219/* Test And Set - UNTESTED */
220static inline int tas (volatile int *pointer)
221 {
222 int result;
223 asm volatile ("tas.b\t@%1;movt\t%0" : "=t"(result) : "r"((char *)pointer) : "memory");
224 return result;
225 }
226
227static inline void sti (void)
228 {
229 asm volatile ("ldc\t%0,sr" : : "r"(0<<4));
230 }
231
232static inline void cli (void)
233 {
234 asm volatile ("ldc\t%0,sr" : : "r"(15<<4));
235 }
236
237/* Compare And Swap */
238static inline int cas (volatile int *pointer,int requested_value,int new_value)
239 {
240 cli();
241 if (*pointer == requested_value)
242 {
243 *pointer = new_value;
244 sti ();
245 return 1;
246 }
247 sti ();
248 return 0;
249 }
250
251static inline int cas2 (volatile int *pointer1,volatile int *pointer2,int requested_value1,int requested_value2,int new_value1,int new_value2)
252 {
253 cli();
254 if (*pointer1 == requested_value1 && *pointer2 == requested_value2)
255 {
256 *pointer1 = new_value1;
257 *pointer2 = new_value2;
258 sti ();
259 return 1;
260 }
261 sti ();
262 return 0;
263 }
264
265extern void system_reboot (void);
266
267#endif